Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How u-boot bootloader reads/saves its environment Variables?

Tags:

linux

arm

u-boot

  • How u-boot bootloader reads/saves its environment Variables ?
  • How we declare address of u-boot environment Variable section in Flash ?

  • From description at here : The U-Boot environment is a block of memory that is kept on persistent storage and copied to RAM when U-Boot starts.

What's meaning of " copied to RAM" ?

U-boot will copy block of memory of environment variables to RAM ?

Thanks

like image 415
Thang Le Avatar asked Dec 11 '13 17:12

Thang Le


People also ask

Where are U-Boot environment variables stored?

The U-Boot environment is stored in the SD Card memory and is persistent across power or reset cycles. Parameters defined by the U-boot environment variables include: target IP address, target MAC address, location in RAM where a Linux bootable image will be loaded, and many others.

What is boot environment variable?

The U-Boot environment is a block of memory in persistent storage. It is used to store variables in the form name=value.


1 Answers

Yes, U-boot will copy block of memory of environment variables to RAM.

The persistent storage, where the block comes from, is platform-specific. Some common storage options (and source file handling that storage option):

NOR flash   env/flash.c
SPI flash   env/sf.c
MMC         env/mmc.c

CONFIG_ definitions in include/configs/yourboard.h will determine the details. For example, for SPI flash mapped at top of memory, maybe:

#define CONFIG_ENV_IS_IN_SPI_FLASH
#define CONFIG_ENV_SIZE    0x00001000
#define CONFIG_ENV_ADDR    0xFFFFF000

CONFIG_ENV_ADDR is address of u-boot environment Variable section in Flash.

Note that u-boot automatically creates a CRC32 over this section when writing the environment to persistent storage. That CRC is checked when environment is read on startup. If CRC check does not pass, the stored environment is not used; instead a new default environment hardcoded into the program code is used, that is a special case.

During U-Boot initialization, the environment variables are imported into a hash table. In operation, all read/write operations, and all "printenv" (display environment variable) and "setenv" (set environment variable) commands use those table entries. Any changes are unsaved until command "saveenv" is done, which writes to the persistent storage.

For more info, see u-boot/common/cmd_nvedit.c lines 14-24 and u-boot/README lines 3474-3881 (line numbers are for v2013.10).

like image 164
Joe Kul Avatar answered Oct 17 '22 01:10

Joe Kul