default kernel cmdline/bootargs
最近再想一個問題,如果編譯Kernel的時候預設有加上cmdline了,那Bootloader再傳bootargs的時候,會怎麼樣?
找到的網頁可能是參考arm的,說預設的會直接被覆蓋掉,但這無法解釋x86平台的行為。
所以去找了一下kernel的code,發現會直接把bootloader傳過來的 append 到 預設的cmdline去,所以如果有相同的argument的話,應該default的會先拿來用吧。
arch/x86/kernel/setup.c
static char __initdata command_line[COMMAND_LINE_SIZE];
#ifdef CONFIG_CMDLINE_BOOL
static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
#endif
#ifdef CONFIG_CMDLINE_BOOL
#ifdef CONFIG_CMDLINE_OVERRIDE
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
#else
if (builtin_cmdline[0]) {
/* append boot loader cmdline to builtin */
strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
}
#endif
#endif
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
找到的網頁可能是參考arm的,說預設的會直接被覆蓋掉,但這無法解釋x86平台的行為。
所以去找了一下kernel的code,發現會直接把bootloader傳過來的 append 到 預設的cmdline去,所以如果有相同的argument的話,應該default的會先拿來用吧。
arch/x86/kernel/setup.c
static char __initdata command_line[COMMAND_LINE_SIZE];
#ifdef CONFIG_CMDLINE_BOOL
static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
#endif
#ifdef CONFIG_CMDLINE_BOOL
#ifdef CONFIG_CMDLINE_OVERRIDE
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
#else
if (builtin_cmdline[0]) {
/* append boot loader cmdline to builtin */
strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
}
#endif
#endif
strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
*cmdline_p = command_line;
留言