CM4 + Yocto: MMC device number with U-Boot

I haven’t quite got to the bottom of this, but it appears the default community RPi Yocto integration fails on the CM4 because the eMMC device number is 1, rather than 0. On boot:

U-Boot> boot
Card did not respond to voltage select! : -110
** Booting bootflow 'mmc@7e340000.bootdev.part_1' with script
Working FDT set to 2eff6200
Card did not respond to voltage select! : -110
Card did not respond to voltage select! : -110
** Bad device specification mmc 0 **
Couldn't find partition mmc 0:2
Can't set block device
Bad Linux ARM64 Image magic!
Boot failed (err=-14)

If I hand-modify mender_setup from the U-Boot console so that it sets mender_uboot_root to mmc 1:${mender_boot_part_hex} then the kernel boots.

So you would think I just needed to set MENDER_STORAGE_DEVICE to /dev/mmcblk1, so MENDER_UBOOT_STORAGE_DEVICE would be 1. However when I do this:

ERROR: u-boot-1_2024.01-r0 do_configure: U-Boot configuration rpi_arm64_config has setting:
CONFIG_SYS_MMC_ENV_DEV=0
but Mender expects:
CONFIG_SYS_MMC_ENV_DEV=1
Please fix U-Boot's configuration file.
ERROR: u-boot-1_2024.01-r0 do_configure: ExecutionError('/BuildRoot/build/tmp-glibc/work/xebra_cm4-oe-linux/u-boot/2024.01/temp/run.do_configure.1549453', 1, None, None)
ERROR: Logfile of failure stored in: /BuildRoot/build/tmp-glibc/work/xebra_cm4-oe-linux/u-boot/2024.01/temp/log.do_configure.1549453
ERROR: Task (/BuildRoot/meta/recipes-bsp/u-boot/u-boot_2024.01.bb:do_configure) failed with exit code '1'

Pre-Mender integration, the CM4 booted fine with U-Boot.

Hi @lukehatpadl,

Thanks for reaching out! Judging just from your description, adjusting the two *_STORAGE_DEVICE assignments should do the trick. If I remember correctly, then the warning about CONFIG_SYS_MMC_DEV_ENV checks if the MENDER_UBOOT_STORAGE_DEVICE matches what is given in the u-boot configuration. So you need to also adjust this in the u-boot config, possibly through a patch. Then I think you should be good.

Greetz,
Josef

1 Like

Thank you, that fixed the build, will test shortly.

1 Like

Now that I’m a little deeper in the world of device trees, it turns out this was a red herring. The build was picking up the wrong device tree, which was assigning the builtin eMMC to the mmc1 node. Switching back to the correct device tree solved this.

The underlying fix was to ensure RPI_KERNEL_DEVICETREE has only a single value:

RPI_KERNEL_DEVICETREE = "broadcom/bcm2711-rpi-cm4.dtb"

and also, as Mender appears to pick the last element in KERNEL_DEVICETREE, that the overlays precede the device tree:

KERNEL_DEVICETREE = "\
    ${RPI_KERNEL_DEVICETREE_OVERLAYS} \
    ${RPI_KERNEL_DEVICETREE} \
"

If anyone knows a better way to solve this, I am all ears!