diff options
author | Michael Pratt <mcpratt@pm.me> | 2021-02-24 22:55:09 -0500 |
---|---|---|
committer | Petr Štetiar <ynezz@true.cz> | 2021-04-08 09:20:59 +0200 |
commit | 4a0cc5d4ef29a11914850c72158aca1e2a170fb0 (patch) | |
tree | 4595a9c3115f558a600fda44aff98039837e85a2 /target/linux/ath79/image/common-senao.mk | |
parent | 1b8bd17c2d07c7397015a86941db9e114e1d349a (diff) | |
download | upstream-4a0cc5d4ef29a11914850c72158aca1e2a170fb0.tar.gz upstream-4a0cc5d4ef29a11914850c72158aca1e2a170fb0.tar.bz2 upstream-4a0cc5d4ef29a11914850c72158aca1e2a170fb0.zip |
ath79: remove 'fakeroot' for Senao devices
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>
Diffstat (limited to 'target/linux/ath79/image/common-senao.mk')
-rw-r--r-- | target/linux/ath79/image/common-senao.mk | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/target/linux/ath79/image/common-senao.mk b/target/linux/ath79/image/common-senao.mk index dd1a53c969..9b5903d8e7 100644 --- a/target/linux/ath79/image/common-senao.mk +++ b/target/linux/ath79/image/common-senao.mk @@ -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 |