Managing U-Boot Environment Variables from Linux User Space with the Yocto Project and OpenEmbedded
In the previous episode of my Yocto Project and OpenEmbedded series for Raspberry Pi 5, we transitioned to the open-source U-Boot bootloader. Now, in this follow-up (Episode 5), we will explore how to view and modify U-Boot environment variables from the Linux user space using the fw_printenv and fw_setenv tools from libubootenv.
U-Boot
U-Boot is a widely adopted open-source bootloader for embedded systems. It plays a crucial role in initializing hardware and loading the OS kernel. Supporting multiple architectures such as ARM, x86, and RISC-V, U-Boot provides features like networking, storage access, and scripting capabilities, making it a versatile component in Linux-based embedded devices.
Our demonstrations leverage the community-driven Yocto and OpenEmbedded BSP layer meta-raspberrypi. The build setup is based on the Yocto LTS release Scarthgap, which defaults to U-Boot v2024.01. However, since Raspberry Pi 5 support was only introduced in U-Boot v2024.04, we previously used the scarthgap/u-boot branch of the Yocto/OE layer meta-lts-mixins to bridge this gap.
Steps to Modify U-Boot Environment Variables from Linux User Space
Follow these steps to manage U-Boot environment variables from Linux user space on our custom image for Raspberry Pi 5:
1. Initialize the Build Environment
source oe-init-build-env
2. Modify Local Configuration
Add the following line to conf/local.conf to include the necessary U-Boot utilities:
Flash the generated core-image-base onto a microSD card and boot the Raspberry Pi 5 with it.
5. Interrupt U-Boot and List Available Variables
When prompted, quickly press any key to interrupt U-Boot and access the U-Boot shell. Then, execute:
printenv
6. Create a New U-Boot Environment Variable
setenv hello world
7. Boot into Linux
To proceed with booting into the Linux distribution, execute:
boot
(Optional: You can also use saveenv to persist changes, but it is not needed for this demo.)
8. List U-Boot Variables from Linux User Space
After logging in as root, verify the U-Boot environment variables using:
fw_printenv hello
9. Modify a U-Boot Variable from Linux
fw_setenv hello world2
10. Create a New U-Boot Variable from Linux
fw_setenv foo bar
11. Reboot and Verify Changes
Reboot the Raspberry Pi 5, interrupt U-Boot, and check the values of hello and foo:
fw_printenv hello
fw_printenv foo
Conclusion
By following these steps, you can efficiently modify U-Boot environment variables from Linux user space on the Raspberry Pi 5. The same approach can be applied to other embedded Linux devices and hardware platforms using U-Boot. This process is essential for fine-tuning embedded system configurations without needing direct U-Boot shell access every time. It is often used for software update solutions such as Mender, RAUC and SWUpdate. Stay tuned for more insights into embedded development with the Yocto Project and OpenEmbedded!