From patchwork Wed Feb 27 22:18:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1049169 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="i/uwuiaT"; 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 448qpz4FF8z9sBF for ; Thu, 28 Feb 2019 09:19:23 +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=/o31gIYT4GrPExZ4iijOq/RfKZW91A129/9y1ZgplGI=; b=i/uwuiaTpvmCMuQdxi5MbkTpWW LNCZYD82FIR9OUtlQz97oGQ/+45pYCiXu9lSJ1reUD3lCX+0wyNpux/Bx8DrrnRaaTa0hJBPSxnh/ wbLWd5+aS02QZ7KBpeuJBeOI2fIVI9KHoKZusCBK0qSgLO40ncNa3w5p8ah3+vtx7SpgkkDy/rTbB 9gau44c8VenXtyehj4OQROfkygXHcGaxUQPcmf6BvCsiCUX3Vux6HXDLPDZwGbzDVxwZ1WNFImLr7 N1MQ65/vnE3NIEB65UHQdjuYMX4Aq/6BIh0oCv2JKCQnXY2lzHh41Er739xr3fnpkFEX12uVkNS6B Paq6LO+Q==; 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 1gz7Xo-0005C8-5q; Wed, 27 Feb 2019 22:19:16 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gz7Wr-0003o3-GU for openwrt-devel@lists.openwrt.org; Wed, 27 Feb 2019 22:18:21 +0000 Received: from localhost.localdomain ([188.194.105.77]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MlO9r-1hQVFg2Kh3-00liHp for ; Wed, 27 Feb 2019 23:18:13 +0100 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Wed, 27 Feb 2019 23:18:07 +0100 Message-Id: <20190227221809.1697-5-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190227221809.1697-1-freifunk@adrianschmutzler.de> References: <20190227221809.1697-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:Zwx09Qx2aoTkJN7GYosLoGZH82egUUgrFKZU0du0u7JgRvadoBJ 7qT2bxuITAutK58PP/XnLY+FvyVMNUrR5UrkyUYyxHejxaGWQ8/ZWC2D6Q5BfBXIWTlaiy8 nLjw2BZVRZugXrfol69XZLxPiDwBgcTSAhxVz5bjr7g+lw/XhxlGQJWHDvBN4uTpux9Xzwu +M+ZIK84u1kfXibOd7Tfg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:DWq5NdRgmKw=:m3KRXuk28EyGSb+P21HYGM Jf6NUEH4iZvi3ghcnqV5Kq2ikf6irpaBXYAMGdfiwWcAaidH7nLovOPR8whhoGTTQIZAkqzFM 1N8Iuyxb8JO47WxvNm5TS6iP3AYhayBF02bl19WBQm01OhRNvchb5tu4DgIH/uOL7aGbE2Iky AQSshBZoaOPkgmrcImUegQyHENNT7RyO1bFNnV/iqDD0GcKkt3Sxsw4fo9vk/pwCgJG+xc23G +JVQE5bMkduKXLnG3FAd7IUWAvyiJ/17z9gPPvJnA3sioLxYbNRS66vcLoVG+MW/9NfvfRn14 4p8+tewUqVEm+pg3byvHbrs3HGXqOLa8V262VzvLlc8+mA109L4KelFO8FmUv1Yfxx0inWzKq 7LD7qh5EDtyq89yLNOhsn6wNzKK+g5C7+6dDYus1rLbAN/ZiSfV1WqVLv66sb1vru8WoTddPS g7F7becOOscPQZnOR2NFFDZAYwNXVsMl98FoSMRRtDu8gVsIj1pMqia5FptcmuWmeWeEgoDHW gKkjppwLyyf01tBFl8G/7Sdz6ozXX2X6+MhDcouHHi6WvBQSgKXxoj07pjyFss5y9AxBeH3Y9 VTjMStrxduv1uryfwNC8R4219SFmndby7MckVS+FsHjPY3CSyJkI4rB9iA6zTAhFezFUhRGbB JSW6JKQ85odstLIBlpIxN1CYnvIWVLI5Add9c/r5wCdHNXbBPMlwCIuT7aTSFsISDJu/ixBRf qf8hCsR14iEM6Lriw+4NqgBJxafjNF4By25KiXdu5o0kC5eJpiQtbHqIe1LkYN+ENiP6JuuRw XSRYdMR X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190227_141818_004036_BEB36F67 X-CRM114-Status: GOOD ( 14.99 ) 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 http://www.dnswl.org/, no trust [217.72.192.73 listed in list.dnswl.org] Subject: [OpenWrt-Devel] [PATCH v3 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. --- 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 a19c0c2478..76a6f2ced6 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,52 +62,52 @@ case "$FIRMWARE" in devolo,dvl1750c|\ devolo,dvl1750e|\ devolo,dvl1750i) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0) -1) ;; dlink,dir-859-a1) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata "wlan5mac") ;; elecom,wrc-1750ghbk2-i) - ath10kcal_extract "ART" 20480 2116 + mtd_eeprom_extract "ART" 20480 2116 ;; engenius,ews511ap|\ glinet,gl-ar750s|\ glinet,gl-x750|\ tplink,re450-v2) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1) ;; iodata,wn-ac1167dgr|\ iodata,wn-ac1600dgr2) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1) ;; nec,wg800hp) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac_crc $(mtd_get_mac_text board_data 2176) ;; ocedo,koala) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac $(mtd_get_mac_binary art 12) ;; openmesh,om5p-ac-v2) - ath10kcal_extract "ART" 20480 2116 + mtd_eeprom_extract "ART" 20480 2116 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16) ;; tplink,archer-c2-v3) - ath10kcal_extract "ART" 20480 2116 + mtd_eeprom_extract "ART" 20480 2116 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1) ;; tplink,archer-c7-v2) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1) ;; tplink,archer-a7-v5|\ tplink,archer-c7-v4|\ tplink,archer-c7-v5) - ath10kcal_extract "art" 20480 2116 + mtd_eeprom_extract "art" 20480 2116 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1) ;; ubnt,unifiac-lite|\ @@ -147,14 +117,14 @@ case "$FIRMWARE" in ubnt,nanostation-ac|\ ubnt,nanostation-ac-loco|\ ubnt,unifiac-pro) - ath10kcal_extract "EEPROM" 20480 2116 + mtd_eeprom_extract "EEPROM" 20480 2116 ;; esac ;; "ath10k/pre-cal-pci-0000:00:00.0.bin") case $board in phicomm,k2t) - ath10kcal_extract "art" 20480 12064 + mtd_eeprom_extract "art" 20480 12064 ath10kcal_patch_mac_crc $(k2t_get_mac "5g_mac") ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \ /lib/firmware/ath10k/QCA9888/hw2.0/board.bin @@ -162,7 +132,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