blob: 0d2a1973e3c781e42497e778327188264a21e491 [file] [log] [blame]
#!/usr/bin/python3
import binascii
# Fetch and trim whitespace from the wlan mac
with open('/sys/class/net/wlan0/address') as mac_address_file:
mac_address = mac_address_file.read().strip()
# Split the address on :, reverse the order, rejoin and convert to binary.
# This gives it to us in the proper endianness to write into the EEPROM.
mac_address_bin = binascii.a2b_hex(''.join(reversed(mac_address.split(':'))))
# Overwrite the EEPROM at the correct offset.
# With this as a real value instead of zeroes, the bluetooth driver
# will use the address instead of generating a random one.
with open('/lib/firmware/EEPROM_MT7668.bin', 'r+b') as eeprom:
eeprom.seek(0x384)
eeprom.write(mac_address_bin)