Skip to contentSkip to conversation

warp7: Fix U-Boot corruption after saving the environment

PATCH New Fabio Estevam 4 participants 7 messages Oct 21, 2019 – Nov 27, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" followed by a "reset" causes U-Boot to hang because of this overlap.

Fix this problem by increasing the CONFIG_ENV_OFFSET size.

Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.

CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.

---
 include/configs/warp7.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
include/configs/warp7.h +12 -1
index 73541fe176..d103567cf4 100644
@@ -132,7 +132,18 @@
 /* environment organization */
 #define CONFIG_ENV_SIZE			SZ_8K
 
-#define CONFIG_ENV_OFFSET		(8 * SZ_64K)
+/* Environment starts at 768k = 768 * 1024 = 786432 */
+#define CONFIG_ENV_OFFSET		786432
+/*
+ * Detect overlap between U-Boot image and environment area in build-time
+ *
+ * CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-dtb.imx offset
+ * CONFIG_BOARD_SIZE_LIMIT = 768k - 1k = 767k = 785408
+ *
+ * Currently CONFIG_BOARD_SIZE_LIMIT does not handle expressions, so
+ * write the direct value here
+ */
+#define CONFIG_BOARD_SIZE_LIMIT		785408
 #define CONFIG_SYS_FSL_USDHC_NUM	1
 
 #define CONFIG_SYS_MMC_ENV_DEV		0
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

Hello Fabio,

Le 21/10/2019 à 16:22, Fabio Estevam a écrit :

Quoted 5 lines

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" followed by a "reset" causes U-Boot to hang because of this overlap.

On top-of master 32ded50 ("spl: mmc: make eMMC HW boot partition configuration optional ")
I am not able to reproduce the described behavior.

See above:
---------

=> env set foo bar
=> env save
Saving Environment to MMC... Writing to MMC(0)... OK => reset
resetting ...

U-Boot 2019.10-00750-g32ded50 (Oct 21 2019 - 17:42:20 +0200)

CPU:   Freescale i.MX7S rev1.2 800 MHz (running at 792 MHz)
CPU:   Extended Commercial temperature grade (-20C to 105C) at 41C
Reset cause: POR
Model: Warp i.MX7 Board
Board: WARP7 in secure mode OPTEE DRAM 0x9d000000-0xa0000000
DRAM:  464 MiB
MMC:   FSL_SDHC: 1, FSL_SDHC: 0
Loading Environment from MMC... OK
In:    serial at 30860000
Out:   serial at 30860000
Err:   serial at 30860000
SEC0: RNG instantiated
Net:   usb_ether
Warning: usb_ether (eth0) using random MAC address - 4a:fd:63:75:a8:29

Hit any key to stop autoboot: 0
switch to partitions #0, OK
mmc0(part 0) is current device
switch to partitions #0, OK
mmc0(part 0) is current device
8417416 bytes read in 125 ms (64.2 MiB/s)
Booting from mmc ...
29058 bytes read in 11 ms (2.5 MiB/s)
Kernel image @ 0x80800000 [ 0x000000 - 0x807088 ]
## Flattened Device Tree blob at 83000000

    Booting using the fdt blob at 0x83000000
    Using Device Tree in place at 83000000, end 8300a181

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0

Did you change anything in your configuration?

Thanks !

Pierre-Jean

Quoted 39 lines

Fix this problem by increasing the CONFIG_ENV_OFFSET size.

Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.

CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.

---
  include/configs/warp7.h | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
include/configs/warp7.h +12 -1
index 73541fe176..d103567cf4 100644
@@ -132,7 +132,18 @@
  /* environment organization */
  #define CONFIG_ENV_SIZE			SZ_8K
 
-#define CONFIG_ENV_OFFSET		(8 * SZ_64K)
+/* Environment starts at 768k = 768 * 1024 = 786432 */
+#define CONFIG_ENV_OFFSET		786432
+/*
+ * Detect overlap between U-Boot image and environment area in build-time
+ *
+ * CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-dtb.imx offset
+ * CONFIG_BOARD_SIZE_LIMIT = 768k - 1k = 767k = 785408
+ *
+ * Currently CONFIG_BOARD_SIZE_LIMIT does not handle expressions, so
+ * write the direct value here
+ */
+#define CONFIG_BOARD_SIZE_LIMIT		785408
  #define CONFIG_SYS_FSL_USDHC_NUM	1
 
  #define CONFIG_SYS_MMC_ENV_DEV		0
Signature · 3 lines
Pierre-Jean Texier
Embedded Linux Engineer
https://koncepto.io
#2 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

Hi Pierre-Jean,

Quoted 3 lines · Pierre-Jean Texier

On top-of master 32ded50 ("spl: mmc: make eMMC HW boot partition configuration optional ")
I am not able to reproduce the described behavior.

I used u-boot-imx tree and this is what I get:

ls -al u-boot-dtb.imx
-rw-r--r-- 1 fabio fabio 547840 out 21 13:45 u-boot-dtb.imx

Original CONFIG_ENV_OFFSET is:
#define CONFIG_ENV_OFFSET (8 * SZ_64K)

CONFIG_ENV_OFFSET = 8 * 64 * 1024 = 524288

So the u-boot-dtb.imx is overlapping the env region.

Maybe your compiler is producing a smaller binary and you are not getting the issue.

Anyway, it is safer to increase CONFIG_ENV_OFFSET and use CONFIG_BOARD_SIZE_LIMIT to detect such problem in build-time.

#3 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

Fabio,

Le 21/10/2019 à 18:50, Fabio Estevam a écrit :

Quoted 4 lines

Hi Pierre-Jean,

On Mon, Oct 21, 2019 at 1:43 PM Pierre-Jean Texier <[email protected]> wrote:

Quoted 8 lines
Quoted 3 lines

On top-of master 32ded50 ("spl: mmc: make eMMC HW boot partition configuration optional ")
I am not able to reproduce the described behavior.

I used u-boot-imx tree and this is what I get:

ls -al u-boot-dtb.imx
-rw-r--r-- 1 fabio fabio 547840 out 21 13:45 u-boot-dtb.imx

Same for me, but I can't reproduce this issue :/

Quoted 7 lines

Original CONFIG_ENV_OFFSET is:
#define CONFIG_ENV_OFFSET (8 * SZ_64K)

CONFIG_ENV_OFFSET = 8 * 64 * 1024 = 524288

So the u-boot-dtb.imx is overlapping the env region.

Indeed.

Quoted 7 lines

Maybe your compiler is producing a smaller binary and you are not getting the issue.

Anyway, it is safer to increase CONFIG_ENV_OFFSET and use CONFIG_BOARD_SIZE_LIMIT to detect such problem in build-time.

You're right, I agree with that ;)

So,

Thanks !

Regards

Signature · 3 lines
Pierre-Jean Texier
Embedded Linux Engineer
https://koncepto.io
#4 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

Hi Fabio, Pierre-Jean

Le 21/10/2019 à 19:12, Pierre-Jean Texier a écrit :

Quoted 12 lines

Fabio,

Le 21/10/2019 à 18:50, Fabio Estevam a écrit :

Quoted 9 lines

Hi Pierre-Jean,

Quoted 3 lines · Pierre-Jean Texier

On top-of master 32ded50 ("spl: mmc: make eMMC HW boot partition configuration optional ")
I am not able to reproduce the described behavior.

Quoted 6 lines
Quoted 4 lines

I used u-boot-imx tree and this is what I get:

ls -al u-boot-dtb.imx
-rw-r--r-- 1 fabio fabio 547840 out 21 13:45 u-boot-dtb.imx

Same for me, but I can't reproduce this issue :/

Same for me

Quoted 12 lines
Quoted 8 lines

Original CONFIG_ENV_OFFSET is:
#define CONFIG_ENV_OFFSET (8 * SZ_64K)

CONFIG_ENV_OFFSET = 8 * 64 * 1024 = 524288

So the u-boot-dtb.imx is overlapping the env region.

Indeed.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

Maybe your compiler is producing a smaller binary and you are not getting the issue.

Anyway, it is safer to increase CONFIG_ENV_OFFSET and use CONFIG_BOARD_SIZE_LIMIT to detect such problem in build-time.

You're right, I agree with that ;)

I agree with you ;)

Quoted 5 lines

So,

Best regards,

Joris

Quoted 5 lines

Thanks !

Regards

#5 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

In reply to Fabio Estevam

Hi Stefano,

Quoted 9 lines · Fabio Estevam

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" followed by a "reset" causes U-Boot to hang because of this overlap.

Fix this problem by increasing the CONFIG_ENV_OFFSET size.

Quoted 7 lines

Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.

CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.

Can we get this one for 2020.01?

Thanks

#6 lore raw

PATCH 1/1 warp7: Fix U-Boot corruption after saving the environment

Quoted 15 lines · Fabio Estevam

Hi Stefano,

Quoted 12 lines · Fabio Estevam

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" followed by a "reset" causes U-Boot to hang because of this overlap.

Fix this problem by increasing the CONFIG_ENV_OFFSET size.

Also, in order to prevent this same problem in the future, use CONFIG_BOARD_SIZE_LIMIT, which will detect the overlap in build-time.

Quoted 7 lines
Quoted 4 lines

CONFIG_BOARD_SIZE_LIMIT does not accept math expressions, so declare CONFIG_ENV_OFFSET with its direct value instead.

Can we get this one for 2020.01?

I'll pick up it.

Stefano

Quoted 2 lines

Thanks

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================