Stm32mp157a-dk2 - Uboot env from user space

Good afternoon,

i have build a rootfs for my STM32mp157-dk2 board using buildroot. It starts and boots well.
I also installed the uboot-tools by setting it in buildroot config. so i can call “fw_printenv” from user space. On Stm32mp1 uboot saves the “uboot.env”-file directly unter ‘/’ - e.g. “/uboot.env”.
For being able to print or save thr uboot-env from user space one should create a configuration file for “fw_printenv” which should be located in “/etc/fw_env.config”. I did it:

/etc/fw_env.conf"

# Device name Device offset Env. size Flash sector size
/uboot.env 0x0000 0x2000

but unfortunately by calling “fw_printenv” i get following error message:

Warning: Bad CRC, using default environment

So tried different addresses and sizes, also values defined in newest uboot version in
“stm32mp15_basic_defconfig”.

But all without success!

Does anybody know, how the settings in “fw_env.config” should look like for STM32mp1 board?

Thanks

@ajava, this can be a little tricky, as the u-boot environment variable has a few more defines, you need to tune for your partition layout.

The default config is shown here (stm32mp15_basic_defconfig):

make menuconfig shows:

[*] Environment is not stored
[ ] Environment in EEPROM
[ ] Environment is in a FAT filesystem
[*] Environment is in a EXT4 filesystem
[ ] Environment in flash memory
[ ] Environment in an MMC device
[ ] Environment in a NAND device
[ ] Environment in a non-volatile RAM
[ ] Environment is in OneNAND
[ ] Environment is in remote memory space
[*] Environment is in SPI flash
[ ]   SPI flash bus for environment
[ ]   SPI flash chip select for environment
[ ]   SPI flash max frequency for environment
[ ]   SPI flash mode for environment
[*] Environment in a UBI volume
[*] Enable redundant environment support
(mmc) Name of the block device for the environment
(0:auto) Device and partition for where to store the environemt in EXT4
(/uboot.env) Name of the EXT4 file to use for the environment
(0x0) Environment address
(0x280000) Environment offset
(0x2C0000) Redundant environment offset
(0x2000) Environment Size
(0x40000) Environment Sector-Size
(UBI) UBI partition name
(uboot_config) UBI volume name
(uboot_config_r) UBI redundant volume name
(0) ubi environment VID offset
[*] Relocate gd->en_addr
[ ] Create default environment from file
[*] Add run-time information to the environment

So by default, CONFIG_ENV_IS_IN_EXT4 is enabled, which means it has to be a file in a ext4 partition…

CONFIG_ENV_EXT4_INTERFACE = mmc ; so it has to be an mmc node in u-boot

ENV_EXT4_DEVICE_AND_PART = [=0:auto] ; so first interface, first partition with the bootable flag…

CONFIG_ENV_EXT4_FILE = /uboot.env ; so file named /uboot.env in the root directory.

Thus your:

# Device name Device offset Env. size Flash sector size
/uboot.env 0x0000 0x2000

Is not going to work, as it’s a raw file and not a flash location.

Regards,

@RobertCNelson, thanks a lot for your reply. I got the info actually from what you have posted. So i assume the env-size of “0x2000” should be true! But how should device name look like, maybe

/dev/mmcblk0p4

which is my ext4-rootfs partition.

But if it is true, how on earth can i get the offset of the “uboot.env” file on this parittion?

Regards
Arash

Hi @ajava, this is more of a configuration bug in u-boot’s selection options… Once you select that it’s an actual “file” in in a partition such as “ext4/fat” the offset values are redundant and not used.

/dev/mmcblk0p4 should be okay:
(0:auto) Device and partition for where to store the environemt in EXT4"
- "D:auto": first partition in device D with bootable flag set.
            If none, first valid partition in device D. If no
            partition table then means device D.

Symbol: ENV_EXT4_DEVICE_AND_PART [=0:auto]

So as long as that partition has the boot flag…

Which this set:

sudo sgdisk -A 4:set:2 ${DISK}

But you could change it to:

0:auto -> 0:4

Regards

@RobertCNelson Thanks, i will try it out and report later!