Determine functional versions from mount directory

In order to support the same version on the primary and backup flash
locations, the version string is not enough to determine which version
is functional. Therefore add a functional suffix to the mount directory
of the functional and use that to set the Version as functional.

Tested: The mount directories indicate which version is functional,
associations look correct.

- static:
root@romulus:~# ls -l /run/media/rofs-79139bc0-functional/etc/
lrwxrwxrwx    1 root     root            15 Jan 22 20:11 os-release ->
/etc/os-release

root@romulus:~# busctl call xyz.openbmc_project.ObjectMapper
/xyz/openbmc_project/software/functional org.freedesktop.DBus.Properties
Get ss xyz.openbmc_project.Association endpoints
v as 1 "/xyz/openbmc_project/software/79139bc0"

- ubi
root@witherspoon:~# df
/dev/ubiblock0_0         18816     18816         0 100% /media/rofs-cfb85943-functional
/dev/ubiblock4_0         18816     18816         0 100% /media/rofs-26085328

- mmc:
Verified functional association is correct, the rofs directories are
still unmounted after the bmc updater starts.

Change-Id: I8114a86b36ca1c6b1634b01fcce3cef0a2369eca
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/obmc-flash-bmc b/obmc-flash-bmc
index aa9773f..30c3fcd 100644
--- a/obmc-flash-bmc
+++ b/obmc-flash-bmc
@@ -264,6 +264,9 @@
   altbmcmtd="$(findmtd "alt-bmc")"
   mtds="${bmcmtd: -1}","${altbmcmtd: -1}"
 
+  rootubi="$(findrootubi)"
+  rootname="$(findname "${rootubi}")"
+
   IFS=',' read -r -a mtds <<< "$mtds"
   mtds=($(echo "${mtds[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
   for mtd in ${mtds[@]}; do
@@ -279,7 +282,11 @@
       name="$(echo -e "${name}" | tr -d '[:space:]')"
 
       if [[ ${name} == rofs-* ]]; then
-        mountdir="/media/${name}"
+        if [[ "${name}" == "${rootname}" ]]; then
+          mountdir="/media/${name}-functional"
+        else
+          mountdir="/media/${name}"
+        fi
 
         if [ ! -d ${mountdir} ]; then
           mkdir -p "${mountdir}"
@@ -515,6 +522,20 @@
   fi
 }
 
+mmc_mount() {
+  primaryId="$(mmc_get_primary_label)"
+  secondaryId="$(mmc_get_secondary_label)"
+
+  primaryDir="${mediaDir}/rofs-${primaryId}-functional"
+  secondaryDir="${mediaDir}/rofs-${secondaryId}"
+
+  mkdir -p "${primaryDir}"
+  mkdir -p "${secondaryDir}"
+
+  mount PARTLABEL=rofs-${primaryId} "${primaryDir}" -t ext4 -o ro || rmdir "${primaryDir}"
+  mount PARTLABEL=rofs-${secondaryId} "${secondaryDir}" -t ext4 -o ro || rmdir "${secondaryDir}"
+}
+
 mmc_update() {
   # Update u-boot if needed
   bootPartition="mmcblk0boot0"
@@ -658,6 +679,10 @@
     imgpath="$3"
     mmc_update
     ;;
+  mmc-mount)
+    mediaDir="$2"
+    mmc_mount
+    ;;
   mmc-remove)
     flashid="$2"
     mmc_remove