-
-
Save igrr/3537f8ddb03a50aa980e2e0c121c7581 to your computer and use it in GitHub Desktop.
Script for https://github.com/espressif/qemu/issues/76
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import binascii | |
import sys | |
def main(): | |
parser = argparse.ArgumentParser(description="Generate efuse binary") | |
parser.add_argument( | |
"--mac", type=str, default="11:22:33:44:55:66", help="MAC address to use" | |
) | |
parser.add_argument("output_file", type=argparse.FileType("wb"), help="Output file") | |
args = parser.parse_args() | |
mac_addr_str = args.mac | |
mac_addr = binascii.unhexlify(mac_addr_str.replace(":", "")) | |
mac_addr_crc = calc_mac_addr_crc(mac_addr) | |
efuse_data = bytearray(124) | |
# MAC address | |
efuse_data[4:10] = mac_addr[::-1] | |
efuse_data[10] = mac_addr_crc | |
# Chip revision bits | |
efuse_data[13] = 0x80 | |
efuse_data[22] = 0x10 | |
args.output_file.write(efuse_data) | |
def calc_mac_addr_crc(mac_addr): | |
i = 0 | |
j = 0 | |
crc = 0 | |
length = len(mac_addr) | |
while length > 0: | |
length -= 1 | |
crc = crc ^ mac_addr[j] | |
j += 1 | |
for i in range(8): | |
if (crc) & 0x01: | |
crc = ((crc >> 1) ^ (0x8C)) & 0xFF | |
else: | |
crc = (crc >> 1) & 0xFF | |
return crc | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment