lantiq: fix ath9k EEPROM data swapping for some devices

The EEPROM data in the flash of the ARV7518PW, ARV8539PW22,
BTHOMEHUBV2B and BTHOMEHUBV3A is stored byte-swapped (swab16), meaning
that for example the ath9k base_eep_header fields "version" (high and
low byte), "opCapFlags" and "eepMisc" are swapped (the latter ones are
just 1 byte wide, thus their position is swapped).

The old "ath,eep-endian" property enabled the corresponding swapping
logic in the ath9k driver (swab16 in ath9k_hw_nvram_swap_data, which is
based on the magic bytes in the EEPROM data which have nothing to do
with the calibration data - thus this logic should not be used
anymore).
Since we have switched to the upstream ath9k devicetree bindings there
is no binding anymore which enables swab16 in ath9k (as this logic is
not recommended anymore as explained above), leading to ath9k
initialization errors:
ath: phy0: Bad EEPROM VER 0x0001 or REV 0x00e0
(this shows that the version field is swapped, expected values are VER
0x000E and REV 0x0001)

Swapping the ath9k calibration data when extracting it from the flash
fixes the devices listed above (all other devices do not require
additional swapping, since the position of the fields is already as
expected by ath9k). This allows ath9k to read the version correctly
again, as well as the more important "eepmisc" field (which is used for
determining whether the data inside the EEPROM is Big or Little Endian
which is required to parse the EEPROM contents correctly).

Fixes: a20616863d ("lantiq: use ath9k device tree bindings
binding/owl-loader")

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
This commit is contained in:
Martin Blumenstingl 2016-12-04 08:26:55 +01:00 committed by Mathias Kresin
parent ee55a19a61
commit afa3709266

View file

@ -32,27 +32,39 @@ ath9k_eeprom_die() {
ath9k_eeprom_extract_raw() { ath9k_eeprom_extract_raw() {
local source=$1 local source=$1
local offset=$2 local offset=$2
local swap=$3
local size=4096 local size=4096
local bs=1
local conv=
dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$size 2>/dev/null || \ if [ $swap -gt 0 ]; then
bs=2
conv="conv=swab"
size=$((size / bs))
offset=$((offset / bs))
fi
dd if=$source of=/lib/firmware/$FIRMWARE bs=$bs skip=$offset count=$size $conv 2>/dev/null || \
ath9k_eeprom_die "failed to extract from $mtd" ath9k_eeprom_die "failed to extract from $mtd"
} }
ath9k_eeprom_extract() { ath9k_eeprom_extract() {
local part=$1 local part=$1
local offset=$2 local offset=$2
local swap=$3
local mtd local mtd
mtd=$(find_mtd_chardev $part) mtd=$(find_mtd_chardev $part)
[ -n "$mtd" ] || \ [ -n "$mtd" ] || \
ath9k_eeprom_die "no mtd device found for partition $part" ath9k_eeprom_die "no mtd device found for partition $part"
ath9k_eeprom_extract_raw $mtd $offset ath9k_eeprom_extract_raw $mtd $offset $swap
} }
ath9k_ubi_eeprom_extract() { ath9k_ubi_eeprom_extract() {
local part=$1 local part=$1
local offset=$2 local offset=$2
local swap=$3
local ubidev=$(nand_find_ubi $CI_UBIPART) local ubidev=$(nand_find_ubi $CI_UBIPART)
local ubi local ubi
@ -60,7 +72,7 @@ ath9k_ubi_eeprom_extract() {
[ -n "$ubi" ] || \ [ -n "$ubi" ] || \
ath9k_eeprom_die "no UBI volume found for $part" ath9k_eeprom_die "no UBI volume found for $part"
ath9k_eeprom_extract_raw /dev/$ubi $offset ath9k_eeprom_extract_raw /dev/$ubi $offset $swap
} }
ath9k_patch_firmware_mac() { ath9k_patch_firmware_mac() {
@ -101,37 +113,37 @@ case "$FIRMWARE" in
case "$board" in case "$board" in
ARV7518PW) ARV7518PW)
ath9k_eeprom_extract "boardconfig" 1024 ath9k_eeprom_extract "boardconfig" 1024 1
;; ;;
ARV8539PW22) ARV8539PW22)
ath9k_eeprom_extract "art" 1024 ath9k_eeprom_extract "art" 1024 1
;; ;;
BTHOMEHUBV2B) BTHOMEHUBV2B)
ath9k_eeprom_extract "art" 0 ath9k_eeprom_extract "art" 0 1
ath9k_patch_firmware_mac "00:00:00:00:00:00" 524 1 514 ath9k_patch_firmware_mac "00:00:00:00:00:00" 524 0 514
;; ;;
BTHOMEHUBV3A) BTHOMEHUBV3A)
ath9k_eeprom_extract "art-copy" 0 ath9k_eeprom_extract "art-copy" 0 1
ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 268 1 258 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 268 0 258
;; ;;
BTHOMEHUBV5A) BTHOMEHUBV5A)
ath9k_ubi_eeprom_extract "caldata" 4096 ath9k_ubi_eeprom_extract "caldata" 4096 0
ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi caldata 4364) +2) 268 0 258 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi caldata 4364) +2) 268 0 258
;; ;;
DGN3500*) DGN3500*)
ath9k_eeprom_extract "calibration" 61440 ath9k_eeprom_extract "calibration" 61440 0
ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 524 0 514 ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 524 0 514
;; ;;
FRITZ3370) FRITZ3370)
ath9k_eeprom_extract "urlader" 2437 ath9k_eeprom_extract "urlader" 2437 0
ath9k_patch_firmware_mac "00:00:00:00:00:00" 2 0 ath9k_patch_firmware_mac "00:00:00:00:00:00" 2 0
;; ;;
FRITZ7320|FRITZ7360SL) FRITZ7320|FRITZ7360SL)
ath9k_eeprom_extract "urlader" 2437 ath9k_eeprom_extract "urlader" 2437 0
ath9k_patch_firmware_mac "00:00:00:00:00:00" 268 0 258 ath9k_patch_firmware_mac "00:00:00:00:00:00" 268 0 258
;; ;;
TDW8970|TDW8980) TDW8970|TDW8980)
ath9k_eeprom_extract "boardconfig" 135168 ath9k_eeprom_extract "boardconfig" 135168 0
;; ;;
*) *)
ath9k_eeprom_die "board $board is not supported yet" ath9k_eeprom_die "board $board is not supported yet"