mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-27 17:18:59 +00:00
d5035f0d26
Use a similar upgrade method for sysupgrade.bin, like factory.bin, for Senao boards with the tar.gz OEM upgrade platform, and 'failsafe' image which is loaded on checksum failure. This is inspired by the OEM upgrade script /etc/fwupgrade.sh and the existing platforms for dual-boot Senao boards. Previously, if the real kernel was damaged or missing the only way to recover was with UART serial console, because the OKLI lzma-loader is programmed to halt. uboot did not detect cases where kernel or rootfs is damaged and boots OKLI instead of the failsafe image, because the checksums stored in uboot environment did not include the real kernel and rootfs space. Now, the stored checksums include the space for both the lzma-loader, kernel, and rootfs. Therefore, these boards are now practically unbrickable. Also, the factory.bin and sysupgrade.bin are now the same, except for image metadata. This allows for flashing OEM image directly from openwrt as well as flashing openwrt image directly from OEM. Make 'loader' partition writable so that it can be updated during a sysupgrade. tested with ENS202EXT v1 EAP1200H EAP350 v1 EAP600 ECB350 v1 ECB600 ENH202 v1 Signed-off-by: Michael Pratt <mcpratt@pm.me>
41 lines
1.8 KiB
Makefile
41 lines
1.8 KiB
Makefile
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 $@.len $@.md5
|
|
endef
|
|
|
|
define Device/senao_loader_okli
|
|
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-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs | pad-rootfs | \
|
|
check-size | senao-tar-gz $$$$(SENAO_IMGNAME)
|
|
IMAGE/sysupgrade.bin := $$(IMAGE/factory.bin) | append-metadata
|
|
endef
|