Fw_printenv: environment WRONG, but dd mmblk0 | hd looks right

I flashed this image:

$ aml-burn-tool -b VIM3 -i VIM3_Ubuntu-server-focal_Linux-4.9_arm64_EMMC_V1.0.7-210625.img

I verified that U-Boot env persistence works by first adding near the top of /boot/boot.ini:

echo "test123=${test123}"
setenv test123 avalue

After two reboots, the echo line shows test123=avalue, finding the value from the previous saveenv.

During boot, in the serial console I see:

mmcblk0p3 env 0x6c00000 0x800000

I confirmed that the offset of the env partition contains the U-Boot environment:

$ sudo dd if=/dev/mmcblk0 skip=$((0x6c00000/512)) count=$((0x800000/512)) | hd | grep -FA1 test
000019d0  66 69 3b 66 69 3b 66 69  3b 00 74 65 73 74 31 32  |fi;fi;fi;.test12|
000019e0  33 3d 61 76 61 6c 75 65  00 74 72 79 5f 61 75 74  |3=avalue.try_aut|


Then I installed:

$ sudo apt-get install libubootenv-tool

I configured /etc/fw_env.config with

/dev/mmcblk0 0x6c00000 0x800000

But I’m getting:

$ sudo fw_printenv
Environment WRONG, copy 0
Cannot read environment, using default
Cannot read default environment from file

I also tried adding 512 for explicit sector size at the end of the fw_env.config line, but it made no difference.

What am I doing wrong?

We already has correct configuration file, why did you change it?

khadas@Khadas:~$ cat /etc/fw_env.config
# Configuration file for fw_(printenv/setenv) utility.
# Up to two entries are valid, in this case the redundant
# environment sector is assumed present.
# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash.
# Futhermore, if the Flash sector size is ommitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash

# Block device example
/dev/env                0x0             0x10000

why did you change it?

Oh. Haha. Because it says “block device example”. I didn’t think to check if it actually worked :slight_smile:

Okay, so I reverted to the “example” and it works. But why did mmcblk0 + offset not work?

I made one more test with

/dev/mmcblk0 0x6c00000 0x10000

and it worked.
So I guess the offset reported for the env partition does work, but the size reserved in the eMMC is wrong?

#define CONFIG_ENV_SIZE   (64*1024)

Then, why is the env partition allocated with size 0x000800000 ?