u-boot environment variables

U-Boot supports user configuration using environment variables which can be made persistent by saving to persistent storage, for example flash memory.

Environment variables are set using env set (alias setenv), printed using env print (alias printenv), and saved to persistent storage using env save (alias saveenv). Using env set without a value can be used to delete a variable from the environment. As long as you don’t save the environment, you are working with an in-memory copy. In case the Flash area containing the environment is erased by accident, a default environment is provided.

For more info refer: env command and Environment Variables

Save environment to mmc

modify the _defconfig file

 CONFIG_ENV_SIZE=0x20000
 CONFIG_ENV_OFFSET=0x680000
 CONFIG_ENV_IS_IN_MMC=y

NOTE: make sure to disable CONFIG_ENV_OVERWRITE if enabled.

Apply below change to diaable CONFIG_ENV_OVERWRITE.

 -CONFIG_ENV_OVERWRITE=y
 +# CONFIG_ENV_OVERWRITE=y is not set

Save environment to fat partation

modify the _defconfig file

CONFIG_ENV_SIZE=0x20000
CONFIG_ENV_OFFSET=0x680000
CONFIG_ENV_IS_IN_FAT=y
CONFIG_ENV_FAT_INTERFACE="mmc"
CONFIG_ENV_FAT_DEVICE_AND_PART="1:1"
CONFIG_ENV_FAT_FILE="saveenv.env"
CONFIG_ENV_FAT_FILE_REDUND="saveenv.env"

NOTE: make sure to disable CONFIG_ENV_OVERWRITE if enabled.

Save environment to NOR Flash

modify the _defconfig file

CONFIG_ENV_IS_IN_SPI_FLASH=y
CONFIG_ENV_OFFSET=0x680000
CONFIG_ENV_SIZE=0x40000
CONFIG_ENV_OFFSET_REDUND=y
CONFIG_ENV_SECT_SIZE=0x40000

Save environment to NAND Flash

modify the _defconfig file

CONFIG_CMD_NAND=y
CONFIG_SPI_FLASH_MTD=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
CONFIG_ENV_OFFSET=0x680000
CONFIG_ENV_SIZE=0x40000
CONFIG_ENV_OFFSET_REDUND=y
CONFIG_ENV_SECT_SIZE=0x40000
# Select SPI Flash BUS
CONFIG_SF_DEFAULT_BUS=0

NOTE: make sure to modify CONFIG_SF_DEFAULT_BUS based on the bus where NAND Flash connected.


©2023-2024 rculock.com