mirror of
https://github.com/espressif/esptool.git
synced 2025-10-16 14:28:54 +08:00
fix: ROM doesn't attach in-package flash chips
This commit is contained in:

committed by
Radim Karniš

parent
0cabb38dd4
commit
bc9f2a656d
@@ -779,6 +779,13 @@ def main(argv=None, esp=None):
|
||||
"Keeping initial baud rate %d" % initial_baud
|
||||
)
|
||||
|
||||
def _define_spi_conn(spi_connection):
|
||||
"""Prepare SPI configuration string and value for flash_spi_attach()"""
|
||||
clk, q, d, hd, cs = spi_connection
|
||||
spi_config_txt = f"CLK:{clk}, Q:{q}, D:{d}, HD:{hd}, CS:{cs}"
|
||||
value = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk
|
||||
return spi_config_txt, value
|
||||
|
||||
# Override the common SPI flash parameter stuff if configured to do so
|
||||
if hasattr(args, "spi_connection") and args.spi_connection is not None:
|
||||
spi_config = args.spi_connection
|
||||
@@ -790,15 +797,26 @@ def main(argv=None, esp=None):
|
||||
esp.check_spi_connection(args.spi_connection)
|
||||
# Encode the pin numbers as a 32-bit integer with packed 6-bit values,
|
||||
# the same way the ESP ROM takes them
|
||||
clk, q, d, hd, cs = args.spi_connection
|
||||
spi_config = f"CLK:{clk}, Q:{q}, D:{d}, HD:{hd}, CS:{cs}"
|
||||
value = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk
|
||||
spi_config, value = _define_spi_conn(args.spi_connection)
|
||||
print(f"Configuring SPI flash mode ({spi_config})...")
|
||||
esp.flash_spi_attach(value)
|
||||
elif args.no_stub:
|
||||
print("Enabling default SPI flash mode...")
|
||||
# ROM loader doesn't enable flash unless we explicitly do it
|
||||
esp.flash_spi_attach(0)
|
||||
if esp.CHIP_NAME != "ESP32" or esp.secure_download_mode:
|
||||
print("Enabling default SPI flash mode...")
|
||||
# ROM loader doesn't enable flash unless we explicitly do it
|
||||
esp.flash_spi_attach(0)
|
||||
else:
|
||||
# ROM doesn't attach in-package flash chips
|
||||
spi_chip_pads = esp.get_chip_spi_pads()
|
||||
spi_config_txt, value = _define_spi_conn(spi_chip_pads)
|
||||
if spi_chip_pads != (0, 0, 0, 0, 0):
|
||||
print(
|
||||
"Attaching flash from eFuses' SPI pads configuration"
|
||||
f"({spi_config_txt})..."
|
||||
)
|
||||
else:
|
||||
print("Enabling default SPI flash mode...")
|
||||
esp.flash_spi_attach(value)
|
||||
|
||||
# XMC chip startup sequence
|
||||
XMC_VENDOR_ID = 0x20
|
||||
|
@@ -36,6 +36,9 @@ class ESP32ROM(ESPLoader):
|
||||
SPI_MISO_DLEN_OFFS = 0x2C
|
||||
EFUSE_RD_REG_BASE = 0x3FF5A000
|
||||
|
||||
EFUSE_BLK0_RDATA3_REG_OFFS = EFUSE_RD_REG_BASE + 0x00C
|
||||
EFUSE_BLK0_RDATA5_REG_OFFS = EFUSE_RD_REG_BASE + 0x014
|
||||
|
||||
EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT_REG = EFUSE_RD_REG_BASE + 0x18
|
||||
EFUSE_DIS_DOWNLOAD_MANUAL_ENCRYPT = 1 << 7 # EFUSE_RD_DISABLE_DL_ENCRYPT
|
||||
|
||||
@@ -276,6 +279,20 @@ class ESP32ROM(ESPLoader):
|
||||
|
||||
return features
|
||||
|
||||
def get_chip_spi_pads(self):
|
||||
"""Read chip spi pad config
|
||||
return: clk, q, d, hd, cd
|
||||
"""
|
||||
efuse_blk0_rdata5 = self.read_reg(self.EFUSE_BLK0_RDATA5_REG_OFFS)
|
||||
spi_pad_clk = efuse_blk0_rdata5 & 0x1F
|
||||
spi_pad_q = (efuse_blk0_rdata5 >> 5) & 0x1F
|
||||
spi_pad_d = (efuse_blk0_rdata5 >> 10) & 0x1F
|
||||
spi_pad_cs = (efuse_blk0_rdata5 >> 15) & 0x1F
|
||||
|
||||
efuse_blk0_rdata3_reg = self.read_reg(self.EFUSE_BLK0_RDATA3_REG_OFFS)
|
||||
spi_pad_hd = (efuse_blk0_rdata3_reg >> 4) & 0x1F
|
||||
return spi_pad_clk, spi_pad_q, spi_pad_d, spi_pad_hd, spi_pad_cs
|
||||
|
||||
def read_efuse(self, n):
|
||||
"""Read the nth word of the ESP3x EFUSE region."""
|
||||
return self.read_reg(self.EFUSE_RD_REG_BASE + (4 * n))
|
||||
|
Reference in New Issue
Block a user