3 # Enabling this option is needed to remove patterns from the argument list if
4 # there are no matching files. Without this, "touch" would create the file
5 # "*.ini" if there was no file that matched.
12 #------------------------------------------------------------------------------
17 # read delta configuration file for generating update configuration file to be used during update.
18 # delta config file format : PART_NAME PART_BIN DELTA_BIN UPDATE_TYPE BLK_DEV BLK_OFFSET (deliminator : TAB)
25 if [ ! -r ${in_file} ]; then
26 echo "file ${in_file} cannot be read"
34 if [ "${line:0:1}" = "#" ]; then
40 if [ "${line_len}" = "0" ]; then
46 PART_NAME[${line_num}]=${fields[0]}
47 PART_BIN[${line_num}]=${fields[1]}
48 DELTA_BIN[${line_num}]=${fields[2]}
49 UPDATE_TYPE[${line_num}]=${fields[3]}
50 BLK_DEV[${line_num}]=${fields[4]}
51 BLK_OFFSET[${line_num}]=${fields[5]}
53 line_num=$(($line_num + 1))
59 if [ -f ${out_file} ]; then
60 sudo rm -fr ${out_file}
63 for ((update_idx=0;update_idx<PART_NUM;update_idx++))
65 f1=${PART_NAME[${update_idx}]}
66 f2=${DELTA_BIN[${update_idx}]}
67 f3=${UPDATE_TYPE[${update_idx}]}
68 f4=${BLK_DEV[${update_idx}]}
69 f5=${BLK_OFFSET[${update_idx}]}
71 echo -e "$f1\t\t$f2\t\t$f3\t\t$f4\t\t$f5" >> ${out_file}
77 #------------------------------------------------------------------------------
79 # fn_set_default_params
82 # set default params used globally in this script
85 fn_set_default_params()
88 MK_PART_DELTA=${COMMON_BINDIR}/mk_part_delta.sh
89 DELTA_CFG_PATH=./cfg/delta.cfg
90 UPDATE_CFG_PATH=./cfg/update.cfg
91 UPDATE_INFO_FILE=update-info.ini
92 UPDATE_INFO_PATH=./data/${UPDATE_INFO_FILE}
93 SETUP_SCRIPT_PATH=./cfg/setup.sh
94 UPDATE_MANAGER=./data/upgrade-trigger.sh
96 LOG_PATH=./data/Delta.log
97 BUILD_STRING_FILE=build_string.txt
98 BUILD_STRING_PATH=./data/${BUILD_STRING_FILE}
99 # Getting date and minor version
100 MONDATE=$(date +%m%d)
102 while [ -d "result/${MONDATE}_${i}" ]
106 MONDATE="${MONDATE}_${i}"
107 echo "MONDATE = ${MONDATE}"
109 if [ "z${OLD_TAR_DIR}" = "z" ]; then
110 export OLD_TAR_DIR="old_tar"
112 if [ "z${NEW_TAR_DIR}" = "z" ]; then
113 export NEW_TAR_DIR="new_tar"
117 #------------------------------------------------------------------------------
119 # fn_swap_binary_files
122 # change old & new for making backward delta
125 fn_swap_binary_files()
127 TEMP_TAR_DIR=${OLD_TAR_DIR}
128 export OLD_TAR_DIR=${NEW_TAR_DIR}
129 export NEW_TAR_DIR=${TEMP_TAR_DIR}
132 #------------------------------------------------------------------------------
134 # fn_print_update_cfg
136 fn_print_update_cfg()
138 for ((update_idx=0;update_idx<PART_NUM;update_idx++))
140 echo "------------------------------"
141 echo "[PART_NAME] ${PART_NAME[${update_idx}]}"
142 echo "[DELTA_BIN] ${DELTA_BIN[${update_idx}]}"
143 echo "[UPDATE_TYPE] ${UPDATE_TYPE[${update_idx}]}"
144 echo "[BLK_DEV] ${BLK_DEV[${update_idx}]}"
145 echo "[BLK_OFFSET] ${BLK_OFFSET[${update_idx}]}"
148 echo "------------------------------"
151 #------------------------------------------------------------------------------
153 # fn_process_extra_delta
156 fn_process_extra_delta()
159 if [ "${part_name}" = "RAMDISK2" ]; then
160 if [ "${RAMDISK2_FULL_IMG}" = "0" ]; then
161 #--- delta recovery partition ---
162 ${MK_PART_DELTA} ${part_name} DELTA_IMAGE:AT_BOOT_FOTA ${part_bin} ${delta_bin}
163 if [ "$?" = "0" ]; then
164 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
165 sudo mv ${RESULT_DIR}/${part_bin}/${delta_bin} ${DELTA_DIR}
168 if [ "${RAMDISK2_FULL_IMG}" = "1" ]; then
169 #--- full recovery partition ---
170 ${MK_PART_DELTA} ${part_name} FULL_IMAGE:AT_BOOT_FOTA ${part_bin} ${delta_bin}
171 if [ "$?" = "0" ]; then
172 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
173 sudo mv ${RESULT_DIR}/${part_bin}/${part_bin} ${DELTA_DIR}
176 elif [ "${part_name}" = "RECOVERY" ]; then
177 #--- recovery kernel ---
178 sudo echo "1" > ${DELTA_DIR}/${delta_bin}
179 elif [ "${part_name}" = "EXTRA" ]; then
184 #------------------------------------------------------------------------------
186 # fn_get_tar_file_names
189 # find tar file name (without path) that contains given partition binary
192 fn_get_tar_file_names()
196 cd ${DATA_DIR}/${OLD_TAR_DIR}
197 OLD_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
200 cd ${DATA_DIR}/${NEW_TAR_DIR}
201 NEW_TAR_LIST=`ls *.tar *.tar.gz *.tgz *.tar.md5 2>/dev/null`
204 #--- find which tar contains the binary ---
205 for tar_file in ${OLD_TAR_LIST}
207 result=`tar -tvf ${DATA_DIR}/${OLD_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
208 if [ "$?" = "0" ]; then
209 OLD_TAR_FILE=${tar_file}
214 for tar_file in ${NEW_TAR_LIST}
216 result=`tar -tvf ${DATA_DIR}/${NEW_TAR_DIR}/${tar_file} | grep " ${BIN_TO_FIND}$"`
217 if [ "$?" = "0" ]; then
218 NEW_TAR_FILE=${tar_file}
225 #------------------------------------------------------------------------------
227 # fn_extract_from_image
230 # extract some files from given image
233 fn_extract_from_image()
242 fn_get_tar_file_names $IMAGE
243 tar xvf ${DATA_DIR}/${NEW_TAR_DIR}/${NEW_TAR_FILE} ${IMAGE}
244 if [ "$?" != "0" ]; then
248 sudo mount -o loop ${IMAGE} ${MNT_PNT}
249 if [ "$?" != "0" ]; then
253 EXTRACT_FILE="${MNT_PNT}${TARGET_FILE}"
254 if [ -d ${EXTRACT_FILE} ]; then
255 sudo cp -Rd ${EXTRACT_FILE}/* ${DELTA_DIR}
256 elif [ -e ${EXTRACT_FILE} ]; then
257 sudo cp ${EXTRACT_FILE} ${DELTA_DIR}
259 echo "There is no ${TARGET_FILE} in ${IMAGE}"
262 sudo umount ${MNT_PNT}
263 sudo rm -rf ${MNT_PNT}
267 ###############################################################################
272 COMMON_BINDIR=${PWD}/../common/bin
274 fn_set_default_params
276 fn_gen_update_cfg ${DELTA_CFG_PATH} ${UPDATE_CFG_PATH}
278 ################### Make delta Forward and Backward #####################
279 if [ "z${FW_BW}" = "z" ]; then
280 #FW_BW="FW_DELTA BW_DELTA"
284 START_TIMESTAMP="$(date +%T)"
286 for Make_Delta in $FW_BW
288 #--- archive result directory ---
289 echo "Make $Make_Delta Delta file"
290 RESULT_DIR=result/$MONDATE/$Make_Delta
291 DELTA_DIR=${RESULT_DIR}/DELTA
292 mkdir -p ${DELTA_DIR}
294 if [ "$Make_Delta" = "BW_DELTA" ]; then
299 #--- make delta for each partition ---
300 for ((part_num=0;part_num<PART_NUM;part_num++))
302 part_name=${PART_NAME[${part_num}]}
303 update_type=${UPDATE_TYPE[${part_num}]}
304 part_bin=${PART_BIN[${part_num}]}
305 delta_bin=${DELTA_BIN[${part_num}]}
307 PART_OUT=${part_name}_OUT
309 if [ "${update_type}" = "EXTRA" ]; then
310 fn_process_extra_delta
312 ${MK_PART_DELTA} ${part_name} ${update_type} ${part_bin} ${delta_bin}
313 if [ "$?" = "0" ]; then
314 if [ "${update_type}" = "DELTA_FS" ]; then
315 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
316 sudo mv ${RESULT_DIR}/${part_bin} ${DELTA_DIR}
318 sudo mv data/${PART_OUT} ${RESULT_DIR}/${part_bin}
319 sudo mv ${RESULT_DIR}/${part_bin}/${delta_bin} ${DELTA_DIR}
321 if [ "$?" != "0" ]; then
322 echo "Warning: No differences - remove record for \"${part_name}\" from the final update.cfg"
323 sed -i "/^${part_name}\b/d" "${UPDATE_CFG_PATH}"
326 sudo rm -rf ${RESULT_DIR}/${part_bin}
327 echo "Error: Abort Delta Generation"
331 sudo rm -rf ${RESULT_DIR}/${part_bin}
334 if [ ! -s "${UPDATE_CFG_PATH}" ]; then
335 echo "Error: No differences between versions - abort delta generation"
339 #move update.cfg to delta directory
340 if [ -r ${UPDATE_CFG_PATH} ]; then
341 sudo cp ${UPDATE_CFG_PATH} ${DELTA_DIR}/update.cfg
342 sudo rm ${UPDATE_CFG_PATH}
344 if [ -r ${LOG_PATH} ]; then
345 sudo cp ${LOG_PATH} ${RESULT_DIR}/Delta.log
349 if [ -r ${BUILD_STRING_PATH} ]; then
350 sudo cp ${BUILD_STRING_PATH} ${DELTA_DIR}/${BUILD_STRING_FILE}
351 sudo rm ${BUILD_STRING_PATH}
354 if [ -r ${UPDATE_INFO_PATH} ]; then
355 sudo cp ${UPDATE_INFO_PATH} ${DELTA_DIR}/${UPDATE_INFO_FILE}
356 sudo rm ${UPDATE_INFO_PATH}
359 if [ -r ${SETUP_SCRIPT_PATH} ]; then
360 sudo cp ${SETUP_SCRIPT_PATH} ${DELTA_DIR}/setup.sh
363 #--- extract files which would be appended to delta.tar ---
364 echo "Extract binaries for update from images"
365 fn_extract_from_image rootfs.img /usr/libexec/upgrade-support
366 fn_extract_from_image rootfs.img /usr/bin/upgrade-apply
368 #--- archive result directory ---
370 echo "tar result directory"
371 sudo tar cf ${MONDATE}_${Make_Delta}.tar $Make_Delta
374 echo "Making delta binary is End!! ($Make_Delta)"
377 if [ -r ${UPDATE_CFG_PATH} ]; then
378 sudo rm ${UPDATE_CFG_PATH}
381 sudo cp ${COMMON_BINDIR}/unpack.sh ./
383 # Ensure essential files are at beginning of archive (metadata, scripts and binaries to perform upgrade)
384 touch *.txt *.cfg *.ini *.sh *.ua
385 sha1sum * > checksum.SHA1
386 sudo tar --overwrite -cpf ../delta.tar $(ls -1td *)
389 SIGN_PKCS_PASSWORD=$2
390 if [ "z${SIGN_PKCS_FILE}" != "z" ]; then
391 if [ "z${SIGN_PKCS_PASSWORD}" != "z" ]; then
392 SIGNER_OPTIONAL_ARGUMENT="-p ${SIGN_PKCS_PASSWORD}"
394 sudo ${COMMON_BINDIR}/sign_img.sh -k ${SIGN_PKCS_FILE} -i ../delta.tar ${SIGNER_OPTIONAL_ARGUMENT}
398 END_TIMESTAMP="$(date +%T)"
400 echo "OVERALL TIMESTAMP : [START] ${START_TIMESTAMP} ~ [END] ${END_TIMESTAMP}"