Introduce recovery-update.service submit/tizen/20171027.093656
authorSunmin Lee <sunm.lee@samsung.com>
Tue, 12 Sep 2017 04:14:06 +0000 (13:14 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Fri, 27 Oct 2017 09:04:47 +0000 (18:04 +0900)
The recovery partition used to be updated separately
in the first boot after update other partitions.
This service implements recovery partition update
in normal boot mode.

Change-Id: Ie6e5966e5a6760daad87d304eb556aa8ad15ad02
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
packaging/system-rw-update.spec
units/recovery-update.service [new file with mode: 0755]
upgrade/recovery-update.sh [new file with mode: 0755]
upgrade/update-init.sh
upgrade/update.sh

index 954ec3b..df736d0 100644 (file)
@@ -1,6 +1,6 @@
 Name:       system-rw-update
 Summary:    System RW update management
-Version:    1.0.0
+Version:    1.1.0
 Release:    0
 Group:      Base/Startup
 License:    Apache-2.0
@@ -49,6 +49,11 @@ ln -s ../offline-update.service %{buildroot}%{_unitdir}/system-update.target.wan
 ln -s ../getty.target %{buildroot}%{_unitdir}/system-update.target.wants
 ln -s ../cynara.socket %{buildroot}%{_unitdir}/system-update.target.wants
 
+# recovery update service
+mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/
+install -m 0644 units/recovery-update.service %{buildroot}%{_libdir}/systemd/system/recovery-update.service
+ln -s ../recovery-update.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/recovery-update.service
+
 # SDB debugging
 install -m 644 units/udev-sdb-init.service %{buildroot}%{_unitdir}
 ln -s ../udev-sdb-init.service %{buildroot}%{_unitdir}/system-update.target.wants
@@ -73,6 +78,8 @@ fi
 %{_datadir}/upgrade/*
 %{_unitdir}/offline-update.service
 %{_unitdir}/system-update.target.wants
+%{_unitdir}/recovery-update.service
+%{_unitdir}/multi-user.target.wants/recovery-update.service
 %{_unitdir}/udev-sdb-init.service
 
 %files ani
diff --git a/units/recovery-update.service b/units/recovery-update.service
new file mode 100755 (executable)
index 0000000..478f99c
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Recovery Update
+Wants=local-fs.target
+After=local-fs.target
+
+[Service]
+Type=oneshot
+SmackProcessLabel=System
+ExecStart=/usr/share/upgrade/recovery-update.sh
+
+[Install]
+WantedBy=multi-user.target
diff --git a/upgrade/recovery-update.sh b/upgrade/recovery-update.sh
new file mode 100755 (executable)
index 0000000..dc068a5
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+FULL_RECOVERY_P=ramdisk-recovery.img
+TOTA_RECOVERY_P=RAMDISK2
+BLKDEV_RECOVERY=
+POSTRESULT=post.result
+
+STATUS_DIR=/opt/data/recovery
+
+UPI_RECOVERY_PARTITION_COPY_ERROR=fa19
+UPI_RECOVERY_UPDATE_ERROR=fa1a
+
+#=====================
+# funtions
+#=====================
+
+#------------------------------------------------
+#      print_log
+#------------------------------------------------
+print_log() {
+       echo $@
+       echo $@ >> ${PATCH_LOG_FILE}
+       /bin/sync
+}
+
+#------------------------------------------------
+#       get partition id
+#------------------------------------------------
+get_partition_id() {
+       BLKID="/usr/sbin/blkid"
+       
+       PART_RECOVERY=$("$BLKID" --match-token PARTLABEL=ramdisk2 -o device ||
+                       "$BLKID" --match-token LABEL=ramdisk-recovery -o device)
+}
+
+#=====================
+# main routine start
+#=====================
+
+get_partition_id
+
+BLKDEV_RECOVERY=${PART_RECOVERY}
+
+if [ ! -d ${STATUS_DIR} ]; then
+       echo "${STATUS_DIR} not exist"
+       exit 0
+fi
+
+if [ -f ${DST_DIR}/${TOTA_RECOVERY_P} ]; then
+       /bin/mv ${DST_DIR}/${TOTA_RECOVERY_P} ${DST_DIR}/${FULL_RECOVERY_P}
+fi
+
+PATCH_LOG_FILE=${STATUS_DIR}/RW.LOG
+
+DST_DIR=/opt/usr/data/fota
+
+#------------------------------------------------
+#      update recovery partition
+#------------------------------------------------
+if [ -r ${DST_DIR}/${FULL_RECOVERY_P} ]; then
+
+       #--- FULL_IMG case ---
+       TIMESTAMP=$(/bin/date +%H:%M:%S)
+       print_log "start recovery partition update : (${TIMESTAMP})"
+
+       /bin/dd if=${DST_DIR}/${FULL_RECOVERY_P} of=${BLKDEV_RECOVERY}
+       if [ "$?" = "0" ]; then
+               /bin/rm -f ${DST_DIR}/${FULL_RECOVERY_P}
+               /bin/sync
+               print_log "update succeeded"
+       else
+               if [ -f /opt/data/recovery/result ]; then
+                       fotaflag=`/bin/cat /opt/data/recovery/result`
+                       if [ "$fotaflag" = "0" ]; then
+                               echo ${UPI_RECOVERY_PARTITION_COPY_ERROR} > /opt/data/recovery/result
+                               /usr/bin/chmod 644 /opt/data/recovery/result
+                               print_log "Change result to ${UPI_RECOVERY_PARTITION_COPY_ERROR}"
+                       fi
+               fi
+               print_log "update failed"
+       fi
+
+       TIMESTAMP=$(/bin/date +%H:%M:%S)
+       print_log "end recovery partition update : (${TIMESTAMP})"
+else
+       ULOG="skip recovery partition update"
+       /usr/bin/grep "${ULOG}" ${PATCH_LOG_FILE} > /dev/null 2>&1
+       if [ "$?" != 0 ]; then
+               print_log "${ULOG}"
+       fi
+fi
index 6825aeb..5a02ac3 100755 (executable)
@@ -7,6 +7,13 @@ RW_MACRO=/usr/share/upgrade/rw-update-macro.inc
 RW_UPDATE=/usr/share/upgrade/update.sh
 DEBUG_MODE=/opt/usr/.upgdebug
 
+DELTA_TAR=delta.tar
+FULL_RECOVERY=ramdisk-recovery.img
+TOTA_RECOVERY=RAMDISK2
+DST_DIR=/opt/usr/data/fota
+STATUS_DIR=/opt/data/recovery
+DELTA_PATH_FILE=${STATUS_DIR}/DELTA.PATH
+
 if [ -f $RW_MACRO ]; then
        source $RW_MACRO
        get_version_info
@@ -21,6 +28,17 @@ fi
 # Permission Update for shared directories
 /etc/gumd/useradd.d/91_user-dbspace-permissions.post owner
 
+# Pre operations for recovery update
+if [ -f ${DELTA_PATH_FILE} ]; then
+       if [ -f ${DST_DIR}/${TOTA_RECOVERY} ]; then
+               /bin/mv ${DST_DIR}/${TOTA_RECOVERY} ${DST_DIR}/${FULL_RECOVERY}
+       fi
+fi
+
+if [ -f ${DELTA_DIR}/${DELTA_TAR} ]; then
+       /bin/rm -f ${DELTA_DIR}/${DELTA_TAR}
+fi
+
 sleep 10
 if [ -f $DEBUG_MODE ]; then
        exit
index 9129823..ca15404 100755 (executable)
@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin
 
 TMP_DIR=/tmp/upgrade
 PATCH_DIR=/usr/share/upgrade/scripts
-RESULT_FILE=/opt/data/recovery/rw_result
+RW_LOG=/opt/data/recovery/RW.LOG
 SDB_RULE=/opt/data/recovery/99-sdb-switch.rules
 VERSION_FILE=/opt/etc/version
 RW_MACRO=/usr/share/upgrade/rw-update-macro.inc
@@ -24,7 +24,7 @@ RW_ANI=/usr/bin/rw-update-ani
 Verity_Check() {
 
        if [ "z$1" = "z" ]; then
-               echo "Input Shell Script Null" >> ${RESULT_FILE}
+               echo "Input Shell Script Null" >> ${RW_LOG}
                return 1
        fi
 
@@ -39,18 +39,18 @@ Verity_Check() {
 
                        md5list=`/usr/bin/grep ${SC_FILE} ${SC_LIST} | /usr/bin/awk -F' ' '{print $2}'`
                        if [ "$md5result" = "$md5list" ]; then
-                               echo "[PASS    ] ${SC_FILE} verity check" >> ${RESULT_FILE}
+                               echo "[PASS    ] ${SC_FILE} verity check" >> ${RW_LOG}
                                return 0
                        else
-                               echo "[MISMATCH] ${SC_FILE} md5sum" >> ${RESULT_FILE}
+                               echo "[MISMATCH] ${SC_FILE} md5sum" >> ${RW_LOG}
                                return 2
                        fi
                else
-                       echo "[No entry] ${SC_FILE} in ${SC_LIST}" >> ${RESULT_FILE}
+                       echo "[No entry] ${SC_FILE} in ${SC_LIST}" >> ${RW_LOG}
                        return 1
                fi
        else
-               echo "No such file ${SC_LIST}" >> ${RESULT_FILE}
+               echo "No such file ${SC_LIST}" >> ${RW_LOG}
                return 1
        fi
 }
@@ -64,12 +64,12 @@ if [ -e ${RW_ANI} ]; then
        RW_GUI=1
 fi
 
-echo "System RW update: rw update started" > ${RESULT_FILE}
+echo "System RW update: rw update started" > ${RW_LOG}
 
 # Execute update scripts
 if [ ! -d ${PATCH_DIR} ]
 then
-       echo "FAIL: Upgrade directory does not exist" >> ${RESULT_FILE}
+       echo "FAIL: Upgrade directory does not exist" >> ${RW_LOG}
 else
        if [ "${RW_GUI}" = "1" ]; then
                progress=0
@@ -97,7 +97,7 @@ else
 
        sync
 
-       echo "SUCCESS: Upgrade successfully finished" >> ${RESULT_FILE}
+       echo "SUCCESS: Upgrade successfully finished" >> ${RW_LOG}
 fi
 
 if [ -e ${SDB_RULE} ]; then