fw_printenv does not work reliable

  • Hello,


    we have to read/write u-boot environment variables from Linux user space. I added the u-boot-fw-utils to the image, my fw_env.config is


    /dev/mmcblk2boot0 0x00040000 0x4000

    /dev/mmcblk2boot0 0x00040000 0x4000


    Basically, everything seems to work. However, changes in environment variables from u-boot become sometimes not visible in Linux. One way to make this 100% reproducible is the following sequence:


    - create a variable from Linux, e.g. "fw_setenv zzz 42"

    - boot to u-boot, "printenv" shows the created variable as expected "zzz=42"

    - now delete the variable from u-boot "setenv zzz", and "saveenv"

    - verify with "printenv" that the variable is really deleted

    - boot to Linux, "fw_printenv" still shows "zzz=42" (!!!)

    - boot again to u-boot, the variable is still not listed with "printenv"


    First I thought this happens only if variables are deleted from u-boot (in which case I could use a workaround), but the problem occurs also when u-boot just changes variable values, though not always.


    Do you have any hints how I can fix this problem?


    PCoreMX8MP-FERT4.110

    U-Boot 2021.04-F+S-fsimx8mp-Y2023.09 (Aug 31 2023 - 12:56:23 +0000) for F&S

    NBoot: 2023.09

    fsimx8mp-Y2023.09

  • > Can't directly help you with your issue


    Oh, actually you did! Your hint solved the issue. I had a wrong assumption about the meaning of the 2nd line. And indeed, mistakes with the redundant environment are a good explanation for such effects. Thanks a lot for your help!

  • Hi,


    I can confirm the fix, where the file /etc/fw_env.config should contain the following content:


    Code
    1. # MMCdevice offset size
    2. /dev/mmcblk2boot0 0x00040000 0x4000
    3. /dev/mmcblk2boot1 0x00040000 0x4000


    With this I was able to read the ENV. But writing failed:

    Code
    1. # fw_setenv zzz 42
    2. Write error on /dev/mmcblk2boot1: Operation not permitted
    3. Error: can't write fw_env to flash


    Regarding [1], I was able to verify the fix above, but only until the next boot.

    Code
    1. # echo 0 > /sys/block/mmcblk2boot0/force_ro
    2. # echo 0 > /sys/block/mmcblk2boot1/force_ro
    3. # fw_setenv zzz 42


    Where you able to write the uboot env out of the box?

    Or where do we need to enable writing permanently?



    [1]:

    https://www.kernel.org/doc/Doc…ion/mmc/mmc-dev-parts.txt

  • Hello,


    the eMMC boot partitions are always mounted read only by default.

    We would recommend to keep it that way and only mount read/write if you have to write the environment.

    This is, because the bootloader is also saved to these partitions, and should be protected

    After that, you should mount it read only again.


    Your F&S Support Team