diff mbox series

distro_bootcmd: Add support for loading user environment

Message ID 20200131105917.10118-1-jonathanh@nvidia.com
State New
Headers show
Series distro_bootcmd: Add support for loading user environment | expand

Commit Message

Jon Hunter Jan. 31, 2020, 10:59 a.m. UTC
U-Boot supports loading a user environment from a file in the
file-system. Therefore to make it easier for users to override the
default environment, add support to the 'distro_bootcmd' to look for
and load a user environment in a file called 'uEnv.txt' in the same
locations where an extlinux.conf or boot script might be found.

Note that by importing the environment with the '-t' option, the current
environment is appended/updated rather than replaced completely.

Signed-off-by: Jon Hunter <jonathanh at nvidia.com>
---
 include/config_distro_bootcmd.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Soeren Moch Jan. 31, 2020, 12:42 p.m. UTC | #1
On 31.01.20 11:59, Jon Hunter wrote:
> U-Boot supports loading a user environment from a file in the
> file-system. Therefore to make it easier for users to override the
> default environment, add support to the 'distro_bootcmd' to look for
> and load a user environment in a file called 'uEnv.txt' in the same
> locations where an extlinux.conf or boot script might be found.

We already have boot script support, which can easily be used to modify
the environment. Do we really need to bloat the distro_boot machinery
further with environment import, that is quite limited in contrast to
boot scripts?

Soeren

> Note that by importing the environment with the '-t' option, the current
> environment is appended/updated rather than replaced completely.
>
> Signed-off-by: Jon Hunter <jonathanh at nvidia.com>
> ---
>  include/config_distro_bootcmd.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
> index fc0935fa21af..5607f382ad73 100644
> --- a/include/config_distro_bootcmd.h
> +++ b/include/config_distro_bootcmd.h
> @@ -422,6 +422,19 @@
>  	"boot_script_dhcp=boot.scr.uimg\0" \
>  	BOOTENV_BOOT_TARGETS \
>  	\
> +	"load_user_env="                                                  \
> +		"load ${devtype} ${devnum}:${distro_bootpart} "           \
> +			"${scriptaddr} ${prefix}uEnv.txt; "              \
> +		"env import -t ${scriptaddr} ${filesize}\0"               \
> +	\
> +	"scan_dev_for_user_env="                                          \
> +		"if test -e ${devtype} "                                  \
> +				"${devnum}:${distro_bootpart} "           \
> +				"${prefix}uEnv.txt; then "               \
> +			"echo Found ${prefix}uEnv.txt; "                 \
> +			"run load_user_env; "                             \
> +		"fi\0"                                                    \
> +	\
>  	"boot_syslinux_conf=extlinux/extlinux.conf\0" \
>  	"boot_extlinux="                                                  \
>  		"sysboot ${devtype} ${devnum}:${distro_bootpart} any "    \
> @@ -457,6 +470,7 @@
>  		"echo Scanning ${devtype} "                               \
>  				"${devnum}:${distro_bootpart}...; "       \
>  		"for prefix in ${boot_prefixes}; do "                     \
> +			"run scan_dev_for_user_env; "                     \
>  			"run scan_dev_for_extlinux; "                     \
>  			"run scan_dev_for_scripts; "                      \
>  		"done;"                                                   \
>
Jon Hunter Jan. 31, 2020, 1:24 p.m. UTC | #2
On 31/01/2020 12:42, Soeren Moch wrote:
> On 31.01.20 11:59, Jon Hunter wrote:
>> U-Boot supports loading a user environment from a file in the
>> file-system. Therefore to make it easier for users to override the
>> default environment, add support to the 'distro_bootcmd' to look for
>> and load a user environment in a file called 'uEnv.txt' in the same
>> locations where an extlinux.conf or boot script might be found.
> 
> We already have boot script support, which can easily be used to modify
> the environment. Do we really need to bloat the distro_boot machinery
> further with environment import, that is quite limited in contrast to
> boot scripts?

If you are booting with an extlinux.conf file, as we do by default, then
if this file is found, this is always booted from before you have the
opportunity to run the boot.scr script.

Furthermore if you did switch the order to boot from a boot.scr script
before the extlinux.conf, but you just wanted to do some simple
modifications of the environment before booting (ie. so the boot.scr
does not actually boot the system), then as the code is today you get a
'echo SCRIPT FAILED: continuing...' message.

Yes this could be changed, but just seems cleaner and simpler to add
support to make changes to the environment before the extlinux.conf is
loaded.

Yes this does add more to the environment, but it is hardly significant
bloat, but if that is a concern then we could always disable this by
default and allow users to enable it.

Jon
Tom Rini Jan. 31, 2020, 2:05 p.m. UTC | #3
On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
> 
> On 31/01/2020 12:42, Soeren Moch wrote:
> > On 31.01.20 11:59, Jon Hunter wrote:
> >> U-Boot supports loading a user environment from a file in the
> >> file-system. Therefore to make it easier for users to override the
> >> default environment, add support to the 'distro_bootcmd' to look for
> >> and load a user environment in a file called 'uEnv.txt' in the same
> >> locations where an extlinux.conf or boot script might be found.
> > 
> > We already have boot script support, which can easily be used to modify
> > the environment. Do we really need to bloat the distro_boot machinery
> > further with environment import, that is quite limited in contrast to
> > boot scripts?
> 
> If you are booting with an extlinux.conf file, as we do by default, then
> if this file is found, this is always booted from before you have the
> opportunity to run the boot.scr script.
> 
> Furthermore if you did switch the order to boot from a boot.scr script
> before the extlinux.conf, but you just wanted to do some simple
> modifications of the environment before booting (ie. so the boot.scr
> does not actually boot the system), then as the code is today you get a
> 'echo SCRIPT FAILED: continuing...' message.
> 
> Yes this could be changed, but just seems cleaner and simpler to add
> support to make changes to the environment before the extlinux.conf is
> loaded.
> 
> Yes this does add more to the environment, but it is hardly significant
> bloat, but if that is a concern then we could always disable this by
> default and allow users to enable it.

This is something I think we had talked about and rejected doing
initially.  Can you please expand on the use-case here, and why it's
perhaps not better handled via PREBOOT on some platforms?  Thanks!
Jon Hunter Jan. 31, 2020, 2:42 p.m. UTC | #4
On 31/01/2020 14:05, Tom Rini wrote:
> On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
>>
>> On 31/01/2020 12:42, Soeren Moch wrote:
>>> On 31.01.20 11:59, Jon Hunter wrote:
>>>> U-Boot supports loading a user environment from a file in the
>>>> file-system. Therefore to make it easier for users to override the
>>>> default environment, add support to the 'distro_bootcmd' to look for
>>>> and load a user environment in a file called 'uEnv.txt' in the same
>>>> locations where an extlinux.conf or boot script might be found.
>>>
>>> We already have boot script support, which can easily be used to modify
>>> the environment. Do we really need to bloat the distro_boot machinery
>>> further with environment import, that is quite limited in contrast to
>>> boot scripts?
>>
>> If you are booting with an extlinux.conf file, as we do by default, then
>> if this file is found, this is always booted from before you have the
>> opportunity to run the boot.scr script.
>>
>> Furthermore if you did switch the order to boot from a boot.scr script
>> before the extlinux.conf, but you just wanted to do some simple
>> modifications of the environment before booting (ie. so the boot.scr
>> does not actually boot the system), then as the code is today you get a
>> 'echo SCRIPT FAILED: continuing...' message.
>>
>> Yes this could be changed, but just seems cleaner and simpler to add
>> support to make changes to the environment before the extlinux.conf is
>> loaded.
>>
>> Yes this does add more to the environment, but it is hardly significant
>> bloat, but if that is a concern then we could always disable this by
>> default and allow users to enable it.
> 
> This is something I think we had talked about and rejected doing
> initially.  Can you please expand on the use-case here, and why it's
> perhaps not better handled via PREBOOT on some platforms?  Thanks!

We have one specific use-case in a downstream version of u-boot where we
store some parameters in the u-boot environment for tweaking the DT
firmware on boot [0]. Now there are cases where we do not wish to modify
DT at all and so want to clear these variables and I would like a way to
automate the re-configuration of the u-boot environment without the user
having to manually set these just by the presence of a uEnv.txt file on
the disk.

Admittedly, this particular use-case/scenario is not directly applicable
to the mainline u-boot branch as there is no support for these
environment variables for Tegra (yet). However, it seemed that this
change would have some value in upstream u-boot as well to allow the
user to change any default environment variables without having to
re-compile and hence, I decided submit this change here.

For example, if we wanted to tweak any of the default environment
variables that are currently in 'include/configs/tegra210-common.h' we
could. Now you may say if we are not tweaking these very often, then why
not recompile, and we could, but given that we have the ability to load
environment parameters from a file on disk, it seems as shame that in
the current boot flow there is no way to make use of this extremely
useful feature.

Cheers!
Jon

[0]
https://nv-tegra.nvidia.com/gitweb/?p=3rdparty/u-boot.git;a=blob;f=include/configs/tegra210-common.h;h=81a3a2a447efacf34227847997fcc50639f54999;hb=refs/heads/l4t/l4t-r32.3.1-v2016.07#l59
Tom Rini Jan. 31, 2020, 2:54 p.m. UTC | #5
On Fri, Jan 31, 2020 at 02:42:25PM +0000, Jon Hunter wrote:
> 
> On 31/01/2020 14:05, Tom Rini wrote:
> > On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
> >>
> >> On 31/01/2020 12:42, Soeren Moch wrote:
> >>> On 31.01.20 11:59, Jon Hunter wrote:
> >>>> U-Boot supports loading a user environment from a file in the
> >>>> file-system. Therefore to make it easier for users to override the
> >>>> default environment, add support to the 'distro_bootcmd' to look for
> >>>> and load a user environment in a file called 'uEnv.txt' in the same
> >>>> locations where an extlinux.conf or boot script might be found.
> >>>
> >>> We already have boot script support, which can easily be used to modify
> >>> the environment. Do we really need to bloat the distro_boot machinery
> >>> further with environment import, that is quite limited in contrast to
> >>> boot scripts?
> >>
> >> If you are booting with an extlinux.conf file, as we do by default, then
> >> if this file is found, this is always booted from before you have the
> >> opportunity to run the boot.scr script.
> >>
> >> Furthermore if you did switch the order to boot from a boot.scr script
> >> before the extlinux.conf, but you just wanted to do some simple
> >> modifications of the environment before booting (ie. so the boot.scr
> >> does not actually boot the system), then as the code is today you get a
> >> 'echo SCRIPT FAILED: continuing...' message.
> >>
> >> Yes this could be changed, but just seems cleaner and simpler to add
> >> support to make changes to the environment before the extlinux.conf is
> >> loaded.
> >>
> >> Yes this does add more to the environment, but it is hardly significant
> >> bloat, but if that is a concern then we could always disable this by
> >> default and allow users to enable it.
> > 
> > This is something I think we had talked about and rejected doing
> > initially.  Can you please expand on the use-case here, and why it's
> > perhaps not better handled via PREBOOT on some platforms?  Thanks!
> 
> We have one specific use-case in a downstream version of u-boot where we
> store some parameters in the u-boot environment for tweaking the DT
> firmware on boot [0]. Now there are cases where we do not wish to modify
> DT at all and so want to clear these variables and I would like a way to
> automate the re-configuration of the u-boot environment without the user
> having to manually set these just by the presence of a uEnv.txt file on
> the disk.
> 
> Admittedly, this particular use-case/scenario is not directly applicable
> to the mainline u-boot branch as there is no support for these
> environment variables for Tegra (yet). However, it seemed that this
> change would have some value in upstream u-boot as well to allow the
> user to change any default environment variables without having to
> re-compile and hence, I decided submit this change here.
> 
> For example, if we wanted to tweak any of the default environment
> variables that are currently in 'include/configs/tegra210-common.h' we
> could. Now you may say if we are not tweaking these very often, then why
> not recompile, and we could, but given that we have the ability to load
> environment parameters from a file on disk, it seems as shame that in
> the current boot flow there is no way to make use of this extremely
> useful feature.

I really think this is a good case for CONFIG_PREBOOT to execute a
script (and we have other examples of that today) rather than something
to put in to distro boot for everyone.  Thanks!
David Abdurachmanov Jan. 31, 2020, 2:58 p.m. UTC | #6
On Fri, Jan 31, 2020 at 3:42 PM Jon Hunter <jonathanh at nvidia.com> wrote:
>
>
> On 31/01/2020 14:05, Tom Rini wrote:
> > On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
> >>
> >> On 31/01/2020 12:42, Soeren Moch wrote:
> >>> On 31.01.20 11:59, Jon Hunter wrote:
> >>>> U-Boot supports loading a user environment from a file in the
> >>>> file-system. Therefore to make it easier for users to override the
> >>>> default environment, add support to the 'distro_bootcmd' to look for
> >>>> and load a user environment in a file called 'uEnv.txt' in the same
> >>>> locations where an extlinux.conf or boot script might be found.
> >>>
> >>> We already have boot script support, which can easily be used to modify
> >>> the environment. Do we really need to bloat the distro_boot machinery
> >>> further with environment import, that is quite limited in contrast to
> >>> boot scripts?
> >>
> >> If you are booting with an extlinux.conf file, as we do by default, then
> >> if this file is found, this is always booted from before you have the
> >> opportunity to run the boot.scr script.
> >>
> >> Furthermore if you did switch the order to boot from a boot.scr script
> >> before the extlinux.conf, but you just wanted to do some simple
> >> modifications of the environment before booting (ie. so the boot.scr
> >> does not actually boot the system), then as the code is today you get a
> >> 'echo SCRIPT FAILED: continuing...' message.
> >>
> >> Yes this could be changed, but just seems cleaner and simpler to add
> >> support to make changes to the environment before the extlinux.conf is
> >> loaded.
> >>
> >> Yes this does add more to the environment, but it is hardly significant
> >> bloat, but if that is a concern then we could always disable this by
> >> default and allow users to enable it.
> >
> > This is something I think we had talked about and rejected doing
> > initially.  Can you please expand on the use-case here, and why it's
> > perhaps not better handled via PREBOOT on some platforms?  Thanks!
>
> We have one specific use-case in a downstream version of u-boot where we
> store some parameters in the u-boot environment for tweaking the DT
> firmware on boot [0]. Now there are cases where we do not wish to modify
> DT at all and so want to clear these variables and I would like a way to
> automate the re-configuration of the u-boot environment without the user
> having to manually set these just by the presence of a uEnv.txt file on
> the disk.
>
> Admittedly, this particular use-case/scenario is not directly applicable
> to the mainline u-boot branch as there is no support for these
> environment variables for Tegra (yet). However, it seemed that this
> change would have some value in upstream u-boot as well to allow the
> user to change any default environment variables without having to
> re-compile and hence, I decided submit this change here.

>From Fedora/RISCV maintainer this sounds quite interesting. While
working on boot flow I do re-building U-Boot multiple times tweaking
the default environment (e.g. using preboot), but that's so annoying.
uEnv.txt would be a lot easier and probably easier to explain to users
who want to make quick modifications (as quick as modifying
extlinux.conf).

Also every time I re-build U-Boot I have to rebuild OpenSBI (which has
U-Boot as a payload right now).

>
> For example, if we wanted to tweak any of the default environment
> variables that are currently in 'include/configs/tegra210-common.h' we
> could. Now you may say if we are not tweaking these very often, then why
> not recompile, and we could, but given that we have the ability to load
> environment parameters from a file on disk, it seems as shame that in
> the current boot flow there is no way to make use of this extremely
> useful feature.
>
> Cheers!
> Jon
>
> [0]
> https://nv-tegra.nvidia.com/gitweb/?p=3rdparty/u-boot.git;a=blob;f=include/configs/tegra210-common.h;h=81a3a2a447efacf34227847997fcc50639f54999;hb=refs/heads/l4t/l4t-r32.3.1-v2016.07#l59
>
> --
> nvpublic
Tom Rini Jan. 31, 2020, 6:14 p.m. UTC | #7
On Fri, Jan 31, 2020 at 03:58:48PM +0100, David Abdurachmanov wrote:
> On Fri, Jan 31, 2020 at 3:42 PM Jon Hunter <jonathanh at nvidia.com> wrote:
> >
> >
> > On 31/01/2020 14:05, Tom Rini wrote:
> > > On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
> > >>
> > >> On 31/01/2020 12:42, Soeren Moch wrote:
> > >>> On 31.01.20 11:59, Jon Hunter wrote:
> > >>>> U-Boot supports loading a user environment from a file in the
> > >>>> file-system. Therefore to make it easier for users to override the
> > >>>> default environment, add support to the 'distro_bootcmd' to look for
> > >>>> and load a user environment in a file called 'uEnv.txt' in the same
> > >>>> locations where an extlinux.conf or boot script might be found.
> > >>>
> > >>> We already have boot script support, which can easily be used to modify
> > >>> the environment. Do we really need to bloat the distro_boot machinery
> > >>> further with environment import, that is quite limited in contrast to
> > >>> boot scripts?
> > >>
> > >> If you are booting with an extlinux.conf file, as we do by default, then
> > >> if this file is found, this is always booted from before you have the
> > >> opportunity to run the boot.scr script.
> > >>
> > >> Furthermore if you did switch the order to boot from a boot.scr script
> > >> before the extlinux.conf, but you just wanted to do some simple
> > >> modifications of the environment before booting (ie. so the boot.scr
> > >> does not actually boot the system), then as the code is today you get a
> > >> 'echo SCRIPT FAILED: continuing...' message.
> > >>
> > >> Yes this could be changed, but just seems cleaner and simpler to add
> > >> support to make changes to the environment before the extlinux.conf is
> > >> loaded.
> > >>
> > >> Yes this does add more to the environment, but it is hardly significant
> > >> bloat, but if that is a concern then we could always disable this by
> > >> default and allow users to enable it.
> > >
> > > This is something I think we had talked about and rejected doing
> > > initially.  Can you please expand on the use-case here, and why it's
> > > perhaps not better handled via PREBOOT on some platforms?  Thanks!
> >
> > We have one specific use-case in a downstream version of u-boot where we
> > store some parameters in the u-boot environment for tweaking the DT
> > firmware on boot [0]. Now there are cases where we do not wish to modify
> > DT at all and so want to clear these variables and I would like a way to
> > automate the re-configuration of the u-boot environment without the user
> > having to manually set these just by the presence of a uEnv.txt file on
> > the disk.
> >
> > Admittedly, this particular use-case/scenario is not directly applicable
> > to the mainline u-boot branch as there is no support for these
> > environment variables for Tegra (yet). However, it seemed that this
> > change would have some value in upstream u-boot as well to allow the
> > user to change any default environment variables without having to
> > re-compile and hence, I decided submit this change here.
> 
> From Fedora/RISCV maintainer this sounds quite interesting. While
> working on boot flow I do re-building U-Boot multiple times tweaking
> the default environment (e.g. using preboot), but that's so annoying.
> uEnv.txt would be a lot easier and probably easier to explain to users
> who want to make quick modifications (as quick as modifying
> extlinux.conf).
> 
> Also every time I re-build U-Boot I have to rebuild OpenSBI (which has
> U-Boot as a payload right now).

Can you not solve this by having CONFIG_PREBOOT load uEnv.txt?  I might
not have been clear enough that my suggestion was to do that before,
sorry.
Stephen Warren Jan. 31, 2020, 6:18 p.m. UTC | #8
On 1/31/20 7:54 AM, Tom Rini wrote:
> On Fri, Jan 31, 2020 at 02:42:25PM +0000, Jon Hunter wrote:
>>
>> On 31/01/2020 14:05, Tom Rini wrote:
>>> On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
>>>>
>>>> On 31/01/2020 12:42, Soeren Moch wrote:
>>>>> On 31.01.20 11:59, Jon Hunter wrote:
>>>>>> U-Boot supports loading a user environment from a file in the
>>>>>> file-system. Therefore to make it easier for users to override the
>>>>>> default environment, add support to the 'distro_bootcmd' to look for
>>>>>> and load a user environment in a file called 'uEnv.txt' in the same
>>>>>> locations where an extlinux.conf or boot script might be found.
>>>>>
>>>>> We already have boot script support, which can easily be used to modify
>>>>> the environment. Do we really need to bloat the distro_boot machinery
>>>>> further with environment import, that is quite limited in contrast to
>>>>> boot scripts?
>>>>
>>>> If you are booting with an extlinux.conf file, as we do by default, then
>>>> if this file is found, this is always booted from before you have the
>>>> opportunity to run the boot.scr script.
>>>>
>>>> Furthermore if you did switch the order to boot from a boot.scr script
>>>> before the extlinux.conf, but you just wanted to do some simple
>>>> modifications of the environment before booting (ie. so the boot.scr
>>>> does not actually boot the system), then as the code is today you get a
>>>> 'echo SCRIPT FAILED: continuing...' message.
>>>>
>>>> Yes this could be changed, but just seems cleaner and simpler to add
>>>> support to make changes to the environment before the extlinux.conf is
>>>> loaded.
>>>>
>>>> Yes this does add more to the environment, but it is hardly significant
>>>> bloat, but if that is a concern then we could always disable this by
>>>> default and allow users to enable it.
>>>
>>> This is something I think we had talked about and rejected doing
>>> initially.  Can you please expand on the use-case here, and why it's
>>> perhaps not better handled via PREBOOT on some platforms?  Thanks!
>>
>> We have one specific use-case in a downstream version of u-boot where we
>> store some parameters in the u-boot environment for tweaking the DT
>> firmware on boot [0]. Now there are cases where we do not wish to modify
>> DT at all and so want to clear these variables and I would like a way to
>> automate the re-configuration of the u-boot environment without the user
>> having to manually set these just by the presence of a uEnv.txt file on
>> the disk.
>>
>> Admittedly, this particular use-case/scenario is not directly applicable
>> to the mainline u-boot branch as there is no support for these
>> environment variables for Tegra (yet). However, it seemed that this
>> change would have some value in upstream u-boot as well to allow the
>> user to change any default environment variables without having to
>> re-compile and hence, I decided submit this change here.
>>
>> For example, if we wanted to tweak any of the default environment
>> variables that are currently in 'include/configs/tegra210-common.h' we
>> could. Now you may say if we are not tweaking these very often, then why
>> not recompile, and we could, but given that we have the ability to load
>> environment parameters from a file on disk, it seems as shame that in
>> the current boot flow there is no way to make use of this extremely
>> useful feature.
> 
> I really think this is a good case for CONFIG_PREBOOT to execute a
> script (and we have other examples of that today) rather than something
> to put in to distro boot for everyone.  Thanks!

I can definitely imagine there are many reasons a user might want to 
have a way to modify U-Boot's environment easily via creating/editing 
uEnv.txt rather than having to interactively run setenv/saveenv on the 
U-Boot console.

So, I think the main question is where to place uEnv.txt. If we use 
CONFIG_PREBOOT, we'd either have to:

a) Hard-code a single storage device to load it from, which involved 
deciding on a platform-by-platform basis which is the best location to 
load it from.

OR:

b) Duplicate the existing device scanning logic from the distro boot 
scripts into CONFIG_PREBOOT. I'd rather not see the duplication.

This patch achieves the auto-scanning for uEnv.txt without the 
disadvantage of (b) above. Also, it allows uEnv.txt to follow a 
removable storage device, which can have advantages. In the specific 
use-case Jon is working on, we'll want to edit the environment to 
disable some U-Boot features when using an upstream kernel, and not do 
that editing when booting a downstream kernel. On the particular 
platform Jon is using, the primary storage device is an SD card. If 
uEnv.txt can follow the SD card that'd be very useful. Of course, we 
could just hard-code the SD card as the location of uEnv.txt, but that 
wouldn't work well for systems that don't use removable media as the 
primary storage location (so we'd choose to look for uEnv.txt on e.g. 
fixed eMMC) yet the user has actually chosen to boot from SD card (which 
is earlier in boot_targets to allow booting from SD).

In summary, I think doing this in the distro boot commands probably does 
make sense.
Soeren Moch Jan. 31, 2020, 6:28 p.m. UTC | #9
On 31.01.20 19:18, Stephen Warren wrote:
> On 1/31/20 7:54 AM, Tom Rini wrote:
>> On Fri, Jan 31, 2020 at 02:42:25PM +0000, Jon Hunter wrote:
>>>
>>> On 31/01/2020 14:05, Tom Rini wrote:
>>>> On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
>>>>>
>>>>> On 31/01/2020 12:42, Soeren Moch wrote:
>>>>>> On 31.01.20 11:59, Jon Hunter wrote:
>>>>>>> U-Boot supports loading a user environment from a file in the
>>>>>>> file-system. Therefore to make it easier for users to override the
>>>>>>> default environment, add support to the 'distro_bootcmd' to look
>>>>>>> for
>>>>>>> and load a user environment in a file called 'uEnv.txt' in the same
>>>>>>> locations where an extlinux.conf or boot script might be found.
>>>>>>
>>>>>> We already have boot script support, which can easily be used to
>>>>>> modify
>>>>>> the environment. Do we really need to bloat the distro_boot
>>>>>> machinery
>>>>>> further with environment import, that is quite limited in
>>>>>> contrast to
>>>>>> boot scripts?
>>>>>
>>>>> If you are booting with an extlinux.conf file, as we do by
>>>>> default, then
>>>>> if this file is found, this is always booted from before you have the
>>>>> opportunity to run the boot.scr script.
>>>>>
>>>>> Furthermore if you did switch the order to boot from a boot.scr
>>>>> script
>>>>> before the extlinux.conf, but you just wanted to do some simple
>>>>> modifications of the environment before booting (ie. so the boot.scr
>>>>> does not actually boot the system), then as the code is today you
>>>>> get a
>>>>> 'echo SCRIPT FAILED: continuing...' message.
>>>>>
>>>>> Yes this could be changed, but just seems cleaner and simpler to add
>>>>> support to make changes to the environment before the
>>>>> extlinux.conf is
>>>>> loaded.
>>>>>
>>>>> Yes this does add more to the environment, but it is hardly
>>>>> significant
>>>>> bloat, but if that is a concern then we could always disable this by
>>>>> default and allow users to enable it.
>>>>
>>>> This is something I think we had talked about and rejected doing
>>>> initially.  Can you please expand on the use-case here, and why it's
>>>> perhaps not better handled via PREBOOT on some platforms?  Thanks!
>>>
>>> We have one specific use-case in a downstream version of u-boot
>>> where we
>>> store some parameters in the u-boot environment for tweaking the DT
>>> firmware on boot [0]. Now there are cases where we do not wish to
>>> modify
>>> DT at all and so want to clear these variables and I would like a
>>> way to
>>> automate the re-configuration of the u-boot environment without the
>>> user
>>> having to manually set these just by the presence of a uEnv.txt file on
>>> the disk.
>>>
>>> Admittedly, this particular use-case/scenario is not directly
>>> applicable
>>> to the mainline u-boot branch as there is no support for these
>>> environment variables for Tegra (yet). However, it seemed that this
>>> change would have some value in upstream u-boot as well to allow the
>>> user to change any default environment variables without having to
>>> re-compile and hence, I decided submit this change here.
>>>
>>> For example, if we wanted to tweak any of the default environment
>>> variables that are currently in 'include/configs/tegra210-common.h' we
>>> could. Now you may say if we are not tweaking these very often, then
>>> why
>>> not recompile, and we could, but given that we have the ability to load
>>> environment parameters from a file on disk, it seems as shame that in
>>> the current boot flow there is no way to make use of this extremely
>>> useful feature.
>>
>> I really think this is a good case for CONFIG_PREBOOT to execute a
>> script (and we have other examples of that today) rather than something
>> to put in to distro boot for everyone.  Thanks!
>
> I can definitely imagine there are many reasons a user might want to
> have a way to modify U-Boot's environment easily via creating/editing
> uEnv.txt rather than having to interactively run setenv/saveenv on the
> U-Boot console.
>
> So, I think the main question is where to place uEnv.txt. If we use
> CONFIG_PREBOOT, we'd either have to:
>
> a) Hard-code a single storage device to load it from, which involved
> deciding on a platform-by-platform basis which is the best location to
> load it from.
>
> OR:
>
> b) Duplicate the existing device scanning logic from the distro boot
> scripts into CONFIG_PREBOOT. I'd rather not see the duplication.
>
> This patch achieves the auto-scanning for uEnv.txt without the
> disadvantage of (b) above. Also, it allows uEnv.txt to follow a
> removable storage device, which can have advantages. In the specific
> use-case Jon is working on, we'll want to edit the environment to
> disable some U-Boot features when using an upstream kernel, and not do
> that editing when booting a downstream kernel. On the particular
> platform Jon is using, the primary storage device is an SD card. If
> uEnv.txt can follow the SD card that'd be very useful. Of course, we
> could just hard-code the SD card as the location of uEnv.txt, but that
> wouldn't work well for systems that don't use removable media as the
> primary storage location (so we'd choose to look for uEnv.txt on e.g.
> fixed eMMC) yet the user has actually chosen to boot from SD card
> (which is earlier in boot_targets to allow booting from SD).
>
> In summary, I think doing this in the distro boot commands probably
> does make sense.
Everything what you put into the config_distro_bootcmd.h include file
you can put as well in your board specific config file after including
this include file. If several boards want to use this uEnv logic, they
can create a separate include file for that.

Please do not bloat the distro_boot machinery with something that is not
part of what distros use to configure and boot the kernel.

Thanks,
Soeren
Tom Rini Jan. 31, 2020, 6:34 p.m. UTC | #10
On Fri, Jan 31, 2020 at 07:28:02PM +0100, Soeren Moch wrote:
> 
> 
> On 31.01.20 19:18, Stephen Warren wrote:
> > On 1/31/20 7:54 AM, Tom Rini wrote:
> >> On Fri, Jan 31, 2020 at 02:42:25PM +0000, Jon Hunter wrote:
> >>>
> >>> On 31/01/2020 14:05, Tom Rini wrote:
> >>>> On Fri, Jan 31, 2020 at 01:24:21PM +0000, Jon Hunter wrote:
> >>>>>
> >>>>> On 31/01/2020 12:42, Soeren Moch wrote:
> >>>>>> On 31.01.20 11:59, Jon Hunter wrote:
> >>>>>>> U-Boot supports loading a user environment from a file in the
> >>>>>>> file-system. Therefore to make it easier for users to override the
> >>>>>>> default environment, add support to the 'distro_bootcmd' to look
> >>>>>>> for
> >>>>>>> and load a user environment in a file called 'uEnv.txt' in the same
> >>>>>>> locations where an extlinux.conf or boot script might be found.
> >>>>>>
> >>>>>> We already have boot script support, which can easily be used to
> >>>>>> modify
> >>>>>> the environment. Do we really need to bloat the distro_boot
> >>>>>> machinery
> >>>>>> further with environment import, that is quite limited in
> >>>>>> contrast to
> >>>>>> boot scripts?
> >>>>>
> >>>>> If you are booting with an extlinux.conf file, as we do by
> >>>>> default, then
> >>>>> if this file is found, this is always booted from before you have the
> >>>>> opportunity to run the boot.scr script.
> >>>>>
> >>>>> Furthermore if you did switch the order to boot from a boot.scr
> >>>>> script
> >>>>> before the extlinux.conf, but you just wanted to do some simple
> >>>>> modifications of the environment before booting (ie. so the boot.scr
> >>>>> does not actually boot the system), then as the code is today you
> >>>>> get a
> >>>>> 'echo SCRIPT FAILED: continuing...' message.
> >>>>>
> >>>>> Yes this could be changed, but just seems cleaner and simpler to add
> >>>>> support to make changes to the environment before the
> >>>>> extlinux.conf is
> >>>>> loaded.
> >>>>>
> >>>>> Yes this does add more to the environment, but it is hardly
> >>>>> significant
> >>>>> bloat, but if that is a concern then we could always disable this by
> >>>>> default and allow users to enable it.
> >>>>
> >>>> This is something I think we had talked about and rejected doing
> >>>> initially.  Can you please expand on the use-case here, and why it's
> >>>> perhaps not better handled via PREBOOT on some platforms?  Thanks!
> >>>
> >>> We have one specific use-case in a downstream version of u-boot
> >>> where we
> >>> store some parameters in the u-boot environment for tweaking the DT
> >>> firmware on boot [0]. Now there are cases where we do not wish to
> >>> modify
> >>> DT at all and so want to clear these variables and I would like a
> >>> way to
> >>> automate the re-configuration of the u-boot environment without the
> >>> user
> >>> having to manually set these just by the presence of a uEnv.txt file on
> >>> the disk.
> >>>
> >>> Admittedly, this particular use-case/scenario is not directly
> >>> applicable
> >>> to the mainline u-boot branch as there is no support for these
> >>> environment variables for Tegra (yet). However, it seemed that this
> >>> change would have some value in upstream u-boot as well to allow the
> >>> user to change any default environment variables without having to
> >>> re-compile and hence, I decided submit this change here.
> >>>
> >>> For example, if we wanted to tweak any of the default environment
> >>> variables that are currently in 'include/configs/tegra210-common.h' we
> >>> could. Now you may say if we are not tweaking these very often, then
> >>> why
> >>> not recompile, and we could, but given that we have the ability to load
> >>> environment parameters from a file on disk, it seems as shame that in
> >>> the current boot flow there is no way to make use of this extremely
> >>> useful feature.
> >>
> >> I really think this is a good case for CONFIG_PREBOOT to execute a
> >> script (and we have other examples of that today) rather than something
> >> to put in to distro boot for everyone.  Thanks!
> >
> > I can definitely imagine there are many reasons a user might want to
> > have a way to modify U-Boot's environment easily via creating/editing
> > uEnv.txt rather than having to interactively run setenv/saveenv on the
> > U-Boot console.
> >
> > So, I think the main question is where to place uEnv.txt. If we use
> > CONFIG_PREBOOT, we'd either have to:
> >
> > a) Hard-code a single storage device to load it from, which involved
> > deciding on a platform-by-platform basis which is the best location to
> > load it from.
> >
> > OR:
> >
> > b) Duplicate the existing device scanning logic from the distro boot
> > scripts into CONFIG_PREBOOT. I'd rather not see the duplication.
> >
> > This patch achieves the auto-scanning for uEnv.txt without the
> > disadvantage of (b) above. Also, it allows uEnv.txt to follow a
> > removable storage device, which can have advantages. In the specific
> > use-case Jon is working on, we'll want to edit the environment to
> > disable some U-Boot features when using an upstream kernel, and not do
> > that editing when booting a downstream kernel. On the particular
> > platform Jon is using, the primary storage device is an SD card. If
> > uEnv.txt can follow the SD card that'd be very useful. Of course, we
> > could just hard-code the SD card as the location of uEnv.txt, but that
> > wouldn't work well for systems that don't use removable media as the
> > primary storage location (so we'd choose to look for uEnv.txt on e.g.
> > fixed eMMC) yet the user has actually chosen to boot from SD card
> > (which is earlier in boot_targets to allow booting from SD).
> >
> > In summary, I think doing this in the distro boot commands probably
> > does make sense.
> Everything what you put into the config_distro_bootcmd.h include file
> you can put as well in your board specific config file after including
> this include file. If several boards want to use this uEnv logic, they
> can create a separate include file for that.
> 
> Please do not bloat the distro_boot machinery with something that is not
> part of what distros use to configure and boot the kernel.

And making it easier to re-use chunks of environment logic is part of
what and why I want include/environment/.  Perhaps another starting
point here would be to make the scan logic reusable and placed somewhere
there so that it can be used in both PREBOOT options and distro boot and
elsewhere.

> 
> Thanks,
> Soeren
>
diff mbox series

Patch

diff --git a/include/config_distro_bootcmd.h b/include/config_distro_bootcmd.h
index fc0935fa21af..5607f382ad73 100644
--- a/include/config_distro_bootcmd.h
+++ b/include/config_distro_bootcmd.h
@@ -422,6 +422,19 @@ 
 	"boot_script_dhcp=boot.scr.uimg\0" \
 	BOOTENV_BOOT_TARGETS \
 	\
+	"load_user_env="                                                  \
+		"load ${devtype} ${devnum}:${distro_bootpart} "           \
+			"${scriptaddr} ${prefix}uEnv.txt; "              \
+		"env import -t ${scriptaddr} ${filesize}\0"               \
+	\
+	"scan_dev_for_user_env="                                          \
+		"if test -e ${devtype} "                                  \
+				"${devnum}:${distro_bootpart} "           \
+				"${prefix}uEnv.txt; then "               \
+			"echo Found ${prefix}uEnv.txt; "                 \
+			"run load_user_env; "                             \
+		"fi\0"                                                    \
+	\
 	"boot_syslinux_conf=extlinux/extlinux.conf\0" \
 	"boot_extlinux="                                                  \
 		"sysboot ${devtype} ${devnum}:${distro_bootpart} any "    \
@@ -457,6 +470,7 @@ 
 		"echo Scanning ${devtype} "                               \
 				"${devnum}:${distro_bootpart}...; "       \
 		"for prefix in ${boot_prefixes}; do "                     \
+			"run scan_dev_for_user_env; "                     \
 			"run scan_dev_for_extlinux; "                     \
 			"run scan_dev_for_scripts; "                      \
 		"done;"                                                   \