U-Boot not storing environment in the expected EXT4 partition
0
votes
0
answers
240
views
I am using Yocto Kirkstone to build a system for an i.MX8 board. I need to access the U-Boot environment variables from Linux userspace. For this, I need to use fw_printenv and fw_setenv from Linux userspace, and have U-Boot also be able to write into the designated EXT4 partition (in my case it should be an EXT4 partition on MMC device 2 partition 2).
My problem is that U-Boot successfully persistently stores the environment - it just does not seem to store it in the expected location.
When I flash the eMMC for the i.MX8 and power the device on for the first time, I see the following:
U-Boot 2022.04-compulab+g7226f0644a (Aug 26 2024 - 01:02:28 +0000)
CPU: i.MX8MP rev1.1 at 1200 MHz
Reset cause: POR
Model: CompuLab IOT-GATE-IMX8PLUS
DRAM: 4 GiB
Core: 107 devices, 30 uclasses, devicetree: separate
WDT: Not starting watchdog@30280000
MMC: FSL_SDHC: 2
Loading Environment from MMC... *** Warning - bad CRC, using default environment
...
*** My Debug Print: Saving environment now: rootwait rw quiet console=ttymxc1,115200 cma=64M root=/dev/mapper/encrypted_fs_a usbcore.autosuspend=-1 audit=0 systemd.restore_state=0 rfkill.default_state=1 rauc.slot=rootfs_a ...
Saving Environment to MMC... Writing to MMC(2)... OK
bootargs=rootwait rw quiet console=ttymxc1,115200 cma=64M root=/dev/mapper/encrypted_fs_a usbcore.autosuspend=-1 audit=0 systemd.restore_state=0 rfkill.default_state=1 rauc.slot=rootfs_a
78297 bytes read in 1 ms (74.7 MiB/s)
117641056 bytes read in 424 ms (264.6 MiB/s)
If I interrupt U-Boot and set some new variables, they are persistent across power cycles.
Setting a new variable:
iot-gate-imx8plus *** My Debug Print U-Boot => setenv name tom
iot-gate-imx8plus *** My Debug PrintU-Boot => saveenv
Saving Environment to MMC... Writing to MMC(2)... OK
iot-gate-imx8plus *** My Debug Print U-Boot =>
Power cycle and query the new variable:
iot-gate-imx8plus *** My Debug Print U-Boot => reset
resetting ...
U-Boot SPL 2022.04-compulab+g7226f0644a (Aug 26 2024 - 01:02:28 +0000)
pca9450@25 [ldo4][u] = 1v8
DDRINFO: EEPROM VALID DATA [ [ cafecafe ] = 1061010 4
DDRINFO(D): Samsung 4096MB @ 3200 MHz
DDRINFO: start DRAM init
DDRINFO: DRAM rate 3200MTS
DDRINFO:ddrphy calibration done
DDRINFO: ddrmix config done
DDRINFO(M): mr5-8 [ 0x1061010 ]
DDRINFO(E): mr5-8 [ 0x1061010 ]
Normal Boot
WDT: Not starting watchdog@30280000
Boot Stage: Primary boot
image offset 0x0, pagesize 0x200, ivt offset 0x0
...
switch to partitions #0, OK
mmc2(part 0) is current device
flash target is MMC:2
Net: eth0: ethernet@30be0000, eth1: ethernet@30bf0000 [PRIME]
Fastboot: Normal
starting USB...
Bus usb@38100000: Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
Bus usb@38200000: Register 2000140 NbrPorts 2
Starting the controller
USB XHCI 1.10
scanning bus usb@38100000 for devices... 1 USB Device(s) found
scanning bus usb@38200000 for devices... 3 USB Device(s) found
scanning usb for storage devices... 0 Storage Device(s) found
Normal Boot
Hit any key to stop autoboot: 0
iot-gate-imx8plus *** My Debug Print U-Boot =>
iot-gate-imx8plus *** My Debug Print U-Boot => printenv name
name=tom
iot-gate-imx8plus *** My Debug Print U-Boot =>
So clearly U-Boot is capable of storing my environment across reboots.
However, from Linux userspace, fw_printenv does not show the same environment, and does not include this new variable. Furthermore, if I try to overwrite the name with a new value in with fw_setenv, then U-Boot will not show the change reflected from it's perspective.
[device ~]$ fw_printenv name
name=
My fw_env.conf file looks like this:
[device ~]$ cat /etc/fw_env.config
/bootenv/u-boot-initial-env-sd 0x0000 0x4000
The 'bootenv' mount is on mmc dev 2 partition 2:
[device ~]$ mount | grep booten
/dev/mmcblk2p2 on /bootenv type ext4 (rw,relatime)
No errors are thrown from either U-Boot or Linux fw_setenv/fw_printenv when they read or modify the U-Boot environment, but changes in either are not considered from the other's perspective. Therefore they are somehow not considering the same storage location. So far I have been unable to determine where U-Boot is exactly storing it's environment persistently.
I have configured U-Boot to store the environment in the EXT4 partition primarily with the following configuration options:
CONFIG_ENV_IS_IN_EXT4=y
CONFIG_ENV_EXT4_INTERFACE="mmc"
CONFIG_ENV_EXT4_DEVICE_AND_PART="2:2"
CONFIG_ENV_EXT4_FILE="/u-boot-initial-env-sd"
CONFIG_SYS_REDUNDAND_ENVIRONMENT=n
CONFIG_USE_DEFAULT_ENV_FILE="/u-boot-initial-env-sd"
CONFIG_ENV_IS_NOWHERE=y"
CONFIG_ENV_IS_IN_MMC=y
CONFIG_SYS_MMC_ENV_DEV=2
CONFIG_SYS_MMC_ENV_PART=2
Complete U-Boot environment related portion of ".config" file for compilation:
#
# Environment
#
CONFIG_ENV_SUPPORT=y
CONFIG_ENV_SOURCE_FILE=""
CONFIG_SAVEENV=y
# CONFIG_ENV_OVERWRITE is not set
CONFIG_ENV_IS_NOWHERE=y
# CONFIG_ENV_IS_IN_EEPROM is not set
# CONFIG_ENV_IS_IN_FAT is not set
CONFIG_ENV_IS_IN_EXT4=y
# CONFIG_ENV_IS_IN_FLASH is not set
CONFIG_ENV_IS_IN_MMC=y
# CONFIG_ENV_IS_IN_NAND is not set
# CONFIG_ENV_IS_IN_NVRAM is not set
# CONFIG_ENV_IS_IN_ONENAND is not set
# CONFIG_ENV_IS_IN_REMOTE is not set
# CONFIG_ENV_IS_IN_SATA is not set
# CONFIG_ENV_IS_IN_SPI_FLASH is not set
# CONFIG_SYS_REDUNDAND_ENVIRONMENT is not set
CONFIG_ENV_EXT4_INTERFACE="mmc"
CONFIG_ENV_EXT4_DEVICE_AND_PART="2:2"
CONFIG_ENV_EXT4_FILE="/u-boot-initial-env-sd"
CONFIG_SYS_RELOC_GD_ENV_ADDR=y
CONFIG_SYS_MMC_ENV_DEV=2
CONFIG_SYS_MMC_ENV_PART=2
# CONFIG_USE_DEFAULT_ENV_FILE is not set
CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y
# CONFIG_ENV_IMPORT_FDT is not set
# CONFIG_ENV_APPEND is not set
# CONFIG_ENV_WRITEABLE_LIST is not set
# CONFIG_ENV_ACCESS_IGNORE_FORCE is not set
# CONFIG_VERSION_VARIABLE is not set
CONFIG_NET=y
CONFIG_PROT_UDP=y
# CONFIG_BOOTP_SEND_HOSTNAME is not set
CONFIG_NET_RANDOM_ETHADDR=y
# CONFIG_NETCONSOLE is not set
# CONFIG_IP_DEFRAG is not set
CONFIG_TFTP_BLOCKSIZE=1468
CONFIG_TFTP_WINDOWSIZE=1
# CONFIG_TFTP_TSIZE is not set
# CONFIG_SERVERIP_FROM_PROXYDHCP is not set
CONFIG_SERVERIP_FROM_PROXYDHCP_DELAY_MS=100
# CONFIG_KEEP_SERVERADDR is not set
# CONFIG_UDP_CHECKSUM is not set
# CONFIG_BOOTP_SERVERIP is not set
How can I determine where U-Boot is storing the persistent environment and debug the disconnect between Linux userspace and U-Boot?
UPDATE:
I have a hunch that there is some misconfiguration in U-Boot since I am seeing the following:
Loading Environment from MMC... OK
When I would expect to see this for EXT4:
Loading Environment from EXT4... OK
The same for 'saveenv' from U-Boot. It refers to MMC and not EXT4:
iot-gate-imx8plus *** My Debug U-Boot => saveenv
Saving Environment to MMC... Writing to MMC(2)... OK
I would expect the following:
Saving Environment to EXT4...
Asked by PhilBot
(101 rep)
Aug 26, 2024, 02:45 AM