Skip to contentSkip to conversation

boot/uboot: add initial environment support

PATCH Superseded Michael Walle 3 participants 6 messages May 27, 2019 – Nov 7, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 boot/uboot: add initial environment support

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 copied into the target filesystem, where it will be used by the uboot-tools.

---

changes since v1:
- rename _INITIAL to _BUILTIN
- add help texts
- make commit message little bit more clearer, hopefully ;)

 boot/uboot/Config.in | 24 ++++++++++++++++++++++++
 boot/uboot/uboot.mk  | 17 ++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)
boot/uboot/Config.in +24 -0
index 33b7e67ff7..45bbf88b6f 100644
@@ -488,7 +488,30 @@ 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_BUILTIN
+	bool "Using uboot's built-in environment file"
+	help
+	  Select this option if you want to build the image from
+	  u-boot's built-in environment. The content will be the
+	  same as the default environment of the u-boot binary.
+
+	  This feature requires commit
+	  bdaa73a5b3923257add182b4ab8058dbfa33421b from upstream
+	  U-Boot, available from versions 2019.07 or later.
+
+config BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
+	bool "Using a custom environment file"
+	help
+	  Select this option if you want to specify your own
+	  custom environment file.
+
+endchoice
 
+if BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
 config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
 	string "Source files for environment"
 	help
@@ -497,6 +520,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"
boot/uboot/uboot.mk +16 -1
index ae09c37d84..0da1f37cbd 100644
@@ -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_BUILTIN),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
Signature · 1 line
2.11.0
#1 lore raw

PATCH v2 1/1 boot/uboot: add initial environment support

Hi,

Le 27/05/2019 ? 21:23, Michael Walle a ?crit?:

Quoted 4 lines

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 copied into the target filesystem, where it will be used by the uboot-tools.

In fact, u-boot-initial-env file can also be used
by SWUpdate [1] and libubootenv [2] now ;).

Quoted 86 lines

---

changes since v1:
- rename _INITIAL to _BUILTIN
- add help texts
- make commit message little bit more clearer, hopefully ;)

  boot/uboot/Config.in | 24 ++++++++++++++++++++++++
  boot/uboot/uboot.mk  | 17 ++++++++++++++++-
  2 files changed, 40 insertions(+), 1 deletion(-)
boot/uboot/Config.in +24 -0
index 33b7e67ff7..45bbf88b6f 100644
@@ -488,7 +488,30 @@ 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_BUILTIN
+	bool "Using uboot's built-in environment file"
+	help
+	  Select this option if you want to build the image from
+	  u-boot's built-in environment. The content will be the
+	  same as the default environment of the u-boot binary.
+
+	  This feature requires commit
+	  bdaa73a5b3923257add182b4ab8058dbfa33421b from upstream
+	  U-Boot, available from versions 2019.07 or later.
+
+config BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
+	bool "Using a custom environment file"
+	help
+	  Select this option if you want to specify your own
+	  custom environment file.
+
+endchoice
 
+if BR2_TARGET_UBOOT_ENVIMAGE_CUSTOM
  config BR2_TARGET_UBOOT_ENVIMAGE_SOURCE
  	string "Source files for environment"
  	help
@@ -497,6 +520,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"
boot/uboot/uboot.mk +14 -1
index ae09c37d84..0da1f37cbd 100644
@@ -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_BUILTIN),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
 

boot/uboot/uboot.mk endef · line 408

Quoted 10 lines
boot/uboot/uboot.mk +2 -0
  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

Otherwise, tested on NXP WaRP7 with BR2_TARGET_UBOOT_ENVIMAGE_BUILTIN config option.
Setup : U-Boot master and libubootenv package (buildroot -next).

[1] -
https://github.com/sbabic/swupdate/blob/fa06a75f3d8b3a58fedf4d5d036c526062c74386/bootloader/uboot.c#L130
[2] -
https://github.com/sbabic/libubootenv/blob/master/src/fw_printenv.c#L125

Signature · 2 lines
Best regards,
Pierre-Jean Texier
#2 lore raw

PATCH v2 1/1 boot/uboot: add initial environment support

In reply to Michael Walle

Am 2019-05-27 21:23, schrieb Michael Walle:

Quoted 6 lines

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 copied into the target filesystem, where it will be used by the uboot-tools.

Quoted 8 lines

---

changes since v1:
- rename _INITIAL to _BUILTIN
- add help texts
- make commit message little bit more clearer, hopefully ;)

ping? :)

-michael

#3 lore raw

PATCH v2 1/1 boot/uboot: add initial environment support

Am 2019-06-16 14:37, schrieb Michael Walle:

Quoted 10 lines

Am 2019-05-27 21:23, schrieb Michael Walle:

Quoted 9 lines

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 copied into the target filesystem, where it will be used by the uboot-tools.

---

Quoted 7 lines
Quoted 5 lines

changes since v1:
- rename _INITIAL to _BUILTIN
- add help texts
- make commit message little bit more clearer, hopefully ;)

ping? :)

ping? ? :)

-michael

#4 lore raw

PATCH v2 1/1 boot/uboot: add initial environment support

In reply to Michael Walle

Hello Michael,

Quoted 7 lines · On Mon, 27 May 2019 21:23:42 +0200 Michael Walle <[email protected]> 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 copied into the target filesystem, where it will be used by the uboot-tools.

---

This feature was in the mean time added in uboot.mk, in a slightly different form, but it does the same thing.

See:

https://git.buildroot.org/buildroot/commit/?id=2c8ff251cb16d38fb417a488ee0367cd03eebda2

Could you check if it works for you as well?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH v2 1/1 boot/uboot: add initial environment support

Hi Thomas,

Am 2019-10-27 20:38, schrieb Thomas Petazzoni:

Quoted 12 lines
Quoted 8 lines

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 copied into the target filesystem, where it will be used by the uboot-tools.

---

This feature was in the mean time added in uboot.mk, in a slightly different form, but it does the same thing.

Quoted 6 lines

See:

https://git.buildroot.org/buildroot/commit/?id=2c8ff251cb16d38fb417a488ee0367cd03eebda2

Could you check if it works for you as well?

Yes that works too. We're actually already using it.

-michael