Search code examples
embedded-linuxu-boot

Access u-boot env variables set by fw_setenv from boot.scr


I'm experimenting with nanopi board with ubuntu OS and u-boot bootloader. When booted into system, I set u-boot environment variable with fw_setenv:

$ fw_setenv foo bar

On the following reboot I'd like to access this foo variable from the /boot/boot.scr script:

if [ -z "${foo}" ]; then
    echo "Fail"
else
    echo "Ok"
fi

I get Fail, so foo is inaccessible. I've no experience with u-boot but I read that it has two sets of environment variables: one read-only (fixed as a part of U-boot image), and another read/write (user environment). So it looks like user environment is not accessible from boot.scr script? Is it true? How can I make my foo variable visible at the moment when boot.scr is executed?

Upd: My /etc/fw_env.config file:

# Block device
/dev/mmcblk1    0xc0000    0x20000

U-boot version: 2020.01


Solution

  • The problem is found. U-boot constants CONFIG_SYS_MMC_ENV_DEV, CONFIG_ENV_OFFSET, and CONFIG_ENV_SIZE did not match those in /etc/fw_env.config. Solved the problem by changing these constants to

    #define CONFIG_SYS_MMC_ENV_DEV          1
    #define CONFIG_ENV_OFFSET               0x3f8000
    #define CONFIG_ENV_SIZE                 0x20000
    

    recompiling u-boot and updating fw_env.config accordingly:

    /dev/mmcblk1    0x3f8000    0x20000