dual-image: remount alt partitions during update

When the BMC is to updating the alt image, it needs to stop the sync
manager, umount the rofs/rwfs-alt partitions before the flashing,
mount them after it's done, and restart the sync manager.

Otherwise the mount point of rofs/rwfs-alt will get error because the
content is updated.

Tested: Verify the rofs/rwfs-alt are umounted during the alt flashing,
        and are mounted again after the flashing is done, and the sync
        manager is restarted.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I21e2bd8e0616cf529b9b4e5245d5da1ea4dfb51e
diff --git a/obmc-flash-bmc b/obmc-flash-bmc
index ab353bf..07e730e 100644
--- a/obmc-flash-bmc
+++ b/obmc-flash-bmc
@@ -317,6 +317,12 @@
   fi
 }
 
+umount_static_alt() {
+  altFs=$1
+  altFsMount="/run/media/${altFs}"
+  umount "${altFsMount}"
+}
+
 # Read the current env variable and set it on the alternate boot env
 copy_env_var_to_alt() {
   varName=$1
@@ -707,6 +713,9 @@
   static-altfs)
     mount_static_alt "$2" "$3" "$4"
     ;;
+  umount-static-altfs)
+    umount_static_alt "$2"
+    ;;
   *)
     echo "Invalid argument"
     exit 1
diff --git a/static/obmc-flash-bmc-alt@.service.in b/static/obmc-flash-bmc-alt@.service.in
index 8ea4790..f302e03 100644
--- a/static/obmc-flash-bmc-alt@.service.in
+++ b/static/obmc-flash-bmc-alt@.service.in
@@ -4,4 +4,10 @@
 [Service]
 Type=oneshot
 RemainAfterExit=no
+ExecStartPre=-/bin/systemctl stop xyz.openbmc_project.Software.Sync.service
+ExecStartPre=-/usr/bin/obmc-flash-bmc umount-static-altfs rofs-alt
+ExecStartPre=-/usr/bin/obmc-flash-bmc umount-static-altfs rwfs-alt
 ExecStart=/usr/sbin/flashcp /tmp/images/%i/image-bmc /dev/mtd/alt-bmc
+ExecStartPost=-/usr/bin/obmc-flash-bmc static-altfs squashfs alt-rofs rofs-alt
+ExecStartPost=-/usr/bin/obmc-flash-bmc static-altfs jffs2 alt-rwfs rwfs-alt
+ExecStartPost=-/bin/systemctl start xyz.openbmc_project.Software.Sync.service