mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-09 21:59:12 -04:00
mmi_info: read all from bootconfig
After 8450 rebased to qcom FC, the bootconfig feature begins enable. So that some androidboot.* canot be found in the cmdline, and case can not read it. When bootconfig enabled, read it from /proc/bootconifg file. Change-Id: I77b8e023c1fbb85ee941663878823c26d357df2e Signed-off-by: qianlong <qianl2@motorola.com> Reviewed-on: https://gerrit.mot.com/2010969 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Zhenxin Xi <xizx@motorola.com> Submit-Approved: Jira Key
This commit is contained in:
parent
b720cdf2d7
commit
1f1f1b568d
2 changed files with 95 additions and 85 deletions
|
|
@ -70,100 +70,16 @@
|
|||
static char bootreason[BOOTREASON_MAX_LEN];
|
||||
static char bootmode[BOOTMODE_MAX_LEN];
|
||||
|
||||
#ifdef CONFIG_BOOT_CONFIG
|
||||
#include <linux/bootconfig.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#define BOOTCONFIG_FULLPATH "/proc/bootconfig"
|
||||
static char bootconfig_tmp[256];
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
|
||||
static inline ssize_t kernel_read_stub(struct file *file, void *addr, size_t count)
|
||||
{
|
||||
loff_t pos = 0;
|
||||
return kernel_read(file, addr, count, &pos);
|
||||
}
|
||||
#else
|
||||
static inline ssize_t kernel_read_stub(struct file *file, void *addr, size_t count)
|
||||
{
|
||||
return kernel_read(file, 0, addr, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int mmi_read_bootconfig(const char *bootconfig_key, char **bootconfig_val)
|
||||
{
|
||||
struct file *filep = NULL;
|
||||
char *xbc_buf = NULL;
|
||||
int bytes = 0;
|
||||
char *start_bootdevice = NULL;
|
||||
int rc = 0;
|
||||
|
||||
filep = filp_open(BOOTCONFIG_FULLPATH, O_RDONLY, 0600);
|
||||
if (IS_ERR_OR_NULL(filep)) {
|
||||
rc = PTR_ERR(filep);
|
||||
pr_err("opening (%s) errno=%d\n", BOOTCONFIG_FULLPATH, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
xbc_buf = kzalloc(XBC_DATA_MAX, GFP_KERNEL);
|
||||
if (!xbc_buf) {
|
||||
pr_err("alloc len %d memory fail\n", XBC_DATA_MAX);
|
||||
filp_close(filep, NULL);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
bytes = kernel_read_stub(filep, (void *) xbc_buf, XBC_DATA_MAX);
|
||||
pr_debug("read bootconfig bytes %d\n", bytes);
|
||||
if (bytes <= 0) {
|
||||
pr_err("fail read bytes %d\n", bytes);
|
||||
kfree(xbc_buf);
|
||||
filp_close(filep, NULL);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
start_bootdevice = strstr(xbc_buf, bootconfig_key);
|
||||
if (start_bootdevice) {
|
||||
char *p = start_bootdevice + strlen(bootconfig_key);
|
||||
int i = 0;
|
||||
|
||||
memset(bootconfig_tmp, 0, sizeof(bootconfig_tmp));
|
||||
while (p && *p && (*p != '\n') && (*p != '"')
|
||||
&& (i < sizeof(bootconfig_tmp))) {
|
||||
bootconfig_tmp[i] = *p;
|
||||
i++;
|
||||
p++;
|
||||
}
|
||||
*bootconfig_val = bootconfig_tmp;
|
||||
pr_info("bootconfig key %s%s\"\n", bootconfig_key, *bootconfig_val);
|
||||
} else {
|
||||
pr_err("cannot find key %s\n", bootconfig_key);
|
||||
rc = -ENOENT;
|
||||
}
|
||||
|
||||
kfree(xbc_buf);
|
||||
filp_close(filep, NULL);
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void mmi_bootarg_setup(void)
|
||||
{
|
||||
char *s;
|
||||
|
||||
#ifndef CONFIG_BOOT_CONFIG
|
||||
if (mmi_get_bootarg("androidboot.bootreason=", &s) == 0)
|
||||
strlcpy(bootreason, s, BOOTREASON_MAX_LEN);
|
||||
|
||||
if (mmi_get_bootarg("androidboot.mode=", &s) == 0)
|
||||
strlcpy(bootmode, s, BOOTMODE_MAX_LEN);
|
||||
#else
|
||||
if (mmi_read_bootconfig("androidboot.bootreason = \"", &s) == 0)
|
||||
strlcpy(bootreason, s, BOOTREASON_MAX_LEN);
|
||||
|
||||
if (mmi_read_bootconfig("androidboot.mode = \"", &s) == 0)
|
||||
strlcpy(bootmode, s, BOOTMODE_MAX_LEN);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -93,7 +93,87 @@ bool mmi_device_is_available(struct device_node *np)
|
|||
}
|
||||
EXPORT_SYMBOL(mmi_device_is_available);
|
||||
|
||||
int mmi_get_bootarg(char *key, char **value)
|
||||
#ifdef CONFIG_BOOT_CONFIG
|
||||
#include <linux/bootconfig.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/version.h>
|
||||
//#include <linux/vmalloc.h>
|
||||
#define BOOTCONFIG_FULLPATH "/proc/bootconfig"
|
||||
static char bootconfig_tmp[256];
|
||||
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
|
||||
static inline ssize_t kernel_read_stub(struct file *file, void *addr, size_t count)
|
||||
{
|
||||
loff_t pos = 0;
|
||||
return kernel_read(file, addr, count, &pos);
|
||||
}
|
||||
#else
|
||||
static inline ssize_t kernel_read_stub(struct file *file, void *addr, size_t count)
|
||||
{
|
||||
return kernel_read(file, 0, addr, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int mmi_get_bootarg_bootconfig(const char *bootconfig_key, char **bootconfig_val)
|
||||
{
|
||||
struct file *filep = NULL;
|
||||
char *xbc_buf = NULL;
|
||||
int bytes = 0;
|
||||
char *start_bootdevice = NULL;
|
||||
int rc = 0;
|
||||
|
||||
filep = filp_open(BOOTCONFIG_FULLPATH, O_RDONLY, 0600);
|
||||
if (IS_ERR_OR_NULL(filep)) {
|
||||
rc = PTR_ERR(filep);
|
||||
pr_err("opening (%s) errno=%d\n", BOOTCONFIG_FULLPATH, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
xbc_buf = kzalloc(XBC_DATA_MAX, GFP_KERNEL);
|
||||
if (!xbc_buf) {
|
||||
pr_err("alloc len %d memory fail\n", XBC_DATA_MAX);
|
||||
filp_close(filep, NULL);
|
||||
return -ENOMEM;
|
||||
|
||||
}
|
||||
|
||||
bytes = kernel_read_stub(filep, (void *) xbc_buf, XBC_DATA_MAX);
|
||||
pr_debug("read bootconfig bytes %d\n", bytes);
|
||||
if (bytes <= 0) {
|
||||
pr_err("fail read bytes %d\n", bytes);
|
||||
kfree(xbc_buf);
|
||||
filp_close(filep, NULL);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
start_bootdevice = strstr(xbc_buf, bootconfig_key);
|
||||
if (start_bootdevice) {
|
||||
char *p = start_bootdevice + strlen(bootconfig_key);
|
||||
int i = 0;
|
||||
|
||||
memset(bootconfig_tmp, 0, sizeof(bootconfig_tmp));
|
||||
while (p && *p && (*p != '\n') && (*p != '"')
|
||||
&& (i < sizeof(bootconfig_tmp))) {
|
||||
bootconfig_tmp[i] = *p;
|
||||
i++;
|
||||
p++;
|
||||
}
|
||||
*bootconfig_val = bootconfig_tmp;
|
||||
pr_info("bootconfig key %s%s\"\n", bootconfig_key, *bootconfig_val);
|
||||
} else {
|
||||
pr_err("cannot find key %s\n", bootconfig_key);
|
||||
rc = -ENOENT;
|
||||
}
|
||||
|
||||
kfree(xbc_buf);
|
||||
filp_close(filep, NULL);
|
||||
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int mmi_get_bootarg_cmdline(char *key, char **value)
|
||||
{
|
||||
const char *bootargs_tmp = NULL;
|
||||
char *idx = NULL;
|
||||
|
|
@ -136,6 +216,20 @@ err:
|
|||
return err;
|
||||
}
|
||||
|
||||
int mmi_get_bootarg(char *key, char **value)
|
||||
{
|
||||
#ifdef CONFIG_BOOT_CONFIG
|
||||
char *tmp_buf = " = \"";
|
||||
char new_key[256];
|
||||
memset(new_key, 0x0, 256);
|
||||
memcpy(new_key, key, strlen(key) - 1);
|
||||
strcat(new_key, tmp_buf);
|
||||
return mmi_get_bootarg_bootconfig(new_key, value);
|
||||
#else
|
||||
return mmi_get_bootarg_cmdline(key, value);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void mmi_of_populate_setup(void)
|
||||
{
|
||||
const char *temp;
|
||||
|
|
|
|||
Loading…
Reference in a new issue