From a8528a1fdbd7e20bf2874ba00c9bdc6b159877d3 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Thu, 26 May 2022 16:41:59 +0200 Subject: [PATCH] Add script to generate full delta To generate the full delta, pass the 'full' argument to the delta-generation.sh: ./scripts/delta-generation.sh . device_XYZ full Change-Id: Ic847f396455b97e07091bf01c62bfb21b5da7ea9 --- mk_delta/common/bin/mk_delta_full.sh | 220 +++++++++++++++++++++++++++++++++++ scripts/delta-generation.sh | 23 +++- 2 files changed, 239 insertions(+), 4 deletions(-) create mode 100755 mk_delta/common/bin/mk_delta_full.sh diff --git a/mk_delta/common/bin/mk_delta_full.sh b/mk_delta/common/bin/mk_delta_full.sh new file mode 100755 index 0000000..c812b08 --- /dev/null +++ b/mk_delta/common/bin/mk_delta_full.sh @@ -0,0 +1,220 @@ +#!/bin/bash + +set -u +shopt -s nullglob + +fn_set_default_params() +{ + MY_ID=$(whoami) + DATA_DIR=./data + CFG_DIR=./cfg + DELTA_CFG_PATH=${CFG_DIR}/delta.cfg + UPDATE_CFG_PATH=${DATA_DIR}/update.cfg + UPDATE_INFO_FILE=update-info.ini + UPDATE_INFO_ORIG_PATH=${CFG_DIR}/${UPDATE_INFO_FILE}.in + UPDATE_INFO_PATH=${DATA_DIR}/${UPDATE_INFO_FILE} + SETUP_SCRIPT_PATH=${CFG_DIR}/setup.sh + + LOG_PATH=${DATA_DIR}/Delta.log + BUILD_STRING_FILE=build_string.txt + BUILD_STRING_PATH=${DATA_DIR}/${BUILD_STRING_FILE} + # Getting date and minor version + MONDATE=$(date +%m%d) + i=1 + while [ -d "result/${MONDATE}_${i}" ] + do + i=$(($i + 1)) + done + MONDATE="${MONDATE}_${i}" + echo "MONDATE = ${MONDATE}" + + NEW_TAR_DIR="new_tar" + RESULT_DIR=result/$MONDATE/FW_DELTA + DELTA_DIR=${RESULT_DIR}/DELTA + mkdir -p ${DELTA_DIR} + + DIR_WITH_IMAGES=${DATA_DIR}/images + mkdir -p ${DIR_WITH_IMAGES} +} + +fn_gen_metadata() +{ + ROOTFS_IMG="$1" + + echo "===== Start writing image versions =====" + local TMP_MNT_PNT="TMP_MNT_PNT" + mkdir -p ${TMP_MNT_PNT} + + local OLD_BUILD_STRING="0.0" + + sudo mount -o loop ${ROOTFS_IMG} ${TMP_MNT_PNT} + local NEW_BUILD_STRING=`cat ${TMP_MNT_PNT}/etc/info.ini | grep "Release=" | sed "s/Release=//" | sed "s/;$//"` + local BINOUT="$(LC_ALL=C LANG=C file -b ${TMP_MNT_PNT}/bin/ls)" + + # Copy upgrade scripts + cp -Rd ${TMP_MNT_PNT}/usr/libexec/upgrade-support/* ${DELTA_DIR} + sudo umount ${TMP_MNT_PNT} + + case "${BINOUT}" in + # ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, ... + *ELF*64-bit*x86-64*) ARCHITECTURE=x86-64;; + + # ELF 32-bit LSB shared object, ARM, EABI5 version, dynamically linked, interpreter /lib/ld-linux.so.3, ... + *ELF*32-bit*ARM,*) ARCHITECTURE=arm32;; + + # ELF 64-bit LSB pie executable, ARM aarch64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, ... + *ELF*64-bit*ARM*aarch64*) ARCHITECTURE=arm64;; + esac + + echo "${BUILD_STRING_FILE} : ${OLD_BUILD_STRING}@${NEW_BUILD_STRING}" + echo -n ${OLD_BUILD_STRING}@${NEW_BUILD_STRING} > ${BUILD_STRING_PATH} + + sed -e "s,@SOURCE_VERSION@,${OLD_BUILD_STRING},g" \ + -e "s,@TARGET_VERSION@,${NEW_BUILD_STRING},g" \ + -e "s,@ARCHITECTURE@,${ARCHITECTURE},g" \ + -e "s,@IMAGE_TYPE@,all,g" \ + < "${UPDATE_INFO_ORIG_PATH}" > "${UPDATE_INFO_PATH}" + + echo "update-info.ini:" + cat "${UPDATE_INFO_PATH}" + rm -rf ${TMP_MNT_PNT} + echo "===== Finish writing image versions =====" +} + +fn_read_delta_cfg() +{ + in_file=$1 + + echo "Read ${in_file}" + + if [ ! -r ${in_file} ]; then + echo "file ${in_file} cannot be read" + return 1 + fi + + line_num=0 + while read line + do + # skip comment line + if [ "${line:0:1}" = "#" ]; then + continue + fi + + # skip empty line + line_len=${#line} + if [ "${line_len}" = "0" ]; then + continue + fi + + + fields=(${line}) + PART_NAME[${line_num}]=${fields[0]} + PART_BIN[${line_num}]=${fields[1]} + DELTA_BIN[${line_num}]=${fields[2]} + + line_num=$(($line_num + 1)) + + done < ${in_file} + + PART_NUM=${line_num} + return 0 +} + +fn_extract_all_images() +{ + echo "Extracting archives with images:" + for tar_file in "${DATA_DIR}/${NEW_TAR_DIR}"/*.{tar,tar.gz} + do + echo -e "\t$(basename ${tar_file})" + tar xf "${tar_file}" -C "${DIR_WITH_IMAGES}" + done +} + +fn_copy_image() +{ + PART_NAME="$1" + PART_BIN="$2" + DELTA_BIN="$3" + CUR_DIR=$(pwd) + + echo -ne "Add an image for ${PART_NAME} (${PART_BIN} -> ${DELTA_BIN})" + IMG_SIZE=$(du -b ${DIR_WITH_IMAGES}/${PART_BIN} | awk '{print $1}') + SHA1_SUM=$(sha1sum ${DIR_WITH_IMAGES}/${PART_BIN} | awk '{print $1}') + echo -e "\t\t${IMG_SIZE}\t[${SHA1_SUM}]" + + if [ "${PART_NAME}" == "rootfs" ]; then + fn_gen_metadata ${DIR_WITH_IMAGES}/${PART_BIN} + fi + + sudo mv ${DIR_WITH_IMAGES}/${PART_BIN} ${DELTA_DIR}/${DELTA_BIN} + sudo chown ${MY_ID}:${MY_ID} ${DELTA_DIR}/${PART_BIN} + + echo -e "${PART_NAME}\t${DELTA_BIN}\tPRE_UA\t/dev/null\t0\t0\t${IMG_SIZE}\t0\t${SHA1_SUM}" >> ${UPDATE_CFG_PATH} +} + +fn_make_delta_full() +{ + echo "Make full delta file" + fn_extract_all_images $DIR_WITH_IMAGES + + for ((part_num=0;part_num rpi3 | tw1" + echo " DELTA_TYPE> common | full (default: common)" exit fi TOTA_UPG_PATH=$1 TARGET=$2 -SIGN_PKCS_FILE=$3 -SIGN_PKCS_PASSWORD=$4 + +if [ -z ${3+x} ]; then + DELTA_TYPE="common" +else + DELTA_TYPE=$3 +fi + +if [ "$DELTA_TYPE" == "common" ]; then + SIGN_PKCS_FILE=$4 + SIGN_PKCS_PASSWORD=$5 +fi # Path of downloaded images (old, new) TOTA_UPG_WORK=${TOTA_UPG_PATH}/mk_delta/${TARGET} @@ -57,5 +68,9 @@ cd ${CWD} # Execute mk_delta script CWD=${PWD} cd ${TOTA_UPG_WORK} -../common/bin/mk_delta.sh ${SIGN_PKCS_FILE} ${SIGN_PKCS_PASSWORD} +if [ "$DELTA_TYPE" == "full" ]; then + ../common/bin/mk_delta_full.sh +else + ../common/bin/mk_delta.sh ${SIGN_PKCS_FILE} ${SIGN_PKCS_PASSWORD} +fi cd ${CWD} -- 2.7.4