Hi Rasmus, On Mon, 19 Oct 2020 at 08:43, Rasmus Villemoes <rasmus.villem...@prevas.dk> wrote: > > On 19/10/2020 15.56, Simon Glass 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. > > > > 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. > > > > Signed-off-by: Simon Glass <s...@chromium.org> > > --- > > > > 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(-) > > > > diff --git a/README b/README > > index 91c5a1a8fa3..263e31ab7f6 100644 > > --- a/README > > +++ b/README > > @@ -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 > > 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.
Yes, thanks, will fix. > > 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. 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