MA-12335 Canonical Boot Reason in Android Pie 9.0

Read boot reason from SRC(system reset controller) and report
it to kernel by "androidboot.bootreason=<>" kernel commandline.
This is enabled on imx6/7/7ulp/8m, imx8 will report default value
"androidboot.bootreason=reboot" since it can't get such info on
A core at u-boot stage.

Test: Boot reason report ok on imx6qp/imx7ulp/imx8qxp.

Change-Id: I03effaa03bc513bec6153e82c1a04e29c07e7db8
Signed-off-by: Ji Luo <ji.luo@nxp.com>
This commit is contained in:
Ji Luo 2018-09-10 18:44:31 +08:00
parent 225fa189fa
commit 02b8787d0d
4 changed files with 53 additions and 0 deletions

View File

@ -43,7 +43,12 @@ static char *get_reset_cause(void)
struct src *src_regs = (struct src *)SRC_BASE_ADDR; struct src *src_regs = (struct src *)SRC_BASE_ADDR;
cause = readl(&src_regs->srsr); cause = readl(&src_regs->srsr);
#ifndef CONFIG_ANDROID_BOOT_IMAGE
/* We will read the ssrs states later for android so we don't
* clear the states here.
*/
writel(cause, &src_regs->srsr); writel(cause, &src_regs->srsr);
#endif
reset_cause = cause; reset_cause = cause;
switch (cause) { switch (cause) {
@ -87,6 +92,17 @@ static char *get_reset_cause(void)
} }
} }
#ifdef CONFIG_ANDROID_BOOT_IMAGE
void get_reboot_reason(char *ret)
{
struct src *src_regs = (struct src *)SRC_BASE_ADDR;
strcpy(ret, (char *)get_reset_cause());
/* clear the srsr here, its state has been recorded in reset_cause */
writel(reset_cause, &src_regs->srsr);
}
#endif
u32 get_imx_reset_cause(void) u32 get_imx_reset_cause(void)
{ {
return reset_cause; return reset_cause;

View File

@ -252,7 +252,12 @@ static char *get_reset_cause(char *ret)
srs = readl(reg_srs); srs = readl(reg_srs);
cause1 = readl(reg_ssrs); cause1 = readl(reg_ssrs);
#ifndef CONFIG_ANDROID_BOOT_IMAGE
/* We will read the ssrs states later for android so we don't
* clear the states here.
*/
writel(cause1, reg_ssrs); writel(cause1, reg_ssrs);
#endif
reset_cause = cause1; reset_cause = cause1;
@ -292,6 +297,17 @@ static char *get_reset_cause(char *ret)
return ret; return ret;
} }
#ifdef CONFIG_ANDROID_BOOT_IMAGE
void get_reboot_reason(char *ret)
{
u32 *reg_ssrs = (u32 *)(SRC_BASE_ADDR + 0x28);
get_reset_cause(ret);
/* clear the ssrs here, its state has been recorded in reset_cause */
writel(reset_cause, reg_ssrs);
}
#endif
void arch_preboot_os(void) void arch_preboot_os(void)
{ {
#if defined(CONFIG_VIDEO_MXS) #if defined(CONFIG_VIDEO_MXS)

View File

@ -143,6 +143,23 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
metrics.odt, metrics.sw); metrics.odt, metrics.sw);
strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline)); strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
#if defined(CONFIG_ARCH_MX6) || defined(CONFIG_ARCH_MX7) || \
defined(CONFIG_ARCH_MX7ULP) || defined(CONFIG_ARCH_IMX8M)
char cause[18];
memset(cause, '\0', sizeof(cause));
get_reboot_reason(cause);
if (strstr(cause, "POR"))
sprintf(newbootargs," androidboot.bootreason=cold,powerkey");
else if (strstr(cause, "WDOG") || strstr(cause, "WDG"))
sprintf(newbootargs," androidboot.bootreason=watchdog");
else
sprintf(newbootargs," androidboot.bootreason=reboot");
#else
sprintf(newbootargs," androidboot.bootreason=reboot");
#endif
strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
#ifdef CONFIG_AVB_SUPPORT #ifdef CONFIG_AVB_SUPPORT
/* secondary cmdline added by avb */ /* secondary cmdline added by avb */
char *bootargs_sec = env_get("bootargs_sec"); char *bootargs_sec = env_get("bootargs_sec");

View File

@ -164,6 +164,10 @@ int print_cpuinfo(void);
int update_flash_size(int flash_size); int update_flash_size(int flash_size);
int arch_early_init_r(void); int arch_early_init_r(void);
#ifdef CONFIG_ANDROID_BOOT_IMAGE
void get_reboot_reason(char *ret);
#endif
/* /*
* setup_board_extra() - Fill in extra details in the bd_t structure * setup_board_extra() - Fill in extra details in the bd_t structure
* *