Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 1 | From 12a40099310177c4a494654b592e7f76ec4045f4 Mon Sep 17 00:00:00 2001 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 2 | From: Matthew Garrett <mjg59@coreos.com> |
| 3 | Date: Thu, 9 Apr 2015 13:25:00 -0700 |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 4 | Subject: [PATCH 1/4] x86: Allow built-in command line to work in early kernel |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 5 | init |
| 6 | |
| 7 | The kernel supports having a command line built into it. Unfortunately this |
| 8 | doesn't work in all cases - the built-in command line is only appended |
| 9 | after we've jumped to the kernel proper, but various parts of the early |
| 10 | boot process also pay attention to the command line. |
| 11 | |
| 12 | This patch moves the command line override code from the kernel itself to |
| 13 | the early init code. Unfortunately the kernel can be executed by jumping |
| 14 | to the 16-bit entry point, the UEFI entry point, directly to the 32-bit |
| 15 | entry point or even to the entry point of the uncompressed image, and |
| 16 | there is no guarantee that any of these will have access to data held in |
| 17 | the others. As a result, four copies of the command line will be embedded |
| 18 | in the kernel. |
| 19 | |
| 20 | This patch also defines a new field in boot_params in order to allow the |
| 21 | earlier entry points to inform the generic setup code that the command line |
| 22 | has already been appended and so shouldn't be added once more. |
| 23 | |
| 24 | Updated for Linux 4.19 by Lorenz Brun <lorenz@nexantic.com> |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 25 | Updated for Linux 5.4 by Leopold Schabel <leo@nexantic.com> |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 26 | Updated for Linux 5.6 by Lorenz Brun <lorenz@nexantic.com> |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 27 | |
| 28 | Signed-off-by: Matthew Garrett <mjg59@coreos.com> |
| 29 | --- |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 30 | Documentation/x86/zero-page.rst | 1 + |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 31 | arch/x86/boot/boot.h | 10 ++++ |
| 32 | arch/x86/boot/cmdline.c | 37 ++++++++++++++ |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 33 | arch/x86/boot/compressed/cmdline.c | 10 ++++ |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 34 | arch/x86/boot/compressed/eboot.c | 3 ++ |
| 35 | arch/x86/boot/compressed/misc.c | 2 + |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 36 | arch/x86/boot/compressed/misc.h | 1 + |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 37 | arch/x86/boot/main.c | 3 ++ |
| 38 | arch/x86/include/uapi/asm/bootparam.h | 5 +- |
| 39 | arch/x86/kernel/setup.c | 16 +++--- |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 40 | .../firmware/efi/libstub/efi-stub-helper.c | 51 +++++++++++++++++-- |
| 41 | 11 files changed, 127 insertions(+), 12 deletions(-) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 42 | |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 43 | diff --git a/Documentation/x86/zero-page.rst b/Documentation/x86/zero-page.rst |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 44 | index f088f5881666..5339329af8d2 100644 |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 45 | --- a/Documentation/x86/zero-page.rst |
| 46 | +++ b/Documentation/x86/zero-page.rst |
| 47 | @@ -16,6 +16,7 @@ Offset/Size Proto Name Meaning |
| 48 | 000/040 ALL screen_info Text mode or frame buffer information |
| 49 | (struct screen_info) |
| 50 | 040/014 ALL apm_bios_info APM BIOS information (struct apm_bios_info) |
| 51 | +054/004 ALL setup_flags Flags passed from early kernel setup |
| 52 | 058/008 ALL tboot_addr Physical address of tboot shared page |
| 53 | 060/010 ALL ist_info Intel SpeedStep (IST) BIOS support information |
| 54 | (struct ist_info) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 55 | diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 56 | index ca866f1cca2e..a97502baba73 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 57 | --- a/arch/x86/boot/boot.h |
| 58 | +++ b/arch/x86/boot/boot.h |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 59 | @@ -269,6 +269,7 @@ void intcall(u8 int_no, const struct biosregs *ireg, struct biosregs *oreg); |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 60 | /* cmdline.c */ |
| 61 | int __cmdline_find_option(unsigned long cmdline_ptr, const char *option, char *buffer, int bufsize); |
| 62 | int __cmdline_find_option_bool(unsigned long cmdline_ptr, const char *option); |
| 63 | +int __cmdline_init(unsigned long cmdline_ptr, struct boot_params *params); |
| 64 | static inline int cmdline_find_option(const char *option, char *buffer, int bufsize) |
| 65 | { |
| 66 | unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr; |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 67 | @@ -289,6 +290,15 @@ static inline int cmdline_find_option_bool(const char *option) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 68 | return __cmdline_find_option_bool(cmd_line_ptr, option); |
| 69 | } |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 70 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 71 | +static inline int cmdline_init(void) |
| 72 | +{ |
| 73 | + unsigned long cmd_line_ptr = boot_params.hdr.cmd_line_ptr; |
| 74 | + |
| 75 | + if (cmd_line_ptr >= 0x100000) |
| 76 | + return -1; /* inaccessible */ |
| 77 | + |
| 78 | + return __cmdline_init(cmd_line_ptr, &boot_params); |
| 79 | +} |
| 80 | /* cpu.c, cpucheck.c */ |
| 81 | int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr); |
| 82 | int check_knl_erratum(void); |
| 83 | diff --git a/arch/x86/boot/cmdline.c b/arch/x86/boot/cmdline.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 84 | index 4ff01176c1cc..b5dfbe0b3209 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 85 | --- a/arch/x86/boot/cmdline.c |
| 86 | +++ b/arch/x86/boot/cmdline.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 87 | @@ -12,6 +12,10 @@ |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 88 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 89 | #include "boot.h" |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 90 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 91 | +#ifdef CONFIG_CMDLINE_BOOL |
| 92 | +static char builtin_cmdline[] = CONFIG_CMDLINE; |
| 93 | +#endif |
| 94 | + |
| 95 | static inline int myisspace(u8 c) |
| 96 | { |
| 97 | return c <= ' '; /* Close enough approximation */ |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 98 | @@ -154,3 +158,36 @@ int __cmdline_find_option_bool(unsigned long cmdline_ptr, const char *option) |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 99 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 100 | return 0; /* Buffer overrun */ |
| 101 | } |
| 102 | + |
| 103 | +int __cmdline_init(unsigned long cmdline_ptr, struct boot_params *params) |
| 104 | +{ |
| 105 | +#ifdef CONFIG_CMDLINE_BOOL |
| 106 | + addr_t cptr; |
| 107 | + int i = 0; |
| 108 | + |
| 109 | + if (!cmdline_ptr) |
| 110 | + return -1; /* No command line */ |
| 111 | + |
| 112 | + set_fs(cmdline_ptr >> 4); |
| 113 | + cptr = cmdline_ptr & 0xf; |
| 114 | + |
| 115 | +#ifndef CONFIG_CMDLINE_OVERRIDE |
| 116 | + while (cptr < 0x10000) { |
| 117 | + char c = rdfs8(cptr); |
| 118 | + if (!c) { |
| 119 | + wrfs8(' ', cptr++); |
| 120 | + break; |
| 121 | + } |
| 122 | + cptr++; |
| 123 | + } |
| 124 | +#endif /* !CONFIG_CMDLINE_OVERRIDE */ |
| 125 | + while (builtin_cmdline[i] && cptr < 0xffff) |
| 126 | + wrfs8(builtin_cmdline[i++], cptr++); |
| 127 | + |
| 128 | + wrfs8('\0', cptr); |
| 129 | + |
| 130 | + params->setup_flags |= SETUP_CMDLINE_APPENDED; |
| 131 | +#endif /* CONFIG_CMDLINE_BOOL */ |
| 132 | + |
| 133 | + return 0; |
| 134 | +} |
| 135 | diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/cmdline.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 136 | index f1add5d85da9..c69b27a5e76d 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 137 | --- a/arch/x86/boot/compressed/cmdline.c |
| 138 | +++ b/arch/x86/boot/compressed/cmdline.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 139 | @@ -11,6 +11,10 @@ static inline char rdfs8(addr_t addr) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 140 | { |
| 141 | return *((char *)(fs + addr)); |
| 142 | } |
| 143 | +static inline void wrfs8(u8 v, addr_t addr) |
| 144 | +{ |
| 145 | + *((char *)(fs + addr)) = v; |
| 146 | +} |
| 147 | #include "../cmdline.c" |
| 148 | unsigned long get_cmd_line_ptr(void) |
| 149 | { |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 150 | @@ -28,3 +32,9 @@ int cmdline_find_option_bool(const char *option) |
| 151 | { |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 152 | return __cmdline_find_option_bool(get_cmd_line_ptr(), option); |
| 153 | } |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 154 | +int cmdline_init(void) |
| 155 | +{ |
| 156 | + if (!(boot_params->setup_flags & SETUP_CMDLINE_APPENDED)) |
| 157 | + return __cmdline_init(get_cmd_line_ptr(), boot_params); |
| 158 | + return 0; |
| 159 | +} |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 160 | diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 161 | index 287393d725f0..6854fe44ac2c 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 162 | --- a/arch/x86/boot/compressed/eboot.c |
| 163 | +++ b/arch/x86/boot/compressed/eboot.c |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 164 | @@ -413,6 +413,9 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 165 | /* Fill in upper bits of command line address, NOP on 32 bit */ |
| 166 | boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 167 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 168 | +#ifdef CONFIG_CMDLINE_BOOL |
| 169 | + boot_params->setup_flags |= SETUP_CMDLINE_APPENDED; |
| 170 | +#endif |
| 171 | hdr->ramdisk_image = 0; |
| 172 | hdr->ramdisk_size = 0; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 173 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 174 | diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 175 | index 9652d5c2afda..05fd4372b630 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 176 | --- a/arch/x86/boot/compressed/misc.c |
| 177 | +++ b/arch/x86/boot/compressed/misc.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 178 | @@ -366,6 +366,8 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap, |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 179 | lines = boot_params->screen_info.orig_video_lines; |
| 180 | cols = boot_params->screen_info.orig_video_cols; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 181 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 182 | + cmdline_init(); |
| 183 | + |
| 184 | console_init(); |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 185 | |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 186 | /* |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 187 | diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 188 | index c8181392f70d..e2f962e7c0d4 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 189 | --- a/arch/x86/boot/compressed/misc.h |
| 190 | +++ b/arch/x86/boot/compressed/misc.h |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 191 | @@ -68,6 +68,7 @@ static inline void debug_puthex(const char *s) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 192 | /* cmdline.c */ |
| 193 | int cmdline_find_option(const char *option, char *buffer, int bufsize); |
| 194 | int cmdline_find_option_bool(const char *option); |
| 195 | +int cmdline_init(void); |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 196 | |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 197 | struct mem_vector { |
| 198 | unsigned long long start; |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 199 | diff --git a/arch/x86/boot/main.c b/arch/x86/boot/main.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 200 | index e3add857c2c9..e20e81253a7d 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 201 | --- a/arch/x86/boot/main.c |
| 202 | +++ b/arch/x86/boot/main.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 203 | @@ -136,6 +136,9 @@ void main(void) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 204 | /* First, copy the boot header into the "zeropage" */ |
| 205 | copy_boot_params(); |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 206 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 207 | + /* Handle built-in command line */ |
| 208 | + cmdline_init(); |
| 209 | + |
| 210 | /* Initialize the early-boot console */ |
| 211 | console_init(); |
| 212 | if (cmdline_find_option_bool("debug")) |
| 213 | diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 214 | index 8669c6bdbb84..e11a678d4afa 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 215 | --- a/arch/x86/include/uapi/asm/bootparam.h |
| 216 | +++ b/arch/x86/include/uapi/asm/bootparam.h |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 217 | @@ -37,6 +37,9 @@ |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 218 | #define XLF_5LEVEL (1<<5) |
| 219 | #define XLF_5LEVEL_ENABLED (1<<6) |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 220 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 221 | +/* setup_flags */ |
| 222 | +#define SETUP_CMDLINE_APPENDED (1<<0) |
| 223 | + |
| 224 | #ifndef __ASSEMBLY__ |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 225 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 226 | #include <linux/types.h> |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 227 | @@ -175,7 +178,7 @@ struct jailhouse_setup_data { |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 228 | struct boot_params { |
| 229 | struct screen_info screen_info; /* 0x000 */ |
| 230 | struct apm_bios_info apm_bios_info; /* 0x040 */ |
| 231 | - __u8 _pad2[4]; /* 0x054 */ |
| 232 | + __u32 setup_flags; /* 0x054 */ |
| 233 | __u64 tboot_addr; /* 0x058 */ |
| 234 | struct ist_info ist_info; /* 0x060 */ |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 235 | __u64 acpi_rsdp_addr; /* 0x070 */ |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 236 | diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 237 | index a74262c71484..6dcc6722ca73 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 238 | --- a/arch/x86/kernel/setup.c |
| 239 | +++ b/arch/x86/kernel/setup.c |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 240 | @@ -903,16 +903,18 @@ void __init setup_arch(char **cmdline_p) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 241 | bss_resource.end = __pa_symbol(__bss_stop)-1; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 242 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 243 | #ifdef CONFIG_CMDLINE_BOOL |
| 244 | + if (!(boot_params.setup_flags & SETUP_CMDLINE_APPENDED)) { |
| 245 | #ifdef CONFIG_CMDLINE_OVERRIDE |
| 246 | - strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
| 247 | -#else |
| 248 | - if (builtin_cmdline[0]) { |
| 249 | - /* append boot loader cmdline to builtin */ |
| 250 | - strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); |
| 251 | - strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); |
| 252 | strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
| 253 | - } |
| 254 | +#else |
| 255 | + if (builtin_cmdline[0]) { |
| 256 | + /* append boot loader cmdline to builtin */ |
| 257 | + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE); |
| 258 | + strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE); |
| 259 | + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE); |
| 260 | + } |
| 261 | #endif |
| 262 | + } |
| 263 | #endif |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 264 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 265 | strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE); |
| 266 | diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 267 | index 74ddfb496140..5b066819befb 100644 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 268 | --- a/drivers/firmware/efi/libstub/efi-stub-helper.c |
| 269 | +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c |
Leopold Schabel | f1d34d3 | 2020-01-07 14:15:44 +0100 | [diff] [blame] | 270 | @@ -9,9 +9,14 @@ |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 271 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 272 | #include <linux/efi.h> |
| 273 | #include <asm/efi.h> |
| 274 | +#include <asm/setup.h> |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 275 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 276 | #include "efistub.h" |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 277 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 278 | +#ifdef CONFIG_CMDLINE_BOOL |
| 279 | +static char builtin_cmdline[] = CONFIG_CMDLINE; |
| 280 | +#endif |
| 281 | + |
| 282 | /* |
| 283 | * Some firmware implementations have problems reading files in one go. |
| 284 | * A read chunk size of 1MB seems to work for most platforms. |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 285 | @@ -814,6 +819,20 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n) |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 286 | #ifndef MAX_CMDLINE_ADDRESS |
| 287 | #define MAX_CMDLINE_ADDRESS ULONG_MAX |
| 288 | #endif |
| 289 | +static size_t efi_strlcat(char *dest, const char *src, size_t count) |
| 290 | +{ |
| 291 | + size_t dsize = strlen(dest); |
| 292 | + size_t len = strlen(src); |
| 293 | + size_t res = dsize + len; |
| 294 | + |
| 295 | + dest += dsize; |
| 296 | + count -= dsize; |
| 297 | + if (len >= count) |
| 298 | + len = count-1; |
| 299 | + memcpy(dest, src, len); |
| 300 | + dest[len] = 0; |
| 301 | + return res; |
| 302 | +} |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 303 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 304 | /* |
| 305 | * Convert the unicode UEFI command line to ASCII to pass to kernel. |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 306 | @@ -823,14 +842,16 @@ static u8 *efi_utf16_to_utf8(u8 *dst, const u16 *src, int n) |
| 307 | char *efi_convert_cmdline(efi_loaded_image_t *image, |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 308 | int *cmd_line_len) |
| 309 | { |
| 310 | + unsigned long cmdline_addr = 0; |
| 311 | + int i; |
| 312 | + efi_status_t status; |
| 313 | +#ifndef CONFIG_CMDLINE_OVERRIDE |
| 314 | const u16 *s2; |
| 315 | u8 *s1 = NULL; |
| 316 | - unsigned long cmdline_addr = 0; |
| 317 | int load_options_chars = image->load_options_size / 2; /* UTF-16 */ |
| 318 | const u16 *options = image->load_options; |
| 319 | int options_bytes = 0; /* UTF-8 bytes */ |
| 320 | int options_chars = 0; /* UTF-16 chars */ |
| 321 | - efi_status_t status; |
| 322 | u16 zero = 0; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 323 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 324 | if (options) { |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 325 | @@ -849,8 +870,13 @@ char *efi_convert_cmdline(efi_loaded_image_t *image, |
| 326 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 327 | options_bytes++; /* NUL termination */ |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 328 | |
| 329 | - status = efi_high_alloc(options_bytes, 0, &cmdline_addr, |
| 330 | - MAX_CMDLINE_ADDRESS); |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 331 | +#ifdef CONFIG_CMDLINE_BOOL |
| 332 | + /* Add length of the built-in command line, plus a space */ |
| 333 | + options_bytes += strlen(builtin_cmdline); |
| 334 | + options_bytes++; |
| 335 | +#endif |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 336 | + status = efi_high_alloc(options_bytes, 0, |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 337 | + &cmdline_addr, MAX_CMDLINE_ADDRESS); |
| 338 | if (status != EFI_SUCCESS) |
| 339 | return NULL; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 340 | |
| 341 | @@ -860,7 +886,24 @@ char *efi_convert_cmdline(efi_loaded_image_t *image, |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 342 | s1 = efi_utf16_to_utf8(s1, s2, options_chars); |
| 343 | *s1 = '\0'; |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 344 | |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 345 | +#ifdef CONFIG_CMDLINE_BOOL |
| 346 | + efi_strlcat((char *)cmdline_addr, " ", COMMAND_LINE_SIZE); |
| 347 | + efi_strlcat((char *)cmdline_addr, builtin_cmdline, COMMAND_LINE_SIZE); |
| 348 | +#endif |
| 349 | *cmd_line_len = options_bytes; |
| 350 | +#else /* CONFIG_CMDLINE_OVERRIDE */ |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 351 | + status = efi_high_alloc(strlen(builtin_cmdline), 0, |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 352 | + &cmdline_addr, MAX_CMDLINE_ADDRESS); |
| 353 | + if (status != EFI_SUCCESS) |
| 354 | + return NULL; |
| 355 | + while (builtin_cmdline[i] && i < COMMAND_LINE_SIZE) { |
| 356 | + ((char *)cmdline_addr)[i] = builtin_cmdline[i]; |
| 357 | + i++; |
| 358 | + } |
| 359 | + ((char *)cmdline_addr)[i] = '\0'; |
| 360 | + *cmd_line_len = strlen(builtin_cmdline); |
| 361 | +#endif /* CONFIG_CMDLINE_OVERRIDE */ |
| 362 | + |
| 363 | return (char *)cmdline_addr; |
| 364 | } |
Lorenz Brun | fd16651 | 2020-04-01 17:29:45 +0200 | [diff] [blame] | 365 | |
| 366 | -- |
| 367 | 2.20.1 |
Lorenz Brun | 0bcaaee | 2019-11-06 12:42:39 +0100 | [diff] [blame] | 368 | |