diff mbox series

[OpenWrt-Devel] ath79: speed up ath9k-eeprom extraction

Message ID 1550838639-32232-1-git-send-email-hanipouspilot@gmail.com
State Accepted, archived
Headers show
Series [OpenWrt-Devel] ath79: speed up ath9k-eeprom extraction | expand

Commit Message

Dmitry Tunin Feb. 22, 2019, 12:30 p.m. UTC
This is a simple copy of ipq40xx: speed up ath10k-caldata extraction commit /a69e101ed1169f562fc030a783cd997d3f066b16

Tested on DIR-825-B1

3768+0 records in
3768+0 records out
real	0m 11.90s
user	0m 0.03s
sys	0m 9.94s

1+0 records in
1+0 records out
real	0m 0.03s
user	0m 0.00s
sys	0m 0.03s

With this change eeprom extraction is fast enough to get working Wi-Fi after initial install.

Signed-off-by: Dmitry Tunin <hanipouspilot@gmail.com>
---
 target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Štetiar Feb. 22, 2019, 12:52 p.m. UTC | #1
Dmitry Tunin <hanipouspilot@gmail.com> [2019-02-22 15:30:39]:

Hi,

> Signed-off-by: Dmitry Tunin <hanipouspilot@gmail.com>
> ---
>  target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> index 8b217d1..84e4d07 100644
> --- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> +++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> @@ -20,7 +20,7 @@ ath9k_eeprom_extract() {
>  	[ -n "$mtd" ] || \
>  		ath9k_eeprom_die "no mtd device found for partition $part"
>  
> -	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> +	dd if=$mtd of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
>  		ath9k_eeprom_die "failed to extract from $mtd"
>  }

I'm wondering if this isn't a good opportunity to simply generalize this copy&paste galore:

apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom:        dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom:  dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata:        dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom:   dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata: dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
brcm63xx/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom:       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count || \
ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata:       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata:       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom: dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \

as a bonus all the platforms using the common code base couldn't benefit from this speed up.

-- ynezz
Dmitry Tunin Feb. 22, 2019, 1:13 p.m. UTC | #2
пт, 22 февр. 2019 г. в 15:53, Petr Štetiar <ynezz@true.cz>:
>
> Dmitry Tunin <hanipouspilot@gmail.com> [2019-02-22 15:30:39]:
>
> Hi,
>
> > Signed-off-by: Dmitry Tunin <hanipouspilot@gmail.com>
> > ---
> >  target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> > index 8b217d1..84e4d07 100644
> > --- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> > +++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> > @@ -20,7 +20,7 @@ ath9k_eeprom_extract() {
> >       [ -n "$mtd" ] || \
> >               ath9k_eeprom_die "no mtd device found for partition $part"
> >
> > -     dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> > +     dd if=$mtd of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
> >               ath9k_eeprom_die "failed to extract from $mtd"
> >  }
>
> I'm wondering if this isn't a good opportunity to simply generalize this copy&paste galore:

What do you mean by "generalize"? Fix it on all platforms, or having
common 10-ath9k-eeprom, 11-ath10k-caldata, etc files., or common code
that will be used on all platforms in some other file?
The first approach is obviously simple enough, but the second is not
that easy, but doable.

>
> apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom:        dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom:  dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata:        dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom:   dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata: dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> brcm63xx/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom:       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count || \
> ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata:       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata:       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom: dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
>
> as a bonus all the platforms using the common code base couldn't benefit from this speed up.
>
> -- ynezz
Petr Štetiar Feb. 22, 2019, 1:57 p.m. UTC | #3
Dmitry Tunin <hanipouspilot@gmail.com> [2019-02-22 16:13:52]:

> What do you mean by "generalize"? Fix it on all platforms, or having
> common 10-ath9k-eeprom, 11-ath10k-caldata, etc files., or common code
> that will be used on all platforms in some other file?
> The first approach is obviously simple enough, but the second is not
> that easy, but doable.

Simply moving common bits to some generic file which could be shared by all
platforms. Something like this for ar71xx, ath79 and ramips, untested. 

---
 package/base-files/files/lib/functions/eeprom.sh   | 54 ++++++++++++
 .../etc/hotplug.d/firmware/10-ath9k-eeprom         | 97 +++++-----------------
 .../etc/hotplug.d/firmware/10-ath9k-eeprom         | 84 +++++--------------
 .../etc/hotplug.d/firmware/10-rt2x00-eeprom        | 32 ++-----
 4 files changed, 106 insertions(+), 161 deletions(-)
 create mode 100644 package/base-files/files/lib/functions/eeprom.sh

diff --git a/package/base-files/files/lib/functions/eeprom.sh b/package/base-files/files/lib/functions/eeprom.sh
new file mode 100644
index 0000000..3b585da
--- /dev/null
+++ b/package/base-files/files/lib/functions/eeprom.sh
@@ -0,0 +1,54 @@
+. /lib/functions.sh
+. /lib/functions/system.sh
+
+eeprom_die() {
+	echo "eeprom: " "$*"
+	exit 1
+}
+
+mtd_eeprom_extract() {
+	local part=$1
+	local offset=$2
+	local count=$3
+	local mtd
+
+	mtd=$(find_mtd_chardev $part)
+	[ -n "$mtd" ] || \
+		eeprom_die "no mtd device found for partition $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
+	local count=$3
+	local mtd
+	local reversed
+	local caldata
+
+	mtd=$(find_mtd_chardev "$part")
+	reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
+
+	for byte in $reversed; do
+		caldata="\x${byte}${caldata}"
+	done
+
+	printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
+}
+
+ubi_eeprom_extract() {
+	local part=$1
+	local offset=$2
+	local count=$3
+	local ubidev=$(nand_find_ubi $CI_UBIPART)
+	local ubi
+
+	ubi=$(nand_find_volume $ubidev $part)
+	[ -n "$ubi" ] || \
+		eeprom_die "no UBI volume found for $part"
+
+	dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+		eeprom_die "failed to extract from $ubi"
+}
diff --git a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index 94bce7d..21808fb 100644
--- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -2,60 +2,7 @@
 
 [ -e /lib/firmware/$FIRMWARE ] && exit 0
 
-. /lib/functions.sh
-. /lib/functions/system.sh
-
-ath9k_eeprom_die() {
-	echo "ath9k eeprom: " "$*"
-	exit 1
-}
-
-ath9k_eeprom_extract() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd
-
-	mtd=$(find_mtd_chardev $part)
-	[ -n "$mtd" ] || \
-		ath9k_eeprom_die "no mtd device found for partition $part"
-
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath9k_eeprom_die "failed to extract from $mtd"
-}
-
-ath9k_ubi_eeprom_extract() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local ubidev=$(nand_find_ubi $CI_UBIPART)
-	local ubi
-
-	ubi=$(nand_find_volume $ubidev $part)
-	[ -n "$ubi" ] || \
-		ath9k_eeprom_die "no UBI volume found for $part"
-
-	dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath9k_eeprom_die "failed to extract from $ubi"
-}
-
-ath9k_eeprom_extract_reverse() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd
-	local reversed
-	local caldata
-
-	mtd=$(find_mtd_chardev "$part")
-	reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
-
-	for byte in $reversed; do
-		caldata="\x${byte}${caldata}"
-	done
-
-	printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
-}
+. /lib/functions/eeprom.sh
 
 ath9k_patch_firmware_mac() {
 	local mac=$1
@@ -72,48 +19,48 @@ case "$FIRMWARE" in
 	case $board in
 	c-55|\
 	c-60)
-		ath9k_eeprom_extract "art" 4096 2048
+		mtd_eeprom_extract "art" 4096 2048
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +1)
 		;;
 	fritz4020|\
 	fritz450e)
-		ath9k_eeprom_extract_reverse "urlader" 5441 1088
+		mtd_eeprom_extract_reverse "urlader" 5441 1088
 		;;
 	mr18)
 		. /lib/upgrade/nand.sh
 
 		if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
-			ath9k_ubi_eeprom_extract "caldata" 4096 2048
+			ubi_eeprom_extract "caldata" 4096 2048
 		else
-			ath9k_eeprom_extract "odm-caldata" 4096 2048
+			mtd_eeprom_extract "odm-caldata" 4096 2048
 		fi
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +1)
 		;;
 	r6100 | \
 	wndr3700v4 | \
 	wndr4300)
-		ath9k_eeprom_extract "caldata" 4096 2048
+		mtd_eeprom_extract "caldata" 4096 2048
 		ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 0)
 		;;
 	rambutan)
-		ath9k_eeprom_extract "art" 4096 2048
+		mtd_eeprom_extract "art" 4096 2048
 		;;
 	wlr8100)
-		ath9k_eeprom_extract "art" 4096 2048
+		mtd_eeprom_extract "art" 4096 2048
 		ath9k_patch_firmware_mac $(mtd_get_mac_ascii u-boot-env "ethaddr")
 		;;
 	z1)
 		. /lib/upgrade/nand.sh
 
 		if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
-			ath9k_ubi_eeprom_extract "caldata" 4096 2048
+			ubi_eeprom_extract "caldata" 4096 2048
 		else
-			ath9k_eeprom_extract "origcaldata" 4096 2048
+			mtd_eeprom_extract "origcaldata" 4096 2048
 		fi
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
@@ -121,39 +68,39 @@ case "$FIRMWARE" in
 "pci_wmac0.eeprom")
 	case $board in
 	c-55)
-		ath9k_eeprom_extract "art" 20480 2048
+		mtd_eeprom_extract "art" 20480 2048
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +2)
 		;;
 	fritz300e)
-		ath9k_eeprom_extract_reverse "urloader" 5441 1088
+		mtd_eeprom_extract_reverse "urloader" 5441 1088
 		;;
 	mr18)
 		. /lib/upgrade/nand.sh
 
 		if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
-			ath9k_ubi_eeprom_extract "caldata" 20480 2048
+			ubi_eeprom_extract "caldata" 20480 2048
 		else
-			ath9k_eeprom_extract "odm-caldata" 20480 2048
+			mtd_eeprom_extract "odm-caldata" 20480 2048
 		fi
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
 		;;
 	wndr3700v4 | \
 	wndr4300)
-		ath9k_eeprom_extract "caldata" 20480 2048
+		mtd_eeprom_extract "caldata" 20480 2048
 		ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 12)
 		;;
 	z1)
 		. /lib/upgrade/nand.sh
 
 		if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
-			ath9k_ubi_eeprom_extract "caldata" 86016 4096
+			ubi_eeprom_extract "caldata" 86016 4096
 		else
-			ath9k_eeprom_extract "origcaldata" 86016 4096
+			mtd_eeprom_extract "origcaldata" 86016 4096
 		fi
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
@@ -164,14 +111,14 @@ case "$FIRMWARE" in
 		. /lib/upgrade/nand.sh
 
 		if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
-			ath9k_ubi_eeprom_extract "caldata" 36864 2048
+			ubi_eeprom_extract "caldata" 36864 2048
 		else
-			ath9k_eeprom_extract "odm-caldata" 36864 2048
+			mtd_eeprom_extract "odm-caldata" 36864 2048
 		fi
 		ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index 8b217d1..8979075 100644
--- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -2,45 +2,7 @@
 
 [ -e /lib/firmware/$FIRMWARE ] && exit 0
 
-. /lib/functions.sh
-. /lib/functions/system.sh
-
-ath9k_eeprom_die() {
-	echo "ath9k eeprom: " "$*"
-	exit 1
-}
-
-ath9k_eeprom_extract() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd
-
-	mtd=$(find_mtd_chardev $part)
-	[ -n "$mtd" ] || \
-		ath9k_eeprom_die "no mtd device found for partition $part"
-
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		ath9k_eeprom_die "failed to extract from $mtd"
-}
-
-ath9k_eeprom_extract_reverse() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd
-	local reversed
-	local caldata
-
-	mtd=$(find_mtd_chardev "$part")
-	reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
-
-	for byte in $reversed; do
-		caldata="\x${byte}${caldata}"
-	done
-
-	printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
-}
+. /lib/functions/eeprom.sh
 
 xor() {
 	local val
@@ -98,50 +60,50 @@ case "$FIRMWARE" in
 "ath9k-eeprom-ahb-18100000.wmac.bin")
 	case $board in
 	avm,fritz4020)
-		ath9k_eeprom_extract_reverse "urlader" 5441 1088
+		mtd_eeprom_extract_reverse "urlader" 5441 1088
 		;;
 	dlink,dir-825-c1|\
 	dlink,dir-835-a1)
-		ath9k_eeprom_extract "art" 4096 1088
+		mtd_eeprom_extract "art" 4096 1088
 		ath9k_patch_fw_mac_crc $(mtd_get_mac_text "mac" 4) 2
 		;;
 	dlink,dir-859-a1)
-		ath9k_eeprom_extract "art" 4096 1088
+		mtd_eeprom_extract "art" 4096 1088
 		ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 2
 		;;
 	iodata,wn-ac1167dgr|\
 	iodata,wn-ac1600dgr|\
 	iodata,wn-ac1600dgr2|\
 	iodata,wn-ag300dgr)
-		ath9k_eeprom_extract "art" 4096 1088
+		mtd_eeprom_extract "art" 4096 1088
 		ath9k_patch_fw_mac $(mtd_get_mac_ascii u-boot-env ethaddr) 2
 		;;
 	nec,wg800hp)
-		ath9k_eeprom_extract "art" 4096 1088
+		mtd_eeprom_extract "art" 4096 1088
 		ath9k_patch_fw_mac $(mtd_get_mac_text board_data 1664) 2
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
 "ath9k-eeprom-pci-0000:00:00.0.bin")
 	case $board in
 	avm,fritz300e)
-		ath9k_eeprom_extract_reverse "urloader" 5441 1088
+		mtd_eeprom_extract_reverse "urloader" 5441 1088
 		;;
 	buffalo,whr-g301n|\
 	buffalo,wzr-hp-g302h-a1a0|\
 	tplink,tl-wr841-v5|\
 	tplink,tl-wr941-v4)
-		ath9k_eeprom_extract "art" 4096 3768
+		mtd_eeprom_extract "art" 4096 3768
 		;;
 	buffalo,wzr-hp-g450h)
-		ath9k_eeprom_extract "ART" 4096 1088
+		mtd_eeprom_extract "ART" 4096 1088
 		;;
 	dlink,dir-825-c1|\
 	dlink,dir-835-a1)
-		ath9k_eeprom_extract "art" 20480 1088
+		mtd_eeprom_extract "art" 20480 1088
 		ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "mac" 24) 1) 2
 		;;
 	ocedo,raccoon|\
@@ -149,7 +111,7 @@ case "$FIRMWARE" in
 	tplink,tl-wdr4300|\
 	tplink,tl-wdr4900-v2|\
 	winchannel,wb2000)
-		ath9k_eeprom_extract "art" 20480 1088
+		mtd_eeprom_extract "art" 20480 1088
 		;;
 	netgear,wnr612-v2|\
 	on,n150r|\
@@ -167,20 +129,20 @@ case "$FIRMWARE" in
 	ubnt,bullet-m|\
 	ubnt,nano-m|\
 	ubnt,rocket-m)
-		ath9k_eeprom_extract "art" 4096 4096
+		mtd_eeprom_extract "art" 4096 4096
 		;;
 	pqi,air-pen)
-		ath9k_eeprom_extract "art" 4096 2002
+		mtd_eeprom_extract "art" 4096 2002
 		;;
 	ubnt,unifi)
-		ath9k_eeprom_extract "art" 4096 2048
+		mtd_eeprom_extract "art" 4096 2048
 		;;
 	wd,mynet-wifi-rangeextender)
-		ath9k_eeprom_extract "art" 4096 4096
+		mtd_eeprom_extract "art" 4096 4096
 		ath9k_patch_fw_mac_crc $(nvram get wl0_hwaddr) "$mac" 2
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
@@ -190,14 +152,14 @@ case "$FIRMWARE" in
 	netgear,wndr3700|\
 	netgear,wndr3700v2|\
 	netgear,wndr3800)
-		ath9k_eeprom_extract "art" 4096 3768
+		mtd_eeprom_extract "art" 4096 3768
 		;;
 	dlink,dir-825-b1)
-		ath9k_eeprom_extract "caldata" 4096 3768
+		mtd_eeprom_extract "caldata" 4096 3768
 		ath9k_patch_fw_mac_crc $(mtd_get_mac_text "caldata" 65440) 524
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
@@ -207,14 +169,14 @@ case "$FIRMWARE" in
 	netgear,wndr3700|\
 	netgear,wndr3700v2|\
 	netgear,wndr3800)
-		ath9k_eeprom_extract "art" 20480 3768
+		mtd_eeprom_extract "art" 20480 3768
 		;;
 	dlink,dir-825-b1)
-		ath9k_eeprom_extract "caldata" 20480 3768
+		mtd_eeprom_extract "caldata" 20480 3768
 		ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "caldata" 65460) 1) 524
 		;;
 	*)
-		ath9k_eeprom_die "board $board is not supported yet"
+		eeprom_die "board $board is not supported yet"
 		;;
 	esac
 	;;
diff --git a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
index 13a4687..60b0e68 100644
--- a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
+++ b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
@@ -1,24 +1,5 @@
 #!/bin/sh
 
-rt2x00_eeprom_die() {
-	echo "rt2x00 eeprom: " "$*"
-	exit 1
-}
-
-rt2x00_eeprom_extract() {
-	local part=$1
-	local offset=$2
-	local count=$3
-	local mtd
-
-	mtd=$(find_mtd_part $part)
-	[ -n "$mtd" ] || \
-		rt2x00_eeprom_die "no mtd device found for partition $part"
-
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
-		rt2x00_eeprom_die "failed to extract from $mtd"
-}
-
 jboot_eeprom_extract() {
 	local part=$1
 	local offset=$2
@@ -26,21 +7,21 @@ jboot_eeprom_extract() {
 
 	mtd=$(find_mtd_part $part)
 	[ -n "$mtd" ] || \
-		rt2x00_eeprom_die "no mtd device found for partition $part"
+		eeprom_die "no mtd device found for partition $part"
 
 	jboot_config_read -i $mtd -o $offset -e /lib/firmware/$FIRMWARE  2>/dev/null || \
-		rt2x00_eeprom_die "failed to extract from $mtd"
+		eeprom_die "failed to extract from $mtd"
 }
 
 rt2x00_eeprom_set_macaddr() {
 	local macaddr=$1
 
 	[ -n "$macaddr" ] || \
-		rt2x00_eeprom_die "invalid wlan mac address"
+		eeprom_die "invalid wlan mac address"
 
 	macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
 				conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
-		rt2x00_eeprom_die "failed to write mac address to eeprom file"
+		eeprom_die "failed to write mac address to eeprom file"
 }
 
 FW="/lib/firmware/$FIRMWARE"
@@ -48,6 +29,7 @@ FW="/lib/firmware/$FIRMWARE"
 
 . /lib/functions.sh
 . /lib/functions/system.sh
+. /lib/functions/eeprom.sh
 
 board=$(board_name)
 
@@ -67,11 +49,11 @@ case "$FIRMWARE" in
 		;;
 	tiny-ac)
 		wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
-		rt2x00_eeprom_extract "factory" 0 512
+		mtd_eeprom_extract "factory" 0 512
 		rt2x00_eeprom_set_macaddr $wifi_mac
 		;;
 	*)
-		rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
+		eeprom_die "Please define mtd-eeprom in $board DTS file!"
 		;;
 	esac
 	;;

-- ynezz
Dmitry Tunin Feb. 22, 2019, 2:32 p.m. UTC | #4
пт, 22 февр. 2019 г. в 16:57, Petr Štetiar <ynezz@true.cz>:
>
> Dmitry Tunin <hanipouspilot@gmail.com> [2019-02-22 16:13:52]:
>
> > What do you mean by "generalize"? Fix it on all platforms, or having
> > common 10-ath9k-eeprom, 11-ath10k-caldata, etc files., or common code
> > that will be used on all platforms in some other file?
> > The first approach is obviously simple enough, but the second is not
> > that easy, but doable.
>
> Simply moving common bits to some generic file which could be shared by all
> platforms. Something like this for ar71xx, ath79 and ramips, untested.
>
> ---
>  package/base-files/files/lib/functions/eeprom.sh   | 54 ++++++++++++
>  .../etc/hotplug.d/firmware/10-ath9k-eeprom         | 97 +++++-----------------
>  .../etc/hotplug.d/firmware/10-ath9k-eeprom         | 84 +++++--------------
>  .../etc/hotplug.d/firmware/10-rt2x00-eeprom        | 32 ++-----
>  4 files changed, 106 insertions(+), 161 deletions(-)
>  create mode 100644 package/base-files/files/lib/functions/eeprom.sh
>
> diff --git a/package/base-files/files/lib/functions/eeprom.sh b/package/base-files/files/lib/functions/eeprom.sh
> new file mode 100644
> index 0000000..3b585da
> --- /dev/null
> +++ b/package/base-files/files/lib/functions/eeprom.sh
> @@ -0,0 +1,54 @@
> +. /lib/functions.sh
> +. /lib/functions/system.sh
> +
> +eeprom_die() {
> +       echo "eeprom: " "$*"
> +       exit 1
> +}
> +
> +mtd_eeprom_extract() {
> +       local part=$1
> +       local offset=$2
> +       local count=$3
> +       local mtd
> +
> +       mtd=$(find_mtd_chardev $part)
> +       [ -n "$mtd" ] || \
> +               eeprom_die "no mtd device found for partition $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
> +       local count=$3
> +       local mtd
> +       local reversed
> +       local caldata
> +
> +       mtd=$(find_mtd_chardev "$part")
> +       reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
> +
> +       for byte in $reversed; do
> +               caldata="\x${byte}${caldata}"
> +       done
> +
> +       printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
> +}
> +
> +ubi_eeprom_extract() {
> +       local part=$1
> +       local offset=$2
> +       local count=$3
> +       local ubidev=$(nand_find_ubi $CI_UBIPART)
> +       local ubi
> +
> +       ubi=$(nand_find_volume $ubidev $part)
> +       [ -n "$ubi" ] || \
> +               eeprom_die "no UBI volume found for $part"
> +
> +       dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> +               eeprom_die "failed to extract from $ubi"
> +}
> diff --git a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> index 94bce7d..21808fb 100644
> --- a/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> +++ b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> @@ -2,60 +2,7 @@
>
>  [ -e /lib/firmware/$FIRMWARE ] && exit 0
>
> -. /lib/functions.sh
> -. /lib/functions/system.sh
> -
> -ath9k_eeprom_die() {
> -       echo "ath9k eeprom: " "$*"
> -       exit 1
> -}
> -
> -ath9k_eeprom_extract() {
> -       local part=$1
> -       local offset=$2
> -       local count=$3
> -       local mtd
> -
> -       mtd=$(find_mtd_chardev $part)
> -       [ -n "$mtd" ] || \
> -               ath9k_eeprom_die "no mtd device found for partition $part"
> -
> -       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> -               ath9k_eeprom_die "failed to extract from $mtd"
> -}
> -
> -ath9k_ubi_eeprom_extract() {
> -       local part=$1
> -       local offset=$2
> -       local count=$3
> -       local ubidev=$(nand_find_ubi $CI_UBIPART)
> -       local ubi
> -
> -       ubi=$(nand_find_volume $ubidev $part)
> -       [ -n "$ubi" ] || \
> -               ath9k_eeprom_die "no UBI volume found for $part"
> -
> -       dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> -               ath9k_eeprom_die "failed to extract from $ubi"
> -}
> -
> -ath9k_eeprom_extract_reverse() {
> -       local part=$1
> -       local offset=$2
> -       local count=$3
> -       local mtd
> -       local reversed
> -       local caldata
> -
> -       mtd=$(find_mtd_chardev "$part")
> -       reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
> -
> -       for byte in $reversed; do
> -               caldata="\x${byte}${caldata}"
> -       done
> -
> -       printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
> -}
> +. /lib/functions/eeprom.sh
>
>  ath9k_patch_firmware_mac() {
>         local mac=$1
> @@ -72,48 +19,48 @@ case "$FIRMWARE" in
>         case $board in
>         c-55|\
>         c-60)
> -               ath9k_eeprom_extract "art" 4096 2048
> +               mtd_eeprom_extract "art" 4096 2048
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +1)
>                 ;;
>         fritz4020|\
>         fritz450e)
> -               ath9k_eeprom_extract_reverse "urlader" 5441 1088
> +               mtd_eeprom_extract_reverse "urlader" 5441 1088
>                 ;;
>         mr18)
>                 . /lib/upgrade/nand.sh
>
>                 if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
> -                       ath9k_ubi_eeprom_extract "caldata" 4096 2048
> +                       ubi_eeprom_extract "caldata" 4096 2048
>                 else
> -                       ath9k_eeprom_extract "odm-caldata" 4096 2048
> +                       mtd_eeprom_extract "odm-caldata" 4096 2048
>                 fi
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +1)
>                 ;;
>         r6100 | \
>         wndr3700v4 | \
>         wndr4300)
> -               ath9k_eeprom_extract "caldata" 4096 2048
> +               mtd_eeprom_extract "caldata" 4096 2048
>                 ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 0)
>                 ;;
>         rambutan)
> -               ath9k_eeprom_extract "art" 4096 2048
> +               mtd_eeprom_extract "art" 4096 2048
>                 ;;
>         wlr8100)
> -               ath9k_eeprom_extract "art" 4096 2048
> +               mtd_eeprom_extract "art" 4096 2048
>                 ath9k_patch_firmware_mac $(mtd_get_mac_ascii u-boot-env "ethaddr")
>                 ;;
>         z1)
>                 . /lib/upgrade/nand.sh
>
>                 if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
> -                       ath9k_ubi_eeprom_extract "caldata" 4096 2048
> +                       ubi_eeprom_extract "caldata" 4096 2048
>                 else
> -                       ath9k_eeprom_extract "origcaldata" 4096 2048
> +                       mtd_eeprom_extract "origcaldata" 4096 2048
>                 fi
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
> @@ -121,39 +68,39 @@ case "$FIRMWARE" in
>  "pci_wmac0.eeprom")
>         case $board in
>         c-55)
> -               ath9k_eeprom_extract "art" 20480 2048
> +               mtd_eeprom_extract "art" 20480 2048
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +2)
>                 ;;
>         fritz300e)
> -               ath9k_eeprom_extract_reverse "urloader" 5441 1088
> +               mtd_eeprom_extract_reverse "urloader" 5441 1088
>                 ;;
>         mr18)
>                 . /lib/upgrade/nand.sh
>
>                 if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
> -                       ath9k_ubi_eeprom_extract "caldata" 20480 2048
> +                       ubi_eeprom_extract "caldata" 20480 2048
>                 else
> -                       ath9k_eeprom_extract "odm-caldata" 20480 2048
> +                       mtd_eeprom_extract "odm-caldata" 20480 2048
>                 fi
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
>                 ;;
>         wndr3700v4 | \
>         wndr4300)
> -               ath9k_eeprom_extract "caldata" 20480 2048
> +               mtd_eeprom_extract "caldata" 20480 2048
>                 ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 12)
>                 ;;
>         z1)
>                 . /lib/upgrade/nand.sh
>
>                 if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
> -                       ath9k_ubi_eeprom_extract "caldata" 86016 4096
> +                       ubi_eeprom_extract "caldata" 86016 4096
>                 else
> -                       ath9k_eeprom_extract "origcaldata" 86016 4096
> +                       mtd_eeprom_extract "origcaldata" 86016 4096
>                 fi
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
> @@ -164,14 +111,14 @@ case "$FIRMWARE" in
>                 . /lib/upgrade/nand.sh
>
>                 if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
> -                       ath9k_ubi_eeprom_extract "caldata" 36864 2048
> +                       ubi_eeprom_extract "caldata" 36864 2048
>                 else
> -                       ath9k_eeprom_extract "odm-caldata" 36864 2048
> +                       mtd_eeprom_extract "odm-caldata" 36864 2048
>                 fi
>                 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
> diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> index 8b217d1..8979075 100644
> --- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> +++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
> @@ -2,45 +2,7 @@
>
>  [ -e /lib/firmware/$FIRMWARE ] && exit 0
>
> -. /lib/functions.sh
> -. /lib/functions/system.sh
> -
> -ath9k_eeprom_die() {
> -       echo "ath9k eeprom: " "$*"
> -       exit 1
> -}
> -
> -ath9k_eeprom_extract() {
> -       local part=$1
> -       local offset=$2
> -       local count=$3
> -       local mtd
> -
> -       mtd=$(find_mtd_chardev $part)
> -       [ -n "$mtd" ] || \
> -               ath9k_eeprom_die "no mtd device found for partition $part"
> -
> -       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> -               ath9k_eeprom_die "failed to extract from $mtd"
> -}
> -
> -ath9k_eeprom_extract_reverse() {
> -       local part=$1
> -       local offset=$2
> -       local count=$3
> -       local mtd
> -       local reversed
> -       local caldata
> -
> -       mtd=$(find_mtd_chardev "$part")
> -       reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
> -
> -       for byte in $reversed; do
> -               caldata="\x${byte}${caldata}"
> -       done
> -
> -       printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
> -}
> +. /lib/functions/eeprom.sh
>
>  xor() {
>         local val
> @@ -98,50 +60,50 @@ case "$FIRMWARE" in
>  "ath9k-eeprom-ahb-18100000.wmac.bin")
>         case $board in
>         avm,fritz4020)
> -               ath9k_eeprom_extract_reverse "urlader" 5441 1088
> +               mtd_eeprom_extract_reverse "urlader" 5441 1088
>                 ;;
>         dlink,dir-825-c1|\
>         dlink,dir-835-a1)
> -               ath9k_eeprom_extract "art" 4096 1088
> +               mtd_eeprom_extract "art" 4096 1088
>                 ath9k_patch_fw_mac_crc $(mtd_get_mac_text "mac" 4) 2
>                 ;;
>         dlink,dir-859-a1)
> -               ath9k_eeprom_extract "art" 4096 1088
> +               mtd_eeprom_extract "art" 4096 1088
>                 ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 2
>                 ;;
>         iodata,wn-ac1167dgr|\
>         iodata,wn-ac1600dgr|\
>         iodata,wn-ac1600dgr2|\
>         iodata,wn-ag300dgr)
> -               ath9k_eeprom_extract "art" 4096 1088
> +               mtd_eeprom_extract "art" 4096 1088
>                 ath9k_patch_fw_mac $(mtd_get_mac_ascii u-boot-env ethaddr) 2
>                 ;;
>         nec,wg800hp)
> -               ath9k_eeprom_extract "art" 4096 1088
> +               mtd_eeprom_extract "art" 4096 1088
>                 ath9k_patch_fw_mac $(mtd_get_mac_text board_data 1664) 2
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
>  "ath9k-eeprom-pci-0000:00:00.0.bin")
>         case $board in
>         avm,fritz300e)
> -               ath9k_eeprom_extract_reverse "urloader" 5441 1088
> +               mtd_eeprom_extract_reverse "urloader" 5441 1088
>                 ;;
>         buffalo,whr-g301n|\
>         buffalo,wzr-hp-g302h-a1a0|\
>         tplink,tl-wr841-v5|\
>         tplink,tl-wr941-v4)
> -               ath9k_eeprom_extract "art" 4096 3768
> +               mtd_eeprom_extract "art" 4096 3768
>                 ;;
>         buffalo,wzr-hp-g450h)
> -               ath9k_eeprom_extract "ART" 4096 1088
> +               mtd_eeprom_extract "ART" 4096 1088
>                 ;;
>         dlink,dir-825-c1|\
>         dlink,dir-835-a1)
> -               ath9k_eeprom_extract "art" 20480 1088
> +               mtd_eeprom_extract "art" 20480 1088
>                 ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "mac" 24) 1) 2
>                 ;;
>         ocedo,raccoon|\
> @@ -149,7 +111,7 @@ case "$FIRMWARE" in
>         tplink,tl-wdr4300|\
>         tplink,tl-wdr4900-v2|\
>         winchannel,wb2000)
> -               ath9k_eeprom_extract "art" 20480 1088
> +               mtd_eeprom_extract "art" 20480 1088
>                 ;;
>         netgear,wnr612-v2|\
>         on,n150r|\
> @@ -167,20 +129,20 @@ case "$FIRMWARE" in
>         ubnt,bullet-m|\
>         ubnt,nano-m|\
>         ubnt,rocket-m)
> -               ath9k_eeprom_extract "art" 4096 4096
> +               mtd_eeprom_extract "art" 4096 4096
>                 ;;
>         pqi,air-pen)
> -               ath9k_eeprom_extract "art" 4096 2002
> +               mtd_eeprom_extract "art" 4096 2002
>                 ;;
>         ubnt,unifi)
> -               ath9k_eeprom_extract "art" 4096 2048
> +               mtd_eeprom_extract "art" 4096 2048
>                 ;;
>         wd,mynet-wifi-rangeextender)
> -               ath9k_eeprom_extract "art" 4096 4096
> +               mtd_eeprom_extract "art" 4096 4096
>                 ath9k_patch_fw_mac_crc $(nvram get wl0_hwaddr) "$mac" 2
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
> @@ -190,14 +152,14 @@ case "$FIRMWARE" in
>         netgear,wndr3700|\
>         netgear,wndr3700v2|\
>         netgear,wndr3800)
> -               ath9k_eeprom_extract "art" 4096 3768
> +               mtd_eeprom_extract "art" 4096 3768
>                 ;;
>         dlink,dir-825-b1)
> -               ath9k_eeprom_extract "caldata" 4096 3768
> +               mtd_eeprom_extract "caldata" 4096 3768
>                 ath9k_patch_fw_mac_crc $(mtd_get_mac_text "caldata" 65440) 524
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
> @@ -207,14 +169,14 @@ case "$FIRMWARE" in
>         netgear,wndr3700|\
>         netgear,wndr3700v2|\
>         netgear,wndr3800)
> -               ath9k_eeprom_extract "art" 20480 3768
> +               mtd_eeprom_extract "art" 20480 3768
>                 ;;
>         dlink,dir-825-b1)
> -               ath9k_eeprom_extract "caldata" 20480 3768
> +               mtd_eeprom_extract "caldata" 20480 3768
>                 ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "caldata" 65460) 1) 524
>                 ;;
>         *)
> -               ath9k_eeprom_die "board $board is not supported yet"
> +               eeprom_die "board $board is not supported yet"
>                 ;;
>         esac
>         ;;
> diff --git a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
> index 13a4687..60b0e68 100644
> --- a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
> +++ b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
> @@ -1,24 +1,5 @@
>  #!/bin/sh
>
> -rt2x00_eeprom_die() {
> -       echo "rt2x00 eeprom: " "$*"
> -       exit 1
> -}
> -
> -rt2x00_eeprom_extract() {
> -       local part=$1
> -       local offset=$2
> -       local count=$3
> -       local mtd
> -
> -       mtd=$(find_mtd_part $part)
> -       [ -n "$mtd" ] || \
> -               rt2x00_eeprom_die "no mtd device found for partition $part"
> -
> -       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
> -               rt2x00_eeprom_die "failed to extract from $mtd"
> -}
> -
>  jboot_eeprom_extract() {
>         local part=$1
>         local offset=$2
> @@ -26,21 +7,21 @@ jboot_eeprom_extract() {
>
>         mtd=$(find_mtd_part $part)
>         [ -n "$mtd" ] || \
> -               rt2x00_eeprom_die "no mtd device found for partition $part"
> +               eeprom_die "no mtd device found for partition $part"
>
>         jboot_config_read -i $mtd -o $offset -e /lib/firmware/$FIRMWARE  2>/dev/null || \
> -               rt2x00_eeprom_die "failed to extract from $mtd"
> +               eeprom_die "failed to extract from $mtd"
>  }
>
>  rt2x00_eeprom_set_macaddr() {
>         local macaddr=$1
>
>         [ -n "$macaddr" ] || \
> -               rt2x00_eeprom_die "invalid wlan mac address"
> +               eeprom_die "invalid wlan mac address"
>
>         macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
>                                 conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
> -               rt2x00_eeprom_die "failed to write mac address to eeprom file"
> +               eeprom_die "failed to write mac address to eeprom file"
>  }
>
>  FW="/lib/firmware/$FIRMWARE"
> @@ -48,6 +29,7 @@ FW="/lib/firmware/$FIRMWARE"
>
>  . /lib/functions.sh
>  . /lib/functions/system.sh
> +. /lib/functions/eeprom.sh
>
>  board=$(board_name)
>
> @@ -67,11 +49,11 @@ case "$FIRMWARE" in
>                 ;;
>         tiny-ac)
>                 wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
> -               rt2x00_eeprom_extract "factory" 0 512
> +               mtd_eeprom_extract "factory" 0 512
>                 rt2x00_eeprom_set_macaddr $wifi_mac
>                 ;;
>         *)
> -               rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
> +               eeprom_die "Please define mtd-eeprom in $board DTS file!"
>                 ;;
>         esac
>         ;;
>
> -- ynezz

The only problem here is that not all platforms need it.
Christian Lamparter Feb. 25, 2019, 6:20 p.m. UTC | #5
On Friday, February 22, 2019 3:32:03 PM CET Dmitry Tunin wrote:
> пт, 22 февр. 2019 г. в 16:57, Petr Štetiar <ynezz@true.cz>:
> >
> > Dmitry Tunin <hanipouspilot@gmail.com> [2019-02-22 16:13:52]:
> >
> > > What do you mean by "generalize"? Fix it on all platforms, or having
> > > common 10-ath9k-eeprom, 11-ath10k-caldata, etc files., or common code
> > > that will be used on all platforms in some other file?
> > > The first approach is obviously simple enough, but the second is not
> > > that easy, but doable.
> >
> > Simply moving common bits to some generic file which could be shared by all
> > platforms. Something like this for ar71xx, ath79 and ramips, untested.
> > [...]
> >
> > -- ynezz
> 

If I may add something to the discussion, that's probably not on everyone's
radar (apart from mtd-cal-data binding we all know). The plan for the future
is to make use of the upcoming mtd->nvmem provider brigde for both the
caldata and the mac-address update (interestingly enough, this started with
the ipq806x mac-patching thread:
<https://www.mail-archive.com/openwrt-devel@lists.openwrt.org/msg44616.html>
Only after playing with 950-call-of_get_mac_address-from-device.patch 
I stumbled onto the nvmem development).

Support for reading MTD via the nvmem API was added upstream by commit:
|commit c4dfa25ab307a277eafa7067cd927fbe4d9be4ba
|Author: Alban Bedel <albeu@free.fr>
|Date:   Tue Nov 13 15:01:10 2018 +0100
|
|    mtd: add support for reading MTD devices via the nvmem API
|    
|    Allow drivers that use the nvmem API to read data stored on MTD devices.
|    For this the mtd devices are registered as read-only NVMEM providers.
|    
|    We don't support device tree systems for now.

and

|commit 517f14d9cf3533d5ab4fded195ab6f80a92e378f
|Author: Bartosz Golaszewski <bgolaszewski@baylibre.com>
|Date:   Fri Nov 30 11:53:25 2018 +0000
|
|   nvmem: add new config option
|    
|   We want to add nvmem support for MTD. TI DaVinci is the first platform
|   that will be using it, but only in non-DT mode. In order not to
|   introduce any new interface to supporting of which we would have to
|   commit - add a new config option that tells nvmem not to use the DT
|   node of the parent device.
|    
|   This way we won't be creating nvmem devices corresponding with MTD
|   partitions defined in device tree. By default MTD will set this new
|   field to true.
|   
|   Once a set of bindings for MTD nvmem cells is agreed upon, we'll be
|   able to remove this option.

So the idea right now is that once upstream agreed upon whatever they want
to do with the binding, is to introduce that method and earmark it for new
devices (and people that want to convert their own device). The extraction
scripts will be left in place as a fallback mainly for devices that can't
use the nvmem provider (caldata in a ubi volume, reversed data, etc...).

> The only problem here is that not all platforms need it.
The problem I always have is more along the way that a patch should receive
some "on-device" testing. So I do look forward for patches that received a
"Tested-by:" tag or has positive replies from random/unlikely people. But
we sadly all know that this system has its limits.

Regards,
Christian
Dmitry Tunin Feb. 25, 2019, 6:31 p.m. UTC | #6
пн, 25 февр. 2019 г. в 21:20, Christian Lamparter <chunkeey@gmail.com>:

> > The only problem here is that not all platforms need it.
> The problem I always have is more along the way that a patch should receive
> some "on-device" testing. So I do look forward for patches that received a
> "Tested-by:" tag or has positive replies from random/unlikely people. But
> we sadly all know that this system has its limits.

In this case mine is really tested on a device if that really matters
in this case;-)
I don't think there can be any problems with this simple approach.

Regarding "not all devices" I meant that that eeprom.sh when added to
global base-files, will be useless for many platforms.
I added DIR-825B1 to ath79 and it needed some hacks to get eeprom and
mac, there is no way to upstream this type of methods. But it is an
old device.

But without these patches many devices have disabled wireless on first
boot after flashing, because caldata is not ready in time. Fixing this
annoying behavior is important.
Adrian Schmutzler Feb. 25, 2019, 7 p.m. UTC | #7
> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org] On
> Behalf Of Dmitry Tunin
> Sent: Montag, 25. Februar 2019 19:31
> To: Christian Lamparter <chunkeey@gmail.com>
> Cc: Adrian Schmutzler <freifunk@adrianschmutzler.de>; Petr Štetiar
> <ynezz@true.cz>; openwrt-devel@lists.openwrt.org
> Subject: Re: [OpenWrt-Devel] [PATCH] ath79: speed up ath9k-eeprom
> extraction
> 
> пн, 25 февр. 2019 г. в 21:20, Christian Lamparter <chunkeey@gmail.com>:
> 
> > > The only problem here is that not all platforms need it.
> > The problem I always have is more along the way that a patch should receive
> > some "on-device" testing. So I do look forward for patches that received a
> > "Tested-by:" tag or has positive replies from random/unlikely people. But
> > we sadly all know that this system has its limits.
> 
> In this case mine is really tested on a device if that really matters
> in this case;-)
> I don't think there can be any problems with this simple approach.

Well, then let's take yours for the moment and I will build and test patches based on that during the week. (ar71xx/ath79)

Despite that, my patch 3/3 is platform-specific (and will thus not be subject to code merging) and might be merged right ahead, unless you want to wait for testing here, too.

BTW: Sorry for topposting, I'm not used to avoiding that.

Best

Adrian

> 
> Regarding "not all devices" I meant that that eeprom.sh when added to
> global base-files, will be useless for many platforms.
> I added DIR-825B1 to ath79 and it needed some hacks to get eeprom and
> mac, there is no way to upstream this type of methods. But it is an
> old device.
> 
> But without these patches many devices have disabled wireless on first
> boot after flashing, because caldata is not ready in time. Fixing this
> annoying behavior is important.
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Adrian Schmutzler Feb. 25, 2019, 11:13 p.m. UTC | #8
Hi Dmitry,

I just sent a bunch of patches based on your initial patch.

Note that your patch is only stored as comment to another and lacks Signed-off, if I'm not mistaken.

Will try to test all of this during the week.

Best

Adrian

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> On Behalf Of Dmitry Tunin
> Sent: Montag, 25. Februar 2019 19:31
> To: Christian Lamparter <chunkeey@gmail.com>
> Cc: Adrian Schmutzler <freifunk@adrianschmutzler.de>; Petr Štetiar
> <ynezz@true.cz>; openwrt-devel@lists.openwrt.org
> Subject: Re: [OpenWrt-Devel] [PATCH] ath79: speed up ath9k-eeprom
> extraction
> 
> пн, 25 февр. 2019 г. в 21:20, Christian Lamparter <chunkeey@gmail.com>:
> 
> > > The only problem here is that not all platforms need it.
> > The problem I always have is more along the way that a patch should
> > receive some "on-device" testing. So I do look forward for patches
> > that received a "Tested-by:" tag or has positive replies from
> > random/unlikely people. But we sadly all know that this system has its
> limits.
> 
> In this case mine is really tested on a device if that really matters in this case;-
> ) I don't think there can be any problems with this simple approach.
> 
> Regarding "not all devices" I meant that that eeprom.sh when added to
> global base-files, will be useless for many platforms.
> I added DIR-825B1 to ath79 and it needed some hacks to get eeprom and
> mac, there is no way to upstream this type of methods. But it is an old
> device.
> 
> But without these patches many devices have disabled wireless on first boot
> after flashing, because caldata is not ready in time. Fixing this annoying
> behavior is important.
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Adrian Schmutzler Feb. 26, 2019, 1:03 p.m. UTC | #9
> -----Original Message-----
> From: Dmitry Tunin [mailto:hanipouspilot@gmail.com]
> Sent: Dienstag, 26. Februar 2019 10:45
> To: Adrian Schmutzler <mail@adrianschmutzler.de>
> Subject: Re: [OpenWrt-Devel] [PATCH] ath79: speed up ath9k-eeprom
> extraction
> 
> вт, 26 февр. 2019 г. в 02:13, <mail@adrianschmutzler.de>:
> >
> > Hi Dmitry,
> >
> > I just sent a bunch of patches based on your initial patch.
> >
> > Note that your patch is only stored as comment to another and lacks Signed-
> off, if I'm not mistaken.
> That wasn't my patch. It was a comment to my initial patch as an
> opinion how to do it better.
> 

Ah, now I finally get it.
Sorry for the noise.

So, since you were first and your real initial patch is tested, I suppose it should be applied.

Despite that, some feedback about whether the merging in eeprom.sh is an accepted way to go would be helpful.

If no, I would rebase my first patchset (changing dd in-place) on Dmitry's real patch.

If yes, either Petr Štetiar can resend his patch proposal or allow me to "take it over", and I go on with my second patchset (moving all to eeprom.sh).

What will it be?

Best

Adrian


> 
> >
> > Will try to test all of this during the week.
> >
> > Best
> >
> > Adrian
> >
> > > -----Original Message-----
> > > From: openwrt-devel [mailto:openwrt-devel-bounces@lists.openwrt.org]
> > > On Behalf Of Dmitry Tunin
> > > Sent: Montag, 25. Februar 2019 19:31
> > > To: Christian Lamparter <chunkeey@gmail.com>
> > > Cc: Adrian Schmutzler <freifunk@adrianschmutzler.de>; Petr Štetiar
> > > <ynezz@true.cz>; openwrt-devel@lists.openwrt.org
> > > Subject: Re: [OpenWrt-Devel] [PATCH] ath79: speed up ath9k-eeprom
> > > extraction
> > >
> > > пн, 25 февр. 2019 г. в 21:20, Christian Lamparter <chunkeey@gmail.com>:
> > >
> > > > > The only problem here is that not all platforms need it.
> > > > The problem I always have is more along the way that a patch should
> > > > receive some "on-device" testing. So I do look forward for patches
> > > > that received a "Tested-by:" tag or has positive replies from
> > > > random/unlikely people. But we sadly all know that this system has its
> > > limits.
> > >
> > > In this case mine is really tested on a device if that really matters in this
> case;-
> > > ) I don't think there can be any problems with this simple approach.
> > >
> > > Regarding "not all devices" I meant that that eeprom.sh when added to
> > > global base-files, will be useless for many platforms.
> > > I added DIR-825B1 to ath79 and it needed some hacks to get eeprom and
> > > mac, there is no way to upstream this type of methods. But it is an old
> > > device.
> > >
> > > But without these patches many devices have disabled wireless on first boot
> > > after flashing, because caldata is not ready in time. Fixing this annoying
> > > behavior is important.
> > >
> > > _______________________________________________
> > > openwrt-devel mailing list
> > > openwrt-devel@lists.openwrt.org
> > > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
> > _______________________________________________
> > openwrt-devel mailing list
> > openwrt-devel@lists.openwrt.org
> > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Dmitry Tunin Feb. 26, 2019, 1:34 p.m. UTC | #10
вт, 26 февр. 2019 г. в 16:03, Adrian Schmutzler <mail@adrianschmutzler.de>:
>
> > -----Original Message-----
> > From: Dmitry Tunin [mailto:hanipouspilot@gmail.com]
> > Sent: Dienstag, 26. Februar 2019 10:45
> > To: Adrian Schmutzler <mail@adrianschmutzler.de>
> > Subject: Re: [OpenWrt-Devel] [PATCH] ath79: speed up ath9k-eeprom
> > extraction
> >
> > вт, 26 февр. 2019 г. в 02:13, <mail@adrianschmutzler.de>:
> > >
> > > Hi Dmitry,
> > >
> > > I just sent a bunch of patches based on your initial patch.
> > >
> > > Note that your patch is only stored as comment to another and lacks Signed-
> > off, if I'm not mistaken.
> > That wasn't my patch. It was a comment to my initial patch as an
> > opinion how to do it better.
> >
>
> Ah, now I finally get it.
> Sorry for the noise.
>
> So, since you were first and your real initial patch is tested, I suppose it should be applied.
>
> Despite that, some feedback about whether the merging in eeprom.sh is an accepted way to go would be helpful.
>
> If no, I would rebase my first patchset (changing dd in-place) on Dmitry's real patch.
>
> If yes, either Petr Štetiar can resend his patch proposal or allow me to "take it over", and I go on with my second patchset (moving all to eeprom.sh).
>
> What will it be?
>

My opinion is that I have no opinion really. It's important to speedup
that process, but everything else is very minor.
Using eeprom.sh needs a bit of testing on  many platforms, but I am
already 99.9% sure it'll work OK.

The other part with changing dd's that patch mac addresses can be or
not. I don't really care, because it is catching fractions of seconds.
It looks OK for me too.

Petr posted his variant to me most likely with intention that I or
someone else takes care of it properly. So it would be very good if
you finish the job the way you like.
If it can be properly tested on every target would be great.
diff mbox series

Patch

diff --git a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
index 8b217d1..84e4d07 100644
--- a/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
+++ b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
@@ -20,7 +20,7 @@  ath9k_eeprom_extract() {
 	[ -n "$mtd" ] || \
 		ath9k_eeprom_die "no mtd device found for partition $part"
 
-	dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
+	dd if=$mtd of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
 		ath9k_eeprom_die "failed to extract from $mtd"
 }