mk_delta: extract file for update
authorSunmin Lee <sunm.lee@samsung.com>
Mon, 18 Dec 2017 07:10:26 +0000 (16:10 +0900)
committerSunmin Lee <sunm.lee@samsung.com>
Wed, 20 Dec 2017 02:49:08 +0000 (11:49 +0900)
Some binaries used for update are required to be extracted
from new image and appended to update package (delta.tar).
Extract these file from known image and path, whether those
images are listed in config file or not.

Change-Id: I31e52b0eb651827b55cd5653828e462335e8ca35
Signed-off-by: Sunmin Lee <sunm.lee@samsung.com>
mk_delta/artik530_710/cfg/delta.cfg
mk_delta/common/bin/mk_delta.sh
mk_delta/common/bin/mk_part_delta.sh

index 4001588..1f30c1e 100644 (file)
@@ -3,5 +3,5 @@
 
 rootfs                 rootfs.img              rootfs.img/     DELTA_FS        /dev/mmcblk0p3  0
 # TODO : make a new update type for ramdisk
-ramdisk                        ramdisk.img             N/A             EXCLUDED        N/A             N/A
-ramdisk-recovery       ramdisk-recovery.img    N/A             EXCLUDED        N/A             N/A
+#ramdisk                       ramdisk.img             N/A             EXCLUDED        N/A             N/A
+#ramdisk-recovery      ramdisk-recovery.img    N/A             EXCLUDED        N/A             N/A
index 97cb947..05b081d 100755 (executable)
@@ -64,9 +64,7 @@ fn_gen_update_cfg()
                f4=${BLK_DEV[${update_idx}]}
                f5=${BLK_OFFSET[${update_idx}]}
 
-               if [ "${f3}" != "EXCLUDED" ]; then
-                       echo -e "$f1\t\t$f2\t\t$f3\t\t$f4\t\t$f5" >> ${out_file}
-               fi
+               echo -e "$f1\t\t$f2\t\t$f3\t\t$f4\t\t$f5" >> ${out_file}
        done
 
        return 0
@@ -175,6 +173,87 @@ fn_process_extra_delta()
        fi
 }
 
+#------------------------------------------------------------------------------
+# Function :
+#      fn_get_tar_file_names
+#
+# Description :
+#      find tar file name (without path) that contains given partition binary
+#
+
+fn_get_tar_file_names()
+{
+       BIN_TO_FIND=$1
+
+       cd ${DATA_DIR}/${OLD_TAR_DIR}
+       OLD_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
+       cd ${CUR_DIR}
+
+       cd ${DATA_DIR}/${NEW_TAR_DIR}
+       NEW_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
+       cd ${CUR_DIR}
+
+       #--- find which tar contains the binary ---
+       for tar_file in ${OLD_TAR_LIST}
+       do
+               result=`tar -tvf ${DATA_DIR}/${OLD_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
+               if [ "$?" = "0" ]; then
+                       OLD_TAR_FILE=${tar_file}
+                       break
+               fi
+       done
+
+       for tar_file in ${NEW_TAR_LIST}
+       do
+               result=`tar -tvf ${DATA_DIR}/${NEW_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
+               if [ "$?" = "0" ]; then
+                       NEW_TAR_FILE=${tar_file}
+                       break
+               fi
+       done
+
+}
+
+#------------------------------------------------------------------------------
+# Function :
+#      fn_extract_from_image
+#
+# Description :
+#      extract some files from given image
+#
+
+fn_extract_from_image()
+{
+       CUR_DIR=`pwd`
+       DATA_DIR=./data
+       IMAGE=$1
+       TARGET_FILE=$2
+       MNT_PNT=TMP_MNT
+       mkdir -p ${MNT_PNT}
+
+       fn_get_tar_file_names $IMAGE
+       tar xvf ${DATA_DIR}/${NEW_TAR_DIR}/${NEW_TAR_FILE} ${IMAGE}
+       if [ "$?" != "0" ]; then
+               return 1;
+       fi
+
+       sudo mount -t ext4 -o loop ${IMAGE} ${MNT_PNT}
+       if [ "$?" != "0" ]; then
+               return 1;
+       fi
+
+       EXTRACT_FILE="${MNT_PNT}${TARGET_FILE}"
+       if [ -e ${EXTRACT_FILE} ]; then
+               sudo cp ${EXTRACT_FILE} ${DELTA_DIR}
+       else
+               echo "There is no ${TARGET_FILE} in ${IMAGE}"
+       fi
+
+       sudo umount ${MNT_PNT}
+       sudo rm -rf ${MNT_PNT}
+       sudo rm -f ${IMAGE}
+}
+
 ###############################################################################
 #==================
 # Main Start
@@ -217,10 +296,7 @@ do
 
                PART_OUT=${part_name}_OUT
 
-               if [ "${update_type}" = "EXCLUDED" ]; then
-                       ${MK_PART_DELTA} ${part_name} ${update_type} ${part_bin} ${delta_bin}
-                       continue
-               elif [ "${update_type}" = "EXTRA" ]; then
+               if [ "${update_type}" = "EXTRA" ]; then
                        fn_process_extra_delta
                else
                        ${MK_PART_DELTA} ${part_name} ${update_type} ${part_bin} ${delta_bin}
@@ -251,17 +327,10 @@ do
                sudo rm ${LOG_PATH}
        fi
 
-       #--- move delta.ua to delta directory ---
-       if [ -r ${DELTA_UA} ]; then
-               sudo cp ${DELTA_UA} ${DELTA_DIR}/delta.ua
-               sudo rm ${DELTA_UA}
-       fi
-
-       #--- move update manager script to delta directory ---
-       if [ -r ${UPDATE_MANAGER} ]; then
-               sudo cp ${UPDATE_MANAGER} ${DELTA_DIR}/upgrade-trigger.sh
-               sudo rm ${UPDATE_MANAGER}
-       fi
+       #--- extract files which would be appended to delta.tar ---
+       echo "Extract binaries for update from images"
+       fn_extract_from_image rootfs.img /usr/bin/upgrade-trigger.sh
+       fn_extract_from_image ramdisk-recovery.img /usr/bin/delta.ua
 
        #--- archive result directory ---
        cd result/$MONDATE
index fc7e875..8be627f 100755 (executable)
@@ -457,44 +457,6 @@ fn_get_tar_file_names()
 
 }
 
-#------------------------------------------------------------------------------
-# Function :
-#      extract_from_image
-#
-# Description :
-#      extract some file from given image
-#
-
-fn_extract_from_image()
-{
-       IMAGE=$1
-       TARGET_FILE=$2
-       MNT_PNT=${PART_NAME}_MNT
-       mkdir -p ${MNT_PNT}
-
-       tar xvf ${DATA_DIR}/${NEW_TAR_DIR}/${NEW_TAR_FILE} ${IMAGE}
-       if [ "$?" != "0" ]; then
-               return 1;
-       fi
-
-       sudo mount -t ext4 -o loop ${IMAGE} ${MNT_PNT}
-       if [ "$?" != "0" ]; then
-               return 1;
-       fi
-
-       EXTRACT_FILE="${MNT_PNT}${TARGET_FILE}"
-       if [ -e ${EXTRACT_FILE} ]; then
-               sudo cp ${EXTRACT_FILE} ${DATA_DIR}
-       else
-               echo "There is no ${TARGET_FILE} in ${IMAGE}"
-       fi
-
-       sudo umount ${MNT_PNT}
-       sudo rm -rf ${MNT_PNT}
-       sudo rm -f ${IMAGE}
-}
-
-
 ###############################################################################
 #==================
 # Main Start
@@ -555,20 +517,6 @@ NEW_TAR_FILE=
 
 fn_get_tar_file_names ${PART_BIN}
 
-case "${PART_NAME}" in
-       "ramdisk2" | "ramdisk-recovery" )
-               fn_extract_from_image ${PART_BIN} /usr/bin/delta.ua
-               ;;
-       "rootfs" )
-               fn_extract_from_image ${PART_BIN} /usr/bin/upgrade-trigger.sh
-               ;;
-esac
-
-if [ "${UPDATE_TYPE}" = "EXCLUDED" ]; then
-       exit 0
-fi
-
-OLD_TAR_MISSING=
 if [ "z${OLD_TAR_FILE}" = "z" ]; then
        if [ ! "${UPDATE_TYPE}" = "FULL_IMG" ] && [ ! "${UPDATE_TYPE}" = "PRE_UA" ]; then
                echo "[old] tar file does not exist in ${DATA_DIR}/${OLD_TAR_DIR} which contains ${PART_BIN}"