From c4453b53c5d0fb407d5f32501bf2947519b3d413 Mon Sep 17 00:00:00 2001 From: Alexey Min Date: Wed, 11 Sep 2019 21:51:40 +0300 Subject: [PATCH] arch: arm64: Add config option to fix bootloader cmdline args Android bootloader passes some arguments in kernel command line, that make booting custom OSes harder: * skip_initramfs * root=PARTUUID=... * init=/init Those parameters override default boot partition to hardcoded, set init binary to /init, disable booting from initramfs. If enabled, those parameters will be erased from bootloader's command line, and custom OS can boot the way it likes. * * * Additionally, removes `console=ram` parameter as it breaks boot. Co-authored-by: Alexey Min Co-authored-by: Samuel Dionne-Riel --- arch/arm64/Kconfig | 17 +++++++++++++++++ drivers/of/fdt.c | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 4aeab058d62..86db137ed47 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -851,6 +851,23 @@ config CMDLINE_FORCE command-line options your boot loader passes to the kernel. endchoice +config CMDLINE_DROP_DANGEROUS_ANDROID_OPTIONS + bool "Drop certain dangerous options from cmdline" + default n + help + Android bootloader passes some arguments in kernel command + line, that make booting custom OSes harder: + + * skip_initramfs + * root=PARTUUID=... + * init=/init + + Those parameters override default boot partition to hardcoded, + set init binary to /init, disable booting from initramfs. + + If enabled, those parameters will be erased from bootloader's + command line, and custom OS can boot the way it likes. + config EFI_STUB bool diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 821f6b591ce..b15823ccaf4 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -948,6 +948,26 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname, pr_debug("Command line is: %s\n", (char*)data); +#ifdef CONFIG_CMDLINE_DROP_DANGEROUS_ANDROID_OPTIONS + pr_err("Replacing dangerous cmdline options..."); + // For boot as recovery + cmdline = strstr((const char *)data, "skip_initramfs"); + if (cmdline) + *cmdline = '_'; + cmdline = strstr((const char *)data, "root="); + if (cmdline) + *cmdline = '_'; + cmdline = strstr((const char *)data, "init="); + if (cmdline) + *cmdline = '_'; + + // Additional cleanup for Galaxy A5 + cmdline = strstr((const char *)data, "console=ram"); + if (cmdline) + *cmdline = '_'; + pr_err("Command line now is: %s\n", (char*)data); +#endif + /* break now */ return 1; } -- 2.29.2