ath79: remove 'fakeroot' for Senao devices
authorMichael Pratt <mcpratt@pm.me>
Thu, 25 Feb 2021 03:55:09 +0000 (22:55 -0500)
committerPetr Štetiar <ynezz@true.cz>
Fri, 11 Jun 2021 05:20:31 +0000 (07:20 +0200)
By using the same custom kernel header magic
in both OKLI lzma-loader, DTS, and makefile
this hack is not necessary anymore

However, "rootfs" size and checksum
must now be supplied by the factory.bin image
through a script that is accepted by the OEM upgrade script.

This is because Senao OEM scripts assume a squashfs header exists
at the offset for the original "rootfs" partition
which is actually the kernel + rootfs in this implementation,
and takes size value from the header that would be there with hexdump,
but this offset is now the uImage header instead.

This frees up 1 eraseblock
previously used by the "fakeroot" partition
for bypassing the OEM image verification.

Also, these Senao devices with a 'failsafe' partition
and the tar-gz factory.bin platform would otherwise require
flashing the new tar-gz sysupgrade.bin afterward.
So this also prevents having to flash both images
when starting from OEM or 'failsafe'

the OEM upgrade script verifies the header magic numbers,
but only the first two bytes.
Example:

    [ "${magic_word_kernel}" = "2705" ] &&
    [ "${magic_word_rootfs}" = "7371" -o "${magic_word_rootfs}" = "6873" ] &&
    errcode="0"

therefore picked the magic number
0x73714f4b
which is
'sqOK'

Signed-off-by: Michael Pratt <mcpratt@pm.me>
(cherry picked from commit 4a0cc5d4ef29a11914850c72158aca1e2a170fb0)

target/linux/ath79/dts/ar724x_senao_loader.dtsi
target/linux/ath79/dts/ar934x_senao_loader.dtsi
target/linux/ath79/dts/qca955x_senao_loader.dtsi
target/linux/ath79/image/common-senao.mk
target/linux/ath79/image/generic.mk
target/linux/ath79/image/tiny.mk

index fdc2726e6f247bb813eb2a6209d09e0581302027..54dbec18b369149984455a38a2fcca74cb1323e1 100644 (file)
@@ -15,7 +15,7 @@
 
                        partition@0 {
                                compatible = "openwrt,uimage", "denx,uimage";
-                               openwrt,ih-magic = <IH_MAGIC_OKLI>;
+                               openwrt,ih-magic = <0x73714f4b>;
                                label = "firmware";
                                reg = <0x0 0x0>;
                        };
                                reg = <0xb0000 0xf0000>;
                        };
 
-                       partition@1a0000 {
-                               label = "fakeroot";
-                               reg = <0x1a0000 0x10000>;
-                               read-only;
-                       };
-
-                       fwconcat0: partition@1b0000 {
+                       fwconcat0: partition@1a0000 {
                                label = "fwconcat0";
-                               reg = <0x1b0000 0x4c0000>;
+                               reg = <0x1a0000 0x4d0000>;
                        };
 
                        partition@670000 {
index aa8a36d24263f85438693caecea5ecf6f715e640..35e5f135350c6bf8ab6d4c189e0cb1a7a9810301 100644 (file)
@@ -15,7 +15,7 @@
 
                        partition@0 {
                                compatible = "openwrt,uimage", "denx,uimage";
-                               openwrt,ih-magic = <IH_MAGIC_OKLI>;
+                               openwrt,ih-magic = <0x73714f4b>;
                                label = "firmware";
                                reg = <0x0 0x0>;
                        };
                                reg = <0x0b0000 0x170000>;
                        };
 
-                       partition@220000 {
-                               label = "fakeroot";
-                               reg = <0x220000 0x010000>;
-                               read-only;
-                       };
-
-                       fwconcat0: partition@230000 {
+                       fwconcat0: partition@220000 {
                                label = "fwconcat0";
-                               reg = <0x230000 0xbc0000>;
+                               reg = <0x220000 0xbd0000>;
                        };
 
                        partition@df0000 {
index 3f5fc0e9382d63e786e8c7e75671b8354dc612e6..77eabde80afad8b7f386d4816826b1d8e1716b80 100644 (file)
@@ -17,7 +17,7 @@
 
                        partition@0 {
                                compatible = "openwrt,uimage", "denx,uimage";
-                               openwrt,ih-magic = <IH_MAGIC_OKLI>;
+                               openwrt,ih-magic = <0x73714f4b>;
                                label = "firmware";
                                reg = <0x0 0x0>;
                        };
                                reg = <0x0b0000 0x170000>;
                        };
 
-                       partition@220000 {
-                               label = "fakeroot";
-                               reg = <0x220000 0x010000>;
-                               read-only;
-                       };
-
-                       fwconcat0: partition@230000 {
+                       fwconcat0: partition@220000 {
                                label = "fwconcat0";
-                               reg = <0x230000 0xb40000>;
+                               reg = <0x220000 0xb50000>;
                        };
 
                        partition@d70000 {
index dd1a53c969c4abf45d76dc6c7ee1c131c89ae539..9b5903d8e7ca55357edf0ad1c1cbbf41d0e212c1 100644 (file)
@@ -3,30 +3,37 @@ DEVICE_VARS += SENAO_IMGNAME
 # This needs to make /tmp/_sys/sysupgrade.tgz an empty file prior to
 # sysupgrade, as otherwise it will implant the old configuration from
 # OEM firmware when writing rootfs from factory.bin
+# rootfs size and checksum is taken from a squashfs header
+# the header does not exist, therefore, supply the size and md5
 define Build/senao-tar-gz
        -[ -f "$@" ] && \
        mkdir -p $@.tmp && \
        touch $@.tmp/failsafe.bin && \
        echo '#!/bin/sh' > $@.tmp/before-upgrade.sh && \
        echo ': > /tmp/_sys/sysupgrade.tgz' >> $@.tmp/before-upgrade.sh && \
+       echo -n $$(( $$(cat $@ | wc -c) / 4096 * 4096 )) > $@.len && \
+       dd if=$@ bs=$$(cat $@.len) count=1 | md5sum - | cut -d ' ' -f 1 > $@.md5 && \
+       echo '#!/bin/sh' > $@.tmp/after-upgrade.sh && \
+       printf 'fw_setenv rootfs_size 0x%08x\n' $$(cat $@.len) >> $@.tmp/after-upgrade.sh && \
+       printf 'fw_setenv rootfs_checksum %s\n' $$(cat $@.md5) >> $@.tmp/after-upgrade.sh && \
        $(CP) $(KDIR)/loader-$(DEVICE_NAME).uImage \
                $@.tmp/openwrt-$(word 1,$(1))-uImage-lzma.bin && \
        $(CP) $@ $@.tmp/openwrt-$(word 1,$(1))-root.squashfs && \
        $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
                $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
                -C $@.tmp . | gzip -9n > $@ && \
-       rm -rf $@.tmp
+       rm -rf $@.tmp $@.len $@.md5
 endef
 
 define Device/senao_loader_okli
-  KERNEL := kernel-bin | append-dtb | lzma | uImage lzma -M 0x4f4b4c49
+  KERNEL := kernel-bin | append-dtb | lzma | uImage lzma -M 0x73714f4b
+  LOADER_KERNEL_MAGIC := 0x73714f4b
   LOADER_TYPE := bin
   COMPILE := loader-$(1).bin loader-$(1).uImage
   COMPILE/loader-$(1).bin := loader-okli-compile
   COMPILE/loader-$(1).uImage := append-loader-okli $(1) | pad-to 64k | lzma | \
        uImage lzma
   IMAGES += factory.bin
-  IMAGE/factory.bin := append-squashfs-fakeroot-be | pad-to $$$$(BLOCKSIZE) | \
-       append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
+  IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
        check-size | senao-tar-gz $$$$(SENAO_IMGNAME)
 endef
index f358d44064438c2aad4cf45840dee40f5381b2fe..bda47ce74da35696035db22c2f0b9609b8cbb67d 100644 (file)
@@ -994,8 +994,8 @@ define Device/engenius_eap1200h
   DEVICE_VENDOR := EnGenius
   DEVICE_MODEL := EAP1200H
   DEVICE_PACKAGES := ath10k-firmware-qca988x-ct kmod-ath10k-ct
-  IMAGE_SIZE := 11520k
-  LOADER_FLASH_OFFS := 0x230000
+  IMAGE_SIZE := 11584k
+  LOADER_FLASH_OFFS := 0x220000
   SENAO_IMGNAME := ar71xx-generic-eap1200h
 endef
 TARGET_DEVICES += engenius_eap1200h
@@ -1006,8 +1006,8 @@ define Device/engenius_eap300-v2
   DEVICE_VENDOR := EnGenius
   DEVICE_MODEL := EAP300
   DEVICE_VARIANT := v2
-  IMAGE_SIZE := 12032k
-  LOADER_FLASH_OFFS := 0x230000
+  IMAGE_SIZE := 12096k
+  LOADER_FLASH_OFFS := 0x220000
   SENAO_IMGNAME := senao-eap300v2
 endef
 TARGET_DEVICES += engenius_eap300-v2
@@ -1017,8 +1017,8 @@ define Device/engenius_eap600
   SOC := ar9344
   DEVICE_VENDOR := EnGenius
   DEVICE_MODEL := EAP600
-  IMAGE_SIZE := 12032k
-  LOADER_FLASH_OFFS := 0x230000
+  IMAGE_SIZE := 12096k
+  LOADER_FLASH_OFFS := 0x220000
   SENAO_IMGNAME := senao-eap600
 endef
 TARGET_DEVICES += engenius_eap600
@@ -1054,8 +1054,8 @@ define Device/engenius_ecb600
   SOC := ar9344
   DEVICE_VENDOR := EnGenius
   DEVICE_MODEL := ECB600
-  IMAGE_SIZE := 12032k
-  LOADER_FLASH_OFFS := 0x230000
+  IMAGE_SIZE := 12096k
+  LOADER_FLASH_OFFS := 0x220000
   SENAO_IMGNAME := senao-ecb600
 endef
 TARGET_DEVICES += engenius_ecb600
@@ -1067,8 +1067,8 @@ define Device/engenius_ens202ext-v1
   DEVICE_MODEL := ENS202EXT
   DEVICE_VARIANT := v1
   DEVICE_PACKAGES := rssileds
-  IMAGE_SIZE := 12032k
-  LOADER_FLASH_OFFS := 0x230000
+  IMAGE_SIZE := 12096k
+  LOADER_FLASH_OFFS := 0x220000
   SENAO_IMGNAME := senao-ens202ext
 endef
 TARGET_DEVICES += engenius_ens202ext-v1
@@ -1080,8 +1080,8 @@ define Device/engenius_enstationac-v1
   DEVICE_MODEL := EnStationAC
   DEVICE_VARIANT := v1
   DEVICE_PACKAGES := ath10k-firmware-qca988x-ct kmod-ath10k-ct rssileds
-  IMAGE_SIZE := 11520k
-  LOADER_FLASH_OFFS := 0x230000
+  IMAGE_SIZE := 11584k
+  LOADER_FLASH_OFFS := 0x220000
   SENAO_IMGNAME := ar71xx-generic-enstationac
 endef
 TARGET_DEVICES += engenius_enstationac-v1
index dec3cd368db4a7a309fd8e6e63216bb84d94f57b..e9aab2ce069bcb5c4d7cadb4f22b86139d2e8c7c 100644 (file)
@@ -37,8 +37,8 @@ define Device/engenius_eap350-v1
   DEVICE_VENDOR := EnGenius
   DEVICE_MODEL := EAP350
   DEVICE_VARIANT := v1
-  IMAGE_SIZE := 4864k
-  LOADER_FLASH_OFFS := 0x1b0000
+  IMAGE_SIZE := 4928k
+  LOADER_FLASH_OFFS := 0x1a0000
   SENAO_IMGNAME := senao-eap350
 endef
 TARGET_DEVICES += engenius_eap350-v1
@@ -49,8 +49,8 @@ define Device/engenius_ecb350-v1
   DEVICE_VENDOR := EnGenius
   DEVICE_MODEL := ECB350
   DEVICE_VARIANT := v1
-  IMAGE_SIZE := 4864k
-  LOADER_FLASH_OFFS := 0x1b0000
+  IMAGE_SIZE := 4928k
+  LOADER_FLASH_OFFS := 0x1a0000
   SENAO_IMGNAME := senao-ecb350
 endef
 TARGET_DEVICES += engenius_ecb350-v1
@@ -62,8 +62,8 @@ define Device/engenius_enh202-v1
   DEVICE_MODEL := ENH202
   DEVICE_VARIANT := v1
   DEVICE_PACKAGES := rssileds
-  IMAGE_SIZE := 4864k
-  LOADER_FLASH_OFFS := 0x1b0000
+  IMAGE_SIZE := 4928k
+  LOADER_FLASH_OFFS := 0x1a0000
   SENAO_IMGNAME := senao-enh202
 endef
 TARGET_DEVICES += engenius_enh202-v1