Hello!
I am currently struggling with reading from and to the U-boot environment from Linux on edm-g-imx8mp board from Technexion. I have build the U-boot binary using U-boot-tn-imx Yocto repository provided by Technexion and later attempted to build u-boot firmware utils. I have managed to pinpoint my issue to be related to placement of the U-boot+SPL, and some other imx8mp binaries on the eMMC drive.
To provision the device I am using UUU ( Universal Update Utility) to firstly flash the aforementioned imx-boot binary (as it was created via U-boot recipe in Yocto Project) followed by .wic.bz2 file containing another copy of bootloader as well as /boot and /rootFS partitions as describbed by the imx-boot-bootpart.wks file in Yocto Project. The contents of .wks file are shown below.
# short-description: Create SD card image with a boot partition | |
# long-description: | |
# Create an image that can be written onto a SD card using dd for use | |
# with i.MX SoC family | |
# It uses u-boot + other binaries gathered together on imx-boot file | |
# | |
# The disk layout used is: | |
# - ---------- -------------- -------------- | |
# | | imx-boot | boot | rootfs | | |
# - ---------- -------------- -------------- | |
# ^ ^ ^ ^ ^ | |
# | | | | | | |
# 0 | 8MiB 72MiB 72MiB + rootfs + IMAGE_EXTRA_SPACE (default 10MiB) | |
# 32 32 or 33kiB | see reference manual |
# | |
part u-boot --source rawcopy --sourceparams="file=imx-boot" --ondisk mmcblk --no-table --align 32 | |
part /boot --source bootimg-partition --ondisk mmcblk --fstype=vfat --label boot --active --align 8192 --size 64 | |
part / --source rootfs --ondisk mmcblk --fstype=ext4 --label root --align 8192 | |
bootloader --ptable msdos |
My issue is now that when I restart the device the U-boot environment that is being read mismatches the U-boot environment pointed to by sbin/fw_printenv and sbin/fw_setenv. I am aware of the fact that the memory addresses these point to can be dynamically changed at runtime via changes to the /etc/fw_env.config file. I am however unable to determine correct offset and size values for the edm-g-imx8mp board. Additionally the values as generated by fw-utils recipe are incorrect and have to be adjusted. The contents of the fw_env.config follow below:
# 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 omitted, this value is assumed to
# be the same as the Environment size, which is valid for NOR and SPI-dataflash
# Device offset must be prefixed with 0x to be parsed as a hexadecimal value.
# NOR example
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd1 0x0000 0x4000 0x4000
/dev/mtd2 0x0000 0x4000 0x4000
# MTD SPI-dataflash example
# MTD device name Device offset Env. size Flash sector size Number of sectors
#/dev/mtd5 0x4200 0x4200
#/dev/mtd6 0x4200 0x4200
# NAND example
#/dev/mtd0 0x4000 0x4000 0x20000 2
# On a block device a negative offset is treated as a backwards offset from the
# end of the device/partition, rather than a forwards offset from the start.
# Block device example
#/dev/mmcblk0 0xc0000 0x20000
#/dev/mmcblk0 -0x20000 0x20000
# VFAT example
#/boot/uboot.env 0x0000 0x4000
# UBI volume
#/dev/ubi0_0 0x0 0x1f000 0x1f000
#/dev/ubi0_1 0x0 0x1f000 0x1f000
# UBI volume by name
#/dev/ubi0:env 0x0 0x1f000 0x1f000
#/dev/ubi0:env-redund 0x0 0x1f000 0x1f000
Commenting out the mtd1 and mtd2 devices and changing the mmblk0 to be mmcblk2 along with inserting offset and size as defined in u-boot-tn-imx-fw-utils/git/configs/edm-gimx8mp_defconfig repeated below, result in me being able to write and read from U-boot environment on Hardware User Space Partition i.e mmcblk2
CONFIG_ENV_SIZE=0x1000
CONFIG_ENV_OFFSET=0x400000
This however is not the U-boot environment that the device uses at boot-up. I am unaware where the start-up U-boot environment is on the MMC flash memory. Based on the output of the mmc_burn_all.lst file shown below. The U-boot binary is being flashed to the mmblk2boot0 partition. After doing some reading I found out that the U-boot environment in many cases is then present on the mmcblk2boot1, but I am unable to verify that. Contents of the mmc_burn_all.lst are shown below:
uuu_version 1.2.39
# This command will be run when i.MX6/7 i.MX8MM, i.MX8MQ
SDP: boot -f _flash.bin
# This command will be run when ROM support stream mode
# i.MX8QXP, i.MX8QM
SDPS: boot -f _flash.bin
# These commands will be run when use SPL and will be skipped if no spl
# SDPU will be deprecated. please use SDPV instead of SDPU
# {
SDPU: delay 1000
SDPU: write -f _flash.bin -offset 0x57c00
SDPU: jump
# }
# These commands will be run when use SPL and will be skipped if no spl
# if (SPL support SDPV)
# {
SDPV: delay 1000
SDPV: write -f _flash.bin -skipspl
SDPV: jump
# }
FB: ucmd setenv fastboot_dev mmc
FB: ucmd setenv mmcdev ${emmc_dev}
FB: ucmd mmc dev ${emmc_dev}
FB: flash -raw2sparse all _rootfs.sdcard
FB: flash bootloader _flash.bin
FB: ucmd if env exists emmc_ack; then ; else setenv emmc_ack 0; fi;
FB: ucmd mmc partconf ${emmc_dev} ${emmc_ack} 1 0
FB: done
Could somebody provide me with correct values for the fw_env.config file so that I can read and write to the U-boot environment placed in either mmcblk2boot0 or mmcblk2boot1 partitions?
Solved! Go to Solution.
doesn't matter the bootloader (flash.bin) boot from eMMC one of two boot partitions or from user partition.
The u-boot environment is always saved to user partition.
/etc/fw_env.config should be
/dev/mmcblk2 0x400000 0x1000
just one line is enough.
doesn't matter the bootloader (flash.bin) boot from eMMC one of two boot partitions or from user partition.
The u-boot environment is always saved to user partition.
/etc/fw_env.config should be
/dev/mmcblk2 0x400000 0x1000
just one line is enough.
You are right it was my oversight that caused me to be confused. When setting an environment via fw_setenv and subsequently printing it via fw_printenv the variables are displayed at the bottom of the printout block. However when calling printenv from u-boot command line the variables are displayed at the top of the prinout block.
Thank you for your answer!