Yocto 添加自定义 UBoot 环境变量

问题描述 投票:0回答:1

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

我的文件

u-boot-imx_2021.04.bbappend
包含

FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += " file://uboot.patch"

我的文件

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
+

应用此补丁,例如我可以看到

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"

当我启动我的设备并进入 U-Boot 时,我运行

printenv
并且我的两个新变量不存在。我错过了哪一小步?

embedded-linux yocto u-boot
1个回答
0
投票

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

你好像有两个误会

首先,配置符号(例如 CONFIG_XXX)和环境变量之间的关系并不像您假设的那样相关。只有一组已知的配置符号(在它们被翻译成预处理器宏之后)用于构建默认环境。 (由于配置符号(在 .config 中)和宏(在 include/generated/autoconf.h 中)看起来相同,一些开发人员忘记或不知道有一个转换过程。)所以你根本无法创建自己的通过新配置符号(或宏)的环境变量。

默认环境的搭建参考include/env_default.h


其次,U-Boot其实有几组环境变量,具体是default、active、saved。

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

保存的环境是一组保留在持久存储中的环境变量。它们必须使用

saveenv
命令编写,并使用 CRC32 校验字进行验证。

活动环境是 U-Boot 执行时保存在 RAM 中的一组环境变量。
在启动时,U-Boot 尝试用保存的环境填充活动环境,但前提是 CRC32 校验字确认保存的环境的完整性。
验证成功后,持久存储中的环境变量(静默地)成为活动环境。
当验证失败时,会显示一条通知,“Warning: Bad CRC, using default environment”,默认环境中的环境变量成为活动环境。

printenv
命令显示活动环境变量集。在构建 U-Boot 时,通常会定义一组默认环境变量。也可以选择创建一组已保存的环境变量(例如,可以与新的 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.

另一种为默认环境添加新环境变量的方法是使用CONFIG_USE_DEFAULT_ENV_FILE。

 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.
© www.soinside.com 2019 - 2024. All rights reserved.