U-Boot – Load custom config

By | December 1, 2021

In my app, I needed to force Linux Kernel Framebuffer resolution, until X server is initialized. This is possible via various kernel command line options, one is using video=HDMI-A-1:1280x720. Now I need to have this to be possible to configure via my app, and in this tutorial I will show you how I made it.

In u-boot, you’re specifying the kernel command line arguments from boot.cmd, but I don’t want to my app to modify the boot.cmd, since it needs to be also compiled. Thankfully, u-boot have command, which can load additional environment variables env import.

setenv disp_size ""

if test -e ${devtype} ${devnum} {$prefix}/boot_config.txt; then
	load ${devtype} ${devnum} 0x45000000 {$prefix}/boot_config.txt
	env import -t 0x45000000 ${filesize}
fi

setenv bootargs console=ttyS0,115200 earlyprintk root=PARTLABEL=rootfs rootwait ${disp_size}

So, very simply, what is devtype, devnum and prefix ? Devtype is type of device from which is currently booted, in case of SD Card or eMMC, it’s “mmc”. devnum is a device number from devtype, thus in my case, I have SD card supported which is 0, and eMMC which is 1. And last, prefix, it’s a prefix where the boot.cmd is found, mostly it’s / or /boot.

So basically, you check if boot_config.txt exists, and if yes, load it into memory and import it into the environment variables. This is also how boot_config.txt looks

disp_size=video=HDMI-A-1:800x600

This all works on mainline u-boot and kernel for Allwinner H3 🙂

Also, if you want to load the boot_config.txt from somewhere else (in my case, boot.cmd is on FAT32 partition, and I have boot_config.txt on ext4 partition), this is how I made it:

setenv disp_size ""

if test -e ${devtype} ${devnum}:2 /data/boot_config.txt; then
	load ${devtype} ${devnum}:2 0x45000000 /data/boot_config.txt
	env import -t 0x45000000 ${filesize}
fi

setenv bootargs console=ttyS0,115200 earlyprintk root=PARTLABEL=rootfs rootwait ${disp_size}

So, I added after devnum :2 , that’s the index of partition (you can find it via mmc part command in u-boot) where I have my file, and just added path to the file, and it works.

BTW, if you want to check what resolution is set when there is no X running, use command fbset -s.