[U-Boot] warp7: Fix U-Boot corruption after saving the environment
diff mbox series

Message ID 20191021142258.16071-1-festevam@gmail.com
State New
Delegated to: Stefano Babic
Headers show
Series
  • [U-Boot] warp7: Fix U-Boot corruption after saving the environment
Related show

Commit Message

Fabio Estevam Oct. 21, 2019, 2:22 p.m. UTC
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.

Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 include/configs/warp7.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Pierre-Jean Texier Oct. 21, 2019, 4:43 p.m. UTC | #1
Hello Fabio,

Le 21/10/2019 à 16:22, Fabio Estevam a écrit :
> 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@30860000
Out:   serial@30860000
Err:   serial@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

>      
> 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.
> 
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>   include/configs/warp7.h | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/include/configs/warp7.h b/include/configs/warp7.h
> index 73541fe176..d103567cf4 100644
> --- a/include/configs/warp7.h
> +++ b/include/configs/warp7.h
> @@ -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
>
Fabio Estevam Oct. 21, 2019, 4:50 p.m. UTC | #2
Hi Pierre-Jean,

On Mon, Oct 21, 2019 at 1:43 PM Pierre-Jean Texier <pjtexier@koncepto.io> wrote:

> 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.
Pierre-Jean Texier Oct. 21, 2019, 5:12 p.m. UTC | #3
Fabio,

Le 21/10/2019 à 18:50, Fabio Estevam a écrit :
> Hi Pierre-Jean,
> 
> On Mon, Oct 21, 2019 at 1:43 PM Pierre-Jean Texier <pjtexier@koncepto.io> wrote:
> 
>> 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 :/

> 
> 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.

> 
> 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,

Acked-by: Pierre-Jean Texier <pjtexier@koncepto.io>
Tested-by: Pierre-Jean Texier <pjtexier@koncepto.io>

Thanks !

Regards
Joris Offouga Oct. 21, 2019, 5:32 p.m. UTC | #4
Hi Fabio, Pierre-Jean

Le 21/10/2019 à 19:12, Pierre-Jean Texier a écrit :
> Fabio,
>
> Le 21/10/2019 à 18:50, Fabio Estevam a écrit :
>> Hi Pierre-Jean,
>>
>> On Mon, Oct 21, 2019 at 1:43 PM Pierre-Jean Texier 
>> <pjtexier@koncepto.io> wrote:
>>
>>> 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 :/
Same for me
>
>>
>> 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.
>
>>
>> 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 ;)
>
> So,
>
> Acked-by: Pierre-Jean Texier <pjtexier@koncepto.io>
> Tested-by: Pierre-Jean Texier <pjtexier@koncepto.io>

Acked-by: Joris Offouga <offougajoris@gmail.com>

Tested-by: Joris Offouga <offougajoris@gmail.com>

Best regards,

Joris


>
> Thanks !
>
> Regards
>

Patch
diff mbox series

diff --git a/include/configs/warp7.h b/include/configs/warp7.h
index 73541fe176..d103567cf4 100644
--- a/include/configs/warp7.h
+++ b/include/configs/warp7.h
@@ -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