Skip to content

Commit

Permalink
lantiq: switch to owl-loader for loading ath9k eeprom/calibration data
Browse files Browse the repository at this point in the history
This moves the extraction of the eeprom calibration data to a hotplug
firmware script. Additionally it modifies all .dts to configure ath9k
directly from within the .dts.
The owl-loader approach enables support on devices with exotic eeprom
data locations (such as unaligned positions on the flash or data
inside an UBI volume).

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
[add ath9k caldata mac address patcher]
[fixes DGN3500 wifi mac]
[fixes BTHOMEHUBV3A wifi mac]
[set invalid mac for BTHOMEHUB2B, FRITZ3370, FRITZ7320 & FRITZ7360SL to restore previous random mac behavior]
Signed-off-by: Mathias Kresin <dev@kresin.me>
  • Loading branch information
mkresin committed Sep 10, 2016
1 parent ba1f1d0 commit 4827ec3
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 160 deletions.
132 changes: 132 additions & 0 deletions target/linux/lantiq/base-files/etc/hotplug.d/firmware/12-ath9k-eeprom
@@ -0,0 +1,132 @@
#!/bin/sh
# Based on ar71xx 10-ath9k-eeprom

[ -e /lib/firmware/$FIRMWARE ] && exit 0

. /lib/functions.sh
. /lib/functions/system.sh
. /lib/functions/lantiq.sh
. /lib/upgrade/nand.sh

# xor multiple hex values of the same length
xor() {
local ret="0x$1"

shift 1
while [[ "$1" ]]; do
local val="0x$1"
ret=$((${ret:-0} ^ ${val:-0}))
shift 1
done

printf "%02x" "$ret"
}

ath9k_eeprom_die() {
echo "ath9k eeprom: " "$*"
exit 1
}

ath9k_eeprom_extract_raw() {
local source=$1
local offset=$2
local size=4096

dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$size 2>/dev/null || \
ath9k_eeprom_die "failed to extract from $mtd"
}

ath9k_eeprom_extract() {
local part=$1
local offset=$2
local mtd

mtd=$(find_mtd_chardev $part)
[ -n "$mtd" ] || \
ath9k_eeprom_die "no mtd device found for partition $part"

ath9k_eeprom_extract_raw $mtd $offset
}

ath9k_ubi_eeprom_extract() {
local part=$1
local offset=$2
local ubidev=$(nand_find_ubi $CI_UBIPART)
local ubi

ubi=$(nand_find_volume $ubidev $part)
[ -n "$ubi" ] || \
ath9k_eeprom_die "no UBI volume found for $part"

ath9k_eeprom_extract_raw /dev/$ubi $offset
}

ath9k_patch_firmware_mac() {
local mac=$1
local mac_offset=$2
local swap=$3
local chksum_offset=$4
local xor_mac
local xor_fw_mac
local xor_fw_chksum

[ -z "$mac" -o -z "$mac_offset" ] && return

[ $swap -gt 0 ] && mac="${mac:3:2}:${mac:0:2}:${mac:9:2}:${mac:6:2}:${mac:15:2}:${mac:12:2}"

[ -n "$chksum_offset" ] && {
xor_mac="${mac:0:2}${mac:3:2} ${mac:6:2}${mac:9:2} ${mac:12:2}${mac:15:2}"
xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/2 "%04x "' /lib/firmware/$FIRMWARE)

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)

echo -ne \\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"|"ath9k-eeprom-pci-0000:02:00.0.bin")
local board=$(lantiq_board_name)
case $board in
ARV7518PW)
ath9k_eeprom_extract "boardconfig" 1024
;;
ARV8539PW22)
ath9k_eeprom_extract "art" 1024
;;
BTHOMEHUBV2B)
ath9k_eeprom_extract "art" 0
ath9k_patch_firmware_mac "00:00:00:00:00:00" 524 1 514
;;
BTHOMEHUBV3A)
ath9k_eeprom_extract "art-copy" 0
ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 268 1 258
;;
BTHOMEHUBV5A)
ath9k_eeprom_extract "caldata" 4096
;;
DGN3500*)
ath9k_eeprom_extract "calibration" 61440
ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 524 0 514
;;
FRITZ3370)
ath9k_eeprom_extract "urlader" 2437
ath9k_patch_firmware_mac "00:00:00:00:00:00" 2 0
;;
FRITZ7320|FRITZ7360SL)
ath9k_eeprom_extract "urlader" 2437
ath9k_patch_firmware_mac "00:00:00:00:00:00" 268 0 258
;;
TDW8970|TDW8980)
ath9k_eeprom_extract "boardconfig" 135168
;;
*)
ath9k_eeprom_die "board $board is not supported yet"
;;
esac
;;
esac
31 changes: 15 additions & 16 deletions target/linux/lantiq/dts/ARV7518PW.dts
Expand Up @@ -77,15 +77,6 @@
gpio-controller;
lantiq,shadow = <0x0>;
};

ath9k_eep {
compatible = "ath9k,eeprom";
ath,eep-flash = <&boardconfig 0x400>;
ath,mac-offset = <0x16>;
ath,mac-increment = <1>;
ath,pci-slot = <14>;
ath,eep-endian;
};
};

gpio: pinmux@E100B10 {
Expand Down Expand Up @@ -138,13 +129,6 @@
gpios = <&gpio 14 0>;
};

pci@E105400 {
status = "okay";
lantiq,external-clock;
gpio-reset = <&gpio 21 0>;
req-mask = <0xf>;
};

};

/*
Expand Down Expand Up @@ -229,3 +213,18 @@
};
};
};

&pci0 {
status = "okay";
gpio-reset = <&gpio 21 0>;
lantiq,external-clock;
req-mask = <0xf>;

ath9k@7000 {
reg = <0x7000 0 0 0 0>;
qca,no-eeprom; /* load from ath9k-eeprom-pci-0000:00:0e.0.bin */
mtd-mac-address = <&boardconfig 0x16>;
mtd-mac-address-increment = <1>;
qca,check-eeprom-endianness;
};
};
27 changes: 12 additions & 15 deletions target/linux/lantiq/dts/ARV8539PW22.dts
Expand Up @@ -66,16 +66,6 @@
};
};
};

ath9k_eep {
compatible = "ath9k,eeprom";
ath,eep-flash = <&art 0x400>;
ath,mac-offset = <0x16>;
ath,mac-increment = <1>;
ath,pci-slot = <14>;
ath,eep-endian;
ath,arv-ath9k-fix;
};
};

gpio: pinmux@E100B10 {
Expand Down Expand Up @@ -112,11 +102,6 @@
mtd-mac-address = <&art 0x16>;
};

pci@E105400 {
status = "okay";
gpio-reset = <&gpio 21 0>;
};

ifxhcd@E101000 {
status = "okay";
gpios = <&gpio 14 0>;
Expand Down Expand Up @@ -176,3 +161,15 @@
};
};

&pci0 {
status = "okay";
gpio-reset = <&gpio 21 0>;

ath9k@7000 {
reg = <0x7000 0 0 0 0>;
qca,no-eeprom; /* load from ath9k-eeprom-pci-0000:00:0e.0.bin */
mtd-mac-address = <&art 0x16>;
mtd-mac-address-increment = <1>;
qca,check-eeprom-endianness;
};
};
33 changes: 14 additions & 19 deletions target/linux/lantiq/dts/BTHOMEHUBV2B.dts
Expand Up @@ -110,15 +110,6 @@
};
};
};


ath9k_eep {
compatible = "ath9k,eeprom";
ath,eep-flash = <&ath9k_cal 0x0000>;
ath,mac-increment = <1>;
ath,pci-slot = <14>;
ath,eep-endian;
};
};

gpio: pinmux@E100B10 {
Expand Down Expand Up @@ -208,16 +199,6 @@
lantiq,shadow = <0xfff>;
lantiq,groups = <0x3>;
};

pci@E105400 {
status = "okay";
lantiq,bus-clock = <33333333>;
interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
interrupt-map = <0x7000 0 0 1 &icu0 30 1>;
gpio-reset = <&gpio 21 0>;
req-mask = <0x1>; /* GNT1 */
};

};

gpio-keys-polled {
Expand Down Expand Up @@ -298,3 +279,17 @@
};
};

&pci0 {
status = "okay";
lantiq,bus-clock = <33333333>;
interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
interrupt-map = <0x7000 0 0 1 &icu0 30 1>;
gpio-reset = <&gpio 21 0>;
req-mask = <0x1>; /* GNT1 */

ath9k@7000 {
reg = <0x7000 0 0 0 0>;
qca,no-eeprom; /* load from ath9k-eeprom-pci-0000:00:0e.0.bin */
qca,check-eeprom-endianness;
};
};
22 changes: 10 additions & 12 deletions target/linux/lantiq/dts/BTHOMEHUBV3A.dts
Expand Up @@ -81,13 +81,6 @@
};
};
};

ath9k_eep {
compatible = "ath9k,eeprom";
ath,eep-flash = <&ath9k_cal 0x0000>;
ath,pci-slot = <14>;
ath,eep-endian;
};
};

gpio: pinmux@E100B10 {
Expand Down Expand Up @@ -146,11 +139,6 @@
gpios = <&gpio 33 0>;
};

pci@E105400 {
status = "okay";
gpio-reset = <&gpio 21 0>;
};

};

gpio-keys-polled {
Expand Down Expand Up @@ -220,3 +208,13 @@
};
};

&pci0 {
status = "okay";
gpio-reset = <&gpio 21 0>;

ath9k@7000 {
reg = <0x7000 0 0 0 0>;
qca,no-eeprom; /* load from ath9k-eeprom-pci-0000:00:0e.0.bin */
qca,check-eeprom-endianness;
};
};
32 changes: 16 additions & 16 deletions target/linux/lantiq/dts/BTHOMEHUBV5A.dts
Expand Up @@ -116,14 +116,6 @@
status = "okay";
gpios = <&gpio 33 0>;
};

pci@E105400 {
status = "okay";
lantiq,bus-clock = <33333333>;
interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
interrupt-map = <0x7000 0 0 1 &icu0 30 1>;
gpio-reset = <&gpio 21 0>;
};
};

gphy-xrx200 {
Expand All @@ -133,14 +125,6 @@
phys = [ 00 01 ];
};

ath9k_eep {
compatible = "ath9k,eeprom";
ath,eep-flash = <&caldata 0x1000>;
ath,mac-offset = <0x110c>;
ath,mac-increment = <2>;
ath,pci-slot = <0xe>; /* 14 */
};

gpio-keys-polled {
compatible = "gpio-keys-polled";
#address-cells = <1>;
Expand Down Expand Up @@ -219,6 +203,22 @@
};
};

&pci0 {
status = "okay";
lantiq,bus-clock = <33333333>;
interrupt-map-mask = <0xf800 0x0 0x0 0x7>;
interrupt-map = <0x7000 0 0 1 &icu0 30 1>;
gpio-reset = <&gpio 21 0>;

ath9k@7000 {
reg = <0x7000 0 0 0 0>;
qca,no-eeprom; /* load from ath9k-eeprom-pci-0000:00:0e.0.bin */
qca,disable-5ghz;
mtd-mac-address = <&caldata 0x110c>;
mtd-mac-address-increment = <2>;
};
};

&eth0 {
lan: interface@0 {
compatible = "lantiq,xrx200-pdi";
Expand Down

0 comments on commit 4827ec3

Please sign in to comment.