8 #------------------------------------------------------------------------------
18 echo "*******************************************************************"
21 #------------------------------------------------------------------------------
23 # fn_extract_mounting_wrapper
28 # extract neccessary files/info from binary images,
29 # by mounting them and calling fn_extract_needed_files()
31 fn_extract_mounting_wrapper()
33 if [ "$PART_NAME" != "rootfs" ] && [ "$PART_NAME" != "hal" ]; then
36 local MNT_PNT_OLD="MNT_PNT_OLD"
37 local MNT_PNT_NEW="MNT_PNT_NEW"
39 mkdir -p ${MNT_PNT_OLD}
40 mkdir -p ${MNT_PNT_NEW}
42 sudo mount -o loop,ro "${PART_IMG_OLD}" ${MNT_PNT_OLD}
43 sudo mount -o loop,ro "${PART_IMG_NEW}" ${MNT_PNT_NEW}
45 fn_extract_needed_files ${MNT_PNT_OLD} ${MNT_PNT_NEW}
47 sudo umount ${MNT_PNT_OLD}
48 sudo umount ${MNT_PNT_NEW}
54 #------------------------------------------------------------------------------
56 # fn_extract_needed_files
59 # $1 - mount point of older partiton
60 # $2 - mount point of newer partition
63 # extract neccessary files/info from already mounted partitions
65 fn_extract_needed_files()
67 # mount/umount as rarely as possible
71 if [ "$PART_NAME" == "hal" ]; then
72 local HAL_TARG_NAME="hal-model-conf.xml"
73 local HAL_MODEL_CONFIG_PATH=${MNT_PNT_OLD}"/etc/config/model-config.xml"
75 # exctarct files/binaries
76 cp "${HAL_MODEL_CONFIG_PATH}" ./${HAL_TARG_NAME}
78 elif [ "$PART_NAME" == "rootfs" ]; then
80 local ROOTFS_TARG_NAME="rootfs-model-config.xml"
81 local TIZEN_TARG_NAME="tizen-build.conf"
82 local UPGRADE_SUPPORT="upgrade-support"
83 local UPGRADE_APPLY="upgrade-apply"
84 local UPGRADE_APPLY_DELTAFS="upgrade-apply-deltafs"
85 local DELTA_VERIFIER="delta-verifier"
86 local BLKID_PRINT="blkid-print"
88 local ROOTFS_MODEL_CONFIG_PATH=${MNT_PNT_OLD}"/etc/config/model-config.xml"
89 local TIZEN_BUILD_CONFIG_PATH=${MNT_PNT_OLD}"/etc/tizen-build.conf"
90 local UPGRADE_SUPPORT_PATH=${MNT_PNT_NEW}"/usr/libexec/"${UPGRADE_SUPPORT}
91 local UPGRADE_APPLY_PATH=${MNT_PNT_NEW}"/usr/bin/"${UPGRADE_APPLY}
92 local UPGRADE_APPLY_DELTAFS_PATH=${MNT_PNT_NEW}"/usr/bin/"${UPGRADE_APPLY_DELTAFS}
93 local DELTA_VERIFIER_PATH=${MNT_PNT_NEW}"/usr/bin/"${DELTA_VERIFIER}
94 local BLKID_PRINT_PATH=${MNT_PNT_NEW}"/usr/bin/"${BLKID_PRINT}
96 # build string building
97 echo "===== Start writing image versions ====="
98 local BUILD_STRING_FILE="build_string.txt"
99 local OLD_BUILD_STRING=`cat ${MNT_PNT_OLD}/etc/info.ini | grep "Date=" | sed "s/Date=//" | sed "s/;$//"`
100 local NEW_BUILD_STRING=`cat ${MNT_PNT_NEW}/etc/info.ini | grep "Date=" | sed "s/Date=//" | sed "s/;$//"`
101 echo "${BUILD_STRING_FILE} : ${OLD_BUILD_STRING}@${NEW_BUILD_STRING}"
102 echo -n ${OLD_BUILD_STRING}@${NEW_BUILD_STRING} > ${BUILD_STRING_FILE}
103 echo "===== Finish writing image versions ====="
105 # extract files/binaries
106 cp "${ROOTFS_MODEL_CONFIG_PATH}" ./${ROOTFS_TARG_NAME}
107 cp "${TIZEN_BUILD_CONFIG_PATH}" ./${TIZEN_TARG_NAME}
108 cp -r "${UPGRADE_SUPPORT_PATH}" ./${UPGRADE_SUPPORT}
109 cp "${UPGRADE_APPLY_PATH}" ./${UPGRADE_APPLY}
110 cp "${UPGRADE_APPLY_DELTAFS_PATH}" ./${UPGRADE_APPLY_DELTAFS}
111 cp "${DELTA_VERIFIER_PATH}" ./${DELTA_VERIFIER}
112 cp "${BLKID_PRINT_PATH}" ./${BLKID_PRINT}
117 #------------------------------------------------------------------------------
122 # $1 - PART_NAME. to descriminate
123 # $2 - base directory to search files for old partition
124 # $3 - base directory to search files for new partition
127 # extract attribute information of files on the given partition
135 V1_ATTR_FILE=${OUTPUT_DIR}/v1_${TARGET}_attr.txt
136 V1_NAME_FILE=${OUTPUT_DIR}/v1_list.txt
137 V2_ATTR_FILE=${OUTPUT_DIR}/v2_${TARGET}_attr.txt
138 V2_NAME_FILE=${OUTPUT_DIR}/v2_list.txtfg
139 V23_NAME_FILE=v23_${TARGET}_attr.txt
140 V13_NAME_FILE=v13_${TARGET}_attr.txt
141 ATTR_CMD=extended_attr.sh
143 echo "Attribute generation for ${TARGET} [START] $(date +%T)"
145 sudo find ./${BASE_DIR_OLD} -type f -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; > ${V1_ATTR_FILE}
146 sudo find ./${BASE_DIR_OLD} -type l -printf '"%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
147 sudo find ./${BASE_DIR_OLD} -type d -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V1_ATTR_FILE}
149 sudo find ./${BASE_DIR_NEW} -type f -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; > ${V2_ATTR_FILE}
150 sudo find ./${BASE_DIR_NEW} -type l -printf '"%P" SymLink 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
151 sudo find ./${BASE_DIR_NEW} -type d -printf '"%P" Regular 14 %04m:%04U:%04G:' -exec ${COMMON_BINDIR}/${ATTR_CMD} {} \; >> ${V2_ATTR_FILE}
153 ################ Change user and group permission from '0' to '0000' ############
154 sed -i 's/: 0/:0000/g' ${V1_ATTR_FILE}
155 sed -i 's/: /:000/g' ${V1_ATTR_FILE}
156 sed -i 's/: /:00/g' ${V1_ATTR_FILE}
157 sed -i 's/: /:0/g' ${V1_ATTR_FILE}
159 sed -i 's/: 0/:0000/g' ${V2_ATTR_FILE}
160 sed -i 's/: /:000/g' ${V2_ATTR_FILE}
161 sed -i 's/: /:00/g' ${V2_ATTR_FILE}
162 sed -i 's/: /:0/g' ${V2_ATTR_FILE}
164 ################ Change ":./old" to "/" ############
165 sed -i "s/:.\/${BASE_DIR_OLD}\//:/" ${V1_ATTR_FILE}
166 sed -i "s/:.\/${BASE_DIR_OLD}/:/" ${V1_ATTR_FILE}
168 sed -i "s/:.\/${BASE_DIR_NEW}\//:/" ${V2_ATTR_FILE}
169 sed -i "s/:.\/${BASE_DIR_NEW}/:/" ${V2_ATTR_FILE}
171 echo "Attribute generation for ${TARGET} [END] $(date +%T)"
174 #------------------------------------------------------------------------------
181 PART_IMG_ORG=${PART_BIN}
182 PART_IMG_OLD=${PART_IMG_ORG}.old
183 PART_IMG_NEW=${PART_IMG_ORG}.new
185 #---- untar partition image and rename for old & new ----
186 if [ ! "z${OLD_TAR_FILE}" = "z" ]; then
187 echo "untar ${OLD_TAR_FILE}"
188 tar xvf ${OLD_TAR_DIR}/${OLD_TAR_FILE} ${PART_IMG_ORG}
189 if [ "$?" != "0" ]; then
192 sudo mv ${PART_IMG_ORG} ${PART_IMG_OLD}
195 echo "untar ${NEW_TAR_FILE}"
196 tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_ORG}
197 if [ "$?" != "0" ]; then
200 sudo mv ${PART_IMG_ORG} ${PART_IMG_NEW}
202 # after extraction, get neccessary files
203 fn_extract_mounting_wrapper
205 if [ ! "z${OLD_TAR_FILE}" = "z" ]; then
206 #---- check whether the binaries are same ----
207 sudo diff ${PART_IMG_OLD} ${PART_IMG_NEW}
208 if [ "$?" = "0" ]; then
209 echo "[${PART_NAME}] two binaries are same"
210 sudo rm -rf ${PART_IMG_OLD}
211 sudo rm -rf ${PART_IMG_NEW}
214 sudo python3 ${COMMON_BINDIR}/CreatePatch.py ${UPDATE_TYPE} ${PART_NAME} ${PART_IMG_OLD} ${PART_IMG_NEW} ${OUTPUT_DIR} ${UPDATE_CFG_PATH}
216 sudo rm ${PART_IMG_OLD}
218 if [ $PythonRet != "0" ]; then
219 echo "[${PART_NAME}] Failed to generate DELTA"
224 sudo mv ${PART_IMG_NEW} ${OUTPUT_DIR}/${PART_IMG_ORG}
225 sudo chown ${MY_ID}:${MY_ID} ${OUTPUT_DIR}/${PART_IMG_ORG}
230 #------------------------------------------------------------------------------
232 # fn_mk_delta_img_core
235 # core routine for delta generation
239 fn_mk_delta_img_core()
242 START_TIMESTAMP="generation of ${DELTA} [START] $(date +%T)"
244 #---- untar partition image and rename for old & new ----
245 echo "untar ${OLD_TAR_FILE}"
246 tar xvf ${OLD_TAR_DIR}/${OLD_TAR_FILE} ${PART_IMG_ORG}
247 if [ "$?" != "0" ]; then
250 sudo mv ${PART_IMG_ORG} ${PART_IMG_OLD}
252 echo "untar ${NEW_TAR_FILE}"
253 tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_ORG}
254 if [ "$?" != "0" ]; then
257 sudo mv ${PART_IMG_ORG} ${PART_IMG_NEW}
259 # after extraction, get neccessary files
260 fn_extract_mounting_wrapper
262 #---- check whether the binaries are same ----
263 sudo diff ${PART_IMG_OLD} ${PART_IMG_NEW}
264 if [ "$?" = "0" ]; then
265 echo "[${PART_NAME}] two binaries are same"
266 sudo rm -rf ${PART_IMG_OLD}
267 sudo rm -rf ${PART_IMG_NEW}
271 #---- make delta file ----
273 sudo python3 ${COMMON_BINDIR}/CreatePatch.py ${UPDATE_TYPE} ${PART_NAME} ${PART_IMG_OLD} ${PART_IMG_NEW} ${OUTPUT_DIR} ${UPDATE_CFG_PATH}
275 #sudo xdelta delta ${PART_IMG_OLD} ${PART_IMG_NEW} ./${OUTPUT_DIR}/${PART_NAME}".delta"
277 #---- remove files & directories ----
278 echo "remove temp files/directory & move delta/log to result directory"
279 sudo rm -rf ${PART_IMG_OLD}
280 sudo rm -rf ${PART_IMG_NEW}
283 if [ $PythonRet != "0" ]; then
284 echo "[${PART_NAME}] Failed to generate DELTA"
287 END_TIMESTAMP="generation of ${DELTA} [END] $(date +%T)"
288 echo "${START_TIMESTAMP}"
289 echo "${END_TIMESTAMP}"
295 #------------------------------------------------------------------------------
300 # generate delta file for image type partition
305 PART_IMG_ORG=${PART_BIN}
306 PART_IMG_OLD=${PART_IMG_ORG}.old
307 PART_IMG_NEW=${PART_IMG_ORG}.new
310 DEBUG_DELTA=debug_${DELTA}
311 #CFG_XML=${PART_NAME}_IMG.xml
312 mkdir ${OUTPUT_DIR}/i
315 if [ "$?" != "0" ]; then
322 #------------------------------------------------------------------------------
324 # mk_inter_attrib_file
327 # makes a list of attributes for those files which differ between v1 aND V2
328 #manoj:to create intermediate attribute list
329 fn_mk_inter_attrib_file()
331 V1ref_ATTR_FILE=${OUTPUT_DIR}/v1_${TARGET}_attr.txt
332 V2ref_ATTR_FILE=${OUTPUT_DIR}/v2_${TARGET}_attr.txt
335 #------------------------------------------------------------------------------
337 # fn_mk_delta_fs_core
340 # core routine for delta generation
341 # File System Update Type (DELTA_FS)
344 fn_mk_delta_fs_core()
346 START_TIMESTAMP="generation of ${DELTA} [START] $(date +%T)"
349 if [ "${DELTA}" = "boot.img/" ]; then
353 #---- untar partition image and rename for old & new ----
354 echo "untar ${OLD_TAR_FILE}"
355 tar xvf ${OLD_TAR_DIR}/${OLD_TAR_FILE} ${PART_IMG_ORG}
356 if [ "$?" != "0" ]; then
359 sudo mv ${PART_IMG_ORG} ${PART_IMG_OLD}
361 echo "untar ${NEW_TAR_FILE}"
362 tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_ORG}
363 if [ "$?" != "0" ]; then
366 sudo mv ${PART_IMG_ORG} ${PART_IMG_NEW}
368 #---- check whether the binaries are same ----
369 sudo diff ${PART_IMG_OLD} ${PART_IMG_NEW}
370 if [ "$?" = "0" ]; then
371 echo "[${PART_NAME}] two binaries are same"
372 sudo rm -rf ${PART_IMG_OLD}
373 sudo rm -rf ${PART_IMG_NEW}
374 sudo rm -rf ${OUTPUT_DIR}
378 #---- make mount point ----
379 mkdir -p ${MNT_PNT_OLD}
380 mkdir -p ${MNT_PNT_NEW}
382 #---- mount partition image to mount point ----
383 echo "mount ${PART_IMG_OLD} & ${PART_IMG_NEW}"
384 sudo mount -o loop ${PART_IMG_OLD} ${MNT_PNT_OLD}
385 if [ "$?" != "0" ]; then
388 sudo mount -o loop ${PART_IMG_NEW} ${MNT_PNT_NEW}
389 if [ "$?" != "0" ]; then
394 fn_extract_needed_files "${MNT_PNT_OLD}" "${MNT_PNT_NEW}"
396 #---- remove unnecessary files & directories ----
397 for ff in ${EXCLUDE_FILES}
399 sudo rm -rf ${MNT_PNT_OLD}/${ff}
400 sudo rm -rf ${MNT_PNT_NEW}/${ff}
403 #---- make attribute ----
404 fn_mk_attribute ${PART_NAME} ${BASE_OLD} ${BASE_NEW}
406 #PART_IMG_ORG parameter should match with DELTA name that is part of default config file. Which will be used to update MAX size file that is present in respective partition.
407 sudo python3 ${COMMON_BINDIR}/CreatePatch.py ${UPDATE_TYPE} ${PART_NAME} ${BASE_OLD} ${BASE_NEW} ${OUTPUT_DIR} ${UPDATE_CFG_PATH} \
408 --attr_old ${V1_ATTR_FILE} --attr_new ${V2_ATTR_FILE}
411 #---- unmount partition image ----
412 echo "umount ${MNT_PNT_OLD} & ${MNT_PNT_NEW}"
413 sudo umount ${MNT_PNT_OLD}
414 sudo umount ${MNT_PNT_NEW}
416 #---- remove files & directories ----
417 echo "remove temp files/directory & move delta/log to result directory"
418 sudo rm -rf ${PART_IMG_OLD}
419 sudo rm -rf ${PART_IMG_NEW}
420 sudo rm -rf ${BASE_OLD} ${BASE_NEW}
423 #---- extra cleanup ----
424 sudo mv ./file_attr_updated_image.txt ${OUTPUT_DIR}/${PART_NAME}_file_attr_updated_image.txt
426 if [ $PythonRet != "0" ]; then
427 echo "[${PART_NAME}] Failed to generate DELTA"
430 END_TIMESTAMP="generation of ${DELTA} [END] $(date +%T)"
431 echo "${START_TIMESTAMP}"
432 echo "${END_TIMESTAMP}"
437 #------------------------------------------------------------------------------
442 # generate delta file for filesystem type partition
447 PART_IMG_ORG=${PART_BIN}
448 PART_IMG_OLD=${PART_IMG_ORG}.old
449 PART_IMG_NEW=${PART_IMG_ORG}.new
452 DEBUG_DELTA=debug_${DELTA}
453 #CFG_XML=${PART_NAME}_FS.xml
455 BASE_OLD=${PART_NAME}_OLD
456 BASE_NEW=${PART_NAME}_NEW
458 #--- !!! this should be modified according to partition ---
459 case "${PART_NAME}" in
461 EXCLUDE_FILES="lost+found dev proc tmp var sys csa"
463 "ramdisk1" | "ramdisk" )
464 EXCLUDE_FILES="lost+found dev proc tmp sys"
466 "ramdisk2" | "ramdisk-recovery" )
467 EXCLUDE_FILES="lost+found"
470 EXCLUDE_FILES="lost+found"
473 EXCLUDE_FILES="lost+found"
483 echo "${PART_NAME} not supported !!!"
488 MNT_PNT_OLD=${BASE_OLD}/
489 MNT_PNT_NEW=${BASE_NEW}/
492 if [ "$?" != "0" ]; then
499 #------------------------------------------------------------------------------
506 PART_IMG_NEW=${PART_BIN}
508 #---- untar partition image and rename for old & new ----
509 echo "untar ${NEW_TAR_FILE}"
510 tar xvf ${NEW_TAR_DIR}/${NEW_TAR_FILE} ${PART_IMG_NEW}
511 if [ "$?" != "0" ]; then
515 sudo mv ${PART_IMG_NEW} ${OUTPUT_DIR}/${PART_BIN}
516 sudo chown ${MY_ID}:${MY_ID} ${OUTPUT_DIR}/${PART_BIN}
523 #------------------------------------------------------------------------------
528 # find tar file name (without path) that contains given partition binary
531 fn_get_tar_file_names()
535 cd ${DATA_DIR}/${OLD_TAR_DIR}
536 OLD_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
539 cd ${DATA_DIR}/${NEW_TAR_DIR}
540 NEW_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
543 #--- find which tar contains the binary ---
544 for tar_file in ${OLD_TAR_LIST}
546 result=`tar -tvf ${DATA_DIR}/${OLD_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
547 if [ "$?" = "0" ]; then
548 OLD_TAR_FILE=${tar_file}
553 for tar_file in ${NEW_TAR_LIST}
555 result=`tar -tvf ${DATA_DIR}/${NEW_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
556 if [ "$?" = "0" ]; then
557 NEW_TAR_FILE=${tar_file}
564 ###############################################################################
571 #--- assign input params to internal variables ---
573 if [ "${param_num}" != "4" ]; then
574 echo "Invalid param num"
575 echo "[Usage] $0 PART_NAME UPDATE_TYPE PART_BIN DELTA_BIN"
584 #--- set some default variables ---
590 COMMON_BINDIR=${CUR_DIR}/../common/bin
591 UPDATE_CFG_PATH=./cfg/update.cfg
593 #--- check if the current working directory is the parent directory of bin, data, cfg, xml ---
595 if [ ! -d ${TEST_DIR} ]; then
596 echo "Invalid working directory. ${TEST_DIR} does not exist"
601 if [ ! -d ${TEST_DIR} ]; then
602 echo "Invalid working directory. ${TEST_DIR} does not exist"
607 #if [ ! -d ${TEST_DIR} ]; then
608 # echo "Invalid working directory. ${TEST_DIR} does not exist"
612 #--- get old/new tar file which includes $PART_BIN ---
613 if [ "z${OLD_TAR_DIR}" = "z" ]; then
614 OLD_TAR_DIR="old_tar"
616 if [ "z${NEW_TAR_DIR}" = "z" ]; then
617 NEW_TAR_DIR="new_tar"
622 fn_get_tar_file_names ${PART_BIN}
624 if [ "z${OLD_TAR_FILE}" = "z" ]; then
625 UPDATE_TYPE_S=(${UPDATE_TYPE//:/ })
626 if [ ! "${UPDATE_TYPE_S[0]}" = "FULL_IMAGE" ]; then
627 echo "[old] tar file does not exist in ${DATA_DIR}/${OLD_TAR_DIR} which contains ${PART_BIN}"
628 #exit 0, cos this is not an error.
633 if [ "z${NEW_TAR_FILE}" = "z" ]; then
634 echo "[new] tar file does not exist in ${DATA_DIR}/${NEW_TAR_DIR} which contains ${PART_BIN}"
638 if [ ! "z${OLD_TAR_FILE}" = "z" ]; then
639 echo "[old] ${OLD_TAR_FILE} contains ${PART_BIN}"
641 echo "[new] ${NEW_TAR_FILE} contains ${PART_BIN}"
644 #--- generate delta binary ---
646 cd ${DATA_DIR} || exit 1
648 OUTPUT_DIR=${PART_NAME}_OUT
649 if [ ! -d ${OUTPUT_DIR} ]; then
650 if [ -f ${OUTPUT_DIR} ]; then
651 sudo rm -f ${OUTPUT_DIR}
656 UPDATE_TYPE_S=(${UPDATE_TYPE//:/ })
657 if [ "${UPDATE_TYPE_S[0]}" = "FULL_IMAGE" ]; then
659 elif [ "${UPDATE_TYPE_S[0]}" = "DELTA_IMAGE" ]; then
661 elif [ "${UPDATE_TYPE_S[0]}" = "DELTA_FS" ]; then
664 echo "Invalid update type"