fw_printenv config for AllWinner devices

The u-boot suite of tools has a very handy tool allowing you to work with the u-boot environment from Linux user space. There are two complications with this on the Allwinner SoCs, first the version of the u-boot tools that Debian ships don’t support the mmc card.

You’ll need an up to date version of u-boot git tree either directly from denx or the linux-sunxi project. Downloading and setting up the git u-boot tree is well documented so I’m not going to cover it here, but the fw_printenv tool isn’t built by default so you need to build it.

make env

The fw_printenv tool is found in the tools/env directory, copy it somewhere useful.

sudo install -m 755 tools/env/fw_printenv /usr/local/bin/

To write to the u-boot environment you also need to create a symlink from fw_printenv to fw_setenv.

sudo ln -s /usr/local/bin/fw_printenv /usr/local/bin/fw_setenv

The second problem is making a working configuration file. The configuration file only needs a single line in it to tell fw_printenv where to look (the offset from the start of the device) for the u-boot environment and how big it is. The complication is they need to be in bytes and given in hex, to calculate the offset and size I used the sd layout from the sunxi wiki and a bit of maths in bc to convert it to hex.

To calculate the offset, multiply the number (1088) of blocks by the block size (512 bytes) and then convert it to base16 (ie hex)

echo "obase=16; 1088*512 "| bc

To calculate the size of the u-boot environment repeat the process but this time with the number (128) of blocks by the block size (1024 bytes) and again convert it to base16.

echo "obase=16; 128*1024 "| bc

Finally put the numbers we have calculated in to the configuration file /etc/fw_env.config

# Device to access      offset          env size
/dev/mmcblk0            0x88000         0x20000

You should now be able to run fw_printenv and get your environment printed out, if the error “Warning: Bad CRC, using default environment” then your u-boot setup is different and you shouldn’t use fw_setenv.