Hi Christian,

Sorry for the delay.

> This patch enables the convenient sysupgrade feature for
> WD's Wi-Fi Range Extender.
> 
> The procedure is pretty much SOP. However, there is one
> small trick to it: The customized u-boot loader verifies
> the image's CRC32 against a reference each time the
> device boots. Now, In case of a jffs2-root filesystem
> the reference checksum would have to be updated every
> time something on the fs changes... Obviously, this
> wouldn't be very practial.
> 
> Luckily, the bootloader check can be defeated by modifying
> the TRX header after the flash.
> 
> Signed-off-by: Christian Lamparter <chunk...@googlemail.com>
> ---
> It seems the wrt160nl suffers from a similar issue. At least
> there's an open ticket #8960 https://dev.openwrt.org/ticket/8960.
> 
> As far as I can tell, the current sysupgrade code already tries
> to fix the TRX header (even on my Archer C7?!) but it fails: 
> 
> Writing from <stdin> to firmware ...
> Appending jffs2 data from /tmp/sysupgrade.tgz to firmware...
> TRX header not found Error fixing up TRX header.
> 
> This is because the current sysupgrade code doesn't know that
> the TRX header has a offset (32 bytes from the beginning).
> ---
>  .../ar71xx/base-files/lib/upgrade/mynet-rext.sh    | 26 
> ++++++++++++++++++++++
>  .../ar71xx/base-files/lib/upgrade/platform.sh      |  6 +++++
>  target/linux/ar71xx/image/Makefile                 |  3 +++
>  3 files changed, 35 insertions(+)
>  create mode 100644 target/linux/ar71xx/base-files/lib/upgrade/mynet-rext.sh
> 
> diff --git a/target/linux/ar71xx/base-files/lib/upgrade/mynet-rext.sh 
> b/target/linux/ar71xx/base-files/lib/upgrade/mynet-rext.sh
> new file mode 100644
> index 0000000..ea4eddd
> --- /dev/null
> +++ b/target/linux/ar71xx/base-files/lib/upgrade/mynet-rext.sh
> @@ -0,0 +1,26 @@
> +#!/bin/sh
> +
> +. /lib/functions.sh
> +. /lib/ar71xx.sh
> +
> +get_image_magic() {
> +     local mtddev=$1
> +     dd bs=8 count=1 skip=0 if=$mtddev 2>/dev/null | hexdump -v -n 8 -e '1/1 
> "%02x"'
> +}

This function is not used anywhere.

> +
> +mynet_rext_check_image() {

The function can be used for the wrt160nl as well. It would be better to rename
it to cybertan_check_image or something similar.

> +     local magic="$(get_magic_long "$1")"
> +     local fw_magic=$(get_magic_long "`find_mtd_part \"firmware\"`")
> +
> +     [ "$fw_magic" != "$magic" ] && {
> +             echo "Invalid image, ID mismatch, got:$magic, but 
> need:$fw_magic"
> +             return 1
> +     }
> +
> +     return 0;
> +}

> +
> +platform_do_upgrade_mynet_rext() {
> +     default_do_upgrade "$ARGV"
> +     mtd -o 32 fixtrx firmware
> +}

Although this works, but it causes an extra erase of the first block of the
firmware partition. We should patch the sysupgrade file on the host while we are
building that and we should skip this extra step.

Can you try the attached patches instead please?

-Gabor
>From 72607d9a08f2cbc69e5bee31415a583f201e761d Mon Sep 17 00:00:00 2001
From: Gabor Juhos <juh...@openwrt.org>
Date: Fri, 29 Nov 2013 21:59:48 +0100
Subject: [PATCH 1/3] ar71xx: image: fix CyberTAN sysupgrade images

In the current sysupgrade images, the CRC32 value of
the TRX header covers the whole rootfs data. Due to
this, the CRC value should be changed during sysupgrade
otherwise the bootloader refuses to load the image on
the next boot.

Change the image generation to create sysupgrade images
where the CRC32 value covers the kernel data only. This
allows to skip the 'fixtrx' step during sysupgrade on
the target.

Signed-off-by: Gabor Juhos <juh...@openwrt.org>
---
 target/linux/ar71xx/image/Makefile |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile
index 8511bba..dee4407 100644
--- a/target/linux/ar71xx/image/Makefile
+++ b/target/linux/ar71xx/image/Makefile
@@ -668,11 +668,15 @@ Image/Build/CyberTAN/loader=$(call Image/BuildLoader,$(1),gz,$(2),0x80060000)
 Image/Build/CyberTAN/buildkernel=$(call MkuImage,gzip,,$(KDIR)/loader-$(2).gz,$(KDIR_TMP)/vmlinux-$(2).uImage)
 
 define Image/Build/CyberTAN
-	$(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp -f $(KDIR_TMP)/vmlinux-$(2).uImage \
+	echo -n '' > $(KDIR_TMP)/empty.bin
+	$(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp \
+		-f $(KDIR_TMP)/vmlinux-$(2).uImage -F $(KDIR_TMP)/empty.bin \
 		-x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
 	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) \
 		-i $(KDIR)/image.tmp \
 		-o $(call sysupname,$(1),$(2))
+	$(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp -f $(KDIR_TMP)/vmlinux-$(2).uImage \
+		-x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
 	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) -g \
 		-i $(KDIR)/image.tmp \
 		-o $(call factoryname,$(1),$(2))
-- 
1.7.10

>From efbc511ab532c3ade0b4a33cce830e3ce567e4e3 Mon Sep 17 00:00:00 2001
From: Gabor Juhos <juh...@openwrt.org>
Date: Fri, 29 Nov 2013 21:59:48 +0100
Subject: [PATCH 2/3] ar71xx: image: unify CyberTAN macros

Make the Image/Build/CyberTAN macro more generic,
and use simple wrappers for the GZIP/LZMA variants.
This simplifies the Makefile a bit, and allows to
build sysupgrade images for the devices which are
using LZMA compressed uImages.

Signed-off-by: Gabor Juhos <juh...@openwrt.org>
---
 target/linux/ar71xx/image/Makefile |   21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile
index dee4407..0f2a2bb 100644
--- a/target/linux/ar71xx/image/Makefile
+++ b/target/linux/ar71xx/image/Makefile
@@ -664,35 +664,30 @@ define Image/Build/TPLINK-LZMA/initramfs
 		-o $(call imgname,$(1),$(2))-uImage.bin
 endef
 
-Image/Build/CyberTAN/loader=$(call Image/BuildLoader,$(1),gz,$(2),0x80060000)
-Image/Build/CyberTAN/buildkernel=$(call MkuImage,gzip,,$(KDIR)/loader-$(2).gz,$(KDIR_TMP)/vmlinux-$(2).uImage)
 
 define Image/Build/CyberTAN
 	echo -n '' > $(KDIR_TMP)/empty.bin
 	$(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp \
 		-f $(KDIR_TMP)/vmlinux-$(2).uImage -F $(KDIR_TMP)/empty.bin \
 		-x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
-	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) \
+	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(5) \
 		-i $(KDIR)/image.tmp \
 		-o $(call sysupname,$(1),$(2))
 	$(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp -f $(KDIR_TMP)/vmlinux-$(2).uImage \
 		-x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
-	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) -g \
+	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(5) -g \
 		-i $(KDIR)/image.tmp \
 		-o $(call factoryname,$(1),$(2))
 	rm $(KDIR)/image.tmp
 endef
 
+Image/Build/CyberTANGZIP/loader=$(call Image/BuildLoader,$(1),gz,$(2),0x80060000)
+Image/Build/CyberTANGZIP/buildkernel=$(call MkuImage,gzip,,$(KDIR)/loader-$(2).gz,$(KDIR_TMP)/vmlinux-$(2).uImage)
+Image/Build/CyberTANGZIP=$(call Image/Build/CyberTAN,$(1),$(2),$(3),$(4),$(5))
+
 Image/Build/CyberTANLZMA/buildkernel=$(call MkuImageLzma,$(2),$(3) $(4))
+Image/Build/CyberTANLZMA=$(call Image/Build/CyberTAN,$(1),$(2),$(3),$(4),$(5))
 
-define Image/Build/CyberTANLZMA
-	$(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp -f $(KDIR_TMP)/vmlinux-$(2).uImage \
-		-x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
-	-$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(5) -g \
-		-i $(KDIR)/image.tmp \
-		-o $(call factoryname,$(1),$(2))
-	rm $(KDIR)/image.tmp
-endef
 
 Image/Build/Netgear/initramfs=$(call MkuImageLzma/initramfs,$(2),$(3) $(4),,-M $(5))
 
@@ -917,7 +912,7 @@ $(eval $(call SingleProfile,CameoDB120,64kraw,DIR835A1,dir-835-a1,DIR-835-A1,tty
 
 $(eval $(call SingleProfile,CameoDB120_8M,64kraw,TEW732BR,tew-732br,TEW-732BR,ttyS0,115200,"00DB120AR9341-RT-120906-NA"))
 
-$(eval $(call SingleProfile,CyberTAN,64k,WRT160NL,wrt160nl,WRT160NL,ttyS0,115200,1.00.01))
+$(eval $(call SingleProfile,CyberTANGZIP,64k,WRT160NL,wrt160nl,WRT160NL,ttyS0,115200,,1.00.01))
 
 $(eval $(call SingleProfile,CyberTANLZMA,64k,MYNETREXT,mynet-rext,MYNET-REXT,ttyS0,115200,$$(mynet_rext_mtdlayout) root=31:4,1.00.01))
 
-- 
1.7.10

>From 6faa07301d837c53c9c07980e365815204e78e01 Mon Sep 17 00:00:00 2001
From: Gabor Juhos <juh...@openwrt.org>
Date: Fri, 29 Nov 2013 21:59:48 +0100
Subject: [PATCH 3/3] ar71xx: sysupgrade for My Net Wi-Fi Range Extender

This patch enables the convenient sysupgrade feature for
WD's Wi-Fi Range Extender.

Signed-off-by: Christian Lamparter <chunk...@googlemail.com>
Patchwork: http://patchwork.openwrt.org/patch/4341/
[juhosg:
  - rename 'mynet_rext_check_image' function to 'cybertan_check_image'
    and move that into platform.sh,
  - remove the the model specific 'platform_do_upgrade_mynet_rext' function,
  - drop the mynet-rext.sh script,
  - remove the image/Makefile change,
  - update commit message]
Signed-off-by: Gabor Juhos <juh...@openwrt.org>
---
 .../linux/ar71xx/base-files/lib/upgrade/platform.sh   |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
index 839ba4e..4328383 100755
--- a/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
+++ b/target/linux/ar71xx/base-files/lib/upgrade/platform.sh
@@ -73,6 +73,18 @@ seama_get_type_magic() {
 	get_image "$@" | dd bs=1 count=4 skip=53 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
 }
 
+cybertan_check_image() {
+	local magic="$(get_magic_long "$1")"
+	local fw_magic="$(ar71xx_get_mtd_part_magic firmware)"
+
+	[ "$fw_magic" != "$magic" ] && {
+		echo "Invalid image, ID mismatch, got:$magic, but need:$fw_magic"
+		return 1
+	}
+
+	return 0
+}
+
 platform_check_image() {
 	local board=$(ar71xx_board_name)
 	local magic="$(get_magic_word "$1")"
@@ -155,6 +167,11 @@ platform_check_image() {
 		dir825b_check_image "$1" && return 0
 		;;
 
+	mynet-rext)
+		cybertan_check_image "$1" && return 0
+		return 1
+		;;
+
 	mynet-n600)
 		[ "$magic_long" != "5ea3a417" ] && {
 			echo "Invalid image, bad magic: $magic_long"
-- 
1.7.10

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to