embedded-linux - Yocto 添加自定义 UBoot 环境变量

标签 embedded-linux yocto u-boot

我正在尝试通过 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 并且我的两个新变量不存在。我错过了什么小步骤?

最佳答案

I am trying to add two new u-boot environment variables
...
When I boot my device and enter U-Boot, I run printenv and my two new variables are not present. What small step am I missing?

配置选项(例如 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 时,定义了一组默认环境变量。 (可选)还可以创建一组保存的环境变量(例如,可以与新的 u-boot.bin 可执行文件一起安装的预构建的 u-boot.env 文件)使用 mkenvimage工具。



向默认环境添加新环境变量的一种方法是使用 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_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.

关于embedded-linux - Yocto 添加自定义 UBoot 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75547754/

相关文章:

嵌入式Linux还是eCos?

c - 无法从 Linux 中的 C 访问程序集的正确全局标签数据

python - 使用 "devtool modify"修改openbmc代码

linux - uEnv.txt 与 boot.scr

linux - uEnv.txt 到 boot.scr 较新版本的 u-boot 问题

c - 用户空间中缺少 I2c eeprom 文件 - SFP 模块

linux-kernel - Linux 内核 - 错误 : Failed to allocate 0x6b3c bytes below 0x1000000

linux - ../util-linux-2.28.1/schedutils/chrt.c :88:17: error: ‘__NR_sched_setattr’ undeclared (first use in this function)

linux - bzImage 和 grub 配置未安装到 yocto dsk 构建中的 .dsk

c - U-Boot:移植代码时出现意外问题