i.MX8M Mini: ROM loader always expects SPL in the same offset on eMMC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i.MX8M Mini: ROM loader always expects SPL in the same offset on eMMC

Jump to solution
1,515 Views
gabrielvalcazar
Contributor IV

Good evening,

My development team is currently working on bringing up a board based on the i.MX8M Mini. We already have a similar board based on the i.MX8M Nano, so we're reusing most of the code where possible.

On the i.MX8M Nano board, we had a system in U-Boot/SPL to calculate the appropriate offset to read/write the imx-boot image from, based on the boot partition used: BOOT1, BOOT2 or User Data. This is because we verified via trial and error that the ROM loader can load the SPL from either of these partitions, so we need to make sure that:

  • The SPL also loads the U-Boot image from the same partition/offset
  • When writing a new imx-boot image to the eMMC, make sure it's in the same partition/offset as the current image

See the following log of the commit that adds this logic into our code:

    ccimx8m: spl: consider the eMMC boot partition on U-Boot jump
    
    The ROM loader of the i.MX8MNano expects the boot image at the
    following offset:
     - If booting from microSD or eMMC User Data area
    	offset of 0x40 sectors (to skip a GPT)
     - If booting from eMMC BOOT1 or BOOT2 partitions
    	offset of 0 (since we don't expect a GPT anywhere)
    
    The function spl_mmc_get_uboot_raw_sector() was assuming an offset
    of 0 if the boot device was the eMMC, no matter the selected
    boot partition.

 However, this code doesn't work as intended on the i.MX8M Mini version of the board, because we think the ROM loader is always trying to load the SPL from the User Data partition. When reading/writing the imx-boot image from SPL/U-Boot, the eMMC seems to be configured to boot from the BOOT partitions, but then the ROM loader is always loading whatever's in the User Data partition.

For reference, this is our implementation (including how we parse the boot partition from the eMMC config):

#define UBOOT_RAW_SECTOR_OFFSET 0x40
unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
{
	u32 boot_dev = spl_boot_device();
	int part;

	switch (boot_dev) {
		case BOOT_DEVICE_MMC1:
			/* microSD card */
			return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
		case BOOT_DEVICE_MMC2:
			/* eMMC */
			part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
			/*
			 * On the BOOT partitions, the bootloader is stored
			 * at offset 0.
			 */
			if (part == 1 || part == 2)
				return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR -
				       UBOOT_RAW_SECTOR_OFFSET;
			/*
			 * On the User Data area the boot loader is expected
			 * at UBOOT_RAW_SECTOR_OFFSET offset.
			 */
			return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
	}
	return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
}

My question is: is this expected behavior? Is it true that the 8M Nano ROM loader can boot from either BOOT or User Data partitions, while the 8M Mini ROM loader always boots from User Data? If not, is there any explanation behind this behavior?

Many thanks in advance,

Gabriel

Labels (1)
0 Kudos
1 Solution
1,474 Views
gabrielvalcazar
Contributor IV

Hi again James,

A colleague of mind found out what was happening. Our code uses an offset of 0 instead of 32k when writing the imx-boot image to a boot partition on the eMMC, because the Nano's ROM loader reads the SPL from offset 0 when booting from said partition. This isn't true for the Mini though, as its ROM always looks for the SPL at the 33k offset, regardless of the partition being used. After reflecting this behavior in our code, everything works as expected.

We can consider this question resolved now. Many thanks for your input,

Gabriel

View solution in original post

0 Kudos
3 Replies
1,507 Views
jamesbone
NXP TechSupport
NXP TechSupport

In the i.MX8M Mini it is a fixed offset where the ROM will look for the header of the image - but note that the offset is differs according to the boot media.

pastedImage_1(1).png

 

0 Kudos
1,475 Views
gabrielvalcazar
Contributor IV

Hi again James,

A colleague of mind found out what was happening. Our code uses an offset of 0 instead of 32k when writing the imx-boot image to a boot partition on the eMMC, because the Nano's ROM loader reads the SPL from offset 0 when booting from said partition. This isn't true for the Mini though, as its ROM always looks for the SPL at the 33k offset, regardless of the partition being used. After reflecting this behavior in our code, everything works as expected.

We can consider this question resolved now. Many thanks for your input,

Gabriel

0 Kudos
1,487 Views
gabrielvalcazar
Contributor IV

Hi James,

Thanks for the quick reply. We're already aware of the 33 Kbyte offset when booting from eMMC, and we handle it appropriately in our code. What we're concerned about is the eMMC partition from which the SPL is loaded from.

eMMC memories have special boot partitions used to store bootloaders/startup software. In our i.MX8M Nano board, we read the eMMC configuration and deduce the partition used for booting: some eMMCs use the boot partitions, while others use the user data area. The thing is, when we detect in the SPL/U-Boot that the eMMC is configured to boot from the boot partitions (and thus, we write the imx-boot image to that partition), the ROM loader is also able to load the SPL from that partition.

The problem is that our i.MX8M Mini boards behave differently, and the ROM loader is always trying to load the SPL from the user data area, even if the eMMC is configured to boot from the boot partitions. Even if this has an easy workaround (always use the user data partition regardless of the eMMC config), we would like to know if this is expected behavior or if we're missing something.

0 Kudos