mmi_info: Get bootconfig from device tree

GKI2.0 doens't allow to export kernel_read and kernel_write api,
so we get bootconfig from device tree.

Change-Id: I186a4b059fcbf55f2006e946677f5f6cbd59aefe
Signed-off-by: qianlong <qianl2@motorola.com>
Reviewed-on: https://gerrit.mot.com/2073134
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Zhenxin Xi <xizx@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
qianlong 2021-09-22 19:45:17 +08:00 • committed by qianl2
commit 65fce26b52

View file

@ -93,87 +93,7 @@ bool mmi_device_is_available(struct device_node *np)
}
EXPORT_SYMBOL(mmi_device_is_available);
#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;
}
#else
static int mmi_get_bootarg_cmdline(char *key, char **value)
static int mmi_get_bootarg_dt(char *key, char **value, char *prop, char *spl_flag)
{
const char *bootargs_tmp = NULL;
char *idx = NULL;
@ -185,7 +105,7 @@ static int mmi_get_bootarg_cmdline(char *key, char **value)
if (n == NULL)
goto err;
if (of_property_read_string(n, "bootargs", &bootargs_tmp) != 0)
if (of_property_read_string(n, prop, &bootargs_tmp) != 0)
goto putnode;
bootargs_tmp_len = strlen(bootargs_tmp);
@ -204,7 +124,7 @@ static int mmi_get_bootarg_cmdline(char *key, char **value)
kvpair = strsep(&idx, " ");
if (kvpair)
if (strsep(&kvpair, "=")) {
*value = strsep(&kvpair, " ");
*value = strsep(&kvpair, spl_flag);
if (*value)
err = 0;
}
@ -215,19 +135,13 @@ putnode:
err:
return err;
}
#endif
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);
return mmi_get_bootarg_dt(key, value, "mmi,bootconfig", "\n");
#else
return mmi_get_bootarg_cmdline(key, value);
return mmi_get_bootarg_dt(key, value, "bootargs", " ");
#endif
}