From 26c60f35c7d6656afb3cc7374d9af8e5f96642bd Mon Sep 17 00:00:00 2001 From: Antoni Adaszkiewicz Date: Thu, 8 Dec 2022 16:05:08 +0100 Subject: [PATCH] Change update-info.ini file generation in "full" type deltas This change will allow update-manager to update using "full" type deltas. Change-Id: I2e9d3ef702483d8b6ab48ba72e2fa908e27b00ac --- mk_delta/common/bin/mk_delta_full.sh | 128 ++++++++++++++++------------- mk_delta/common/bin/update-info-builder.py | 96 +++++++++++++--------- 2 files changed, 127 insertions(+), 97 deletions(-) diff --git a/mk_delta/common/bin/mk_delta_full.sh b/mk_delta/common/bin/mk_delta_full.sh index 8b8d999..d26d60b 100755 --- a/mk_delta/common/bin/mk_delta_full.sh +++ b/mk_delta/common/bin/mk_delta_full.sh @@ -11,10 +11,13 @@ fn_set_default_params() 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_ORIG_PATH=${CFG_DIR}/${UPDATE_INFO_FILE} UPDATE_INFO_PATH=${DATA_DIR}/${UPDATE_INFO_FILE} SETUP_SCRIPT_PATH=${CFG_DIR}/setup.sh + COMMON_BIN_DIR=$(realpath ../common/bin) + UPDATE_INFO_PATH=${COMMON_BIN_DIR}/update-info-builder.py + LOG_PATH=${DATA_DIR}/Delta.log BUILD_STRING_FILE=build_string.txt BUILD_STRING_PATH=${DATA_DIR}/${BUILD_STRING_FILE} @@ -35,54 +38,61 @@ fn_set_default_params() DIR_WITH_IMAGES=${DATA_DIR}/images mkdir -p ${DIR_WITH_IMAGES} + + ROOTFS_EXCTRACTED="rootfs-model-config.xml" + TIZEN_EXCTRACTED="tizen-build.conf" + HAL_EXCTRACTED="hal-model-conf.xml" + UPDATE_INFO_FILE="update-info.ini" +} + +fn_extract_mounting_wrapper() +{ + if [ "$PART_NAME" != "rootfs" ] && [ "$PART_NAME" != "hal" ]; then + return + fi + local MNT_PNT="MNT_PNT" + mkdir -p ${MNT_PNT} + sudo mount -o loop,ro "${DELTA_DIR}/${PART_BIN}" ${MNT_PNT} + + fn_extract_needed_files ${MNT_PNT} + + sudo umount ${MNT_PNT} + rm -rf ${MNT_PNT} } -fn_gen_metadata() +fn_extract_needed_files() { - 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,ro ${ROOTFS_IMG} ${TMP_MNT_PNT} - local NEW_BUILD_STRING=`cat ${TMP_MNT_PNT}/etc/info.ini | grep "Date=" | sed "s/Date=//" | 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} - # Copy upgrade-apply - cp ${TMP_MNT_PNT}/usr/bin/upgrade-apply ${DELTA_DIR} - # Copy upgrade-apply-deltafs - cp ${TMP_MNT_PNT}/usr/bin/upgrade-apply-deltafs ${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 =====" + local MNT_PNT=$1 + + if [ "$PART_NAME" == "hal" ]; then + local HAL_TARG_NAME="hal-model-conf.xml" + local HAL_MODEL_CONFIG_PATH=${MNT_PNT}"/etc/config/model-config.xml" + + # exctarct files/binaries + cp "${HAL_MODEL_CONFIG_PATH}" ${DELTA_DIR}/${HAL_EXCTRACTED} + + elif [ "$PART_NAME" == "rootfs" ]; then + local UPGRADE_SUPPORT="upgrade-support" + local UPGRADE_APPLY="upgrade-apply" + + local ROOTFS_MODEL_CONFIG_PATH=${MNT_PNT}"/etc/config/model-config.xml" + local TIZEN_BUILD_CONFIG_PATH=${MNT_PNT}"/etc/tizen-build.conf" + local UPGRADE_SUPPORT_PATH=${MNT_PNT}"/usr/libexec/"${UPGRADE_SUPPORT} + local UPGRADE_APPLY_PATH=${MNT_PNT}"/usr/bin/"${UPGRADE_APPLY} + + echo "===== Start writing image versions =====" + local OLD_BUILD_STRING="0.0" + local NEW_BUILD_STRING=`cat ${MNT_PNT}/etc/info.ini | grep "Date=" | sed "s/Date=//" | sed "s/;$//"` + echo "${BUILD_STRING_FILE} : ${OLD_BUILD_STRING}@${NEW_BUILD_STRING}" + echo -n ${OLD_BUILD_STRING}@${NEW_BUILD_STRING} > ${BUILD_STRING_PATH} + echo "===== Finish writing image versions =====" + + ## exctarct files/binaries + cp "${ROOTFS_MODEL_CONFIG_PATH}" ${DELTA_DIR}/${ROOTFS_EXCTRACTED} + cp "${TIZEN_BUILD_CONFIG_PATH}" ${DELTA_DIR}/${TIZEN_EXCTRACTED} + cp "${UPGRADE_SUPPORT_PATH}"/* ${DELTA_DIR}/ + cp "${UPGRADE_APPLY_PATH}" ${DELTA_DIR}/ + fi } fn_read_delta_cfg() @@ -146,16 +156,21 @@ fn_copy_image() 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} + fn_extract_mounting_wrapper + echo -e "${PART_NAME}\t${DELTA_BIN}\tFULL_IMAGE:BEFORE_BOOT_FOTA\t/dev/null\t0\t0\t${IMG_SIZE}\t0\t${SHA1_SUM}" >> ${UPDATE_CFG_PATH} } +fn_build_update_info() +{ + sudo python3 "${UPDATE_INFO_PATH}" ${HAL_EXCTRACTED} ${ROOTFS_EXCTRACTED} ${TIZEN_EXCTRACTED} ${UPDATE_INFO_FILE} --full_type + + rm -f ${HAL_EXCTRACTED} ${ROOTFS_EXCTRACTED} ${TIZEN_EXCTRACTED} +} + fn_make_delta_full() { echo "Make full delta file" @@ -189,11 +204,6 @@ fn_make_delta_full() sudo rm ${BUILD_STRING_PATH} fi - if [ -r ${UPDATE_INFO_PATH} ]; then - sudo cp ${UPDATE_INFO_PATH} ${DELTA_DIR}/${UPDATE_INFO_FILE} - sudo rm ${UPDATE_INFO_PATH} - fi - if [ -r ${SETUP_SCRIPT_PATH} ]; then sudo cp ${SETUP_SCRIPT_PATH} ${DELTA_DIR}/setup.sh fi @@ -203,7 +213,13 @@ fn_make_delta_full() fi #--- archive result directory --- - pushd result/$MONDATE/FW_DELTA/DELTA/ + pushd ${DELTA_DIR} + fn_build_update_info + if [ ! -r ${UPDATE_INFO_FILE} ]; then + echo "Delta generation failed - no ${UPDATE_INFO_FILE} generated." + return -1 + fi + sha1sum * > checksum.SHA1 echo "tar result directory" sudo tar cf ../delta.tar * diff --git a/mk_delta/common/bin/update-info-builder.py b/mk_delta/common/bin/update-info-builder.py index 64bc59d..3c1703c 100755 --- a/mk_delta/common/bin/update-info-builder.py +++ b/mk_delta/common/bin/update-info-builder.py @@ -44,27 +44,36 @@ BUILD_PREFIX = "TZ_BUILD_" # following three could be simpler, but this way its easier in case we add more variables to check -def generate_hal_model_config_set(): - hal_list = [ - 'model_name' - ] +def generate_hal_model_config_set(full_type): + hal_list = ['model_name'] + + if not full_type: + hal_list.extend([]) + return set(os.path.join(SYSTEM_PREFIX, elem) for elem in hal_list) -def generate_rootfs_model_config_set(): - rootfs_list = [ - 'manufacturer', - 'device_type' - ] +def generate_rootfs_model_config_set(full_type): + rootfs_list = [] + + if not full_type: + rootfs_list.extend([ + 'manufacturer', + 'device_type' + ]) + return set(os.path.join(SYSTEM_PREFIX, elem) for elem in rootfs_list) -def generate_tizen_build_set(): - tizen_list = [ - 'RELEASE_NAME', - 'ARCH', - 'DATE' - ] +def generate_tizen_build_set(full_type): + tizen_list = ['ARCH'] + + if not full_type: + tizen_list.extend([ + 'RELEASE_NAME', + 'DATE' + ]) + return set(BUILD_PREFIX + elem for elem in tizen_list) @@ -107,28 +116,33 @@ def get_dict_from_xml_file(path, set_info): def generate_main_dict(args): main_dict = {} - hal_set = generate_hal_model_config_set() - rootfs_set = generate_rootfs_model_config_set() - tizen_set = generate_tizen_build_set() + hal_set = generate_hal_model_config_set(args.full_type) + rootfs_set = generate_rootfs_model_config_set(args.full_type) + tizen_set = generate_tizen_build_set(args.full_type) + + if hal_set: + hal_dict = get_dict_from_xml_file(args.hal_model_config_path, hal_set) + if not hal_dict: + print(f'{args.hal_model_config_path}: error parsing file', file=sys.stderr) + return None - hal_dict = get_dict_from_xml_file(args.hal_model_config_path, hal_set) - if not hal_dict: - print(f'{args.hal_model_config_path}: error parsing file', file=sys.stderr) - return None + main_dict.update(hal_dict) - rootfs_dict = get_dict_from_xml_file(args.rootfs_model_config_path, rootfs_set) - if not rootfs_dict: - print(f'{args.rootfs_model_config_path}: error parsing file', file=sys.stderr) - return None + if rootfs_set: + rootfs_dict = get_dict_from_xml_file(args.rootfs_model_config_path, rootfs_set) + if not rootfs_dict: + print(f'{args.rootfs_model_config_path}: error parsing file', file=sys.stderr) + return None - tizen_dict = get_dict_from_text_file(args.tizen_build_config_path, tizen_set) - if not tizen_dict: - print(f'{args.tizen_build_config_path}: error parsing file', file=sys.stderr) - return None + main_dict.update(rootfs_dict) - main_dict.update(hal_dict) - main_dict.update(rootfs_dict) - main_dict.update(tizen_dict) + if tizen_set: + tizen_dict = get_dict_from_text_file(args.tizen_build_config_path, tizen_set) + if not tizen_dict: + print(f'{args.tizen_build_config_path}: error parsing file', file=sys.stderr) + return None + + main_dict.update(tizen_dict) return main_dict @@ -141,6 +155,7 @@ def create_parser(): parser.add_argument('rootfs_model_config_path', type=str, help='path to a file originally at path_to_rootfs/etc/config/model-config.xml') parser.add_argument('tizen_build_config_path', type=str, help='path to a file originally at path_to_rootfs/etc/tizen-build.conf') parser.add_argument('output_file', type=str, help='path to an output file') + parser.add_argument('--full_type', action='store_true', help='create an info file for full type delta') return parser @@ -149,14 +164,13 @@ def main(): parser = create_parser() args = parser.parse_args() - for index, (arg_name, arg_value) in enumerate(vars(args).items(), start=1): - # we do not want output file to exist - if index == len(vars(args)): - if os.path.exists(arg_value): - parser.error(f'{arg_name} = {arg_value} is a file that already exists!') - break - if not (os.path.exists(arg_value) and os.path.isfile(arg_value)): - parser.error(f'{arg_name} = {arg_value} is not a valid path!') + # we do not want output file to exist + if os.path.exists(args.output_file): + parser.error(f'{args.output_file} already exists!') + + for file in [args.hal_model_config_path, args.rootfs_model_config_path, args.tizen_build_config_path]: + if not (os.path.exists(file) and os.path.isfile(file)): + parser.error(f'{file} is not a valid path!') print('--- Generate update info file ---') update_data = generate_main_dict(args) -- 2.7.4