From cd2a6906daff74c417d939aa14704f5d98bc7501 Mon Sep 17 00:00:00 2001 From: INAGAKI Hiroshi Date: Sat, 11 May 2024 14:14:16 +0900 Subject: [PATCH] ramips: parameterize some values in Build/znet-header Parameterize magic number and header length to use the device-specific values. example: On WRC-X1800GS, an additional ELECOM-specific header and a magic number "COMC" are required. Stock FW v1.18: $ hexdump -n $((0x40080)) -C wrc-x1800gs_v1.18.bin 00000000 45 4c 45 43 4f 4d 00 00 57 52 43 2d 58 31 38 30 |ELECOM..WRC-X180| 00000010 30 47 53 00 00 00 00 00 00 00 00 00 00 00 00 00 |0GS.............| 00000020 00 00 00 00 00 00 00 00 31 2e 31 38 00 00 00 00 |........1.18....| 00000030 00 00 00 00 00 00 00 00 43 4f 4d 43 04 00 ac 00 |........COMC....| 00000040 40 f0 49 74 b1 e8 6a ca e4 20 65 1f 34 2e 30 34 |@.It..j.. e.4.04| 00000050 28 58 56 46 2e 31 29 62 31 37 00 00 00 00 00 00 |(XVF.1)b17......| 00000060 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff |................| 00000070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| * 00040000 d0 0d fe ed 00 36 9c c0 00 00 00 38 00 36 9a e0 |.....6.....8.6..| 00040010 00 00 00 28 00 00 00 11 00 00 00 10 00 00 00 00 |...(............| 00040020 00 00 00 6c 00 36 9a a8 00 00 00 00 00 00 00 00 |...l.6..........| 00040030 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 |................| 00040040 00 00 00 03 00 00 00 04 00 00 00 62 65 54 97 8f |...........beT..| 00040050 00 00 00 03 00 00 00 28 00 00 00 00 4d 49 50 53 |.......(....MIPS| 00040060 20 4f 70 65 6e 57 72 74 20 46 49 54 20 28 46 6c | OpenWrt FIT (Fl| 00040070 61 74 74 65 6e 65 64 20 49 6d 61 67 65 20 54 72 |attened Image Tr| 00040080 Signed-off-by: INAGAKI Hiroshi --- target/linux/ramips/image/mt7621.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk index 33fcc805d9..1c6cd237d3 100644 --- a/target/linux/ramips/image/mt7621.mk +++ b/target/linux/ramips/image/mt7621.mk @@ -99,13 +99,15 @@ endef define Build/znet-header $(eval version=$(word 1,$(1))) + $(eval magic=$(if $(word 2,$(1)),$(word 2,$(1)),ZNET)) + $(eval hdrlen=$(if $(word 3,$(1)),$(word 3,$(1)),0x30)) ( \ data_size_crc="$$(dd if=$@ 2>/dev/null | gzip -c | \ tail -c 8 | od -An -N4 -tx4 --endian big | tr -d ' \n')"; \ payload_len="$$(dd if=$@ bs=4 count=1 skip=1 2>/dev/null | od -An -tdI --endian big | tr -d ' \n')"; \ payload_size_crc="$$(dd if=$@ ibs=1 count=$$payload_len 2>/dev/null | gzip -c | \ tail -c 8 | od -An -N4 -tx4 --endian big | tr -d ' \n')"; \ - echo -ne "\x5A\x4E\x45\x54" | dd bs=4 count=1 conv=sync 2>/dev/null; \ + echo -ne "$(magic)" | dd bs=4 count=1 conv=sync 2>/dev/null; \ echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tac | tr -d '\n')" | \ dd bs=4 count=1 conv=sync 2>/dev/null; \ echo -ne "$$(echo $$data_size_crc | sed 's/../\\x&/g')" | \ @@ -114,7 +116,7 @@ define Build/znet-header dd bs=4 count=1 conv=sync 2>/dev/null; \ echo -ne "\x12\x34\x56\x78" | dd bs=4 count=1 conv=sync 2>/dev/null; \ echo -ne "$(version)" | dd bs=28 count=1 conv=sync 2>/dev/null; \ - dd if=/dev/zero bs=262096 count=1 conv=sync 2>/dev/null | tr "\000" "\377"; \ + dd if=/dev/zero bs=$$((0x40000 - $(hdrlen))) count=1 conv=sync 2>/dev/null | tr "\000" "\377"; \ cat $@; \ ) > $@.new mv $@.new $@ -- 2.30.2