Skip to contentSkip to conversation

u-boot: Provide tasks to generate default U-Boot environment(s) images

PATCH Superseded Lukasz Majewski 3 participants 5 messages Jul 9, 2019 – Jul 11, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 u-boot: Provide tasks to generate default U-Boot environment(s) images

This change provides tasks to generate default U-Boot environment images from built U-Boot (via. get_default_envs.sh script).

Those images then can be used to generate wic images (with e.g. eMMC layout). With such approach the end user doesn't see the "CRC environment" error after the first boot.

Moreover, those are built per MACHINE (as u-boot itself is) so then could be used in SWUpdate scenarios with single tar'ed archive with multiple MACHINE specific *.swu images.

It is also possible to adjust the *_ENVS_* variables in machine specific conf file.

Test:
Newest master-next for poky repo - SHA1: eb5b0a0b5e53a6e55a09e66489d3f24d0c6232ee MACHINE = "beaglebone-yocto" in local.conf
bitbake virtual/bootloader

As a result following links are available in deploy directory:
u-boot-env.img{_r}.

---
 meta/recipes-bsp/u-boot/u-boot.inc | 41 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
meta/recipes-bsp/u-boot/u-boot.inc +41 -0
index 9a754fd09b..e0ccf1ce1f 100644
@@ -331,3 +331,44 @@ do_deploy () {
 }
 
 addtask deploy before do_build after do_compile
+
+# Extract default envs from build U-Boot
+DEFAULT_UBOOT_ENVS_FILE ?= "u-boot-env"
+DEFAULT_ENVS ?= "${DEFAULT_UBOOT_ENVS_FILE}.txt"
+UBOOT_ENVS_DEFAULT ?= "${DEFAULT_UBOOT_ENVS_FILE}-${MACHINE}-${PV}-${PR}.img"
+UBOOT_ENVS_SIZE ?= "65536"
+
+# Generate default environment
+do_gen_default_envs[doc] = "Generate image with default U-Boot environment(s)"
+do_gen_default_envs () {
+    ${B}/source/scripts/get_default_envs.sh ${B} > ${B}/${DEFAULT_ENVS}
+
+    # Generate env image
+    ${B}/tools/mkenvimage -s ${UBOOT_ENVS_SIZE} -o ${B}/${UBOOT_ENVS_DEFAULT} ${B}/${DEFAULT_ENVS}
+
+    # Generate redundant env image
+    ${B}/tools/mkenvimage -r -s ${UBOOT_ENVS_SIZE} -o ${B}/${UBOOT_ENVS_DEFAULT}_r ${B}/${DEFAULT_ENVS}
+
+    rm ${B}/${DEFAULT_ENVS}
+}
+
+addtask gen_default_envs before do_deploy after do_compile
+
+# Deploy default environment
+do_deploy_default_envs[doc] = "Copy images with default U-Boot environment to deployment directory"
+do_deploy_default_envs () {
+
+     install -d ${DEPLOYDIR}
+
+     install ${B}/${UBOOT_ENVS_DEFAULT} ${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}
+     install ${B}/${UBOOT_ENVS_DEFAULT}_r ${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}_r
+
+     cd ${DEPLOYDIR}
+     ln -sf ${UBOOT_ENVS_DEFAULT} ${DEFAULT_UBOOT_ENVS_FILE}.img
+     ln -sf ${UBOOT_ENVS_DEFAULT}_r ${DEFAULT_UBOOT_ENVS_FILE}.img_r
+
+     rm ${B}/${UBOOT_ENVS_DEFAULT}
+     rm ${B}/${UBOOT_ENVS_DEFAULT}_r
+}
+
+addtask deploy_default_envs before do_deploy after do_gen_default_envs
Signature · 1 line
2.11.0
#1 lore raw
Quoted 67 lines · Lukasz Majewski

This change provides tasks to generate default U-Boot environment images from built U-Boot (via. get_default_envs.sh script).

Those images then can be used to generate wic images (with e.g. eMMC layout). With such approach the end user doesn't see the "CRC environment" error after the first boot.

Moreover, those are built per MACHINE (as u-boot itself is) so then could be used in SWUpdate scenarios with single tar'ed archive with multiple MACHINE specific *.swu images.

It is also possible to adjust the *_ENVS_* variables in machine specific conf file.

Test:
Newest master-next for poky repo - SHA1: eb5b0a0b5e53a6e55a09e66489d3f24d0c6232ee MACHINE = "beaglebone-yocto" in local.conf
bitbake virtual/bootloader

As a result following links are available in deploy directory:
u-boot-env.img{_r}.

---
 meta/recipes-bsp/u-boot/u-boot.inc | 41 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
meta/recipes-bsp/u-boot/u-boot.inc +31 -0
index 9a754fd09b..e0ccf1ce1f 100644
@@ -331,3 +331,44 @@ do_deploy () {
 }
 
 addtask deploy before do_build after do_compile
+
+# Extract default envs from build U-Boot
+DEFAULT_UBOOT_ENVS_FILE ?= "u-boot-env"
+DEFAULT_ENVS ?= "${DEFAULT_UBOOT_ENVS_FILE}.txt"
+UBOOT_ENVS_DEFAULT ?= "${DEFAULT_UBOOT_ENVS_FILE}-${MACHINE}-${PV}-${PR}.img"
+UBOOT_ENVS_SIZE ?= "65536"
+
+# Generate default environment
+do_gen_default_envs[doc] = "Generate image with default U-Boot environment(s)"
+do_gen_default_envs () {
+    ${B}/source/scripts/get_default_envs.sh ${B} > ${B}/${DEFAULT_ENVS}
+
+    # Generate env image
+    ${B}/tools/mkenvimage -s ${UBOOT_ENVS_SIZE} -o ${B}/${UBOOT_ENVS_DEFAULT} ${B}/${DEFAULT_ENVS}
+
+    # Generate redundant env image
+    ${B}/tools/mkenvimage -r -s ${UBOOT_ENVS_SIZE} -o ${B}/${UBOOT_ENVS_DEFAULT}_r ${B}/${DEFAULT_ENVS}
+
+    rm ${B}/${DEFAULT_ENVS}
+}
+
+addtask gen_default_envs before do_deploy after do_compile
+
+# Deploy default environment
+do_deploy_default_envs[doc] = "Copy images with default U-Boot environment to deployment directory"
+do_deploy_default_envs () {
+
+     install -d ${DEPLOYDIR}
+
+     install ${B}/${UBOOT_ENVS_DEFAULT} ${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}
+     install ${B}/${UBOOT_ENVS_DEFAULT}_r ${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}_r

meta/recipes-bsp/u-boot/u-boot.inc do_deploy () { · line 374

Quoted 10 lines
meta/recipes-bsp/u-boot/u-boot.inc +10 -0
+
+     cd ${DEPLOYDIR}
+     ln -sf ${UBOOT_ENVS_DEFAULT} ${DEFAULT_UBOOT_ENVS_FILE}.img
+     ln -sf ${UBOOT_ENVS_DEFAULT}_r ${DEFAULT_UBOOT_ENVS_FILE}.img_r
+
+     rm ${B}/${UBOOT_ENVS_DEFAULT}
+     rm ${B}/${UBOOT_ENVS_DEFAULT}_r
+}
+
+addtask deploy_default_envs before do_deploy after do_gen_default_envs

I'm not sure this second function/task is right.

DEPLOYDIR is really "owned" by the do_deploy function. As such, if you rerun the deploy task, it should be recreated with the right content.

By default I appreciate that deploy.bbclass doesn't wipe out the directory but it probably should to make it clear what the expectations are here.

I don't think it would cause a real problem right now, until files changed names or something in one of these tasks, then you'd end up with files you didn't expect since nothing ever cleans this directory.

Is there a reason we can't make this part of do_deploy and clean the directory at the start of do_deploy?

Cheers,

Richard

#2 lore raw

Hi Richard,

Quoted 91 lines · Lukasz Majewski
Quoted 79 lines

This change provides tasks to generate default U-Boot environment images from built U-Boot (via. get_default_envs.sh script).

Those images then can be used to generate wic images (with e.g. eMMC layout). With such approach the end user doesn't see the "CRC environment" error after the first boot.

Moreover, those are built per MACHINE (as u-boot itself is) so then could be used in SWUpdate scenarios with single tar'ed archive with multiple MACHINE specific *.swu images.

It is also possible to adjust the *_ENVS_* variables in machine specific conf file.

Test:
Newest master-next for poky repo - SHA1:
eb5b0a0b5e53a6e55a09e66489d3f24d0c6232ee MACHINE = "beaglebone-yocto" in local.conf bitbake virtual/bootloader

As a result following links are available in deploy directory:
u-boot-env.img{_r}.

---
 meta/recipes-bsp/u-boot/u-boot.inc | 41

++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)

(quoted diff) +0 -0

b/meta/recipes-bsp/u-boot/u-boot.inc index 9a754fd09b..e0ccf1ce1f 100644 --- a/meta/recipes-bsp/u-boot/u-boot.inc
+++ b/meta/recipes-bsp/u-boot/u-boot.inc

meta/recipes-bsp/u-boot/u-boot.inc +5 -0
@@ -331,3 +331,44 @@ do_deploy () {
 }
 
 addtask deploy before do_build after do_compile
+
+# Extract default envs from build U-Boot
+DEFAULT_UBOOT_ENVS_FILE ?= "u-boot-env"
+DEFAULT_ENVS ?= "${DEFAULT_UBOOT_ENVS_FILE}.txt"
+UBOOT_ENVS_DEFAULT ?=

"${DEFAULT_UBOOT_ENVS_FILE}-${MACHINE}-${PV}-${PR}.img"

(quoted diff) +3 -0
+UBOOT_ENVS_SIZE ?= "65536" +
+# Generate default environment
+do_gen_default_envs[doc] = "Generate image with default U-Boot

environment(s)" +do_gen_default_envs () {
+ ${B}/source/scripts/get_default_envs.sh ${B} >
${B}/${DEFAULT_ENVS} +

(quoted diff) +2 -0
+    # Generate env image
+    ${B}/tools/mkenvimage -s ${UBOOT_ENVS_SIZE} -o

${B}/${UBOOT_ENVS_DEFAULT} ${B}/${DEFAULT_ENVS} +

(quoted diff) +2 -0
+    # Generate redundant env image
+    ${B}/tools/mkenvimage -r -s ${UBOOT_ENVS_SIZE} -o

${B}/${UBOOT_ENVS_DEFAULT}_r ${B}/${DEFAULT_ENVS} +

meta/recipes-bsp/u-boot/u-boot.inc +7 -0
+    rm ${B}/${DEFAULT_ENVS}
+}
+
+addtask gen_default_envs before do_deploy after do_compile
+
+# Deploy default environment
+do_deploy_default_envs[doc] = "Copy images with default U-Boot

environment to deployment directory" +do_deploy_default_envs () {

meta/recipes-bsp/u-boot/u-boot.inc +4 -0
+
+     install -d ${DEPLOYDIR}
+
+     install ${B}/${UBOOT_ENVS_DEFAULT}

${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}
+ install ${B}/${UBOOT_ENVS_DEFAULT}_r
${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}_r +

meta/recipes-bsp/u-boot/u-boot.inc +3 -0
+     cd ${DEPLOYDIR}
+     ln -sf ${UBOOT_ENVS_DEFAULT} ${DEFAULT_UBOOT_ENVS_FILE}.img
+     ln -sf ${UBOOT_ENVS_DEFAULT}_r

${DEFAULT_UBOOT_ENVS_FILE}.img_r +

meta/recipes-bsp/u-boot/u-boot.inc +5 -0
+     rm ${B}/${UBOOT_ENVS_DEFAULT}
+     rm ${B}/${UBOOT_ENVS_DEFAULT}_r
+}
+
+addtask deploy_default_envs before do_deploy after
Quoted 1 line

do_gen_default_envs

I'm not sure this second function/task is right.

DEPLOYDIR is really "owned" by the do_deploy function. As such, if you rerun the deploy task, it should be recreated with the right content.

By default I appreciate that deploy.bbclass doesn't wipe out the directory but it probably should to make it clear what the expectations are here.

Quoted 6 lines

I don't think it would cause a real problem right now, until files changed names or something in one of these tasks, then you'd end up with files you didn't expect since nothing ever cleans this directory.

Is there a reason we can't make this part of do_deploy and clean the directory at the start of do_deploy?

The only reason was to have more readable code - as it is easier to read separate tasks.

Another issue is that this code shall probably be optional, so I would need to make this feature somehow dependent on some flag ...

Any good suggestions? PACKAGECONFIG seems like a good starting point ?

Quoted 8 lines

Cheers,

Richard

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#3 lore raw
In reply to Lukasz Majewski
Quoted 10 lines · Lukasz Majewski

This change provides tasks to generate default U-Boot environment images from built U-Boot (via. get_default_envs.sh script).

Those images then can be used to generate wic images (with e.g. eMMC layout). With such approach the end user doesn't see the "CRC environment" error after the first boot.

Moreover, those are built per MACHINE (as u-boot itself is) so then could be used in SWUpdate scenarios with single tar'ed archive with multiple MACHINE specific *.swu images.

I like this idea.

Quoted 3 lines

It is also possible to adjust the *_ENVS_* variables in machine specific conf file.

Can you give an example on how that is done or what it would look like?

I have been using this class I created a while back to do just that

https://github.com/akuster/meta-odroid/blob/master/classes/uboot-boot-scr.bbclass

- armin

Quoted 63 lines

Test:
Newest master-next for poky repo - SHA1: eb5b0a0b5e53a6e55a09e66489d3f24d0c6232ee MACHINE = "beaglebone-yocto" in local.conf
bitbake virtual/bootloader

As a result following links are available in deploy directory:
u-boot-env.img{_r}.

---
 meta/recipes-bsp/u-boot/u-boot.inc | 41 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
meta/recipes-bsp/u-boot/u-boot.inc +41 -0
index 9a754fd09b..e0ccf1ce1f 100644
@@ -331,3 +331,44 @@ do_deploy () {
 }
 
 addtask deploy before do_build after do_compile
+
+# Extract default envs from build U-Boot
+DEFAULT_UBOOT_ENVS_FILE ?= "u-boot-env"
+DEFAULT_ENVS ?= "${DEFAULT_UBOOT_ENVS_FILE}.txt"
+UBOOT_ENVS_DEFAULT ?= "${DEFAULT_UBOOT_ENVS_FILE}-${MACHINE}-${PV}-${PR}.img"
+UBOOT_ENVS_SIZE ?= "65536"
+
+# Generate default environment
+do_gen_default_envs[doc] = "Generate image with default U-Boot environment(s)"
+do_gen_default_envs () {
+    ${B}/source/scripts/get_default_envs.sh ${B} > ${B}/${DEFAULT_ENVS}
+
+    # Generate env image
+    ${B}/tools/mkenvimage -s ${UBOOT_ENVS_SIZE} -o ${B}/${UBOOT_ENVS_DEFAULT} ${B}/${DEFAULT_ENVS}
+
+    # Generate redundant env image
+    ${B}/tools/mkenvimage -r -s ${UBOOT_ENVS_SIZE} -o ${B}/${UBOOT_ENVS_DEFAULT}_r ${B}/${DEFAULT_ENVS}
+
+    rm ${B}/${DEFAULT_ENVS}
+}
+
+addtask gen_default_envs before do_deploy after do_compile
+
+# Deploy default environment
+do_deploy_default_envs[doc] = "Copy images with default U-Boot environment to deployment directory"
+do_deploy_default_envs () {
+
+     install -d ${DEPLOYDIR}
+
+     install ${B}/${UBOOT_ENVS_DEFAULT} ${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}
+     install ${B}/${UBOOT_ENVS_DEFAULT}_r ${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}_r
+
+     cd ${DEPLOYDIR}
+     ln -sf ${UBOOT_ENVS_DEFAULT} ${DEFAULT_UBOOT_ENVS_FILE}.img
+     ln -sf ${UBOOT_ENVS_DEFAULT}_r ${DEFAULT_UBOOT_ENVS_FILE}.img_r
+
+     rm ${B}/${UBOOT_ENVS_DEFAULT}
+     rm ${B}/${UBOOT_ENVS_DEFAULT}_r
+}
+
+addtask deploy_default_envs before do_deploy after do_gen_default_envs
#4 lore raw

Hi,

Quoted 11 lines · Lukasz Majewski
Quoted 10 lines

This change provides tasks to generate default U-Boot environment images from built U-Boot (via. get_default_envs.sh script).

Those images then can be used to generate wic images (with e.g. eMMC layout). With such approach the end user doesn't see the "CRC environment" error after the first boot.

Moreover, those are built per MACHINE (as u-boot itself is) so then could be used in SWUpdate scenarios with single tar'ed archive with multiple MACHINE specific *.swu images.

Quoted 8 lines

I like this idea.

Quoted 3 lines

It is also possible to adjust the *_ENVS_* variables in machine specific conf file.

Can you give an example on how that is done or what it would look like?

This code simply needs to have defined:

UBOOT_ENVS_SIZE in machine conf if two machines use different medium for storing the envs (e.g. NAND vs SPI-NOR).

Quoted 5 lines

I have been using this class I created a while back to do just that

https://github.com/akuster/meta-odroid/blob/master/classes/uboot-boot-scr.bbclass

It seems like your class builds the envs from provided values.

Just a hint it is now possible with u-boot to "create" at build time envs with data provided from a simple text file.

The patch here just extracts default envs from build u-boot.

Part of the wic script:

part u-boot-env --source rawcopy --sourceparams="file=u-boot-env.img" --ondisk mmcblk --no-table --align 1024

part u-boot-env-r --source rawcopy --sourceparams="file=u-boot-env.img_r" --ondisk mmcblk --no-table --align
1032

Quoted 61 lines

- armin

Quoted 58 lines

Test:
Newest master-next for poky repo - SHA1:
eb5b0a0b5e53a6e55a09e66489d3f24d0c6232ee MACHINE = "beaglebone-yocto" in local.conf bitbake virtual/bootloader

As a result following links are available in deploy directory:
u-boot-env.img{_r}.

---
 meta/recipes-bsp/u-boot/u-boot.inc | 41

++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)

(quoted diff) +0 -0

b/meta/recipes-bsp/u-boot/u-boot.inc index 9a754fd09b..e0ccf1ce1f 100644 --- a/meta/recipes-bsp/u-boot/u-boot.inc
+++ b/meta/recipes-bsp/u-boot/u-boot.inc

meta/recipes-bsp/u-boot/u-boot.inc +5 -0
@@ -331,3 +331,44 @@ do_deploy () {
 }
 
 addtask deploy before do_build after do_compile
+
+# Extract default envs from build U-Boot
+DEFAULT_UBOOT_ENVS_FILE ?= "u-boot-env"
+DEFAULT_ENVS ?= "${DEFAULT_UBOOT_ENVS_FILE}.txt"
+UBOOT_ENVS_DEFAULT ?=

"${DEFAULT_UBOOT_ENVS_FILE}-${MACHINE}-${PV}-${PR}.img"

(quoted diff) +3 -0
+UBOOT_ENVS_SIZE ?= "65536" +
+# Generate default environment
+do_gen_default_envs[doc] = "Generate image with default U-Boot

environment(s)" +do_gen_default_envs () {
+ ${B}/source/scripts/get_default_envs.sh ${B} >
${B}/${DEFAULT_ENVS} +

(quoted diff) +2 -0
+    # Generate env image
+    ${B}/tools/mkenvimage -s ${UBOOT_ENVS_SIZE} -o

${B}/${UBOOT_ENVS_DEFAULT} ${B}/${DEFAULT_ENVS} +

(quoted diff) +2 -0
+    # Generate redundant env image
+    ${B}/tools/mkenvimage -r -s ${UBOOT_ENVS_SIZE} -o

${B}/${UBOOT_ENVS_DEFAULT}_r ${B}/${DEFAULT_ENVS} +

meta/recipes-bsp/u-boot/u-boot.inc +7 -0
+    rm ${B}/${DEFAULT_ENVS}
+}
+
+addtask gen_default_envs before do_deploy after do_compile
+
+# Deploy default environment
+do_deploy_default_envs[doc] = "Copy images with default U-Boot

environment to deployment directory" +do_deploy_default_envs () {

meta/recipes-bsp/u-boot/u-boot.inc +4 -0
+
+     install -d ${DEPLOYDIR}
+
+     install ${B}/${UBOOT_ENVS_DEFAULT}

${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}
+ install ${B}/${UBOOT_ENVS_DEFAULT}_r
${DEPLOYDIR}/${UBOOT_ENVS_DEFAULT}_r +

meta/recipes-bsp/u-boot/u-boot.inc +2 -0
+     cd ${DEPLOYDIR}
+     ln -sf ${UBOOT_ENVS_DEFAULT} ${DEFAULT_UBOOT_ENVS_FILE}.img
Quoted 10 lines
Quoted 8 lines

+ ln -sf ${UBOOT_ENVS_DEFAULT}_r
${DEFAULT_UBOOT_ENVS_FILE}.img_r +

meta/recipes-bsp/u-boot/u-boot.inc +5 -0
+     rm ${B}/${UBOOT_ENVS_DEFAULT}
+     rm ${B}/${UBOOT_ENVS_DEFAULT}_r
+}
+
+addtask deploy_default_envs before do_deploy after

do_gen_default_envs

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]