Modifying U-Boot env vars at runtime
U-Boot
Miyoo

U-Boot and Miyoo

What we'll be doing:
  1. Querying U-Boot environment variables
  2. Modifying U-Boot environment variables


1. Query U-Boot Environment Variables:

On your device, run the following command to print U-Boot environment variables:

/etc/fw_printenv
Example output:
SdUpgradeImage=miyoo354_fw.img
UpgradePort=1
baudrate=115200
boot1=test
boot2=test
boot3=test
bootargs=console=ttyS0,115200 root=/dev/mtdblock4 rootfstype=squashfs ro init=/linuxrc LX_MEM=0x7f00000 mma_heap=mma_heap_name0,miu=0,sz=0x1500000 
 mma_memblock_remove=1 highres=off mmap_reserved=fb,miu=0,sz=0x300000,max_start_off=0x7C00000,max_end_off=0x7F00000
bootcmd=gpio output 73 1;sleepms 50;gpio output 73 0;sleepms 150;gpio output 73 1;gpio output 85 1; bootlogo 0 0 0 0 0; mw 1f001cc0 11; 
 gpio out 8 0; sf probe 0;sf read 0x22000000 ${sf_kernel_start} ${sf_kernel_size}; gpio out 8 1; sleepms 1000; gpio output 4 1; bootm 0x22000000
bootdelay=0
cpu_part_start=14270000
dispout=K101_IM2BVL
ethact=sstar_emac
ethaddr=00:30:1b:ba:02:db
filesize=1774c
miyoo_upgrade=gpio output 4 1; bootlogo 1 0 0 0 0; UpgradePort 1; sdstar
miyoo_version=202306282128
sf_kernel_size=200000
sf_kernel_start=60000
sf_part_size=20000
sf_part_start=270000
test=Test
usb_folder=images
stderr=/dev/pts/0
stdout=/dev/pts/0
hostname=miyoo

2. Modify U-Boot Environment Variables:

To modify an environment variable, use the fw_setenv command. For example, to set a variable named newvar with the value hello, run:

/etc/fw_setenv newvar hello

3. Verify the Changes:

Confirm the change by printing the environment variables again and using grep to find the specific variable:

/etc/fw_printenv | grep newvar
Example output:
newvar=hello
Alternatively, you can use the printenv command in U-Boot:
 SigmaStar # printenv
 SdUpgradeImage=miyoo354_fw.img
 UpgradePort=1
 baudrate=115200
 boot1=test
 boot2=test
 boot3=test
 bootargs=console=ttyS0,115200 root=/dev/mtdblock4 rootfstype=squashfs ro init=/linuxrc LX_MEM=0x7f00000 mma_heap=mma_heap_name0,miu=0,sz=0x1500000 
  mma_memblock_remove=1 highres=off mmap_reserved=fb,miu=0,sz=0x300000,max_start_off=0x7C00000,max_end_off=0x7F00000
 bootcmd=gpio output 73 1;sleepms 50;gpio output 73 0;sleepms 150;gpio output 73 1;gpio output 85 1; bootlogo 0 0 0 0 0; mw 1f001cc0 11; 
  gpio out 8 0; sf probe 0;sf read 0x22000000 ${sf_kernel_start} ${sf_kernel_size}; gpio out 8 1; sleepms 1000; gpio output 4 1; bootm 0x22000000
 bootdelay=0
 cpu_part_start=14270000
 dispout=K101_IM2BVL
 ethact=sstar_emac
 ethaddr=00:30:1b:ba:02:db
 filesize=1774c
 hostname=miyoo
 miyoo_upgrade=gpio output 4 1; bootlogo 1 0 0 0 0; UpgradePort 1; sdstar
 miyoo_version=202306282128
 sf_kernel_size=200000
 sf_kernel_start=60000
 sf_part_size=20000
 sf_part_start=270000
 stderr=serial
 stdin=serial
 stdout=serial
 newvar=hello
 test=Test
 usb_folder=images

Environment size: 1088/4092 bytes
SigmaStar #

4. Modify an Existing U-Boot Environment Variable:

To modify an existing variable, use the fw_setenv command with the existing variable's name. For example, to change the bootdelay variable to 5, run:

/etc/fw_setenv bootdelay 5

Terminal Icon

/# /etc/fw_setenv newvar hello

/# /etc/fw_printenv | grep newvar

newvar=hello

/# /etc/fw_setenv bootdelay 5

/# /etc/fw_printenv | grep bootdelay

bootdelay=5

/# exit