mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-08 04:42:04 -04:00
utags: read utag block device path in bootconfig from device tree
GKI2.0 doens't allow to export kernel_read and kernel_write api, so we get the block device path in bootconfig from device tree. Change-Id: I8601a35f88344eb5ba7601fc302eb1b846e945a0 Signed-off-by: qianlong <qianl2@motorola.com> Reviewed-on: https://gerrit.mot.com/2072437 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:
parent
aaa2820ec1
commit
6180117a2e
1 changed files with 10 additions and 103 deletions
|
|
@ -1939,7 +1939,7 @@ stop_building_utags:
|
|||
#ifdef CONFIG_OF
|
||||
static char *bootargs_str;
|
||||
|
||||
static int utag_get_bootarg(char *key, char **value)
|
||||
static int utag_get_bootarg(char *key, char **value, char *prop, char *spl_flag)
|
||||
{
|
||||
const char *bootargs_ptr = NULL;
|
||||
char *idx = NULL;
|
||||
|
|
@ -1951,7 +1951,7 @@ static int utag_get_bootarg(char *key, char **value)
|
|||
if (n == NULL)
|
||||
goto err;
|
||||
|
||||
if (of_property_read_string(n, "bootargs", &bootargs_ptr) != 0)
|
||||
if (of_property_read_string(n, prop, &bootargs_ptr) != 0)
|
||||
goto err_putnode;
|
||||
|
||||
bootargs_ptr_len = strlen(bootargs_ptr);
|
||||
|
|
@ -1968,7 +1968,7 @@ static int utag_get_bootarg(char *key, char **value)
|
|||
kvpair = strsep(&idx, " ");
|
||||
if (kvpair)
|
||||
if (strsep(&kvpair, "=")) {
|
||||
*value = strsep(&kvpair, " ");
|
||||
*value = strsep(&kvpair, spl_flag);
|
||||
if (*value)
|
||||
err = 0;
|
||||
}
|
||||
|
|
@ -1981,100 +1981,7 @@ err:
|
|||
}
|
||||
|
||||
#ifdef CONFIG_BOOT_CONFIG
|
||||
static int utag_haskey_bootarg(char *key)
|
||||
{
|
||||
const char *bootargs_ptr = NULL;
|
||||
char *idx = NULL;
|
||||
int err = 0;
|
||||
struct device_node *n = of_find_node_by_path("/chosen");
|
||||
size_t bootargs_ptr_len = 0;
|
||||
|
||||
if (n == NULL)
|
||||
goto err;
|
||||
|
||||
if (of_property_read_string(n, "bootargs", &bootargs_ptr) != 0)
|
||||
goto err_putnode;
|
||||
|
||||
bootargs_ptr_len = strlen(bootargs_ptr);
|
||||
if (!bootargs_str) {
|
||||
/* Following operations need a non-const version of bootargs */
|
||||
bootargs_str = kzalloc(bootargs_ptr_len + 1, GFP_KERNEL);
|
||||
if (!bootargs_str)
|
||||
goto err_putnode;
|
||||
}
|
||||
strlcpy(bootargs_str, bootargs_ptr, bootargs_ptr_len + 1);
|
||||
|
||||
idx = strnstr(bootargs_str, key, strlen(bootargs_str));
|
||||
if (idx)
|
||||
err = 1;
|
||||
|
||||
err_putnode:
|
||||
of_node_put(n);
|
||||
err:
|
||||
return err;
|
||||
}
|
||||
|
||||
#include <linux/bootconfig.h>
|
||||
#define BOOTCONFIG_FULLPATH "/proc/bootconfig"
|
||||
static char bootdevice_name[256];
|
||||
|
||||
static int utags_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;
|
||||
loff_t pos = 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(filep, (void *) xbc_buf, XBC_DATA_MAX, &pos);
|
||||
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(bootdevice_name, 0, sizeof(bootdevice_name));
|
||||
while (p && *p && (*p != '\n') && (*p != '"')
|
||||
&& (i < sizeof(bootdevice_name))) {
|
||||
bootdevice_name[i] = *p;
|
||||
i++;
|
||||
p++;
|
||||
}
|
||||
*bootconfig_val = bootdevice_name;
|
||||
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;
|
||||
}
|
||||
|
||||
static int utags_get_bootdevice_from_bootconfig(char **bootconfig_val)
|
||||
{
|
||||
static char bootdevice_init = 0;
|
||||
|
|
@ -2085,10 +1992,11 @@ static int utags_get_bootdevice_from_bootconfig(char **bootconfig_val)
|
|||
return 0;
|
||||
}
|
||||
|
||||
rc = utags_read_bootconfig("androidboot.bootdevice = \"", bootconfig_val);
|
||||
if (!rc && *bootconfig_val)
|
||||
rc = utag_get_bootarg("androidboot.bootdevice=", bootconfig_val, "mmi,bootconfig", "\n");
|
||||
if (!rc && *bootconfig_val) {
|
||||
strncpy(bootdevice_name, *bootconfig_val, strlen(*bootconfig_val));
|
||||
bootdevice_init = 1;
|
||||
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -2103,15 +2011,14 @@ static void utags_bootdevice_expand(const char **name_ptr, const char *name)
|
|||
char *replace, *suffix, *expanded;
|
||||
|
||||
#ifndef CONFIG_BOOT_CONFIG
|
||||
rc = utag_get_bootarg("androidboot.bootdevice=", &bootdevice);
|
||||
rc = utag_get_bootarg("androidboot.bootdevice=", &bootdevice, "bootargs", " ");
|
||||
if (rc || !bootdevice)
|
||||
goto need_no_expansion;
|
||||
#else
|
||||
if (utag_haskey_bootarg("bootconfig"))
|
||||
rc = utags_get_bootdevice_from_bootconfig(&bootdevice);
|
||||
rc = utags_get_bootdevice_from_bootconfig(&bootdevice);
|
||||
|
||||
if (rc || !bootdevice) {
|
||||
rc = utag_get_bootarg("androidboot.bootdevice=", &bootdevice);
|
||||
rc = utag_get_bootarg("androidboot.bootdevice=", &bootdevice, "bootargs", " ");
|
||||
if (rc || !bootdevice)
|
||||
goto need_no_expansion;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue