Project

General

Profile

u-boot environment initialization

Added by Nathan Wright 27 days ago

We are trying to initialize the u-boot environment from linux kernel space.

We are following the flash script steps that basically unlock the special boot device and dd the file in to the correct location...

echo 0 > /sys/block/mmcblk0boot0/force_ro
dd if=uboot.env of=/dev/mmcblk0boot0 bs=512 seek=7944

7944 being offset address divided block size of 512. We have used dd to read that space and confirmed it appears to be written to disk.

Unfortunately, u-boot disagrees...

U-Boot 2024.04-ti-g1d3ba9d16938 (Oct 29 2024 - 14:04:51 +0000)

SoC:   AM62X SR1.0 HS-FS
Model: Critical Link MitySOM-AM62x
MitySOM-62x - Model No: 6254-TX-X9E-RC Serial No: 24003477 Part Number: 80-001744RC-3A
DRAM:  4 GiB
Core:  101 devices, 31 uclasses, devicetree: separate
MMC:   mmc@fa10000: 0, mmc@fa00000: 1
Loading Environment from FAT... MMC: no card present
** Bad device specification mmc 1 **
Loading Environment from MMC... *** Warning - bad CRC, using default environment

If I pause in u-boot and run saveenv it will initialize the environment and be happy at the next boot up. fw_printenv/setenv in Linux are also happy with that environment.

So I took an image of first 9000 512 blocks of /dev/mmcblk0 when u-boot wasn't happy, and the same image when it was happy, hex dumped them both and compared.

The good crc image has an environment at address offset 0x3e1000, the bad crc image does not have an environment there. It seems like the special device is not really becoming read/write capable when unlocked. Like it is a shadow copy or something.

As a workaround I was able to include the fw_utils and an initial env file and then run `fw_setenv -f /etc/u-boot-initial-env` to initialize it from user space.
After that u-boot was happy with the env.

Any ideas why the dd method failed?

Thanks,
Nathan


Replies (8)

RE: u-boot environment initialization - Added by Michael Williamson 23 days ago

Hi Nathan,

Based on this from your comment:

So I took an image of first 9000 512 blocks of /dev/mmcblk0 ...

I am wondering if uBoot is booting from /dev/mmcblk0 and not /dev/mmblk0boot0 (which would explain your results). Or did you mean you dumped out /dev/mmblk0boot0 in your check?

I will look into this on Monday.

With regards,
Mike

RE: u-boot environment initialization - Added by Nathan Wright 21 days ago

How would I determine that?

In uboot, there is the mmc command and the existing script sets mmcdev to 0 and bootpart to 0 (once it failed to boot at mmcdev 1, bootpart 1:2).

I was under the impression that the mmcblk0boot0 was a linux construct. How does one target that from uboot?

Please forgive my ignorance!

RE: u-boot environment initialization - Added by Jonathan Cormier 21 days ago

Or did you mean you dumped out /dev/mmblk0boot0 in your check?

Can you confirm this part of Mike's question?

It sounds like you were writing to mmcblk0boot0 but u-boot is using mmblk0 instead for the environment location. If that's the case, try writing to mmcblk0 instead and let us know if that works.

RE: u-boot environment initialization - Added by Jonathan Cormier 21 days ago

Note according to our emmc boot instructions. https://support.criticallink.com/redmine/projects/mitysom_am62x/wiki/Boot_EMMC#EMMC-Layout

We do expect the environment to be in the boot0 block. My first guess is this was tested with the 2023 u-boot and might be misconfigured in the 2024 u-boot.

RE: u-boot environment initialization - Added by Nathan Wright 21 days ago

In my checks I tested both blocks. Reading back mmcblk0boot0 did show the environment. Reading back mmcblk0 did not have the environment. This is why I was speculating that Linux wasn't really writing to the actual device.

The probable source of my confusion is that I thought those we were same place.
I thought mmcblk0boot0 was like a read-only window to the front of the emmc.
So, I expected these two commands to technically write to the same location on the media...

dd if=uboot.env  of=/dev/mmcblk0boot0 bs=512 seek=7944
dd if=uboot.env of=/dev/mmcblk0 bs=512 seek=7944

This is apparently not the case?

Further confusing me is that we do boot from the emmc successfully.
So uboot is using mmcblk0boot0 to get the tiboot3.bin, tispl.bin, and u-boot.img, but it is using mmcblk0 for the environment.

Which I guess is fine since we have the workaround of initializing the environment with fw_setenv command.

I would like to understand it though.

RE: u-boot environment initialization - Added by Jonathan Cormier 21 days ago

It looks to me like this is misconfigured in both 2023 and 2024 u-boot.

Here is a trimmed-down version of the u-boot config.

$ ag ENV_ build-mitysom_am62x_devkit/a53/u-boot.cfg
#define CONFIG_ENV_OFFSET 0x3E1000
#define CONFIG_ENV_SIZE 0x1f000
#define CONFIG_SYS_MMC_ENV_DEV 0
#define CONFIG_ENV_IS_IN_MMC 1
#define CONFIG_SPL_ENV_IS_IN_MMC 1
#define CONFIG_SYS_MMC_ENV_PART 0

According to this, u-boot is going to look for the environment exactly where you found it. at address offset 0x3e1000 on mmcblk0. Unfortunately, that is inside the root partition so we need to fix that.

RE: u-boot environment initialization - Added by Jonathan Cormier 21 days ago

Pushed fix to u-boot 2023 and 2024
https://support.criticallink.com/gitweb/?p=u-boot-ti.git;a=commit;h=bb86b0aa5782cc2dcf2fe95c6009c93ae9394263

Test printing the environment after having saved it from u-boot

# dd if=/dev/mmcblk0boot0 bs=512 iseek=7944 | strings
7addr_fit=0x90000000
arch=arm
args_all=setenv optargs ${optargs} earlycon=ns16550a,mmio32,0x02800000 ${mtdparts}
args_mmc=run finduuid;setenv bootargs console=${console} ${optargs} root=PARTUUID=${uuid} rw rootfstype=${mmcrootfstype}
args_ospi_nand=setenv bootargs console=${console} ${optargs} ubi.mtd=${ospi_nand_bootpart} root=${ospi_nand_bootvolume} rootfstype=ubifs
...

RE: u-boot environment initialization - Added by Jonathan Cormier 21 days ago

The probable source of my confusion is that I thought those we were same place.
I thought mmcblk0boot0 was like a read-only window to the front of the emmc.

Correct. eMMC spec adds two unique boot sections and an rpmb? section. Which are distinct from the regular flash storage area seen on sdcards.

    (1-8/8)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)