From 6a17e7f3933b5eccd07a5d1126acd2e5c1efea81 Mon Sep 17 00:00:00 2001 From: KonstantinKondrashov Date: Wed, 7 Jun 2023 14:54:31 +0800 Subject: [PATCH] esptool & espefuse: Fix byte order in MAC (for C6 and H2) MAC: 60:55:f9:ff:fe:f7:2c:a2 (EUI64, used for IEEE802154) BASE MAC: 60:55:f9:f7:2c:a2 (used for BT) MAC_EXT: ff:fe --- docs/en/espefuse/inc/summary_ESP32-H2.rst | 4 +-- espefuse/efuse/base_fields.py | 9 ++++-- espefuse/efuse/esp32c6/fields.py | 33 ++++++++++++++------- espefuse/efuse/esp32c6/mem_definition.py | 11 +++++++ espefuse/efuse/esp32c6/operations.py | 3 +- espefuse/efuse/esp32h2/fields.py | 35 +++++++++++++--------- espefuse/efuse/esp32h2/mem_definition.py | 17 ++++++++++- espefuse/efuse/esp32h2/operations.py | 3 +- espefuse/efuse/esp32h2beta1/fields.py | 36 ++++++++++++++--------- espefuse/efuse/esp32h2beta1/operations.py | 3 +- esptool/cmds.py | 10 +++++-- esptool/targets/esp32.py | 4 ++- esptool/targets/esp32c3.py | 5 +++- esptool/targets/esp32c6.py | 23 ++++++++++----- esptool/targets/esp32h2.py | 2 +- esptool/targets/esp32h2beta1.py | 5 +++- esptool/targets/esp32s2.py | 5 +++- esptool/targets/esp32s3.py | 5 +++- esptool/targets/esp8266.py | 4 ++- test/test_espefuse.py | 21 +++---------- 20 files changed, 153 insertions(+), 85 deletions(-) diff --git a/docs/en/espefuse/inc/summary_ESP32-H2.rst b/docs/en/espefuse/inc/summary_ESP32-H2.rst index 920ace3f37..0032586bdd 100644 --- a/docs/en/espefuse/inc/summary_ESP32-H2.rst +++ b/docs/en/espefuse/inc/summary_ESP32-H2.rst @@ -62,10 +62,10 @@ Mac fuses: MAC (BLOCK1) MAC address - = 60:55:f9:f7:2c:05:ff:fe (OK) R/W + = 60:55:f9:f7:2c:05 (OK) R/W MAC_EXT (BLOCK1) Stores the extended bits of MAC address = ff:fe (OK) R/W CUSTOM_MAC (BLOCK3) Custom MAC - = 00:00:00:00:00:00:ff:fe (OK) R/W + = 00:00:00:00:00:00 (OK) R/W Security fuses: DIS_FORCE_DOWNLOAD (BLOCK0) Represents whether the function that forces chip i = False R/W (0b0) diff --git a/espefuse/efuse/base_fields.py b/espefuse/efuse/base_fields.py index fe244efc3c..ab12f0312b 100644 --- a/espefuse/efuse/base_fields.py +++ b/espefuse/efuse/base_fields.py @@ -577,6 +577,9 @@ def __init__(self, parent, param): self.bitarray.set(0) self.update(self.parent.blocks[self.block].bitarray) + def is_field_calculated(self): + return self.word is None or self.pos is None + def check_format(self, new_value_str): if new_value_str is None: return new_value_str @@ -669,8 +672,10 @@ def save(self, new_value): self.save_to_block(bitarray_field) def update(self, bit_array_block): - if self.word is None or self.pos is None: - self.bitarray.overwrite(self.convert_to_bitstring(self.get()), pos=0) + if self.is_field_calculated(): + self.bitarray.overwrite( + self.convert_to_bitstring(self.check_format(self.get())), pos=0 + ) return field_len = self.bitarray.len bit_array_block.pos = bit_array_block.length - ( diff --git a/espefuse/efuse/esp32c6/fields.py b/espefuse/efuse/esp32c6/fields.py index 2d09c9fd33..3f67ec06d0 100644 --- a/espefuse/efuse/esp32c6/fields.py +++ b/espefuse/efuse/esp32c6/fields.py @@ -326,23 +326,27 @@ def check_format(self, new_value_str): raise esptool.FatalError( "Required MAC Address in AA:CD:EF:01:02:03 format!" ) - if new_value_str.count(":") != 5: + num_bytes = 8 if self.name == "MAC_EUI64" else 6 + if new_value_str.count(":") != num_bytes - 1: raise esptool.FatalError( - "MAC Address needs to be a 6-byte hexadecimal format " + f"MAC Address needs to be a {num_bytes}-byte hexadecimal format " "separated by colons (:)!" ) - hexad = new_value_str.replace(":", "") - if len(hexad) != 12: + hexad = new_value_str.replace(":", "").split(" ", 1)[0] + hexad = hexad.split(" ", 1)[0] if self.is_field_calculated() else hexad + if len(hexad) != num_bytes * 2: raise esptool.FatalError( - "MAC Address needs to be a 6-byte hexadecimal number " - "(12 hexadecimal characters)!" + f"MAC Address needs to be a {num_bytes}-byte hexadecimal number " + f"({num_bytes * 2} hexadecimal characters)!" ) # order of bytearray = b'\xaa\xcd\xef\x01\x02\x03', bindata = binascii.unhexlify(hexad) - # unicast address check according to - # https://tools.ietf.org/html/rfc7042#section-2.1 - if esptool.util.byte(bindata, 0) & 0x01: - raise esptool.FatalError("Custom MAC must be a unicast MAC!") + + if not self.is_field_calculated(): + # unicast address check according to + # https://tools.ietf.org/html/rfc7042#section-2.1 + if esptool.util.byte(bindata, 0) & 0x01: + raise esptool.FatalError("Custom MAC must be a unicast MAC!") return bindata def check(self): @@ -356,6 +360,13 @@ def check(self): def get(self, from_read=True): if self.name == "CUSTOM_MAC": mac = self.get_raw(from_read)[::-1] + elif self.name == "MAC": + mac = self.get_raw(from_read) + elif self.name == "MAC_EUI64": + mac = self.parent["MAC"].get_bitstring(from_read).copy() + mac_ext = self.parent["MAC_EXT"].get_bitstring(from_read) + mac.insert(mac_ext, 24) + mac = mac.bytes else: mac = self.get_raw(from_read) return "%s %s" % (util.hexify(mac, ":"), self.check()) @@ -375,7 +386,7 @@ def print_field(e, new_value): else: # Writing the BLOCK1 (MAC_SPI_8M_0) default MAC is not possible, # as it's written in the factory. - raise esptool.FatalError("Writing Factory MAC address is not supported") + raise esptool.FatalError(f"Burning {self.name} is not supported") # fmt: off diff --git a/espefuse/efuse/esp32c6/mem_definition.py b/espefuse/efuse/esp32c6/mem_definition.py index 60e4b6cdec..25e4caf011 100644 --- a/espefuse/efuse/esp32c6/mem_definition.py +++ b/espefuse/efuse/esp32c6/mem_definition.py @@ -12,6 +12,7 @@ EfuseBlocksBase, EfuseFieldsBase, EfuseRegistersBase, + Field, ) @@ -151,6 +152,16 @@ def __init__(self) -> None: self.BLOCK2_CALIBRATION_EFUSES.append(efuse) self.ALL_EFUSES[i] = None + f = Field() + f.name = "MAC_EUI64" + f.block = 1 + f.bit_len = 64 + f.type = f"bytes:{f.bit_len // 8}" + f.category = "MAC" + f.class_type = "mac" + f.description = "calc MAC_EUI64 = MAC[0]:MAC[1]:MAC[2]:MAC_EXT[0]:MAC_EXT[1]:MAC[3]:MAC[4]:MAC[5]" + self.CALC.append(f) + for efuse in self.ALL_EFUSES: if efuse is not None: self.EFUSES.append(efuse) diff --git a/espefuse/efuse/esp32c6/operations.py b/espefuse/efuse/esp32c6/operations.py index f37991ccab..f8e450fa0d 100644 --- a/espefuse/efuse/esp32c6/operations.py +++ b/espefuse/efuse/esp32c6/operations.py @@ -167,8 +167,7 @@ def add_commands(subparsers, efuses): p.add_argument( "mac", help="Custom MAC Address to burn given in hexadecimal format with bytes " - "separated by colons (e.g. AA:CD:EF:01:02:03). " - "Final CUSTOM_MAC = CUSTOM_MAC[48] + MAC_EXT[16]", + "separated by colons (e.g. AA:CD:EF:01:02:03).", type=fields.base_fields.CheckArgValue(efuses, "CUSTOM_MAC"), ) add_force_write_always(p) diff --git a/espefuse/efuse/esp32h2/fields.py b/espefuse/efuse/esp32h2/fields.py index 5be8352536..7f7d4cee46 100644 --- a/espefuse/efuse/esp32h2/fields.py +++ b/espefuse/efuse/esp32h2/fields.py @@ -327,23 +327,27 @@ def check_format(self, new_value_str): raise esptool.FatalError( "Required MAC Address in AA:CD:EF:01:02:03 format!" ) - if new_value_str.count(":") != 5: + num_bytes = 8 if self.name == "MAC_EUI64" else 6 + if new_value_str.count(":") != num_bytes - 1: raise esptool.FatalError( - "MAC Address needs to be a 6-byte hexadecimal format " + f"MAC Address needs to be a {num_bytes}-byte hexadecimal format " "separated by colons (:)!" ) hexad = new_value_str.replace(":", "") - if len(hexad) != 12: + hexad = hexad.split(" ", 1)[0] if self.is_field_calculated() else hexad + if len(hexad) != num_bytes * 2: raise esptool.FatalError( - "MAC Address needs to be a 6-byte hexadecimal number " - "(12 hexadecimal characters)!" + f"MAC Address needs to be a {num_bytes}-byte hexadecimal number " + f"({num_bytes * 2} hexadecimal characters)!" ) # order of bytearray = b'\xaa\xcd\xef\x01\x02\x03', bindata = binascii.unhexlify(hexad) - # unicast address check according to - # https://tools.ietf.org/html/rfc7042#section-2.1 - if esptool.util.byte(bindata, 0) & 0x01: - raise esptool.FatalError("Custom MAC must be a unicast MAC!") + + if not self.is_field_calculated(): + # unicast address check according to + # https://tools.ietf.org/html/rfc7042#section-2.1 + if esptool.util.byte(bindata, 0) & 0x01: + raise esptool.FatalError("Custom MAC must be a unicast MAC!") return bindata def check(self): @@ -356,11 +360,14 @@ def check(self): def get(self, from_read=True): if self.name == "CUSTOM_MAC": - mac = self.get_raw(from_read)[::-1] + self.parent["MAC_EXT"].get_raw( - from_read - ) + mac = self.get_raw(from_read)[::-1] elif self.name == "MAC": - mac = self.get_raw(from_read) + self.parent["MAC_EXT"].get_raw(from_read) + mac = self.get_raw(from_read) + elif self.name == "MAC_EUI64": + mac = self.parent["MAC"].get_bitstring(from_read).copy() + mac_ext = self.parent["MAC_EXT"].get_bitstring(from_read) + mac.insert(mac_ext, 24) + mac = mac.bytes else: mac = self.get_raw(from_read) return "%s %s" % (util.hexify(mac, ":"), self.check()) @@ -380,7 +387,7 @@ def print_field(e, new_value): else: # Writing the BLOCK1 (MAC_SPI_8M_0) default MAC is not possible, # as it's written in the factory. - raise esptool.FatalError("Writing Factory MAC address is not supported") + raise esptool.FatalError(f"Burning {self.name} is not supported") # fmt: off diff --git a/espefuse/efuse/esp32h2/mem_definition.py b/espefuse/efuse/esp32h2/mem_definition.py index d548794f64..edf07f1129 100644 --- a/espefuse/efuse/esp32h2/mem_definition.py +++ b/espefuse/efuse/esp32h2/mem_definition.py @@ -8,7 +8,12 @@ import yaml -from ..mem_definition_base import EfuseBlocksBase, EfuseFieldsBase, EfuseRegistersBase +from ..mem_definition_base import ( + EfuseBlocksBase, + EfuseFieldsBase, + EfuseRegistersBase, + Field, +) class EfuseDefineRegisters(EfuseRegistersBase): @@ -147,6 +152,16 @@ def __init__(self) -> None: self.BLOCK2_CALIBRATION_EFUSES.append(efuse) self.ALL_EFUSES[i] = None + f = Field() + f.name = "MAC_EUI64" + f.block = 1 + f.bit_len = 64 + f.type = f"bytes:{f.bit_len // 8}" + f.category = "MAC" + f.class_type = "mac" + f.description = "calc MAC_EUI64 = MAC[0]:MAC[1]:MAC[2]:MAC_EXT[0]:MAC_EXT[1]:MAC[3]:MAC[4]:MAC[5]" + self.CALC.append(f) + for efuse in self.ALL_EFUSES: if efuse is not None: self.EFUSES.append(efuse) diff --git a/espefuse/efuse/esp32h2/operations.py b/espefuse/efuse/esp32h2/operations.py index 3ce3c896eb..20a76da96d 100644 --- a/espefuse/efuse/esp32h2/operations.py +++ b/espefuse/efuse/esp32h2/operations.py @@ -166,8 +166,7 @@ def add_commands(subparsers, efuses): p.add_argument( "mac", help="Custom MAC Address to burn given in hexadecimal format with bytes " - "separated by colons (e.g. AA:CD:EF:01:02:03). " - "Final CUSTOM_MAC = CUSTOM_MAC[48] + MAC_EXT[16]", + "separated by colons (e.g. AA:CD:EF:01:02:03).", type=fields.base_fields.CheckArgValue(efuses, "CUSTOM_MAC"), ) add_force_write_always(p) diff --git a/espefuse/efuse/esp32h2beta1/fields.py b/espefuse/efuse/esp32h2beta1/fields.py index ec2e8a217c..bef76f4e24 100644 --- a/espefuse/efuse/esp32h2beta1/fields.py +++ b/espefuse/efuse/esp32h2beta1/fields.py @@ -326,23 +326,27 @@ def check_format(self, new_value_str): raise esptool.FatalError( "Required MAC Address in AA:CD:EF:01:02:03 format!" ) - if new_value_str.count(":") != 5: + num_bytes = 8 if self.name == "MAC_EUI64" else 6 + if new_value_str.count(":") != num_bytes - 1: raise esptool.FatalError( - "MAC Address needs to be a 6-byte hexadecimal format " + f"MAC Address needs to be a {num_bytes}-byte hexadecimal format " "separated by colons (:)!" ) - hexad = new_value_str.replace(":", "") - if len(hexad) != 12: + hexad = new_value_str.replace(":", "").split(" ", 1)[0] + hexad = hexad.split(" ", 1)[0] if self.is_field_calculated() else hexad + if len(hexad) != num_bytes * 2: raise esptool.FatalError( - "MAC Address needs to be a 6-byte hexadecimal number " - "(12 hexadecimal characters)!" + f"MAC Address needs to be a {num_bytes}-byte hexadecimal number " + f"({num_bytes * 2} hexadecimal characters)!" ) # order of bytearray = b'\xaa\xcd\xef\x01\x02\x03', bindata = binascii.unhexlify(hexad) - # unicast address check according to - # https://tools.ietf.org/html/rfc7042#section-2.1 - if esptool.util.byte(bindata, 0) & 0x01: - raise esptool.FatalError("Custom MAC must be a unicast MAC!") + + if not self.is_field_calculated(): + # unicast address check according to + # https://tools.ietf.org/html/rfc7042#section-2.1 + if esptool.util.byte(bindata, 0) & 0x01: + raise esptool.FatalError("Custom MAC must be a unicast MAC!") return bindata def check(self): @@ -355,11 +359,14 @@ def check(self): def get(self, from_read=True): if self.name == "CUSTOM_MAC": - mac = self.get_raw(from_read)[::-1] + self.parent["MAC_EXT"].get_raw( - from_read - ) + mac = self.get_raw(from_read)[::-1] elif self.name == "MAC": - mac = self.get_raw(from_read) + self.parent["MAC_EXT"].get_raw(from_read) + mac = self.get_raw(from_read) + elif self.name == "MAC_EUI64": + mac = self.parent["MAC"].get_bitstring(from_read).copy() + mac_ext = self.parent["MAC_EXT"].get_bitstring(from_read) + mac.insert(mac_ext, 24) + mac = mac.bytes else: mac = self.get_raw(from_read) return "%s %s" % (util.hexify(mac, ":"), self.check()) @@ -379,6 +386,7 @@ def print_field(e, new_value): else: # Writing the BLOCK1 (MAC_SPI_8M_0) default MAC is not possible, # as it's written in the factory. + raise esptool.FatalError(f"Burning {self.name} is not supported") raise esptool.FatalError("Writing Factory MAC address is not supported") diff --git a/espefuse/efuse/esp32h2beta1/operations.py b/espefuse/efuse/esp32h2beta1/operations.py index 35cbb94c3a..9f602544ae 100644 --- a/espefuse/efuse/esp32h2beta1/operations.py +++ b/espefuse/efuse/esp32h2beta1/operations.py @@ -166,8 +166,7 @@ def add_commands(subparsers, efuses): p.add_argument( "mac", help="Custom MAC Address to burn given in hexadecimal format with bytes " - "separated by colons (e.g. AA:CD:EF:01:02:03). " - "Final CUSTOM_MAC = CUSTOM_MAC[48] + MAC_EXT[16]", + "separated by colons (e.g. AA:CD:EF:01:02:03).", type=fields.base_fields.CheckArgValue(efuses, "CUSTOM_MAC"), ) add_force_write_always(p) diff --git a/esptool/cmds.py b/esptool/cmds.py index ed9cdb3a32..02442f9dee 100644 --- a/esptool/cmds.py +++ b/esptool/cmds.py @@ -1029,12 +1029,16 @@ def elf2image(args): def read_mac(esp, args): - mac = esp.read_mac() - def print_mac(label, mac): print("%s: %s" % (label, ":".join(map(lambda x: "%02x" % x, mac)))) - print_mac("MAC", mac) + eui64 = esp.read_mac("EUI64") + if eui64: + print_mac("MAC", eui64) + print_mac("BASE MAC", esp.read_mac("BASE_MAC")) + print_mac("MAC_EXT", esp.read_mac("MAC_EXT")) + else: + print_mac("MAC", esp.read_mac("BASE_MAC")) def chip_id(esp, args): diff --git a/esptool/targets/esp32.py b/esptool/targets/esp32.py index b805ed453e..45aac2e95c 100644 --- a/esptool/targets/esp32.py +++ b/esptool/targets/esp32.py @@ -283,8 +283,10 @@ def read_efuse(self, n): def chip_id(self): raise NotSupportedError(self, "chip_id") - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): """Read MAC from EFUSE region""" + if mac_type != "BASE_MAC": + return None words = [self.read_efuse(2), self.read_efuse(1)] bitstring = struct.pack(">II", *words) bitstring = bitstring[2:8] # trim the 2 byte CRC diff --git a/esptool/targets/esp32c3.py b/esptool/targets/esp32c3.py index 3b3c30153e..f7d6540d3f 100644 --- a/esptool/targets/esp32c3.py +++ b/esptool/targets/esp32c3.py @@ -134,7 +134,10 @@ def override_vddsdio(self, new_voltage): "VDD_SDIO overrides are not supported for ESP32-C3" ) - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): + """Read MAC from EFUSE region""" + if mac_type != "BASE_MAC": + return None mac0 = self.read_reg(self.MAC_EFUSE_REG) mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC bitstring = struct.pack(">II", mac1, mac0)[2:] diff --git a/esptool/targets/esp32c6.py b/esptool/targets/esp32c6.py index a2d736c51f..fd39c6e096 100644 --- a/esptool/targets/esp32c6.py +++ b/esptool/targets/esp32c6.py @@ -134,15 +134,22 @@ def override_vddsdio(self, new_voltage): "VDD_SDIO overrides are not supported for ESP32-C6" ) - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): + """Read MAC from EFUSE region""" mac0 = self.read_reg(self.MAC_EFUSE_REG) - mac_reg1 = self.read_reg(self.MAC_EFUSE_REG + 4) - mac1 = mac_reg1 & 0xFFFF - mac_ext = (mac_reg1 >> 16) & 0xFFFF - bitstring = struct.pack(">HIH", mac1, mac0, mac_ext) - # MAC: 60:55:f9:f7:2c:a2:ff:fe - # | mac1| mac0 | mac_ext| - return tuple(bitstring) + mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC + base_mac = struct.pack(">II", mac1, mac0)[2:] + ext_mac = struct.pack(">H", (mac1 >> 16) & 0xFFFF) + eui64 = base_mac[0:3] + ext_mac + base_mac[3:6] + # BASE MAC: 60:55:f9:f7:2c:a2 + # EUI64 MAC: 60:55:f9:ff:fe:f7:2c:a2 + # EXT_MAC: ff:fe + macs = { + "BASE_MAC": tuple(base_mac), + "EUI64": tuple(eui64), + "MAC_EXT": tuple(ext_mac), + } + return macs.get(mac_type, None) def get_flash_crypt_config(self): return None # doesn't exist on ESP32-C6 diff --git a/esptool/targets/esp32h2.py b/esptool/targets/esp32h2.py index 73fe60c339..88a0bba182 100644 --- a/esptool/targets/esp32h2.py +++ b/esptool/targets/esp32h2.py @@ -50,7 +50,7 @@ def get_chip_description(self): return f"{chip_name} (revision v{major_rev}.{minor_rev})" def get_chip_features(self): - return ["BLE"] + return ["BLE", "IEEE802.15.4"] def get_crystal_freq(self): # ESP32H2 XTAL is fixed to 32MHz diff --git a/esptool/targets/esp32h2beta1.py b/esptool/targets/esp32h2beta1.py index 2720f15868..49e38e44ae 100644 --- a/esptool/targets/esp32h2beta1.py +++ b/esptool/targets/esp32h2beta1.py @@ -106,7 +106,10 @@ def override_vddsdio(self, new_voltage): "VDD_SDIO overrides are not supported for ESP32-H2" ) - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): + """Read MAC from EFUSE region""" + if mac_type != "BASE_MAC": + return None mac0 = self.read_reg(self.MAC_EFUSE_REG) mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC bitstring = struct.pack(">II", mac1, mac0)[2:] diff --git a/esptool/targets/esp32s2.py b/esptool/targets/esp32s2.py index bffd553317..92b6118126 100644 --- a/esptool/targets/esp32s2.py +++ b/esptool/targets/esp32s2.py @@ -182,7 +182,10 @@ def override_vddsdio(self, new_voltage): "VDD_SDIO overrides are not supported for ESP32-S2" ) - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): + """Read MAC from EFUSE region""" + if mac_type != "BASE_MAC": + return None mac0 = self.read_reg(self.MAC_EFUSE_REG) mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC bitstring = struct.pack(">II", mac1, mac0)[2:] diff --git a/esptool/targets/esp32s3.py b/esptool/targets/esp32s3.py index ef611dc8b9..8a29add2d6 100644 --- a/esptool/targets/esp32s3.py +++ b/esptool/targets/esp32s3.py @@ -213,7 +213,10 @@ def override_vddsdio(self, new_voltage): "VDD_SDIO overrides are not supported for ESP32-S3" ) - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): + """Read MAC from EFUSE region""" + if mac_type != "BASE_MAC": + return None mac0 = self.read_reg(self.MAC_EFUSE_REG) mac1 = self.read_reg(self.MAC_EFUSE_REG + 4) # only bottom 16 bits are MAC bitstring = struct.pack(">II", mac1, mac0)[2:] diff --git a/esptool/targets/esp8266.py b/esptool/targets/esp8266.py index f9966634d5..9027eb86ea 100644 --- a/esptool/targets/esp8266.py +++ b/esptool/targets/esp8266.py @@ -131,8 +131,10 @@ def chip_id(self): id1 = self.read_reg(self.ESP_OTP_MAC1) return (id0 >> 24) | ((id1 & 0xFFFFFF) << 8) - def read_mac(self): + def read_mac(self, mac_type="BASE_MAC"): """Read MAC from OTP ROM""" + if mac_type != "BASE_MAC": + return None mac0 = self.read_reg(self.ESP_OTP_MAC0) mac1 = self.read_reg(self.ESP_OTP_MAC1) mac3 = self.read_reg(self.ESP_OTP_MAC3) diff --git a/test/test_espefuse.py b/test/test_espefuse.py index 68cbc34ee3..6f81763235 100755 --- a/test/test_espefuse.py +++ b/test/test_espefuse.py @@ -184,8 +184,6 @@ def test_get_custom_mac(self): self.espefuse_py("get_custom_mac -h") if arg_chip == "esp32": right_msg = "Custom MAC Address is not set in the device." - elif arg_chip in ["esp32h2", "esp32h2beta1"]: - right_msg = "Custom MAC Address: 00:00:00:00:00:00:00:00 (OK)" else: right_msg = "Custom MAC Address: 00:00:00:00:00:00 (OK)" self.espefuse_py("get_custom_mac", check_msg=right_msg) @@ -386,19 +384,13 @@ class TestBurnCustomMacCommands(EfuseTestCase): def test_burn_custom_mac(self): self.espefuse_py("burn_custom_mac -h") cmd = "burn_custom_mac AA:CD:EF:11:22:33" + mac = "aa:cd:ef:11:22:33" if arg_chip == "esp32": self.espefuse_py( - cmd, - check_msg="Custom MAC Address version 1: " - "aa:cd:ef:11:22:33 (CRC 0x63 OK)", + cmd, check_msg=f"Custom MAC Address version 1: {mac} (CRC 0x63 OK)" ) else: - mac_custom = ( - "aa:cd:ef:11:22:33:00:00" - if arg_chip in ["esp32h2", "esp32h2beta1"] - else "aa:cd:ef:11:22:33" - ) - self.espefuse_py(cmd, check_msg=f"Custom MAC Address: {mac_custom} (OK)") + self.espefuse_py(cmd, check_msg=f"Custom MAC Address: {mac} (OK)") def test_burn_custom_mac2(self): self.espefuse_py( @@ -645,12 +637,7 @@ def test_burn_mac_custom_efuse(self): ret_code=2, ) self.espefuse_py("burn_efuse CUSTOM_MAC AA:CD:EF:01:02:03") - if arg_chip in ["esp32h2", "esp32h2beta1"]: - self.espefuse_py( - "get_custom_mac", check_msg=f"aa:cd:ef:01:02:03:00:00 {crc_msg}" - ) - else: - self.espefuse_py("get_custom_mac", check_msg=f"aa:cd:ef:01:02:03 {crc_msg}") + self.espefuse_py("get_custom_mac", check_msg=f"aa:cd:ef:01:02:03 {crc_msg}") def test_burn_efuse(self): self.espefuse_py("burn_efuse -h")