forked from espressif/arduino-esp32
Update IDF and Tools
This commit is contained in:
115
tools/esptool.py
115
tools/esptool.py
@ -388,7 +388,7 @@ class ESPLoader(object):
|
||||
return val, data
|
||||
if byte(data, 0) != 0 and byte(data, 1) == self.ROM_INVALID_RECV_MSG:
|
||||
self.flush_input() # Unsupported read_reg can result in more than one error response for some reason
|
||||
raise UnsupportedCommandError(self)
|
||||
raise UnsupportedCommandError(self, op)
|
||||
|
||||
finally:
|
||||
if new_timeout != saved_timeout:
|
||||
@ -624,7 +624,7 @@ class ESPLoader(object):
|
||||
|
||||
Returns number of blocks (of size self.FLASH_WRITE_SIZE) to write.
|
||||
"""
|
||||
def flash_begin(self, size, offset):
|
||||
def flash_begin(self, size, offset, begin_rom_encrypted=False):
|
||||
num_blocks = (size + self.FLASH_WRITE_SIZE - 1) // self.FLASH_WRITE_SIZE
|
||||
erase_size = self.get_erase_size(offset, size)
|
||||
|
||||
@ -636,7 +636,7 @@ class ESPLoader(object):
|
||||
|
||||
params = struct.pack('<IIII', erase_size, num_blocks, self.FLASH_WRITE_SIZE, offset)
|
||||
if isinstance(self, ESP32S2ROM) and not self.IS_STUB:
|
||||
params += struct.pack('<I', 0) # enter encrypted flash mode (ROM version of this is unsupported for now)
|
||||
params += struct.pack('<I', 1 if begin_rom_encrypted else 0)
|
||||
self.check_command("enter Flash download mode", self.ESP_FLASH_BEGIN,
|
||||
params, timeout=timeout)
|
||||
if size != 0 and not self.IS_STUB:
|
||||
@ -653,6 +653,11 @@ class ESPLoader(object):
|
||||
|
||||
""" Encrypt before writing to flash """
|
||||
def flash_encrypt_block(self, data, seq, timeout=DEFAULT_TIMEOUT):
|
||||
if isinstance(self, ESP32S2ROM) and not self.IS_STUB:
|
||||
# ROM support performs the encrypted writes via the normal write command,
|
||||
# triggered by flash_begin(begin_rom_encrypted=True)
|
||||
return self.flash_block(data, seq, timeout)
|
||||
|
||||
self.check_command("Write encrypted to target Flash after seq %d" % seq,
|
||||
self.ESP_FLASH_ENCRYPT_DATA,
|
||||
struct.pack('<IIII', len(data), seq, 0, 0) + data,
|
||||
@ -1226,13 +1231,13 @@ class ESP32ROM(ESPLoader):
|
||||
# ESP32 uses a 4 byte status reply
|
||||
STATUS_BYTES_LENGTH = 4
|
||||
|
||||
SPI_REG_BASE = 0x60002000
|
||||
SPI_REG_BASE = 0x3ff42000
|
||||
SPI_USR_OFFS = 0x1c
|
||||
SPI_USR1_OFFS = 0x20
|
||||
SPI_USR2_OFFS = 0x24
|
||||
SPI_MOSI_DLEN_OFFS = 0x28
|
||||
SPI_MISO_DLEN_OFFS = 0x2c
|
||||
EFUSE_RD_REG_BASE = 0x6001a000
|
||||
EFUSE_RD_REG_BASE = 0x3ff5a000
|
||||
|
||||
EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT_REG = EFUSE_RD_REG_BASE + 0x18
|
||||
EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT = (1 << 7) # EFUSE_RD_DISABLE_DL_ENCRYPT
|
||||
@ -1334,39 +1339,42 @@ class ESP32ROM(ESPLoader):
|
||||
pkg_version += ((word3 >> 2) & 0x1) << 3
|
||||
return pkg_version
|
||||
|
||||
def get_chip_description(self):
|
||||
def get_chip_revision(self):
|
||||
word3 = self.read_efuse(3)
|
||||
word5 = self.read_efuse(5)
|
||||
apb_ctl_date = self.read_reg(self.DR_REG_SYSCON_BASE + 0x7C)
|
||||
|
||||
rev_bit0 = (word3 >> 15) & 0x1
|
||||
rev_bit1 = (word5 >> 20) & 0x1
|
||||
rev_bit2 = (apb_ctl_date >> 31) & 0x1
|
||||
pkg_version = self.get_pkg_version()
|
||||
|
||||
chip_name = {
|
||||
0: "ESP32D0WDQ6",
|
||||
1: "ESP32D0WDQ5",
|
||||
2: "ESP32D2WDQ5",
|
||||
4: "ESP32-U4WDH",
|
||||
5: "ESP32-PICO",
|
||||
6: "ESP32-PICO-V3-02",
|
||||
}.get(pkg_version, "unknown ESP32")
|
||||
|
||||
chip_revision = 0
|
||||
if rev_bit0:
|
||||
if rev_bit1:
|
||||
if rev_bit2:
|
||||
chip_revision = 3
|
||||
return 3
|
||||
else:
|
||||
chip_revision = 2
|
||||
return 2
|
||||
else:
|
||||
chip_revision = 1
|
||||
return 1
|
||||
return 0
|
||||
|
||||
if chip_name == "ESP32-PICO":
|
||||
if chip_revision == 1:
|
||||
chip_name += "-D4"
|
||||
elif chip_revision == 3:
|
||||
chip_name += "-V3"
|
||||
def get_chip_description(self):
|
||||
pkg_version = self.get_pkg_version()
|
||||
chip_revision = self.get_chip_revision()
|
||||
rev3 = (chip_revision == 3)
|
||||
single_core = self.read_efuse(3) & (1 << 0) # CHIP_VER DIS_APP_CPU
|
||||
|
||||
chip_name = {
|
||||
0: "ESP32-S0WDQ6" if single_core else "ESP32-D0WDQ6",
|
||||
1: "ESP32-S0WD" if single_core else "ESP32-D0WD",
|
||||
2: "ESP32-D2WD",
|
||||
4: "ESP32-U4WDH",
|
||||
5: "ESP32-PICO-V3" if rev3 else "ESP32-PICO-D4",
|
||||
6: "ESP32-PICO-V3-02",
|
||||
}.get(pkg_version, "unknown ESP32")
|
||||
|
||||
# ESP32-D0WD-V3, ESP32-D0WDQ6-V3
|
||||
if chip_name.startswith("ESP32-D0WD") and rev3:
|
||||
chip_name += "-V3"
|
||||
|
||||
return "%s (revision %d)" % (chip_name, chip_revision)
|
||||
|
||||
@ -1400,6 +1408,9 @@ class ESP32ROM(ESPLoader):
|
||||
if pkg_version in [2, 4, 5, 6]:
|
||||
features += ["Embedded Flash"]
|
||||
|
||||
if pkg_version == 6:
|
||||
features += ["Embedded PSRAM"]
|
||||
|
||||
word4 = self.read_efuse(4)
|
||||
adc_vref = (word4 >> 8) & 0x1F
|
||||
if adc_vref:
|
||||
@ -1632,6 +1643,8 @@ class ESP32S2ROM(ESP32ROM):
|
||||
and any(p == self.PURPOSE_VAL_XTS_AES256_KEY_2 for p in purposes)
|
||||
|
||||
def uses_usb(self, _cache=[]):
|
||||
if self.secure_download_mode:
|
||||
return False # can't detect native USB in secure download mode
|
||||
if not _cache:
|
||||
buf_no = self.read_reg(self.UARTDEV_BUF_NO) & 0xff
|
||||
_cache.append(buf_no == self.UARTDEV_BUF_NO_USB)
|
||||
@ -2566,18 +2579,18 @@ class NotSupportedError(FatalError):
|
||||
# argument.
|
||||
|
||||
|
||||
class UnsupportedCommandError(FatalError):
|
||||
class UnsupportedCommandError(RuntimeError):
|
||||
"""
|
||||
Wrapper class for when ROM loader returns an invalid command response.
|
||||
|
||||
Usually this indicates the loader is running in Secure Download Mode.
|
||||
"""
|
||||
def __init__(self, esp):
|
||||
def __init__(self, esp, op):
|
||||
if esp.secure_download_mode:
|
||||
msg = "This command is not supported in Secure Download Mode"
|
||||
msg = "This command (0x%x) is not supported in Secure Download Mode" % op
|
||||
else:
|
||||
msg = "Invalid (unsupported) command"
|
||||
FatalError.__init__(self, msg)
|
||||
msg = "Invalid (unsupported) command 0x%x" % op
|
||||
RuntimeError.__init__(self, msg)
|
||||
|
||||
|
||||
def load_ram(esp, args):
|
||||
@ -2694,21 +2707,22 @@ def write_flash(esp, args):
|
||||
if args.encrypt:
|
||||
do_write = True
|
||||
|
||||
if esp.get_encrypted_download_disabled():
|
||||
raise FatalError("This chip has encrypt functionality in UART download mode disabled. "
|
||||
+ "This is the Flash Encryption configuration for Production mode instead of Development mode.")
|
||||
if not esp.secure_download_mode:
|
||||
if esp.get_encrypted_download_disabled():
|
||||
raise FatalError("This chip has encrypt functionality in UART download mode disabled. "
|
||||
+ "This is the Flash Encryption configuration for Production mode instead of Development mode.")
|
||||
|
||||
crypt_cfg_efuse = esp.get_flash_crypt_config()
|
||||
crypt_cfg_efuse = esp.get_flash_crypt_config()
|
||||
|
||||
if crypt_cfg_efuse is not None and crypt_cfg_efuse != 0xF:
|
||||
print('Unexpected FLASH_CRYPT_CONFIG value: 0x%x' % (crypt_cfg_efuse))
|
||||
do_write = False
|
||||
if crypt_cfg_efuse is not None and crypt_cfg_efuse != 0xF:
|
||||
print('Unexpected FLASH_CRYPT_CONFIG value: 0x%x' % (crypt_cfg_efuse))
|
||||
do_write = False
|
||||
|
||||
enc_key_valid = esp.is_flash_encryption_key_valid()
|
||||
enc_key_valid = esp.is_flash_encryption_key_valid()
|
||||
|
||||
if not enc_key_valid:
|
||||
print('Flash encryption key is not programmed')
|
||||
do_write = False
|
||||
if not enc_key_valid:
|
||||
print('Flash encryption key is not programmed')
|
||||
do_write = False
|
||||
|
||||
for address, argfile in args.addr_filename:
|
||||
if address % esp.FLASH_ENCRYPTED_WRITE_ALIGN:
|
||||
@ -2755,7 +2769,7 @@ def write_flash(esp, args):
|
||||
blocks = esp.flash_defl_begin(uncsize, len(image), address)
|
||||
else:
|
||||
ratio = 1.0
|
||||
blocks = esp.flash_begin(uncsize, address)
|
||||
blocks = esp.flash_begin(uncsize, address, begin_rom_encrypted=args.encrypt)
|
||||
argfile.seek(0) # in case we need it again
|
||||
seq = 0
|
||||
written = 0
|
||||
@ -3323,16 +3337,13 @@ def main(custom_commandline=None):
|
||||
if esp is None:
|
||||
raise FatalError("Could not connect to an Espressif device on any of the %d available serial ports." % len(ser_list))
|
||||
|
||||
print("Chip is %s" % (esp.get_chip_description()))
|
||||
|
||||
print("Features: %s" % ", ".join(esp.get_chip_features()))
|
||||
|
||||
print("Crystal is %dMHz" % esp.get_crystal_freq())
|
||||
|
||||
try:
|
||||
if esp.secure_download_mode:
|
||||
print("Chip is %s in Secure Download Mode" % esp.CHIP_NAME)
|
||||
else:
|
||||
print("Chip is %s" % (esp.get_chip_description()))
|
||||
print("Features: %s" % ", ".join(esp.get_chip_features()))
|
||||
print("Crystal is %dMHz" % esp.get_crystal_freq())
|
||||
read_mac(esp, args)
|
||||
except UnsupportedCommandError:
|
||||
pass # can't get this data in Secure Download Mode
|
||||
|
||||
if not args.no_stub:
|
||||
if esp.secure_download_mode:
|
||||
|
Reference in New Issue
Block a user