archlinuxarm/PKGBUILDs — pull request #1048 by alexeicolin (2014-12-29 04:30:06+00:00)
Title: linux-odroid: generate initramfs image (to support persistent partition names)

**Package**: linux-odroid (-u3,-x,-x2), uboot-odroid
**Architecture**: armv7h
**Device**: Hardkernel Odroid U3 (also affected X, X2)

**What it isn't doing**: Linux does not boot from MMC when an SD card is present.
**What it should be doing**: It should be possible to configure U-Boot (uEnv.txt) such that Linux can boot from MMC regardless of whether an SD card is present or not.

**Steps to reproduce**:
1. On Odroid U3 board install Arch to MMC by [official instructions](http://archlinuxarm.org/platforms/armv7/samsung/odroid-u3#qt-platform_tabs-ui-tabs2). The default root file system specification in U-Boot config (`/boot/uEnv.txt`) is `root=/dev/mmcblk0p1`.
2. Plug in an SD card whose first partition does not contain Linux.
3. Attempt to boot: Linux will fail to mount root file system because `/dev/mmcblk0p1` points to the first partition on the SD card not on the MMC. Changing to `/dev/mmcblk1p1` will work... until you decide to take the SD card out and the MMC device index will flip back to 0.

I actually did not follow these exact steps since my MMC is partitioned differently from the default into (`/boot, swap, /, /home` in that order), but that is not relevant to the issue.

**Details**: On Odroid U3 board there are two *removable* block devices: SD card and MMC module. If only one of the two is plugged in, then the one and only device is assigned index 0. Otherwise, the MMC module is assigned index 1 and the SD card index 0. Thus, the MMC module may be either at index 0 or 1 depending on whether an SD card is plugged into the SD slot. As a result, any given U-Boot configuration using device numbers can either boot the system when the SD card is present OR when it is not present, but not in both cases.

**Solution**: Use a persistent name for the root partition, such as `root=LABEL=sys` or `root=UUID=...`. However, for that to work, a ramdisk with early userspace is needed. The proposed commit updates `linux-odroid` package to generate an initramfs image using mkinitcpio and pack it using mkimage for use by U-Boot.

The latter step (mkimage) means a build dependency on `uboot-tools` and a reference to the boot loader in a kernel package which is logically independent of boot loaders. However, the integrated and automated solution is worth this dependency wrinkle. Otherwise, the user would have to pack the image manually before using persistent names in `uEnv.txt`. In contrast, in the proposed version, the user can start using `LABEL=` or `UUID=` in uEnv.txt immediately after installing the new `linux-odroid`. U-Boot from `odroid-uboot` already looks for a ramdisk by default (`rdfile=` in `uEnv.txt` can only override the filename), and this patch generates it with the default name.

Commit b8f6d4e is some harmless factoring of the package script to avoid duplicating identical build code for the three boards.