Accessing U-Boot Environment from Userspace
The 4Kopen board uses U-Boot as the bootloader. Using the u-boot-tools package, you can inspect and modify the U-Boot environment from within userspace.
apt install u-boot-tools
You'll also need to setup the configuration, put only the following in /etc/fw_env.config
:
# MTD device name Device offset Env. size Flash sector size
/dev/mtd0 0xC0000 0x4000 0x10000
Once setup, you can use fw_printenv
to confirm that it is operating correctly:
fourkopen@4kopen:~ $ sudo fw_printenv
bootcmd=run load_mac;echo Looking for uenv.txt on sdcard;if mmc rescan && fatload mmc 0:1 0x98000000 uenv.txt; then setenv bootdev mmc; run load_env; boot; echo *** Boot from MMC failed... ***; fi; echo Looking for uenv.txt on usb 0:1; if usb start && usb storage && fatload usb 0:1 0x98000000 uenv.txt; then setenv bootdev usb; run load_env; boot; echo *** Boot from USB failed... ***; fi; echo Starting a default system; display_splash error; run error; sf probe; sf read 0x98000000 0x100000 766a00; bootm 0x98000000; reset;
bootdelay=0
error=run ledt; run ledt; run ledt; run ledt; run ledt;
ethact=stmac-1
fdt_high=0xffffffff
ledt=led green on;sleep 1;led green off;sleep 1;
load_env=env import -t 0x98000000 ${filesize}
load_mac=sf probe; sf read 0x97000000 0xD0000 1B;env import -t 0x97000000 1B;
stderr=serial
stdin=serial
stdout=serial
If you see a warning about CRC issues, or "using default environment", then something is probably not configured correctly. For example:
Warning: Bad CRC, using default environment
NOTE: Do NOT use fw_setenv
if fw_printenv
gives any warnings, as you likely have an error with your configuration and risk corrupting the flash, and potentially rendering the board unusable.
NOTE: Incorrect use of the fw_setenv
utility can render your board unusable - be careful.
Utilities
- Print whole environment:
fw_printenv
- Print specific environment variable:
fw_printenv ${NAME}
- Clear (delete) environment variable
fw_setenv ${NAME}
- Set environment variable:
fw_setenv ${NAME} ${VALUE}