ath79: allow skipping hash for Senao sysupgrade
authorMichael Pratt <mcpratt@pm.me>
Fri, 9 Dec 2022 22:47:11 +0000 (17:47 -0500)
committerHauke Mehrtens <hauke@hauke-m.de>
Fri, 6 Jan 2023 14:34:07 +0000 (15:34 +0100)
Some vendors of Senao boards have a similar flash layout
situation that causes the need to split the firmware partition
and use the lzma-loader, but do not store
checksums of the partitions or otherwise
do not even have a uboot environment partition.

This adds simple shell logic to skip that part.

Also, simplify some lines and variable usage.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
target/linux/ath79/generic/base-files/lib/upgrade/failsafe_datachk.sh
target/linux/ath79/generic/base-files/lib/upgrade/platform.sh
target/linux/ath79/tiny/base-files/lib/upgrade/failsafe_datachk.sh
target/linux/ath79/tiny/base-files/lib/upgrade/platform.sh

index de84233de10b5cc95aa9e0bccdb554bfc31c878d..23847a1aae4ff6b6b870dbeceecd97cef1d77f9b 100644 (file)
@@ -8,8 +8,6 @@
 # So the kernel check is for the loader, the rootfs check is for kernel + rootfs
 
 platform_do_upgrade_failsafe_datachk() {
-       local setenv_script="/tmp/fw_env_upgrade"
-
        local flash_base=0x9f000000
 
        local kernel_mtd=$(find_mtd_index ${KERNEL_PART:-kernel})
@@ -34,31 +32,33 @@ platform_do_upgrade_failsafe_datachk() {
        local rootfs_md5=$($IMAGE_CMD $ROOTFS_FILE | dd bs=4k count=$rootfs_blocks iflag=fullblock | md5sum | cut -d ' ' -f1)
 
        # prepare new u-boot-env vars
-       printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $setenv_script
-       printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $setenv_script
-       printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
+       printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $ENV_SCRIPT
+       printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $ENV_SCRIPT
+       printf "vmlinux_checksum %s\n" ${kernel_md5} >> $ENV_SCRIPT
 
-       printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $setenv_script
-       printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $setenv_script
-       printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
+       printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $ENV_SCRIPT
+       printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $ENV_SCRIPT
+       printf "rootfs_checksum %s\n" ${rootfs_md5} >> $ENV_SCRIPT
 
        # store u-boot-env
        mkdir -p /var/lock
-       fw_setenv -s $setenv_script || {
+       [ -n "$SKIP_HASH" ] || fw_setenv -s $ENV_SCRIPT || {
                echo 'failed to update U-Boot environment'
                exit 1
        }
 
        # sysupgrade
-       sleep 2
-       sync
-       echo 3 > /proc/sys/vm/drop_caches
+       sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
+
        $IMAGE_CMD $KERNEL_FILE | mtd $MTD_ARGS write - ${KERNEL_PART:-kernel}
-       sleep 2
-       sync
+
+       sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
+
        if [ -n "$UPGRADE_BACKUP" ]; then
                $IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
        else
                $IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS write - ${ROOTFS_PART:-rootfs}
        fi
+
+       sync
 }
index c58e0053448bb392c164b315bb0d50f9c2532310..0de3dbf3b51aa41aa1f593736dbc065144fd1af3 100644 (file)
@@ -45,6 +45,7 @@ platform_do_upgrade() {
        watchguard,ap100|\
        watchguard,ap200|\
        watchguard,ap300)
+               ENV_SCRIPT="/tmp/fw_env"
                IMAGE_LIST="tar tzf $1"
                IMAGE_CMD="tar xzOf $1"
                KERNEL_PART="loader"
index de84233de10b5cc95aa9e0bccdb554bfc31c878d..23847a1aae4ff6b6b870dbeceecd97cef1d77f9b 100644 (file)
@@ -8,8 +8,6 @@
 # So the kernel check is for the loader, the rootfs check is for kernel + rootfs
 
 platform_do_upgrade_failsafe_datachk() {
-       local setenv_script="/tmp/fw_env_upgrade"
-
        local flash_base=0x9f000000
 
        local kernel_mtd=$(find_mtd_index ${KERNEL_PART:-kernel})
@@ -34,31 +32,33 @@ platform_do_upgrade_failsafe_datachk() {
        local rootfs_md5=$($IMAGE_CMD $ROOTFS_FILE | dd bs=4k count=$rootfs_blocks iflag=fullblock | md5sum | cut -d ' ' -f1)
 
        # prepare new u-boot-env vars
-       printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $setenv_script
-       printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $setenv_script
-       printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
+       printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $ENV_SCRIPT
+       printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $ENV_SCRIPT
+       printf "vmlinux_checksum %s\n" ${kernel_md5} >> $ENV_SCRIPT
 
-       printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $setenv_script
-       printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $setenv_script
-       printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
+       printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $ENV_SCRIPT
+       printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $ENV_SCRIPT
+       printf "rootfs_checksum %s\n" ${rootfs_md5} >> $ENV_SCRIPT
 
        # store u-boot-env
        mkdir -p /var/lock
-       fw_setenv -s $setenv_script || {
+       [ -n "$SKIP_HASH" ] || fw_setenv -s $ENV_SCRIPT || {
                echo 'failed to update U-Boot environment'
                exit 1
        }
 
        # sysupgrade
-       sleep 2
-       sync
-       echo 3 > /proc/sys/vm/drop_caches
+       sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
+
        $IMAGE_CMD $KERNEL_FILE | mtd $MTD_ARGS write - ${KERNEL_PART:-kernel}
-       sleep 2
-       sync
+
+       sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
+
        if [ -n "$UPGRADE_BACKUP" ]; then
                $IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
        else
                $IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS write - ${ROOTFS_PART:-rootfs}
        fi
+
+       sync
 }
index 6d05b88d45c660b043845dde0878a948a23bdd55..eb8441c6d267fa53114ca6c53e95a67fec93fe63 100644 (file)
@@ -19,6 +19,7 @@ platform_do_upgrade() {
        engenius,eap350-v1|\
        engenius,ecb350-v1|\
        engenius,enh202-v1)
+               ENV_SCRIPT="/tmp/fw_env"
                IMAGE_LIST="tar tzf $1"
                IMAGE_CMD="tar xzOf $1"
                KERNEL_PART="loader"