espressif / esptool

Espressif SoC serial bootloader utility
https://docs.espressif.com/projects/esptool
GNU General Public License v2.0
5.51k stars 1.37k forks source link

v4.5.1 esptool.py won't write flash above 16M on a 32MB ESP32S3 module (ESPTOOL-648) #859

Closed chewhs00 closed 1 year ago

chewhs00 commented 1 year ago

Operating System

Ubuntu 20.04.5 LTS

Esptool Version

v4.5.1

Python Version

3.8.10

Chip Description

ESP32-S3 (revision v0.1), 32MB Octal Flash, 80MHz, opi_dtr

Device Description

Module on a custom board.

Hardware Configuration

No response

How is Esptool Run

Terminal, esptool repo

Full Esptool Command Line that Was Run

~/esp/esptool/esptool.py --chip esp32s3 --p /dev/ttyUSB0 --no-stub write_flash --flash_size 32MB -z 0x1C10000 dummy.bin

Esptool Output

****** Power the unit in Bootloading mode ******

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub erase_flash
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
Erasing flash (this may take a while)...

A fatal error occurred: ESP32-S3 ROM does not support function erase_flash.

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 erase_flash
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 76.2s
Hard resetting via RTS pin...

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0xc10000 $((256*1024)) read_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to configure SPI flash pins. Only got 2 byte status response.

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 read_flash 0xc10000 $((256*1024)) read_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Stub is already running. No upload is necessary.
262144 (100 %)
262144 (100 %)
Read 262144 bytes at 0x00c10000 in 25.3 seconds (82.8 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read_c10000.bin 
3b874d3ba46c638fc3094f8e92fb744ca974893873f8885f54e23760f9b6311b  read_c10000.bin

****** Reboot the unit in bootloading mode ******

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0xc10000 $((256*1024)) read2_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to read flash block (result was 01090000: CRC or checksum was invalid)

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 read_flash 0xc10000 $((256*1024)) read2_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Uploading stub...
Running stub...
Stub running...
262144 (100 %)
262144 (100 %)
Read 262144 bytes at 0x00c10000 in 25.3 seconds (82.8 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read2_c10000.bin 
3b874d3ba46c638fc3094f8e92fb744ca974893873f8885f54e23760f9b6311b  read2_c10000.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0x1c10000 $((256*1024)) read_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to configure SPI flash pins. Only got 2 byte status response.

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 read_flash 0x1c10000 $((256*1024)) read_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Stub is already running. No upload is necessary.
WARNING: Flasher stub doesn't fully support flash size larger than 16MB, in case of failure use --no-stub.
262144 (100 %)
262144 (100 %)
Read 262144 bytes at 0x01c10000 in 25.3 seconds (82.7 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read_1c10000.bin
3b874d3ba46c638fc3094f8e92fb744ca974893873f8885f54e23760f9b6311b  read_1c10000.bin

$ dd if=/dev/zero of=dummy.bin bs=$((256*1024)) count=1
1+0 records in
1+0 records out
262144 bytes (262 kB, 256 KiB) copied, 0.00280336 s, 93.5 MB/s

$ sha256sum dummy.bin 
8a39d2abd3999ab73c34db2476849cddf303ce389b35826850f9a700589b4a90  dummy.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub write_flash --flash_size 32MB -z 0x1C10000  dummy.bin 
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
Configuring flash size...
Flash will be erased from 0x01c10000 to 0x01c4ffff...
Erasing flash...
Compressed 262144 bytes to 277...
Took 1.12s to erase flash block
Wrote 262144 bytes (277 compressed) at 0x01c10000 in 1.3 seconds (effective 1579.9 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 read_flash 0xc10000 $((256*1024)) read3_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Uploading stub...
Running stub...
Stub running...
262144 (100 %)
262144 (100 %)
Read 262144 bytes at 0x00c10000 in 25.3 seconds (82.8 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read3_c10000.bin 
8a39d2abd3999ab73c34db2476849cddf303ce389b35826850f9a700589b4a90  read3_c10000.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0xc10000 $((256*1024)) read4_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to configure SPI flash pins. Only got 2 byte status response.

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0x1c10000 $((256*1024)) read2_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to configure SPI flash pins. Only got 2 byte status response.

****** Reboot the unit in bootloading mode ******

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0x1c10000 $((256*1024)) read2_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to read flash block (result was 01090000: CRC or checksum was invalid)

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 read_flash 0x1c10000 $((256*1024)) read2_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Uploading stub...
Running stub...
Stub running...
WARNING: Flasher stub doesn't fully support flash size larger than 16MB, in case of failure use --no-stub.
262144 (100 %)
262144 (100 %)
Read 262144 bytes at 0x01c10000 in 25.5 seconds (82.3 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read2_1c10000.bin 
3b874d3ba46c638fc3094f8e92fb744ca974893873f8885f54e23760f9b6311b  read2_1c10000.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub write_flash --flash_size 32MB -z 0x1C10000  dummy.bin 
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to configure SPI flash pins. Only got 2 byte status response.

****** Reboot the unit in bootloading mode ******

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub write_flash --flash_size 32MB -z 0x1C10000  dummy.bin 
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
Configuring flash size...
Flash will be erased from 0x01c10000 to 0x01c4ffff...
Erasing flash...
Compressed 262144 bytes to 277...
Took 1.12s to erase flash block
Wrote 262144 bytes (277 compressed) at 0x01c10000 in 1.3 seconds (effective 1583.1 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0x1c10000 $((256*1024)) read3_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
262144 (100 %)
Read 262144 bytes at 0x01c10000 in 105.9 seconds (19.8 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read3_1c10000.bin 
8a39d2abd3999ab73c34db2476849cddf303ce389b35826850f9a700589b4a90  read3_1c10000.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0xc10000 $((256*1024)) read5_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
262144 (100 %)
Read 262144 bytes at 0x00c10000 in 106.5 seconds (19.7 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read5_c10000.bin 
8a39d2abd3999ab73c34db2476849cddf303ce389b35826850f9a700589b4a90  read5_c10000.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 erase_flash
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 76.1s
Hard resetting via RTS pin...

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub write_flash --flash_size 32MB -z 0x1C10000  dummy.bin 
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to configure SPI flash pins. Only got 2 byte status response.

****** Reboot the unit in bootloading mode ******

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub write_flash --flash_size 32MB -z 0x1C10000  dummy.bin 
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
Configuring flash size...
Flash will be erased from 0x01c10000 to 0x01c4ffff...
Erasing flash...
Compressed 262144 bytes to 277...
Took 1.12s to erase flash block
Wrote 262144 bytes (277 compressed) at 0x01c10000 in 1.3 seconds (effective 1597.7 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0xc10000 $((256*1024)) read6_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
262144 (100 %)
Read 262144 bytes at 0x00c10000 in 107.0 seconds (19.6 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read6_c10000.bin 
8a39d2abd3999ab73c34db2476849cddf303ce389b35826850f9a700589b4a90  read6_c10000.bin

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0x1c10000 $((256*1024)) read4_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...
262144 (100 %)
Read 262144 bytes at 0x01c10000 in 107.5 seconds (19.5 kbit/s)...
Hard resetting via RTS pin...

$ sha256sum read4_1c10000.bin 
8a39d2abd3999ab73c34db2476849cddf303ce389b35826850f9a700589b4a90  read4_1c10000.bin

****** Reboot the unit in bootloading mode ******

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0xc10000 $((256*1024)) read7_c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to read flash block (result was 01090000: CRC or checksum was invalid)

$ ~/esp/esptool/esptool.py -p /dev/ttyUSB0 --chip esp32s3 --no-stub read_flash 0x1c10000 $((256*1024)) read5_1c10000.bin
esptool.py v4.5.1
Serial port /dev/ttyUSB0
Connecting...
Chip is ESP32-S3 (revision v0.1)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e4:23:7c
Enabling default SPI flash mode...

A fatal error occurred: Failed to read flash block (result was 01090000: CRC or checksum was invalid)

More Information

My goal is to flash a 256kB binary image at a location above 16MB boundary, in this case at 0x1C10000. To check if it is successfully written to the proper location, I read it back with/without stub, at both locations 0xC10000 and 0x1C10000. With the above sequence of read/write, I still don't know if I wrote to 0x1C10000 correctly or I have accidentally corrupted 0xC10000. This --no-stub option sometimes fails for unknown reason!

Other Steps to Reproduce

See above Esptool Output

I Have Read the Troubleshooting Guide

dobairoland commented 1 year ago

Do you have any particular reason to use --no-stub? You are right that it is not working but I don't know what we could do about it. The ROM code is invoked and not everything is initialized/implemented there for OPI flash support.

If you don't use --no-stub then the flasher stub of esptool is used where this is implemented and should work.

chewhs00 commented 1 year ago

@dobairoland , I thought stub only works when accessing within 16MB. Is that no longer the case?

dobairoland commented 1 year ago

Support was added in v4.5.

chewhs00 commented 1 year ago

Any release schedule this get included in idf 4.4 and idf 5.0?

dobairoland commented 1 year ago

It is already included with ESP-IDF v5.0+. There is no schedule now if or when will be included with v4.4.x.