Skip to content

Commit

Permalink
feat(flash_id): Print the flash type if available for the chip
Browse files Browse the repository at this point in the history
Closes #730
  • Loading branch information
dobairoland committed Nov 24, 2022
1 parent ee27a64 commit b25606b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions esptool/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,11 @@ def flash_id(esp, args):
print(
"Detected flash size: %s" % (DETECTED_FLASH_SIZES.get(flid_lowbyte, "Unknown"))
)
flash_type = esp.flash_type()
flash_type_dict = {0: "quad (4 data lines)", 1: "octal (8 data lines)"}
flash_type_str = flash_type_dict.get(flash_type)
if flash_type_str:
print(f"Flash type: {flash_type_str}")


def read_flash(esp, args):
Expand Down
4 changes: 4 additions & 0 deletions esptool/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ def flash_id(self):
SPIFLASH_RDID = 0x9F
return self.run_spiflash_command(SPIFLASH_RDID, b"", 24)

def flash_type(self):
"""Read flash type bit field from eFuse. Returns 0, 1, None (not present)"""
return None # not implemented for all chip targets

def get_security_info(self):
res = self.check_command("get security info", self.ESP_GET_SECURITY_INFO, b"")
esp32s2 = True if len(res) == 12 else False
Expand Down
11 changes: 11 additions & 0 deletions esptool/targets/esp32s2.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class ESP32S2ROM(ESP32ROM):
EFUSE_SECURE_BOOT_EN_REG = EFUSE_BASE + 0x038
EFUSE_SECURE_BOOT_EN_MASK = 1 << 20

EFUSE_RD_REPEAT_DATA3_REG = EFUSE_BASE + 0x3C
EFUSE_RD_REPEAT_DATA3_REG_FLASH_TYPE_MASK = 1 << 9

PURPOSE_VAL_XTS_AES256_KEY_1 = 2
PURPOSE_VAL_XTS_AES256_KEY_2 = 3
PURPOSE_VAL_XTS_AES128_KEY = 4
Expand Down Expand Up @@ -184,6 +187,14 @@ def read_mac(self):
bitstring = struct.pack(">II", mac1, mac0)[2:]
return tuple(bitstring)

def flash_type(self):
return (
1
if self.read_reg(self.EFUSE_RD_REPEAT_DATA3_REG)
& self.EFUSE_RD_REPEAT_DATA3_REG_FLASH_TYPE_MASK
else 0
)

def get_flash_crypt_config(self):
return None # doesn't exist on ESP32-S2

Expand Down
11 changes: 11 additions & 0 deletions esptool/targets/esp32s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class ESP32S3ROM(ESP32ROM):
EFUSE_SECURE_BOOT_EN_REG = EFUSE_BASE + 0x038
EFUSE_SECURE_BOOT_EN_MASK = 1 << 20

EFUSE_RD_REPEAT_DATA3_REG = EFUSE_BASE + 0x3C
EFUSE_RD_REPEAT_DATA3_REG_FLASH_TYPE_MASK = 1 << 9

PURPOSE_VAL_XTS_AES256_KEY_1 = 2
PURPOSE_VAL_XTS_AES256_KEY_2 = 3
PURPOSE_VAL_XTS_AES128_KEY = 4
Expand Down Expand Up @@ -193,6 +196,14 @@ def read_mac(self):
bitstring = struct.pack(">II", mac1, mac0)[2:]
return tuple(bitstring)

def flash_type(self):
return (
1
if self.read_reg(self.EFUSE_RD_REPEAT_DATA3_REG)
& self.EFUSE_RD_REPEAT_DATA3_REG_FLASH_TYPE_MASK
else 0
)

def uses_usb_otg(self, _cache=[]):
"""
Check the UARTDEV_BUF_NO register to see if USB-OTG console is being used
Expand Down

0 comments on commit b25606b

Please sign in to comment.