Suggestion: When flash is uninitialized, *silently* fall back to default environment

Zack Weinberg zackw at
Thu Jul 1 01:19:19 CEST 2021

Consider a boot ROM that looks for u-boot in several places (SPI
flash, eMMC flash, etc) and loads the first one it finds, and then
u-boot repeats the same search to find its own configuration.  If
there is _nothing_ on the SPI flash and u-boot and all its
configuration is on the eMMC, this will work fine _except_ that you'll
get a scary-looking message from env_set_default

*** Warning: bad CRC, using default environment

because uninitialized flash memory reads as all-ones (FF FF FF FF ...)
and the crc32 of ENV_SIZE bytes of 0xFF will typically not be 0xFFFF.

I'd like to suggest that env_import() should, when the CRC fails, scan
the environment block, and if it's uniformly 0xFF or uniformly 0x00,
then it should call env_set_default(0,0) instead of
env_set_default("bad CRC", 0).  If I'm reading the code right, the
only effect of this will be to suppress the warning message.

Thanks for your consideration,

ps. Can we be sure that the crc32 of ENV_SIZE bytes of 0xFF will
_never_ be 0xFFFF and the crc32 of ENV_SIZE bytes of 0x00 will _never_
be 0x0000?  If not, it might be wise to do the scans for blank
flash/disk sectors _first_, rather than relying on the CRC to detect

More information about the U-Boot mailing list