From patchwork Mon Apr 20 13:35:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thibaut X-Patchwork-Id: 1273396 X-Patchwork-Delegate: koen.vandeputte@ncentric.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=fail (p=quarantine dis=none) header.from=slashdirt.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=S952h2un; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=slashdirt.org header.i=@slashdirt.org header.a=rsa-sha256 header.s=mail header.b=unqhXehe; 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 495SSd3Mxqz9sSv for ; Mon, 20 Apr 2020 23:38:09 +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:Cc: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:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=p9oHuMlJnSaznsXumR2w5f4gNfkC2xqbgzjUNFX/XCs=; b=S952h2unzq80/Y zkf0J9YCs11kYFApqELQ9/fP+1/BNfnW5IFb/9kG9wnLJB/hNRJHl9SBTD5HgW6PYuz3tHDQh7T1s XAc6gl21m3X4xtPmC+wZ/Otg+Wf5gX/juzbHdhmWhZB64p89a+rL80TQ+4IJorakIWRUsNtUI91I8 E2tJiSaVlxtjTyhHXwFrPOwCTJuR4BRyw00R3+s66qHV56XNYD+ekV5dKG2MiXS+fChrfQe3zrEej 2rOO9YlsbQKeu8z5LC6HtCeJ+S1Qp+lC0lMRo2wMGQp9/YVGdjmebZkmnXOpO3YTelrTbEi13IzGn /79PiJ3GW69BVGuCy4Fw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQWcc-0003Xe-S8; Mon, 20 Apr 2020 13:38:02 +0000 Received: from vps.slashdirt.org ([144.91.108.218]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQWab-0000xh-Dp for openwrt-devel@lists.openwrt.org; Mon, 20 Apr 2020 13:35:59 +0000 Received: from supercopter (82-64-212-153.subs.proxad.net [82.64.212.153]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by vps.slashdirt.org (Postfix) with ESMTPS id A3BCF6055A; Mon, 20 Apr 2020 15:35:52 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 vps.slashdirt.org A3BCF6055A Authentication-Results: vps.slashdirt.org; dmarc=fail (p=quarantine dis=none) header.from=slashdirt.org DKIM-Filter: OpenDKIM Filter v2.11.0 vps.slashdirt.org A3BCF6055A DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=slashdirt.org; s=mail; t=1587389753; bh=jxOLS48KvHBIw6Z1eARGYy634JCRUgZXJ9mtZhXhD1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=unqhXeheooeEujZx7N9vW5bVgDzClS4PJ98LndlY0XSGz4EMqexbvHlwB239bnqmN nf1cx+vsmNmFStyDUbvQIjcfGr+913i6Ea+c/lglQkbx5STJqpIyqQSk9MqWQF8rVI 0JLFNTgF2VJEbfftEBmYtiT2WZWOigmyuSGnyQTE= Received: by supercopter (sSMTP sendmail emulation); Mon, 20 Apr 2020 15:35:52 +0200 From: =?utf-8?q?Thibaut_VAR=C3=88NE?= To: openwrt-devel@lists.openwrt.org Date: Mon, 20 Apr 2020 15:35:00 +0200 Message-Id: <20200420133503.18700-12-hacks@slashdirt.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20200420133503.18700-1-hacks@slashdirt.org> References: <20200420133503.18700-1-hacks@slashdirt.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,TXREP, UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on vps.slashdirt.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200420_063557_643050_5009D755 X-CRM114-Status: GOOD ( 12.49 ) X-Spam-Score: 0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.4 NO_DNS_FOR_FROM RBL: Envelope sender has no MX or A DNS records [listed in slashdirt.org. IN A] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [OpenWrt-Devel] [PATCH v2 11/14] package/base-files: caldata: allow setting target file 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: , Cc: =?utf-8?q?Thibaut_VAR=C3=88NE?= , koen.vandeputte@ncentric.com Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This will enable platforms to extract caldata to an arbitrary file, or patch mac in an abitrary file. Signed-off-by: Thibaut VARĂˆNE Acked-by: Adrian Schmutzler --- package/base-files/Makefile | 2 +- package/base-files/files/lib/functions/caldata.sh | 29 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/package/base-files/Makefile b/package/base-files/Makefile index 156e7bc8b9..f1f0f17a60 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk include $(INCLUDE_DIR)/feeds.mk PKG_NAME:=base-files -PKG_RELEASE:=218 +PKG_RELEASE:=219 PKG_FLAGS:=nonshared PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/ diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-files/files/lib/functions/caldata.sh index 3bdb1e4dd5..e9349c7eee 100644 --- a/package/base-files/files/lib/functions/caldata.sh +++ b/package/base-files/files/lib/functions/caldata.sh @@ -60,15 +60,21 @@ caldata_from_file() { local source=$1 local offset=$(($2)) local count=$(($3)) + local target=$4 - dd if=$source of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \ + [ -z "$target" ] && target=/lib/firmware/$FIRMWARE + + dd if=$source of=$target 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" + local target=$2 + + [ -z "$target" ] && target=/lib/firmware/$FIRMWARE - magic=$(hexdump -v -n 2 -e '1/1 "%02x"' /lib/firmware/$FIRMWARE) + magic=$(hexdump -v -n 2 -e '1/1 "%02x"' $target) [ "$magic" = "$expected" ] return $? } @@ -77,6 +83,7 @@ caldata_patch_chksum() { local mac=$1 local mac_offset=$(($2)) local chksum_offset=$(($3)) + local target=$4 local xor_mac local xor_fw_mac local xor_fw_chksum @@ -91,38 +98,44 @@ caldata_patch_chksum() { 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 + dd of=$target conv=notrunc bs=1 seek=$chksum_offset count=2 } caldata_patch_mac() { local mac=$1 local mac_offset=$(($2)) local chksum_offset=$3 + local target=$4 [ -z "$mac" -o -z "$mac_offset" ] && return - [ -n "$chksum_offset" ] && caldata_patch_chksum "$mac" "$mac_offset" "$chksum_offset" + [ -z "$target" ] && target=/lib/firmware/$FIRMWARE + + [ -n "$chksum_offset" ] && caldata_patch_chksum "$mac" "$mac_offset" "$chksum_offset" "$target" - macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=$mac_offset count=1 || \ + macaddr_2bin $mac | dd of=$target conv=notrunc oflag=seek_bytes bs=6 seek=$mac_offset count=1 || \ caldata_die "failed to write MAC address to eeprom file" } ath9k_patch_mac() { local mac=$1 + local target=$2 - caldata_patch_mac "$mac" 0x2 + caldata_patch_mac "$mac" 0x2 "" "$target" } ath9k_patch_mac_crc() { local mac=$1 local mac_offset=$2 local chksum_offset=$((mac_offset - 10)) + local target=$4 - caldata_patch_mac "$mac" "$mac_offset" "$chksum_offset" + caldata_patch_mac "$mac" "$mac_offset" "$chksum_offset" "$target" } ath10k_patch_mac() { local mac=$1 + local target=$2 - caldata_patch_mac "$mac" 0x6 0x2 + caldata_patch_mac "$mac" 0x6 0x2 "$target" }