From 0998d1e4fc58e668ccf2ea5e07b86317b066160d Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Wed, 3 Jun 2020 16:22:42 -0500 Subject: initramfs: Add init script for eMMC This init script mounts the rootfs based on the root u-boot env variable, mounts the read-write filesystem and sets up the overlay. (From meta-phosphor rev: 86164b2e072cc6cebc9caf1614e2b1fa0e0884a0) Change-Id: If9121048b6223d5391e5f6a8b7d6cd7d22707969 Signed-off-by: Adriana Kobylak Signed-off-by: Andrew Geissler --- .../images/obmc-phosphor-initramfs.bb | 6 ++- .../initrdscripts/phosphor-mmc-init.bb | 26 +++++++++++ .../initrdscripts/phosphor-mmc-init/mmc-init.sh | 51 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb create mode 100644 meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh diff --git a/meta-phosphor/recipes-phosphor/images/obmc-phosphor-initramfs.bb b/meta-phosphor/recipes-phosphor/images/obmc-phosphor-initramfs.bb index 739aab50b..4c7237fca 100644 --- a/meta-phosphor/recipes-phosphor/images/obmc-phosphor-initramfs.bb +++ b/meta-phosphor/recipes-phosphor/images/obmc-phosphor-initramfs.bb @@ -2,7 +2,11 @@ DESCRIPTION = "Small image capable of booting a device. The kernel includes \ the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \ first 'init' program more efficiently." -PACKAGE_INSTALL = "${VIRTUAL-RUNTIME_base-utils} base-passwd ${ROOTFS_BOOTSTRAP_INSTALL} obmc-phosphor-initfs" +# Init scripts +INIT_PACKAGE = "obmc-phosphor-initfs" +INIT_PACKAGE_df-phosphor-mmc = "phosphor-mmc-init" + +PACKAGE_INSTALL = "${VIRTUAL-RUNTIME_base-utils} base-passwd ${ROOTFS_BOOTSTRAP_INSTALL} ${INIT_PACKAGE}" # Do not pollute the initrd image with rootfs features IMAGE_FEATURES = "read-only-rootfs" diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb new file mode 100644 index 000000000..45ae452c7 --- /dev/null +++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init.bb @@ -0,0 +1,26 @@ +SUMMARY = "Phosphor OpenBMC pre-init scripts for mmc" +DESCRIPTION = "Phosphor OpenBMC filesystem mount implementation for mmc." +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" + +PR = "r1" + +inherit allarch + +RDEPENDS_${PN} += " \ + ${VIRTUAL-RUNTIME_base-utils} \ + gptfdisk \ + parted \ + udev \ +" + +S = "${WORKDIR}" +SRC_URI += "file://mmc-init.sh" + +do_install() { + install -m 0755 ${WORKDIR}/mmc-init.sh ${D}/init + install -d ${D}/dev + mknod -m 622 ${D}/dev/console c 5 1 +} + +FILES_${PN} += " /init /dev " diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh new file mode 100644 index 000000000..ec4b745db --- /dev/null +++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# Get the value of the root env variable found in /proc/cmdline +get_root() { + local root="$(cat /proc/cmdline)" + root="${root##* root=PARTLABEL=}" + root="${root%% *}" + [ "${root}" != "" ] && echo "${root}" +} + +fslist="proc sys dev run" +rodir=/mnt/rofs +cd / +mkdir -p $fslist +mount dev dev -tdevtmpfs +mount sys sys -tsysfs +mount proc proc -tproc +mount tmpfs run -t tmpfs -o mode=755,nodev + +# Move the secondary GPT to the end of the device if needed. Look for the GPT +# header signature "EFI PART" located 512 bytes from the end of the device. +magic=$(tail -c 512 /dev/mmcblk0 | hexdump -C -n 8 | grep "EFI PART") +if test -z "${magic}"; then + sgdisk -e /dev/mmcblk0 + partprobe +fi + +# There eMMC GPT labels for the rootfs are rofs-a and rofs-b, and the label for +# the read-write partition is rwfs. Run udev to make the partition labels show +# up. Mounting by label allows for partition numbers to change if needed. +udevd --daemon +udevadm trigger --type=devices --action=add +udevadm settle --timeout=10 + +mkdir -p $rodir +if ! mount /dev/disk/by-partlabel/"$(get_root)" $rodir -t ext4 -o ro; then + /bin/sh +fi +if ! mount /dev/disk/by-partlabel/rwfs $rodir/var -t ext4 -o rw; then + /bin/sh +fi + +rm -rf $rodir/var/persist/etc-work/ +mkdir -p $rodir/var/persist/etc $rodir/var/persist/etc-work $rodir/var/persist/home/root +mount overlay $rodir/etc -t overlay -o lowerdir=$rodir/etc,upperdir=$rodir/var/persist/etc,workdir=$rodir/var/persist/etc-work + +for f in $fslist; do + mount --move $f $rodir/$f +done + +exec chroot $rodir /sbin/init -- cgit v1.2.3