From f308ccfa6624473f7d3ee45e0e9511258a289b63 Mon Sep 17 00:00:00 2001 From: Francisco Gil Date: Thu, 17 Nov 2022 17:15:37 +0100 Subject: [PATCH] update-firmware: rename the firmware-update from recovery-utils There is a problem when building the SDK because two binaries have the same name (update-firmware) and makes the compilation to fail. Change the name to update-firmware.recovery and create a wrapper over the update-firmware to check if the system is not dual boot to call it. Rework the code to make it more reliable. Remove the umount of the alternative linux partition, now it is not needed because only the active linux partition is mounted now. Signed-off-by: Francisco Gil --- .../recovery-utils/recovery-reboot/Makefile | 2 +- .../dualboot/dualboot/dualboot-init | 44 +++++++++---------- .../dualboot/dualboot/update-firmware | 39 +++++++++------- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/recovery-reboot/Makefile b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/recovery-reboot/Makefile index b8b406071..f9251c34e 100644 --- a/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/recovery-reboot/Makefile +++ b/meta-digi-dey/recipes-core/recovery/recovery-utils/recovery-utils/recovery-reboot/Makefile @@ -40,7 +40,7 @@ all: $(PROGRAM) install: $(PROGRAM) install -d $(DESTDIR)/usr/bin install -m 0755 $(PROGRAM) $(DESTDIR)/usr/bin/ - ln -sf $(PROGRAM) $(DESTDIR)/usr/bin/update-firmware + ln -sf $(PROGRAM) $(DESTDIR)/usr/bin/update-firmware.recovery ln -sf $(PROGRAM) $(DESTDIR)/usr/bin/encrypt-partitions .PHONY: clean diff --git a/meta-digi-dey/recipes-digi/dualboot/dualboot/dualboot-init b/meta-digi-dey/recipes-digi/dualboot/dualboot/dualboot-init index 8ede937ab..1e4337891 100644 --- a/meta-digi-dey/recipes-digi/dualboot/dualboot/dualboot-init +++ b/meta-digi-dey/recipes-digi/dualboot/dualboot/dualboot-init @@ -14,37 +14,37 @@ #=============================================================================== dualboot_init () { - if [ "$(fw_printenv -n dualboot 2>/dev/null)" = "yes" ]; then - echo -n "Starting dualboot check: " - ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" - if [ -z "${ACTIVE_SYSTEM}" ]; then - if grep -qs environment /proc/mtd; then - MTD_BOOT_PART="$(fw_printenv -n mtdbootpart 2>/dev/null)" - fw_setenv active_system "${MTD_BOOT_PART}" - else - BOOT_PART="$(fw_printenv -n mmcpart 2>/dev/null)" - BOOT_DEV="$(fw_printenv -n mmcbootdev 2>/dev/null)" - CURRENT_PART="$(sed -ne 's,PARTNAME=,,g;T;p' /sys/class/block/mmcblk"${BOOT_DEV}"p"${BOOT_PART}"/uevent)" - fw_setenv active_system "${CURRENT_PART}" - fi + ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" + if [ -z "${ACTIVE_SYSTEM}" ]; then + if grep -qs environment /proc/mtd; then + MTD_BOOT_PART="$(fw_printenv -n mtdbootpart 2>/dev/null)" + fw_setenv active_system "${MTD_BOOT_PART}" + else + BOOT_PART="$(fw_printenv -n mmcpart 2>/dev/null)" + BOOT_DEV="$(fw_printenv -n mmcbootdev 2>/dev/null)" + CURRENT_PART="$(sed -ne 's,PARTNAME=,,g;T;p' /sys/class/block/mmcblk"${BOOT_DEV}"p"${BOOT_PART}"/uevent)" + fw_setenv active_system "${CURRENT_PART}" fi + fi - ISUPGRADING="$(fw_printenv -n upgrade_available 2>/dev/null)" + ISUPGRADING="$(fw_printenv -n upgrade_available 2>/dev/null)" - if [ "$ISUPGRADING" = "1" ]; then - BOOTCOUNT="$(fw_printenv -n bootcount 2>/dev/null)" - if [ "${BOOTCOUNT}" -lt 3 ]; then - fw_setenv upgrade_available - fw_setenv bootcount 0 - fi + if [ "$ISUPGRADING" = "1" ]; then + BOOTCOUNT="$(fw_printenv -n bootcount 2>/dev/null)" + if [ "${BOOTCOUNT}" -lt 3 ]; then + fw_setenv upgrade_available + fw_setenv bootcount 0 fi - echo "done." fi } case "$1" in start) - dualboot_init + if [ "$(fw_printenv -n dualboot 2>/dev/null)" = "yes" ]; then + echo -n "Starting dualboot check: " + dualboot_init + echo "done." + fi ;; stop) ;; diff --git a/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware b/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware index 0ca753613..f5019e468 100755 --- a/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware +++ b/meta-digi-dey/recipes-digi/dualboot/dualboot/update-firmware @@ -15,7 +15,12 @@ # #=============================================================================== -SCRIPTNAME="$(basename $(readlink -f ${0}))" + +if [ "$(fw_printenv -n dualboot 2>/dev/null)" != "yes" ]; then + exec update-firmware.recovery "$@" +fi + +SCRIPTNAME="$(basename "$(readlink -f "${0}")")" VERBOSE="" PUBLIC_KEY="/etc/ssl/certs/key.pub" ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" @@ -63,14 +68,9 @@ if [ -z "${UPDATE_FILE}" ]; then fi # Check if the rootfs is ubifs to determine if it is a nand or emmc device -PARTTABLE="/proc/mounts" -NANDROOTFS="$(sed -ne "s/\(rootfs\).*\.*/\1/g;T;p" ${PARTTABLE} 2>/dev/null)" +NANDROOTFS="$(sed -ne "s/\(rootfs\).*\.*/\1/g;T;p" /proc/mounts 2>/dev/null)" if [ -z "${NANDROOTFS}" ]; then - # Get Boot partition device and index. - BOOT_PART="$(fw_printenv -n mmcpart 2>/dev/null)" - BOOT_DEV="$(fw_printenv -n mmcbootdev 2>/dev/null)" - # Get current partition information so we can # determine where to flash the images. if [ "${ACTIVE_SYSTEM}" = "linux_a" ]; then @@ -85,12 +85,22 @@ if [ -z "${NANDROOTFS}" ]; then IMAGE_SET="mmc,primary" fi - # 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/^.//')" + # get boot and rootfs partition index + MMC_PART="$(realpath /dev/disk/by-partlabel/${KERNELBOOT} | grep -o '[[:digit:]]\+$')" # 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}')" + MMCROOT_DEV="$(realpath /dev/disk/by-partlabel/${ROOTFS})" + for uuid in /dev/disk/by-partuuid/*; do + if [ "$(realpath "${uuid}")" = "${MMCROOT_DEV}" ]; then + PART_UUID="$(basename "${uuid}")" + break + fi + done + + if [ -z "${MMC_PART}" ] || [ -z "${PART_UUID}" ]; then + echo "[ERROR] detecting partitions to update." + exit + fi echo "" echo "Updating '${IMAGE_SET}' image set from '${UPDATE_FILE}'..." @@ -99,8 +109,8 @@ if [ -z "${NANDROOTFS}" ]; then # Execute the update. swupdate ${VERBOSE} -i "${UPDATE_FILE}" -e "${IMAGE_SET}" if [ "$?" = "0" ]; then - fw_setenv mmcroot PARTUUID=${PART_UUID} - fw_setenv mmcpart ${MMC_PART} + fw_setenv mmcroot "PARTUUID=${PART_UUID}" + fw_setenv mmcpart "${MMC_PART}" fw_setenv active_system ${KERNELBOOT} fw_setenv bootcount 0 echo "Firmware update finished; Rebooting system." @@ -127,9 +137,6 @@ else echo "Updating '${IMAGE_SET}' image set from '${UPDATE_FILE}'..." echo "" - # Umount the partition before the update. - umount /mnt/${KERNELBOOT} - # Execute the update. if [ -f "${PUBLIC_KEY}" ]; then swupdate ${VERBOSE} -i "${UPDATE_FILE}" -e "${IMAGE_SET}" -k "${PUBLIC_KEY}"