sunxi: fix initial environment loading without MMC
authorSamuel Holland <samuel@sholland.org>
Wed, 20 Apr 2022 22:15:39 +0000 (23:15 +0100)
committerAndre Przywara <andre.przywara@arm.com>
Sun, 26 Jun 2022 10:22:54 +0000 (11:22 +0100)
commite008e5132f7e160320dcc0ffb8fe7fef5264aecd
treed20d15ad318d47bdab8f5bdd586cd8e494df7d42
parent33112ae0214ed6b260fc982329d02253eab3e35d
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 requires MMC
support compiled in, so the board hangs when trying to initially load
the environment.

Change the algorithm to only return configured environment locations,
and improve the fallback algorithm on the way.

The env_init() routine calling this function here does not behave well
if the return value is ENVL_UNKNOWN on the very first call: it will make
U-Boot proper silently hang very early.
Work around this issue by making sure we return some configured (dummy)
environment location when prio is 0. This for instance happens when
booting via FEL.

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 <macroalpha82@gmail.com>
Signed-off-by: Samuel Holland <samuel@sholland.org>
[Andre: fix FEL boot case by not returning ENVL_UNKNOWN when prio==0]
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
board/sunxi/board.c