mmc: Support a patch directory for each version

Create a patch directory for the running and alternate hostfw
versions. Otherwise the patches may not be compatible if a
side switch occurs.

Also don't delete patches when updating the running version
because it's not known if it's just a side switch. This should
be handled by the code update app which currently is done by
the BMC updater.

Change-Id: Ie975e5f8176ad97ee5ed2dd7594a83ba8c57bdb3
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/mmc/obmc-flash-bios b/mmc/obmc-flash-bios
index 4cc6bb5..c77cf8e 100644
--- a/mmc/obmc-flash-bios
+++ b/mmc/obmc-flash-bios
@@ -52,8 +52,6 @@
     # Save the label
     echo "${boot_label}" > "${running_label_file}"
 
-    # Remove patches
-    rm -f ${base_dir}/patch/*
   fi
 
   # Mount alternate dir
@@ -75,18 +73,37 @@
     return 0
   fi
 
-  target="/media/hostfw/patch"
-  if [ ! -d "${target}" ]; then
-    mkdir -p "${target}"
+  boot_label="$(fw_printenv -n bootside)"
+  if [ "${boot_label}" = "a" ]; then
+    alternate_label="b"
+  else
+    alternate_label="a"
   fi
 
-  patchdir="/usr/local/share"
-  if [ ! -d "${patchdir}" ]; then
-    mkdir -p "${patchdir}"
+  # Create patch directories
+  patch_dir="/media/hostfw/patch-"
+  running_patch_dir="${patch_dir}${boot_label}"
+  if [ ! -d "${running_patch_dir}" ]; then
+    mkdir -p "${running_patch_dir}"
+  fi
+  alternate_patch_dir="${patch_dir}${alternate_label}"
+  if [ ! -d "${alternate_patch_dir}" ]; then
+    mkdir -p "${alternate_patch_dir}"
   fi
 
-  ln -s "${target}" "${patchdir}/hostfw"
-  ln -s "${target}" "${patchdir}/pnor"
+  # Create patch symlinks
+  symlink_base="/usr/local/share"
+  if [ ! -d "${symlink_base}" ]; then
+    mkdir -p "${symlink_base}"
+  fi
+  hostfw_symlink_base="${symlink_base}/hostfw"
+  if [ ! -d "${hostfw_symlink_base}" ]; then
+    mkdir -p "${hostfw_symlink_base}"
+  fi
+
+  ln -s "${running_patch_dir}" "${symlink_base}/pnor"
+  ln -s "${running_patch_dir}" "${hostfw_symlink_base}/running"
+  ln -s "${alternate_patch_dir}" "${hostfw_symlink_base}/alternate"
 }
 
 case "$1" in