diff mbox series

boot/uboot: add initial environment support

Message ID 20190519191635.23814-1-michael@walle.cc
State Changes Requested
Headers show
Series boot/uboot: add initial environment support | expand

Commit Message

Michael Walle May 19, 2019, 7:16 p.m. UTC
Since v2019.07 U-Boot supports extracting the compiled-in environment.
As a first step, add support to the environment generation in buildroot.
In the future, the text file may also be injected into the target
filesystem.

Signed-off-by: Michael Walle <michael@walle.cc>
---

Future u-boot versions will support this. Getting support into buildroot as
soon as possible would be cool.

 boot/uboot/Config.in | 13 +++++++++++++
 boot/uboot/uboot.mk  | 17 ++++++++++++++++-
 2 files changed, 29 insertions(+), 1 deletion(-)

Comments

Thomas Petazzoni May 26, 2019, 7:50 p.m. UTC | #1
Hello Michael,

Thanks for this patch! See below a number of comments.

On Sun, 19 May 2019 21:16:35 +0200
Michael Walle <michael@walle.cc> wrote:

> Since v2019.07 U-Boot supports extracting the compiled-in environment.
> As a first step, add support to the environment generation in buildroot.
> In the future, the text file may also be injected into the target
> filesystem.

I'm not sure what you mean by "injected into the target filesystem".
How would this be useful ? U-Boot would pick the environment from the
root filesystem ?

> diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
> index 33b7e67ff7..92f00bf752 100644
> --- a/boot/uboot/Config.in
> +++ b/boot/uboot/Config.in
> @@ -488,7 +488,19 @@ menuconfig BR2_TARGET_UBOOT_ENVIMAGE
>  	  The environment image will be called uboot-env.bin.
>  
>  if BR2_TARGET_UBOOT_ENVIMAGE
> +choice
> +	prompt "Environment image source"
> +	default BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
> +
> +config BR2_TARGET_UBOOT_ENVIMAGE_INITIAL
> +	bool "Using the initial environment file"

I'm not a fan of the "initial" terminology, although admittedly it's
the one apparently chosen upstream. "built-in" would be a lot more
logical, no ?

Also, I think this option needs a help text that describes what it
does, and the fact that it only works with U-Boot >= 2019.07.

> +config BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
> +	bool "Using a custom environment file"

Ditto, a help text would be good.

Other than that, looks good to me. Could you just fix those minor
details and send an updated version ?

Thanks,

Thomas
Michael Walle May 27, 2019, 12:13 p.m. UTC | #2
Hi Thomas,

Am 2019-05-26 21:50, schrieb Thomas Petazzoni:
> Hello Michael,
> 
> Thanks for this patch! See below a number of comments.

Thanks for the review ;)

> On Sun, 19 May 2019 21:16:35 +0200
> Michael Walle <michael@walle.cc> wrote:
> 
>> Since v2019.07 U-Boot supports extracting the compiled-in environment.
>> As a first step, add support to the environment generation in 
>> buildroot.
>> In the future, the text file may also be injected into the target
>> filesystem.
> 
> I'm not sure what you mean by "injected into the target filesystem".
> How would this be useful ? U-Boot would pick the environment from the
> root filesystem ?

Traditionally, both the u-boot and the fw_env tools (uboot-tools) had 
the
same compiled-in environment. That approach falls short, if the u-boot
and its tools are compiled sperately (like with distributions). So
the distribution uboot-tools have just the standard compiled-in
envionment, which doesn't match the one from the bootloader. If the
bootloader didn't find an saved environment (there may be other cases,
too), it will fall back to the compiled-in one. Same does the tools,
but they will fall back to a different one..

See the original commit here:
http://git.denx.de/?p=u-boot.git;a=commit;h=bdaa73a5b3923257add182b4ab8058dbfa33421b

The tools doesn't make use of that at the moment. But I'd imagine having
the text file in the filesystem like the config.gz of the linux kernel.

But as I've already mentioned, the file can already be used to generate 
a
flash image which has the u-boot environment pre-set.


>> diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
>> index 33b7e67ff7..92f00bf752 100644
>> --- a/boot/uboot/Config.in
>> +++ b/boot/uboot/Config.in
>> @@ -488,7 +488,19 @@ menuconfig BR2_TARGET_UBOOT_ENVIMAGE
>>  	  The environment image will be called uboot-env.bin.
>> 
>>  if BR2_TARGET_UBOOT_ENVIMAGE
>> +choice
>> +	prompt "Environment image source"
>> +	default BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
>> +
>> +config BR2_TARGET_UBOOT_ENVIMAGE_INITIAL
>> +	bool "Using the initial environment file"
> 
> I'm not a fan of the "initial" terminology, although admittedly it's
> the one apparently chosen upstream. "built-in" would be a lot more
> logical, no ?

Yes, and tbh I'd prefer the build-in, too. But then its harder to match
the terms if someone is familiar with u-boot. Its your choice.

> Also, I think this option needs a help text that describes what it
> does, and the fact that it only works with U-Boot >= 2019.07.

Ok. If we use BUILT_IN above, we could clarify here, that the term in
u-boot is "initial environment file".

>> +config BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
>> +	bool "Using a custom environment file"
> 
> Ditto, a help text would be good.

Ok.

> Other than that, looks good to me. Could you just fix those minor
> details and send an updated version ?

Sure, I'll send it this evening, given that you choose one of the two
options above until then ;)

-michael
diff mbox series

Patch

diff --git a/boot/uboot/Config.in b/boot/uboot/Config.in
index 33b7e67ff7..92f00bf752 100644
--- a/boot/uboot/Config.in
+++ b/boot/uboot/Config.in
@@ -488,7 +488,19 @@  menuconfig BR2_TARGET_UBOOT_ENVIMAGE
 	  The environment image will be called uboot-env.bin.
 
 if BR2_TARGET_UBOOT_ENVIMAGE
+choice
+	prompt "Environment image source"
+	default BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
+
+config BR2_TARGET_UBOOT_ENVIMAGE_INITIAL
+	bool "Using the initial environment file"
+
+config BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
+	bool "Using a custom environment file"
+
+endchoice
 
+if BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
 config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
 	string "Source files for environment"
 	help
@@ -497,6 +509,7 @@  config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
 	  lines starting with a # are ignored.
 
 	  Multiple source files are concatenated in the order listed.
+endif # BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
 
 config BR2_TARGET_UBOOT_ENVIMAGE_SIZE
 	string "Size of environment"
diff --git a/boot/uboot/uboot.mk b/boot/uboot/uboot.mk
index ae09c37d84..2ecf74036e 100644
--- a/boot/uboot/uboot.mk
+++ b/boot/uboot/uboot.mk
@@ -271,9 +271,22 @@  define UBOOT_BUILD_OMAP_IFT
 endef
 
 ifneq ($(BR2_TARGET_UBOOT_ENVIMAGE),)
-define UBOOT_GENERATE_ENV_IMAGE
+ifeq ($(BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM),y)
+define UBOOT_CREATE_ENV_SOURCE
 	cat $(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SOURCE)) \
 		>$(@D)/buildroot-env.txt
+endef
+endif
+
+ifeq ($(BR2_TARGET_UBOOT_ENVIMAGE_INITIAL),y)
+UBOOT_MAKE_TARGET += u-boot-initial-env
+define UBOOT_CREATE_ENV_SOURCE
+	cp -dpf $(@D)/u-boot-initial-env $(@D)/buildroot-env.txt
+endef
+endif
+
+define UBOOT_GENERATE_ENV_IMAGE
+	$(UBOOT_CREATE_ENV_SOURCE)
 	$(HOST_DIR)/bin/mkenvimage -s $(BR2_TARGET_UBOOT_ENVIMAGE_SIZE) \
 		$(if $(BR2_TARGET_UBOOT_ENVIMAGE_REDUNDANT),-r) \
 		$(if $(filter "BIG",$(BR2_ENDIAN)),-b) \
@@ -385,9 +398,11 @@  endef
 
 ifeq ($(BR2_TARGET_UBOOT_ENVIMAGE),y)
 ifeq ($(BR_BUILDING),y)
+ifeq ($(BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM),y)
 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SOURCE)),)
 $(error Please define a source file for Uboot environment (BR2_TARGET_UBOOT_ENVIMAGE_SOURCE setting))
 endif
+endif
 ifeq ($(call qstrip,$(BR2_TARGET_UBOOT_ENVIMAGE_SIZE)),)
 $(error Please provide Uboot environment size (BR2_TARGET_UBOOT_ENVIMAGE_SIZE setting))
 endif