Hi, I’m the Toradex AI Assistant.
I might make mistakes or occasionally get you wrong. Our support team will step in if needed.
Adding U-Boot Environment Variables in Yocto Build
You can add U-Boot environment variables directly during your Yocto build by modifying the U-Boot configuration files. Here’s how to approach this:
Method 1: Modify Board-Specific Configuration Files
The default environment variables are set at compilation time and built into the U-Boot binary (1). You can modify these by creating a U-Boot bbappend file that patches the board-specific configuration header file.
For example, if you’re working with a Verdin iMX8M Plus, you would modify the configuration found in the board-specific header file (1). The default environment is defined using CONFIG_EXTRA_ENV_SETTINGS (1).
Here’s an example of how environment variables are defined in the configuration:
/* Initial environment variables */
#define CONFIG_EXTRA_ENV_SETTINGS \
BOOTENV \
MEM_LAYOUT_ENV_SETTINGS \
"bootcmd_mfg=fastboot 0\0" \
"boot_file=Image\0" \
"boot_scripts=" BOOT_SCRIPT "\0" \
"boot_script_dhcp=" BOOT_SCRIPT "\0" \
"console=ttymxc2\0" \
"fdt_board=dev\0" \
"initrd_addr=0x43800000\0" \
"initrd_high=0xffffffffffffffff\0" \
"setup=setenv setupargs console=tty1 console=${console},${baudrate} " \
"consoleblank=0 earlycon\0" \
"update_uboot=askenv confirm Did you load flash.bin (y/N)?; " \
"if test \"$confirm\" = \"y\"; then " \
"setexpr blkcnt ${filesize} + 0x1ff && setexpr blkcnt " \
"${blkcnt} / 0x200; mmc dev 2 1; mmc write ${loadaddr} 0x0 " \
"${blkcnt}; fi\0"
(1)
Method 2: Create a U-Boot bbappend
Create a bbappend file for the U-Boot recipe (e.g., u-boot-toradex_%.bbappend) in your custom meta layer. In this file, you can:
- Add patches to modify the board configuration header
- Use
do_configure_prepend or do_configure_append tasks to modify configuration files
- Set additional environment variables through the build system
Important Considerations
When working with U-Boot environment variables, keep these best practices in mind (1):
- Default Environment: The default environment is always present and is used when the board is first flashed (1)
- Persistent Storage: Changes made with
setenv in U-Boot only affect the RAM representation until saveenv is called (1)
- Dynamic Variables: Some variables can be altered by U-Boot code during boot, so saving the environment can have unexpected consequences (1)
Alternative Approach: TorizonCore Builder Limitations
While TorizonCore Builder is excellent for many customizations, it has limitations. TorizonCore Builder does not support customizing the bootloader (U-Boot) (2). For U-Boot modifications like adding environment variables, you need to use the Yocto Project approach (2).
The method you mentioned using TorizonCore Builder to modify the u-boot-initial-env-sd file in a post-build script is a valid workaround, but integrating the changes directly into the Yocto build provides better maintainability and reproducibility.
Best regards, Toradex AI Assistant.
Did you like my answer?

If I answered your question, please tick the “Solution” checkbox.
For follow-up questions to me, please use @ToradexAI in your post.