Skip to contentSkip to conversation

Some more env fixes

PATCH In review Marek Behún 4 participants 47 messages Oct 22, 2021 – Nov 18, 2021

lore
Share & tools
lore
#0 lore raw

cover Some more env fixes

From: Marek Behún <[email protected]>

Hello Tom, Simon and others,

here are some various fixes for env. More are to follow after this, the code is horrible and I want to implement something there.

Marek Behún (14):
env: sf: Cosmetic fix in env_sf_init_addr()
env: sf: Use ENV_VALID enum names instead of literals
env: sf: Put ENV_INVALID into gd->env_valid on CRC failure
env: nand: Put ENV_INVALID into gd->env_valid if default environment
env: nvram: Let generic env_init() assign default environment
env: nvram: Cosmetic fix in env_nvram_init()
env: nowhere: Let generic env_init() assign default environment
env: nowhere: Cosmetic fix
env: flash: Let generic env_init() assign default environment
env: flash: Cosmetic fix
board: synquacer: developerbox: Don't set gd->env_addr to
default_environment
board: freescale: various boards: Let env subsystem set gd->env_addr
env: Always use char for default_environment
env: Use static_assert() to check if default_environment is too large

 board/Marvell/mvebu_armada-37xx/board.c     |  2 +-
 board/freescale/ls1012afrdm/ls1012afrdm.c   |  4 ----
 board/freescale/ls1012aqds/ls1012aqds.c     |  4 ----
 board/freescale/ls1012ardb/ls1012ardb.c     |  4 ----
 board/freescale/ls1028a/ls1028a.c           |  4 ----
 board/freescale/ls1088a/ls1088a.c           |  4 ----
 board/freescale/ls2080aqds/ls2080aqds.c     |  3 ---
 board/freescale/ls2080ardb/ls2080ardb.c     |  3 ---
 board/freescale/lx2160a/lx2160a.c           |  3 ---
 board/socionext/developerbox/developerbox.c |  2 --
 env/common.c                                | 11 +++--------
 env/flash.c                                 |  5 +----
 env/nand.c                                  |  3 +--
 env/nowhere.c                               |  5 ++---
 env/nvram.c                                 |  7 +++----
 env/sf.c                                    |  7 +++----
 include/env_default.h                       | 10 ++++++++--
 include/env_internal.h                      |  4 ++--
 18 files changed, 24 insertions(+), 61 deletions(-)
Signature · 1 line
2.32.0
#1 lore raw

PATCH 1/14 env: sf: Cosmetic fix in env_sf_init_addr()

From: Marek Behún <[email protected]>

In the if clause we use tabs and in the else clause spaces. Let's use spaces in the if clause too.

---
 env/sf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
env/sf.c +2 -2
index e4b7ca9e04..4096e18387 100644
@@ -338,8 +338,8 @@ static int env_sf_init_addr(void)
 	env_t *env_ptr = (env_t *)env_sf_get_env_addr();
 
 	if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
-		gd->env_addr	= (ulong)&(env_ptr->data);
-		gd->env_valid	= 1;
+		gd->env_addr = (ulong)&(env_ptr->data);
+		gd->env_valid = 1;
 	} else {
 		gd->env_addr = (ulong)&default_environment[0];
 		gd->env_valid = 1;
Signature · 1 line
2.32.0
#4 lore raw

PATCH 2/14 env: sf: Use ENV_VALID enum names instead of literals

In reply to Marek Behún

From: Marek Behún <[email protected]>

The function env_sf_init_addr() assigns number literals (1) instead of ENV_VALID to gd->env_valid. Fix this.

---
 env/sf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
env/sf.c +2 -2
index 4096e18387..c251d076d7 100644
@@ -339,10 +339,10 @@ static int env_sf_init_addr(void)
 
 	if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
 		gd->env_addr = (ulong)&(env_ptr->data);
-		gd->env_valid = 1;
+		gd->env_valid = ENV_VALID;
 	} else {
 		gd->env_addr = (ulong)&default_environment[0];
-		gd->env_valid = 1;
+		gd->env_valid = ENV_VALID;
 	}
 
 	return 0;
Signature · 1 line
2.32.0
#7 lore raw

PATCH 3/14 env: sf: Put ENV_INVALID into gd->env_valid on CRC failure

In reply to Marek Behún

From: Marek Behún <[email protected]>

env_sf_init_addr() says the environment is valid even if it is assigning default environment due to CRC failure. Change this to ENV_INVALID and let the generic env_init() function, which calls this initializer, assign the default environment.

---
 env/sf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
env/sf.c +1 -2
index c251d076d7..6a4bb756f0 100644
@@ -341,8 +341,7 @@ static int env_sf_init_addr(void)
 		gd->env_addr = (ulong)&(env_ptr->data);
 		gd->env_valid = ENV_VALID;
 	} else {
-		gd->env_addr = (ulong)&default_environment[0];
-		gd->env_valid = ENV_VALID;
+		gd->env_valid = ENV_INVALID;
 	}
 
 	return 0;
Signature · 1 line
2.32.0
Reviewed-by on v1 3/14
#8 lore raw

Re: [PATCH 03/14] env: sf: Put ENV_INVALID into gd->env_valid on CRC failure

Quoted 8 lines · Marek Behún

From: Marek Behún <[email protected]>

env_sf_init_addr() says the environment is valid even if it is assigning default environment due to CRC failure. Change this to ENV_INVALID and let the generic env_init() function, which calls this initializer, assign the default environment.

Quoted 4 lines
---
 env/sf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
#9 lore raw

PATCH 4/14 env: nand: Put ENV_INVALID into gd->env_valid if default environment

In reply to Marek Behún

From: Marek Behún <[email protected]>

env_nand_init() says the environment is valid even if it is assigning default environment due to not being able to access nand pre-reloaction (determined by macro values). Change this to ENV_INVALID and let the generic env_init() function, which calls this initializer, assign the default environment.

---
 env/nand.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
env/nand.c +1 -2
index be82e97d69..21aa367d5b 100644
@@ -107,8 +107,7 @@ static int env_nand_init(void)
 	gd->env_addr = (ulong)env_ptr->data;
 
 #else /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
-	gd->env_addr	= (ulong)&default_environment[0];
-	gd->env_valid	= ENV_VALID;
+	gd->env_valid	= ENV_INVALID;
 #endif /* ENV_IS_EMBEDDED || CONFIG_NAND_ENV_DST */
 
 	return 0;
Signature · 1 line
2.32.0
Reviewed-by on v1 4/14
#10 lore raw

Re: [PATCH 04/14] env: nand: Put ENV_INVALID into gd->env_valid if default environment

Quoted 9 lines · Marek Behún

From: Marek Behún <[email protected]>

env_nand_init() says the environment is valid even if it is assigning default environment due to not being able to access nand pre-reloaction (determined by macro values). Change this to ENV_INVALID and let the generic env_init() function, which calls this initializer, assign the default environment.

Quoted 5 lines
---
 env/nand.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by
#11 lore raw

Re: [PATCH 04/14] env: nand: Put ENV_INVALID into gd->env_valid if default environment

Quoted 9 lines · Marek Behún

From: Marek Behún <[email protected]>

env_nand_init() says the environment is valid even if it is assigning default environment due to not being able to access nand pre-reloaction (determined by macro values). Change this to ENV_INVALID and let the generic env_init() function, which calls this initializer, assign the default environment.

Quoted 5 lines
---
 env/nand.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

#12 lore raw

PATCH 5/14 env: nvram: Let generic env_init() assign default environment

In reply to Marek Behún

From: Marek Behún <[email protected]>

env_nvram_init() assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/nvram.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
env/nvram.c +1 -2
index 261b31edfb..297573c4ed 100644
@@ -94,8 +94,7 @@ static int env_nvram_init(void)
 #endif
 		gd->env_valid = ENV_VALID;
 	} else {
-		gd->env_addr	= (ulong)&default_environment[0];
-		gd->env_valid	= ENV_INVALID;
+		gd->env_valid = ENV_INVALID;
 	}
 
 	return 0;
Signature · 1 line
2.32.0
Reviewed-by on v1 5/14
#13 lore raw

Re: [PATCH 05/14] env: nvram: Let generic env_init() assign default environment

Quoted 12 lines · Marek Behún

From: Marek Behún <[email protected]>

env_nvram_init() assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/nvram.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by
#14 lore raw

Re: [PATCH 05/14] env: nvram: Let generic env_init() assign default environment

Quoted 12 lines · Marek Behún

From: Marek Behún <[email protected]>

env_nvram_init() assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/nvram.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

#15 lore raw

PATCH 6/14 env: nvram: Cosmetic fix in env_nvram_init()

In reply to Marek Behún

From: Marek Behún <[email protected]>

Use spaces consistently in assignments instead of tabs.

---
 env/nvram.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
env/nvram.c +2 -2
index 297573c4ed..fb265235af 100644
@@ -87,10 +87,10 @@ static int env_nvram_init(void)
 	nvram_read(data, CONFIG_ENV_ADDR + sizeof(ulong), ENV_SIZE);
 
 	if (crc32(0, data, ENV_SIZE) == crc) {
-		gd->env_addr	= (ulong)CONFIG_ENV_ADDR + sizeof(long);
+		gd->env_addr = (ulong)CONFIG_ENV_ADDR + sizeof(long);
 #else
 	if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
-		gd->env_addr	= (ulong)&env_ptr->data;
+		gd->env_addr = (ulong)&env_ptr->data;
 #endif
 		gd->env_valid = ENV_VALID;
 	} else {
Signature · 1 line
2.32.0
#18 lore raw

PATCH 7/14 env: nowhere: Let generic env_init() assign default environment

In reply to Marek Behún

From: Marek Behún <[email protected]>

env_nowhere_init() assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/nowhere.c | 1 -
 1 file changed, 1 deletion(-)
env/nowhere.c +0 -1
index 1fcf503453..dc93b6f2e4 100644
@@ -22,7 +22,6 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 static int env_nowhere_init(void)
 {
-	gd->env_addr	= (ulong)&default_environment[0];
 	gd->env_valid	= ENV_INVALID;
 
 	return 0;
Signature · 1 line
2.32.0
Reviewed-by on v1 7/14
#19 lore raw

Re: [PATCH 07/14] env: nowhere: Let generic env_init() assign default environment

Quoted 12 lines · Marek Behún

From: Marek Behún <[email protected]>

env_nowhere_init() assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/nowhere.c | 1 -
 1 file changed, 1 deletion(-)
Reviewed-by
#20 lore raw

Re: [PATCH 07/14] env: nowhere: Let generic env_init() assign default environment

Quoted 12 lines · Marek Behún

From: Marek Behún <[email protected]>

env_nowhere_init() assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/nowhere.c | 1 -
 1 file changed, 1 deletion(-)

Applied to u-boot-dm, thanks!

#21 lore raw

PATCH 8/14 env: nowhere: Cosmetic fix

In reply to Marek Behún

From: Marek Behún <[email protected]>

Use spaces instead of tabs in assignments, since there are no lines to align assignment values to.

---
 env/nowhere.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
env/nowhere.c +2 -2
index dc93b6f2e4..9ebc357dbd 100644
@@ -22,7 +22,7 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 static int env_nowhere_init(void)
 {
-	gd->env_valid	= ENV_INVALID;
+	gd->env_valid = ENV_INVALID;
 
 	return 0;
 }
@@ -37,7 +37,7 @@ static int env_nowhere_load(void)
 	if (!IS_ENABLED(CONFIG_SPL_BUILD))
 		env_set_default(NULL, 0);
 
-	gd->env_valid	= ENV_INVALID;
+	gd->env_valid = ENV_INVALID;
 
 	return 0;
 }
Signature · 1 line
2.32.0
#24 lore raw

PATCH 9/14 env: flash: Let generic env_init() assign default environment

In reply to Marek Behún

From: Marek Behún <[email protected]>

env_flash_init() (both implementations) assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/flash.c | 3 ---
 1 file changed, 3 deletions(-)
env/flash.c +0 -3
index ebee9069e4..77d4c030a5 100644
@@ -77,7 +77,6 @@ static int env_flash_init(void)
 	uchar flag1 = flash_addr->flags;
 	uchar flag2 = flash_addr_new->flags;
 
-	ulong addr_default = (ulong)&default_environment[0];
 	ulong addr1 = (ulong)&(flash_addr->data);
 	ulong addr2 = (ulong)&(flash_addr_new->data);
 
@@ -92,7 +91,6 @@ static int env_flash_init(void)
 		gd->env_addr	= addr2;
 		gd->env_valid	= ENV_VALID;
 	} else if (!crc1_ok && !crc2_ok) {
-		gd->env_addr	= addr_default;
 		gd->env_valid	= ENV_INVALID;
 	} else if (flag1 == ENV_REDUND_ACTIVE &&
 		   flag2 == ENV_REDUND_OBSOLETE) {
@@ -231,7 +229,6 @@ static int env_flash_init(void)
 		return 0;
 	}
 
-	gd->env_addr	= (ulong)&default_environment[0];
 	gd->env_valid	= ENV_INVALID;
 	return 0;
 }
Signature · 1 line
2.32.0
Reviewed-by on v1 9/14
#25 lore raw

Re: [PATCH 09/14] env: flash: Let generic env_init() assign default environment

Quoted 12 lines · Marek Behún

From: Marek Behún <[email protected]>

env_flash_init() (both implementations) assigns default environment if ENV_INVALID, but this is done in the generic env_init() function, which calls this initializer, so drop it from here.

---
 env/flash.c | 3 ---
 1 file changed, 3 deletions(-)
#26 lore raw

PATCH 10/14 env: flash: Cosmetic fix

In reply to Marek Behún

From: Marek Behún <[email protected]>

Change tab to space in env_flash_init().

---
 env/flash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/flash.c +1 -1
index 77d4c030a5..b928880502 100644
@@ -229,7 +229,7 @@ static int env_flash_init(void)
 		return 0;
 	}
 
-	gd->env_valid	= ENV_INVALID;
+	gd->env_valid = ENV_INVALID;
 	return 0;
 }
 #endif
Signature · 1 line
2.32.0
#29 lore raw

PATCH 11/14 board: synquacer: developerbox: Don't set gd->env_addr to default_environment

In reply to Marek Behún

From: Marek Behún <[email protected]>

This board sets gd->env_addr to default_environment in board_init(), but the board has environment in SPI flash according to defconfig. Let the env API handle environment automatically.

Cc Masami Hiramatsu <[email protected]>
---
 board/socionext/developerbox/developerbox.c | 2 --
 1 file changed, 2 deletions(-)
board/socionext/developerbox/developerbox.c +0 -2
index 9552bfcdc3..31b1349514 100644
@@ -82,8 +82,6 @@ int board_init(void)
 {
 	gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
 
-	gd->env_addr = (ulong)&default_environment[0];
-
 	synquacer_setup_scbm_smmu();
 
 	return 0;
Signature · 1 line
2.32.0
Reviewed-by on v1 11/14
#30 lore raw

Re: [PATCH 11/14] board: synquacer: developerbox: Don't set gd->env_addr to default_environment

Quoted 7 lines · Marek Behún

From: Marek Behún <[email protected]>

This board sets gd->env_addr to default_environment in board_init(), but the board has environment in SPI flash according to defconfig. Let the env API handle environment automatically.

Quoted 5 lines
Cc Masami Hiramatsu <[email protected]>
---
 board/socionext/developerbox/developerbox.c | 2 --
 1 file changed, 2 deletions(-)
Reviewed-by
#31 lore raw

Re: [PATCH 11/14] board: synquacer: developerbox: Don't set gd->env_addr to default_environment

Quoted 7 lines · Marek Behún

From: Marek Behún <[email protected]>

This board sets gd->env_addr to default_environment in board_init(), but the board has environment in SPI flash according to defconfig. Let the env API handle environment automatically.

Quoted 5 lines
Cc Masami Hiramatsu <[email protected]>
---
 board/socionext/developerbox/developerbox.c | 2 --
 1 file changed, 2 deletions(-)

Applied to u-boot-dm, thanks!

#32 lore raw

Re: [PATCH 11/14] board: synquacer: developerbox: Don't set gd->env_addr to default_environment

In reply to Marek Behún

Hi Marek,

I found this cause a synchronous abort on boot on the developerbox when the env_vars on SPI flash is corrupted. See below log. Can we revert it? I confirmed that reverting this patch fixes the problem.

Thank you,

[2021-11-17 13:49:19] U-Boot 2021.10-01018-g535870f3b0 (Nov 17 2021 - 13:45:48 +0900)
[2021-11-17 13:49:19]
[2021-11-17 13:49:19] CPU: SC2A11:Cortex-A53 MPCore 24cores
[2021-11-17 13:49:19] Model: Socionext Developer Box [2021-11-17 13:49:19] DRAM: 3.9 GiB
[2021-11-17 13:49:20] MMC: sdhci@52300000: 0
[2021-11-17 13:49:20] Loading Environment from SPIFlash... SF:
Detected mx66u51235f with page size 2
56 Bytes, erase size 4 KiB, total 64 MiB
[2021-11-17 13:49:20] *** Warning - bad CRC, using default environment [2021-11-17 13:49:20]
[2021-11-17 13:49:20] "Synchronous Abort" handler, esr 0x96000210 [2021-11-17 13:49:20] elr: 0000000008245cbc lr : 0000000008245ca4 (reloc) [2021-11-17 13:49:20] elr: 00000000fbf5acbc lr : 00000000fbf5aca4 [2021-11-17 13:49:20] x0 : 000000000000000a x1 : 0000000000000001 [2021-11-17 13:49:20] x2 : 0000000000000000 x3 : 0000000000010301 [2021-11-17 13:49:20] x4 : 0000000000000000 x5 : 0000000000000000 [2021-11-17 13:49:20] x6 : 0000000000000000 x7 : 0000000000000000 [2021-11-17 13:49:20] x8 : 0000000000000004 x9 : 0000000000000008 [2021-11-17 13:49:20] x10: 00000000000186a0 x11: 00000000ffffffd0 [2021-11-17 13:49:20] x12: 0000000000000006 x13: 000000000001869f [2021-11-17 13:49:20] x14: 00000000faee0b00 x15: 0000000000000000 [2021-11-17 13:49:20] x16: 00000000fbf52b24 x17: 0000000000000000 [2021-11-17 13:49:20] x18: 00000000faee4d80 x19: 00000000faf1aad8 [2021-11-17 13:49:20] x20: 000000000828eadf x21: 000000000000000a [2021-11-17 13:49:20] x22: 0000000000000020 x23: 00000000fbfaa016 [2021-11-17 13:49:20] x24: 00000000faee4e70 x25: 000000000828eadf [2021-11-17 13:49:20] x26: 0000000000000400 x27: 000000000002ffff [2021-11-17 13:49:20] x28: 0000000000000000 x29: 00000000faee06b0 [2021-11-17 13:49:20]

2021年10月22日(金) 22:47 Marek Behún <[email protected]>:

Quoted 29 lines

From: Marek Behún <[email protected]>

This board sets gd->env_addr to default_environment in board_init(), but the board has environment in SPI flash according to defconfig. Let the env API handle environment automatically.

Cc Masami Hiramatsu <[email protected]>
---
 board/socionext/developerbox/developerbox.c | 2 --
 1 file changed, 2 deletions(-)
board/socionext/developerbox/developerbox.c +0 -3
index 9552bfcdc3..31b1349514 100644
@@ -82,8 +82,6 @@ int board_init(void)
 {
        gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
 
-       gd->env_addr = (ulong)&default_environment[0];
-
        synquacer_setup_scbm_smmu();
 
        return 0;
--

2.32.0

Signature · 1 line
Masami Hiramatsu
#33 lore raw

Re: [PATCH 11/14] board: synquacer: developerbox: Don't set gd->env_addr to default_environment

Hi Masami,

Quoted 7 lines · Masami Hiramatsu

Hi Marek,

I found this cause a synchronous abort on boot on the developerbox when the env_vars on SPI flash is corrupted. See below log. Can we revert it? I confirmed that reverting this patch fixes the problem.

Yes, can you send a patch?

Marek, I think you are working on respinning the rest of your series. Can you take a look at this problem? It would be nice if we could repeat it on sandbox.

Regardds,
SImon

Quoted 68 lines

Thank you,

[2021-11-17 13:49:19] U-Boot 2021.10-01018-g535870f3b0 (Nov 17 2021 - 13:45:48 +0900)
[2021-11-17 13:49:19]
[2021-11-17 13:49:19] CPU: SC2A11:Cortex-A53 MPCore 24cores
[2021-11-17 13:49:19] Model: Socionext Developer Box [2021-11-17 13:49:19] DRAM: 3.9 GiB
[2021-11-17 13:49:20] MMC: sdhci@52300000: 0
[2021-11-17 13:49:20] Loading Environment from SPIFlash... SF:
Detected mx66u51235f with page size 2
56 Bytes, erase size 4 KiB, total 64 MiB
[2021-11-17 13:49:20] *** Warning - bad CRC, using default environment [2021-11-17 13:49:20]
[2021-11-17 13:49:20] "Synchronous Abort" handler, esr 0x96000210 [2021-11-17 13:49:20] elr: 0000000008245cbc lr : 0000000008245ca4 (reloc) [2021-11-17 13:49:20] elr: 00000000fbf5acbc lr : 00000000fbf5aca4 [2021-11-17 13:49:20] x0 : 000000000000000a x1 : 0000000000000001 [2021-11-17 13:49:20] x2 : 0000000000000000 x3 : 0000000000010301 [2021-11-17 13:49:20] x4 : 0000000000000000 x5 : 0000000000000000 [2021-11-17 13:49:20] x6 : 0000000000000000 x7 : 0000000000000000 [2021-11-17 13:49:20] x8 : 0000000000000004 x9 : 0000000000000008 [2021-11-17 13:49:20] x10: 00000000000186a0 x11: 00000000ffffffd0 [2021-11-17 13:49:20] x12: 0000000000000006 x13: 000000000001869f [2021-11-17 13:49:20] x14: 00000000faee0b00 x15: 0000000000000000 [2021-11-17 13:49:20] x16: 00000000fbf52b24 x17: 0000000000000000 [2021-11-17 13:49:20] x18: 00000000faee4d80 x19: 00000000faf1aad8 [2021-11-17 13:49:20] x20: 000000000828eadf x21: 000000000000000a [2021-11-17 13:49:20] x22: 0000000000000020 x23: 00000000fbfaa016 [2021-11-17 13:49:20] x24: 00000000faee4e70 x25: 000000000828eadf [2021-11-17 13:49:20] x26: 0000000000000400 x27: 000000000002ffff [2021-11-17 13:49:20] x28: 0000000000000000 x29: 00000000faee06b0 [2021-11-17 13:49:20]

2021年10月22日(金) 22:47 Marek Behún <[email protected]>:

Quoted 27 lines

From: Marek Behún <[email protected]>

This board sets gd->env_addr to default_environment in board_init(), but the board has environment in SPI flash according to defconfig. Let the env API handle environment automatically.

Cc Masami Hiramatsu <[email protected]>
---
 board/socionext/developerbox/developerbox.c | 2 --
 1 file changed, 2 deletions(-)
board/socionext/developerbox/developerbox.c +0 -3
index 9552bfcdc3..31b1349514 100644
@@ -82,8 +82,6 @@ int board_init(void)
 {
        gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
 
-       gd->env_addr = (ulong)&default_environment[0];
-
        synquacer_setup_scbm_smmu();
 
        return 0;
--
Quoted 2 lines

2.32.0

--
Masami Hiramatsu

#34 lore raw

Re: [PATCH 11/14] board: synquacer: developerbox: Don't set gd->env_addr to default_environment

Hi Simon,

2021年11月18日(木) 5:36 Simon Glass <[email protected]>:

Quoted 6 lines

Hi Masami,

Quoted 1 line · Masami Hiramatsu
Quoted 8 lines
Quoted 6 lines

Hi Marek,

I found this cause a synchronous abort on boot on the developerbox when the env_vars on SPI flash is corrupted. See below log. Can we revert it? I confirmed that reverting this patch fixes the problem.

Yes, can you send a patch?

OK, I'll send it soon.

Thank you!

Quoted 78 lines

Marek, I think you are working on respinning the rest of your series. Can you take a look at this problem? It would be nice if we could repeat it on sandbox.

Regardds,
SImon

Quoted 68 lines

Thank you,

[2021-11-17 13:49:19] U-Boot 2021.10-01018-g535870f3b0 (Nov 17 2021 - 13:45:48 +0900)
[2021-11-17 13:49:19]
[2021-11-17 13:49:19] CPU: SC2A11:Cortex-A53 MPCore 24cores
[2021-11-17 13:49:19] Model: Socionext Developer Box [2021-11-17 13:49:19] DRAM: 3.9 GiB
[2021-11-17 13:49:20] MMC: sdhci@52300000: 0
[2021-11-17 13:49:20] Loading Environment from SPIFlash... SF:
Detected mx66u51235f with page size 2
56 Bytes, erase size 4 KiB, total 64 MiB
[2021-11-17 13:49:20] *** Warning - bad CRC, using default environment [2021-11-17 13:49:20]
[2021-11-17 13:49:20] "Synchronous Abort" handler, esr 0x96000210 [2021-11-17 13:49:20] elr: 0000000008245cbc lr : 0000000008245ca4 (reloc) [2021-11-17 13:49:20] elr: 00000000fbf5acbc lr : 00000000fbf5aca4 [2021-11-17 13:49:20] x0 : 000000000000000a x1 : 0000000000000001 [2021-11-17 13:49:20] x2 : 0000000000000000 x3 : 0000000000010301 [2021-11-17 13:49:20] x4 : 0000000000000000 x5 : 0000000000000000 [2021-11-17 13:49:20] x6 : 0000000000000000 x7 : 0000000000000000 [2021-11-17 13:49:20] x8 : 0000000000000004 x9 : 0000000000000008 [2021-11-17 13:49:20] x10: 00000000000186a0 x11: 00000000ffffffd0 [2021-11-17 13:49:20] x12: 0000000000000006 x13: 000000000001869f [2021-11-17 13:49:20] x14: 00000000faee0b00 x15: 0000000000000000 [2021-11-17 13:49:20] x16: 00000000fbf52b24 x17: 0000000000000000 [2021-11-17 13:49:20] x18: 00000000faee4d80 x19: 00000000faf1aad8 [2021-11-17 13:49:20] x20: 000000000828eadf x21: 000000000000000a [2021-11-17 13:49:20] x22: 0000000000000020 x23: 00000000fbfaa016 [2021-11-17 13:49:20] x24: 00000000faee4e70 x25: 000000000828eadf [2021-11-17 13:49:20] x26: 0000000000000400 x27: 000000000002ffff [2021-11-17 13:49:20] x28: 0000000000000000 x29: 00000000faee06b0 [2021-11-17 13:49:20]

2021年10月22日(金) 22:47 Marek Behún <[email protected]>:

Quoted 27 lines

From: Marek Behún <[email protected]>

This board sets gd->env_addr to default_environment in board_init(), but the board has environment in SPI flash according to defconfig. Let the env API handle environment automatically.

Cc Masami Hiramatsu <[email protected]>
---
 board/socionext/developerbox/developerbox.c | 2 --
 1 file changed, 2 deletions(-)
board/socionext/developerbox/developerbox.c +0 -3
index 9552bfcdc3..31b1349514 100644
@@ -82,8 +82,6 @@ int board_init(void)
 {
        gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
 
-       gd->env_addr = (ulong)&default_environment[0];
-
        synquacer_setup_scbm_smmu();
 
        return 0;
--
Quoted 2 lines

2.32.0

--
Masami Hiramatsu

Signature · 1 line
Masami Hiramatsu
#35 lore raw

PATCH 1/1 Revert "board: synquacer: developerbox: Don't set gd->env_addr to default_environment"

Without default setting of gd->env_addr, U-Boot will cause a synchronous abort if the env-variables on the SPI flash is broken or not saved corectly. Set gd->env_addr correctly.

This reverts commit 535870f3b0fb09ee9b2885409f05304111464643.

---
 board/socionext/developerbox/developerbox.c |    2 ++
 1 file changed, 2 insertions(+)
board/socionext/developerbox/developerbox.c +2 -0
index 31b1349514..9552bfcdc3 100644
@@ -82,6 +82,8 @@ int board_init(void)
 {
 	gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
 
+	gd->env_addr = (ulong)&default_environment[0];
+
 	synquacer_setup_scbm_smmu();
 
 	return 0;
author Reviewed-by on v1 1/1
#36 lore raw

Re: [PATCH] Revert "board: synquacer: developerbox: Don't set gd->env_addr to default_environment"

Quoted 17 lines · On Thu, 18 Nov 2021 14:45:25 +0900 Masami Hiramatsu…

Without default setting of gd->env_addr, U-Boot will cause a synchronous abort if the env-variables on the SPI flash is broken or not saved corectly. Set gd->env_addr correctly.

This reverts commit 535870f3b0fb09ee9b2885409f05304111464643.

---
 board/socionext/developerbox/developerbox.c |    2 ++
 1 file changed, 2 insertions(+)
board/socionext/developerbox/developerbox.c +0 -0
index 31b1349514..9552bfcdc3 100644

board/socionext/developerbox/developerbox.c int board_init(void) · line 89

Quoted 8 lines
board/socionext/developerbox/developerbox.c +2 -0
@@ -82,6 +82,8 @@ int board_init(void)
 {
 	gd->bd->bi_boot_params = CONFIG_SYS_LOAD_ADDR + LOAD_OFFSET;
 
+	gd->env_addr = (ulong)&default_environment[0];
+
 	synquacer_setup_scbm_smmu();
 
 	return 0;

I will look into this when I respin the default environment series.

Marek

#37 lore raw

Re: [PATCH] Revert "board: synquacer: developerbox: Don't set gd->env_addr to default_environment"

In reply to Masami Hiramatsu
Quoted 8 lines · Masami Hiramatsu

Without default setting of gd->env_addr, U-Boot will cause a synchronous abort if the env-variables on the SPI flash is broken or not saved corectly. Set gd->env_addr correctly.

This reverts commit 535870f3b0fb09ee9b2885409f05304111464643.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#38 lore raw

PATCH 12/14 board: freescale: various boards: Let env subsystem set gd->env_addr

In reply to Marek Behún

From: Marek Behún <[email protected]>

Various freescale boards set gd->env_addr to default_environment in board_init(), conditional on CONFIG_ENV_IS_NOWHERE, but this is redundant, since it is done by env_init() before board_init() is called.

Let the env subsystem handle this.

Cc Ramon Fried <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Mian Yousaf Kaukab <[email protected]>
---
 board/freescale/ls1012afrdm/ls1012afrdm.c | 4 ----
 board/freescale/ls1012aqds/ls1012aqds.c   | 4 ----
 board/freescale/ls1012ardb/ls1012ardb.c   | 4 ----
 board/freescale/ls1028a/ls1028a.c         | 4 ----
 board/freescale/ls1088a/ls1088a.c         | 4 ----
 board/freescale/ls2080aqds/ls2080aqds.c   | 3 ---
 board/freescale/ls2080ardb/ls2080ardb.c   | 3 ---
 board/freescale/lx2160a/lx2160a.c         | 3 ---
 8 files changed, 29 deletions(-)
board/freescale/ls1012afrdm/ls1012afrdm.c +0 -4
index 6473ee0572..5dd19cfcd9 100644
@@ -172,10 +172,6 @@ int board_init(void)
 	if (current_el() == 3)
 		out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
 
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
-
 #ifdef CONFIG_FSL_CAAM
 	sec_init();
 #endif
board/freescale/ls1012aqds/ls1012aqds.c +0 -4
index 6e21040601..68578e81a5 100644
@@ -150,10 +150,6 @@ int board_init(void)
 	erratum_a010315();
 #endif
 
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
-
 #ifdef CONFIG_FSL_CAAM
 	sec_init();
 #endif
board/freescale/ls1012ardb/ls1012ardb.c +0 -4
index 62e8af48cf..064fb4d39f 100644
@@ -173,10 +173,6 @@ int board_init(void)
 	erratum_a010315();
 #endif
 
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
-
 #ifdef CONFIG_FSL_CAAM
 	sec_init();
 #endif
board/freescale/ls1028a/ls1028a.c +0 -4
index 461c571b36..486a544d35 100644
@@ -73,10 +73,6 @@ u32 get_lpuart_clk(void)
 
 int board_init(void)
 {
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
-
 #ifdef CONFIG_FSL_CAAM
 	sec_init();
 #endif
board/freescale/ls1088a/ls1088a.c +0 -4
index 2f422634d5..7046fbaeb5 100644
@@ -810,10 +810,6 @@ int board_init(void)
 	select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
 	board_retimer_init();
 
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
-
 #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
 	/* invert AQR105 IRQ pins polarity */
 	out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
board/freescale/ls2080aqds/ls2080aqds.c +0 -3
index 62658c4702..2f0139edef 100644
@@ -211,9 +211,6 @@ int board_init(void)
 			     FSL_QIXIS_BRDCFG9_QSPI);
 #endif
 
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
 	select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
 
 #ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
board/freescale/ls2080ardb/ls2080ardb.c +0 -3
index 58b852383e..bf660a8e65 100644
@@ -281,9 +281,6 @@ int board_init(void)
 
 	init_final_memctl_regs();
 
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
 	select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
 
 #ifdef CONFIG_FSL_QIXIS
board/freescale/lx2160a/lx2160a.c +0 -3
index e61289d228..bd5abb677a 100644
@@ -588,9 +588,6 @@ int board_init(void)
 #if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
 	u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
 #endif
-#ifdef CONFIG_ENV_IS_NOWHERE
-	gd->env_addr = (ulong)&default_environment[0];
-#endif
 
 	select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
 
Signature · 1 line
2.32.0
Reviewed-by on v1 12/14
#39 lore raw

Re: [PATCH 12/14] board: freescale: various boards: Let env subsystem set gd->env_addr

Quoted 13 lines · Marek Behún

From: Marek Behún <[email protected]>

Various freescale boards set gd->env_addr to default_environment in board_init(), conditional on CONFIG_ENV_IS_NOWHERE, but this is redundant, since it is done by env_init() before board_init() is called.

Let the env subsystem handle this.

Cc Ramon Fried <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Mian Yousaf Kaukab <[email protected]>
Quoted 10 lines
---
 board/freescale/ls1012afrdm/ls1012afrdm.c | 4 ----
 board/freescale/ls1012aqds/ls1012aqds.c   | 4 ----
 board/freescale/ls1012ardb/ls1012ardb.c   | 4 ----
 board/freescale/ls1028a/ls1028a.c         | 4 ----
 board/freescale/ls1088a/ls1088a.c         | 4 ----
 board/freescale/ls2080aqds/ls2080aqds.c   | 3 ---
 board/freescale/ls2080ardb/ls2080ardb.c   | 3 ---
 board/freescale/lx2160a/lx2160a.c         | 3 ---
 8 files changed, 29 deletions(-)
Reviewed-by
#40 lore raw

Re: [PATCH 12/14] board: freescale: various boards: Let env subsystem set gd->env_addr

Quoted 13 lines · Marek Behún

From: Marek Behún <[email protected]>

Various freescale boards set gd->env_addr to default_environment in board_init(), conditional on CONFIG_ENV_IS_NOWHERE, but this is redundant, since it is done by env_init() before board_init() is called.

Let the env subsystem handle this.

Cc Ramon Fried <[email protected]>
Cc Priyanka Jain <[email protected]>
Cc Mian Yousaf Kaukab <[email protected]>
Quoted 10 lines
---
 board/freescale/ls1012afrdm/ls1012afrdm.c | 4 ----
 board/freescale/ls1012aqds/ls1012aqds.c   | 4 ----
 board/freescale/ls1012ardb/ls1012ardb.c   | 4 ----
 board/freescale/ls1028a/ls1028a.c         | 4 ----
 board/freescale/ls1088a/ls1088a.c         | 4 ----
 board/freescale/ls2080aqds/ls2080aqds.c   | 3 ---
 board/freescale/ls2080ardb/ls2080ardb.c   | 3 ---
 board/freescale/lx2160a/lx2160a.c         | 3 ---
 8 files changed, 29 deletions(-)

Applied to u-boot-dm, thanks!

#41 lore raw

PATCH 13/14 env: Always use char for default_environment

In reply to Marek Behún

From: Marek Behún <[email protected]>

Sometimes we use uchar and sometimes char for the default environment array. By always using char, we can get rid of some explicit casts.

---
 board/Marvell/mvebu_armada-37xx/board.c | 2 +-
 env/common.c                            | 6 +++---
 include/env_default.h                   | 4 ++--
 include/env_internal.h                  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)
board/Marvell/mvebu_armada-37xx/board.c +1 -1
index 2de9c2ac17..d7b6ecafbf 100644
@@ -87,7 +87,7 @@ int board_init(void)
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
-	char *ptr = (char *)&default_environment[0];
+	char *ptr = &default_environment[0];
 	struct udevice *dev;
 	struct mmc *mmc_dev;
 	bool ddr4, emmc;
env/common.c +3 -3
index db213b7748..664d2e688e 100644
@@ -162,7 +162,7 @@ int env_get_f(const char *name, char *buf, unsigned len)
 	name_len = strlen(name);
 
 	if (gd->env_valid == ENV_INVALID)
-		env = (const char *)default_environment;
+		env = default_environment;
 	else
 		env = (const char *)gd->env_addr;
 
@@ -264,7 +264,7 @@ void env_set_default(const char *s, int flags)
 	}
 
 	flags |= H_DEFAULT;
-	if (himport_r(&env_htab, (char *)default_environment,
+	if (himport_r(&env_htab, default_environment,
 			sizeof(default_environment), '\0', flags, 0,
 			0, NULL) == 0)
 		pr_err("## Error: Environment import failed: errno = %d\n",
@@ -283,7 +283,7 @@ int env_set_default_vars(int nvars, char * const vars[], int flags)
 	 * (and use \0 as a separator)
 	 */
 	flags |= H_NOCLEAR | H_DEFAULT;
-	return himport_r(&env_htab, (const char *)default_environment,
+	return himport_r(&env_htab, default_environment,
 				sizeof(default_environment), '\0',
 				flags, 0, nvars, vars);
 }
include/env_default.h +2 -2
index 66e203eb6e..a6724719ec 100644
@@ -20,9 +20,9 @@ env_t embedded_environment __UBOOT_ENV_SECTION__(environment) = {
 #elif defined(DEFAULT_ENV_INSTANCE_STATIC)
 static char default_environment[] = {
 #elif defined(DEFAULT_ENV_IS_RW)
-uchar default_environment[] = {
+char default_environment[] = {
 #else
-const uchar default_environment[] = {
+const char default_environment[] = {
 #endif
 #ifndef CONFIG_USE_DEFAULT_ENV_FILE
 #ifdef	CONFIG_ENV_CALLBACK_LIST_DEFAULT
include/env_internal.h +2 -2
index b7bddcb00d..f74927cd64 100644
@@ -112,9 +112,9 @@ extern env_t embedded_environment;
 #endif /* ENV_IS_EMBEDDED */
 
 #ifdef DEFAULT_ENV_IS_RW
-extern unsigned char default_environment[];
+extern char default_environment[];
 #else
-extern const unsigned char default_environment[];
+extern const char default_environment[];
 #endif
 
 #ifndef DO_DEPS_ONLY
Signature · 1 line
2.32.0
Reviewed-by on v1 13/14
#42 lore raw

Re: [PATCH 13/14] env: Always use char for default_environment

Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

Sometimes we use uchar and sometimes char for the default environment array. By always using char, we can get rid of some explicit casts.

Quoted 7 lines
---
 board/Marvell/mvebu_armada-37xx/board.c | 2 +-
 env/common.c                            | 6 +++---
 include/env_default.h                   | 4 ++--
 include/env_internal.h                  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)
Reviewed-by
#43 lore raw

Re: [PATCH 13/14] env: Always use char for default_environment

Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

Sometimes we use uchar and sometimes char for the default environment array. By always using char, we can get rid of some explicit casts.

Quoted 7 lines
---
 board/Marvell/mvebu_armada-37xx/board.c | 2 +-
 env/common.c                            | 6 +++---
 include/env_default.h                   | 4 ++--
 include/env_internal.h                  | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

Applied to u-boot-dm, thanks!

#44 lore raw

PATCH 14/14 env: Use static_assert() to check if default_environment is too large

In reply to Marek Behún

From: Marek Behún <[email protected]>

Check sizeof(default_environment) against ENV_SIZE in a static_assert() instead of runtime.
Only check if !USE_HOSTCC (for in fw_env tool ENV_SIZE expands to a variable, and cannot be checked statically) nad !DEFAULT_ENV_INSTANCE_EMBEDDED, for in that case the default_environment variable is not set.

---
 env/common.c          | 5 -----
 include/env_default.h | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)
env/common.c +0 -5
index 664d2e688e..99729ca002 100644
@@ -247,11 +247,6 @@ char *env_get_default(const char *name)
 
 void env_set_default(const char *s, int flags)
 {
-	if (sizeof(default_environment) > ENV_SIZE) {
-		puts("*** Error - default environment is too large\n\n");
-		return;
-	}
-
 	if (s) {
 		if ((flags & H_INTERACTIVE) == 0) {
 			printf("*** Warning - %s, "
include/env_default.h +6 -0
index a6724719ec..23430dc70d 100644
@@ -121,3 +121,9 @@ const char default_environment[] = {
 	}
 #endif
 };
+
+#if !defined(USE_HOSTCC) && !defined(DEFAULT_ENV_INSTANCE_EMBEDDED)
+#include <env_internal.h>
+static_assert(sizeof(default_environment) <= ENV_SIZE,
+	      "Default environment is too large");
+#endif
Signature · 1 line
2.32.0
Reviewed-by on v1 14/14
#45 lore raw

Re: [PATCH 14/14] env: Use static_assert() to check if default_environment is too large

Quoted 10 lines · Marek Behún

From: Marek Behún <[email protected]>

Check sizeof(default_environment) against ENV_SIZE in a static_assert() instead of runtime.
Only check if !USE_HOSTCC (for in fw_env tool ENV_SIZE expands to a variable, and cannot be checked statically) nad !DEFAULT_ENV_INSTANCE_EMBEDDED, for in that case the default_environment variable is not set.

Quoted 5 lines
---
 env/common.c          | 5 -----
 include/env_default.h | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)
Reviewed-by
#46 lore raw

Re: [PATCH 14/14] env: Use static_assert() to check if default_environment is too large

Quoted 10 lines · Marek Behún

From: Marek Behún <[email protected]>

Check sizeof(default_environment) against ENV_SIZE in a static_assert() instead of runtime.
Only check if !USE_HOSTCC (for in fw_env tool ENV_SIZE expands to a variable, and cannot be checked statically) nad !DEFAULT_ENV_INSTANCE_EMBEDDED, for in that case the default_environment variable is not set.

Quoted 5 lines
---
 env/common.c          | 5 -----
 include/env_default.h | 6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)

Applied to u-boot-dm, thanks!