diff options
author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2020-12-08 00:38:17 +0300 |
---|---|---|
committer | Jason M. Bills <jason.m.bills@linux.intel.com> | 2020-12-08 00:38:17 +0300 |
commit | 8d6ae7f2a817751fad151168fa10ce28ee0869d8 (patch) | |
tree | 281032f7ec07c41589aa094bd165cc2a98f2d3a7 /meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh | |
parent | c16fb8893b19075db4bcf3b5bf33c1db8c3ca2bd (diff) | |
parent | 5da3c2284560a7e08ffafd03c5b5ba44a3242228 (diff) | |
download | openbmc-8d6ae7f2a817751fad151168fa10ce28ee0869d8.tar.xz |
Merge tag '0.26' of ssh://git-amr-1.devtools.intel.com:29418/openbmc-openbmc into update
Diffstat (limited to 'meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh')
-rw-r--r-- | meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh | 66 |
1 files changed, 66 insertions, 0 deletions
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..061757519 --- /dev/null +++ b/meta-phosphor/recipes-phosphor/initrdscripts/phosphor-mmc-init/mmc-init.sh @@ -0,0 +1,66 @@ +#!/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 + +# Wait up to 5s for the mmc device to appear. Continue even if the count is +# exceeded. A failure will be caught later like in the mount command. +mmcdev="/dev/mmcblk0" +count=0 +while [ $count -lt 5 ]; do + if [ -e "${mmcdev}" ]; then + break + fi + sleep 1 + count=$((count + 1)) +done + +# 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 "${mmcdev}" | hexdump -C -n 8 | grep "EFI PART") +if test -z "${magic}"; then + sgdisk -e "${mmcdev}" + 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 + +rwfsdev="/dev/disk/by-partlabel/rwfs" +fsck.ext4 -p "${rwfsdev}" +if ! mount "${rwfsdev}" $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 |