bootm: Support substitions in bootargs and add tests
Subsystems (2)
cover bootm: Support substitions in bootargs and add tests
This series adds tests to the fixup_silent-linux() function and extends the 'zimage' command to use it.
It also adds a new string-substition feature to allow bootargs to be a template, rather than having to build it up piece by piece with information obtained in a build script.
It also updates zimage to use the same command-line processing.
With these additions it is possible to boot Chrome OS from a U-Boot script on most Chromebooks.
Simon Glass (11):
env: Allow returning errors from hdelete_r()
bootm: Add tests for fixup_silent_linux()
bootm: Update fixup_silent_linux() to return an error
bootm: Rename fixup_silent_linux()
bootm: Add a bool parameter to bootm_process_cmdline_env()
bootm: Use size rather than length for CONSOLE_ARG
bootm: Split out bootargs environment reading / writing
bootm: Update bootm_process_cmdline_env() to use flags
bootm: Allow updating the bootargs in a buffer
x86: zimage: Add silent-console processing
bootm: Support string substitution in bootargs
README | 16 +++ arch/Kconfig | 2 + arch/x86/lib/zimage.c | 14 +++ cmd/nvedit.c | 6 +- common/Kconfig.boot | 20 ++++ common/bootm.c | 206 +++++++++++++++++++++++++++++------ include/bootm.h | 40 +++++++ include/search.h | 11 +- include/test/suites.h | 1 + lib/hashtable.c | 12 +-- test/Makefile | 1 + test/bootm.c | 243 ++++++++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 1 + test/env/hashtable.c | 2 +- 14 files changed, 534 insertions(+), 41 deletions(-) create mode 100644 test/bootm.c
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 1/11 env: Allow returning errors from hdelete_r()
At present this function returns 1 on success and 0 on failure. But in the latter case it provides no indication of what went wrong.
If an attempt is made to delete a non-existent variable, the caller may want to ignore this error. This happens when setting a non-existent variable to "", for example.
Update the function to return 0 on success and a useful error code on failure. Add a function comment too.
Make sure that env_set() does not return an error if it is deleting a variable that doesn't exist. We could update env_set() to return useful error numbers also, but that is beyond the scope of this change.
wip
---
cmd/nvedit.c | 6 ++++-- include/search.h | 11 ++++++++++- lib/hashtable.c | 12 ++++++------ test/env/hashtable.c | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-)
cmd/nvedit.c +4 -2
@@ -266,7 +266,9 @@ static int _do_env_set(int flag, int argc, char *const argv[], int env_flag)/* Delete only ? */ if (argc <3 || argv[2 ] ==NULL ) {int rc =hdelete_r (name, &env_htab, env_flag); -return !rc; + +/* If the variable didn't exist, don't report an error */ +return rc && rc != -ENOENT ?1 :0 ; }/*
@@ -895,7 +897,7 @@ static int do_env_delete(struct cmd_tbl *cmdtp, int flag,while (--argc >0 ) {char *name = *++argv; -if (!hdelete_r (name, &env_htab, env_flag)) +if (hdelete_r (name, &env_htab, env_flag)) ret =1 ; }
include/search.h +10 -1
@@ -80,7 +80,16 @@ int hsearch_r(struct env_entry item, enum env_action action,int hmatch_r (const char *match,int last_idx,struct env_entry **retval,struct hsearch_data *htab); -/* Search and delete entry matching "key" in internal hash table. */ +/** +* hdelete_r() - Search and delete entry in internal hash table +* +* @key: Name of entry to delete +* @htab: Hash table +* @flag: Flags to use (H_...) +* @return 0 on success, -ENOENT if not found, -EPERM if the hash table callback +* rejected changing the variable, -EINVAL if the hash table refused to +* delete the variable +*/ int hdelete_r (const char *key,struct hsearch_data *htab,int flag); ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
lib/hashtable.c +6 -6
@@ -472,7 +472,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab, int flag) idx =hsearch_r (e,ENV_FIND , &ep, htab,0 );if (idx ==0 ) {__set_errno (ESRCH ); -return 0 ;/* not found */ +return -ENOENT ;/* not found */ }/* Check for permission */
@@ -481,7 +481,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab, int flag)debug ("change_ok() rejected deleting variable " "%s, skipping it!\n" , key);__set_errno (EPERM ); -return 0 ; +return -EPERM ; }/* If there is a callback, call it */
@@ -490,12 +490,12 @@ int hdelete_r(const char *key, struct hsearch_data *htab, int flag)debug ("callback() rejected deleting variable " "%s, skipping it!\n" , key);__set_errno (EINVAL ); -return 0 ; +return -EINVAL ; }_hdelete (key, htab, ep, idx); -return 1 ; +return 0 ; }#if !(defined(CONFIG_SPL_BUILD ) && !defined(CONFIG_SPL_SAVEENV ))
@@ -917,7 +917,7 @@ int himport_r(struct hsearch_data *htab,if (!drop_var_from_set (name, nvars, localvars))continue ; -if (hdelete_r (name, htab, flag) ==0 ) +if (hdelete_r (name, htab, flag))debug ("DELETE ERROR ##############################\n" );continue ;
@@ -979,7 +979,7 @@ int himport_r(struct hsearch_data *htab,* b) if the variable was not present in current env, we notify * it might be a typo */ -if (hdelete_r (localvars[i], htab, flag) ==0 ) +if (hdelete_r (localvars[i], htab, flag))printf ("WARNING: '%s' neither in running nor in imported env!\n" , localvars[i]);else printf ("WARNING: '%s' not in imported env, deleting it!\n" , localvars[i]);
test/env/hashtable.c +1 -1
@@ -80,7 +80,7 @@ static int htab_create_delete(struct unit_test_state *uts,ut_asserteq_str (key, ritem->key);ut_asserteq_str (key, ritem->data); -ut_asserteq (1 ,hdelete_r (key, htab,0 )); +ut_asserteq (0 ,hdelete_r (key, htab,0 )); }return 0 ;
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 2/11 bootm: Add tests for fixup_silent_linux()
In reply to Simon GlassThis function currently has no tests. Export it so that we can implement a simple test on sandbox. Use IS_ENABLED() to remove the unused code, instead #ifdef.
---
arch/Kconfig | 1 + common/bootm.c | 14 +++++----- include/bootm.h | 3 +++ include/test/suites.h | 1 + test/Makefile | 1 + test/bootm.c | 59 +++++++++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 1 + 7 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 test/bootm.c
arch/Kconfig +1 -0
@@ -140,6 +140,7 @@ config SANDBOX imply ACPI_PMC_SANDBOX imply CMD_PMC imply CMD_CLONE + imply SILENT_CONSOLE config SH bool "SuperH architecture"
common/bootm.c +7 -7
@@ -463,18 +463,21 @@ ulong bootm_disable_interrupts(void)return iflag; } -#if defined(CONFIG_SILENT_CONSOLE ) && !defined(CONFIG_SILENT_U_BOOT_ONLY ) -#define CONSOLE_ARG "console="#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) -static void fixup_silent_linux (void ) +void fixup_silent_linux (void ) {char *buf;const char *env_val; -char *cmdline =env_get ("bootargs" ); +char *cmdline;int want_silent; +if (!IS_ENABLED (CONFIG_SILENT_CONSOLE ) && + !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY )) +return ; + cmdline =env_get ("bootargs" ); +/* * Only fix cmdline when requested. The environment variable can be: *
@@ -521,7 +524,6 @@ static void fixup_silent_linux(void)debug ("after silent fix-up: %s\n" , env_val);free (buf); } -#endif /* CONFIG_SILENT_CONSOLE */ /** * Execute selected states of the bootm command.
@@ -625,10 +627,8 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,if (!ret && (states &BOOTM_STATE_OS_BD_T )) ret =boot_fn (BOOTM_STATE_OS_BD_T , argc, argv, images);if (!ret && (states &BOOTM_STATE_OS_PREP )) { -#if defined(CONFIG_SILENT_CONSOLE ) && !defined(CONFIG_SILENT_U_BOOT_ONLY )if (images->os.os ==IH_OS_LINUX )fixup_silent_linux (); -#endif ret =boot_fn (BOOTM_STATE_OS_PREP , argc, argv, images); }
include/bootm.h +3 -0
@@ -85,4 +85,7 @@ void arch_preboot_os(void);*/ void board_preboot_os (void ); +/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */ +void fixup_silent_linux (void ); +#endif
include/test/suites.h +1 -0
@@ -26,6 +26,7 @@ int cmd_ut_category(const char *name, const char *prefix, struct unit_test *tests, int n_ents, int argc, char *const argv[]); +int do_ut_bootm (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]);int do_ut_bloblist (struct cmd_tbl *cmdtp,int flag,int argc,char *const argv[]); int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc,
test/Makefile +1 -0
@@ -3,6 +3,7 @@ # (C) Copyright 2012 The Chromium Authors obj-$(CONFIG_SANDBOX) += bloblist.o +obj-$(CONFIG_SANDBOX) += bootm.o obj-$(CONFIG_CMDLINE) += cmd/ obj-$(CONFIG_UNIT_TEST) += cmd_ut.o obj-$(CONFIG_UNIT_TEST) += ut.o
test/bootm.c new file +59 -0
59 lines not on this page · raw message
test/cmd_ut.c +1 -0
@@ -86,6 +86,7 @@ static struct cmd_tbl cmd_ut_sub[] = { "", ""), U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist, "", ""), + U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", ""), U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""),#endif
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 3/11 bootm: Update fixup_silent_linux() to return an error
In reply to Simon GlassAt present this function fails silently on error. Update it to produce an error code. Report this error to the user and abort the boot, since it likely will prevent a successful start.
No tests are added at this stage, since additional refactoring is taking place in subsequent patches.
---
common/bootm.c | 22 +++++++++++++++------- include/bootm.h | 11 +++++++++-- test/bootm.c | 10 +++++----- 3 files changed, 29 insertions(+), 14 deletions(-)
common/bootm.c +15 -7
@@ -466,7 +466,7 @@ ulong bootm_disable_interrupts(void)#define CONSOLE_ARG "console="#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) -void fixup_silent_linux (void ) +int fixup_silent_linux (void ) {char *buf;const char *env_val;
@@ -475,7 +475,7 @@ void fixup_silent_linux(void)if (!IS_ENABLED (CONFIG_SILENT_CONSOLE ) && !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY )) -return ; +return 0 ; cmdline =env_get ("bootargs" );/*
@@ -487,9 +487,9 @@ void fixup_silent_linux(void)*/ want_silent =env_get_yesno ("silent_linux" );if (want_silent ==0 ) -return ; +return 0 ;else if (want_silent ==-1 && !(gd->flags &GD_FLG_SILENT )) -return ; +return 0 ;debug ("before silent fix-up: %s\n" , cmdline);if (cmdline && (cmdline[0 ] !='\0' )) {
@@ -499,7 +499,7 @@ void fixup_silent_linux(void) buf =malloc (strlen (cmdline) +1 +CONSOLE_ARG_LEN +1 );if (!buf) {debug ("%s: out of memory\n" , __func__); -return ; +return -ENOSPC ; }if (start) {
@@ -523,6 +523,8 @@ void fixup_silent_linux(void)env_set ("bootargs" , env_val);debug ("after silent fix-up: %s\n" , env_val);free (buf); + +return 0 ; }/**
@@ -627,8 +629,14 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,if (!ret && (states &BOOTM_STATE_OS_BD_T )) ret =boot_fn (BOOTM_STATE_OS_BD_T , argc, argv, images);if (!ret && (states &BOOTM_STATE_OS_PREP )) { -if (images->os.os ==IH_OS_LINUX ) -fixup_silent_linux (); +if (images->os.os ==IH_OS_LINUX ) { + ret =fixup_silent_linux (); +if (ret) { +printf ("Cmdline setup failed (err=%d)\n" , ret); + ret =CMD_RET_FAILURE ; + goto err; + } + } ret =boot_fn (BOOTM_STATE_OS_PREP , argc, argv, images); }
include/bootm.h +9 -2
@@ -85,7 +85,14 @@ void arch_preboot_os(void);*/ void board_preboot_os (void ); -/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */ -void fixup_silent_linux (void ); +/* +* fixup_silent_linux() - Process fix-ups for the command line +* +* Updates the 'bootargs' envvar as required. This handles making Linux boot +* silently if requested ('silent_linux' envvar) +* +* @return 0 if OK, -ENOMEM if out of memory +*/ +int fixup_silent_linux (void );#endif
test/bootm.c +5 -5
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state *uts)/* 'silent_linux' not set should do nothing */ env_set ("silent_linux" ,NULL );env_set ("bootargs" ,CONSOLE_STR ); -fixup_silent_linux (); +ut_assertok (fixup_silent_linux ());ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));env_set ("bootargs" ,NULL ); -fixup_silent_linux (); +ut_assertok (fixup_silent_linux ());ut_assertnull (env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"no" ));env_set ("bootargs" ,CONSOLE_STR ); -fixup_silent_linux (); +ut_assertok (fixup_silent_linux ());ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"yes" ));env_set ("bootargs" ,CONSOLE_STR ); -fixup_silent_linux (); +ut_assertok (fixup_silent_linux ());ut_asserteq_str ("console=" ,env_get ("bootargs" ));/* Empty buffer should still add the string */ env_set ("bootargs" ,NULL ); -fixup_silent_linux (); +ut_assertok (fixup_silent_linux ());ut_asserteq_str ("console=" ,env_get ("bootargs" ));return 0 ;
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 4/11 bootm: Rename fixup_silent_linux()
In reply to Simon GlassWe want to add more processing to this function. Before doing so, rename it to bootm_process_cmdline_env(), which is more generic.
---
common/bootm.c | 4 ++-- include/bootm.h | 4 ++-- test/bootm.c | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-)
common/bootm.c +2 -2
@@ -466,7 +466,7 @@ ulong bootm_disable_interrupts(void)#define CONSOLE_ARG "console="#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) -int fixup_silent_linux (void ) +int bootm_process_cmdline_env (void ) {char *buf;const char *env_val;
@@ -630,7 +630,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, ret =boot_fn (BOOTM_STATE_OS_BD_T , argc, argv, images);if (!ret && (states &BOOTM_STATE_OS_PREP )) {if (images->os.os ==IH_OS_LINUX ) { - ret =fixup_silent_linux (); + ret =bootm_process_cmdline_env ();if (ret) {printf ("Cmdline setup failed (err=%d)\n" , ret); ret =CMD_RET_FAILURE ;
include/bootm.h +2 -2
@@ -86,13 +86,13 @@ void arch_preboot_os(void);void board_preboot_os (void );/* -* fixup_silent_linux() - Process fix-ups for the command line +* bootm_process_cmdline_env() - Process fix-ups for the command line * * Updates the 'bootargs' envvar as required. This handles making Linux boot * silently if requested ('silent_linux' envvar) * * @return 0 if OK, -ENOMEM if out of memory */ -int fixup_silent_linux (void ); +int bootm_process_cmdline_env (void );#endif
test/bootm.c +5 -5
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state *uts)/* 'silent_linux' not set should do nothing */ env_set ("silent_linux" ,NULL );env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (fixup_silent_linux ()); +ut_assertok (bootm_process_cmdline_env ());ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));env_set ("bootargs" ,NULL ); -ut_assertok (fixup_silent_linux ()); +ut_assertok (bootm_process_cmdline_env ());ut_assertnull (env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"no" ));env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (fixup_silent_linux ()); +ut_assertok (bootm_process_cmdline_env ());ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"yes" ));env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (fixup_silent_linux ()); +ut_assertok (bootm_process_cmdline_env ());ut_asserteq_str ("console=" ,env_get ("bootargs" ));/* Empty buffer should still add the string */ env_set ("bootargs" ,NULL ); -ut_assertok (fixup_silent_linux ()); +ut_assertok (bootm_process_cmdline_env ());ut_asserteq_str ("console=" ,env_get ("bootargs" ));return 0 ;
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 5/11 bootm: Add a bool parameter to bootm_process_cmdline_env()
In reply to Simon GlassThis function will soon do more than just handle the 'silent linux' feature. As a first step, update it to take a boolean parameter, indicating whether or not the processing is required.
---
common/bootm.c | 20 ++++++++++---------- include/bootm.h | 3 ++- test/bootm.c | 10 +++++----- 3 files changed, 17 insertions(+), 16 deletions(-)
common/bootm.c +10 -10
@@ -466,15 +466,17 @@ ulong bootm_disable_interrupts(void)#define CONSOLE_ARG "console="#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) -int bootm_process_cmdline_env (void ) +int bootm_process_cmdline_env (bool do_silent) {char *buf;const char *env_val;char *cmdline;int want_silent; -if (!IS_ENABLED (CONFIG_SILENT_CONSOLE ) && - !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY )) +/* First check if any action is needed */ + do_silent =IS_ENABLED (CONFIG_SILENT_CONSOLE ) && + !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY ) && do_silent; +if (!do_silent)return 0 ; cmdline =env_get ("bootargs" );
@@ -629,13 +631,11 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,if (!ret && (states &BOOTM_STATE_OS_BD_T )) ret =boot_fn (BOOTM_STATE_OS_BD_T , argc, argv, images);if (!ret && (states &BOOTM_STATE_OS_PREP )) { -if (images->os.os ==IH_OS_LINUX ) { - ret =bootm_process_cmdline_env (); -if (ret) { -printf ("Cmdline setup failed (err=%d)\n" , ret); - ret =CMD_RET_FAILURE ; - goto err; - } + ret =bootm_process_cmdline_env (images->os.os ==IH_OS_LINUX ); +if (ret) { +printf ("Cmdline setup failed (err=%d)\n" , ret); + ret =CMD_RET_FAILURE ; + goto err; } ret =boot_fn (BOOTM_STATE_OS_PREP , argc, argv, images); }
include/bootm.h +2 -1
@@ -91,8 +91,9 @@ void board_preboot_os(void);* Updates the 'bootargs' envvar as required. This handles making Linux boot * silently if requested ('silent_linux' envvar) * +* @do_silent: Process bootargs for silent console * @return 0 if OK, -ENOMEM if out of memory */ -int bootm_process_cmdline_env (void ); +int bootm_process_cmdline_env (bool do_silent);#endif
test/bootm.c +5 -5
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state *uts)/* 'silent_linux' not set should do nothing */ env_set ("silent_linux" ,NULL );env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (bootm_process_cmdline_env ()); +ut_assertok (bootm_process_cmdline_env (true));ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));env_set ("bootargs" ,NULL ); -ut_assertok (bootm_process_cmdline_env ()); +ut_assertok (bootm_process_cmdline_env (true));ut_assertnull (env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"no" ));env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (bootm_process_cmdline_env ()); +ut_assertok (bootm_process_cmdline_env (true));ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"yes" ));env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (bootm_process_cmdline_env ()); +ut_assertok (bootm_process_cmdline_env (true));ut_asserteq_str ("console=" ,env_get ("bootargs" ));/* Empty buffer should still add the string */ env_set ("bootargs" ,NULL ); -ut_assertok (bootm_process_cmdline_env ()); +ut_assertok (bootm_process_cmdline_env (true));ut_asserteq_str ("console=" ,env_get ("bootargs" ));return 0 ;
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 6/11 bootm: Use size rather than length for CONSOLE_ARG
In reply to Simon GlassUse the size (including terminator) for in this function, rather than the length. This is arguably easier to follow, with the coming refactor.
---
common/bootm.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
common/bootm.c +8 -7
@@ -463,8 +463,8 @@ ulong bootm_disable_interrupts(void)return iflag; } -#define CONSOLE_ARG "console=" -#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1) +#define CONSOLE_ARG "console=" +#define CONSOLE_ARG_SIZE sizeof(CONSOLE_ARG)int bootm_process_cmdline_env (bool do_silent) {
@@ -498,7 +498,7 @@ int bootm_process_cmdline_env(bool do_silent)char *start =strstr (cmdline,CONSOLE_ARG );/* Allocate space for maximum possible new command line */ - buf =malloc (strlen (cmdline) +1 +CONSOLE_ARG_LEN +1 ); + buf =malloc (strlen (cmdline) +1 +CONSOLE_ARG_SIZE );if (!buf) {debug ("%s: out of memory\n" , __func__);return -ENOSPC ;
@@ -506,13 +506,14 @@ int bootm_process_cmdline_env(bool do_silent)if (start) {char *end =strchr (start,' ' ); -int num_start_bytes = start - cmdline +CONSOLE_ARG_LEN ; +int start_bytes; -strncpy (buf, cmdline, num_start_bytes); + start_bytes = start - cmdline +CONSOLE_ARG_SIZE -1 ; +strncpy (buf, cmdline, start_bytes);if (end) -strcpy (buf + num_start_bytes, end); +strcpy (buf + start_bytes, end);else - buf[num_start_bytes] ='\0' ; + buf[start_bytes] ='\0' ; }else {sprintf (buf,"%s %s" , cmdline,CONSOLE_ARG ); }
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 7/11 bootm: Split out bootargs environment reading / writing
In reply to Simon GlassAt present bootm_process_cmdline_env() reads the 'bootargs' variable and then writes it back afterwards. This is painful for tests, which would rather use a simple buffer.
It is also useful for zimage to use a buffer, since it does not actually put the Linux command line in the bootargs variable.
Refactor the existing code into two pieces. One handles reading and writing the environment variable, as well as allocating a buffer for use by the rest of the code, which now operates on a buffer.
---
common/bootm.c | 95 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 22 deletions(-)
common/bootm.c +73 -22
@@ -19,6 +19,7 @@#include <net.h> #include <asm/cache.h> #include <asm/io.h> +#include <linux/sizes.h> #if defined(CONFIG_CMD_USB )#include <usb.h> #endif
@@ -35,6 +36,8 @@#define CONFIG_SYS_BOOTM_LEN 0x800000#endif +#define MAX_CMDLINE_SIZE SZ_4K +#define IH_INITRD_ARCH IH_ARCH_DEFAULT#ifndef USE_HOSTCC
@@ -466,20 +469,31 @@ ulong bootm_disable_interrupts(void)#define CONSOLE_ARG "console="#define CONSOLE_ARG_SIZE sizeof(CONSOLE_ARG) -int bootm_process_cmdline_env (bool do_silent) +/** +* fixup_silent_linux() - Handle silencing the linux boot if required +* +* This uses the silent_linux envvar to control whether to add/set a "console=" +* parameter to the command line +* +* @buf: Buffer containing the string to process +* @maxlen: Maximum length of buffer +* @return 0 if OK, -ENOSPC if @maxlen is too small +*/ +static int fixup_silent_linux (char *buf,int maxlen) { -char *buf; -const char *env_val; -char *cmdline;int want_silent; +char *cmdline; +int size; -/* First check if any action is needed */ - do_silent =IS_ENABLED (CONFIG_SILENT_CONSOLE ) && - !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY ) && do_silent; -if (!do_silent) -return 0 ; - cmdline =env_get ("bootargs" ); - +/* +* Move the input string to the end of buffer. The output string will be +* built up at the start. +*/ + size =strlen (buf) +1 ; +if (size *2 > maxlen) +return -ENOSPC ; + cmdline = buf + maxlen - size; +memmove (cmdline, buf, size);/* * Only fix cmdline when requested. The environment variable can be: *
@@ -494,15 +508,12 @@ int bootm_process_cmdline_env(bool do_silent)return 0 ;debug ("before silent fix-up: %s\n" , cmdline); -if (cmdline && (cmdline[0 ] !='\0' )) { +if (*cmdline) {char *start =strstr (cmdline,CONSOLE_ARG ); -/* Allocate space for maximum possible new command line */ - buf =malloc (strlen (cmdline) +1 +CONSOLE_ARG_SIZE ); -if (!buf) { -debug ("%s: out of memory\n" , __func__); +/* Check space for maximum possible new command line */ +if (size +CONSOLE_ARG_SIZE > maxlen)return -ENOSPC ; - }if (start) {char *end =strchr (start,' ' );
@@ -517,15 +528,55 @@ int bootm_process_cmdline_env(bool do_silent) }else {sprintf (buf,"%s %s" , cmdline,CONSOLE_ARG ); } - env_val = buf; +if (buf +strlen (buf) >= cmdline) +return -ENOSPC ; }else { - buf =NULL ; - env_val =CONSOLE_ARG ; +if (maxlen <sizeof (CONSOLE_ARG )) +return -ENOSPC ; +strcpy (buf,CONSOLE_ARG ); } +debug ("after silent fix-up: %s\n" , buf); -env_set ("bootargs" , env_val); -debug ("after silent fix-up: %s\n" , env_val); +return 0 ; +} + +int bootm_process_cmdline_env (bool do_silent) +{ +const int maxlen =MAX_CMDLINE_SIZE ; +const char *env; +char *buf; +int ret; + +/* First check if any action is needed */ + do_silent =IS_ENABLED (CONFIG_SILENT_CONSOLE ) && + !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY ) && do_silent; +if (!do_silent) +return 0 ; + + env =env_get ("bootargs" ); +if (env &&strlen (env) >= maxlen) +return -E2BIG ; + buf =malloc (maxlen); +if (!buf) +return -ENOMEM ; +if (env) +strcpy (buf, env); +else + *buf ='\0' ; + ret =fixup_silent_linux (buf, maxlen); +if (!ret) { + ret =env_set ("bootargs" , buf); + +/* +* If buf is "" and bootargs does not exist, this will produce +* an error trying to delete bootargs. Ignore it +*/ +if (ret == -ENOENT ) + ret =0 ; + }free (buf); +if (ret) +return log_msg_ret ("env" , ret);return 0 ; }
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 7/11 bootm: Split out bootargs environment reading / writing
Dear Simon,
In message <[email protected]> you wrote:
...
Quoted 3 lines
It is also useful for zimage to use a buffer, since it does not actually put the Linux command line in the bootargs variable.
...which I consider a bug that should be fixed.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A good marriage would be between a blind wife and deaf husband.
-- Michel de MontaignePATCH 7/11 bootm: Split out bootargs environment reading / writing
Hi Wolfgang,
Quoted 10 lines · Wolfgang Denk
Dear Simon,
In message <[email protected]> you wrote:
...Quoted 3 lines
It is also useful for zimage to use a buffer, since it does not actually put the Linux command line in the bootargs variable.
...which I consider a bug that should be fixed.
OK I was wondering about that.
The messy thing about zimage is that the command line comes from the setup.bin in the kernel, and then needs to be modified. So you can't just blindly use the 'bootargs' var. Perhaps that is why it wasn't done?
I also feel eventually that bootm could subsume zboot given the similarities. Or maybe zboot just dies if people stop using the old boot approach?
Regards,
Simon
PATCH 7/11 bootm: Split out bootargs environment reading / writing
Dear Simon,
Quoted 4 lines · In message <CAPnjgZ0LCKLdpq85gfyOU-Z0BJgydo_KY+JEX7KTb_WFDpFM+A@mail.gmail.com>…
Quoted 4 lines
Quoted 3 lines
It is also useful for zimage to use a buffer, since it does not actually put the Linux command line in the bootargs variable.
Quoted 8 lines
Quoted 1 line
...which I consider a bug that should be fixed.
OK I was wondering about that.
The messy thing about zimage is that the command line comes from the setup.bin in the kernel, and then needs to be modified. So you can't just blindly use the 'bootargs' var. Perhaps that is why it wasn't done?
I can't say. I never used zImages, and probably never will.
Quoted 3 lines
I also feel eventually that bootm could subsume zboot given the similarities. Or maybe zboot just dies if people stop using the old boot approach?
I would not shed a tear.
I cannot understand why people still use this. We should more actively encourage the use of FIT images in favour of all these old formats.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "If it ain't broke, don't fix it." - Bert Lantz
PATCH 7/11 bootm: Split out bootargs environment reading / writing
Hi Wolfgang,
Quoted 23 lines · Wolfgang Denk
Dear Simon,
Quoted 4 lines · In message <CAPnjgZ0LCKLdpq85gfyOU-Z0BJgydo_KY+JEX7KTb_WFDpFM+A@mail.gmail.com>…
Quoted 4 lines
Quoted 3 lines
It is also useful for zimage to use a buffer, since it does not actually put the Linux command line in the bootargs variable.
Quoted 8 lines
Quoted 1 line
...which I consider a bug that should be fixed.
OK I was wondering about that.
The messy thing about zimage is that the command line comes from the setup.bin in the kernel, and then needs to be modified. So you can't just blindly use the 'bootargs' var. Perhaps that is why it wasn't done?
I can't say. I never used zImages, and probably never will.
Quoted 3 lines
I also feel eventually that bootm could subsume zboot given the similarities. Or maybe zboot just dies if people stop using the old boot approach?
Quoted 5 lines
I would not shed a tear.
I cannot understand why people still use this. We should more actively encourage the use of FIT images in favour of all these old formats.
Well x86 does support FIT, but oddly it still has the setup.bin business, because the kernel requires it! At least it uses bootm, though.
Something for the future...
Regards,
Simon
PATCH 8/11 bootm: Update bootm_process_cmdline_env() to use flags
In reply to Simon GlassAt present only one transformation is supported: making the Linux console silent. To prepare for adding more, convert the boolean parameter into a flag value.
---
common/bootm.c | 8 +++++--- include/bootm.h | 11 +++++++++-- test/bootm.c | 10 +++++----- 3 files changed, 19 insertions(+), 10 deletions(-)
common/bootm.c +5 -3
@@ -540,16 +540,17 @@ static int fixup_silent_linux(char *buf, int maxlen)return 0 ; } -int bootm_process_cmdline_env (bool do_silent) +int bootm_process_cmdline_env (int flags) {const int maxlen =MAX_CMDLINE_SIZE ; +bool do_silent;const char *env;char *buf;int ret;/* First check if any action is needed */ do_silent =IS_ENABLED (CONFIG_SILENT_CONSOLE ) && - !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY ) && do_silent; + !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY ) && (flags &BOOTM_CL_SILENT );if (!do_silent)return 0 ;
@@ -683,7 +684,8 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,if (!ret && (states &BOOTM_STATE_OS_BD_T )) ret =boot_fn (BOOTM_STATE_OS_BD_T , argc, argv, images);if (!ret && (states &BOOTM_STATE_OS_PREP )) { - ret =bootm_process_cmdline_env (images->os.os ==IH_OS_LINUX ); + ret =bootm_process_cmdline_env (images->os.os ==IH_OS_LINUX ? +BOOTM_CL_SILENT :0 );if (ret) {printf ("Cmdline setup failed (err=%d)\n" , ret); ret =CMD_RET_FAILURE ;
include/bootm.h +9 -2
@@ -75,6 +75,13 @@ void board_quiesce_devices(void);*/ void switch_to_non_secure_mode (void ); +/* Flags to control bootm_process_cmdline() */ +enum bootm_cmdline_t { +BOOTM_CL_SILENT =1 <<0 ,/* Do silent console processing */ + +BOOTM_CL_ALL =1 ,/* All substitutions */ +}; +/** * arch_preboot_os() - arch specific configuration before booting */
@@ -91,9 +98,9 @@ void board_preboot_os(void);* Updates the 'bootargs' envvar as required. This handles making Linux boot * silently if requested ('silent_linux' envvar) * -* @do_silent: Process bootargs for silent console +* @flags: Flags to control what happens (see bootm_cmdline_t) * @return 0 if OK, -ENOMEM if out of memory */ -int bootm_process_cmdline_env (bool do_silent); +int bootm_process_cmdline_env (int flags);#endif
test/bootm.c +5 -5
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state *uts)/* 'silent_linux' not set should do nothing */ env_set ("silent_linux" ,NULL );env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (bootm_process_cmdline_env (true)); +ut_assertok (bootm_process_cmdline_env (BOOTM_CL_SILENT ));ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));env_set ("bootargs" ,NULL ); -ut_assertok (bootm_process_cmdline_env (true)); +ut_assertok (bootm_process_cmdline_env (BOOTM_CL_SILENT ));ut_assertnull (env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"no" ));env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (bootm_process_cmdline_env (true)); +ut_assertok (bootm_process_cmdline_env (BOOTM_CL_SILENT ));ut_asserteq_str (CONSOLE_STR ,env_get ("bootargs" ));ut_assertok (env_set ("silent_linux" ,"yes" ));env_set ("bootargs" ,CONSOLE_STR ); -ut_assertok (bootm_process_cmdline_env (true)); +ut_assertok (bootm_process_cmdline_env (BOOTM_CL_SILENT ));ut_asserteq_str ("console=" ,env_get ("bootargs" ));/* Empty buffer should still add the string */ env_set ("bootargs" ,NULL ); -ut_assertok (bootm_process_cmdline_env (true)); +ut_assertok (bootm_process_cmdline_env (BOOTM_CL_SILENT ));ut_asserteq_str ("console=" ,env_get ("bootargs" ));return 0 ;
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 9/11 bootm: Allow updating the bootargs in a buffer
In reply to Simon GlassAt present we only support updating the 'bootargs' environment variable. Add another function to update a buffer instead. This will allow zimage to use this feature.
Also add a lot more tests to cover various cases.
---
common/bootm.c | 18 +++++++- include/bootm.h | 16 +++++++ test/bootm.c | 114 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 132 insertions(+), 16 deletions(-)
common/bootm.c +17 -1
@@ -540,6 +540,22 @@ static int fixup_silent_linux(char *buf, int maxlen)return 0 ; } +int bootm_process_cmdline (char *buf,int maxlen,int flags) +{ +int ret; + +/* Check config first to enable compiler to eliminate code */ +if (IS_ENABLED (CONFIG_SILENT_CONSOLE ) && + !IS_ENABLED (CONFIG_SILENT_U_BOOT_ONLY ) && + (flags &BOOTM_CL_SILENT )) { + ret =fixup_silent_linux (buf, maxlen); +if (ret) +return log_msg_ret ("silent" , ret); + } + +return 0 ; +} +int bootm_process_cmdline_env (int flags) {const int maxlen =MAX_CMDLINE_SIZE ;
@@ -564,7 +580,7 @@ int bootm_process_cmdline_env(int flags)strcpy (buf, env); else *buf ='\0' ; - ret =fixup_silent_linux (buf, maxlen); + ret =bootm_process_cmdline (buf, maxlen, flags);if (!ret) { ret =env_set ("bootargs" , buf);
include/bootm.h +16 -0
@@ -93,6 +93,22 @@ void arch_preboot_os(void);void board_preboot_os (void );/* +* bootm_process_cmdline() - Process fix-ups for the command line +* +* This handles: making Linux boot silently if requested ('silent_linux' envvar) +* +* @maxlen must provide enough space for the string being processed plus the +* resulting string +* +* @buf: buffer holding commandline string to adjust +* @maxlen: Maximum length of buffer at @buf (including \0) +* @flags: Flags to control what happens (see bootm_cmdline_t) +* @return 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too +* long +*/ +int bootm_process_cmdline (char *buf,int maxlen,int flags); + +/** * bootm_process_cmdline_env() - Process fix-ups for the command line * * Updates the 'bootargs' envvar as required. This handles making Linux boot
test/bootm.c +99 -15
132 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 9/11 bootm: Allow updating the bootargs in a buffer
Dear Simon Glass,
Quoted 3 lines · In message <[email protected]> you wrote:
At present we only support updating the 'bootargs' environment variable. Add another function to update a buffer instead. This will allow zimage to use this feature.
I think this is the wrong way to address a problem.
Instead, zimage should use bootargs as well.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de The faster I go, the behinder I get. -- Lewis Carroll
PATCH 9/11 bootm: Allow updating the bootargs in a buffer
Hi Wolfgang,
Quoted 11 lines · Wolfgang Denk
Dear Simon Glass,
Quoted 3 lines · In message <[email protected]> you wrote:
At present we only support updating the 'bootargs' environment variable. Add another function to update a buffer instead. This will allow zimage to use this feature.
I think this is the wrong way to address a problem.
Instead, zimage should use bootargs as well.
OK I can add that. But for testing purposes it is still good to be able to have the feature in a function that can be called without going through environment variables.
Regards,
SImon
PATCH 9/11 bootm: Allow updating the bootargs in a buffer
Dear Simon,
Quoted 8 lines · In message <CAPnjgZ3hYf9F7eBqMQBKpe4jM=hW46dhCPxGU=cBVV8M_WNKDQ@mail.gmail.com>…
Quoted 4 lines
I think this is the wrong way to address a problem.
Instead, zimage should use bootargs as well.
OK I can add that. But for testing purposes it is still good to be able to have the feature in a function that can be called without going through environment variables.
OK with me - if it doesn't add to the code size.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The C-shell doesn't parse. It adhoculates.
- Casper.Dik at Holland.Sun.COM in <[email protected]>PATCH 9/11 bootm: Allow updating the bootargs in a buffer
Hi Wolfgang,
Quoted 7 lines · Wolfgang Denk
Dear Simon,
Quoted 3 lines · In message <CAPnjgZ3hYf9F7eBqMQBKpe4jM=hW46dhCPxGU=cBVV8M_WNKDQ@mail.gmail.com>…
Quoted 3 lines
I think this is the wrong way to address a problem.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Instead, zimage should use bootargs as well.
OK I can add that. But for testing purposes it is still good to be able to have the feature in a function that can be called without going through environment variables.
OK with me - if it doesn't add to the code size.
The bootm refactoring adds about 144 bytes of code for Thumb2 and 31 bytes of data. I think it is worth it for the ability to add tests. The extra substitution feature doesn't add any size if not enabled.
Regards,
Simon
PATCH 10/11 x86: zimage: Add silent-console processing
In reply to Simon GlassAt present zimage does its own command-line processing and does not support the 'silent console' feature. There doesn't seem to be any good reason for this.
Add support for silent console to zimage.
---
arch/x86/lib/zimage.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/x86/lib/zimage.c +14 -0
@@ -13,6 +13,7 @@*/ #include <common.h> +#include <bootm.h> #include <command.h> #include <env.h> #include <irq_func.h>
@@ -317,6 +318,11 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, }if (cmd_line) { +int max_size =0xff ; +int ret; + +if (bootproto >=0x0206 ) + max_size = hdr->cmdline_size;if (bootproto >=0x0202 ) { hdr->cmd_line_ptr = (uintptr_t )cmd_line; }else if (bootproto >=0x0200 ) {
@@ -332,6 +338,14 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,strcpy (cmd_line, (char *)cmdline_force); elsebuild_command_line (cmd_line ,auto_boot ); + ret =bootm_process_cmdline (cmd_line, max_size,BOOTM_CL_ALL ); +if (ret) { +printf ("Cmdline setup failed (err=%d)\n" , ret); +return ret; + } +printf ("Kernel command line: \"" ); +puts (cmd_line); +printf ("\"\n" ); }if (IS_ENABLED (CONFIG_INTEL_MID ) && bootproto >=0x0207 )
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 11/11 bootm: Support string substitution in bootargs
In reply to Simon GlassIn some cases it is necessary to pass parameters to Linux so that it will boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution providing the UUID of the root device.
For example, to substitute the GUID of the kernel partition:
setenv bootargs "console=/dev/ttyS0 rootdev=%U/PARTNROFF=1 kern_guid=%U" part uuid mmc 2:2 uuid
setenv bootargs_U $uuid
bootm
This is particularly useful when the command line from another place. For example, Chrome OS stores the command line next to the kernel itself. It depends on the kernel version being used as well as the hardware features, so it is extremely difficult to devise a U-Boot script that works on all boards and kernel versions. With this feature, the command line can be read from disk and used directly, with a few substitutions set up.
---
README | 16 +++++++ arch/Kconfig | 1 + common/Kconfig.boot | 20 ++++++++ common/bootm.c | 72 +++++++++++++++++++++++++++-- include/bootm.h | 14 ++++-- test/bootm.c | 110 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 221 insertions(+), 12 deletions(-)
README +16 -0
@@ -3229,6 +3229,22 @@ List of environment variables (most likely not complete): bootargs - Boot arguments when booting an RTOS image + bootargs_subst - Substitution parameters for bootargs. These are applied after + the commandline has been built. The format is: + + <key>=<value>[!<key>=<value>...] + + where + <key> is a string to replace + <value> is the value to replace it with (either a simple + string or an environment variable starting with $ + + One use for this is to insert the root-disk UUID into the + command line where bootargs contains "root=%U" + + part uuid mmc 2:2 uuid + setenv cmdline_repl %U=$uuid + bootfile - Name of the image to load with TFTP bootm_low - Memory range available for image processing in the bootm
arch/Kconfig +1 -0
@@ -141,6 +141,7 @@ config SANDBOX imply CMD_PMC imply CMD_CLONE imply SILENT_CONSOLE + imply BOOTARGS_SUBST config SH bool "SuperH architecture"
common/Kconfig.boot +20 -0
@@ -848,6 +848,26 @@ config BOOTARGS CONFIG_BOOTARGS goes into the environment value "bootargs". Note that this value will also override the "chosen" node in FDT blob. +config BOOTARGS_SUBST + bool "Support substituting strings in boot arguments" + help + This allows substituting string values in the boot arguments. These + are applied after the commandline has been built. Set the + 'bootargs_subst' envvar to control this. The format is: + + <key>=<value>[!<key>=<value>...] + + where + <key> is a string to replace + <value> is the value to replace it with (either a simple + string or an environment variable starting with $ + + One use for this is to insert the root-disk UUID into the + command line where bootargs contains "root=%U" + + part uuid mmc 2:2 uuid + setenv cmdline_repl %U=$uuid + config USE_BOOTCOMMAND bool "Enable a default value for bootcmd" help
common/bootm.c +69 -3
96 lines not on this page · raw message
include/bootm.h +10 -4
@@ -78,8 +78,9 @@ void switch_to_non_secure_mode(void);/* Flags to control bootm_process_cmdline() */ enum bootm_cmdline_t {BOOTM_CL_SILENT =1 <<0 ,/* Do silent console processing */ +BOOTM_CL_SUBST =1 <<1 ,/* Do substitution */ -BOOTM_CL_ALL =1 ,/* All substitutions */ +BOOTM_CL_ALL =3 ,/* All substitutions */ };/**
@@ -95,7 +96,10 @@ void board_preboot_os(void);/* * bootm_process_cmdline() - Process fix-ups for the command line * -* This handles: making Linux boot silently if requested ('silent_linux' envvar) +* This handles: +* +* - making Linux boot silently if requested ('silent_linux' envvar) +* - performing substitutions in the command line ('bootargs_subst' envvar) * * @maxlen must provide enough space for the string being processed plus the * resulting string
@@ -111,8 +115,10 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags);/** * bootm_process_cmdline_env() - Process fix-ups for the command line * -* Updates the 'bootargs' envvar as required. This handles making Linux boot -* silently if requested ('silent_linux' envvar) +* Updates the 'bootargs' envvar as required. This handles: +* +* - making Linux boot silently if requested ('silent_linux' envvar) +* - performing substitutions in the command line ('bootargs_subst' envvar) * * @flags: Flags to control what happens (see bootm_cmdline_t) * @return 0 if OK, -ENOMEM if out of memory
test/bootm.c +105 -5
127 lines not on this page · raw message
Signature · 1 line
2.29.0.rc1.297.gfa9743e501-goog
PATCH 11/11 bootm: Support string substitution in bootargs
Quoted 51 lines · Simon Glass
In some cases it is necessary to pass parameters to Linux so that it will boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution providing the UUID of the root device.
For example, to substitute the GUID of the kernel partition:
setenv bootargs "console=/dev/ttyS0 rootdev=%U/PARTNROFF=1 kern_guid=%U" part uuid mmc 2:2 uuid
setenvbootargs_U$uuid
bootmThis is particularly useful when the command line from another place. For example, Chrome OS stores the command line next to the kernel itself. It depends on the kernel version being used as well as the hardware features, so it is extremely difficult to devise a U-Boot script that works on all boards and kernel versions. With this feature, the command line can be read from disk and used directly, with a few substitutions set up.
Signed-off-by Simon Glass <[email protected]>---
README | 16 +++++++ arch/Kconfig | 1 + common/Kconfig.boot | 20 ++++++++ common/bootm.c | 72 +++++++++++++++++++++++++++-- include/bootm.h | 14 ++++-- test/bootm.c | 110 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 221 insertions(+), 12 deletions(-)README +5
-0@@ -3229,6 +3229,22 @@ List of environment variables (most likely not complete): bootargs - Boot arguments when booting an RTOS image + bootargs_subst - Substitution parameters for bootargs. These are applied after + the commandline has been built. The format is: + + <key>=<value>[!<key>=<value>...] +
README List of environment variables (most likely not complete): · line 3246
Quoted 10 lines
README +10
-0+ where + <key> is a string to replace + <value> is the value to replace it with (either a simple + string or an environment variable starting with $ + + One use for this is to insert the root-disk UUID into the + command line where bootargs contains "root=%U" + + part uuid mmc 2:2 uuid + setenv cmdline_repl %U=$uuid
cmdline_repl seems to be stale, it should be bootargs_subst. But the whole paragraph seems stale, as you actually implement and test the bootargs_X approach.
Anyway, this does seem useful, but I really question the choice of leaving %A in there if bootargs_A does not exist. It's hard if not impossible to create an environment variable whose value is empty, and I can easily imagine it would be useful to allow a %A to expand to nothing. So why not just use the usual semantics of requiring a double %% to put a single % in the output? It's probably quite rare that one would need that anyway.
Rasmus
PATCH 11/11 bootm: Support string substitution in bootargs
Hi Rasmus,
Quoted 59 lines · Rasmus Villemoes
Quoted 57 lines · Simon Glass
In some cases it is necessary to pass parameters to Linux so that it will boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution providing the UUID of the root device.
For example, to substitute the GUID of the kernel partition:
setenv bootargs "console=/dev/ttyS0 rootdev=%U/PARTNROFF=1 kern_guid=%U" part uuid mmc 2:2 uuid
setenvbootargs_U$uuid
bootmThis is particularly useful when the command line from another place. For example, Chrome OS stores the command line next to the kernel itself. It depends on the kernel version being used as well as the hardware features, so it is extremely difficult to devise a U-Boot script that works on all boards and kernel versions. With this feature, the command line can be read from disk and used directly, with a few substitutions set up.
Signed-off-by Simon Glass <[email protected]>---
README | 16 +++++++ arch/Kconfig | 1 + common/Kconfig.boot | 20 ++++++++ common/bootm.c | 72 +++++++++++++++++++++++++++-- include/bootm.h | 14 ++++-- test/bootm.c | 110 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 221 insertions(+), 12 deletions(-)README +11
-0@@ -3229,6 +3229,22 @@ List of environment variables (most likely not complete): bootargs - Boot arguments when booting an RTOS image + bootargs_subst - Substitution parameters for bootargs. These are applied after + the commandline has been built. The format is: + + <key>=<value>[!<key>=<value>...] + + where + <key> is a string to replace + <value> is the value to replace it with (either a simple + string or an environment variable starting with $ + + One use for this is to insert the root-disk UUID into the
Quoted 8 lines
README List of environment variables (most likely not complete): · line 3246
Quoted 4 lines
README +4
-0+ command line where bootargs contains "root=%U" + + part uuid mmc 2:2 uuid + setenv cmdline_repl %U=$uuid
cmdline_replseems to be stale, it should bebootargs_subst. But the whole paragraph seems stale, as you actually implement and test thebootargs_Xapproach.
Yes, thanks, will fix.
Quoted 8 lines
Anyway, this does seem useful, but I really question the choice of leaving %A in there if
bootargs_Adoes not exist. It's hard if not impossible to create an environment variable whose value is empty, and I can easily imagine it would be useful to allow a %A to expand to nothing. So why not just use the usual semantics of requiring a double %% to put a single % in the output? It's probably quite rare that one would need that anyway.
I did wonder about the empty env var thing. IMO it would be nice to support empty variables, so we can distinguish between an empty one and a missing one.
My concern with removing the var is if people have % in the string. This way I don't have to worry about quoting, etc. See Wolgang's email in this thread too.
Regards,
Simon
PATCH 11/11 bootm: Support string substitution in bootargs
Dear Simon,
Quoted 4 lines · In message <CAPnjgZ3gkCO6_DdQh3XJrsf9SdVa0v3pGuwejGBoDHPEijyRkg@mail.gmail.com>…
I did wonder about the empty env var thing. IMO it would be nice to support empty variables, so we can distinguish between an empty one and a missing one.
What exactly is the use case for this that justifies the additional code needed to implement this feature?
Please keep in mind that this is a boot loader, and we are not attending a contest for feature-completeness.
[Non-random signature this time.]
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Perfection is reached, not when there is no longer anything to add,
but when there is no longer anything to take away.
- Antoine de Saint-ExuperyPATCH 11/11 bootm: Support string substitution in bootargs
In reply to Simon GlassDear Simon,
Quoted 6 lines · In message <[email protected]> you wrote:
In some cases it is necessary to pass parameters to Linux so that it will boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.
Quoted 6 lines
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution providing the UUID of the root device.
Argh, no, please don't.
You add something unconditionally to common code which very few people need. U-Boot size is growing all the time because of such ... features. This may be acceptable on the systems you have in mind, but I consider this selfish.
Why do we have to add yet another non-standard way of substituting variables in a string? Can we not use alreay existing methonds instead?
Why do you have to use "%U" in your template instead of for example "${uuid}" ?
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If you use modules, you pay the price. Sane embedded solutions
running in "tight" environments don't use modules :-)
-- Benjamin Herrenschmidt in <1258234866.2140.451.camel@pasglop>PATCH 11/11 bootm: Support string substitution in bootargs
Am 2020-10-19 16:54, schrieb Wolfgang Denk:
Quoted 26 lines
Dear Simon,
Quoted 8 lines · In message <[email protected]> you wrote:
In some cases it is necessary to pass parameters to Linux so that it will
boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on
whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.Quoted 7 lines
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution
providing the UUID of the root device.Argh, no, please don't.
You add something unconditionally to common code which very few people need. U-Boot size is growing all the time because of such ... features. This may be acceptable on the systems you have in mind, but I consider this selfish.
Quoted 6 lines
Why do we have to add yet another non-standard way of substituting variables in a string? Can we not use alreay existing methonds instead?
Why do you have to use "%U" in your template instead of for example "${uuid}" ?
I'd second that. Having variables evaluated inside the bootargs would be very valuable IMHO.
At the moment we have some cumbersome constructs like
set_bootargs="setenv bootargs bla ${var}"
-michael
PATCH 11/11 bootm: Support string substitution in bootargs
Hi Michael,
Quoted 32 lines · Michael Walle
Am 2020-10-19 16:54, schrieb Wolfgang Denk:
Quoted 30 lines
Dear Simon,
Quoted 8 lines · In message <[email protected]> you wrote:
In some cases it is necessary to pass parameters to Linux so that it will
boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on
whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.Quoted 7 lines
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution
providing the UUID of the root device.Argh, no, please don't.
You add something unconditionally to common code which very few people need. U-Boot size is growing all the time because of such ... features. This may be acceptable on the systems you have in mind, but I consider this selfish.
Why do we have to add yet another non-standard way of substituting variables in a string? Can we not use alreay existing methonds instead?
Quoted 8 lines
Quoted 2 lines
Why do you have to use "%U" in your template instead of for example "${uuid}" ?
I'd second that. Having variables evaluated inside the bootargs would be very valuable IMHO.
At the moment we have some cumbersome constructs like
set_bootargs="setenv bootargs bla ${var}"
Yes it is a real pain. The substitution happens on first parse two, so you have to put these commands in separate variables if you are building things up.
Another thing to mention is that years ago I sent a series to help with that last bit, i.e. make variables evaluate recursively. I'm trying to remember what happened to it.
Regards,
Simon
PATCH 11/11 bootm: Support string substitution in bootargs
Dear Simon,
Quoted 7 lines · In message <CAPnjgZ2rAQZN_bdQ5C-9cB4u8F8PrhZkBWYx0zWxj_yEBrV2qw@mail.gmail.com>…
Quoted 3 lines
At the moment we have some cumbersome constructs like
set_bootargs="setenv bootargs bla ${var}"Yes it is a real pain. The substitution happens on first parse two, so you have to put these commands in separate variables if you are building things up.
Come on, is it really that big a problem?
You define all your needed settings (foo, bar, baz, and maybe uuid), and then you run a single command
setenv bootargs "${foo} ${bar} %{baz} ${uuid}"?
Yes, it takes one additional step, but it's simple and does not need extra code.
[And if someone bothered to update hush to a recent version, and while doing so revisited the adaptions needed for U-Boot, we could also do much better. IIRC, things like command substitution were omitted then because of the code size it would have required; given today's resources this might be an optional feature for many.]
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de ...when fits of creativity run strong, more than one programmer or writer has been known to abandon the desktop for the more spacious floor. - Fred Brooks, Jr.
PATCH 11/11 bootm: Support string substitution in bootargs
Hi Wolfgang,
Quoted 17 lines · Wolfgang Denk
Dear Simon,
Quoted 7 lines · In message <CAPnjgZ2rAQZN_bdQ5C-9cB4u8F8PrhZkBWYx0zWxj_yEBrV2qw@mail.gmail.com>…
Quoted 3 lines
At the moment we have some cumbersome constructs like
set_bootargs="setenv bootargs bla ${var}"Yes it is a real pain. The substitution happens on first parse two, so you have to put these commands in separate variables if you are building things up.
Come on, is it really that big a problem?
You define all your needed settings (foo, bar, baz, and maybe uuid), and then you run a single command
Quoted 6 lines
setenv bootargs "${foo} ${bar} %{baz} ${uuid}"?
Yes, it takes one additional step, but it's simple and does not need extra code.
It is actually not simple, for three reasons:
1. With zboot the args come from the kernel setup.bin and must be modified
2. With Chrome OS the args come from the kernel partition and must be augmented / substituted
3. The above command cannot be in the same env var as anything else, since substitution breaks in that case
So you end up with a really complicated mess of environment variables and scripts that is barely manageable. I want it to be simple.
See here for example (this only deals with 3 above, not 1 and 2, which would still need custom code without my series)
Quoted 6 lines
[And if someone bothered to update hush to a recent version, and while doing so revisited the adaptions needed for U-Boot, we could also do much better. IIRC, things like command substitution were omitted then because of the code size it would have required; given today's resources this might be an optional feature for many.]
Yes I agree, so long as the code size increase is not horrific.
+Tom Rini what do you think?
Regards,
Simon
PATCH 11/11 bootm: Support string substitution in bootargs
Dear Simon,
Quoted 7 lines · In message <CAPnjgZ1SfwRa_LXh0zu3Oug=GLEUQx5MdCCvqW90-FV5hvX9uw@mail.gmail.com>…
Quoted 3 lines
Yes, it takes one additional step, but it's simple and does not need extra code.
It is actually not simple, for three reasons:
1. With zboot the args come from the kernel setup.bin and must be modified
Don't use zboot, then. In my opinion, zboot is crap and should never have been added, but there were so many requests for it. Nevertheless, the use of crippleware is a sin that carries with it its own punishment.
Don't do it, then.
Or, if you feel there is some value in zboot that should be conserved, fix it to work like the rest of U-Boot.
Quoted 2 lines
2. With Chrome OS the args come from the kernel partition and must be augmented / substituted
OK. But then why can we not still use the standard variable substitution mechanism we already have?
Quoted 2 lines
3. The above command cannot be in the same env var as anything else, since substitution breaks in that case
Sorry, I don't understand what you mean heare. What is "the same env var" versus "anything else"? Maybe you can give a specific example?
Quoted 2 lines
So you end up with a really complicated mess of environment variables and scripts that is barely manageable. I want it to be simple.
Again, I can't follow you. Why must there be a mess?
Quoted 4 lines
See here for example (this only deals with 3 above, not 1 and 2, which would still need custom code without my series)
Sorry - all I see there is some complex settings if these make sense I can't tell) - but how would things be better if you could - for example - use "%U" instead of "${uuid}" as you suggested?
Also, is your approach not necessarily limited? You can now think of a handful of variables you may want to pass, say root device, root partition, uuid, maybe MAC address etc. But the next user will need kernel args that you did not think of - so how do we proceed? Add all features anybody needs to that new code? That certainly does not scale. Or mix "%FOO" and "${foo}" style arguments? That's even worse. I really fail to see the benefits, I see only ugliness and problems.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Good manners are the settled medium of social, as specie is of
commercial, life; returns are equally expected for both.
- Lord Chesterfield _Letters to his Son_, 25 December 1753PATCH 11/11 bootm: Support string substitution in bootargs
Hi Wolfgang,
Quoted 17 lines · Wolfgang Denk
Dear Simon,
Quoted 7 lines · In message <CAPnjgZ1SfwRa_LXh0zu3Oug=GLEUQx5MdCCvqW90-FV5hvX9uw@mail.gmail.com>…
Quoted 3 lines
Yes, it takes one additional step, but it's simple and does not need extra code.
It is actually not simple, for three reasons:
1. With zboot the args come from the kernel setup.bin and must be modified
Don't use zboot, then. In my opinion, zboot is crap and should never have been added, but there were so many requests for it. Nevertheless, the use of crippleware is a sin that carries with it its own punishment.
Quoted 4 lines
Don't do it, then.
Or, if you feel there is some value in zboot that should be conserved, fix it to work like the rest of U-Boot.
Well my series does that to a large extent. It is much more like bootm now, in that it is properly split into stages. I think it would be possible to combine parts of it into bootm as a future step, although it is non-trivial, and I think we should build out more tests first.
But zboot does make use of an existing command line and does all the weird x86 processing, so I don't know how we could get rid of it.
Quoted 6 lines
Quoted 3 lines
2. With Chrome OS the args come from the kernel partition and must be augmented / substituted
OK. But then why can we not still use the standard variable substitution mechanism we already have?
I don't think the actual mechanism is a big deal. We could do a string replace (does U-Boot support that?) of %U with ${uuid} for example, to make it work for my case.
Or we could go with an idea I previously rejected, to just provide a simple string replace feature, with any special characters in the search string. For example:
setenv bootargs_repl "%U=${uuid} %P=${partid}"
Quoted 6 lines
Quoted 3 lines
3. The above command cannot be in the same env var as anything else, since substitution breaks in that case
Sorry, I don't understand what you mean heare. What is "the same env var" versus "anything else"? Maybe you can give a specific example?
Did you see the 'run regen_scripts' script?
At present I can do
setenv uuid blah; setenv partid blah; bootm
but with your scheme I need the 'run regen_script' to set the variables correctly, which is a real pain as my example shows.
Quoted 7 lines
Quoted 4 lines
So you end up with a really complicated mess of environment variables and scripts that is barely manageable. I want it to be simple.
Again, I can't follow you. Why must there be a mess?
Quoted 8 lines
Quoted 4 lines
See here for example (this only deals with 3 above, not 1 and 2, which would still need custom code without my series)
Sorry - all I see there is some complex settings if these make sense I can't tell) - but how would things be better if you could - for example - use "%U" instead of "${uuid}" as you suggested?
My point here is not about %U, it is about the pain of multiple stages to get the variables right. WIth bootargs substitution we can just set the variables and boot.
Quoted 9 lines
Also, is your approach not necessarily limited? You can now think of a handful of variables you may want to pass, say root device, root partition, uuid, maybe MAC address etc. But the next user will need kernel args that you did not think of - so how do we proceed? Add all features anybody needs to that new code? That certainly does not scale. Or mix "%FOO" and "${foo}" style arguments? That's even worse. I really fail to see the benefits, I see only ugliness and problems.
These scripts are board-specific, so each board can do what it likes here. But the nice thing is not having to manually build up the bootargs.
Can we step past the %U business? I think we can use the ${var} stuff with some substitution.
Regards,
Simon
PATCH 11/11 bootm: Support string substitution in bootargs
Dear Simon,
Quoted 5 lines · In message <CAPnjgZ2Vn3oWAHy71smw-+fRo28HUA0K32DP6FPoGtjtK3XoFQ@mail.gmail.com>…
Well my series does that to a large extent. It is much more like bootm now, in that it is properly split into stages. I think it would be possible to combine parts of it into bootm as a future step, although it is non-trivial, and I think we should build out more tests first.
Hm... I fear that this is rather cementing the zboot support so we never get rid of it...
Quoted 3 lines
But zboot does make use of an existing command line and does all the weird x86 processing, so I don't know how we could get rid of it.
How about a command that takes this existing command line and "imports" it into a standard bootargs variable?
Quoted 3 lines
I don't think the actual mechanism is a big deal. We could do a string replace (does U-Boot support that?) of %U with ${uuid} for example, to make it work for my case.
Yes, we can.
=> env print commandline bootargs
## Error: "commandline" not defined
## Error: "bootargs" not defined
=> env set commandline 'This is a %A test for %U replacement.' => setexpr bootargs gsub %A boring "${commandline}" bootargs=This is a boring test for %U replacement. => setexpr bootargs gsub %U '${uuid}'
bootargs=This is a boring test for ${uuid} replacement. => env print bootargs
bootargs=This is a boring test for ${uuid} replacement.
Quoted 3 lines
Or we could go with an idea I previously rejected, to just provide a simple string replace feature, with any special characters in the search string. For example:
But we have all this already, even with regular expressions and (simple) backreferences.
Quoted 11 lines
Quoted 2 lines
Sorry, I don't understand what you mean heare. What is "the same env var" versus "anything else"? Maybe you can give a specific example?
Did you see the 'run
regen_scripts' script?At present I can do
setenv uuid blah; setenv partid blah; bootm
but with your scheme I need the 'run
regen_script' to set the variables correctly, which is a real pain as my example shows.
Just insert a "run" there, and you are done with it.
Quoted 3 lines
My point here is not about %U, it is about the pain of multiple stages to get the variables right. WIth bootargs substitution we can just set the variables and boot.
I think this is not so much a bootargs question (or at least it should not be it). bootargs is just another environment variable without any specific properties except that it's content is being passed to the kerenl, so you want to have the needed variable substituion doen before that.
It was an intentional decison not to do this automagically, based on the thinking that accorsing to UNNIX philosophy it is not each individual command which implements things like wildcard or variable substitution, but rather this is something the shell does for you, and the commands are dumb in this respect. This works reasonably well, except that we don't pass bootargs as argument to the bootm command - rather it is done internally by default, this lacking the variable substituion.
You may call this a design bug, and I will accept the blame for it.
To me the obvious fix would be to correct this behavious such that we extend bootm to accept the bootargs argument as a command line parameter, thus enabling variable substitution there, too.
As far as I'm concenred, I don't think this is necessary as all it takes to work around this is a single call of a "run" command which can do exactly that, too.
But I agree, this is just a workaround, and it would be more consistent to pass bootargs as argument directly.
And this is also the direction I see how the zboot stuff should be
fixed: import the Linux command line into the environment, modify it as needed (if necessary using regular expression matching / string substituion to fix it up to use common U-Boot variable names), and then pass it like the rest of the world to the kernel.
Quoted 2 lines
Can we step past the %U business? I think we can use the ${var} stuff with some substitution.
Don't we have that already? What exactly is it you miss?
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Steal five dollars and you were a petty thief. Steal thousands of
dollars and you are either a government or a hero.
- Terry Pratchett, _Going_Postal_PATCH 11/11 bootm: Support string substitution in bootargs
Hi Wolfgang,
Quoted 97 lines · Wolfgang Denk
Dear Simon,
Quoted 5 lines · In message <CAPnjgZ2Vn3oWAHy71smw-+fRo28HUA0K32DP6FPoGtjtK3XoFQ@mail.gmail.com>…
Well my series does that to a large extent. It is much more like bootm now, in that it is properly split into stages. I think it would be possible to combine parts of it into bootm as a future step, although it is non-trivial, and I think we should build out more tests first.
Hm... I fear that this is rather cementing the zboot support so we never get rid of it...
Quoted 3 lines
But zboot does make use of an existing command line and does all the weird x86 processing, so I don't know how we could get rid of it.
How about a command that takes this existing command line and "imports" it into a standard bootargs variable?
Quoted 3 lines
I don't think the actual mechanism is a big deal. We could do a string replace (does U-Boot support that?) of %U with ${uuid} for example, to make it work for my case.
Yes, we can.
=> env print commandline bootargs
## Error: "commandline" not defined
## Error: "bootargs" not defined
=> env set commandline 'This is a %A test for %U replacement.' => setexpr bootargs gsub %A boring "${commandline}" bootargs=This is a boring test for %U replacement. => setexpr bootargs gsub %U '${uuid}'
bootargs=This is a boring test for ${uuid} replacement. => env print bootargs
bootargs=This is a boring test for ${uuid} replacement.Quoted 3 lines
Or we could go with an idea I previously rejected, to just provide a simple string replace feature, with any special characters in the search string. For example:
But we have all this already, even with regular expressions and (simple) backreferences.
Quoted 11 lines
Quoted 2 lines
Sorry, I don't understand what you mean heare. What is "the same env var" versus "anything else"? Maybe you can give a specific example?
Did you see the 'run
regen_scripts' script?At present I can do
setenv uuid blah; setenv partid blah; bootm
but with your scheme I need the 'run
regen_script' to set the variables correctly, which is a real pain as my example shows.Just insert a "run" there, and you are done with it.
Quoted 3 lines
My point here is not about %U, it is about the pain of multiple stages to get the variables right. WIth bootargs substitution we can just set the variables and boot.
I think this is not so much a bootargs question (or at least it should not be it). bootargs is just another environment variable without any specific properties except that it's content is being passed to the kerenl, so you want to have the needed variable substituion doen before that.
It was an intentional decison not to do this automagically, based on the thinking that accorsing to UNNIX philosophy it is not each individual command which implements things like wildcard or variable substitution, but rather this is something the shell does for you, and the commands are dumb in this respect. This works reasonably well, except that we don't pass bootargs as argument to the bootm command - rather it is done internally by default, this lacking the variable substituion.
You may call this a design bug, and I will accept the blame for it.
To me the obvious fix would be to correct this behavious such that we extend bootm to accept the bootargs argument as a command line parameter, thus enabling variable substitution there, too.
As far as I'm concenred, I don't think this is necessary as all it takes to work around this is a single call of a "run" command which can do exactly that, too.
But I agree, this is just a workaround, and it would be more consistent to pass bootargs as argument directly.
And this is also the direction I see how the zboot stuff should be
fixed: import the Linux command line into the environment, modify it as needed (if necessary using regular expression matching / string substituion to fix it up to use common U-Boot variable names), and then pass it like the rest of the world to the kernel.
Quoted 4 lines
Quoted 2 lines
Can we step past the %U business? I think we can use the ${var} stuff with some substitution.
Don't we have that already? What exactly is it you miss?
I have sent a new version of this series that uses ${var}.
Regards,
Simon
PATCH 11/11 bootm: Support string substitution in bootargs
In reply to Wolfgang DenkHi Wolfgang,
Quoted 17 lines · Wolfgang Denk
Dear Simon,
Quoted 6 lines · In message <[email protected]> you wrote:
In some cases it is necessary to pass parameters to Linux so that it will boot correctly. For example, the rootdev parameter is often used to specify the root device. However the root device may change depending on whence U-Boot loads the kernel. At present it is necessary to build up the command line by adding device strings to it one by one.
Quoted 6 lines
It is often more convenient to provide a template for bootargs, with U-Boot doing the substitution from other environment variables.
Add a way to substitute strings in the bootargs variable. This allows things like "rootdev=%U" to be used in bootargs, with the %U substitution providing the UUID of the root device.
Quoted 6 lines
Argh, no, please don't.
You add something unconditionally to common code which very few people need. U-Boot size is growing all the time because of such ... features. This may be acceptable on the systems you have in mind, but I consider this selfish.
Did you see the Kconfig option?
Quoted 4 lines
Why do we have to add yet another non-standard way of substituting variables in a string? Can we not use alreay existing methonds instead?
What sort of methods?
Quoted 3 lines
Why do you have to use "%U" in your template instead of for example "${uuid}" ?
This is what Chrome OS uses, so it is easier this way, Otherwise I have to replace %U with ${uuid} first.
Which code can I use to parse the ${var} thing?
Regards,
Simon
PATCH 11/11 bootm: Support string substitution in bootargs
Dear Simon,
Quoted 7 lines · In message <CAPnjgZ3sg693VXsEpvjnvkuUzfF612cxWvpWuvx_XiVNgQH4Jg@mail.gmail.com>…
Quoted 5 lines
You add something unconditionally to common code which very few people need. U-Boot size is growing all the time because of such ... features. This may be acceptable on the systems you have in mind, but I consider this selfish.
Did you see the
Kconfigoption?
So you claim the size does not grow with the feature not selected?
Quoted 5 lines
Quoted 3 lines
Why do we have to add yet another non-standard way of substituting variables in a string? Can we not use alreay existing methonds instead?
What sort of methods?
Variable substitution?
Quoted 5 lines
Quoted 2 lines
Why do you have to use "%U" in your template instead of for example "${uuid}" ?
This is what Chrome OS uses, so it is easier this way, Otherwise I have to replace %U with ${uuid} first.
That's what I meant when I wrote "selfish" ;-)
Quoted 1 line
Which code can I use to parse the ${var} thing?
setenv and run ?
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de My brother sent me a postcard the other day with this big sattelite photo of the entire earth on it. On the back it said: "Wish you were here". - Steven Wright
PATCH 11/11 bootm: Support string substitution in bootargs
Hi Wolfgang,
Quoted 5 lines · Wolfgang Denk
Dear Simon,
Quoted 1 line · In message <CAPnjgZ3sg693VXsEpvjnvkuUzfF612cxWvpWuvx_XiVNgQH4Jg@mail.gmail.com>…
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
You add something unconditionally to common code which very few people need. U-Boot size is growing all the time because of such ... features. This may be acceptable on the systems you have in mind, but I consider this selfish.
Did you see the
Kconfigoption?So you claim the size does not grow with the feature not selected?
That's what I see, except that there is some size growth due to the refactoring / adding tests.
Quoted 12 lines
Quoted 6 lines
Quoted 4 lines
Why do we have to add yet another non-standard way of substituting variables in a string? Can we not use alreay existing methonds instead?
What sort of methods?
Variable substitution?
Quoted 3 lines
Quoted 2 lines
Why do you have to use "%U" in your template instead of for example "${uuid}" ?
Quoted 8 lines
Quoted 2 lines
This is what Chrome OS uses, so it is easier this way, Otherwise I have to replace %U with ${uuid} first.
That's what I meant when I wrote "selfish" ;-)
Quoted 1 line
Which code can I use to parse the ${var} thing?
setenv and run ?
Will respond on other emails.
Regards,
SImon
cover bootm: Support substitions in bootargs and add tests
In reply to Simon GlassQuoted 11 lines · Simon Glass
This series adds tests to the fixup_silent-linux() function and extends the 'zimage' command to use it.
It also adds a new string-substition feature to allow bootargs to be a template, rather than having to build it up piece by piece with information obtained in a build script.
It also updates zimage to use the same command-line processing.
With these additions it is possible to boot Chrome OS from a U-Boot script on most Chromebooks.
Hello Simon,
could you, please, add a patch documenting the usage of the new string-substitution feature in the HTML documentation.
Best regards
Heinrich
Quoted 32 lines
Simon Glass (11):
env: Allow returning errors fromhdelete_r()
bootm: Add tests forfixup_silent_linux()
bootm: Updatefixup_silent_linux()to return an error
bootm: Renamefixup_silent_linux()
bootm: Add a bool parameter tobootm_process_cmdline_env()
bootm: Use size rather than length forCONSOLE_ARG
bootm: Split out bootargs environment reading / writing
bootm: Updatebootm_process_cmdline_env()to use flags
bootm: Allow updating the bootargs in a buffer
x86: zimage: Add silent-console processing
bootm: Support string substitution in bootargsREADME | 16 +++ arch/Kconfig | 2 + arch/x86/lib/zimage.c | 14 +++ cmd/nvedit.c | 6 +- common/Kconfig.boot | 20 ++++ common/bootm.c | 206 +++++++++++++++++++++++++++++------ include/bootm.h | 40 +++++++ include/search.h | 11 +- include/test/suites.h | 1 + lib/hashtable.c | 12 +-- test/Makefile | 1 + test/bootm.c | 243 ++++++++++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 1 + test/env/hashtable.c | 2 +- 14 files changed, 534 insertions(+), 41 deletions(-) create mode 100644 test/bootm.c
cover bootm: Support substitions in bootargs and add tests
Hi Heinrich,
Quoted 11 lines · Heinrich Schuchardt
Quoted 9 lines · Simon Glass
This series adds tests to the fixup_silent-linux() function and extends the 'zimage' command to use it.
It also adds a new string-substition feature to allow bootargs to be a template, rather than having to build it up piece by piece with information obtained in a build script.
It also updates zimage to use the same command-line processing.
Quoted 7 lines
Quoted 2 lines
With these additions it is possible to boot Chrome OS from a U-Boot script on most Chromebooks.
Hello Simon,
could you, please, add a patch documenting the usage of the new string-substitution feature in the HTML documentation.
OK will do. I meant to send this series three weeks ago and forgot about it...
Regards,
Simon