From patchwork Fri Mar 1 14:40:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1050234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adrianschmutzler.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="US6am7Vw"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449sYw0vNLz9s2R for ; Sat, 2 Mar 2019 01:41:40 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZjLPwA5VO4RswIgbTKEv96CCu3cxR3TfriL+d1s5pOY=; b=US6am7VwFL3nGA7MK/hXUpJg/X tmUWvH0QAe6EtP76oPlFD38KiJV7lio2/6wkBebhKmPNBKVVbngU90sniIchS94SwB1iDvRjI3Bvu ImnBfCFD5ua0eZzpmKoHRk2QjzxXvLSCYdh2msjaOQ3Rn4/1OrYk2XUqR8oCdAeUXxzFULOKCt0Ns seTKy9ZruAxiCE/KqV60o4RQzJ856h3LkIWUA6IzQQTbG/0+01dmbsAxMGsk8sOqhlI9qhuyhL1JO OQH3hr0GMgKzlbTpm9WzQu9tiY2J8+/TlfacBkhjy45akRs1dxK36T8vuS+FTJ7rCo/N/QA/NFmKr 7qdJIh1w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzjLw-0007Hc-S4; Fri, 01 Mar 2019 14:41:32 +0000 Received: from mout.kundenserver.de ([212.227.126.135]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gzjKx-0005pV-Rj for openwrt-devel@lists.openwrt.org; Fri, 01 Mar 2019 14:40:38 +0000 Received: from localhost.localdomain ([188.194.105.77]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N6bPS-1h3hti0IZy-0183pG for ; Fri, 01 Mar 2019 15:40:28 +0100 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Fri, 1 Mar 2019 15:40:20 +0100 Message-Id: <20190301144022.1984-5-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190301144022.1984-1-freifunk@adrianschmutzler.de> References: <20190301144022.1984-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Jt6HttbK/CL3jDgY4cPKS0Si3p+ccfXUzO7+YRBT1/yUDebDR1e 6+ylcjx4F/K2r7+TYuZMvEjhORGJuTTbgWJu3BJouWp1SWabbVVkrN5F/v3lXl26j2wkrqO Jd7QvFOm8TsdFpRRLAcH7mJ5+ik2TUZpO1RRX87qpqED1TePz6gU0xQJ1uRByowDWZnYnIM jQqw26S2/368sXTOz8DXg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:ojZfmoo4PcE=:6/EyLUsrZqSHagqhECzpid IHFisM/Rx/rmfxgU1SVjzErve93IO/9JyKpAnPH/WP6XR5KbESUswnOxm8amUYQG/v0XeLksS HCxzAILGttJpVPuv2k9TbjvbO5ySi38fdJ6XHwnKcYIH50A5fyiGALl0I3RWZ85yv3wwrhtgt krq6JMb9O2QTRYYkq/vOzkRK3sj2T/FvH1fL7APJ/Wl16cxs65aUyyBvJONWBI4HHFg+8BI7h xKtwsnJ5hrB78wIKcqpD9iaLixh28sTOizFYaoW7T1OVp/me5r4jn4MwcfFouSzYR7Lod6OHT EGFi8v0AjlXdz5BzlRSDryNmDHlN9upMO5JoOkACNW+Fuu9xLVqNrsrN4ZTTmJ2dirENevJMW +8O6SpZLjREdI+KcE1wZvyCW3ilK3w/8spXubYE/mpVjntKfBmFNG7gLzSA4uWM80+L+iQGi6 zBlhaOgaaslWd0HtsjVC1k9PTiGDQKaiqbaOhcw211dMuzmbauYlXzcdtlwQDPsIMA4xEXLIP 0HgGE7MMRjnGN62KvDO68SzI/Mr4FR34s2PUYbh89cc+wFx5KN5OBaPlTrhwb+aM7aOrz2+tI vVs7cE57KBksB7/03H7QPLWnStng3YiJOmdcUI6SKZVzkp/sB5o9X/FoN+dAYTkSoDJmss4GC /vCL1x9ZGl1D0Ae8YlNHozT7yvfkoqBTR8SDvpiF8tw2cN/a8nM0pSHppcsEKbgFHPZNEnQaX QWlb23Fe+VVxgQUhbW5etq8a7u9Cselo9EsgI8lc4D3OndGVupFzXXP5moL+yktQJcSmhJdYI pJVdm4Q X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190301_064032_362673_64EF7448 X-CRM114-Status: GOOD ( 14.08 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [212.227.126.135 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [212.227.126.135 listed in wl.mailspike.net] Subject: [OpenWrt-Devel] [PATCH v4 4/6] ar71xx/ath79: Merge eeprom/caldata extraction into eeprom.sh X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org eeprom/caldata extraction is the same across different targets and also uses similar functions compared to each other. This patch is based on the proposed unification by Petr Štetiar. While this only covers ath79/ar71xx, others target supposedly will be merged easily. Signed-off-by: Adrian Schmutzler --- New in v3: Merged from the migration patches in my alternate patchset, which is obsoleted now. Changed in v4: - Rebased --- package/base-files/files/lib/functions/eeprom.sh | 88 ++++++++++++++++++++ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 97 +++++----------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 78 +++++------------ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 84 +++++-------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 60 ++++--------- 5 files changed, 171 insertions(+), 236 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 0000000000..80df3bb359 --- /dev/null +++ b/package/base-files/files/lib/functions/eeprom.sh @@ -0,0 +1,88 @@ +. /lib/functions.sh +. /lib/functions/system.sh + +eeprom_die() { + echo "eeprom: " "$*" + exit 1 +} + +ath10kcal_die() { + echo "ath10cal: " "$*" + 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 iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ + 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 iflag=skip_bytes bs=$count skip=$offset count=1 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 iflag=skip_bytes bs=$count skip=$offset count=1 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 iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ + ath10kcal_die "failed to extract calibration data from $source" +} 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 208d5f6bff..6b94b19ee7 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 iflag=skip_bytes bs=$count skip=$offset count=1 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 iflag=skip_bytes bs=$count skip=$offset count=1 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/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ar71xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index cd5c1c2bcb..37223686fb 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 iflag=skip_bytes bs=$count skip=$offset count=1 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 iflag=skip_bytes bs=$count skip=$offset count=1 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/10-ath9k-eeprom b/target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom index d8b292f4da..685bab4b05 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 iflag=skip_bytes bs=$count skip=$offset count=1 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/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index f8e385be68..52f9582e10 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 iflag=skip_bytes bs=$count skip=$offset count=1 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 iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ - ath10kcal_die "failed to extract calibration data from $mtd" -} - ath10kcal_patch_mac() { local mac=$1 @@ -79,9 +52,6 @@ ath10kcal_patch_mac_crc() { [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh -. /lib/functions/system.sh - board=$(board_name) case "$FIRMWARE" in @@ -92,53 +62,53 @@ 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-c5-v1|\ 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|\ @@ -148,14 +118,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 @@ -163,7 +133,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