b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | From f15d27f9c90ede4b16eb37f9ae573ef81c2b6996 Mon Sep 17 00:00:00 2001 |
| 2 | From: David Bauer <mail@david-bauer.net> |
| 3 | Date: Thu, 31 Dec 2020 18:49:12 +0100 |
| 4 | Subject: [PATCH] MIPS: add bootargs-override property |
| 5 | |
| 6 | Add support for the bootargs-override property to the chosen node |
| 7 | similar to the one used on ipq806x or mpc85xx. |
| 8 | |
| 9 | This is necessary, as the U-Boot used on some boards, notably the |
| 10 | Ubiquiti UniFi 6 Lite, overwrite the bootargs property of the chosen |
| 11 | node leading to a kernel panic when loading OpenWrt. |
| 12 | |
| 13 | Signed-off-by: David Bauer <mail@david-bauer.net> |
| 14 | --- |
| 15 | arch/mips/kernel/setup.c | 30 ++++++++++++++++++++++++++++++ |
| 16 | 1 file changed, 30 insertions(+) |
| 17 | |
| 18 | --- a/arch/mips/kernel/setup.c |
| 19 | +++ b/arch/mips/kernel/setup.c |
| 20 | @@ -571,8 +571,28 @@ static int __init bootcmdline_scan_chose |
| 21 | return 1; |
| 22 | } |
| 23 | |
| 24 | +static int __init bootcmdline_scan_chosen_override(unsigned long node, const char *uname, |
| 25 | + int depth, void *data) |
| 26 | +{ |
| 27 | + bool *dt_bootargs = data; |
| 28 | + const char *p; |
| 29 | + int l; |
| 30 | + |
| 31 | + if (depth != 1 || !data || strcmp(uname, "chosen") != 0) |
| 32 | + return 0; |
| 33 | + |
| 34 | + p = of_get_flat_dt_prop(node, "bootargs-override", &l); |
| 35 | + if (p != NULL && l > 0) { |
| 36 | + strlcpy(boot_command_line, p, COMMAND_LINE_SIZE); |
| 37 | + *dt_bootargs = true; |
| 38 | + } |
| 39 | + |
| 40 | + return 1; |
| 41 | +} |
| 42 | + |
| 43 | static void __init bootcmdline_init(char **cmdline_p) |
| 44 | { |
| 45 | + bool dt_bootargs_override = false; |
| 46 | bool dt_bootargs = false; |
| 47 | |
| 48 | /* |
| 49 | @@ -586,6 +606,14 @@ static void __init bootcmdline_init(char |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | + * If bootargs-override in the chosen node is set, use this as the |
| 54 | + * command line |
| 55 | + */ |
| 56 | + of_scan_flat_dt(bootcmdline_scan_chosen_override, &dt_bootargs_override); |
| 57 | + if (dt_bootargs_override) |
| 58 | + return; |
| 59 | + |
| 60 | + /* |
| 61 | * If the user specified a built-in command line & |
| 62 | * MIPS_CMDLINE_BUILTIN_EXTEND, then the built-in command line is |
| 63 | * prepended to arguments from the bootloader or DT so we'll copy them |