From 4395fa1f119504d6aa3bb4cb5ce8c1ce67ec61d3 Mon Sep 17 00:00:00 2001 From: David Escalona Date: Fri, 30 Jun 2023 11:41:03 +0200 Subject: [PATCH] meta-digi-dey: swupdate-images: add SWUpdate script support Enable scripting support during the installation of system images with SWU. A new shell script is included by default in all the SWU update packages that will be executed just before the update starts and just after it finishes. The script is empty and contains two place-holders that will be called in the two scenarios mentioned before. Users can customize this script to execute specific actions based on their final product needs or provide their own one by setting its location in the 'SWUPDATE_SCRIPT' variable. While on it, rename the 'sw-description_template' file to 'sw-description-images_template' as it is more accurate with the update mechanism it is used for. Signed-off-by: David Escalona --- ...emplate => sw-description-images_template} | 18 +++++++++ .../swu-images/files/update_images.sh | 39 +++++++++++++++++++ meta-digi-dey/recipes-digi/swu-images/swu.inc | 15 ++++++- 3 files changed, 70 insertions(+), 2 deletions(-) rename meta-digi-dey/recipes-digi/swu-images/files/{sw-description_template => sw-description-images_template} (69%) create mode 100755 meta-digi-dey/recipes-digi/swu-images/files/update_images.sh 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-images_template similarity index 69% rename from meta-digi-dey/recipes-digi/swu-images/files/sw-description_template rename to meta-digi-dey/recipes-digi/swu-images/files/sw-description-images_template index c6bcca558..8b7e7d2f3 100644 --- a/meta-digi-dey/recipes-digi/swu-images/files/sw-description_template +++ b/meta-digi-dey/recipes-digi/swu-images/files/sw-description-images_template @@ -8,6 +8,12 @@ software = images: ( ##IMAGES_PRIMARY## ); + scripts: ( + { + filename = "@@SWUPDATE_SCRIPT_NAME@@"; + type = "shellscript"; + } + ); uboot: ( { name = "upgrade_available"; @@ -23,6 +29,12 @@ software = images: ( ##IMAGES_SECONDARY## ); + scripts: ( + { + filename = "@@SWUPDATE_SCRIPT_NAME@@"; + type = "shellscript"; + } + ); uboot: ( { name = "upgrade_available"; @@ -38,6 +50,12 @@ software = images: ( ##IMAGES_SINGLE## ); + scripts: ( + { + filename = "@@SWUPDATE_SCRIPT_NAME@@"; + type = "shellscript"; + } + ); uboot: ( { name = "rootfstype" diff --git a/meta-digi-dey/recipes-digi/swu-images/files/update_images.sh b/meta-digi-dey/recipes-digi/swu-images/files/update_images.sh new file mode 100755 index 000000000..5219ebc54 --- /dev/null +++ b/meta-digi-dey/recipes-digi/swu-images/files/update_images.sh @@ -0,0 +1,39 @@ +#!/bin/sh +#=============================================================================== +# +# update_images +# +# Copyright (C) 2023 by Digi International Inc. +# All rights reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published by +# the Free Software Foundation. +# +# +# !Description: SWU update images script +# +#=============================================================================== + +# Sanity check. This script should be always executed with at least one argument. +if [ $# -lt 1 ]; then + exit 1; +fi + +# Called just before installation process starts. +if [ "${1}" = "preinst" ]; then + : + + # TODO: Execute custom code here. For example: + # - Mount additional devices/partitions. + # - Stop services/process before installing files. +fi + +# Called just after installation process ends. +if [ "${1}" = "postinst" ]; then + : + + # TODO: Execute custom code here. For example: + # - Clean files/directories. + # - Post-process files. +fi diff --git a/meta-digi-dey/recipes-digi/swu-images/swu.inc b/meta-digi-dey/recipes-digi/swu-images/swu.inc index 2e022730e..e5cc9e701 100644 --- a/meta-digi-dey/recipes-digi/swu-images/swu.inc +++ b/meta-digi-dey/recipes-digi/swu-images/swu.inc @@ -6,12 +6,13 @@ LICENSE = "GPL-2.0-only" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6" SRC_URI = " \ - file://sw-description_template \ + file://sw-description-images_template \ file://sw-description-uboot \ file://swupdate_uboot_nand.sh \ file://swupdate_uboot_mmc.sh \ file://image_template_mmc \ file://image_template_nand \ + file://update_images.sh \ " inherit swupdate @@ -71,6 +72,11 @@ ROOTFS_TYPE = "${@bb.utils.contains('IMAGE_FEATURES', 'read-only-rootfs', 'squas # 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 ?= "${WORKDIR}/update_images.sh" +SWUPDATE_SCRIPT_NAME = "${@os.path.basename(d.getVar('SWUPDATE_SCRIPT'))}" +SWUPDATE_IMAGES += " ${SWUPDATE_SCRIPT_NAME}" + do_unpack[postfuncs] += "fill_description" fill_description() { @@ -86,7 +92,12 @@ fill_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 + 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 # Build image names.