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 <francisco.gilmartinez@digi.com>
This commit is contained in:
Francisco Gil 2022-11-17 17:15:37 +01:00
parent cae4c1f1dc
commit f308ccfa66
3 changed files with 46 additions and 39 deletions

View File

@ -40,7 +40,7 @@ all: $(PROGRAM)
install: $(PROGRAM) install: $(PROGRAM)
install -d $(DESTDIR)/usr/bin install -d $(DESTDIR)/usr/bin
install -m 0755 $(PROGRAM) $(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 ln -sf $(PROGRAM) $(DESTDIR)/usr/bin/encrypt-partitions
.PHONY: clean .PHONY: clean

View File

@ -14,37 +14,37 @@
#=============================================================================== #===============================================================================
dualboot_init () { dualboot_init () {
if [ "$(fw_printenv -n dualboot 2>/dev/null)" = "yes" ]; then ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)"
echo -n "Starting dualboot check: " if [ -z "${ACTIVE_SYSTEM}" ]; then
ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" if grep -qs environment /proc/mtd; then
if [ -z "${ACTIVE_SYSTEM}" ]; then MTD_BOOT_PART="$(fw_printenv -n mtdbootpart 2>/dev/null)"
if grep -qs environment /proc/mtd; then fw_setenv active_system "${MTD_BOOT_PART}"
MTD_BOOT_PART="$(fw_printenv -n mtdbootpart 2>/dev/null)" else
fw_setenv active_system "${MTD_BOOT_PART}" BOOT_PART="$(fw_printenv -n mmcpart 2>/dev/null)"
else BOOT_DEV="$(fw_printenv -n mmcbootdev 2>/dev/null)"
BOOT_PART="$(fw_printenv -n mmcpart 2>/dev/null)" CURRENT_PART="$(sed -ne 's,PARTNAME=,,g;T;p' /sys/class/block/mmcblk"${BOOT_DEV}"p"${BOOT_PART}"/uevent)"
BOOT_DEV="$(fw_printenv -n mmcbootdev 2>/dev/null)" fw_setenv active_system "${CURRENT_PART}"
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 fi
fi
ISUPGRADING="$(fw_printenv -n upgrade_available 2>/dev/null)" ISUPGRADING="$(fw_printenv -n upgrade_available 2>/dev/null)"
if [ "$ISUPGRADING" = "1" ]; then if [ "$ISUPGRADING" = "1" ]; then
BOOTCOUNT="$(fw_printenv -n bootcount 2>/dev/null)" BOOTCOUNT="$(fw_printenv -n bootcount 2>/dev/null)"
if [ "${BOOTCOUNT}" -lt 3 ]; then if [ "${BOOTCOUNT}" -lt 3 ]; then
fw_setenv upgrade_available fw_setenv upgrade_available
fw_setenv bootcount 0 fw_setenv bootcount 0
fi
fi fi
echo "done."
fi fi
} }
case "$1" in case "$1" in
start) start)
dualboot_init if [ "$(fw_printenv -n dualboot 2>/dev/null)" = "yes" ]; then
echo -n "Starting dualboot check: "
dualboot_init
echo "done."
fi
;; ;;
stop) stop)
;; ;;

View File

@ -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="" VERBOSE=""
PUBLIC_KEY="/etc/ssl/certs/key.pub" PUBLIC_KEY="/etc/ssl/certs/key.pub"
ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)" ACTIVE_SYSTEM="$(fw_printenv -n active_system 2>/dev/null)"
@ -63,14 +68,9 @@ if [ -z "${UPDATE_FILE}" ]; then
fi fi
# Check if the rootfs is ubifs to determine if it is a nand or emmc device # Check if the rootfs is ubifs to determine if it is a nand or emmc device
PARTTABLE="/proc/mounts" NANDROOTFS="$(sed -ne "s/\(rootfs\).*\<ubifs\>.*/\1/g;T;p" /proc/mounts 2>/dev/null)"
NANDROOTFS="$(sed -ne "s/\(rootfs\).*\<ubifs\>.*/\1/g;T;p" ${PARTTABLE} 2>/dev/null)"
if [ -z "${NANDROOTFS}" ]; then 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 # Get current partition information so we can
# determine where to flash the images. # determine where to flash the images.
if [ "${ACTIVE_SYSTEM}" = "linux_a" ]; then if [ "${ACTIVE_SYSTEM}" = "linux_a" ]; then
@ -85,12 +85,22 @@ if [ -z "${NANDROOTFS}" ]; then
IMAGE_SET="mmc,primary" IMAGE_SET="mmc,primary"
fi fi
# get boot partition index # get boot and rootfs partition index
MMC_PART="$(ls -l /dev/disk/by-partlabel/ | grep -i ${KERNELBOOT} | awk '{print $11}' | sed -e 's/[../mmcblkp]//g' -e 's/^.//')" MMC_PART="$(realpath /dev/disk/by-partlabel/${KERNELBOOT} | grep -o '[[:digit:]]\+$')"
# search rootfs UUID # search rootfs UUID
MMCROOT_PART="$(ls -l /dev/disk/by-partlabel/ | grep -i ${ROOTFS} | awk '{print $11}' | sed -e 's/[../mmcblkp]//g' -e 's/^.//')" MMCROOT_DEV="$(realpath /dev/disk/by-partlabel/${ROOTFS})"
PART_UUID="$(ls -l /dev/disk/by-partuuid/ | grep -i mmcblk${BOOT_DEV}p${MMCROOT_PART} | awk '{print $9}')" 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 ""
echo "Updating '${IMAGE_SET}' image set from '${UPDATE_FILE}'..." echo "Updating '${IMAGE_SET}' image set from '${UPDATE_FILE}'..."
@ -99,8 +109,8 @@ if [ -z "${NANDROOTFS}" ]; then
# Execute the update. # Execute the update.
swupdate ${VERBOSE} -i "${UPDATE_FILE}" -e "${IMAGE_SET}" swupdate ${VERBOSE} -i "${UPDATE_FILE}" -e "${IMAGE_SET}"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
fw_setenv mmcroot PARTUUID=${PART_UUID} fw_setenv mmcroot "PARTUUID=${PART_UUID}"
fw_setenv mmcpart ${MMC_PART} fw_setenv mmcpart "${MMC_PART}"
fw_setenv active_system ${KERNELBOOT} fw_setenv active_system ${KERNELBOOT}
fw_setenv bootcount 0 fw_setenv bootcount 0
echo "Firmware update finished; Rebooting system." echo "Firmware update finished; Rebooting system."
@ -127,9 +137,6 @@ else
echo "Updating '${IMAGE_SET}' image set from '${UPDATE_FILE}'..." echo "Updating '${IMAGE_SET}' image set from '${UPDATE_FILE}'..."
echo "" echo ""
# Umount the partition before the update.
umount /mnt/${KERNELBOOT}
# Execute the update. # Execute the update.
if [ -f "${PUBLIC_KEY}" ]; then if [ -f "${PUBLIC_KEY}" ]; then
swupdate ${VERBOSE} -i "${UPDATE_FILE}" -e "${IMAGE_SET}" -k "${PUBLIC_KEY}" swupdate ${VERBOSE} -i "${UPDATE_FILE}" -e "${IMAGE_SET}" -k "${PUBLIC_KEY}"