[OpenWrt-Devel] [PATCH v2 11/14] package/base-files: caldata: allow setting target file

mail at adrianschmutzler.de mail at adrianschmutzler.de
Mon Apr 20 10:09:18 EDT 2020


Acked-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>

I personally prefer
[ -n "$var" ] || do something
to
[ -z "$var" ] && do something
but that's pure matter of taste again.

Best

Adrian

> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of Thibaut VARÈNE
> Sent: Montag, 20. April 2020 15:35
> To: openwrt-devel at lists.openwrt.org
> Cc: Thibaut VARÈNE <hacks at slashdirt.org>; koen.vandeputte at ncentric.com
> Subject: [OpenWrt-Devel] [PATCH v2 11/14] package/base-files: caldata:
> allow setting target file
> 
> This will enable platforms to extract caldata to an arbitrary file, or patch mac
> in an abitrary file.
> 
> Signed-off-by: Thibaut VARÈNE <hacks at slashdirt.org>
> ---
>  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"
>  }
> --
> 2.11.0
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20200420/52a2301b/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list