[OpenWrt-Devel] [PATCH 1/3] ar71xx/ath79: Merge ath10k-caldata extraction into eeprom.sh

Adrian Schmutzler freifunk at adrianschmutzler.de
Mon Feb 25 18:11:13 EST 2019


ath10k-caldata extraction is the same across different targets
and also uses similar function compared to ath9k-eeprom
extraction.

This patch merges ath10k stuff into the same file where ath9k
function have already been collected.

Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
 package/base-files/files/lib/functions/eeprom.sh   | 34 ++++++++++
 .../etc/hotplug.d/firmware/11-ath10k-caldata       | 78 +++++++---------------
 .../etc/hotplug.d/firmware/11-ath10k-caldata       | 57 +++++-----------
 3 files changed, 72 insertions(+), 97 deletions(-)

diff --git a/package/base-files/files/lib/functions/eeprom.sh b/package/base-files/files/lib/functions/eeprom.sh
index 3b585dab7c..13494b63db 100644
--- a/package/base-files/files/lib/functions/eeprom.sh
+++ b/package/base-files/files/lib/functions/eeprom.sh
@@ -6,6 +6,11 @@ eeprom_die() {
 	exit 1
 }
 
+ath10kcal_die() {
+	echo "ath10cal: " "$*"
+	exit 1
+}
+
 mtd_eeprom_extract() {
 	local part=$1
 	local offset=$2
@@ -20,6 +25,26 @@ mtd_eeprom_extract() {
 		eeprom_die "failed to extract from $mtd"
 }
 
+mtd_eeprom_extract_check() {
+	local part=$1
+	local offset=$2
+	local count=$3
+	local mtd cal_size
+
+	mtd=$(find_mtd_chardev $part)
+	[ -n "$mtd" ] || \
+		eeprom_die "no mtd device found for partition $part"
+
+	# Check that the calibration data size in header equals the desired size
+	cal_size=$(dd if=$mtd bs=2 count=1 skip=$(( $offset / 2 )) conv=swab 2>/dev/null | hexdump -ve '1/2 "%d"')
+
+	[ "$count" = "$cal_size" ] || \
+		eeprom_die "no calibration data found in $part"
+
+	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+		eeprom_die "failed to extract from $mtd"
+}
+
 mtd_eeprom_extract_reverse() {
 	local part=$1
 	local offset=$2
@@ -52,3 +77,12 @@ ubi_eeprom_extract() {
 	dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
 		eeprom_die "failed to extract from $ubi"
 }
+
+ath10kcal_from_file() {
+	local source=$1
+	local offset=$2
+	local count=$3
+
+	dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+		ath10kcal_die "failed to extract calibration data from $source"
+}
diff --git a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index 3450819630..ab128497ae 100644
--- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -1,38 +1,6 @@
 #!/bin/sh
 
-ath10kcal_die() {
-	echo "ath10cal: " "$*"
-	exit 1
-}
-
-ath10kcal_from_file() {
-	local source=$1
-	local offset=$2
-	local count=$3
-
-	dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath10kcal_die "failed to extract calibration data from $source"
-}
-
-ath10kcal_extract() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd cal_size
-
-	mtd=$(find_mtd_chardev $part)
-	[ -n "$mtd" ] || \
-		ath10kcal_die "no mtd device found for partition $part"
-
-	# Check that the calibration data size in header equals the desired size
-	cal_size=$(dd if=$mtd bs=2 count=1 skip=$(( $offset / 2 )) conv=swab 2>/dev/null | hexdump -ve '1/2 "%d"')
-
-	[ "$count" = "$cal_size" ] || \
-		ath10kcal_die "no calibration data found in $part"
-
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath10kcal_die "failed to extract calibration data from $mtd"
-}
+. /lib/functions/eeprom.sh
 
 ath10kcal_patch_mac() {
 	local mac=$1
@@ -57,17 +25,17 @@ case "$FIRMWARE" in
 	mr1750|\
 	mr1750v2|\
 	om5p-acv2)
-		ath10kcal_extract "ART" 20480 2116
+		mtd_eeprom_extract_check "ART" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
 		;;
 	archer-c25-v1|\
 	tl-wdr6500-v2)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
 		;;
 	archer-c7-v4|\
 	archer-c7-v5)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
 		;;
 	cf-e355ac-v1|\
@@ -81,42 +49,42 @@ case "$FIRMWARE" in
 	oolite-v5.2-dev|\
 	sr3200|\
 	xd3200)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		;;
 	dap-2695-a1)
-		ath10kcal_extract "radiocfg" 20480 2116
+		mtd_eeprom_extract_check "radiocfg" 20480 2116
 		ath10kcal_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a)
 		;;
 	dir-869-a1|\
 	qihoo-c301)
-		ath10kcal_extract "radiocfg" 20480 2116
+		mtd_eeprom_extract_check "radiocfg" 20480 2116
 		ath10kcal_patch_mac $(mtd_get_mac_ascii devdata wlan5mac)
 		;;
 	dw33d)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(mtd_get_mac_binary art 18)
 		;;
 	epg5000|\
 	esr1750)
-		ath10kcal_extract "caldata" 20480 2116
+		mtd_eeprom_extract_check "caldata" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
 		;;
 	gl-ar750s|\
 	gl-ar750|\
 	tl-wpa8630)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
 		;;
 	koala)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary art 12) +0)
 		;;
 	mc-mac1200r)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
 		;;
 	r6100)
-		ath10kcal_extract "caldata" 20480 2116
+		mtd_eeprom_extract_check "caldata" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) +2)
 		;;
 	rb-952ui-5ac2nd|\
@@ -126,15 +94,15 @@ case "$FIRMWARE" in
 	re355|\
 	re450|\
 	tl-wr902ac-v1)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
 		;;
 	unifiac-lite|\
 	unifiac-pro)
-		ath10kcal_extract "EEPROM" 20480 2116
+		mtd_eeprom_extract_check "EEPROM" 20480 2116
 		;;
 	wi2a-ac200i)
-		ath10kcal_extract "ART" 20480 2116
+		mtd_eeprom_extract_check "ART" 20480 2116
 		;;
 	esac
 	;;
@@ -142,16 +110,16 @@ case "$FIRMWARE" in
 	case $board in
 	archer-c5|\
 	archer-c7)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
 		;;
 	nbg6616|\
 	nbg6716)
-		ath10kcal_extract "RFdata" 20480 2116
+		mtd_eeprom_extract_check "RFdata" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
 		;;
 	om5p-ac)
-		ath10kcal_extract "ART" 20480 2116
+		mtd_eeprom_extract_check "ART" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
 		;;
 	rb-911g-5hpacd|\
@@ -160,7 +128,7 @@ case "$FIRMWARE" in
 		ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
 		;;
 	wlr8100)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract_check "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1)
 		;;
 	esac
@@ -173,18 +141,18 @@ case "$FIRMWARE" in
 	archer-c60-v1|\
 	cf-e355ac-v2|\
 	cf-e375ac)
-		ath10kcal_extract "art" 20480 12064
+		mtd_eeprom_extract_check "art" 20480 12064
 		ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
 			/lib/firmware/ath10k/QCA9888/hw2.0/board.bin
 		;;
 	archer-c60-v2)
-		ath10kcal_extract "art" 20480 12064
+		mtd_eeprom_extract_check "art" 20480 12064
 		ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
 			/lib/firmware/ath10k/QCA9888/hw2.0/board.bin
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
 		;;
 	cf-e385ac)
-		ath10kcal_extract "art" 20480 12064
+		mtd_eeprom_extract_check "art" 20480 12064
 		;;
 	esac
 	;;
diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
index f4741fa3eb..50632a9a28 100644
--- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
+++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
@@ -1,6 +1,7 @@
 #!/bin/sh
 
 . /lib/functions/k2t.sh
+. /lib/functions/eeprom.sh
 
 # xor multiple hex values of the same length
 xor() {
@@ -18,34 +19,6 @@ xor() {
 	printf "%0${retlen}x" "$ret"
 }
 
-ath10kcal_die() {
-	echo "ath10cal: " "$*"
-	exit 1
-}
-
-ath10kcal_from_file() {
-	local source=$1
-	local offset=$2
-	local count=$3
-
-	dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath10kcal_die "failed to extract calibration data from $source"
-}
-
-ath10kcal_extract() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd
-
-	mtd=$(find_mtd_chardev $part)
-	[ -n "$mtd" ] || \
-		ath10kcal_die "no mtd device found for partition $part"
-
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath10kcal_die "failed to extract calibration data from $mtd"
-}
-
 ath10kcal_patch_mac() {
 	local mac=$1
 
@@ -92,52 +65,52 @@ case "$FIRMWARE" in
 	devolo,dvl1750c|\
 	devolo,dvl1750e|\
 	devolo,dvl1750i)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0) -1)
 		;;
 	dlink,dir-859-a1)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac $(mtd_get_mac_ascii devdata "wlan5mac")
 		;;
 	elecom,wrc-1750ghbk2-i)
-		ath10kcal_extract "ART" 20480 2116
+		mtd_eeprom_extract "ART" 20480 2116
 		;;
 	engenius,ews511ap|\
 	glinet,gl-ar750s|\
 	glinet,gl-x750|\
 	tplink,re450-v2)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
 		;;
 	iodata,wn-ac1167dgr|\
 	iodata,wn-ac1600dgr2)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1)
 		;;
 	nec,wg800hp)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac_crc $(mtd_get_mac_text board_data 2176)
 		;;
 	ocedo,koala)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac $(mtd_get_mac_binary art 12)
 		;;
 	openmesh,om5p-ac-v2)
-		ath10kcal_extract "ART" 20480 2116
+		mtd_eeprom_extract "ART" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
 		;;
 	tplink,archer-c2-v3)
-		ath10kcal_extract "ART" 20480 2116
+		mtd_eeprom_extract "ART" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
 		;;
 	tplink,archer-c7-v2)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
 		;;
 	tplink,archer-a7-v5|\
 	tplink,archer-c7-v4|\
 	tplink,archer-c7-v5)
-		ath10kcal_extract "art" 20480 2116
+		mtd_eeprom_extract "art" 20480 2116
 		ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
 		;;
 	ubnt,unifiac-lite|\
@@ -147,14 +120,14 @@ case "$FIRMWARE" in
 	ubnt,nanostation-ac|\
 	ubnt,nanostation-ac-loco|\
 	ubnt,unifiac-pro)
-		ath10kcal_extract "EEPROM" 20480 2116
+		mtd_eeprom_extract "EEPROM" 20480 2116
 		;;
 	esac
 	;;
 "ath10k/pre-cal-pci-0000:00:00.0.bin")
 	case $board in
 	phicomm,k2t)
-		ath10kcal_extract "art" 20480 12064
+		mtd_eeprom_extract "art" 20480 12064
 		ath10kcal_patch_mac_crc $(k2t_get_mac "5g_mac")
 		ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
 			/lib/firmware/ath10k/QCA9888/hw2.0/board.bin
@@ -162,7 +135,7 @@ case "$FIRMWARE" in
 	tplink,archer-c58-v1|\
 	tplink,archer-c59-v1|\
 	tplink,archer-c6-v2)
-		ath10kcal_extract "art" 20480 12064
+		mtd_eeprom_extract "art" 20480 12064
 		ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary mac 8) -1)
 		ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
 			/lib/firmware/ath10k/QCA9888/hw2.0/board.bin
-- 
2.11.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list