11.09.2016 03:36, J Mo:


On 09/10/2016 10:27 AM, Mathias Kresin wrote:
10.09.2016 03:35, J Mo:
--- a/include/image-commands.mk
+++ b/include/image-commands.mk
@@ -168,3 +168,19 @@ define Build/sysupgrade-tar
         --rootfs $(call
param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
         $@
 endef
+
+define Build/cameo-sig
+    { \
+        cameo_sig=$(word 1, $(1)) ;\
+        align=$(if $(2),$(2),64) ;\
+        oldsize=$$(stat -c %s $@) ;\
+        sigsize=$$(echo -n $$cameo_sig | wc -c) ;\
+        padsize=$$(( ( ( ( $$oldsize + $$sigsize ) / $$align ) + 1 )
- ( ( $$oldsize + $$sigsize ) / $$align ) )) ;\
+        newsize=$$(( $$oldsize + $$padsize )) ;\
+        echo "Appending Cameo signature: \"$$cameo_sig\",
oldsize=$$oldsize align=$$align sigsize=$$sigsize padsize=$$padsize
newsize=$$newsize" ;\
+        dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync ;\
+        echo -n "$$cameo_sig" >> $@.new ; \
+    }
+    @mv $@.new $@
+endef


I'm not doing anything obscure here. This should be self-evident. Add a
byte-aligned signature. pad-to can't do that.

Well if it would be obvious what you are trying to do I wouldn't ask.

I still don't get what and to which boundary you are trying to align. After fixing the build errors I do get the following:

Appending Cameo signature: "AP148AR9880-RT-150127-00", oldsize=5901955 align=64 sigsize=24 padsize=1 newsize=5901956

PreFooter size: 5901956
PostFooter size: 5901979

Neither the pre footer image nor the post footer image is padded to a multiple of 64 byte.

Do you want to add the signature to a 64 byte padded image or should the image + signature padded to a multiple of 64byte? Where does the 64 byte does come from? It doesn't seam to be related to the 128k blocksize of the flash.

diff --git
a/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
b/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac

index 1ae4352..a3326ab 100644
---
a/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac

+++
b/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac

@@ -18,6 +18,9 @@ case "$board" in
     ea8500)
         echo $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr)
$(($PHYNBR + 1)) ) > /sys${DEVPATH}/macaddress
         ;;
+    tew827dru)
+        echo $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac)
$(($PHYNBR + 1)) ) > /sys${DEVPATH}/macaddress
+        ;;
     *)
         ;;
 esac

This whole file (already before your changes) looks completely wrong
to me. Would you please send me a dump of your ART partition!

I'll have a look at the checksum. I've a checksum patcher for ath9k in
place (https://git.io/vi0eK) which might work for QCA99x0 caldata as
well. This way the ath10kcal_patch_mac function in
hotplug.d/firmware/11-ath10k-caldata can be used to fix the wifi mac
address.

I have uploaded a dump of two ART partitions from two different
tew827dru here if you or anyone else wants to look at them:

http://jmomo.net/files/lede/tew827dru-ARTs/

There is some discussion about this over on the TP-Link Archer C2600
thread. I suggest you go check it out for additional background:

    https://forum.openwrt.org/viewtopic.php?id=54973&p=13
    https://forum.openwrt.org/viewtopic.php?id=54973&p=14
    https://forum.openwrt.org/viewtopic.php?pid=317711#p317711
https://github.com/ianchi/openwrt/commit/83084c84414b44801a1ba8f323b363f0bc748e64

This one is quite neat. It allows me to verify my changes. Would you please try the attached patch.

Before:

$ ./caldata -i './caldata1.bin' -v
Size: 12064
MAC: 12:34:56:78:90:12
Checksum: 0xdf10 (OK)

Patched:

$ ./caldata -v -i ./patched.bin
Size: 12064
MAC: aa:bb:cc:dd:ee:ff
Checksum: 0x184c (OK)


diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index a218183..71fa1e6 100644
--- a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -1,5 +1,25 @@
 #!/bin/sh
 
+[ -e /lib/firmware/$FIRMWARE ] && exit 0
+
+. /lib/ipq806x.sh
+. /lib/functions.sh
+. /lib/functions/system.sh
+
+# xor multiple hex values of the same length
+xor() {
+	local ret="0x$1"
+
+	shift 1
+	while [[ "$1" ]]; do
+		local val="0x$1"
+		ret=$((${ret:-0} ^ ${val:-0}))
+		shift 1
+	done
+
+	printf "%02x" "$ret"
+}
+
 ath10kcal_die() {
 	echo "ath10cal: " "$*"
 	exit 1
@@ -30,39 +50,46 @@ ath10kcal_extract() {
 
 ath10kcal_patch_mac() {
 	local mac=$1
+	local mac_offset=6
+	local chksum_offset=2
+	local xor_mac
+	local xor_fw_mac
+	local xor_fw_chksum
 
 	[ -z "$mac" ] && return
 
-	macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
-}
+	xor_mac="${mac:0:2}${mac:3:2} ${mac:6:2}${mac:9:2} ${mac:12:2}${mac:15:2}"
+	xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/2 "%04x "' /lib/firmware/$FIRMWARE)
 
-[ -e /lib/firmware/$FIRMWARE ] && exit 0
+	xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
+	xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
 
-. /lib/ipq806x.sh
-. /lib/functions.sh
-. /lib/functions/system.sh
+	echo -ne \\x${xor_fw_chksum:0:2}\\x${xor_fw_chksum:2:2} | \
+		dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2
 
-board=$(ipq806x_board_name)
+	macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$mac_offset count=6
+}
 
+board=$(ipq806x_board_name)
 
 case "$FIRMWARE" in
 "ath10k/cal-pci-0000:01:00.0.bin")
 	case $board in
 	c2600)
 		ath10kcal_extract "radio" 4096 12064
-# 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -1)
+ 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -1)
 		;;
 	ea8500)
-		hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
 		ath10kcal_extract "art" 4096 12064
+		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +1)
 		;;
-         r7500v2 |\
-         r7800)
+	r7500v2 |\
+	r7800)
 		ath10kcal_extract "art" 4096 12064
 		;;
 	tew827dru)
-		hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
 		ath10kcal_extract "ART" 4096 12064
+		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac) + 1)
 		;;
 	esac
 	;;
@@ -70,19 +97,19 @@ case "$FIRMWARE" in
 	case $board in
 	c2600)
 		ath10kcal_extract "radio" 20480 12064
-# 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -2)
+ 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary default-mac 8) -2)
 		;;
 	ea8500)
-		hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
 		ath10kcal_extract "art" 20480 12064
+		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +2)
 		;;
-        r7500v2 |\
-        r7800)
+	r7500v2 |\
+	r7800)
 		ath10kcal_extract "art" 20480 12064
 		;;
 	tew827dru)
-		hw_mac_addr=$(mtd_get_mac_ascii devinfo hw_mac_addr)
 		ath10kcal_extract "ART" 20480 12064
+		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac) + 2)
 		;;
 	esac
 	;;
diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
deleted file mode 100644
index a3326ab..0000000
--- a/target/linux/ipq806x/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/ash
-
-[ "$ACTION" == "add" ] || exit 0
-
-PHYNBR=${DEVPATH##*/phy}
-
-[ -n $PHYNBR ] || exit 0
-
-. /lib/ipq806x.sh
-. /lib/functions/system.sh
-
-board=$(ipq806x_board_name)
-
-case "$board" in
-	c2600)
-		echo $(macaddr_add $(mtd_get_mac_binary default-mac 8)  $(($PHYNBR - 1)) ) > /sys${DEVPATH}/macaddress
-		;;
-	ea8500)
-		echo $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) $(($PHYNBR + 1)) ) > /sys${DEVPATH}/macaddress
-		;;
-	tew827dru)
-		echo $(macaddr_add $(mtd_get_mac_ascii APPSBLENV wan_mac) $(($PHYNBR + 1)) ) > /sys${DEVPATH}/macaddress
-		;;
-	*)
-		;;
-esac
_______________________________________________
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev

Reply via email to