PNOR: Mount ubi volumes on BMC reboot

- Create a static service file that will be
  run on all BMC boot to remount the ubi volumes.
- Read the ubinfo for all available volumes from
  obmc/flash-bios script.
- Re-Mount the available volumes on /media/ dir
  using the volume names.

Resolves openbmc/openbmc#1848

Change-Id: I9e336340a04f335d034438406e5f0fff9b21d1b9
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios b/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios
index 2265275..dffd298 100644
--- a/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios
+++ b/common/recipes-phosphor/flash/openpower-software-manager/obmc-flash-bios
@@ -128,6 +128,34 @@
   fi
 }
 
+remount_ubi() {
+  pnormtd="$(findmtd pnor)"
+  pnor="${pnormtd#mtd}"
+  # Get information on all ubi volumes
+  ubinfo=$(ubinfo -d ${pnor})
+  presentVolumes=${ubinfo##*:}
+  IFS=', ' read -r -a array <<< "$presentVolumes"
+  for element in ${array[@]};
+  do
+    elementProperties=$(ubinfo -d $pnor -n $element)
+    # Get ubi volume name by getting rid of additional properties
+    name=${elementProperties#*Name:}
+    name="${name%Character*}"
+    name="$(echo -e "${name}" | tr -d '[:space:]')"
+
+    if [[ ${name} == pnor-prsv ]] || [[ ${name} == pnor-rw* ]] || [[ ${name} == pnor-ro* ]]; then
+      mountdir="/media/${name}"
+      if [[ ${name} == pnor-ro* ]]
+      then
+        ubiblock --create /dev/ubi${pnor}_${element}
+        mount -t squashfs -o ro "/dev/ubiblock${pnor}_${element}" "${mountdir}"
+      else
+        mount -t ubifs "ubi${pnor}:${name}" "${mountdir}"
+      fi
+    fi
+  done
+}
+
 case "$1" in
   ubiattach)
     attach_ubi
@@ -145,6 +173,9 @@
     name="$2"
     umount_ubi
     ;;
+  ubiremount)
+    remount_ubi
+    ;;
   *)
     echo "Invalid argument"
     exit 1