2
0
forked from Ivasoft/openwrt

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 <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler
2019-09-22 11:57:14 +02:00
committed by David Bauer
parent 5b6a809092
commit 2c60de0e3f
10 changed files with 81 additions and 210 deletions

View File

@@ -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"

View File

@@ -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|\