From: Hugo Villeneuve Date: Fri, 30 Dec 2022 05:00:01 +0000 (-0500) Subject: Add swupdate images X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=2d47a6a2cdfbf17288f1eff06033371b6759b5ed;p=yocto%2Fmeta-hvmpd.git Add swupdate images --- diff --git a/recipes-core/images/image-hvmpd-dev-update.bb b/recipes-core/images/image-hvmpd-dev-update.bb new file mode 100644 index 0000000..f874b45 --- /dev/null +++ b/recipes-core/images/image-hvmpd-dev-update.bb @@ -0,0 +1,8 @@ +SUMMARY = "HV MPD SWUpdate development image" + +# Image(s) to build before building swupdate image +IMAGE_DEPENDS = "image-hvmpd-dev" + +require update-common.inc + +SWUPDATE_IMAGES_FSTYPES[image-hvmpd-dev] = ".tar.gz" diff --git a/recipes-core/images/image-hvmpd-prod-update.bb b/recipes-core/images/image-hvmpd-prod-update.bb new file mode 100644 index 0000000..754da4d --- /dev/null +++ b/recipes-core/images/image-hvmpd-prod-update.bb @@ -0,0 +1,8 @@ +SUMMARY = "HV MPD SWUpdate production image" + +# Image(s) to build before building swupdate image +IMAGE_DEPENDS = "image-hvmpd-prod" + +require update-common.inc + +SWUPDATE_IMAGES_FSTYPES[image-hvmpd-prod] = ".tar.gz" diff --git a/recipes-core/images/update-common.inc b/recipes-core/images/update-common.inc new file mode 100644 index 0000000..ed80f58 --- /dev/null +++ b/recipes-core/images/update-common.inc @@ -0,0 +1,15 @@ +LICENSE = "CLOSED" + +FILESEXTRAPATHS:prepend := "${THISDIR}/update:" + +SRC_URI = " \ + file://sw-description \ + file://update.sh \ +" + +# Image(s) and files that will be included in the .swu image +SWUPDATE_IMAGES = "${IMAGE_DEPENDS}" + +UBOOT_PART_VAR ?= "mmcpart" + +inherit swupdate diff --git a/recipes-core/images/update/sw-description b/recipes-core/images/update/sw-description new file mode 100644 index 0000000..78d91e9 --- /dev/null +++ b/recipes-core/images/update/sw-description @@ -0,0 +1,83 @@ +software = { + version = "@@DISTRO_VERSION@@"; + description = "Firmware update description for @@MACHINE@@"; + + @@MACHINE@@ = { + hardware-compatibility: [ "revA" ]; + stable: { + bootenv-common: ( + { + name = "bootcount"; + value = "0"; + }, + { + name = "upgrade_available"; + value = "1"; + }, + ); + + rootfsA: { + images: ( + { + filename = "@@IMAGE_DEPENDS@@-@@MACHINE@@@@SWUPDATE_IMAGES_FSTYPES[@@IMAGE_DEPENDS@@]@@"; + type = "archive"; + compressed = "zlib"; + preserve-attributes = true; + sha256 = "$swupdate_get_sha256(@@IMAGE_DEPENDS@@-@@MACHINE@@@@SWUPDATE_IMAGES_FSTYPES[@@IMAGE_DEPENDS@@]@@)"; + path = "/"; /* Destination path when decompressing. */ + filesystem = "ext4"; + device = "@@ROOT_PARENT_DEV@@@@ROOT_PART_PREFIX@@@@ROOT_PART_A_ID@@"; + } + ); + scripts: ( + { + filename = "update.sh"; + type = "shellscript"; + data = "@@ROOT_PART_PREFIX@@@@ROOT_PART_A_ID@@"; /* Destination partition ID */ + sha256 = "$swupdate_get_sha256(update.sh)"; + } + ); + bootenv: ( + { + ref = "#./../bootenv-common"; + }, + { + name = "@@UBOOT_PART_VAR@@"; + value = "@@ROOT_PART_A_ID@@"; + } + ); + }; + rootfsB: { + images: ( + { + filename = "@@IMAGE_DEPENDS@@-@@MACHINE@@@@SWUPDATE_IMAGES_FSTYPES[@@IMAGE_DEPENDS@@]@@"; + type = "archive"; + compressed = "zlib"; + preserve-attributes = true; + sha256 = "$swupdate_get_sha256(@@IMAGE_DEPENDS@@-@@MACHINE@@@@SWUPDATE_IMAGES_FSTYPES[@@IMAGE_DEPENDS@@]@@)"; + path = "/"; /* Destination path when decompressing. */ + filesystem = "ext4"; + device = "@@ROOT_PARENT_DEV@@@@ROOT_PART_PREFIX@@@@ROOT_PART_B_ID@@"; + } + ); + scripts: ( + { + filename = "update.sh"; + type = "shellscript"; + data = "@@ROOT_PART_PREFIX@@@@ROOT_PART_B_ID@@"; /* Destination partition ID */ + sha256 = "$swupdate_get_sha256(update.sh)"; + } + ); + bootenv: ( + { + ref = "#./../bootenv-common"; + }, + { + name = "@@UBOOT_PART_VAR@@"; + value = "@@ROOT_PART_B_ID@@"; + } + ); + }; + }; + }; +} diff --git a/recipes-core/images/update/update.sh b/recipes-core/images/update/update.sh new file mode 100644 index 0000000..6efa218 --- /dev/null +++ b/recipes-core/images/update/update.sh @@ -0,0 +1,90 @@ +#!/bin/sh +set -e + +# Shell scripts are called via system command. SWUpdate scans for all scripts +# and calls them before and after installing the images. SWUpdate passes +# ‘preinst’ or ‘postinst’ as first argument to the script. If the data attribute +# is defined, its value is passed as the last argument(s) to the script. + +FSTYPE="ext4" + +echo "${0}: arguments = \"${*}\"" + +if [ $# -lt 2 ]; then + exit 1; +fi + +# L'environnement U-Boot doit être valide pour utiliser ce script. +# Après la programmation initiale avec uuu, il faut effectuer la sauvegarde +# de l'environnement en mémoire non-volatile (ex: eMMC) dans U-boot avec +# 'saveenv'. Sinon, fw_saveenv va utiliser l'environnement par défaut contenu +# dans /etc/u-boot-initial-env +if fw_printenv 2>&1 | grep -q 'Cannot read environment'; then + echo "Warning: U-Boot environment cannot be read. Make sure you save the" + echo " default environment to flash using these U-Boot commands:" + echo " $> env default -a" + echo " $> saveenv" +fi + +do_preinst() +{ + # Find internal parent kernel device name of rootfs. + # For example: + # - /dev/sda1 --> /dev/sda + # - /dev/mmcblk2p2 --> /dev/mmcblk2 + disk="/dev/$(lsblk -ndo pkname $(findmnt -n -o SOURCE /))" + + if [ ! -b "${disk}" ]; then + echo "Error: disk \"${disk}\" not found" + exit 1 + fi + + update_dev="${disk}${next_part}" + + if [ ! -b "${update_dev}" ]; then + echo "Error: destination partition \"${update_dev}\" not found" + exit 1 + fi + + echo "${0}: destination device = ${update_dev}" + + # Create temporary mount point: + tmp_file=$(mktemp -q -d /tmp/swupdate-mount.XXXXXX) + if [ ${?} -ne 0 ]; then + echo "Error: cannot create temporary file" + exit 1 + fi + + # Mount update partition: + mount -t ${FSTYPE} ${update_dev} ${tmp_file} + + # Remove old data: + echo "${0}: erasing old data..." + rm -rf ${tmp_file}/* + + # Finish + umount ${tmp_file} + rmdir ${tmp_file} + + exit 0 +} + +do_postinst() +{ + exit 0 +} + +next_part=${2} + +case "$1" in + preinst) + do_preinst + ;; + postinst) + do_postinst + ;; + *) + echo "unsupported install mode: \"${1}\"" + exit 1 + ;; +esac