From e65be961cd63f79f2162bb1acbff7f8fe2a224a0 Mon Sep 17 00:00:00 2001 From: David Escalona Date: Mon, 10 Jul 2023 12:25:40 +0200 Subject: [PATCH] meta-digi-dey: swupdate: reorganize 'swupdate' custom classes and extensions We expect new types of SWU update packages to be created in the future. To avoid splitting all the code in different classes based on the update type, create the generic class 'dey-swupdate' to hold all the custom code and the 'dey-swupdate-common' class to hold all the required variables. This basically renames the old 'swupdate-files' and 'swupdate-files-common' classes. While on it, reorganize the 'swupdate-images' recipe to move variable declarations and functionallity to the correct place: - Move all variable declarations to 'swupdate-digi-common' class and organize them in functional groups. - Improve the way files are included in the 'SWUPDATE_IMAGES' by using the update type variables. - Move the update script copy to the 'do_swuimage' prepend function. Until now, the copy process was executed in the 'fill_description' method, which should only touch the 'sw-description' file. - Rename some variables to use 'SWUPDATE' prefix. - Minor cosmetic changes. https://onedigi.atlassian.net/browse/DEL-8624 Signed-off-by: David Escalona --- meta-digi-dey/classes/dey-image.bbclass | 4 +- .../classes/dey-swupdate-common.bbclass | 84 +++++++++++++++++++ ...ate-files.bbclass => dey-swupdate.bbclass} | 8 +- .../classes/swupdate-files-common.bbclass | 18 ---- .../swu-images/files/image_template_mmc | 4 +- .../swu-images/files/image_template_nand | 4 +- .../files/sw-description-files_template | 2 +- .../files/sw-description-images_template | 8 +- meta-digi-dey/recipes-digi/swu-images/swu.inc | 78 ++++++----------- 9 files changed, 128 insertions(+), 82 deletions(-) create mode 100644 meta-digi-dey/classes/dey-swupdate-common.bbclass rename meta-digi-dey/classes/{swupdate-files.bbclass => dey-swupdate.bbclass} (93%) delete mode 100644 meta-digi-dey/classes/swupdate-files-common.bbclass diff --git a/meta-digi-dey/classes/dey-image.bbclass b/meta-digi-dey/classes/dey-image.bbclass index 21ad42958..e91c10b8e 100644 --- a/meta-digi-dey/classes/dey-image.bbclass +++ b/meta-digi-dey/classes/dey-image.bbclass @@ -74,5 +74,5 @@ DEPENDS += "${@oe.utils.conditional('TRUSTFENCE_SIGN', '1', 'trustfence-sign-too # Do not include kernel in rootfs images PACKAGE_EXCLUDE = "kernel-image-*" -# Create 'tar.gz' file for SWUpdate files update mechanism. -inherit swupdate-files +# Add required methods to generate the correct SWU update package. +inherit dey-swupdate diff --git a/meta-digi-dey/classes/dey-swupdate-common.bbclass b/meta-digi-dey/classes/dey-swupdate-common.bbclass new file mode 100644 index 000000000..ee96e2d97 --- /dev/null +++ b/meta-digi-dey/classes/dey-swupdate-common.bbclass @@ -0,0 +1,84 @@ +# Copyright (C) 2023 Digi International. +# + +####################################### +########## General variables ########## +####################################### + +def get_baseimg_pn(d): + file_name = d.getVar('PN') + return file_name[:file_name.find("-swu")] if "-swu" in file_name else file_name + +IMAGE_DEPENDS = "${@get_baseimg_pn(d)}" + +IMG_NAME = "${IMAGE_DEPENDS}" + +# Update description. +SWUPDATE_DESCRIPTION = "${@oe.utils.ifelse(d.getVar('TRUSTFENCE_ENCRYPT_ROOTFS') == '1', 'Encrypted rootfs ${IMG_NAME} update', '${IMG_NAME} update')}" + +# Storage type. +SWUPDATE_STORAGE_TYPE = "${@oe.utils.conditional('STORAGE_MEDIA', 'mmc', 'mmc', 'mtd', d)}" + +# Root file system type. +SWUPDATE_ROOTFS_TYPE = "${@bb.utils.contains('IMAGE_FEATURES', 'read-only-rootfs', 'squashfs', '', d)}" + +# Dual boot partition names for eMMC or MTD +BOOT_DEV_NAME_A ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p1', 'linux_a', d)}" +BOOT_DEV_NAME_B ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p2', 'linux_b', d)}" +ROOTFS_DEV_NAME_A ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p3', 'rootfs_a', d)}" +ROOTFS_DEV_NAME_B ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p4', 'rootfs_b', d)}" + +####################################### +###### SWU Update based on files ###### +####################################### + +# Variable used to generate the tar.gz file. Do not modify. +SWUPDATE_FILES_TARGZ_FILE_NAME = "swupdate-files.tar.gz" + +# Initialize variable to provide a custom tar.gz file containing files/dirs to install. +SWUPDATE_FILES_TARGZ_FILE ?= "" + +# Initialize variable to store the files/folders that will be part of the SWUpdate package. +SWUPDATE_FILES_LIST ?= "" + +# Checks whether SWU update is based on files or not. +def update_based_on_files(d): + return str(d.getVar('SWUPDATE_FILES_TARGZ_FILE') != "" or d.getVar('SWUPDATE_FILES_LIST') != "").lower() + +# Variable that determines if SWU update is based on files or not. +SWUPDATE_IS_FILES_UPDATE = "${@update_based_on_files(d)}" + +####################################### +##### SWU Update based on images ###### +####################################### + +# Image template based on storage type. +SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE = "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', 'image_template_mmc', 'image_template_nand', d)}" + +# Checks whether SWU update is based on images or not. +def update_based_on_images(d): + return str(d.getVar('SWUPDATE_IS_FILES_UPDATE') != "true").lower() + +# Variable that determines if SWU update is based on images or not. +SWUPDATE_IS_IMAGES_UPDATE = "${@update_based_on_images(d)}" + +####################################### +########## SWU Update U-Boot ########## +####################################### + +# Determine the correct UBoot update script file to use depending on storage type. +SWUPDATE_UBOOT_SCRIPT = "${@oe.utils.conditional('STORAGE_MEDIA', 'mmc', 'swupdate_uboot_mmc.sh', 'swupdate_uboot_nand.sh', d)}" + +UBOOT_EXT ?= ".${UBOOT_SUFFIX}" + +UBOOTIMG_OFFSET ?= "${BOOTLOADER_SEEK_BOOT}" + +####################################### +########## SWU Update Script ########## +####################################### + +# Initialize variable that configures the update script to use. +SWUPDATE_SCRIPT ?= "${@oe.utils.vartrue('SWUPDATE_IS_FILES_UPDATE', 'update_files.sh', 'update_images.sh', d)}" + +# Name of the update script to include in the SWU package. +SWUPDATE_SCRIPT_NAME = "${@os.path.basename(d.getVar('SWUPDATE_SCRIPT'))}" diff --git a/meta-digi-dey/classes/swupdate-files.bbclass b/meta-digi-dey/classes/dey-swupdate.bbclass similarity index 93% rename from meta-digi-dey/classes/swupdate-files.bbclass rename to meta-digi-dey/classes/dey-swupdate.bbclass index 68f3b2849..eb351c1fd 100644 --- a/meta-digi-dey/classes/swupdate-files.bbclass +++ b/meta-digi-dey/classes/dey-swupdate.bbclass @@ -12,7 +12,11 @@ # # Load commmon variables. -inherit swupdate-files-common +inherit dey-swupdate-common + +####################################### +###### SWU Update based on files ###### +####################################### create_swupdate_targz_file() { local targzfile="${DEPLOY_DIR_IMAGE}/${SWUPDATE_FILES_TARGZ_FILE_NAME}" @@ -28,7 +32,7 @@ create_swupdate_targz_file() { # File is not correctly compressed, exit with error. echo "[ERROR] File ${SWUPDATE_FILES_TARGZ_FILE} is not a valid 'tar.gz' file. Aborting..." exit 1 - fi + fi gunzip "${targzfile}" # Add the 'sw-versions' file. tar -C "${IMAGE_ROOTFS}" -uf "${targzfile%.*}" etc/sw-versions diff --git a/meta-digi-dey/classes/swupdate-files-common.bbclass b/meta-digi-dey/classes/swupdate-files-common.bbclass deleted file mode 100644 index 4255d9f18..000000000 --- a/meta-digi-dey/classes/swupdate-files-common.bbclass +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (C) 2023 Digi International. -# - -# Variable used to generate the tar.gz file. Do not modify. -SWUPDATE_FILES_TARGZ_FILE_NAME = "swupdate-files.tar.gz" - -# Initialize variable to provide a custom tar.gz file containing files/dirs to install. -SWUPDATE_FILES_TARGZ_FILE ?= "" - -# Initialize variable to store the files/folders that will be part of the SWUpdate package. -SWUPDATE_FILES_LIST ?= "" - -# Checks whether SWU update is based on files or not. -def update_based_on_files(d): - return str(d.getVar('SWUPDATE_FILES_TARGZ_FILE') != "" or d.getVar('SWUPDATE_FILES_LIST') != "").lower() - -# Variable that determines if SWU update is based on files or not. -SWUPDATE_IS_FILES_UPDATE = "${@update_based_on_files(d)}" diff --git a/meta-digi-dey/recipes-digi/swu-images/files/image_template_mmc b/meta-digi-dey/recipes-digi/swu-images/files/image_template_mmc index cbbe5d655..158806213 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/image_template_mmc +++ b/meta-digi-dey/recipes-digi/swu-images/files/image_template_mmc @@ -1,8 +1,8 @@ - { + { filename = "##IMG_NAME##"; device = "##DEV##"; type = "raw"; sha256 = "$swupdate_get_sha256(##IMG_NAME##)"; compressed = "zlib"; installed-directly = true; - } + } diff --git a/meta-digi-dey/recipes-digi/swu-images/files/image_template_nand b/meta-digi-dey/recipes-digi/swu-images/files/image_template_nand index cefb14271..1fa5cc8b9 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/image_template_nand +++ b/meta-digi-dey/recipes-digi/swu-images/files/image_template_nand @@ -1,7 +1,7 @@ - { + { filename = "##IMG_NAME##"; volume = "##DEV##"; type = "ubivol"; sha256 = "$swupdate_get_sha256(##IMG_NAME##)"; installed-directly = true; - } + } diff --git a/meta-digi-dey/recipes-digi/swu-images/files/sw-description-files_template b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-files_template index 3cd479c14..0931f303e 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/sw-description-files_template +++ b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-files_template @@ -1,7 +1,7 @@ software = { version = "@@DEY_FIRMWARE_VERSION@@"; - description = "@@DESCRIPTION@@"; + description = "@@SWUPDATE_DESCRIPTION@@"; @@SWUPDATE_STORAGE_TYPE@@ = { primary: { diff --git a/meta-digi-dey/recipes-digi/swu-images/files/sw-description-images_template b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-images_template index 8b7e7d2f3..0cc414a85 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/sw-description-images_template +++ b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-images_template @@ -1,7 +1,7 @@ software = { version = "@@DEY_FIRMWARE_VERSION@@"; - description = "@@DESCRIPTION@@"; + description = "@@SWUPDATE_DESCRIPTION@@"; @@SWUPDATE_STORAGE_TYPE@@ = { primary: { @@ -21,7 +21,7 @@ software = }, { name = "rootfstype" - value = "@@ROOTFS_TYPE@@" + value = "@@SWUPDATE_ROOTFS_TYPE@@" } ); } @@ -42,7 +42,7 @@ software = }, { name = "rootfstype" - value = "@@ROOTFS_TYPE@@" + value = "@@SWUPDATE_ROOTFS_TYPE@@" } ); } @@ -59,7 +59,7 @@ software = uboot: ( { name = "rootfstype" - value = "@@ROOTFS_TYPE@@" + value = "@@SWUPDATE_ROOTFS_TYPE@@" } ); } diff --git a/meta-digi-dey/recipes-digi/swu-images/swu.inc b/meta-digi-dey/recipes-digi/swu-images/swu.inc index 0e0a04fc2..1332116de 100644 --- a/meta-digi-dey/recipes-digi/swu-images/swu.inc +++ b/meta-digi-dey/recipes-digi/swu-images/swu.inc @@ -17,33 +17,21 @@ SRC_URI = " \ file://update_files.sh \ " -inherit swupdate swupdate-files-common - -IMAGE_DEPENDS = "${@get_baseimg_pn(d)}" - -IMG_NAME = "${IMAGE_DEPENDS}" - -# Determine the correct UBoot update script file to use depending on storage type. -SWUPDATE_UBOOT_SCRIPT = "${@oe.utils.conditional('STORAGE_MEDIA', 'mmc', 'swupdate_uboot_mmc.sh', 'swupdate_uboot_nand.sh', d)}" - -# Determine the storage type. -SWUPDATE_STORAGE_TYPE = "${@oe.utils.conditional('STORAGE_MEDIA', 'mmc', 'mmc', 'mtd', d)}" +inherit swupdate dey-swupdate-common # Avoid all 'SRC_URI' files to be included in the SWU image. Include only 'SWUPDATE_IMAGES' files and 'sw-description' (added by default). INHIBIT_SWUPDATE_ADD_SRC_URI = "true" +# Files to include in the SWU update package. SWUPDATE_IMAGES = " \ - ${@oe.utils.ifelse(d.getVar('SWUPDATE_IS_FILES_UPDATE') == 'true', '${SWUPDATE_FILES_TARGZ_FILE_NAME}', '${IMG_NAME}')} \ + ${@oe.utils.ifelse(d.getVar('SWUPDATE_IS_IMAGES_UPDATE') == 'true', '${IMG_NAME}', '')} \ + ${@oe.utils.ifelse(d.getVar('SWUPDATE_IS_FILES_UPDATE') == 'true', '${SWUPDATE_FILES_TARGZ_FILE_NAME}', '')} \ ${@oe.utils.ifelse(d.getVar('SWUPDATE_UBOOTIMG') == 'true', '${UBOOT_PREFIX}', '')} \ ${@oe.utils.ifelse(d.getVar('SWUPDATE_UBOOTIMG') == 'true', '${SWUPDATE_UBOOT_SCRIPT}', '')} \ + ${SWUPDATE_SCRIPT_NAME} \ " -DESCRIPTION = "${@oe.utils.ifelse(d.getVar('TRUSTFENCE_ENCRYPT_ROOTFS') == '1', 'Encrypted rootfs ${IMG_NAME} update', '${IMG_NAME} update')}" - -UBOOT_EXT ?= ".${UBOOT_SUFFIX}" - -UBOOTIMG_OFFSET ?= "${BOOTLOADER_SEEK_BOOT}" - +# Associate images and file types. python () { img_fstypes = d.getVar('BOOTFS_EXT') + " " + d.getVar('ROOTFS_EXT') d.setVarFlag("SWUPDATE_IMAGES_FSTYPES", d.getVar('IMG_NAME'), img_fstypes) @@ -52,35 +40,27 @@ python () { d.setVarFlag("SWUPDATE_IMAGES_FSTYPES", d.getVar('UBOOT_PREFIX'), uboot_fstypes) } +# Execute extra tasks before creating SWU update package. python do_swuimage:prepend() { import glob + import os.path + import shutil + # Set signing key for trustfence enabled updates. if (d.getVar('TRUSTFENCE_SIGN') == "1"): d.setVar('SWUPDATE_PRIVATE_KEY', glob.glob(d.getVar('SWUPDATE_PRIVATE_KEY_TEMPLATE'))[0]) + + # Copy script file. + updatescript = d.getVar('SWUPDATE_SCRIPT', True) + imgdeploydir = d.getVar('DEPLOY_DIR_IMAGE', True) + if "/" not in updatescript: + workdir = d.getVar('WORKDIR', True) + updatescript = os.path.join(workdir, updatescript) + if os.path.isfile(updatescript): + shutil.copyfile(updatescript, os.path.join(imgdeploydir, os.path.basename(updatescript))) } -def get_baseimg_pn(d): - file_name = d.getVar('PN') - return file_name[:file_name.find("-swu")] - -# Dual boot partition names for eMMC or MTD -BOOT_DEV_NAME_A ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p1', 'linux_a', d)}" -BOOT_DEV_NAME_B ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p2', 'linux_b', d)}" -ROOTFS_DEV_NAME_A ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p3', 'rootfs_a', d)}" -ROOTFS_DEV_NAME_B ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0p4', 'rootfs_b', d)}" - -ROOTFS_TYPE = "${@bb.utils.contains('IMAGE_FEATURES', 'read-only-rootfs', 'squashfs', '', d)}" - -# Image template based on storage type. -IMAGE_TEMPLATE_FILE = "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '${WORKDIR}/image_template_mmc', '${WORKDIR}/image_template_nand', d)}" - -# Update script. -SWUPDATE_SCRIPT ?= "${@oe.utils.vartrue('SWUPDATE_IS_FILES_UPDATE', '${WORKDIR}/update_files.sh', '${WORKDIR}/update_images.sh', d)}" -SWUPDATE_SCRIPT_NAME = "${@os.path.basename(d.getVar('SWUPDATE_SCRIPT'))}" -SWUPDATE_IMAGES += " ${SWUPDATE_SCRIPT_NAME}" - -do_unpack[postfuncs] += "fill_description" - +# Create and fill 'sw-description' file. fill_description() { if [ "${SWUPDATE_UBOOTIMG}" = "true" ]; then cp ${WORKDIR}/sw-description-uboot ${WORKDIR}/sw-description @@ -99,11 +79,6 @@ fill_description() { cp ${WORKDIR}/sw-description-images_template ${WORKDIR}/sw-description fi - # Copy update script. - if [ -f "${SWUPDATE_SCRIPT}" ]; then - cp "${SWUPDATE_SCRIPT}" "${DEPLOY_DIR_IMAGE}" - fi - if [ "${SWUPDATE_IS_FILES_UPDATE}" = "true" ]; then return 0 fi @@ -114,22 +89,22 @@ fill_description() { # Add primary bank images section for dual boot systems. printf "%s,\n%s\n" \ - "$(sed -e "s,##IMG_NAME##,${BOOT_IMAGE_NAME},g" -e "s,##DEV##,${BOOT_DEV_NAME_A},g" -e "/compressed/d" "${IMAGE_TEMPLATE_FILE}")" \ - "$(sed -e "s,##IMG_NAME##,${ROOTFS_IMAGE_NAME},g" -e "s,##DEV##,${ROOTFS_DEV_NAME_A},g" "${IMAGE_TEMPLATE_FILE}")" \ + "$(sed -e "s,##IMG_NAME##,${BOOT_IMAGE_NAME},g" -e "s,##DEV##,${BOOT_DEV_NAME_A},g" -e "/compressed/d" "${SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE}")" \ + "$(sed -e "s,##IMG_NAME##,${ROOTFS_IMAGE_NAME},g" -e "s,##DEV##,${ROOTFS_DEV_NAME_A},g" "${SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE}")" \ > images_temp.txt sed -i -e "/##IMAGES_PRIMARY##/r images_temp.txt" -e "/##IMAGES_PRIMARY##/d" "${WORKDIR}/sw-description" # Add secondary bank images section for dual boot systems. printf "%s,\n%s\n" \ - "$(sed -e "s,##IMG_NAME##,${BOOT_IMAGE_NAME},g" -e "s,##DEV##,${BOOT_DEV_NAME_B},g" -e "/compressed/d" "${IMAGE_TEMPLATE_FILE}")" \ - "$(sed -e "s,##IMG_NAME##,${ROOTFS_IMAGE_NAME},g" -e "s,##DEV##,${ROOTFS_DEV_NAME_B},g" "${IMAGE_TEMPLATE_FILE}")" \ + "$(sed -e "s,##IMG_NAME##,${BOOT_IMAGE_NAME},g" -e "s,##DEV##,${BOOT_DEV_NAME_B},g" -e "/compressed/d" "${SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE}")" \ + "$(sed -e "s,##IMG_NAME##,${ROOTFS_IMAGE_NAME},g" -e "s,##DEV##,${ROOTFS_DEV_NAME_B},g" "${SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE}")" \ > images_temp.txt sed -i -e "/##IMAGES_SECONDARY##/r images_temp.txt" -e "/##IMAGES_SECONDARY##/d" "${WORKDIR}/sw-description" # Add images section for single boot systems. printf "%s,\n%s\n" \ - "$(sed -e "s,##IMG_NAME##,${BOOT_IMAGE_NAME},g" -e "s,##DEV##,${BOOT_DEV_NAME},g" -e "/compressed/d" "${IMAGE_TEMPLATE_FILE}")" \ - "$(sed -e "s,##IMG_NAME##,${ROOTFS_IMAGE_NAME},g" -e "s,##DEV##,${ROOTFS_DEV_NAME_FINAL},g" "${IMAGE_TEMPLATE_FILE}")" \ + "$(sed -e "s,##IMG_NAME##,${BOOT_IMAGE_NAME},g" -e "s,##DEV##,${BOOT_DEV_NAME},g" -e "/compressed/d" "${SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE}")" \ + "$(sed -e "s,##IMG_NAME##,${ROOTFS_IMAGE_NAME},g" -e "s,##DEV##,${ROOTFS_DEV_NAME_FINAL},g" "${SWUPDATE_IMAGES_IMAGE_TEMPLATE_FILE}")" \ > images_temp.txt sed -i -e "/##IMAGES_SINGLE##/r images_temp.txt" -e "/##IMAGES_SINGLE##/d" "${WORKDIR}/sw-description" @@ -142,3 +117,4 @@ fill_description() { rm -f images_temp.txt } fill_description[dirs] = "${DEPLOY_DIR_IMAGE} ${WORKDIR}" +do_unpack[postfuncs] += "fill_description"