Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read flash partition #697

Open
DaneSlattery opened this issue Oct 25, 2024 · 5 comments
Open

Cannot read flash partition #697

DaneSlattery opened this issue Oct 25, 2024 · 5 comments
Labels
bug Something isn't working status:needs-investigation Issue requires further investigation

Comments

@DaneSlattery
Copy link
Contributor

DaneSlattery commented Oct 25, 2024

I cannot read flash partitions with espflash on an esp32-s3 devkit over UART.

[2024-10-25T10:47:14Z INFO ] 🚀 A new version of espflash is available: v3.2.0
[2024-10-25T10:47:14Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-10-25T10:47:14Z INFO ] Connecting...
[2024-10-25T10:47:14Z INFO ] Using flash stub
Chip type:         esp32s3 (revision v0.2)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       30:30:f9:55:19:54
Error: espflash::read_flash::corrupt_data

  × Corrupt data, expected 1000 bytes but receved fd1 bytes

I am able to do the same with esptool.py:

esptool.py read_flash 0x9000 0x6000 ./nvs_dump.bin
esptool.py v4.8.1
Found 33 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: 30:30:f9:55:19:54
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
24576 (100 %)
24576 (100 %)
Read 24576 bytes at 0x00009000 in 2.2 seconds (90.0 kbit/s)...
Hard resetting via RTS pin...

I don't know what is missing?

@MabezDev
Copy link
Member

Can you try again with --no-stub?

@DaneSlattery
Copy link
Contributor Author

Here's the result:

espflash read-flash --no-stub 0x9000 0x6000 ./nvs_dump_devkit   
[2024-10-25T10:45:55Z INFO ] 🚀 A new version of espflash is available: v3.2.0
Error: espflash::stub_required

  × This command requires using the RAM stub
  help: Don't use the `--no-stub` option with the command

@zakimoo
Copy link

zakimoo commented Nov 21, 2024

same hier

espflash read-flash 0x0 0x0400000 test_3.bin

[2024-11-21T14:48:38Z INFO ] Serial port: '/dev/ttyUSB0'
[2024-11-21T14:48:38Z INFO ] Connecting...
[2024-11-21T14:48:38Z INFO ] Using flash stub
Chip type:         esp32c3 (revision v0.3)
Crystal frequency: 40 MHz
Flash size:        4MB
Features:          WiFi, BLE
MAC address:       a0:76:4e:5a:41:70
Error: espflash::read_flash::corrupt_data

  × Corrupt data, expected 1000 bytes but receved fcf bytes

but with esptool.py it works

esptool.py -b 460800 read_flash 0 0x0400000 flash_contents.bin
esptool.py v4.8.1
Found 1 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-C3
Chip is ESP32-C3 (QFN32) (revision v0.3)
Features: WiFi, BLE, Embedded Flash 4MB (XMC)
Crystal is 40MHz
MAC: a0:76:4e:5a:41:70
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
4194304 (100 %)
4194304 (100 %)
Read 4194304 bytes at 0x00000000 in 106.9 seconds (314.0 kbit/s)...
Hard resetting via RTS pin...

@jessebraham jessebraham added the bug Something isn't working label Jan 9, 2025
@jessebraham jessebraham added the status:needs-investigation Issue requires further investigation label Jan 20, 2025
@liclac
Copy link

liclac commented Feb 2, 2025

Same here, also trying to dump the default NVS partition of my ESP32-S3 devboard (a Heltec LoRa 32 V3).

$ espflash read-flash 0x9000 24576 config2.img
[2025-02-02T17:15:59Z INFO ] Serial port: '/dev/ttyUSB0'
[2025-02-02T17:15:59Z INFO ] Connecting...
[2025-02-02T17:15:59Z INFO ] Using flash stub
Chip type:         esp32s3 (revision v0.2)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       34:cd:b0:3d:40:24
Error: espflash::read_flash::corrupt_data

  × Corrupt data, expected 1000 bytes but receved ffe bytes

Here's the full log, when running with RUST_LOG=trace: https://gist.github.com/liclac/01ee6b5f5bea1095cf37c86c43fb9f60

Doing the same operation with esptool.py works:

$ esptool.py read_flash 0x9000 24576 config.img
esptool.py v4.8.1
Found 3 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded Flash 8MB (GD)
Crystal is 40MHz
MAC: 34:cd:b0:3d:40:24
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
24576 (100 %)
24576 (100 %)
Read 24576 bytes at 0x00009000 in 2.2 seconds (90.3 kbit/s)...
Hard resetting via RTS pin...

I am able to use espflash write-bin to write this dumped image back to it:

$ espflash write-bin 0x9000 config.img
[2025-02-02T17:24:06Z INFO ] Serial port: '/dev/ttyUSB0'
[2025-02-02T17:24:06Z INFO ] Connecting...
[2025-02-02T17:24:07Z INFO ] Using flash stub
Chip type:         esp32s3 (revision v0.2)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       34:cd:b0:3d:40:24
[00:00:00] [========================================]       1/1       0x9000
[2025-02-02T17:24:09Z INFO ] Binary successfully written to flash!

I'm also able to change the data, write it, and read it back just fine:

$ tr \xFF \xAA < config.img > config2.img

$ espflash write-bin 0x9000 config2.img
[2025-02-02T17:26:27Z INFO ] Serial port: '/dev/ttyUSB0'
[2025-02-02T17:26:27Z INFO ] Connecting...
[2025-02-02T17:26:27Z INFO ] Using flash stub
Chip type:         esp32s3 (revision v0.2)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       34:cd:b0:3d:40:24
[00:00:00] [========================================]       1/1       0x9000
[2025-02-02T17:26:29Z INFO ] Binary successfully written to flash!

$ esptool.py read_flash 0x9000 24576 config2_.img
esptool.py v4.8.1
Found 3 serial ports
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP32-S3
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded Flash 8MB (GD)
Crystal is 40MHz
MAC: 34:cd:b0:3d:40:24
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
24576 (100 %)
24576 (100 %)
Read 24576 bytes at 0x00009000 in 2.2 seconds (90.3 kbit/s)...
Hard resetting via RTS pin...

$ diff <(xxd config2.img) <(xxd config2_.img)

$ $ espflash read-flash 0x9000 24576 config.img
[2025-02-02T17:31:33Z INFO ] Serial port: '/dev/ttyUSB0'
[2025-02-02T17:31:33Z INFO ] Connecting...
[2025-02-02T17:31:33Z INFO ] Using flash stub
Chip type:         esp32s3 (revision v0.2)
Crystal frequency: 40 MHz
Flash size:        8MB
Features:          WiFi, BLE
MAC address:       34:cd:b0:3d:40:24
Error: espflash::read_flash::corrupt_data

  × Corrupt data, expected 1000 bytes but receved ffd bytes

A minor observation is that for some reason, every time I re-write the partition and try reading it again, it changes how many bytes the error message says it received, just by a few bytes back or forth seemingly at random (I've seen ffc, ffd and ffe, in no particular order).

Happy to provide any additional information, help debug things, etc., but I'm a bit lost as to where to even start with this.

@liclac
Copy link

liclac commented Feb 3, 2025

I discovered something very interesting: it seems to work fine as long as I ask for 0x1000 bytes or less. The moment I go above that, things start failing - 0x1001 through 0x1009 gets a timeout, 0x1010 and I'm back to the corruption error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working status:needs-investigation Issue requires further investigation
Projects
Status: Todo
Development

No branches or pull requests

5 participants