kernel: split patches folder up into backport, pending and hack folders
[oweals/openwrt.git] / target / linux / generic / pending-4.9 / 920-mangle_bootargs.patch
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 diff --git a/init/Kconfig b/init/Kconfig
15 index 9063c81b9665..fb66d3ef78e0 100644
16 --- a/init/Kconfig
17 +++ b/init/Kconfig
18 @@ -1687,6 +1687,15 @@ config EMBEDDED
19           an embedded system so certain expert options are available
20           for configuration.
21  
22 +config MANGLE_BOOTARGS
23 +       bool "Rename offending bootargs"
24 +       depends on EXPERT
25 +       help
26 +         Sometimes the bootloader passed bogus root= and rootfstype=
27 +         parameters to the kernel, and while you want to ignore them,
28 +         you need to know the values f.e. to support dual firmware
29 +         layouts on the flash.
30 +
31  config HAVE_PERF_EVENTS
32         bool
33         help
34 diff --git a/init/main.c b/init/main.c
35 index ae3996ae9bac..3855fa4ffb95 100644
36 --- a/init/main.c
37 +++ b/init/main.c
38 @@ -352,6 +352,29 @@ static inline void setup_nr_cpu_ids(void) { }
39  static inline void smp_prepare_cpus(unsigned int maxcpus) { }
40  #endif
41  
42 +#ifdef CONFIG_MANGLE_BOOTARGS
43 +static void __init mangle_bootargs(char *command_line)
44 +{
45 +       char *rootdev;
46 +       char *rootfs;
47 +
48 +       rootdev = strstr(command_line, "root=/dev/mtdblock");
49 +
50 +       if (rootdev)
51 +               strncpy(rootdev, "mangled_rootblock=", 18);
52 +
53 +       rootfs = strstr(command_line, "rootfstype");
54 +
55 +       if (rootfs)
56 +               strncpy(rootfs, "mangled_fs", 10);
57 +
58 +}
59 +#else
60 +static void __init mangle_bootargs(char *command_line)
61 +{
62 +}
63 +#endif
64 +
65  /*
66   * We need to store the untouched command line for future reference.
67   * We also need to store the touched command line since the parameter
68 @@ -504,6 +527,7 @@ asmlinkage __visible void __init start_kernel(void)
69         pr_notice("%s", linux_banner);
70         setup_arch(&command_line);
71         mm_init_cpumask(&init_mm);
72 +       mangle_bootargs(command_line);
73         setup_command_line(command_line);
74         setup_nr_cpu_ids();
75         setup_per_cpu_areas();
76 -- 
77 2.11.0
78