Yocto 添加自定义 UBoot 环境变量

huangapple go评论58阅读模式
英文:

Yocto add custom UBoot Environment Variables

问题

在我尝试添加两个新的 U-Boot 环境变量到 Yocto 构建过程中,我发现以下问题:

  1. 我的 u-boot-imx_2021.04.bbappend 文件包含如下内容:
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
SRC_URI += "file://uboot.patch"
  1. 我的 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
  1. 在构建后,我查看了 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"
  1. 然而,当我启动设备并进入 U-Boot 后,运行 printenv 命令时,我发现我的两个新变量并不出现。

根据您提供的信息,似乎您忽略了将新的 U-Boot 环境变量保存到设备上。在 U-Boot 中,只在设置新环境变量后,通过 saveenv 命令将其保存到设备上才会生效。请确保在设置完这些环境变量后,运行以下命令以保存它们:

saveenv

这将把您的新环境变量保存到设备的存储中,以便在以后的启动中使用。如果您已经设置了这些变量,但它们仍然不出现,可能是由于没有正确保存它们导致的。

英文:

I am trying to add two new u-boot environment variables through my Yocto build process.

My file u-boot-imx_2021.04.bbappend contains

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

My file uboot.patch contains

--- 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
+

This patch is applied, for example I can see CONFIG_SYS_REDUNDAND_ENVIRONMENT, and CONFIG_SYS_MALLOC_F_LEN values are set.

When I look into build-fb/tmp/work/imx6ull14x14evk-poky-linux-gnueabi/u-boot-imx/2021.04-r0/build/mx6ull_14x14_evk_emmc_config/include/autoconf.mk I see the following:

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"

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?

答案1

得分: 4

> 我正在尝试添加两个新的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.env文件,可以与新的u-boot.bin可执行文件一起安装)。


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

CONFIG_EXTRA_ENV_SETTINGS

将其定义为包含任意数量的空终止字符串(变量=值对),这些字符串将成为编译到引导映像中的默认环境的一部分。

例如,在你的板的配置文件中放置类似于以下内容:

#define CONFIG_EXTRA_ENV_SETTINGS \
	"myvar1=value1
CONFIG_EXTRA_ENV_SETTINGS
将其定义为包含任意数量的空终止字符串(变量=值对),这些字符串将成为编译到引导映像中的默认环境的一部分。
例如,在你的板的配置文件中放置类似于以下内容:
#define CONFIG_EXTRA_ENV_SETTINGS \
"myvar1=value1\0" \
"myvar2=value2\0"
警告:此方法基于关于U-Boot代码如何存储环境的内部格式的了解。这不是一个官方的、导出的接口!虽然这种格式可能不会很快改变,但也不能保证。你最好知道你在做什么。
注意:过度(滥用)默认环境是不鼓励的。请务必先检查其他预设环境的方法,如“source”命令或“boot”命令。
" \ "myvar2=value2
CONFIG_EXTRA_ENV_SETTINGS
将其定义为包含任意数量的空终止字符串(变量=值对),这些字符串将成为编译到引导映像中的默认环境的一部分。
例如,在你的板的配置文件中放置类似于以下内容:
#define CONFIG_EXTRA_ENV_SETTINGS \
"myvar1=value1\0" \
"myvar2=value2\0"
警告:此方法基于关于U-Boot代码如何存储环境的内部格式的了解。这不是一个官方的、导出的接口!虽然这种格式可能不会很快改变,但也不能保证。你最好知道你在做什么。
注意:过度(滥用)默认环境是不鼓励的。请务必先检查其他预设环境的方法,如“source”命令或“boot”命令。
" 警告:此方法基于关于U-Boot代码如何存储环境的内部格式的了解。这不是一个官方的、导出的接口!虽然这种格式可能不会很快改变,但也不能保证。你最好知道你在做什么。 注意:过度(滥用)默认环境是不鼓励的。请务必先检查其他预设环境的方法,如“source”命令或“boot”命令。

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

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

CONFIG_USE_DEFAULT_ENV_FILE:

通常,根据各种CONFIG_*选项的设置以及CONFIG_EXTRA_ENV_SETTINGS,将自动生成默认环境。通过选择此选项,你可以在外部文件中定义整个默认环境。

英文:

> 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?

The relationship between configuration options (e.g. CONFIG_XXX) and environment variables is not as correlated as you assume. Only a known set of configuration options (after they have been translated into preprocessor macros) are used to compose the default environment. (Since the configuration options (in .config) and macros (in include/generated/autoconf.h) appear identical, some developers forget or are unaware that there is a conversion process.) So you simply cannot create your own environment variable through a new configuration option (or macro).

To see which configuration options are used to compose the default environment, refer to include/env_default.h.


U-Boot actually has several sets of environment variables, specifically the default, active, and saved.

  • The default environment is the set of environment variables that are
    defined at build time, and retained in the binary image.

  • The saved environment is the set of environment variables that are
    retained in persistent storage. They have to be written using the
    saveenv command, and are validated using a CRC32 checkword.

  • The active environment is the set of environment variables that are
    held in RAM while U-Boot executes.

On startup U-Boot tries to populate the (empty) active environment with the saved environment, but only if the CRC32 checkword confirms the integrity of the saved environment.
When validation is successful, the environment variables from the persistent storage (silently) become the active environment.
When validation fails, a notice is displayed, "Warning: Bad CRC, using default environment", and the environment variables from the default environment become the active environment.

The printenv command (only) displays the set of active environment variables.
When building U-Boot, the set of default environment variables is defined. Optionally the set of saved environment variables can also be created (e.g. a pre-built u-boot.env file that can be installed with the new u-boot.bin executable) using the mkenvimage tool.



One method of adding new environment variables to the default environment is to use CONFIG_EXTRA_ENV_SETTINGS. From the README file in U-Boot source:

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
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.
" \ "myvar2=value2
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.
" 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.

Note that CONFIG_EXTRA_ENV_SETTINGS is typically only defined as a macro, rather than used as a configuration option. For example refer to include/configs/mx6ullevk.h.

Another method of adding new environment variables to the default environment is to use CONFIG_USE_DEFAULT_ENV_FILE (which is a configuration option). Its Kconfig description is:

 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.

huangapple
  • 本文由 发表于 2023年2月24日 00:38:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75547754.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定