Linux u-boot 引导加载程序如何读取/保存其环境变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20525704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:36:46  来源:igfitidea点击:

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

linuxarmu-boot

提问by Thang Le

  • 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.

  • u-boot 引导加载程序如何读取/保存其环境变量?
  • 我们如何在 Flash 中声明 u-boot 环境变量部分的地址?

  • 来自此处的描述:U-Boot 环境是一块内存,在 U-Boot 启动时保存在持久存储中并复制到 RAM。

What's meaning of " copied to RAM" ?

复制到内存”是什么意思?

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

U-boot 会将环境变量的内存块复制到 RAM 中吗?

Thanks

谢谢

回答by yegorich

The address and size of env variables block will be defined in the board headers file. See include/configs/am3517_evm.hfor example:

环境变量块的地址和大小将在板头文件中定义。参见include/configs/am3517_evm.h例如:

#define CONFIG_SYS_ENV_SECT_SIZE        (128 << 10)     /* 128 KiB */
#define CONFIG_ENV_OFFSET               SMNAND_ENV_OFFSET
#define CONFIG_ENV_ADDR                 SMNAND_ENV_OFFSET

u-boot loads CONFIG_SYS_ENV_SECT_SIZEfrom SMNAND_ENV_OFFSET. You can change values and then save them via saveenv.

u-bootCONFIG_SYS_ENV_SECT_SIZESMNAND_ENV_OFFSET. 您可以更改值,然后通过saveenv.

回答by Joe Kul

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

是的,U-boot 会将环境变量的内存块复制到 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:

include/configs/yourboard.h 中的 CONFIG_ 定义将确定详细信息。例如,对于映射在内存顶部的 SPI 闪存,可能:

#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.

CONFIG_ENV_ADDR 是 Fl​​ash 中 u-boot 环境变量部分的地址。

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.

请注意,将环境写入持久存储时,u-boot 会自动在此部分上创建 CRC32。在启动时读取环境时会检查该 CRC。如果CRC校验不通过,则不使用存储环境;相反,使用硬编码到程序代码中的新默认环境,这是一种特殊情况。

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.

在 U-Boot 初始化期间,环境变量被导入到哈希表中。在操作中,所有读/写操作以及所有“printenv”(显示环境变量)和“setenv”(设置环境变量)命令都使用这些表条目。任何更改都不会保存,直到命令“saveenv”完成,该命令写入持久存储。

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

有关更多信息,请参阅u-boot/common/cmd_nvedit.c第 14-24 行和u-boot/README行 3474-3881(行号适用于 v2013.10)。