R-Car/Use-MMC-block-as-rootfs-on-v5-10
Overview
Linux kernel v5.10-rc1 has the following commit which applied into R-Car SDHI driver.
7320915 mmc: Set PROBE_PREFER_ASYNCHRONOUS for drivers that existed in v4.14
Since probing the SDHI driver is in asynchronous on v5.10-rc1, the order of /dev/mmcblkN will be unstable. So, we are hard to use an mmc block device as a rootfs by using "root=" on kernel command line. To resolve this issue, we have some solutions.
- device tree alias
- UUID
- PARTUUID
How to use?
Device tree aliases
Linux kernel v5.10-rc1 also has the following commit.
fa2d0aa mmc: core: Allow setting slot index via device tree alias
So, we can add the following aliases to fix the /dev/mmcblkN order.
aliases { mmc0 = &sdhi0; mmc1 = &sdhi1; mmc2 = &sdhi2; mmc3 = &sdhi3; };
To add such aliases, we have 2 options.
- device tree in Linux kernel
- Update on a bootloader at runtime
However, unfotunately, adding aliases into upstream has been rejected[1]. So, updating such aliases on a bootloader (e.g. U-Boot) is better like below.
=> tftpboot 0x4af00000 /r8a77951-salvator-xs.dtb => fdt addr 0x4af00000 => fdt resize => fdt set /aliases mmc0 '/soc/mmc@ee100000' => fdt set /aliases mmc1 '/soc/mmc@ee120000' => fdt set /aliases mmc2 '/soc/mmc@ee140000' => fdt set /aliases mmc3 '/soc/mmc@ee160000' => fdt print /aliases aliases { mmc3 = "/soc/mmc@ee160000"; mmc2 = "/soc/mmc@ee140000"; mmc1 = "/soc/mmc@ee120000"; mmc0 = "/soc/mmc@ee100000"; i2c0 = "/soc/i2c@e6500000"; i2c1 = "/soc/i2c@e6508000"; i2c2 = "/soc/i2c@e6510000"; i2c3 = "/soc/i2c@e66d0000"; i2c4 = "/soc/i2c@e66d8000"; i2c5 = "/soc/i2c@e66e0000"; i2c6 = "/soc/i2c@e66e8000"; i2c7 = "/soc/i2c@e60b0000"; serial0 = "/soc/serial@e6e88000"; serial1 = "/soc/serial@e6550000"; ethernet0 = "/soc/ethernet@e6800000"; }; => tftpboot 0x48080000 /Image => booti 0x48080000 - 0x4af00000
UUID
UUID is in a filesystem. But, Linux kernel doesn't support UUID as root filesystem directly. So, we have to use it via initramfs.
PARTUUID
PARTUUID is in a partition which GUID Partition Table (GPT) is used. And, Linux kernel supports "root=PARTUUID=..." on the Kernel command line. To create a GPT, we have to use gdisk instead of fdisk like below.
# gdisk /dev/mmcblk0 GPT fdisk (gdisk) version 1.0.5 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries in memory. Command (? for help): n Partition number (1-128, default 1): First sector (34-61071326, default = 2048) or {+-}size{KMGTP}: Last sector (2048-61071326, default = 61071326) or {+-}size{KMGTP}: Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/mmcblk0: 61071360 sectors, 29.1 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 343D8BBD-BED8-485D-A98B-D1700B9C9B52 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 61071326 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 61071326 29.1 GiB 8300 Linux filesystem Command (? for help): i Using 1 Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem) Partition unique GUID: CC7E6949-2881-4770-833C-3ADB27B110D8 First sector: 2048 (at 1024.0 KiB) Last sector: 61071326 (at 29.1 GiB) Partition size: 61069279 sectors (29.1 GiB) Attribute flags: 0000000000000000 Partition name: 'Linux filesystem' Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/mmcblk0.
And then, after the partition had a root filesystem, we can use the "Partition unique GUID" as a PARTUUID like below.
=> setenv bootargs 'rw root=PARTUUID=CC7E6949-2881-4770-833C-3ADB27B110D8'