base-files: move xor() from caldata extraction to functions.sh
authorAdrian Schmutzler <freifunk@adrianschmutzler.de>
Sat, 28 Sep 2019 13:12:55 +0000 (15:12 +0200)
committerDavid Bauer <mail@david-bauer.net>
Sun, 13 Oct 2019 17:03:57 +0000 (19:03 +0200)
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 <freifunk@adrianschmutzler.de>
package/base-files/files/lib/functions.sh
target/linux/ath79/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
target/linux/ath79/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
target/linux/ipq806x/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom

index 860fc045100f15a0725e47a38f28f9855835291a..81176431d16588aceef3e30e4c8d885368c04635 100755 (executable)
@@ -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"
index 7911d0aa1eadfcd69d31ea21f6c0da7591079818..0cdd78331551826871b6f6e365f033c127fa7eb4 100644 (file)
@@ -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))
index 0aa8f3d918948fa9e4bc4c671c386825cb0b9954..3844481f5aaa990f4bbb9ddf753a6d5cb6192db1 100644 (file)
@@ -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)
index be576461282689552a500c16cf1fe65e4b42e10a..dfb0a0cf766f6ded237dd7452615cd71d848df56 100644 (file)
@@ -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)
index bdc36070f2240a9cba76830657cf495c52f04d62..c0fb1db16d8791fd9762e54eec996e307b24821f 100644 (file)
@@ -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)
index 6f133c82a7b0346b230bee7f0e37d5c4422b455f..2c4a5a17993abe9da15e691e7b69d66c411aae84 100644 (file)
@@ -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