obmc-flash-bios-ubimount: Create UBI vol for pnor preserved partitions

In addition to create a UBI volume for the read-write (rw) pnor
partitions, create a UBI volume for the preserved (prsv) pnor
partitions to store the host data that should be preserved during
a code update. This volume has a common name instead of a unique
id because only one copy (the active one) needs to be available
in the system.
Add checks to only execute the commands to create the volumes if
needed (they don't exist). This is needed since the preserved one
doesn't need to be created after it's first created.

Change-Id: Ib21d7d5343f3cb48ff71edca29631249dc5717a0
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service b/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service
index 1bf15bf..5cca347 100644
--- a/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service
+++ b/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-squashfsmount@.service
@@ -5,7 +5,7 @@
 
 [Service]
 Type=oneshot
-RemainAfterExit=yes
+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*"`; \
diff --git a/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-ubimount@.service b/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-ubimount@.service
index 5abab7f..a2147ea 100644
--- a/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-ubimount@.service
+++ b/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios-ubimount@.service
@@ -1,11 +1,23 @@
 [Unit]
-Description=Mount UBIFS volume pnor-rw-%I
+Description=Mount UBIFS volume pnor-prsv and pnor-rw-%I
 Requires=obmc-flash-bios-ubiattach.service
 After=obmc-flash-bios-ubiattach.service
 
 [Service]
 Type=oneshot
-RemainAfterExit=yes
-ExecStart=/bin/sh -c '{sbindir}/ubimkvol /dev/ubi0 -N pnor-rw-%i -s 1MiB; \
-                      mkdir /media/pnor-rw-%i; \
-                      mount -t ubifs ubi0:pnor-rw-%i /media/pnor-rw-%i'
+RemainAfterExit=no
+ExecStart=/bin/sh -c 'rw=pnor-rw-%i; \
+                      if [ ! -d "/media/$rw" ]; then \
+                        mkdir /media/$rw; fi; \
+                      if [ ! -d "/media/pnor-prsv" ]; then \
+                        mkdir /media/pnor-prsv; fi; \
+                      rw_ubi=`ubinfo -d 0 -a | grep $rw`; \
+                      if [ -z "$rw_ubi" ]; then \
+                        {sbindir}/ubimkvol /dev/ubi0 -N $rw -s 1MiB; fi; \
+                      prsv_ubi=`ubinfo -d 0 -a | grep pnor-prsv`; \
+                      if [ -z "$prsv_ubi" ]; then \
+                        {sbindir}/ubimkvol /dev/ubi0 -N pnor-prsv -s 1MiB; fi; \
+                      if ! grep -q $rw /proc/mounts; then \
+                        mount -t ubifs ubi0:$rw /media/$rw; fi; \
+                      if ! grep -q pnor-prsv /proc/mounts; then \
+                        mount -t ubifs ubi0:pnor-prsv /media/pnor-prsv; fi;'