Yocto 添加自定义 UBoot 环境变量

Mic*_*ael 3 embedded-linux u-boot yocto

我正在尝试通过 Yocto 构建过程添加两个新的 u-boot 环境变量。

我的文件u-boot-imx_2021.04.bbappend包含

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://uboot.patch"
Run Code Online (Sandbox Code Playgroud)

我的文件uboot.patch包含

--- a/configs/mx6ull_14x14_evk_emmc_defconfig   2023-02-23 10:49:03.969189476 -0600
+++ a/configs/mx6ull_14x14_evk_emmc_defconfig   2023-02-23 10:50:06.401233950 -0600
@@ -91,3 +91,14 @@
 CONFIG_FASTBOOT_BUF_SIZE=0x40000000
 CONFIG_FASTBOOT_FLASH=y
 CONFIG_EFI_PARTITION=y
+
+CONFIG_SYS_REDUNDAND_ENVIRONMENT=y
+CONFIG_ENV_OFFSET_REDUND=0xE2000
+CONFIG_BOOTCOUNT_BOOTLIMIT=3
+CONFIG_SYS_MALLOC_F_LEN=0xF000
+CONFIG_CMD_SAVEENV=y
+CONFIG_CMD_LOADENV=y
+
+CONFIG_SWUPDATE_BOOTCMD="setenv bootargs console=ttymxc0,115200 root=/dev/ram0 rootfstype=ext4 rw;load mmc 1:3 0x83000000 /swupdate-image-imx6ull14x14evk.ext4.gz.u-boot;load mmc 1 0x82a00000 imx6ull-14x14-evk.dtb;load mmc 1 0x80800000 zImage;load mmc 1 0x83000000 300000 100000;setenv root /dev/ram0;setenv rootfstype ext4;setenv fw_env_config /etc/fw_env.config;bootz 0x80800000 0x83000000 0x82a00000;"
+CONFIG_SWUPDATE_KERNEL=0
+
Run Code Online (Sandbox Code Playgroud)

该补丁已应用,例如我可以看到CONFIG_SYS_REDUNDAND_ENVIRONMENT,并且CONFIG_SYS_MALLOC_F_LEN值已设置。

当我查看时,build-fb/tmp/work/imx6ull14x14evk-poky-linux-gnueabi/u-boot-imx/2021.04-r0/build/mx6ull_14x14_evk_emmc_config/include/autoconf.mk我看到以下内容:

CONFIG_SWUPDATE_BOOTCMD="setenv swupdate_bootcmd; setenv bootargs console=ttymxc0,115200 root=/dev/ram0 rootfstype=ext4 rw;load mmc 1:3 0x83000000 /swupdate-image-imx6ull14x14evk.ext4.gz.u-boot;load mmc 1 0x82a00000 imx6ull-14x14-evk.dtb;load mmc 1 0x80800000 zImage;load mmc 1 0x83000000 300000 100000;setenv root /dev/ram0;setenv rootfstype ext4;setenv fw_env_config /etc/fw_env.config;bootz 0x80800000 0x83000000 0x82a00000;"
CONFIG_SWUPDATE_KERNEL="setenv swupdate_kernel 0"
Run Code Online (Sandbox Code Playgroud)

当我启动设备并进入 U-Boot 时,我运行printenv但两个新变量不存在。我错过了什么小步骤?

saw*_*ust 5

我正在尝试添加两个新的 u-boot 环境变量
...
当我启动设备并进入 U-Boot 时,我运行 printenv 并且我的两个新变量不存在。我错过了什么小步骤?

配置选项(例如CONFIG_XXX)和环境变量之间的关系并不像您想象的那样相关。仅使用一组已知的配置选项(在将它们转换为预处理器宏之后)来组成默认环境。(由于配置选项(在.config中)和宏(在include/ generated/autoconf.h中)看起来相同,一些开发人员忘记或没有意识到存在转换过程。)因此,您根本无法通过新的配置选项(或宏)。

要查看哪些配置选项用于组成默认环境,请参阅include/env_default.h


U-Boot 实际上有几组环境变量,具体来说是默认值、活动值和保存值。

  • 默认环境是在构建时定义并保留在二进制映像中的一组环境变量。

  • 保存的环境是保留在持久存储中的一组环境变量。它们必须使用 saveenv命令写入,并使用 CRC32 校验字进行验证。

  • 活动环境是 U-Boot 执行时保存在 RAM 中的一组环境变量。

启动时,U-Boot 尝试使用已保存的环境填充(空)活动环境,但前提是 CRC32 校验字确认已保存环境的完整性。
验证成功后,持久存储中的环境变量(静默)将成为活动环境。
当验证失败时,会显示一条通知“警告:错误的 CRC,使用默认环境”,并且默认环境中的环境变量将变为活动环境。

printenv命令(仅)显示活动环境变量集。
构建 U-Boot 时,定义了一组默认环境变量。或者,也可以使用mkenvimage工具创建一组已保存的环境变量(例如,可以与新的u-boot.bin可执行文件一起安装的预构建的u-boot.env文件)。



将新环境变量添加到默认环境的一种方法是使用 CONFIG_EXTRA_ENV_SETTINGS。来自U-Boot 源中的README文件:

CONFIG_EXTRA_ENV_SETTINGS

Define this to contain any number of null terminated
strings (variable = value pairs) that will be part of
the default environment compiled into the boot image.

For example, place something like this in your
board's config file:

    #define CONFIG_EXTRA_ENV_SETTINGS \
        "myvar1=value1\0" \
        "myvar2=value2\0"

Warning: This method is based on knowledge about the
internal format how the environment is stored by the
U-Boot code. This is NOT an official, exported
interface! Although it is unlikely that this format
will change soon, there is no guarantee either.
You better know what you are doing here.

Note: overly (ab)use of the default environment is
discouraged. Make sure to check other ways to preset
the environment like the "source" command or the
boot command first.
Run Code Online (Sandbox Code Playgroud)

请注意,CONFIG_EXTRA_ENV_SETTINGS 通常仅定义为宏,而不用作配置选项。例如,请参阅include/configs/mx6ullevk.h

将新环境变量添加到默认环境的另一种方法是使用 CONFIG_USE_DEFAULT_ENV_FILE (这是一个配置选项)。其Kconfig描述为:

 CONFIG_USE_DEFAULT_ENV_FILE:
 
 Normally, the default environment is automatically generated
 based on the settings of various CONFIG_* options, as well
 as the CONFIG_EXTRA_ENV_SETTINGS. By selecting this option,
 you can instead define the entire default environment in an 
 external file.
Run Code Online (Sandbox Code Playgroud)