[PATCH v3 2/2] x86: Parse CONFIG_CMDLINE in compressed kernel

From: Baskov Evgeniy
Date: Thu May 05 2022 - 06:33:00 EST


CONFIG_CMDLINE, CONFIG_CMDLINE_BOOL, and CONFIG_CMDLINE_OVERRIDE were
ignored during options lookup in compressed kernel.

Parse CONFIG_CMDLINE-related options correctly in compressed kernel
code.

cmd_line_ptr_init is explicitly placed in .data section since it is
used and expected to be equal to zero before .bss section is cleared.

Signed-off-by: Baskov Evgeniy <baskov@xxxxxxxxx>

diff --git a/arch/x86/boot/compressed/cmdline.c b/arch/x86/boot/compressed/cmdline.c
index f1add5d85da9..261f53ad395a 100644
--- a/arch/x86/boot/compressed/cmdline.c
+++ b/arch/x86/boot/compressed/cmdline.c
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
#include "misc.h"

+#define COMMAND_LINE_SIZE 2048
+
static unsigned long fs;
static inline void set_fs(unsigned long seg)
{
@@ -12,12 +14,32 @@ static inline char rdfs8(addr_t addr)
return *((char *)(fs + addr));
}
#include "../cmdline.c"
+
+#ifdef CONFIG_CMDLINE_BOOL
+static char builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
+static bool builtin_cmdline_init __section(".data");
+#endif
+
unsigned long get_cmd_line_ptr(void)
{
unsigned long cmd_line_ptr = boot_params->hdr.cmd_line_ptr;
-
cmd_line_ptr |= (u64)boot_params->ext_cmd_line_ptr << 32;

+#ifdef CONFIG_CMDLINE_BOOL
+ if (!builtin_cmdline_init) {
+ if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) {
+ strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
+ strlcat(builtin_cmdline,
+ (char *)cmd_line_ptr,
+ COMMAND_LINE_SIZE);
+ }
+
+ builtin_cmdline_init = 1;
+ }
+
+ cmd_line_ptr = (unsigned long)builtin_cmdline;
+#endif
+
return cmd_line_ptr;
}
int cmdline_find_option(const char *option, char *buffer, int bufsize)
--
2.36.0