From 2c60de0e3f8cbe088fe8e495697cb9e98380710d Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Sun, 22 Sep 2019 11:57:14 +0200 Subject: treewide: move MAC address patch functions to common library 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 --- .../etc/hotplug.d/firmware/11-ath10k-caldata | 9 +---- .../etc/hotplug.d/firmware/12-ath9k-eeprom | 43 ++-------------------- 2 files changed, 5 insertions(+), 47 deletions(-) (limited to 'target/linux/lantiq') 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 20160cb32b..d0bef23045 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 + ath9k_patch_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 + ath9k_patch_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 + ath9k_patch_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 + ath9k_patch_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 0x20c ;; avm,fritz3370-rev2-hynix|\ avm,fritz3370-rev2-micron|\ -- cgit v1.2.3