From a04af0cbc1d1b9e3882695705938a171f6c9e779 Mon Sep 17 00:00:00 2001 From: David Escalona Date: Thu, 1 Jun 2023 17:25:37 +0200 Subject: [PATCH] meta-digi-dey: swu-images: simplify sw-description file The fact of including both storage types (mtd and mmc) in the same 'sw-description' file is not providing any kind of benefit. Instead, it makes the file larger, complex and harder to maintain. Additionally, most of the images entries share the same structure and contents, changing only names and mount points. This commit simplifies the 'sw-description' file by configuring the storage type and the images to include in the SWU package at build time, using a generic 'sw-description' template and template files for 'mmc' and 'mtd' images. While on it, use the new 'DEY_FIRMWARE_VERSION' variable for SWU package version and fix the recipe to not include all 'SRC_URI' files in the SWU update image, but only the required files for the update. Also, make use of variable substitution provided by SWU class in the 'sw-description' file. Note: SWU U-Boot update will be broken after this change. Waiting for official support with a robust implementation. https://onedigi.atlassian.net/browse/DEL-8537 https://onedigi.atlassian.net/browse/DEL-8538 Signed-off-by: David Escalona --- .../swu-images/files/image_template_mmc | 8 + .../swu-images/files/image_template_nand | 7 + .../swu-images/files/sw-description | 167 ------------------ .../swu-images/files/sw-description-uboot | 2 +- .../swu-images/files/sw-description_template | 52 ++++++ meta-digi-dey/recipes-digi/swu-images/swu.inc | 71 +++++--- 6 files changed, 119 insertions(+), 188 deletions(-) create mode 100644 meta-digi-dey/recipes-digi/swu-images/files/image_template_mmc create mode 100644 meta-digi-dey/recipes-digi/swu-images/files/image_template_nand delete mode 100644 meta-digi-dey/recipes-digi/swu-images/files/sw-description create mode 100644 meta-digi-dey/recipes-digi/swu-images/files/sw-description_template 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 new file mode 100644 index 000000000..cbbe5d655 --- /dev/null +++ b/meta-digi-dey/recipes-digi/swu-images/files/image_template_mmc @@ -0,0 +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 new file mode 100644 index 000000000..cefb14271 --- /dev/null +++ b/meta-digi-dey/recipes-digi/swu-images/files/image_template_nand @@ -0,0 +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 b/meta-digi-dey/recipes-digi/swu-images/files/sw-description deleted file mode 100644 index 8d0af5f13..000000000 --- a/meta-digi-dey/recipes-digi/swu-images/files/sw-description +++ /dev/null @@ -1,167 +0,0 @@ -software = -{ - version = "##SW_VERSION##"; - description = "##DESCRIPTION##"; - - mmc = { - primary: { - images: ( - { - filename = "##BOOTIMG_NAME##"; - device = "##BOOT_DEV_A##"; - type = "raw"; - sha256 = "$swupdate_get_sha256(##BOOTIMG_NAME##)"; - installed-directly = true; - }, - { - filename = "##ROOTIMG_NAME##"; - device = "##ROOTFS_DEV_A##"; - type = "raw"; - sha256 = "$swupdate_get_sha256(##ROOTIMG_NAME##)"; - compressed = "zlib"; - installed-directly = true; - } - ); - uboot: ( - { - name = "upgrade_available"; - value = "1"; - }, - { - name = "rootfstype" - value = "##ROOTFS_TYPE##" - } - ); - } - secondary: { - images: ( - { - filename = "##BOOTIMG_NAME##"; - device = "##BOOT_DEV_B##"; - type = "raw"; - sha256 = "$swupdate_get_sha256(##BOOTIMG_NAME##)"; - installed-directly = true; - }, - { - filename = "##ROOTIMG_NAME##"; - device = "##ROOTFS_DEV_B##"; - type = "raw"; - sha256 = "$swupdate_get_sha256(##ROOTIMG_NAME##)"; - compressed = "zlib"; - installed-directly = true; - } - ); - uboot: ( - { - name = "upgrade_available"; - value = "1"; - }, - { - name = "rootfstype" - value = "##ROOTFS_TYPE##" - } - ); - } - single: { - images: ( - { - filename = "##BOOTIMG_NAME##"; - device = "##BOOT_DEV##"; - type = "raw"; - sha256 = "$swupdate_get_sha256(##BOOTIMG_NAME##)"; - installed-directly = true; - }, - { - filename = "##ROOTIMG_NAME##"; - device = "##ROOTFS_DEV##"; - type ="raw"; - sha256 = "$swupdate_get_sha256(##ROOTIMG_NAME##)"; - compressed = "zlib"; - installed-directly = true; - } - ); - } - platform = { - ref = "#./single"; - } - } - mtd = { - primary: { - images: ( - { - filename = "##BOOTIMG_NAME##"; - volume = "##BOOT_DEV_A##"; - type = "ubivol"; - sha256 = "$swupdate_get_sha256(##BOOTIMG_NAME##)"; - installed-directly = true; - }, - { - filename = "##ROOTIMG_NAME##"; - volume = "##ROOTFS_DEV_A##"; - type = "ubivol"; - sha256 = "$swupdate_get_sha256(##ROOTIMG_NAME##)"; - installed-directly = true; - } - ); - uboot: ( - { - name = "upgrade_available"; - value = "1"; - }, - { - name = "rootfstype" - value = "##ROOTFS_TYPE##" - } - ); - } - secondary: { - images: ( - { - filename = "##BOOTIMG_NAME##"; - volume = "##BOOT_DEV_B##"; - type = "ubivol"; - sha256 = "$swupdate_get_sha256(##BOOTIMG_NAME##)"; - installed-directly = true; - }, - { - filename = "##ROOTIMG_NAME##"; - volume = "##ROOTFS_DEV_B##"; - type = "ubivol"; - sha256 = "$swupdate_get_sha256(##ROOTIMG_NAME##)"; - installed-directly = true; - } - ); - uboot: ( - { - name = "upgrade_available"; - value = "1"; - }, - { - name = "rootfstype" - value = "##ROOTFS_TYPE##" - } - ); - } - single: { - images: ( - { - filename = "##BOOTIMG_NAME##"; - volume = "##BOOT_DEV##"; - type = "ubivol"; - sha256 = "$swupdate_get_sha256(##BOOTIMG_NAME##)"; - installed-directly = true; - }, - { - filename = "##ROOTIMG_NAME##"; - volume = "##ROOTFS_DEV##"; - type ="ubivol"; - sha256 = "$swupdate_get_sha256(##ROOTIMG_NAME##)"; - installed-directly = true; - } - ); - } - platform = { - ref = "#./single"; - } - }; -} diff --git a/meta-digi-dey/recipes-digi/swu-images/files/sw-description-uboot b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-uboot index 6270310d6..c72e564ba 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/sw-description-uboot +++ b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-uboot @@ -1,6 +1,6 @@ software = { - version = "##SW_VERSION##"; + version = "##FW_VERSION##"; description = "##DESCRIPTION##"; mmc = { diff --git a/meta-digi-dey/recipes-digi/swu-images/files/sw-description_template b/meta-digi-dey/recipes-digi/swu-images/files/sw-description_template new file mode 100644 index 000000000..c6bcca558 --- /dev/null +++ b/meta-digi-dey/recipes-digi/swu-images/files/sw-description_template @@ -0,0 +1,52 @@ +software = +{ + version = "@@DEY_FIRMWARE_VERSION@@"; + description = "@@DESCRIPTION@@"; + + @@SWUPDATE_STORAGE_TYPE@@ = { + primary: { + images: ( + ##IMAGES_PRIMARY## + ); + uboot: ( + { + name = "upgrade_available"; + value = "1"; + }, + { + name = "rootfstype" + value = "@@ROOTFS_TYPE@@" + } + ); + } + secondary: { + images: ( + ##IMAGES_SECONDARY## + ); + uboot: ( + { + name = "upgrade_available"; + value = "1"; + }, + { + name = "rootfstype" + value = "@@ROOTFS_TYPE@@" + } + ); + } + single: { + images: ( + ##IMAGES_SINGLE## + ); + uboot: ( + { + name = "rootfstype" + value = "@@ROOTFS_TYPE@@" + } + ); + } + platform = { + ref = "#./single"; + } + }; +} diff --git a/meta-digi-dey/recipes-digi/swu-images/swu.inc b/meta-digi-dey/recipes-digi/swu-images/swu.inc index 444615d1e..2e022730e 100644 --- a/meta-digi-dey/recipes-digi/swu-images/swu.inc +++ b/meta-digi-dey/recipes-digi/swu-images/swu.inc @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2022, Digi International Inc. +# Copyright (C) 2016-2023, Digi International Inc. SUMMARY = "Generate update package for SWUpdate" SECTION = "base" @@ -6,10 +6,12 @@ LICENSE = "GPL-2.0-only" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6" SRC_URI = " \ - file://sw-description \ + file://sw-description_template \ file://sw-description-uboot \ file://swupdate_uboot_nand.sh \ file://swupdate_uboot_mmc.sh \ + file://image_template_mmc \ + file://image_template_nand \ " inherit swupdate @@ -18,20 +20,27 @@ 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)}" + +# 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" + SWUPDATE_IMAGES = " \ ${IMG_NAME} \ ${@oe.utils.ifelse(d.getVar('SWUPDATE_UBOOTIMG') == 'true', '${UBOOT_PREFIX}', '')} \ + ${@oe.utils.ifelse(d.getVar('SWUPDATE_UBOOTIMG') == 'true', '${SWUPDATE_UBOOT_SCRIPT}', '')} \ " -SOFTWARE_VERSION ?= "0.0.1" 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}" -SWUPDATE_STORAGE_MEDIA = "${@oe.utils.conditional('STORAGE_MEDIA', 'mmc', 'swupdate_uboot_mmc.sh', 'swupdate_uboot_nand.sh', d)}" - python () { img_fstypes = d.getVar('BOOTFS_EXT') + " " + d.getVar('ROOTFS_EXT') d.setVarFlag("SWUPDATE_IMAGES_FSTYPES", d.getVar('IMG_NAME'), img_fstypes) @@ -51,7 +60,6 @@ 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)}" @@ -59,35 +67,58 @@ ROOTFS_DEV_NAME_A ?= "${@bb.utils.contains('STORAGE_MEDIA', 'mmc', '/dev/mmcblk0 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)}" + do_unpack[postfuncs] += "fill_description" fill_description() { if [ "${SWUPDATE_UBOOTIMG}" = "true" ]; then cp ${WORKDIR}/sw-description-uboot ${WORKDIR}/sw-description + cp ${WORKDIR}/${SWUPDATE_UBOOT_SCRIPT} ${DEPLOY_DIR_IMAGE}/${SWUPDATE_UBOOT_SCRIPT} if [ "${TRUSTFENCE_DEK_PATH}" != "0" ] && [ "${TRUSTFENCE_DEK_PATH}" != "default" ]; then sed -i -e "s,##UBOOTIMG_ENC##,enc,g" "${WORKDIR}/sw-description" else sed -i -e "s,##UBOOTIMG_ENC##,normal,g" "${WORKDIR}/sw-description" fi sed -i -e "s,##UBOOTIMG_NAME##,${UBOOT_PREFIX}-${MACHINE}${UBOOT_EXT},g" "${WORKDIR}/sw-description" - sed -i -e "s,##SWUPDATE_UBOOT_SCRIPT##,${SWUPDATE_STORAGE_MEDIA},g" "${WORKDIR}/sw-description" + sed -i -e "s,##SWUPDATE_UBOOT_SCRIPT##,${SWUPDATE_UBOOT_SCRIPT},g" "${WORKDIR}/sw-description" sed -i -e "s,##UBOOTIMG_OFFSET##,${UBOOTIMG_OFFSET},g" "${WORKDIR}/sw-description" + else + cp ${WORKDIR}/sw-description_template ${WORKDIR}/sw-description fi - sed -i -e "s,##BOOTIMG_NAME##,${IMG_NAME}-${MACHINE}${BOOTFS_EXT},g" "${WORKDIR}/sw-description" - sed -i -e "s,##BOOT_DEV##,${BOOT_DEV_NAME},g" "${WORKDIR}/sw-description" - sed -i -e "s,##ROOTIMG_NAME##,${IMG_NAME}-${MACHINE}${ROOTFS_EXT},g" "${WORKDIR}/sw-description" - sed -i -e "s,##ROOTFS_DEV##,${ROOTFS_DEV_NAME_FINAL},g" "${WORKDIR}/sw-description" - sed -i -e "s,##SW_VERSION##,${SOFTWARE_VERSION},g" "${WORKDIR}/sw-description" - sed -i -e "s,##DESCRIPTION##,${DESCRIPTION},g" "${WORKDIR}/sw-description" - # Dualboot description - sed -i -e "s,##BOOT_DEV_A##,${BOOT_DEV_NAME_A},g" "${WORKDIR}/sw-description" - sed -i -e "s,##BOOT_DEV_B##,${BOOT_DEV_NAME_B},g" "${WORKDIR}/sw-description" - sed -i -e "s,##ROOTFS_DEV_A##,${ROOTFS_DEV_NAME_A},g" "${WORKDIR}/sw-description" - sed -i -e "s,##ROOTFS_DEV_B##,${ROOTFS_DEV_NAME_B},g" "${WORKDIR}/sw-description" + # Build image names. + BOOT_IMAGE_NAME="${IMG_NAME}-${MACHINE}${BOOTFS_EXT}" + ROOTFS_IMAGE_NAME="${IMG_NAME}-${MACHINE}${ROOTFS_EXT}" + + # 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}")" \ + > 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}")" \ + > 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}")" \ + > images_temp.txt + sed -i -e "/##IMAGES_SINGLE##/r images_temp.txt" -e "/##IMAGES_SINGLE##/d" "${WORKDIR}/sw-description" + + # Remove 'compressed' flag for read-only file systems as they use 'squashfs' images. if [ -n "${@bb.utils.contains('IMAGE_FEATURES', 'read-only-rootfs', '1', '', d)}" ]; then - sed -i '/compressed/d' "${WORKDIR}/sw-description" + sed -i -e "/compressed/d" "${WORKDIR}/sw-description" fi - sed -i -e "s,##ROOTFS_TYPE##,${ROOTFS_TYPE},g" "${WORKDIR}/sw-description" + # Clean dir. + rm -f images_temp.txt }