From ccc4680924236187f6469984337977650fd8dd2e Mon Sep 17 00:00:00 2001 From: Tatiana Leon Date: Tue, 21 Mar 2023 17:54:09 +0100 Subject: [PATCH] dualboot: update-firmware: new option to swap active system ('--swap-active-system') This allows to remove the script 'on-the-fly-swap-partition.sh'. https://onedigi.atlassian.net/browse/DEL-8399 Signed-off-by: Tatiana Leon --- .../recipes-digi/dualboot/dualboot.bb | 3 -- .../dualboot/on-the-fly-swap-partition.sh | 48 ------------------- .../dualboot/dualboot/update-firmware | 21 ++++++-- 3 files changed, 18 insertions(+), 54 deletions(-) delete mode 100644 meta-digi-dey/recipes-digi/dualboot/dualboot/on-the-fly-swap-partition.sh diff --git a/meta-digi-dey/recipes-digi/dualboot/dualboot.bb b/meta-digi-dey/recipes-digi/dualboot/dualboot.bb index 374a532c7..5437eadd1 100644 --- a/meta-digi-dey/recipes-digi/dualboot/dualboot.bb +++ b/meta-digi-dey/recipes-digi/dualboot/dualboot.bb @@ -11,7 +11,6 @@ SRC_URI = " \ file://dualboot-init \ file://update-firmware \ file://firmware-update-check.service \ - file://on-the-fly-swap-partition.sh \ " S = "${WORKDIR}" @@ -28,7 +27,6 @@ do_install() { install -d ${D}${bindir} install -m 0755 ${WORKDIR}/update-firmware ${D}${bindir} - install -m 0755 ${WORKDIR}/on-the-fly-swap-partition.sh ${D}${bindir} install -d ${D}${systemd_unitdir}/system/ install -m 0644 ${WORKDIR}/firmware-update-check.service ${D}${systemd_unitdir}/system/ @@ -65,7 +63,6 @@ FILES:${PN} += " \ ${sysconfdir}/dualboot-init \ ${sysconfdir}/init.d/dualboot-init \ ${bindir}/update-firmware \ - ${bindir}/on-the-fly-swap-partition.sh \ ${systemd_unitdir}/system/firmware-update-check.service \ ${@oe.utils.conditional('TRUSTFENCE_SIGN', '1', '${sysconfdir}/ssl/certs/key.pub', '', d)} \ " diff --git a/meta-digi-dey/recipes-digi/dualboot/dualboot/on-the-fly-swap-partition.sh b/meta-digi-dey/recipes-digi/dualboot/dualboot/on-the-fly-swap-partition.sh deleted file mode 100644 index 83d1f586a..000000000 --- a/meta-digi-dey/recipes-digi/dualboot/dualboot/on-the-fly-swap-partition.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -#=============================================================================== -# -# on-the-fly-swap-partition.sh -# -# Copyright (C) 2021-2022 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: On the fly script to swap active partition -# -#=============================================================================== - -ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" - -# Get current partition information so we can -# determine where to flash the images. -if [ "${ACTIVE_SYSTEM}" = "linux_a" ]; then - KERNELBOOT="linux_b" - ROOTFS="rootfs_b" -else - KERNELBOOT="linux_a" - ROOTFS="rootfs_a" -fi -if grep -qs environment /proc/mtd; then - fw_setenv mtdbootpart ${KERNELBOOT} - fw_setenv mtdrootfspart ${ROOTFS} - fw_setenv rootfsvol ${ROOTFS} - fw_setenv active_system ${KERNELBOOT} -else - # Get Boot partition device and index. - BOOT_DEV="$(fw_printenv -n mmcbootdev 2>/dev/null)" - - # get boot partition index - MMC_PART="$(ls -l /dev/disk/by-partlabel/ | grep -i ${KERNELBOOT} | awk '{print $11}' | sed -e 's/[../mmcblkp]//g' -e 's/^.//')" - - # search rootfs UUID - MMCROOT_PART="$(ls -l /dev/disk/by-partlabel/ | grep -i ${ROOTFS} | awk '{print $11}' | sed -e 's/[../mmcblkp]//g' -e 's/^.//')" - PART_UUID="$(ls -l /dev/disk/by-partuuid/ | grep -i mmcblk${BOOT_DEV}p${MMCROOT_PART} | awk '{print $9}')" - - fw_setenv mmcroot PARTUUID=${PART_UUID} - fw_setenv mmcpart ${MMC_PART} - fw_setenv active_system ${KERNELBOOT} -fi diff --git a/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware b/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware index eec6aad3e..1434d99dd 100755 --- a/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware +++ b/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware @@ -26,6 +26,7 @@ PUBLIC_KEY="/etc/ssl/certs/key.pub" ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" SHOW_ACTIVE_SYSTEM=0 SCRIPT_MODE=0 +SWAP_ACTIVE_SYSTEM=0 REBOOT=1 UPDATE_FILE="" ALT_BOOT="" @@ -42,6 +43,8 @@ Usage: ${SCRIPTNAME} [OPTIONS] .swu -a --active Show currently active system --no-reboot Do not reboot after update + --swap-active-system Swap active system block. + This option reboots the system, unless '--no-reboot' is specified. -v --verbose Enable verbosity -h --help Print help and exit @@ -59,12 +62,13 @@ show_active_system() { fi } +# $1: message to show reboot_system() { if [ ${REBOOT} -eq 1 ]; then - echo "Firmware update finished. Rebooting the system." + echo "${1}. Rebooting the system." reboot -f else - echo "Firmware update finished. Reboot the system to use the new version." + echo "${1}. Reboot the system to use the new version." fi } @@ -153,7 +157,7 @@ update_device() { if ! swap_active_system; then exit 1 fi - reboot_system + reboot_system "Firmware update finished" else echo "[ERROR] $? There was an error performing the update" fi @@ -165,6 +169,8 @@ while :; do ;; --no-reboot) REBOOT=0 ;; + --swap-active-system) SWAP_ACTIVE_SYSTEM=1 + ;; -s) SCRIPT_MODE=1 ;; -v|--verbose) VERBOSE="-v" @@ -192,6 +198,15 @@ else ALT_ROOTFS="rootfs_a" fi +# Swap active system. +if [ ${SWAP_ACTIVE_SYSTEM} -eq 1 ]; then + if ! swap_active_system; then + exit 1 + fi + reboot_system "Swapped active system to $(echo ${ALT_BOOT} | cut -d'_' -f2 | tr [:lower:] [:upper:])" + exit +fi + # Check update file parameter. if [ -z "${UPDATE_FILE}" ]; then echo "[ERROR] Update file not specified"