ar71xx: Do not use a hardcoded ath10k firmware mac address
authorMartin Blumenstingl <martin.blumenstingl@googlemail.com>
Sun, 18 Sep 2016 21:29:35 +0000 (23:29 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 28 Sep 2016 06:39:01 +0000 (08:39 +0200)
ar71xx has an init-script for special devices where the ath10k OTP
calibration data is stored on the PCIe card's EEPROM (and thus can only
be read by ath10k). Unfortunately the OTP data uses the default mac
address (= all devices come with the same mac address, which leads to
problems when you have multiple of these devices in the same network).

To work around this the mac address is patched in the firmware during
the first boot of the device. To prevent flash wear this was only done
if the ath10k firmware matched a hardcoded md5sum.
However, if the md5sum does not match this can mean that either the mac
address was already patched (which is fine) - unfortunately it can also
mean that the firmware version was updated without updating the
hardcoded md5sum.

Change the "was the mac address already patched" check to actually
compare the mac address inside the ath10k firmware.

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
target/linux/ar71xx/base-files/lib/preinit/82_patch_ath10k

index af12bd5d927181b3461573a330550d2d6c557995..b6af921449b0284d1e05212bbe618d77744e8a15 100644 (file)
@@ -12,16 +12,19 @@ do_patch_ath10k_firmware() {
                return
        }
 
                return
        }
 
-       local firmware_md5_orig="fcb2fbd42d73a63fbf603505c718cbde"
-       local firmware_md5_current="$(md5sum $firmware_file)"
-       local firmware_md5_current="${firmware_md5_current%% *}"
+       local mac_offset=276
+       local mac_length=6
+       local default_mac="00:03:07:12:34:56"
+       local current_mac="$(hexdump -v -n $mac_length -s $mac_offset -e '5/1 "%02x:" 1/1 "%02x"' $firmware_file  2>/dev/null)"
 
 
-       # verify md5sum before patching
-       [ "$firmware_md5_orig" != "$firmware_md5_current" ] || {
+       # check if mac address was already patched
+       [ "$default_mac" = "$current_mac" ] || {
                return
        }
 
                return
        }
 
-       # some boards have bogus mac in otp, patch the default mac in the firmware
+       # some boards have bogus mac in otp (= directly in the PCIe card's EEPROM).
+       # we have to patch the default mac in the firmware because we cannot change
+       # the otp.
        case $(ar71xx_board_name) in
                dgl-5500-a1 | tew-823dru)
                        local mac
        case $(ar71xx_board_name) in
                dgl-5500-a1 | tew-823dru)
                        local mac
@@ -29,7 +32,7 @@ do_patch_ath10k_firmware() {
 
                        cp $firmware_file /tmp/ath10k-firmware.bin
                        macaddr_2bin $mac | dd of=/tmp/ath10k-firmware.bin \
 
                        cp $firmware_file /tmp/ath10k-firmware.bin
                        macaddr_2bin $mac | dd of=/tmp/ath10k-firmware.bin \
-                               conv=notrunc bs=1 seek=276 count=6
+                               conv=notrunc bs=1 seek=$mac_offset count=$mac_length
 
                ;;
        esac
 
                ;;
        esac