sunxi: fix initial environment loading without MMC
PATCH 1/1 sunxi: fix initial environment loading without MMC
Commit e42dad4168fe ("sunxi: use boot source for determining environment location") changed our implementation of env_get_location() and enabled it for every board, even those without MMC support (like the C.H.I.P. boards). However the default fallback location of ENVL_FAT does not cope very well without MMC support compiled in, so the board hangs when trying to initially load the environment.
Change the default fallback location to be ENVL_FAT only when the FAT environment support is enabled, and use ENVL_NOWHERE and ENVL_UBI as alternative fallbacks, when those sources are enabled.
This fixes U-Boot loading on the C.H.I.P. boards.
--- board/sunxi/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
board/sunxi/board.c +8 -1
@@ -132,7 +132,14 @@ void i2c_init_board(void)*/ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +enum env_location boot_loc; + +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE )) + boot_loc =ENVL_NOWHERE ; +else if (IS_ENABLED (CONFIG_ENV_IS_IN_FAT )) + boot_loc =ENVL_FAT ; +else if (IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) + boot_loc =ENVL_UBI ; gd->env_load_prio = prio;
Signature · 1 line
2.35.3
Samuel Holland
maintainerHi Andre,
Quoted 27 lines · Andre Przywara
Commit
e42dad4168fe("sunxi: use boot source for determining environment location") changed our implementation ofenv_get_location()and enabled it for every board, even those without MMC support (like the C.H.I.P. boards). However the default fallback location ofENVL_FATdoes not cope very well without MMC support compiled in, so the board hangs when trying to initially load the environment.Change the default fallback location to be
ENVL_FATonly when the FAT environment support is enabled, and useENVL_NOWHEREandENVL_UBIas alternative fallbacks, when those sources are enabled.This fixes U-Boot loading on the C.H.I.P. boards.
Fixes e42dad4168fe ("sunxi: use boot source for determining environment location")Reported-by Chris Morgan <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- board/sunxi/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)board/sunxi/board.c +0
-0@@ -132,7 +132,14 @@ void i2c_init_board(void)*/ enum env_location env_get_location (enum env_operation op,int prio)
board/sunxi/board.c void i2c_init_board(void) · line 142
Quoted 10 lines
board/sunxi/board.c +8
-1{ -enum env_location boot_loc =ENVL_FAT ; +enum env_location boot_loc; + +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE )) + boot_loc =ENVL_NOWHERE ; +else if (IS_ENABLED (CONFIG_ENV_IS_IN_FAT )) + boot_loc =ENVL_FAT ; +else if (IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) + boot_loc =ENVL_UBI ;
This could leave boot_loc uninitialized. And there is still an unconditional use of ENVL_FAT in the BOOT_DEVICE_MMCx case.
board/sunxi/board.c void i2c_init_board(void) · line 143
Quoted 1 line
board/sunxi/board.c +0
-0gd->env_load_prio = prio;
I don't think the hook is supposed to change this variable.
I'm still a bit confused on the fallback logic you have in place. Splitting it up into three blocks doesn't help. If the goal is to load the environment from the boot device, while preferring filesystems over raw block devices, I propose the following:
board/sunxi/board.c +18 -23
@@ -129,26 +129,38 @@* Try to use the environment from the boot source first. * For MMC, this means a FAT partition on the boot device (SD or eMMC). * If the raw MMC environment is also enabled, this is tried next. -* SPI flash falls back to FAT (on SD card). */ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +if (prio >1 ) +return ENVL_UNKNOWN ; - gd->env_load_prio = prio; +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE )) +return ENVL_NOWHERE ;switch (sunxi_get_boot_device ()) {case BOOT_DEVICE_MMC1 :case BOOT_DEVICE_MMC2 : - boot_loc =ENVL_FAT ; +if (prio ==0 ) { +if (IS_ENABLED (CONFIG_ENV_IS_IN_EXT4 )) +return ENVL_EXT4 ; +if (IS_ENABLED (CONFIG_ENV_IS_IN_FAT )) +return ENVL_FAT ; + } +if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) +return ENVL_MMC ;break ;case BOOT_DEVICE_NAND : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_NAND )) - boot_loc =ENVL_NAND ; +return ENVL_NAND ;break ;case BOOT_DEVICE_SPI : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_SPI_FLASH )) - boot_loc =ENVL_SPI_FLASH ; +return ENVL_SPI_FLASH ;break ;case BOOT_DEVICE_BOARD :break ;
@@ -156,23 +168,6 @@break ; } -/* Always try to access the environment on the boot device first. */ -if (prio ==0 ) -return boot_loc; - -if (prio ==1 ) { -switch (boot_loc) { -case ENVL_SPI_FLASH : -return ENVL_FAT ; -case ENVL_FAT : -if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) -return ENVL_MMC ; -break ; -default : -break ; - } - } -return ENVL_UNKNOWN ; }
Regards,
Samuel
On Sat, 23 Apr 2022 16:01:00 -0500
Samuel Holland <[email protected]> wrote:
Hi Samuel,
thanks for having a look and the comments.
Quoted 33 lines · Andre Przywara
Quoted 32 lines
Commit
e42dad4168fe("sunxi: use boot source for determining environment location") changed our implementation ofenv_get_location()and enabled it for every board, even those without MMC support (like the C.H.I.P. boards). However the default fallback location ofENVL_FATdoes not cope very well without MMC support compiled in, so the board hangs when trying to initially load the environment.Change the default fallback location to be
ENVL_FATonly when the FAT environment support is enabled, and useENVL_NOWHEREandENVL_UBIas alternative fallbacks, when those sources are enabled.This fixes U-Boot loading on the C.H.I.P. boards.
Fixes e42dad4168fe ("sunxi: use boot source for determining environment location")Reported-by Chris Morgan <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- board/sunxi/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)board/sunxi/board.c +3
-1@@ -132,7 +132,14 @@ void i2c_init_board(void)*/ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +enum env_location boot_loc; + +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE ))
Quoted 8 lines
board/sunxi/board.c void i2c_init_board(void) · line 142
Quoted 5 lines
board/sunxi/board.c +5
-0+ boot_loc =ENVL_NOWHERE ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) + boot_loc =ENVL_FAT ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) + boot_loc =ENVL_UBI ;This could leave
boot_locuninitialized. And there is still an unconditional use ofENVL_FATin theBOOT_DEVICE_MMCxcase.
Yeah, it's a mess, and there doesn't seem to be a one-fits-all fallback value. Returning ENVL_UNKNOWN when prio is 0 definitely hangs, as does returning some source without having the corresponding driver compiled in, so getting this right *and* nice-looking is a bit tricky.
Quoted 3 lines
board/sunxi/board.c void i2c_init_board(void) · line 143
Quoted 1 line
board/sunxi/board.c +0
-0gd->env_load_prio = prio;I don't think the hook is supposed to change this variable.
Yeah, don't remember why I initially put that in, I must have copied that from somewhere. All I remember is that this code is touchy (as the bug report leading to that patch shows), and there are quite some corner cases to test.
Quoted 4 lines
I'm still a bit confused on the fallback logic you have in place. Splitting it up into three blocks doesn't help. If the goal is to load the environment from the boot device, while preferring filesystems over raw block devices, I propose the following:
Admittedly this gets messier, I mainly wanted to fix the regression quickly, since it already broke the release for the CHIP boards. I will have a closer look at your suggestion and check for those corner cases, but will probably go with that instead of piling up more cruft on my previous code ;-)
Thanks,
Andre
Quoted 77 lines
board/sunxi/board.c +18
-23@@ -129,26 +129,38 @@* Try to use the environment from the boot source first. * For MMC, this means a FAT partition on the boot device (SD or eMMC). * If the raw MMC environment is also enabled, this is tried next. -* SPI flash falls back to FAT (on SD card). */ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +if (prio >1 ) +return ENVL_UNKNOWN ; - gd->env_load_prio = prio; +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE )) +return ENVL_NOWHERE ;switch (sunxi_get_boot_device ()) {case BOOT_DEVICE_MMC1 :case BOOT_DEVICE_MMC2 : - boot_loc =ENVL_FAT ; +if (prio ==0 ) { +if (IS_ENABLED (CONFIG_ENV_IS_IN_EXT4 )) +return ENVL_EXT4 ; +if (IS_ENABLED (CONFIG_ENV_IS_IN_FAT )) +return ENVL_FAT ; + } +if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) +return ENVL_MMC ;break ;case BOOT_DEVICE_NAND : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_NAND )) - boot_loc =ENVL_NAND ; +return ENVL_NAND ;break ;case BOOT_DEVICE_SPI : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_SPI_FLASH )) - boot_loc =ENVL_SPI_FLASH ; +return ENVL_SPI_FLASH ;break ;case BOOT_DEVICE_BOARD :break ;@@ -156,23 +168,6 @@break ; } -/* Always try to access the environment on the boot device first. */ -if (prio ==0 ) -return boot_loc; - -if (prio ==1 ) { -switch (boot_loc) { -case ENVL_SPI_FLASH : -return ENVL_FAT ; -case ENVL_FAT : -if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) -return ENVL_MMC ; -break ; -default : -break ; - } - } -return ENVL_UNKNOWN ; }Regards,
Samuel
On Tue, 26 Apr 2022 15:25:56 +0100
Andre Przywara <[email protected]> wrote:
Hi Samuel,
Quoted 68 lines
On Sat, 23 Apr 2022 16:01:00 -0500
Samuel Holland <[email protected]> wrote:Hi Samuel,
thanks for having a look and the comments.
Quoted 33 lines · Andre Przywara
Quoted 32 lines
Commit
e42dad4168fe("sunxi: use boot source for determining environment location") changed our implementation ofenv_get_location()and enabled it for every board, even those without MMC support (like the C.H.I.P. boards). However the default fallback location ofENVL_FATdoes not cope very well without MMC support compiled in, so the board hangs when trying to initially load the environment.Change the default fallback location to be
ENVL_FATonly when the FAT environment support is enabled, and useENVL_NOWHEREandENVL_UBIas alternative fallbacks, when those sources are enabled.This fixes U-Boot loading on the C.H.I.P. boards.
Fixes e42dad4168fe ("sunxi: use boot source for determining environment location")Reported-by Chris Morgan <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- board/sunxi/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)board/sunxi/board.c +3
-1@@ -132,7 +132,14 @@ void i2c_init_board(void)*/ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +enum env_location boot_loc; + +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE ))Quoted 8 lines
board/sunxi/board.c void i2c_init_board(void) · line 142
Quoted 5 lines
board/sunxi/board.c +5
-0+ boot_loc =ENVL_NOWHERE ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) + boot_loc =ENVL_FAT ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) + boot_loc =ENVL_UBI ;This could leave
boot_locuninitialized. And there is still an unconditional use ofENVL_FATin theBOOT_DEVICE_MMCxcase.Yeah, it's a mess, and there doesn't seem to be a one-fits-all fallback value. Returning
ENVL_UNKNOWNwhen prio is 0 definitely hangs, as does returning some source without having the corresponding driver compiled in, so getting this right *and* nice-looking is a bit tricky.Quoted 3 lines
board/sunxi/board.c void i2c_init_board(void) · line 143
Quoted 1 line
board/sunxi/board.c +0
-0gd->env_load_prio = prio;I don't think the hook is supposed to change this variable.
Yeah, don't remember why I initially put that in, I must have copied that from somewhere. All I remember is that this code is touchy (as the bug report leading to that patch shows), and there are quite some corner cases to test.
Quoted 4 lines
I'm still a bit confused on the fallback logic you have in place. Splitting it up into three blocks doesn't help. If the goal is to load the environment from the boot device, while preferring filesystems over raw block devices, I propose the following:
Quoted 5 lines
Admittedly this gets messier, I mainly wanted to fix the regression quickly, since it already broke the release for the CHIP boards. I will have a closer look at your suggestion and check for those corner cases, but will probably go with that instead of piling up more cruft on my previous code ;-)
So I was about to submit your solution, but this is suffering from the same old problem: we must not return ENVL_UNKNOWN on the first call. FEL booting triggers this: it will lead to env_init() returning a negative error value, which is fatal, as it's part of init_sequence_f[]. I think the proper fix is to treat this case the same as the -ENOENT case at the end of env_init(), but I don't dare to do this generic change this late in the cycle.
My plan is to hack-fix this for sunxi, for now (see below), then propose the generic change for the next cycle. Does this sound OK? Another solution is to always select ENV_IS_NOWHERE, then return this, but I don't know if this has more side effects, so is also risky at this point.
Quoted 63 lines
Quoted 63 lines
board/sunxi/board.c +18
-15@@ -129,26 +129,38 @@* Try to use the environment from the boot source first. * For MMC, this means a FAT partition on the boot device (SD or eMMC). * If the raw MMC environment is also enabled, this is tried next. -* SPI flash falls back to FAT (on SD card). */ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +if (prio >1 ) +return ENVL_UNKNOWN ; - gd->env_load_prio = prio; +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE )) +return ENVL_NOWHERE ;switch (sunxi_get_boot_device ()) {case BOOT_DEVICE_MMC1 :case BOOT_DEVICE_MMC2 : - boot_loc =ENVL_FAT ; +if (prio ==0 ) { +if (IS_ENABLED (CONFIG_ENV_IS_IN_EXT4 )) +return ENVL_EXT4 ; +if (IS_ENABLED (CONFIG_ENV_IS_IN_FAT )) +return ENVL_FAT ; + } +if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) +return ENVL_MMC ;break ;case BOOT_DEVICE_NAND : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_NAND )) - boot_loc =ENVL_NAND ; +return ENVL_NAND ;break ;case BOOT_DEVICE_SPI : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_SPI_FLASH )) - boot_loc =ENVL_SPI_FLASH ; +return ENVL_SPI_FLASH ;break ;case BOOT_DEVICE_BOARD :break ;@@ -156,23 +168,6 @@break ; } -/* Always try to access the environment on the boot device first. */ -if (prio ==0 ) -return boot_loc; - -if (prio ==1 ) { -switch (boot_loc) { -case ENVL_SPI_FLASH : -return ENVL_FAT ; -case ENVL_FAT :
Quoted 8 lines
board/sunxi/board.c line 175
Quoted 8 lines
board/sunxi/board.c +0
-8-if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) -return ENVL_MMC ; -break ; -default : -break ; - } - } -
+ /*
+ * If we come here for the first call, we *must* return a valid
+ * environment location other than ENVL_UNKNOWN, or the setup sequence
+ * in board_f() will silently hang. This is arguably a bug in
+ * env_init(), but for now pick one environment for which we know for
+ * sure to have a driver for. For all defconfigs this is either FAT
+ * or UBI, or NOWHERE, which is already handled above.
+ */
+ if (prio == 0) {
+ if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
+ return ENVL_FAT;
+ if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
+ return ENVL_UBI;
+ }
Cheers,
Andre
Quoted 8 lines
Quoted 6 lines
board/sunxi/board.c +0
-0return ENVL_UNKNOWN ; }Regards,
Samuel
Samuel Holland
maintainerHi Andre,
Quoted 67 lines
Quoted 61 lines
Quoted 33 lines · Andre Przywara
Quoted 32 lines
Commit
e42dad4168fe("sunxi: use boot source for determining environment location") changed our implementation ofenv_get_location()and enabled it for every board, even those without MMC support (like the C.H.I.P. boards). However the default fallback location ofENVL_FATdoes not cope very well without MMC support compiled in, so the board hangs when trying to initially load the environment.Change the default fallback location to be
ENVL_FATonly when the FAT environment support is enabled, and useENVL_NOWHEREandENVL_UBIas alternative fallbacks, when those sources are enabled.This fixes U-Boot loading on the C.H.I.P. boards.
Fixes e42dad4168fe ("sunxi: use boot source for determining environment location")Reported-by Chris Morgan <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- board/sunxi/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)board/sunxi/board.c +3
-1@@ -132,7 +132,14 @@ void i2c_init_board(void)*/ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +enum env_location boot_loc; + +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE ))Quoted 8 lines
board/sunxi/board.c void i2c_init_board(void) · line 142
Quoted 5 lines
board/sunxi/board.c +5
-0+ boot_loc =ENVL_NOWHERE ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) + boot_loc =ENVL_FAT ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) + boot_loc =ENVL_UBI ;This could leave
boot_locuninitialized. And there is still an unconditional use ofENVL_FATin theBOOT_DEVICE_MMCxcase.Yeah, it's a mess, and there doesn't seem to be a one-fits-all fallback value. Returning
ENVL_UNKNOWNwhen prio is 0 definitely hangs, as does returning some source without having the corresponding driver compiled in, so getting this right *and* nice-looking is a bit tricky.Quoted 3 lines
board/sunxi/board.c void i2c_init_board(void) · line 143
Quoted 1 line
board/sunxi/board.c +0
-0gd->env_load_prio = prio;I don't think the hook is supposed to change this variable.
Yeah, don't remember why I initially put that in, I must have copied that from somewhere. All I remember is that this code is touchy (as the bug report leading to that patch shows), and there are quite some corner cases to test.
Quoted 4 lines
I'm still a bit confused on the fallback logic you have in place. Splitting it up into three blocks doesn't help. If the goal is to load the environment from the boot device, while preferring filesystems over raw block devices, I propose the following:
Quoted 5 lines
Admittedly this gets messier, I mainly wanted to fix the regression quickly, since it already broke the release for the CHIP boards. I will have a closer look at your suggestion and check for those corner cases, but will probably go with that instead of piling up more cruft on my previous code ;-)
Quoted 12 lines
So I was about to submit your solution, but this is suffering from the same old problem: we must not return
ENVL_UNKNOWNon the first call. FEL booting triggers this: it will lead toenv_init()returning a negative error value, which is fatal, as it's part of init_sequence_f[]. I think the proper fix is to treat this case the same as the-ENOENTcase at the end ofenv_init(), but I don't dare to do this generic change this late in the cycle.
My plan is to hack-fix this for sunxi, for now (see below), then propose the generic change for the next cycle. Does this sound OK? Another solution is to always selectENV_IS_NOWHERE, then return this, but I don't know if this has more side effects, so is also risky at this point.
Yes, this sounds reasonable to me.
Regards,
Samuel
Quoted 99 lines
Quoted 71 lines
Quoted 71 lines
board/sunxi/board.c +18
-23@@ -129,26 +129,38 @@* Try to use the environment from the boot source first. * For MMC, this means a FAT partition on the boot device (SD or eMMC). * If the raw MMC environment is also enabled, this is tried next. -* SPI flash falls back to FAT (on SD card). */ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +if (prio >1 ) +return ENVL_UNKNOWN ; - gd->env_load_prio = prio; +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE )) +return ENVL_NOWHERE ;switch (sunxi_get_boot_device ()) {case BOOT_DEVICE_MMC1 :case BOOT_DEVICE_MMC2 : - boot_loc =ENVL_FAT ; +if (prio ==0 ) { +if (IS_ENABLED (CONFIG_ENV_IS_IN_EXT4 )) +return ENVL_EXT4 ; +if (IS_ENABLED (CONFIG_ENV_IS_IN_FAT )) +return ENVL_FAT ; + } +if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) +return ENVL_MMC ;break ;case BOOT_DEVICE_NAND : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_NAND )) - boot_loc =ENVL_NAND ; +return ENVL_NAND ;break ;case BOOT_DEVICE_SPI : +if (prio ==0 &&IS_ENABLED (CONFIG_ENV_IS_IN_UBI )) +return ENVL_UBI ;if (IS_ENABLED (CONFIG_ENV_IS_IN_SPI_FLASH )) - boot_loc =ENVL_SPI_FLASH ; +return ENVL_SPI_FLASH ;break ;case BOOT_DEVICE_BOARD :break ;@@ -156,23 +168,6 @@break ; } -/* Always try to access the environment on the boot device first. */ -if (prio ==0 ) -return boot_loc; - -if (prio ==1 ) { -switch (boot_loc) { -case ENVL_SPI_FLASH : -return ENVL_FAT ; -case ENVL_FAT : -if (IS_ENABLED (CONFIG_ENV_IS_IN_MMC )) -return ENVL_MMC ; -break ; -default : -break ; - } - } -(quoted diff) +14
-0+ /* + * If we come here for the first call, we *must* return a valid + * environment location other than ENVL_UNKNOWN, or the setup sequence + * in board_f() will silently hang. This is arguably a bug in + * env_init(), but for now pick one environment for which we know for + * sure to have a driver for. For all defconfigs this is either FAT + * or UBI, or NOWHERE, which is already handled above. + */ + if (prio == 0) { + if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) + return ENVL_FAT; + if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) + return ENVL_UBI; + }Cheers,
AndreQuoted 8 lines
Quoted 6 lines
board/sunxi/board.c +0
-0return ENVL_UNKNOWN ; }Regards,
Samuel
Quoted 82 lines · Samuel Holland
Hi Andre,
Quoted 67 lines
Quoted 61 lines
Quoted 33 lines · Andre Przywara
Quoted 32 lines
Commit
e42dad4168fe("sunxi: use boot source for determining environment location") changed our implementation ofenv_get_location()and enabled it for every board, even those without MMC support (like the C.H.I.P. boards). However the default fallback location ofENVL_FATdoes not cope very well without MMC support compiled in, so the board hangs when trying to initially load the environment.Change the default fallback location to be
ENVL_FATonly when the FAT environment support is enabled, and useENVL_NOWHEREandENVL_UBIas alternative fallbacks, when those sources are enabled.This fixes U-Boot loading on the C.H.I.P. boards.
Fixes e42dad4168fe ("sunxi: use boot source for determining environment location")Reported-by Chris Morgan <[email protected]>Signed-off-by Andre Przywara <[email protected]>--- board/sunxi/board.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)board/sunxi/board.c +3
-1@@ -132,7 +132,14 @@ void i2c_init_board(void)*/ enum env_location env_get_location (enum env_operation op,int prio) { -enum env_location boot_loc =ENVL_FAT ; +enum env_location boot_loc; + +if (IS_ENABLED (CONFIG_ENV_IS_NOWHERE ))Quoted 8 lines
board/sunxi/board.c void i2c_init_board(void) · line 142
Quoted 5 lines
board/sunxi/board.c +5
-0+ boot_loc =ENVL_NOWHERE ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT)) + boot_loc =ENVL_FAT ; + else if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI)) + boot_loc =ENVL_UBI ;This could leave
boot_locuninitialized. And there is still an unconditional use ofENVL_FATin theBOOT_DEVICE_MMCxcase.Yeah, it's a mess, and there doesn't seem to be a one-fits-all fallback value. Returning
ENVL_UNKNOWNwhen prio is 0 definitely hangs, as does returning some source without having the corresponding driver compiled in, so getting this right *and* nice-looking is a bit tricky.Quoted 3 lines
board/sunxi/board.c void i2c_init_board(void) · line 143
Quoted 1 line
board/sunxi/board.c +0
-0gd->env_load_prio = prio;I don't think the hook is supposed to change this variable.
Yeah, don't remember why I initially put that in, I must have copied that from somewhere. All I remember is that this code is touchy (as the bug report leading to that patch shows), and there are quite some corner cases to test.
Quoted 4 lines
I'm still a bit confused on the fallback logic you have in place. Splitting it up into three blocks doesn't help. If the goal is to load the environment from the boot device, while preferring filesystems over raw block devices, I propose the following:
Quoted 5 lines
Admittedly this gets messier, I mainly wanted to fix the regression quickly, since it already broke the release for the CHIP boards. I will have a closer look at your suggestion and check for those corner cases, but will probably go with that instead of piling up more cruft on my previous code ;-)
Quoted 12 lines
So I was about to submit your solution, but this is suffering from the same old problem: we must not return
ENVL_UNKNOWNon the first call. FEL booting triggers this: it will lead toenv_init()returning a negative error value, which is fatal, as it's part of init_sequence_f[]. I think the proper fix is to treat this case the same as the-ENOENTcase at the end ofenv_init(), but I don't dare to do this generic change this late in the cycle.
My plan is to hack-fix this for sunxi, for now (see below), then propose the generic change for the next cycle. Does this sound OK? Another solution is to always selectENV_IS_NOWHERE, then return this, but I don't know if this has more side effects, so is also risky at this point.
Quoted 1 line
Yes, this sounds reasonable to me.
Also reasonable sounding to me, and sorting out things properly post v2022.07 with some generic change / behavior fix.
Signature · 1 line
Tom