Skip to content

Commit 516cbf3

Browse files
Tim BirdIngo Molnar
authored andcommitted
x86, bootup: add built-in kernel command line for x86 (v2)
Allow x86 to support a built-in kernel command line. The built-in command line can override the one provided by the boot loader, for those cases where the boot loader is broken or it is difficult to change the command line in the the boot loader. H. Peter Anvin wrote: > Ingo Molnar wrote: >> Best would be to make it really apparent in the code that nothing >> changes if this config option is not set. Preferably there should be >> no extra code at all in that case. >> > > I would like to see this: [...Nested ifdefs...] OK. This version changes absolutely nothing if CONFIG_CMDLINE_BOOL is not set (the default). Also, no space is appended even when CONFIG_CMDLINE_BOOL is set, but the builtin string is empty. This is less sloppy all the way around, IMHO. Note that I use the same option names as on other arches for this feature. [ [email protected]: build fix ] Signed-off-by: Tim Bird <[email protected]> Cc: Matt Mackall <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent b635ace commit 516cbf3

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

arch/x86/Kconfig

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,51 @@ config COMPAT_VDSO
13921392

13931393
If unsure, say Y.
13941394

1395+
config CMDLINE_BOOL
1396+
bool "Built-in kernel command line"
1397+
default n
1398+
help
1399+
Allow for specifying boot arguments to the kernel at
1400+
build time. On some systems (e.g. embedded ones), it is
1401+
necessary or convenient to provide some or all of the
1402+
kernel boot arguments with the kernel itself (that is,
1403+
to not rely on the boot loader to provide them.)
1404+
1405+
To compile command line arguments into the kernel,
1406+
set this option to 'Y', then fill in the
1407+
the boot arguments in CONFIG_CMDLINE.
1408+
1409+
Systems with fully functional boot loaders (i.e. non-embedded)
1410+
should leave this option set to 'N'.
1411+
1412+
config CMDLINE
1413+
string "Built-in kernel command string"
1414+
depends on CMDLINE_BOOL
1415+
default ""
1416+
help
1417+
Enter arguments here that should be compiled into the kernel
1418+
image and used at boot time. If the boot loader provides a
1419+
command line at boot time, it is appended to this string to
1420+
form the full kernel command line, when the system boots.
1421+
1422+
However, you can use the CONFIG_CMDLINE_OVERRIDE option to
1423+
change this behavior.
1424+
1425+
In most cases, the command line (whether built-in or provided
1426+
by the boot loader) should specify the device for the root
1427+
file system.
1428+
1429+
config CMDLINE_OVERRIDE
1430+
bool "Built-in command line overrides boot loader arguments"
1431+
default n
1432+
depends on CMDLINE_BOOL
1433+
help
1434+
Set this option to 'Y' to have the kernel ignore the boot loader
1435+
command line, and use ONLY the built-in command line.
1436+
1437+
This is used to work around broken boot loaders. This should
1438+
be set to 'N' under normal conditions.
1439+
13951440
endmenu
13961441

13971442
config ARCH_ENABLE_MEMORY_HOTPLUG

arch/x86/kernel/setup.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ unsigned long saved_video_mode;
223223
#define RAMDISK_LOAD_FLAG 0x4000
224224

225225
static char __initdata command_line[COMMAND_LINE_SIZE];
226+
#ifdef CONFIG_CMDLINE_BOOL
227+
static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
228+
#endif
226229

227230
#if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
228231
struct edd edd;
@@ -673,6 +676,19 @@ void __init setup_arch(char **cmdline_p)
673676
bss_resource.start = virt_to_phys(&__bss_start);
674677
bss_resource.end = virt_to_phys(&__bss_stop)-1;
675678

679+
#ifdef CONFIG_CMDLINE_BOOL
680+
#ifdef CONFIG_CMDLINE_OVERRIDE
681+
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
682+
#else
683+
if (builtin_cmdline[0]) {
684+
/* append boot loader cmdline to builtin */
685+
strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
686+
strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
687+
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
688+
}
689+
#endif
690+
#endif
691+
676692
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
677693
*cmdline_p = command_line;
678694

0 commit comments

Comments
 (0)