From fc4d0e758adc9350242fce2a8a605cadf231aeb0 Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Thu, 6 Jul 2017 11:26:42 -0500 Subject: openpower-software-manager: Move squashfsmount.service logic to script The service files that manage the pnor ubi volumes and mount points are starting to get too much logic in them. Move the logic to a shell script. Change-Id: I4396bcd9fcfd253eeaa3a5ce00621d97386ff399 Signed-off-by: Adriana Kobylak --- .../openpower-software-manager/obmc-flash-bios | 52 ++++++++++++++++++++++ .../obmc-flash-bios-squashfsmount@.service | 7 +-- 2 files changed, 53 insertions(+), 6 deletions(-) (limited to 'meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash') diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios index acc550ba4..cab5f8614 100644 --- a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios +++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios @@ -8,6 +8,20 @@ findmtd() { echo "${m}" } +# Get the ubi device number (ubiX_Y) +findubi() { + u="$(grep -xl "$1" /sys/class/ubi/ubi?/subsystem/ubi*/name)" + u="${u%/name}" + u="${u##*/}" + echo "${u}" +} + +# Get the mount information +is_mounted() { + grep -q "$1" /proc/mounts + return $? +} + # Attach the pnor mtd device to ubi attach_ubi() { pnormtd="$(findmtd pnor)" @@ -33,10 +47,48 @@ attach_ubi() { fi } +mount_squashfs() { + pnormtd="$(findmtd pnor)" + pnor="${pnormtd#mtd}" + ubidev="/dev/ubi${pnor}" + mountdir="/media/${name}" + + if [ ! -d "${mountdir}" ]; then + mkdir "${mountdir}" + fi + + # Create a static ubi volume of arbitrary size 32MB, + # the volume will shrink to fit the pnor image if smaller + vol="$(findubi "${name}")" + if [ -z "${vol}" ]; then + ubimkvol "${ubidev}" -N "${name}" -s 32MiB --type=static + vol="$(findubi "${name}")" + fi + + # Create a ubi block needed for read-only volumes, + # and update the volume with the pnor squashfs image + ubidevid="${vol#ubi}" + block="/dev/ubiblock${ubidevid}" + if [ ! -e "$block" ]; then + img="/tmp/images/${version}/pnor.xz.squashfs" + ubiblock --create "/dev/ubi${ubidevid}" + ubiupdatevol "/dev/ubi${ubidevid}" "${img}" + fi + + if ! is_mounted "${name}"; then + mount -t squashfs -o ro "${block}" "${mountdir}" + fi +} + case "$1" in ubiattach) attach_ubi ;; + squashfsmount) + name="$2" + version="$3" + mount_squashfs + ;; *) echo "Invalid argument" exit 1 diff --git a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service index 5cca34748..91095328c 100644 --- a/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service +++ b/meta-openbmc-machines/meta-openpower/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service @@ -6,9 +6,4 @@ After=obmc-flash-bios-ubiattach.service [Service] Type=oneshot RemainAfterExit=no -ExecStart=/bin/sh -c '{sbindir}/ubimkvol /dev/ubi0 -N pnor-ro-%i -s 32MiB --type=static; \ - mkdir /media/pnor-ro-%i; \ - volumeid%i=`ubinfo -d 0 -N pnor-ro-%i | grep "Volume ID" | sed -e "s|Volume ID:||" -e "s/^ *//" | grep -o "^\S*"`; \ - ubiblock --create /dev/ubi0_$volumeid%i; \ - ubiupdatevol /dev/ubi0_$volumeid%i /tmp/images/%i/pnor.xz.squashfs; \ - mount -t squashfs -o ro /dev/ubiblock0_$volumeid%i /media/pnor-ro-%i' +ExecStart={sbindir}/obmc-flash-bios squashfsmount pnor-ro-%i %i -- cgit v1.2.1