blob: f0f58e7a88fc6a657c1c907d560de53db03769d0 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001From: Imre Kaloz <kaloz@openwrt.org>
2Subject: init: add CONFIG_MANGLE_BOOTARGS and disable it by default
3
4Enabling this option renames the bootloader supplied root=
5and rootfstype= variables, which might have to be know but
6would break the automatisms OpenWrt uses.
7
8Signed-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();