пт, 22 февр. 2019 г. в 16:57, Petr Štetiar <yn...@true.cz>: > > Dmitry Tunin <hanipouspi...@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. _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel