From patchwork Sun Sep 8 14:10:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1159447 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="s//Vq4KK"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46RCrm0rjhz9sDB for ; Mon, 9 Sep 2019 00:11:20 +1000 (AEST) 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=UmrIHP7m4gsf6poR9Xmr8J2P0u4/jmFyxIHMfCTR9hg=; b=s//Vq4KKVpJo5vGJBm9eqPv1uz tBttaEKTGzXSnQiVabo0CXuWPOfCfyScsIUysAChiV91eptGKrNdcYvFum6upxYQN+7i+R1Ht05Fx 1TRMI1fq/rdq1yLM0uzhuNqxXFy3ecpGFwBhlqQ+mGY3f/aKTVmg3lyeiuVSDsCodMuKZcy5jNX91 /yE7h7h3zAm0TXCMLYtIhKbKDgDlIrKHaR1LqRNphlxVDFJl1XKb4XpGRk/WMJIJ3xPkoPP1uGsFb HIwIpRnYdmYXpLjVCXGjRanzgW3Qhka37NXIjrPIkwvVjhSDMIGA9LzBnWWcQWEwK8xSPytO051xW EYCIUh+g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i6xuQ-0007kg-1T; Sun, 08 Sep 2019 14:11:18 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i6xu8-00072A-1z for openwrt-devel@lists.openwrt.org; Sun, 08 Sep 2019 14:11:03 +0000 Received: from buildfff.adridolf.com ([188.193.187.204]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MFspV-1hvBWR1zQ7-00HNVR for ; Sun, 08 Sep 2019 16:10:56 +0200 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Sun, 8 Sep 2019 16:10:49 +0200 Message-Id: <20190908141052.17443-2-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190908141052.17443-1-freifunk@adrianschmutzler.de> References: <20190908141052.17443-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:dkeNhAE3Qi+L+/y/5Ha9CtgSbk2eAZjGEaPh6/9w0Js08QvzYge E017V7dAZmHzM0hTb7ybaMGihPeC6xPdLhCAhbYJnwkIl1+WyhQ0ZWaXzgAu0TIS+s40g0L xU1CcMiRMW1WT9K9Y6Y1nGzDqgdSkaFZbD3xw5suFZqdrJqZOGXFxIXotxx/F2Z7IuvV7qB 7dEhZkgqrWzBqNOKfQ68A== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:OlLOiY56RiM=:vr+MPcCQUaZHBOunwtQQoh i9jd1qvqDJdpXxxUB2EF9ZIPVGgz7r6c6HHgLcrLqJ5retdz7xDus8bhHNU43DPtyGD5hDPx1 TfndNFeX/0dXZUZUK9/Zdrba7d7WyancCCEKAs/qzG2rbTnE/uefOy8LdLELOEobOQJ8rD6iG oSr1aL53fNl1WMBx6zkc8O4Wrx+vMxRSSGdRfUXBI5f4wP+gdwLJFVYGk1lfKMhDqE73MOM2B TTsJWXolwBiI4GhCWMJUZoCtbNNt+xOIBYM2gM7RgpOOOyYJKN0QyBoiTrXnxBU1r9QMNncgo tKCL0ne8i33HUI/35o8qEe+RuxyD9EK6RPxNHQOBJ65QryblzNjke9zoBRUlUawpeagcuP0Ga Qa7of8YauiEpkUSWwTCAtY7hGv5loTDxsR5gRhT/lKB8w8ogjJ3AGY6dosiM4+H1TNLWeADR4 /S0TW0c/dNrsKR8oP24QB+By+TAzwbU9BAiOEH+K1NZ2cvUGmiZD4TF2KGs5GDvCwpFk9k2g3 JSGEYeyOpb6aMwyMVQ0QMmm+pgTqBPG+sGdhIzbUij7AHYc2R6vTBJ1we6ghoYmI8jZcq6OkQ PvndIxhzyU2wM7c+OsyhroA4Qbpc/zwGrjnG1aSr31RP3hNXCW6g5Sd1tVboBC6hm+Eq0Eluj p0Y+gyKjpBW2ZRj/npoBHgJab0NmiAG3OoHXwkGaOBh+RuAVMnN4A2PxxO5erdITZTn9MPV2A pgaDkt//wYrmjhr7j7QC2ubKpfYUjaN2fpxas6NNVA2xB4OHbH9Xx5BVBGM/u5L5nbZr7IFv+ RfxAAXc18H90kjBlPFn3/rFT+/3RfFic0Pji36XwkEdeiHfMniJIwxf4oLixl9XxlEMLUhg X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190908_071100_432518_EDA66EFC X-CRM114-Status: UNSURE ( 8.35 ) X-CRM114-Notice: Please train this message. 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 [217.72.192.75 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH 1/4] base-files: move xor() from caldata extraction to functions.sh X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 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 The xor() function is defined in each of the caldata extraction scripts for several targets. Move it to functions.sh to reduce duplicate code. Signed-off-by: Adrian Schmutzler --- package/base-files/files/lib/functions.sh | 16 ++++++++++++++++ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 15 --------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 18 +----------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 17 +---------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 17 +---------------- .../etc/hotplug.d/firmware/12-ath9k-eeprom | 16 ---------------- 6 files changed, 19 insertions(+), 80 deletions(-) diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index 860fc04510..81176431d1 100755 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -17,6 +17,22 @@ NO_EXPORT=1 LOAD_STATE=1 LIST_SEP=" " +# xor multiple hex values of the same length +xor() { + local val + local ret="0x$1" + local retlen=${#1} + + shift + while [ -n "$1" ]; do + val="0x$1" + ret=$((ret ^ val)) + shift + done + + printf "%0${retlen}x" "$ret" +} + append() { local var="$1" local value="$2" 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 f07dbf83c4..450f85b0fe 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 @@ -42,21 +42,6 @@ ath9k_eeprom_extract_reverse() { printf "%b" "$caldata" > /lib/firmware/$FIRMWARE } -xor() { - local val - local ret="0x$1" - local retlen=${#1} - - shift - while [ -n "$1" ]; do - val="0x$1" - ret=$((ret ^ val)) - shift - done - - printf "%0${retlen}x" "$ret" -} - ath9k_patch_fw_mac() { local mac=$1 local mac_offset=$(($2)) 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 ed3432273c..6e79094e0c 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,23 +1,8 @@ #!/bin/sh +. /lib/functions.sh . /lib/functions/k2t.sh -# xor multiple hex values of the same length -xor() { - local val - local ret="0x$1" - local retlen=${#1} - - shift - while [ -n "$1" ]; do - val="0x$1" - ret=$((ret ^ val)) - shift - done - - printf "%0${retlen}x" "$ret" -} - ath10kcal_die() { echo "ath10cal: " "$*" exit 1 @@ -79,7 +64,6 @@ ath10kcal_patch_mac_crc() { [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh . /lib/functions/system.sh board=$(board_name) diff --git a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index be57646128..dfb0a0cf76 100644 --- a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -1,20 +1,6 @@ #!/bin/sh -# xor multiple hex values of the same length -xor() { - local val - local ret="0x$1" - local retlen=${#1} - - shift - while [ -n "$1" ]; do - val="0x$1" - ret=$((ret ^ val)) - shift - done - - printf "%0${retlen}x" "$ret" -} +. /lib/functions.sh ath10kcal_die() { echo "ath10cal: " "$*" @@ -88,7 +74,6 @@ ath10kcal_is_caldata_valid() { [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh . /lib/functions/system.sh board=$(board_name) diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index bdc36070f2..c0fb1db16d 100644 --- a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -1,20 +1,6 @@ #!/bin/sh -# xor multiple hex values of the same length -xor() { - local val - local ret="0x$1" - local retlen=${#1} - - shift - while [ -n "$1" ]; do - val="0x$1" - ret=$((ret ^ val)) - shift - done - - printf "%0${retlen}x" "$ret" -} +. /lib/functions.sh ath10kcal_die() { echo "ath10cal: " "$*" @@ -71,7 +57,6 @@ ath10kcal_patch_mac_crc() { [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh . /lib/functions/system.sh board=$(board_name) diff --git a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom index 82f6885221..5f3eb0cfe3 100644 --- a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom +++ b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom @@ -7,22 +7,6 @@ . /lib/functions/system.sh . /lib/upgrade/nand.sh -# xor multiple hex values of the same length -xor() { - local val - local ret="0x$1" - local retlen=${#1} - - shift - while [ -n "$1" ]; do - val="0x$1" - ret=$((ret ^ val)) - shift - done - - printf "%0${retlen}x" "$ret" -} - ath9k_eeprom_die() { echo "ath9k eeprom: $*" exit 1 From patchwork Sun Sep 8 14:10:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1159449 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="sfpj/eZ+"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46RCs74xy0z9sDB for ; Mon, 9 Sep 2019 00:11:39 +1000 (AEST) 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=CHs5X0UNUgPd1QHom3/jwuVZzlXKKr4Z8FKioeWcsZ4=; b=sfpj/eZ+myotYkGEWrVbhjW6eu +HD22xSwKpfyFk2w38BwQ8Km3weYf54F3sObGWUwBFGvHqSOev9zWQRUPD/FmEblTA/h2Fdix9TRZ aSXtYz0CVoQVCV8F0C+tD6nmKr37zh/GhV1QUKEEb0x9kaQgoc/w+C9h1kvP4zsaX07C1T9eMWnGx eDzx/k9zGGPQ3xsekcndCG46rk9JWRpGzYOMvt81E/v+EMY5KqCC5BseVe6v9wP0W2f9aCdeXHoOp o9J8zAaqPHwO+obDwOHzYzROVQDdCyvMqhw+WIl8R67r8EVwp0dNFvwWIcXN5DCJu8uS9RGyuf65X 67j5jU9w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i6xuj-0008Ho-Pi; Sun, 08 Sep 2019 14:11:37 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i6xu8-00072C-3p for openwrt-devel@lists.openwrt.org; Sun, 08 Sep 2019 14:11:04 +0000 Received: from buildfff.adridolf.com ([188.193.187.204]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1Mr8O8-1iSbWo2cwY-00oFLs for ; Sun, 08 Sep 2019 16:10:56 +0200 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Sun, 8 Sep 2019 16:10:50 +0200 Message-Id: <20190908141052.17443-3-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190908141052.17443-1-freifunk@adrianschmutzler.de> References: <20190908141052.17443-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:+CRT2i+ZCb1ZrUoGq64KMSZAgoE0g/yOmvxbv2gwm6Z/UjqJasI XAUOlEFEdH5nDvz3AoNr9lMdFYwpqpQDVbcWixwUJ0FQKz1Xy1IOoCerwwMuQvOu9LyQUTU nmnSWF4Vvxr2Fq2/xbaVSeWY+NkWGr0TP9hnDETx7awd73HytUewr9wN0En6A7h/C7Hyhq2 Zp9IY+hMEM5UOZN6OcHRA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:jEXW9oj7GvI=:Zb6TknnPY9AjZfB7PsoGhE AMnZty/5XcJrZopNDkIXE+grYvfLgM6Q2u1QyuPu05ZkGB4UMFaJOMeln1hTSWj7wrJ4afNmV di8lEU6WJnc4w03ZRvcebFmEP57hs6wnZPnyCX1m2magpneLXS/Vil3rptJPt8h+iRbOzZ6gx zU/dMS3yyd5QKTZSDdV4MtJA9Jzp095UP5cEkEwaNYrN7PPkEymRp3k2b+czkVOJMm8z40BJ6 f9Y35wpFy1ih6TopRUcQxbcI+t7uuH4l/eYPXgqvQj7yT7ZIUMCiMZEWdoQYCnl8Bq0C3jMNV BLjm36tA7yJhc4uygbcRMapET7ctRn1mpE2jRhjpI0XzilJXL8D7sDB32n2xg4Vs3lyFZ7lw9 uYjKeG3DhhyRMgIVN9ms8t+mtmAODbVX9SESQ1kio3aWuTLnzRPsR6im8pBoJcVwrBDhoYRNQ q7LZpn8OI9HotTj4ie8V7L0pMfg5aHfA1Bin8mU9/9tFG3laRtgB3lFF99mU0Tm/JXJaoAdQo +RGewXVSTZILoTJToL7s6Ik93GmlOeEPhKdGNcZJsrXeLYIRio7p4bH9KbI0NBILyEx8hhB08 x2Go2JeGd8nwoxB9z5NPxyuO/oMKpNtfabDeLB0ZoYNtdKsRThUfc0F4ZZ9drOqguPxtWNfgY MK3hJLG8lhJ/nav0uQKw+n0CzRlJB0xknDUe6HA6ZnlAIeFTmuoC7xD5lncEwRw9IsLpQHihB kY+sIDAiBnaw6Y/QP5daI5//i4Ow80xSQiCx3NNY27tyQKzklGj7sKktZnJPHL15w905rM32H BDb0dEV07Il6mLA4AeAiUrpvJYsHz/vGRt1m8s3mMkR7a6tfT2yn/LXV2Z9u+DV3kTNdNuE X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190908_071100_752222_A4114FD9 X-CRM114-Status: GOOD ( 15.85 ) 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 [217.72.192.73 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH 2/4] treewide: move calibration data extraction function to library X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 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 This moves the almost identical calibration data extraction functions present multiple times in several targets to a single library file /lib/functions/caldata.sh. Functions are renamed with more generic names to merge different variants that only differ in their names. Most of the targets used find_mtd_chardev, while some used find_mtd_part inside the extraction code. To merge them, the more abundant version with find_mtd_chardev is used in the common code. Signed-off-by: Adrian Schmutzler --- Open questions: 1. I tested find_mtd_chardev and find_mtd_part on mpc85xx, both gave the same result (one uses /dev/mtd*, the other one uses /dev/mtdblock*). Is there any difference or advantage of one over the other in this use-case? 2. For mpc85xx, there is a chained command with "dd if=... | dd of..." used for caldata extraction. I'm a bit surprised about the use of $count and $offset there and would be glad if someone had a look. --- .../base-files/files/lib/functions/caldata.sh | 75 +++++++++++++ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 49 ++------- .../etc/hotplug.d/firmware/10-ath9k-eeprom | 90 +++++----------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 84 +++++---------- .../etc/hotplug.d/firmware/10-rt2x00-eeprom | 27 +---- .../etc/hotplug.d/firmware/11-ath10k-caldata | 101 +++++------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 62 +++-------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 28 +---- .../etc/hotplug.d/firmware/12-ath9k-eeprom | 36 ++----- .../etc/hotplug.d/firmware/10-ath9k-eeprom | 24 ++--- .../etc/hotplug.d/firmware/10-rt2x00-eeprom | 37 ++----- 11 files changed, 207 insertions(+), 406 deletions(-) create mode 100644 package/base-files/files/lib/functions/caldata.sh diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-files/files/lib/functions/caldata.sh new file mode 100644 index 0000000000..f2a306675f --- /dev/null +++ b/package/base-files/files/lib/functions/caldata.sh @@ -0,0 +1,75 @@ +# Copyright (C) 2019 OpenWrt.org + +. /lib/functions.sh +. /lib/functions/system.sh + +caldata_die() { + echo "caldata: " "$*" + exit 1 +} + +caldata_extract() { + local part=$1 + local offset=$(($2)) + local count=$(($3)) + local mtd + + mtd=$(find_mtd_chardev $part) + [ -n "$mtd" ] || caldata_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 || \ + caldata_die "failed to extract calibration data from $mtd" +} + +caldata_extract_ubi() { + local part=$1 + local offset=$(($2)) + local count=$(($3)) + local ubidev + local ubi + + . /lib/upgrade/nand.sh + + ubidev=$(nand_find_ubi $CI_UBIPART) + ubi=$(nand_find_volume $ubidev $part) + [ -n "$ubi" ] || caldata_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 || \ + caldata_die "failed to extract calibration data from $ubi" +} + +caldata_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 +} + +caldata_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 || \ + caldata_die "failed to extract calibration data from $source" +} + +caldata_valid() { + local expected="$1" + + magic=$(hexdump -v -n 2 -e '1/1 "%02x"' /lib/firmware/$FIRMWARE) + [[ "$magic" == "$expected" ]] + return $? +} + diff --git a/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom index 272c084c99..07100b1856 100644 --- a/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom +++ b/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom @@ -2,42 +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" -} +. /lib/functions/caldata.sh ath9k_patch_firmware_mac() { local mac=$1 @@ -56,14 +21,14 @@ case "$FIRMWARE" in . /lib/upgrade/nand.sh if [ -n "$(nand_find_volume ubi0 caldata)" ]; then - ath9k_ubi_eeprom_extract "caldata" 0x5000 0x1000 + caldata_extract_ubi "caldata" 0x5000 0x1000 else - ath9k_eeprom_extract "wifi_data" 0x5000 0x1000 + caldata_extract "wifi_data" 0x5000 0x1000 ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 0xc) fi ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; @@ -74,14 +39,14 @@ case "$FIRMWARE" in . /lib/upgrade/nand.sh if [ -n "$(nand_find_volume ubi0 caldata)" ]; then - ath9k_ubi_eeprom_extract "caldata" 0x1000 0x1000 + caldata_extract_ubi "caldata" 0x1000 0x1000 else - ath9k_eeprom_extract "wifi_data" 0x1000 0x1000 + caldata_extract "wifi_data" 0x1000 0x1000 ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 0x0) fi ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_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 450f85b0fe..3432014f60 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/caldata.sh ath9k_patch_fw_mac() { local mac=$1 @@ -83,11 +45,11 @@ case "$FIRMWARE" in "ath9k-eeprom-ahb-18100000.wmac.bin") case $board in avm,fritz4020) - ath9k_eeprom_extract_reverse "urlader" 0x1541 0x440 + caldata_extract_reverse "urlader" 0x1541 0x440 ;; dlink,dir-825-c1|\ dlink,dir-835-a1) - ath9k_eeprom_extract "art" 0x1000 0x440 + caldata_extract "art" 0x1000 0x440 ath9k_patch_fw_mac_crc $(mtd_get_mac_text "mac" 0x4) 0x2 ;; dlink,dir-842-c1|\ @@ -96,11 +58,11 @@ case "$FIRMWARE" in dlink,dir-859-a1|\ nec,wg1200cr|\ wd,mynet-n750) - ath9k_eeprom_extract "art" 0x1000 0x440 + caldata_extract "art" 0x1000 0x440 ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 0x2 ;; engenius,ecb1750) - ath9k_eeprom_extract "art" 0x1000 0x440 + caldata_extract "art" 0x1000 0x440 ath9k_patch_fw_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env "athaddr") +1) 0x2 ;; engenius,epg5000|\ @@ -108,39 +70,39 @@ case "$FIRMWARE" in iodata,wn-ac1600dgr|\ iodata,wn-ac1600dgr2|\ iodata,wn-ag300dgr) - ath9k_eeprom_extract "art" 0x1000 0x440 + caldata_extract "art" 0x1000 0x440 ath9k_patch_fw_mac $(mtd_get_mac_ascii u-boot-env ethaddr) 0x2 ;; nec,wg800hp) - ath9k_eeprom_extract "art" 0x1000 0x440 + caldata_extract "art" 0x1000 0x440 ath9k_patch_fw_mac $(mtd_get_mac_text board_data 0x680) 0x2 ;; qihoo,c301) - ath9k_eeprom_extract "radiocfg" 0x1000 0x440 + caldata_extract "radiocfg" 0x1000 0x440 ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 0x2 ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_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" 0x1541 0x440 + caldata_extract_reverse "urloader" 0x1541 0x440 ;; buffalo,whr-g301n|\ buffalo,wzr-hp-g302h-a1a0|\ tplink,tl-wr841-v5|\ tplink,tl-wr941-v4) - ath9k_eeprom_extract "art" 0x1000 0xeb8 + caldata_extract "art" 0x1000 0xeb8 ;; buffalo,wzr-hp-g450h) - ath9k_eeprom_extract "art" 0x1000 0x440 + caldata_extract "art" 0x1000 0x440 ;; dlink,dir-825-c1|\ dlink,dir-835-a1) - ath9k_eeprom_extract "art" 0x5000 0x440 + caldata_extract "art" 0x5000 0x440 ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "mac" 0x18) 1) 0x2 ;; ocedo,raccoon|\ @@ -149,7 +111,7 @@ case "$FIRMWARE" in tplink,tl-wdr4300-v1|\ tplink,tl-wdr4900-v2|\ winchannel,wb2000) - ath9k_eeprom_extract "art" 0x5000 0x440 + caldata_extract "art" 0x5000 0x440 ;; netgear,wnr612-v2|\ on,n150r|\ @@ -167,24 +129,24 @@ case "$FIRMWARE" in ubnt,bullet-m|\ ubnt,nano-m|\ ubnt,rocket-m) - ath9k_eeprom_extract "art" 0x1000 0x1000 + caldata_extract "art" 0x1000 0x1000 ;; pqi,air-pen) - ath9k_eeprom_extract "art" 0x1000 0x7d2 + caldata_extract "art" 0x1000 0x7d2 ;; ubnt,unifi) - ath9k_eeprom_extract "art" 0x1000 0x800 + caldata_extract "art" 0x1000 0x800 ;; wd,mynet-n750) - ath9k_eeprom_extract "art" 0x5000 0x440 + caldata_extract "art" 0x5000 0x440 ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan5mac") 0x2 ;; wd,mynet-wifi-rangeextender) - ath9k_eeprom_extract "art" 0x1000 0x1000 + caldata_extract "art" 0x1000 0x1000 ath9k_patch_fw_mac_crc $(nvram get wl0_hwaddr) "$mac" 0x2 ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; @@ -194,14 +156,14 @@ case "$FIRMWARE" in netgear,wndr3700|\ netgear,wndr3700v2|\ netgear,wndr3800) - ath9k_eeprom_extract "art" 0x1000 0xeb8 + caldata_extract "art" 0x1000 0xeb8 ;; dlink,dir-825-b1) - ath9k_eeprom_extract "caldata" 0x1000 0xeb8 + caldata_extract "caldata" 0x1000 0xeb8 ath9k_patch_fw_mac_crc $(mtd_get_mac_text "caldata" 0xffa0) 0x20c ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; @@ -211,14 +173,14 @@ case "$FIRMWARE" in netgear,wndr3700|\ netgear,wndr3700v2|\ netgear,wndr3800) - ath9k_eeprom_extract "art" 0x5000 0xeb8 + caldata_extract "art" 0x5000 0xeb8 ;; dlink,dir-825-b1) - ath9k_eeprom_extract "caldata" 0x5000 0xeb8 + caldata_extract "caldata" 0x5000 0xeb8 ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "caldata" 0xffb4) 1) 0x20c ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_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 6e79094e0c..6417f28a23 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,35 +1,9 @@ #!/bin/sh -. /lib/functions.sh -. /lib/functions/k2t.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 - - mtd=$(find_mtd_chardev $part) - [ -n "$mtd" ] || \ - ath10kcal_die "no mtd device found for partition $part" +[ -e /lib/firmware/$FIRMWARE ] && exit 0 - 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/caldata.sh +. /lib/functions/k2t.sh ath10kcal_patch_mac() { local mac=$1 @@ -62,10 +36,6 @@ ath10kcal_patch_mac_crc() { } } -[ -e /lib/firmware/$FIRMWARE ] && exit 0 - -. /lib/functions/system.sh - board=$(board_name) case "$FIRMWARE" in @@ -74,7 +44,7 @@ case "$FIRMWARE" in comfast,cf-wr650ac-v1|\ comfast,cf-wr650ac-v2|\ yuncore,a770) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ;; devolo,dvl1200e|\ devolo,dvl1200i|\ @@ -82,54 +52,54 @@ case "$FIRMWARE" in devolo,dvl1750e|\ devolo,dvl1750i|\ devolo,dvl1750x) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0x0) -1) ;; dlink,dir-859-a1) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata "wlan5mac") ;; elecom,wrc-1750ghbk2-i) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ;; engenius,ecb1750) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(mtd_get_mac_ascii u-boot-env athaddr) ;; engenius,epg5000|\ iodata,wn-ac1167dgr|\ iodata,wn-ac1600dgr2) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1) ;; engenius,ews511ap) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1) ;; glinet,gl-ar750|\ glinet,gl-ar750s) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary art 0x0) +1) ;; glinet,gl-x750) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary art 0x0) +2) ;; nec,wg800hp) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac_crc $(mtd_get_mac_text board_data 0x880) ;; ocedo,koala|\ ocedo,ursus) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(mtd_get_mac_binary art 0xc) ;; openmesh,om5p-ac-v2) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16) ;; qihoo,c301) - ath10kcal_extract "radiocfg" 0x5000 0x844 + caldata_extract "radiocfg" 0x5000 0x844 ath10kcal_patch_mac_crc $(mtd_get_mac_ascii devdata wlan5mac) ;; tplink,archer-a7-v5|\ @@ -137,29 +107,29 @@ case "$FIRMWARE" in tplink,archer-c7-v4|\ tplink,archer-c7-v5|\ tplink,archer-c25-v1) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary info 0x8) -1) ;; tplink,archer-c5-v1|\ tplink,archer-c7-v2) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary u-boot 0x1fc00) -1) ;; tplink,archer-d50-v1) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary romfile 0xf100) +2) ;; tplink,re350k-v1) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary config 0x10008) +2) ;; tplink,re355-v1|\ tplink,re450-v1) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2) ;; tplink,re450-v2) - ath10kcal_extract "art" 0x5000 0x844 + caldata_extract "art" 0x5000 0x844 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary info 0x8) +1) ;; ubnt,unifiac-lite|\ @@ -170,7 +140,7 @@ case "$FIRMWARE" in ubnt,nanostation-ac|\ ubnt,nanostation-ac-loco|\ ubnt,unifiac-pro) - ath10kcal_extract "EEPROM" 0x5000 0x844 + caldata_extract "EEPROM" 0x5000 0x844 ;; esac ;; @@ -180,18 +150,18 @@ case "$FIRMWARE" in dlink,dir-842-c2|\ dlink,dir-842-c3|\ nec,wg1200cr) - ath10kcal_extract "art" 0x5000 0x2f20 + caldata_extract "art" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_ascii devdata wlan5mac) ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \ /lib/firmware/ath10k/QCA9888/hw2.0/board.bin ;; netgear,ex6400|\ netgear,ex7300) - ath10kcal_extract "caldata" 0x5000 0x2f20 + caldata_extract "caldata" 0x5000 0x2f20 ath10kcal_patch_mac $(mtd_get_mac_binary caldata 0xc) ;; phicomm,k2t) - ath10kcal_extract "art" 0x5000 0x2f20 + caldata_extract "art" 0x5000 0x2f20 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 @@ -201,7 +171,7 @@ case "$FIRMWARE" in tplink,archer-c60-v1|\ tplink,archer-c60-v2|\ tplink,archer-c6-v2) - ath10kcal_extract "art" 0x5000 0x2f20 + caldata_extract "art" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary mac 0x8) -1) ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \ /lib/firmware/ath10k/QCA9888/hw2.0/board.bin diff --git a/target/linux/brcm63xx/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom b/target/linux/brcm63xx/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom index 305d5feda5..2400eb998a 100644 --- a/target/linux/brcm63xx/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom +++ b/target/linux/brcm63xx/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom @@ -1,28 +1,9 @@ #!/bin/sh # Based on gabors ralink wisoc implementation. -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 || \ - rt2x00_eeprom_die "failed to extract from $mtd" -} - [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh +. /lib/functions/caldata.sh board=$(board_name) @@ -30,14 +11,14 @@ case "$FIRMWARE" in "rt2x00.eeprom" ) case $board in hg556a_c) - rt2x00_eeprom_extract "cal_data" 0x1fe00 0x200 + caldata_extract "cal_data" 0x1fe00 0x200 ;; hg622 |\ hg655b) - rt2x00_eeprom_extract "cal_data" 0x0 0x200 + caldata_extract "cal_data" 0x0 0x200 ;; *) - rt2x00_eeprom_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; diff --git a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index dfb0a0cf76..61597ea669 100644 --- a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -1,43 +1,8 @@ #!/bin/sh -. /lib/functions.sh - -ath10kcal_die() { - echo "ath10cal: " "$*" - exit 1 -} - -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_ubi_extract() { - local part=$1 - local offset=$(($2)) - local count=$(($3)) - local ubidev - local ubi - - . /lib/upgrade/nand.sh - - ubidev=$(nand_find_ubi $CI_UBIPART) - ubi=$(nand_find_volume $ubidev $part) - [ -n "$ubi" ] || \ - ath10kcal_die "no UBI volume found for $part" +[ -e /lib/firmware/$FIRMWARE ] && exit 0 - dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ - ath10kcal_die "failed to extract from $ubi" -} +. /lib/functions/caldata.sh ath10kcal_patch_mac_crc() { local mac=$1 @@ -64,26 +29,14 @@ ath10kcal_patch_mac_crc() { dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 } -ath10kcal_is_caldata_valid() { - local expected="$1" - - magic=$(hexdump -v -n 2 -e '1/1 "%02x"' /lib/firmware/$FIRMWARE) - [[ "$magic" == "$expected" ]] - return $? -} - -[ -e /lib/firmware/$FIRMWARE ] && exit 0 - -. /lib/functions/system.sh - board=$(board_name) case "$FIRMWARE" in "ath10k/cal-pci-0000:01:00.0.bin") case "$board" in meraki,mr33) - ath10kcal_ubi_extract "ART" 0x9000 0x844 - ath10kcal_is_caldata_valid "4408" || ath10kcal_extract "ART" 0x9000 0x844 + caldata_extract_ubi "ART" 0x9000 0x844 + caldata_valid "4408" || caldata_extract "ART" 0x9000 0x844 ath10kcal_patch_mac_crc $(macaddr_add $(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 0x66) +1) ;; esac @@ -91,7 +44,7 @@ case "$FIRMWARE" in "ath10k/pre-cal-pci-0000:01:00.0.bin") case "$board" in asus,map-ac2200) - ath10kcal_ubi_extract "Factory" 0x9000 0x2f20 + caldata_extract_ubi "Factory" 0x9000 0x2f20 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \ /lib/firmware/ath10k/QCA9888/hw2.0/board.bin ;; @@ -104,12 +57,12 @@ case "$FIRMWARE" in /usr/bin/fritz_cal_extract -i 1 -s 0x3C000 -e 0x212 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader1") ;; linksys,ea8300) - ath10kcal_extract "ART" 0x9000 0x2f20 + caldata_extract "ART" 0x9000 0x2f20 # OEM assigns 4 sequential MACs ath10kcal_patch_mac_crc $(macaddr_setbit_la $(macaddr_add "$(cat /sys/class/net/eth0/address)" 4)) ;; openmesh,a62) - ath10kcal_extract "0:ART" 0x9000 0x2f20 + caldata_extract "0:ART" 0x9000 0x2f20 ;; esac ;; @@ -120,14 +73,14 @@ case "$FIRMWARE" in glinet,gl-b1300 |\ linksys,ea6350v3 |\ qcom,ap-dk01.1-c1) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ;; asus,map-ac2200) - ath10kcal_ubi_extract "Factory" 0x1000 0x2f20 + caldata_extract_ubi "Factory" 0x1000 0x2f20 ;; asus,rt-ac58u) CI_UBIPART=UBI_DEV - ath10kcal_ubi_extract "Factory" 0x1000 0x2f20 + caldata_extract_ubi "Factory" 0x1000 0x2f20 ;; avm,fritzbox-4040) /usr/bin/fritz_cal_extract -i 1 -s 0x400 -e 0x207 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader_config") @@ -147,29 +100,29 @@ case "$FIRMWARE" in openmesh,a62 |\ qxwlan,e2600ac-c1 |\ qxwlan,e2600ac-c2) - ath10kcal_extract "0:ART" 0x1000 0x2f20 + caldata_extract "0:ART" 0x1000 0x2f20 ;; engenius,ens620ext) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +2) ;; linksys,ea8300) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add "$(cat /sys/class/net/eth0/address)" 2) ;; meraki,mr33) - ath10kcal_ubi_extract "ART" 0x1000 0x2f20 - ath10kcal_is_caldata_valid "202f" || ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract_ubi "ART" 0x1000 0x2f20 + caldata_valid "202f" || caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 0x66) +2) ;; netgear,ex6100v2 |\ netgear,ex6150v2) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary dnidata 0x0) ;; zyxel,nbg6617 |\ zyxel,wre6606) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) -2) ;; esac @@ -181,14 +134,14 @@ case "$FIRMWARE" in glinet,gl-b1300 |\ linksys,ea6350v3 |\ qcom,ap-dk01.1-c1) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ;; asus,map-ac2200) - ath10kcal_ubi_extract "Factory" 0x5000 0x2f20 + caldata_extract_ubi "Factory" 0x5000 0x2f20 ;; asus,rt-ac58u) CI_UBIPART=UBI_DEV - ath10kcal_ubi_extract "Factory" 0x5000 0x2f20 + caldata_extract_ubi "Factory" 0x5000 0x2f20 ;; avm,fritzbox-4040) /usr/bin/fritz_cal_extract -i 1 -s 0x400 -e 0x208 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader_config") @@ -208,29 +161,29 @@ case "$FIRMWARE" in openmesh,a62 |\ qxwlan,e2600ac-c1 |\ qxwlan,e2600ac-c2) - ath10kcal_extract "0:ART" 0x5000 0x2f20 + caldata_extract "0:ART" 0x5000 0x2f20 ;; engenius,ens620ext) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +3) ;; linksys,ea8300) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add "$(cat /sys/class/net/eth0/address)" 3) ;; meraki,mr33) - ath10kcal_ubi_extract "ART" 0x5000 0x2f20 - ath10kcal_is_caldata_valid "202f" || ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract_ubi "ART" 0x5000 0x2f20 + caldata_valid "202f" || caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 0x66) +3) ;; netgear,ex6100v2 |\ netgear,ex6150v2) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary dnidata 0xc) ;; zyxel,nbg6617 |\ zyxel,wre6606) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) -1) ;; esac diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index c0fb1db16d..12b76ec33f 100644 --- a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -1,34 +1,8 @@ #!/bin/sh -. /lib/functions.sh - -ath10kcal_die() { - echo "ath10cal: " "$*" - exit 1 -} - -ath10kcal_from_file() { - local source=$1 - local offset=$(($2)) - local count=$(($3)) - - dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ - ath10kcal_die "failed to extract calibration data from $source" -} - -ath10kcal_extract() { - local part=$1 - local offset=$(($2)) - local count=$(($3)) - local mtd - - mtd=$(find_mtd_chardev $part) - [ -n "$mtd" ] || \ - ath10kcal_die "no mtd device found for partition $part" +[ -e /lib/firmware/$FIRMWARE ] && exit 0 - dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ - ath10kcal_die "failed to extract calibration data from $mtd" -} +. /lib/functions/caldata.sh ath10kcal_patch_mac_crc() { local mac=$1 @@ -55,43 +29,39 @@ ath10kcal_patch_mac_crc() { dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 } -[ -e /lib/firmware/$FIRMWARE ] && exit 0 - -. /lib/functions/system.sh - board=$(board_name) case "$FIRMWARE" in "ath10k/pre-cal-pci-0000:01:00.0.bin") case $board in buffalo,wxr-2533dhp) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary ART 0x1e) ;; linksys,ea8500) - ath10kcal_extract "art" 0x1000 0x2f20 + caldata_extract "art" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +1) ;; nec,wg2600hp) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary PRODUCTDATA 0xc) +1) ;; netgear,d7800 |\ netgear,r7500v2 |\ netgear,r7800) - ath10kcal_extract "art" 0x1000 0x2f20 + caldata_extract "art" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0x6) +1) ;; tplink,c2600) - ath10kcal_extract "radio" 0x1000 0x2f20 + caldata_extract "radio" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary default-mac 0x8) -1) ;; tplink,vr2600v) - ath10kcal_extract "ART" 0x1000 0x2f20 + caldata_extract "ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary default-mac 0x0) -1) ;; zyxel,nbg6817) - ath10kcal_extract "0:ART" 0x1000 0x2f20 + caldata_extract "0:ART" 0x1000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii 0:APPSBLENV ethaddr) +1) ;; esac @@ -99,33 +69,33 @@ case "$FIRMWARE" in "ath10k/pre-cal-pci-0001:01:00.0.bin") case $board in buffalo,wxr-2533dhp) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary ART 0x18) ;; linksys,ea8500) - ath10kcal_extract "art" 0x5000 0x2f20 + caldata_extract "art" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii devinfo hw_mac_addr) +2) ;; nec,wg2600hp) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary PRODUCTDATA 0xc) ;; netgear,d7800 |\ netgear,r7500v2 |\ netgear,r7800) - ath10kcal_extract "art" 0x5000 0x2f20 + caldata_extract "art" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(macaddr_add $(mtd_get_mac_binary art 0x6) +2) ;; tplink,c2600) - ath10kcal_extract "radio" 0x5000 0x2f20 + caldata_extract "radio" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary default-mac 0x8) ;; tplink,vr2600v) - ath10kcal_extract "ART" 0x5000 0x2f20 + caldata_extract "ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_binary default-mac 0x0) ;; zyxel,nbg6817) - ath10kcal_extract "0:ART" 0x5000 0x2f20 + caldata_extract "0:ART" 0x5000 0x2f20 ath10kcal_patch_mac_crc $(mtd_get_mac_ascii 0:APPSBLENV ethaddr) ;; esac diff --git a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index 6d7682a7f3..5b03fb0e01 100644 --- a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -3,29 +3,7 @@ [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh -. /lib/functions/system.sh -. /lib/upgrade/nand.sh - -ath10k_caldata_die() { - echo "ath10k caldata: " "$*" - exit 1 -} - -ath10k_caldata_extract_ubi() { - 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" ] || \ - ath10k_caldata_die "no UBI volume found for $part" - - dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ - ath10k_caldata_die "failed to extract from $ubi" -} +. /lib/functions/caldata.sh ath10k_caldata_set_macaddr() { local macaddr=$1 @@ -39,11 +17,11 @@ case "$FIRMWARE" in board=$(board_name) case $board in bt,homehub-v5a) - ath10k_caldata_extract_ubi "caldata" 20480 2116 + caldata_extract_ubi "caldata" 0x5000 0x844 ath10k_caldata_set_macaddr $(macaddr_add $(mtd_get_mac_binary_ubi caldata 0x110c) +3) ;; *) - ath10k_caldata_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; diff --git a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom index 5f3eb0cfe3..192dcecb28 100644 --- a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom +++ b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom @@ -3,15 +3,9 @@ [ -e /lib/firmware/$FIRMWARE ] && exit 0 -. /lib/functions.sh -. /lib/functions/system.sh +. /lib/functions/caldata.sh . /lib/upgrade/nand.sh -ath9k_eeprom_die() { - echo "ath9k eeprom: $*" - exit 1 -} - ath9k_eeprom_extract_raw() { local source=$1 local offset=$(($2)) @@ -28,25 +22,7 @@ ath9k_eeprom_extract_raw() { fi dd if=$source of=/lib/firmware/$FIRMWARE bs=$bs skip=$offset count=$size $conv 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 + caldata_die "failed to extract from $mtd" } ath9k_eeprom_extract() { @@ -57,7 +33,7 @@ ath9k_eeprom_extract() { mtd=$(find_mtd_chardev $part) [ -n "$mtd" ] || \ - ath9k_eeprom_die "no mtd device found for partition $part" + caldata_die "no mtd device found for partition $part" ath9k_eeprom_extract_raw $mtd $offset $swap } @@ -71,7 +47,7 @@ ath9k_ubi_eeprom_extract() { ubi=$(nand_find_volume $ubidev $part) [ -n "$ubi" ] || \ - ath9k_eeprom_die "no UBI volume found for $part" + caldata_die "no UBI volume found for $part" ath9k_eeprom_extract_raw /dev/$ubi $offset $swap } @@ -143,7 +119,7 @@ case "$FIRMWARE" in avm,fritz3370-rev2-hynix|\ avm,fritz3370-rev2-micron|\ avm,fritz7362sl) - ath9k_eeprom_extract_reverse "urlader" 0x1541 0x440 + caldata_extract_reverse "urlader" 0x1541 0x440 ;; avm,fritz7312|avm,fritz7320|avm,fritz7360sl) ath9k_eeprom_extract "urlader" 0x985 0 @@ -155,7 +131,7 @@ case "$FIRMWARE" in ath9k_eeprom_extract "boardconfig" 0x21000 0 ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; diff --git a/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom index dc66226d7b..168f10e0f6 100644 --- a/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom +++ b/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom @@ -1,11 +1,8 @@ #!/bin/sh -FW_FILE="/lib/firmware/$FIRMWARE" +[ -e /lib/firmware/$FIRMWARE ] && exit 0 -ath9k_eeprom_die() { - echo "ath9k eeprom: " "$*" >&2 - exit 1 -} +. /lib/functions/caldata.sh ath9k_eeprom_extract() { local part=$1 @@ -15,10 +12,10 @@ ath9k_eeprom_extract() { mtd=$(find_mtd_chardev $part) [ -n "$mtd" ] || \ - ath9k_eeprom_die "no mtd device found for partition $part" + caldata_die "no mtd device found for partition $part" - dd if=$mtd bs=$offset skip=1 count=1 2>/dev/null | dd of=$FW_FILE bs=$count count=1 2>/dev/null || \ - ath9k_eeprom_die "failed to extract from $mtd" + dd if=$mtd bs=$offset skip=1 count=1 2>/dev/null | dd of=/lib/firmware/$FIRMWARE bs=$count count=1 2>/dev/null || \ + caldata_die "failed to extract from $mtd" } tpl_set_wireless_mac() @@ -29,14 +26,9 @@ tpl_set_wireless_mac() mac=$(mtd_get_mac_binary u-boot 0x4fc00) mac=$(macaddr_add $mac $offset) - macaddr_2bin $mac | dd bs=1 count=6 seek=2 conv=notrunc of=$FW_FILE 2>/dev/null + macaddr_2bin $mac | dd bs=1 count=6 seek=2 conv=notrunc of=/lib/firmware/$FIRMWARE 2>/dev/null } -[ -e $FW_FILE ] && exit 0 - -. /lib/functions.sh -. /lib/functions/system.sh - board=$(board_name) case "$FIRMWARE" in @@ -47,7 +39,7 @@ case "$FIRMWARE" in tpl_set_wireless_mac 0 ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_die "board $board is not supported yet" ;; esac ;; @@ -59,7 +51,7 @@ case "$FIRMWARE" in tpl_set_wireless_mac -1 ;; *) - ath9k_eeprom_die "board $board is not supported yet" + caldata_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 7b98936ec3..ec70d86dac 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,23 +1,8 @@ #!/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" +[ -e /lib/firmware/$FIRMWARE ] && exit 0 - dd if=$mtd of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ - rt2x00_eeprom_die "failed to extract from $mtd" -} +. /lib/functions/caldata.sh jboot_eeprom_extract() { local part=$1 @@ -26,29 +11,23 @@ jboot_eeprom_extract() { mtd=$(find_mtd_part $part) [ -n "$mtd" ] || \ - rt2x00_eeprom_die "no mtd device found for partition $part" + caldata_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" + caldata_die "failed to extract from $mtd" } rt2x00_eeprom_set_macaddr() { local macaddr=$1 [ -n "$macaddr" ] || \ - rt2x00_eeprom_die "invalid wlan mac address" + caldata_die "invalid wlan mac address" macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \ conv=notrunc oflag=seek_bytes bs=6 seek=4 count=1 2>/dev/null || \ - rt2x00_eeprom_die "failed to write mac address to eeprom file" + caldata_die "failed to write mac address to eeprom file" } -FW="/lib/firmware/$FIRMWARE" -[ -e "$FW" ] && exit 0 - -. /lib/functions.sh -. /lib/functions/system.sh - board=$(board_name) case "$FIRMWARE" in @@ -68,11 +47,11 @@ case "$FIRMWARE" in ;; dovado,tiny-ac) wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR) - rt2x00_eeprom_extract "factory" 0x0 0x200 + caldata_extract "factory" 0x0 0x200 rt2x00_eeprom_set_macaddr $wifi_mac ;; *) - rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!" + caldata_die "Please define mtd-eeprom in $board DTS file!" ;; esac ;; From patchwork Sun Sep 8 14:10:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1159448 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="jrED03ZY"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46RCs05xSGz9sDB for ; Mon, 9 Sep 2019 00:11:32 +1000 (AEST) 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=EJUPUW+VtQJQY6ozhoSWbByqJ8AC8L5PB3bjuVxh3z8=; b=jrED03ZYBn895Wv7qSwp1mEsHt KfNCf/bpG7XKK4REsxoH2wZbPh0Ct+DI/NwdHf2Taf23CC/zk+1o6+B3oNeBdxEVaPnxCgDHzueEk CiUVcUyvtJE0/54PEQG8kgl8FpjWPqeuMvwKZwrBka8dQ1Epx0UQPMGcle85v+rKlyvJ1NVmywxtB xbvPHkmEuNu2HJMW7RoeD9XuwZuM3Uilvblala6MDZhk4OXQAQJte0RN5REvO7Z7k1LDLm8JanIEa RI9OFdi7aCjuOo+zTOSsuTZf27QwbQlHSYEGHSJ9H6eI9tGi5hjvUAhzOMzbaEyQ3flaLtmp+FhFQ nbgTFYDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1i6xuZ-00081U-8j; Sun, 08 Sep 2019 14:11:27 +0000 Received: from mout.kundenserver.de ([217.72.192.75]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1i6xu8-000729-22 for openwrt-devel@lists.openwrt.org; Sun, 08 Sep 2019 14:11:03 +0000 Received: from buildfff.adridolf.com ([188.193.187.204]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MkIEJ-1iZRxR3UU5-00keJT for ; Sun, 08 Sep 2019 16:10:56 +0200 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Date: Sun, 8 Sep 2019 16:10:51 +0200 Message-Id: <20190908141052.17443-4-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190908141052.17443-1-freifunk@adrianschmutzler.de> References: <20190908141052.17443-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:XKP68MsX3rRCCp5Opqvu5b2BgOnNAbbysJjZP0yD0NTFQjLmTAJ sigR3+cF7DZ+pfinGuITQen4VcGKNrgIJjUxgqWndplxZp4+jNbAnktmCQm8HuHTCZylj/o AkjEEZN7Lxt/F4dzsIIoyeg7Oxm4VQk8/fgnckpdP+MUQsnNJkvuD/Abu+HkSioMVoOJE0t 8NCW8Koe4MWd4j63Q6reg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:MBA9SZcWWxs=:x4M4WFx6C/7sbwZE2BSVqX 1RI6Rod/5uafLAVxGXInE0rr+F0mJlVW2SmBdwKkT9QSLPBrlHlDkyjexiQeig2BNNWQIHSkS so2/qCWTfqlQMINLoYDB4jq8nXI+a8JoK0z1c0UDI+N6bqNYdx01Jf+m8unXmlrJDdhnnwsoN 371w+qwIx8j/W0BcMoT/rgvsy2cXy8rEueRnVSWh1uaGs3xj4qnW/Yuss4I9Lwoleixe0Ohd6 9klCT3CArGDR8pbmvmmS6SE4CXl6DXq5Xr9hvgeTsI2QrqOo9jrT2qcbj6jo8k5r3mEG4I4wv uG2cdsvktYaHz54HF4vGPjMzBPS6TWR4c2IflN6+FWrwI+FXc08P7NA2YFUXNbBuI7QAqzSpv 2iJ0khOM6QAEfo2ZQWbwG/2rhyS43dROYTqUArLSq8F1aIHiwDdP4ehXrrKy3FlTwAf8mFOir mJfJTEQisXufsJW+aeqHAGqzursOz7gRvhuNrKnqrV+2gZcLPLk8uTiOKqnnvnTbh/CuKr77X Y04/65IiQ1ml+Ns0NoOZ4AlxYMxGFCmZUrXs0Bqi+BZsoWCc8z05pHIokDfAUeXMTTEl9UU11 Fkj4wiYXiPXvsnoHPwGq+2Iig3FLDIBomT6XaOovqROnuvxPzwG0oA2eJeC4PkuUSnzxdX/jk xcRFffkGCKCMHTB6Db+l73W0k8wqPqzIqcnGVXERa0kYzqwI1m+t2SsdT6c4lIr8Vzjcn/IBv wYAKdKMmtr62KTSRtvh1dcBzcAxymCEhrn+Ktfcaf8PUwROXI8JFSsPVYsbvVFE6LnU1+elJR THomfL4knb131n7FBF8K8CGVdV66Hh1p1DrQRrbX4KQ1029eMcB+IQa9O2KLNAfdBmW7R5k X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190908_071100_430901_E217E462 X-CRM114-Status: GOOD ( 11.80 ) 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 [217.72.192.75 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH 3/4] treewide: move MAC address patch functions to common library X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 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 This unifies MAC address patch functions and moves them to a common script. While those were implemented differently for different targets, they all seem to do the same. The number of different variants is significantly reduced by this patch. Signed-off-by: Adrian Schmutzler --- .../base-files/files/lib/functions/caldata.sh | 47 +++++++++++++++ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 12 +--- .../etc/hotplug.d/firmware/10-ath9k-eeprom | 57 ++++--------------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 31 ---------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 25 -------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 25 -------- .../etc/hotplug.d/firmware/11-ath10k-caldata | 9 +-- .../etc/hotplug.d/firmware/12-ath9k-eeprom | 43 ++------------ .../etc/hotplug.d/firmware/10-ath9k-eeprom | 3 +- .../etc/hotplug.d/firmware/10-rt2x00-eeprom | 15 +---- 10 files changed, 68 insertions(+), 199 deletions(-) diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-files/files/lib/functions/caldata.sh index f2a306675f..1a1849b93f 100644 --- a/package/base-files/files/lib/functions/caldata.sh +++ b/package/base-files/files/lib/functions/caldata.sh @@ -73,3 +73,50 @@ caldata_valid() { return $? } +caldata_patch_fw_mac() { + local mac=$1 + local mac_offset=$(($2)) + local chksum_offset=$(($3)) + local xor_mac + local xor_fw_mac + local xor_fw_chksum + + [ -z "$mac" -o -z "$mac_offset" ] && return + + [ -n "$chksum_offset" ] && { + xor_mac=${mac//:/} + xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" + + xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) + xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" + + xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) + xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) + + printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ + dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 + } + + macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=$mac_offset count=1 || \ + caldata_die "failed to write MAC address to eeprom file" +} + +caldata_patch_fw_mac_crc() { + local mac=$1 + local mac_offset=$2 + local chksum_offset=$((mac_offset - 10)) + + caldata_patch_fw_mac "$mac" "$mac_offset" "$chksum_offset" +} + +ath10kcal_patch_mac() { + local mac=$1 + + caldata_patch_fw_mac "$mac" 0x6 +} + +ath10kcal_patch_mac_crc() { + local mac=$1 + + caldata_patch_fw_mac "$mac" 0x6 0x2 +} diff --git a/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom index 07100b1856..a03c3436cb 100644 --- a/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom +++ b/target/linux/apm821xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom @@ -4,14 +4,6 @@ . /lib/functions/caldata.sh -ath9k_patch_firmware_mac() { - local mac=$1 - - [ -z "$mac" ] && return - - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=2 count=6 -} - board=$(board_name) case "$FIRMWARE" in @@ -24,7 +16,7 @@ case "$FIRMWARE" in caldata_extract_ubi "caldata" 0x5000 0x1000 else caldata_extract "wifi_data" 0x5000 0x1000 - ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 0xc) + caldata_patch_fw_mac $(mtd_get_mac_binary wifi_data 0xc) 0x2 fi ;; *) @@ -42,7 +34,7 @@ case "$FIRMWARE" in caldata_extract_ubi "caldata" 0x1000 0x1000 else caldata_extract "wifi_data" 0x1000 0x1000 - ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 0x0) + caldata_patch_fw_mac $(mtd_get_mac_binary wifi_data 0x0) 0x2 fi ;; *) 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 3432014f60..d5b2a51a70 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 @@ -4,41 +4,6 @@ . /lib/functions/caldata.sh -ath9k_patch_fw_mac() { - local mac=$1 - local mac_offset=$(($2)) - local chksum_offset=$(($3)) - local xor_mac - local xor_fw_mac - local xor_fw_chksum - - [ -z "$mac" -o -z "$mac_offset" ] && return - - [ -n "$chksum_offset" ] && { - xor_mac=${mac//:/} - xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" - - xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" - - xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) - - printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ - dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 - } - - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=$mac_offset count=1 -} - -ath9k_patch_fw_mac_crc() { - local mac=$1 - local mac_offset=$2 - local chksum_offset=$((mac_offset - 10)) - - ath9k_patch_fw_mac "${mac}" "${mac_offset}" "${chksum_offset}" -} - board=$(board_name) case "$FIRMWARE" in @@ -50,7 +15,7 @@ case "$FIRMWARE" in dlink,dir-825-c1|\ dlink,dir-835-a1) caldata_extract "art" 0x1000 0x440 - ath9k_patch_fw_mac_crc $(mtd_get_mac_text "mac" 0x4) 0x2 + caldata_patch_fw_mac_crc $(mtd_get_mac_text "mac" 0x4) 0x2 ;; dlink,dir-842-c1|\ dlink,dir-842-c2|\ @@ -59,11 +24,11 @@ case "$FIRMWARE" in nec,wg1200cr|\ wd,mynet-n750) caldata_extract "art" 0x1000 0x440 - ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 0x2 + caldata_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 0x2 ;; engenius,ecb1750) caldata_extract "art" 0x1000 0x440 - ath9k_patch_fw_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env "athaddr") +1) 0x2 + caldata_patch_fw_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env "athaddr") +1) 0x2 ;; engenius,epg5000|\ iodata,wn-ac1167dgr|\ @@ -71,15 +36,15 @@ case "$FIRMWARE" in iodata,wn-ac1600dgr2|\ iodata,wn-ag300dgr) caldata_extract "art" 0x1000 0x440 - ath9k_patch_fw_mac $(mtd_get_mac_ascii u-boot-env ethaddr) 0x2 + caldata_patch_fw_mac $(mtd_get_mac_ascii u-boot-env ethaddr) 0x2 ;; nec,wg800hp) caldata_extract "art" 0x1000 0x440 - ath9k_patch_fw_mac $(mtd_get_mac_text board_data 0x680) 0x2 + caldata_patch_fw_mac $(mtd_get_mac_text board_data 0x680) 0x2 ;; qihoo,c301) caldata_extract "radiocfg" 0x1000 0x440 - ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 0x2 + caldata_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan24mac") 0x2 ;; *) caldata_die "board $board is not supported yet" @@ -103,7 +68,7 @@ case "$FIRMWARE" in dlink,dir-825-c1|\ dlink,dir-835-a1) caldata_extract "art" 0x5000 0x440 - ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "mac" 0x18) 1) 0x2 + caldata_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "mac" 0x18) 1) 0x2 ;; ocedo,raccoon|\ tplink,tl-wdr3500-v1|\ @@ -139,11 +104,11 @@ case "$FIRMWARE" in ;; wd,mynet-n750) caldata_extract "art" 0x5000 0x440 - ath9k_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan5mac") 0x2 + caldata_patch_fw_mac $(mtd_get_mac_ascii devdata "wlan5mac") 0x2 ;; wd,mynet-wifi-rangeextender) caldata_extract "art" 0x1000 0x1000 - ath9k_patch_fw_mac_crc $(nvram get wl0_hwaddr) "$mac" 0x2 + caldata_patch_fw_mac_crc $(nvram get wl0_hwaddr) "$mac" 0x2 ;; *) caldata_die "board $board is not supported yet" @@ -160,7 +125,7 @@ case "$FIRMWARE" in ;; dlink,dir-825-b1) caldata_extract "caldata" 0x1000 0xeb8 - ath9k_patch_fw_mac_crc $(mtd_get_mac_text "caldata" 0xffa0) 0x20c + caldata_patch_fw_mac_crc $(mtd_get_mac_text "caldata" 0xffa0) 0x20c ;; *) caldata_die "board $board is not supported yet" @@ -177,7 +142,7 @@ case "$FIRMWARE" in ;; dlink,dir-825-b1) caldata_extract "caldata" 0x5000 0xeb8 - ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "caldata" 0xffb4) 1) 0x20c + caldata_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_text "caldata" 0xffb4) 1) 0x20c ;; *) caldata_die "board $board is not supported yet" 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 6417f28a23..68460c855e 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 @@ -5,37 +5,6 @@ . /lib/functions/caldata.sh . /lib/functions/k2t.sh -ath10kcal_patch_mac() { - local mac=$1 - - [ -z "$mac" ] && return - - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=6 count=1 -} - -ath10kcal_patch_mac_crc() { - local mac=$1 - local mac_offset=6 - local chksum_offset=2 - local xor_mac - local xor_fw_mac - local xor_fw_chksum - - xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" - - ath10kcal_patch_mac "$mac" && { - xor_mac=${mac//:/} - xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" - - xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) - - printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ - dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 - } -} - board=$(board_name) case "$FIRMWARE" in diff --git a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index 61597ea669..898e0bb074 100644 --- a/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -4,31 +4,6 @@ . /lib/functions/caldata.sh -ath10kcal_patch_mac_crc() { - local mac=$1 - local mac_offset=6 - local chksum_offset=2 - local xor_mac - local xor_fw_mac - local xor_fw_chksum - - [ -z "$mac" ] && return - - xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" - - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6 - - xor_mac=${mac//:/} - xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" - - xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) - - printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ - dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 -} - board=$(board_name) case "$FIRMWARE" in diff --git a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index 12b76ec33f..f8a4c98542 100644 --- a/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -4,31 +4,6 @@ . /lib/functions/caldata.sh -ath10kcal_patch_mac_crc() { - local mac=$1 - local mac_offset=6 - local chksum_offset=2 - local xor_mac - local xor_fw_mac - local xor_fw_chksum - - [ -z "$mac" ] && return - - xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" - - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6 - - xor_mac=${mac//:/} - xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" - - xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) - - printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ - dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 -} - board=$(board_name) case "$FIRMWARE" in diff --git a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index 5b03fb0e01..244635c6db 100644 --- a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -5,20 +5,13 @@ . /lib/functions/caldata.sh -ath10k_caldata_set_macaddr() { - local macaddr=$1 - - macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \ - conv=notrunc bs=1 seek=6 count=6 -} - case "$FIRMWARE" in "ath10k/cal-pci-0000:02:00.0.bin") board=$(board_name) case $board in bt,homehub-v5a) caldata_extract_ubi "caldata" 0x5000 0x844 - ath10k_caldata_set_macaddr $(macaddr_add $(mtd_get_mac_binary_ubi caldata 0x110c) +3) + ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary_ubi caldata 0x110c) +3) ;; *) caldata_die "board $board is not supported yet" diff --git a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom index 192dcecb28..b5dba670b1 100644 --- a/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom +++ b/target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom @@ -52,41 +52,6 @@ ath9k_ubi_eeprom_extract() { ath9k_eeprom_extract_raw /dev/$ubi $offset $swap } -ath9k_patch_fw_mac_crc() { - local mac=$1 - local mac_offset=$2 - local chksum_offset=$((mac_offset - 10)) - - ath9k_patch_fw_mac "${mac}" "${mac_offset}" "${chksum_offset}" -} - -ath9k_patch_fw_mac() { - local mac=$1 - local mac_offset=$(($2)) - local chksum_offset=$(($3)) - local xor_mac - local xor_fw_mac - local xor_fw_chksum - - [ -z "$mac" -o -z "$mac_offset" ] && return - - [ -n "$chksum_offset" ] && { - xor_mac=${mac//:/} - xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}" - - xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}" - - xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE) - xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac) - - printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \ - dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2 - } - - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$mac_offset count=6 -} - case "$FIRMWARE" in "ath9k-eeprom-pci-0000:00:0e.0.bin" | \ "ath9k-eeprom-pci-0000:01:00.0.bin" | \ @@ -102,19 +67,19 @@ case "$FIRMWARE" in ;; bt,homehub-v2b) ath9k_eeprom_extract "art" 0x0 1 - ath9k_patch_fw_mac_crc "00:00:00:00:00:00" 0x20c + caldata_patch_fw_mac_crc "00:00:00:00:00:00" 0x20c ;; bt,homehub-v3a) ath9k_eeprom_extract "art-copy" 0x0 1 - ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot_env ethaddr) +2) 0x10c + caldata_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot_env ethaddr) +2) 0x10c ;; bt,homehub-v5a) ath9k_ubi_eeprom_extract "caldata" 0x1000 0 - ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_binary_ubi caldata 0x110c) +2) 0x10c + caldata_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_binary_ubi caldata 0x110c) +2) 0x10c ;; netgear,dgn3500|netgear,dgn3500b) ath9k_eeprom_extract "calibration" 0xf000 0 - ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 0x20c + caldata_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 0x20c ;; avm,fritz3370-rev2-hynix|\ avm,fritz3370-rev2-micron|\ diff --git a/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom b/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom index 168f10e0f6..3b9d9130f9 100644 --- a/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom +++ b/target/linux/mpc85xx/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom @@ -24,9 +24,8 @@ tpl_set_wireless_mac() local mac mac=$(mtd_get_mac_binary u-boot 0x4fc00) - mac=$(macaddr_add $mac $offset) - macaddr_2bin $mac | dd bs=1 count=6 seek=2 conv=notrunc of=/lib/firmware/$FIRMWARE 2>/dev/null + caldata_patch_fw_mac $(macaddr_add $mac $offset) 0x2 } board=$(board_name) 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 ec70d86dac..52d81a29c4 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 @@ -17,17 +17,6 @@ jboot_eeprom_extract() { caldata_die "failed to extract from $mtd" } -rt2x00_eeprom_set_macaddr() { - local macaddr=$1 - - [ -n "$macaddr" ] || \ - caldata_die "invalid wlan mac address" - - macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \ - conv=notrunc oflag=seek_bytes bs=6 seek=4 count=1 2>/dev/null || \ - caldata_die "failed to write mac address to eeprom file" -} - board=$(board_name) case "$FIRMWARE" in @@ -43,12 +32,12 @@ case "$FIRMWARE" in wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000) wifi_mac=$(macaddr_add "$wan_mac" 1) jboot_eeprom_extract "config" 0xE000 - rt2x00_eeprom_set_macaddr $wifi_mac + caldata_patch_fw_mac $wifi_mac 0x4 ;; dovado,tiny-ac) wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR) caldata_extract "factory" 0x0 0x200 - rt2x00_eeprom_set_macaddr $wifi_mac + caldata_patch_fw_mac $wifi_mac 0x4 ;; *) caldata_die "Please define mtd-eeprom in $board DTS file!"