8 #------------------------------------------------------------------------------
13 # read delta configuration file for generating update configuration file to be used during update.
14 # delta config file format : PART_NAME PART_BIN DELTA_BIN UPDATE_TYPE BLK_DEV BLK_OFFSET (deliminator : TAB)
21 if [ ! -r ${in_file} ]; then
22 echo "file ${in_file} cannot be read"
30 if [ "${line:0:1}" = "#" ]; then
36 if [ "${line_len}" = "0" ]; then
42 PART_NAME[${line_num}]=${fields[0]}
43 PART_BIN[${line_num}]=${fields[1]}
44 DELTA_BIN[${line_num}]=${fields[2]}
45 UPDATE_TYPE[${line_num}]=${fields[3]}
46 BLK_DEV[${line_num}]=${fields[4]}
47 BLK_OFFSET[${line_num}]=${fields[5]}
49 line_num=$(($line_num + 1))
55 if [ -f ${out_file} ]; then
56 sudo rm -fr ${out_file}
59 for ((update_idx=0;update_idx<PART_NUM;update_idx++))
61 f1=${PART_NAME[${update_idx}]}
62 f2=${DELTA_BIN[${update_idx}]}
63 f3=${UPDATE_TYPE[${update_idx}]}
64 f4=${BLK_DEV[${update_idx}]}
65 f5=${BLK_OFFSET[${update_idx}]}
67 echo -e "$f1\t\t$f2\t\t$f3\t\t$f4\t\t$f5" >> ${out_file}
73 #------------------------------------------------------------------------------
75 # fn_set_default_params
78 # set default params used globally in this script
81 fn_set_default_params()
84 MK_PART_DELTA=${COMMON_BINDIR}/mk_part_delta.sh
85 DELTA_CFG_PATH=./cfg/delta.cfg
86 UPDATE_CFG_PATH=./cfg/update.cfg
87 PRE_SCRIPT_PATH=./cfg/pre.sh
88 DELTA_UA=./data/delta.ua
89 UPDATE_MANAGER=./data/upgrade-trigger.sh
91 LOG_PATH=./data/Delta.log
92 BUILD_ID_PATH=./data/build_id.txt
93 # Getting date and minor version
96 while [ -d "result/${MONDATE}_${i}" ]
100 MONDATE="${MONDATE}_${i}"
101 echo "MONDATE = ${MONDATE}"
103 if [ "z${OLD_TAR_DIR}" = "z" ]; then
104 export OLD_TAR_DIR="old_tar"
106 if [ "z${NEW_TAR_DIR}" = "z" ]; then
107 export NEW_TAR_DIR="new_tar"
111 #------------------------------------------------------------------------------
113 # fn_swap_binary_files
116 # change old & new for making backward delta
119 fn_swap_binary_files()
121 TEMP_TAR_DIR=${OLD_TAR_DIR}
122 export OLD_TAR_DIR=${NEW_TAR_DIR}
123 export NEW_TAR_DIR=${TEMP_TAR_DIR}
126 #------------------------------------------------------------------------------
128 # fn_print_update_cfg
130 fn_print_update_cfg()
132 for ((update_idx=0;update_idx<PART_NUM;update_idx++))
134 echo "------------------------------"
135 echo "[PART_NAME] ${PART_NAME[${update_idx}]}"
136 echo "[DELTA_BIN] ${DELTA_BIN[${update_idx}]}"
137 echo "[UPDATE_TYPE] ${UPDATE_TYPE[${update_idx}]}"
138 echo "[BLK_DEV] ${BLK_DEV[${update_idx}]}"
139 echo "[BLK_OFFSET] ${BLK_OFFSET[${update_idx}]}"
142 echo "------------------------------"
145 #------------------------------------------------------------------------------
147 # fn_process_extra_delta
150 fn_process_extra_delta()
153 if [ "${part_name}" = "RAMDISK2" ]; then
154 if [ "${RAMDISK2_FULL_IMG}" = "0" ]; then
155 #--- delta recovery partition ---
156 ${MK_PART_DELTA} ${part_name} DELTA_IMG ${part_bin} ${delta_bin}
157 if [ "$?" = "0" ]; then
158 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
159 sudo mv ${RESULT_DIR}/${part_bin}/${delta_bin} ${DELTA_DIR}
162 if [ "${RAMDISK2_FULL_IMG}" = "1" ]; then
163 #--- full recovery partition ---
164 ${MK_PART_DELTA} ${part_name} FULL_IMG ${part_bin} ${delta_bin}
165 if [ "$?" = "0" ]; then
166 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
167 sudo mv ${RESULT_DIR}/${part_bin}/${part_bin} ${DELTA_DIR}
170 elif [ "${part_name}" = "RECOVERY" ]; then
171 #--- recovery kernel ---
172 sudo echo "1" > ${DELTA_DIR}/${delta_bin}
173 elif [ "${part_name}" = "EXTRA" ]; then
178 #------------------------------------------------------------------------------
180 # fn_get_tar_file_names
183 # find tar file name (without path) that contains given partition binary
186 fn_get_tar_file_names()
190 cd ${DATA_DIR}/${OLD_TAR_DIR}
191 OLD_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
194 cd ${DATA_DIR}/${NEW_TAR_DIR}
195 NEW_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
198 #--- find which tar contains the binary ---
199 for tar_file in ${OLD_TAR_LIST}
201 result=`tar -tvf ${DATA_DIR}/${OLD_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
202 if [ "$?" = "0" ]; then
203 OLD_TAR_FILE=${tar_file}
208 for tar_file in ${NEW_TAR_LIST}
210 result=`tar -tvf ${DATA_DIR}/${NEW_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
211 if [ "$?" = "0" ]; then
212 NEW_TAR_FILE=${tar_file}
219 #------------------------------------------------------------------------------
221 # fn_extract_from_image
224 # extract some files from given image
227 fn_extract_from_image()
236 fn_get_tar_file_names $IMAGE
237 tar xvf ${DATA_DIR}/${NEW_TAR_DIR}/${NEW_TAR_FILE} ${IMAGE}
238 if [ "$?" != "0" ]; then
242 sudo mount -t ext4 -o loop ${IMAGE} ${MNT_PNT}
243 if [ "$?" != "0" ]; then
247 EXTRACT_FILE="${MNT_PNT}${TARGET_FILE}"
248 if [ -e ${EXTRACT_FILE} ]; then
249 sudo cp ${EXTRACT_FILE} ${DELTA_DIR}
251 echo "There is no ${TARGET_FILE} in ${IMAGE}"
254 sudo umount ${MNT_PNT}
255 sudo rm -rf ${MNT_PNT}
259 ###############################################################################
264 COMMON_BINDIR=${PWD}/../common/bin
266 fn_set_default_params
268 fn_gen_update_cfg ${DELTA_CFG_PATH} ${UPDATE_CFG_PATH}
270 ################### Make delta Forward and Backward #####################
271 if [ "z${FW_BW}" = "z" ]; then
272 #FW_BW="FW_DELTA BW_DELTA"
276 START_TIMESTAMP="$(date +%T)"
278 for Make_Delta in $FW_BW
280 #--- archive result directory ---
281 echo "Make $Make_Delta Delta file"
282 RESULT_DIR=result/$MONDATE/$Make_Delta
283 DELTA_DIR=${RESULT_DIR}/DELTA
284 mkdir -p ${DELTA_DIR}
286 if [ "$Make_Delta" = "BW_DELTA" ]; then
291 #--- make delta for each partition ---
292 for ((part_num=0;part_num<PART_NUM;part_num++))
294 part_name=${PART_NAME[${part_num}]}
295 update_type=${UPDATE_TYPE[${part_num}]}
296 part_bin=${PART_BIN[${part_num}]}
297 delta_bin=${DELTA_BIN[${part_num}]}
299 PART_OUT=${part_name}_OUT
301 if [ "${update_type}" = "EXTRA" ]; then
302 fn_process_extra_delta
304 ${MK_PART_DELTA} ${part_name} ${update_type} ${part_bin} ${delta_bin}
305 if [ "$?" = "0" ]; then
306 if [ "${update_type}" = "DELTA_FS" ]; then
307 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
308 sudo mv ${RESULT_DIR}/${part_bin} ${DELTA_DIR}
310 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
311 sudo mv ${RESULT_DIR}/${part_bin}/${delta_bin} ${DELTA_DIR}
314 sudo rm -rf ${RESULT_DIR}/${part_bin}
315 echo "Error: Abort Delta Generation"
319 sudo rm -rf ${RESULT_DIR}/${part_bin}
322 #move update.cfg to delta directory
323 if [ -r ${UPDATE_CFG_PATH} ]; then
324 sudo cp ${UPDATE_CFG_PATH} ${DELTA_DIR}/update.cfg
325 sudo rm ${UPDATE_CFG_PATH}
327 if [ -r ${LOG_PATH} ]; then
328 sudo cp ${LOG_PATH} ${RESULT_DIR}/Delta.log
332 if [ -r ${BUILD_ID_PATH} ]; then
333 sudo cp ${BUILD_ID_PATH} ${DELTA_DIR}/build_id.txt
334 sudo rm ${BUILD_ID_PATH}
336 if [ -r ${PRE_SCRIPT_PATH} ]; then
337 sudo cp ${PRE_SCRIPT_PATH} ${DELTA_DIR}/pre.sh
340 #--- extract files which would be appended to delta.tar ---
341 echo "Extract binaries for update from images"
342 fn_extract_from_image rootfs.img /usr/bin/upgrade-trigger.sh
343 fn_extract_from_image ramdisk-recovery.img /usr/bin/delta.ua
345 #--- archive result directory ---
347 echo "tar result directory"
348 sudo tar cf ${MONDATE}_${Make_Delta}.tar $Make_Delta
351 echo "Making delta binary is End!! ($Make_Delta)"
354 if [ -r ${UPDATE_CFG_PATH} ]; then
355 sudo rm ${UPDATE_CFG_PATH}
358 sudo cp ${COMMON_BINDIR}/unpack.sh ./
359 sudo tar --overwrite -cf ../delta.tar *
362 SIGN_PKCS_PASSWORD=$2
363 if [ "z${SIGN_PKCS_FILE}" != "z" ] && [ "z${SIGN_PKCS_PASSWORD}" != "z" ]; then
364 sudo ${COMMON_BINDIR}/sign_img.sh ${SIGN_PKCS_FILE} ${SIGN_PKCS_PASSWORD} ../delta.tar
368 END_TIMESTAMP="$(date +%T)"
370 echo "OVERALL TIMESTAMP : [START] ${START_TIMESTAMP} ~ [END] ${END_TIMESTAMP}"