b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From: Imre Kaloz <kaloz@openwrt.org> |
| 2 | Subject: init: add CONFIG_MANGLE_BOOTARGS and disable it by default |
| 3 | |
| 4 | Enabling this option renames the bootloader supplied root= |
| 5 | and rootfstype= variables, which might have to be know but |
| 6 | would break the automatisms OpenWrt uses. |
| 7 | |
| 8 | Signed-off-by: Imre Kaloz <kaloz@openwrt.org> |
| 9 | --- |
| 10 | init/Kconfig | 9 +++++++++ |
| 11 | init/main.c | 24 ++++++++++++++++++++++++ |
| 12 | 2 files changed, 33 insertions(+) |
| 13 | |
| 14 | --- a/init/Kconfig |
| 15 | +++ b/init/Kconfig |
| 16 | @@ -1684,6 +1684,15 @@ config EMBEDDED |
| 17 | an embedded system so certain expert options are available |
| 18 | for configuration. |
| 19 | |
| 20 | +config MANGLE_BOOTARGS |
| 21 | + bool "Rename offending bootargs" |
| 22 | + depends on EXPERT |
| 23 | + help |
| 24 | + Sometimes the bootloader passed bogus root= and rootfstype= |
| 25 | + parameters to the kernel, and while you want to ignore them, |
| 26 | + you need to know the values f.e. to support dual firmware |
| 27 | + layouts on the flash. |
| 28 | + |
| 29 | config HAVE_PERF_EVENTS |
| 30 | bool |
| 31 | help |
| 32 | --- a/init/main.c |
| 33 | +++ b/init/main.c |
| 34 | @@ -367,6 +367,29 @@ static inline void setup_nr_cpu_ids(void |
| 35 | static inline void smp_prepare_cpus(unsigned int maxcpus) { } |
| 36 | #endif |
| 37 | |
| 38 | +#ifdef CONFIG_MANGLE_BOOTARGS |
| 39 | +static void __init mangle_bootargs(char *command_line) |
| 40 | +{ |
| 41 | + char *rootdev; |
| 42 | + char *rootfs; |
| 43 | + |
| 44 | + rootdev = strstr(command_line, "root=/dev/mtdblock"); |
| 45 | + |
| 46 | + if (rootdev) |
| 47 | + strncpy(rootdev, "mangled_rootblock=", 18); |
| 48 | + |
| 49 | + rootfs = strstr(command_line, "rootfstype"); |
| 50 | + |
| 51 | + if (rootfs) |
| 52 | + strncpy(rootfs, "mangled_fs", 10); |
| 53 | + |
| 54 | +} |
| 55 | +#else |
| 56 | +static void __init mangle_bootargs(char *command_line) |
| 57 | +{ |
| 58 | +} |
| 59 | +#endif |
| 60 | + |
| 61 | /* |
| 62 | * We need to store the untouched command line for future reference. |
| 63 | * We also need to store the touched command line since the parameter |
| 64 | @@ -597,6 +620,7 @@ asmlinkage __visible void __init start_k |
| 65 | pr_notice("%s", linux_banner); |
| 66 | early_security_init(); |
| 67 | setup_arch(&command_line); |
| 68 | + mangle_bootargs(command_line); |
| 69 | setup_command_line(command_line); |
| 70 | setup_nr_cpu_ids(); |
| 71 | setup_per_cpu_areas(); |