bootconfig: Cleanup and reorder the init parameter from bootconfig
Subsystems (2)
Masami Hiramatsu
maintainerv2 cover bootconfig: Cleanup and reorder the init parameter from bootconfig
Hi,
Here are the 2nd version of the patches to update the bootconfig. The 1st one is for bootconfig memory cleanup when exiting init stage. The 2nd one and 3rd one are for reordering the init parameters from bootconfig.
Since the current kernel concatenate the kernel cmdline and the bootconfig parameters as below.
[bootconfig kernel params][cmdline] -- [init cmdline][bootconfig init params]
This is bit odd because for the kernel parameters, user passed cmdline can override the previous (bootconfig) one, but for the init cmdline, bootconfig may override the parameter.
Thus, this series invert the order as the following.
[bootconfig kernel params][cmdline] -- [bootconfig init params][init cmdline]
The 3rd patch is adding how to use the bootconfig for passing kernel and init parameters.
Changes in v2:
- introduce exit_boot_config() wrapper for !CONFIG_BOOT_CONFIG.
Thank you,
---
Masami Hiramatsu (3):
init: bootconfig: Remove all bootconfig data when the init memory is removed init/bootconfig: Reorder init parameter from bootconfig and cmdline
docs: bootconfig: Add how to use bootconfig for kernel parameters
Documentation/admin-guide/bootconfig.rst | 39 +++++++++++++++++++++++++++++- init/main.c | 37 ++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 12 deletions(-)
--
Masami Hiramatsu (Linaro) <[email protected]>
Masami Hiramatsu
maintainerPATCH v2 1/3 init: bootconfig: Remove all bootconfig data when the init memory is removed
Since the bootconfig is used only in the init functions, it doesn't need to keep the data after boot. Free it when the init memory is removed.
---
Changes in v2:
- introduce exit_boot_config() wrapper for !CONFIG_BOOT_CONFIG
--- init/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
init/main.c +12 -2
@@ -468,7 +468,12 @@ static void __init setup_boot_config(void) return; } -#else +static void __init exit_boot_config (void ) +{ +xbc_destroy_all (); +} + +#else /* !CONFIG_BOOT_CONFIG */ static void __init setup_boot_config (void ) {
@@ -481,7 +486,11 @@ static int __init warn_bootconfig(char *str)pr_warn ("WARNING: 'bootconfig' found on the kernel command line but CONFIG_BOOT_CONFIG is not set.\n" ); return 0; } -#endif + +#define exit_boot_config () do {} while (0) + +#endif /* CONFIG_BOOT_CONFIG */ +early_param ("bootconfig" , warn_bootconfig);/* Change NUL term back to "=", to make "param" the whole string. */
@@ -1493,6 +1502,7 @@ static int __ref kernel_init(void *unused)kprobe_free_init_mem ();ftrace_free_init_mem ();kgdb_free_init_mem (); +exit_boot_config ();free_initmem ();mark_readonly ();
Masami Hiramatsu
maintainerPATCH v2 2/3 init/bootconfig: Reorder init parameter from bootconfig and cmdline
In reply to Masami HiramatsuReorder the init parameters from bootconfig and kernel cmdline so that the kernel cmdline always be the last part of the parameters as below.
" -- "[bootconfig init params][cmdline init params]
This change will help us to prevent that bootconfig init params overwrite the init params which user gives in the command line.
--- init/main.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
init/main.c +14 -9
@@ -153,10 +153,10 @@ static char *extra_init_args;#ifdef CONFIG_BOOT_CONFIG /* Is bootconfig on command line? */ static bool bootconfig_found; -static bool initargs_found; +static size_t initargs_offs;#else # define bootconfig_found false -# define initargs_found false +# define initargs_offs 0#endif static char *execute_command;
@@ -422,9 +422,9 @@ static void __init setup_boot_config(void)if (IS_ERR (err) || !bootconfig_found)return ; -/* parse_args() stops at '--' and returns an address */ +/* parse_args() stops at the next param of '--' and returns an address */ if (err) - initargs_found = true; + initargs_offs = err - tmp_cmdline;if (!data) {pr_err ("'bootconfig' found on command line, but no bootconfig found\n" );
@@ -655,16 +655,21 @@ static void __init setup_command_line(char *command_line)* Append supplemental init boot args to saved_command_line * so that user can check what command line options passed * to init. +* The order should always be +* " -- "[bootconfig init-param][cmdline init-param] */ - len =strlen (saved_command_line); -if (initargs_found) { - saved_command_line[len++] =' ' ; +if (initargs_offs) { + len = xlen + initargs_offs; +strcpy (saved_command_line + len, extra_init_args); + len += ilen -4 ;/* strlen(extra_init_args) */ +strcpy (saved_command_line + len, + boot_command_line + initargs_offs -1 ); }else { + len =strlen (saved_command_line);strcpy (saved_command_line + len," -- " ); len +=4 ; +strcpy (saved_command_line + len, extra_init_args); } - -strcpy (saved_command_line + len, extra_init_args); } }
Masami Hiramatsu
maintainerPATCH v2 3/3 docs: bootconfig: Add how to use bootconfig for kernel parameters
In reply to Masami HiramatsuAdd a section to describe how to use the bootconfig for specifying kernel and init parameters. This is an important section because it is the reason why this document is under the admin-guide.
--- Documentation/admin-guide/bootconfig.rst | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
Documentation/admin-guide/bootconfig.rst +38 -1
@@ -178,7 +178,7 @@ update the boot loader and the kernel image itself as long as the boot loader passes the correct initrd file size. If by any chance, the boot loader passes a longer size, the kernel fails to find the bootconfig data. -To do this operation, Linux kernel provides "bootconfig" command under +To do this operation, Linux kernel provides ``bootconfig`` command under tools/bootconfig, which allows admin to apply or delete the config file to/from initrd image. You can build it by the following command::
@@ -196,6 +196,43 @@ To remove the config from the image, you can use -d option as below:: Then add "bootconfig" on the normal kernel command line to tell the kernel to look for the bootconfig at the end of the initrd file. + +Kernel parameters via Boot Config +================================= + +In addition to the kernel command line, the boot config can be used for +passing the kernel parameters. All the key-value pairs under ``kernel`` +key will be passed to kernel cmdline directly. Moreover, the key-value +pairs under ``init`` will be passed to init process via the cmdline. +The parameters are concatinated with user-given kernel cmdline string +as the following order, so that the command line parameter can override +bootconfig parameters (this depends on how the subsystem handles parameters +but in general, earlier parameter will be overwritten by later one.):: + + [bootconfig params][cmdline params] -- [bootconfig init params][cmdline init params] + +Here is an example of the bootconfig file for kernel/init parameters.:: + + kernel { + root = 01234567-89ab-cdef-0123-456789abcd + } + init { + splash + } + +This will be copied into the kernel cmdline string as the following:: + + root="01234567-89ab-cdef-0123-456789abcd" -- splash + +If user gives some other command line like,:: + + ro bootconfig -- quiet + +The final kernel cmdline will be the following:: + + root="01234567-89ab-cdef-0123-456789abcd" ro bootconfig -- splash quiet + + Config File Limitation ======================