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

[4.0] read_flash - stub cannot read full 16MB (ESPTOOL-460) #745

Closed
1 task done
henrygab opened this issue May 24, 2022 · 17 comments
Closed
1 task done

[4.0] read_flash - stub cannot read full 16MB (ESPTOOL-460) #745

henrygab opened this issue May 24, 2022 · 17 comments

Comments

@henrygab
Copy link

Operating System

Windows 11 (21H2 Build 22000.675)

Version

other

Python Version

.EXE release v4.0 of tool (although I have 3.9.13 installed)

Chip Description

ESP32-S3-DevKitC-1 (N32R8V)

Device Description

ESP32-S3-DevKitC-1 (N32R8V) ... which has 32MB of flash, but I'm only trying to dump 16MB using the stub....

Hardware Configuration

Nothing but a USB cable connecting the UART port to the PC.

How is Esptool Run

No IDE, straight from cmd.exe

Full Esptool Command Line that Was Run

esptool --baud 115200 read_flash 16252928 524288 ..\ESP32-S3-DevKitC-1-N32R8__start-at-15.5MB.bin

Esptool Output

esptool.py v4.0
Found 1 serial ports
Serial port COM8
Connecting....
Detecting chip type... ESP32-S3
Chip is ESP32-S3
Features: WiFi, BLE
Crystal is 40MHz
MAC: 7c:df:a1:e0:f0:4c
Uploading stub...
Running stub...
Stub running...

A fatal error occurred: Invalid head of packet (0x6F): Possible serial noise or corruption.

More Information

This is a fresh-from-the-factory device, never written to, and still running the default blink sketch.

When trying to dump 32MB, the tool reports (as expected) that the stub supports up to 16MB:

WARNING: Flasher stub doesn't fully support flash size
larger than 16MB, in case of failure use --no-stub.

The following tables show 100% reproducible results for various combinations of start address and size being dumped.

Fails immediately when end address == 16MB

The following is the fatal error printed for each failure below:

`A fatal error occurred: Invalid head of packet (0x6F): Possible serial noise or corruption.`
address addressMB size SizeMB
0 0MB 16777216 16MB
12582912 12MB 4194304 4MB
13631488 13MB 3145728 3MB
14680064 14MB 2097152 2MB
15728640 15MB 1048576 1MB

Seems the stub cannot actually be used to dump 16MB flash directly, because it does not like the end address being equal to 16MB.


Starting at 0, fails dumping >8MB

address addressMB size SizeMB error address @ error
0 0MB 8388608 8MB Succeeds 0MB-8MB ok
0 0MB 9437184 9MB Fails at 77% <8MB
0 0MB 10485760 10MB Fails at 60% 6MB
0 0MB 11534336 11MB Fails at 45% <5MB
0 0MB 12582912 12MB Fails at 33% 4MB
0 0MB 13631488 13MB Fails at 23%
0 0MB 14680064 14MB Fails at 14%
0 0MB 15728640 15MB Fails at 6%

I have not noticed how the inputs affect these 100% repro failures, based on this evidence.


100% repro with varied start/size

address addressMB size SizeMB error address @ error
9437184 9MB 4194304 4MB Fails at 75% 13MB
9437184 9MB 3145728 3MB Succeeds 9MB-12MB ok
9437184 9MB 2097152 2MB Succeeds 9MB-11MB ok
10485760 10MB 4194304 4MB Fails at 50% 12MB
10485760 10MB 3145728 3MB Succeeds(!) 10MB-13MB ok
11534336 11MB 4194304 4MB Fails at 25% 12MB
11534336 11MB 3145728 3MB Fails at 66% 13MB
11534336 11MB 2097152 2MB Succeeds(!) 11MB-13MB ok
12582912 12MB 3145728 3MB Fails at 33% 13MB
12582912 12MB 2097152 2MB Succeeds(!) 12MB-14MB ok
13631488 13MB 2097152 2MB Fails at 50% 14MB
13631488 13MB 1572864 1.5MB Succeeds(!) 13MB-14.5MB ok
13107200 12.5MB 2097152 2MB Fails at 75% 14MB
14155776 13.5MB 2097152 2MB Fails at 25% 14MB
14155776 13.5MB 1048576 1MB Succeeds(!) 13.5MB-14.5MB ok

The above table confuses my guesses ... although 100% reproducible, the failure point does not appear to correspond to an address, does not appear to correspond to an amount completed, ... Not sure what else I could offer here.


So, in summary, the stub can read many of the addresses, but there's something wrong with its handling of >8MB (not >16MB as suggested). See attached traces for trace output of two commands that immediately report the Invalid head of packet (0x6F) error.

Other Steps to Reproduce

No response

I Have Read the Troubleshooting Guide

  • I confirm I have read the troubleshooting guide.
@github-actions github-actions bot changed the title [4.0] read_flash - stub cannot read full 16MB [4.0] read_flash - stub cannot read full 16MB (ESPTOOL-460) May 24, 2022
@henrygab
Copy link
Author

Reading with --no-stub also fails to read much of the flash.
Has this been validated on N32R8V (WROOM-2) ESP32-S3?

How much of the flash should I expect to be usable currently?

I will adjust my partition table accordingly, even if temporarily must limit to 8MB flash....

@JimNickerson
Copy link

I also have had problems with read_flash
VID_303A PID_1001 REV_0101 MI_00

Microsoft Windows [Version 10.0.19044.1865]
(c) Microsoft Corporation. All rights reserved.

D:\Documents\ARDUINO\esp32\RejasCan_v3-1>esptool.lnk flash_id
esptool.py v3.3
Found 1 serial ports
Serial port COM6
Connecting...
Detecting chip type... ESP32-S3
Chip is ESP32-S3
Features: WiFi, BLE
Crystal is 40MHz
MAC: 68:b6:b3:22:a0:f4
Uploading stub...
Running stub...
Stub running...
Manufacturer: c8
Device: 4018
Detected flash size: 16MB
Hard resetting via RTS pin...

D:\Documents\ARDUINO\esp32\RejasCan_v3-1>esptool.lnk --no-stub -b 1000000000 read_flash 0 0x100000 flash_1mbb_contents.bin
esptool.py v3.3
Found 1 serial ports
Serial port COM6
Connecting...
Detecting chip type... ESP32-S3
Chip is ESP32-S3
Features: WiFi, BLE
Crystal is 40MHz
MAC: 68:b6:b3:22:a0:f4
Changing baud rate to 1000000000
Changed.
Enabling default SPI flash mode...
1048576 (100 %)
Read 1048576 bytes at 0x0 in 48.6 seconds (172.8 kbit/s)...
Hard resetting via RTS pin...

D:\Documents\ARDUINO\esp32\RejasCan_v3-1>esptool.lnk --no-stub read_flash 0 0x400000 flash_4mb_contents.bin
esptool.py v3.3
Found 1 serial ports
Serial port COM6
Connecting...
Detecting chip type... ESP32-S3
Chip is ESP32-S3
Features: WiFi, BLE
Crystal is 40MHz
MAC: 68:b6:b3:22:a0:f4
Enabling default SPI flash mode...
2097152 (50 %)
A fatal error occurred: Failed to read flash block (result was 01090000: CRC or checksum was invalid)

D:\Documents\ARDUINO\esp32\RejasCan_v3-1>

@henrygab
Copy link
Author

Great! Based on the bot comment (ESPTOOL-460), I understand that this entered the Espressif bug triage database.

(( In other words, someone will at least look at this issue some more. ))

Looking forward to the stub (or even the no-stub) working for these 32MB Flash devkits....

@dobairoland
Copy link
Collaborator

Hi @henrygab. I'm sorry no one has left a note for you. Could you please try the latest v.4.3 release. Maybe 3190894 already solves this.

@henrygab
Copy link
Author

Hi @dobairland,

With 4.3, the flash_id subcommand now properly reports the 32MB flash size. In addition, when using --no-stub, the attempt to read the full flash would start. (but so slow). I'm happy to pretend this is really a 16MB flash, to be able to use the stub, and thus flash in less than an hour. 🙂

Unfortunately, the issue persists with v4.3:

.\esptool.exe --baud 115200 read_flash 0 16777216 .\image.bin
...
A fatal error occurred: Invalid head of packet (0x6F): Possible serial noise or corruption.

FYI, the following works reliably at higher baud rate, so the cables are not suspect:

.\esptool.exe --baud 921600 read_flash 0 8388608   .\image.bin
...
8388608 (100 %)
Read 8388608 bytes at 0x00000000 in 131.8 seconds (509.2 kbit/s)...
Hard resetting via RTS pin...

Anyways, the failure is 100% repro, and takes less than 10 seconds: Simply connect a DevKit-C1 (N32R8) using its UART port.

@dobairoland
Copy link
Collaborator

Thanks for checking. We will try to address this soon....

@henrygab
Copy link
Author

@dobairoland: Hello, Roland!

This is just a periodic check-in. I will limit these to once per ~3-4 weeks, unless you suggest a different period of time.

The purpose is to see if there is any update on the issue.

For example, have you been able to reproduce the underlying issue (even if not understanding the root cause)?

Is there a different (but currently supported) method to read and write to the full 32MB of flash on these devices?

Thanks!

@radimkarnis
Copy link
Collaborator

Hello @henrygab,
thanks for checking in.

I can verify that the issue is completely reproducible, your detailed report is spot on.

The root cause is not fully known yet. You can see opi_flash.c 270 appear in the serial terminal when the fail happens. I tracked it down to a failing assertion in the ROM (so the problem is not in the stub, that's why --no-stub fails too).

We haven't come up with a fix, yet.

@henrygab
Copy link
Author

Hello @radimkarnis ,

First, I want to thank you for your open communication on what you discovered in the last post. I appreciate your sharing the status.

Another month has flown by, so I thought I'd check in again ... see if any updates (even if only that you've tried three ideas, and each one hit a blocking issue; or that a new ROM / chip revision will be necessary).

I realize it's not possible to change the ROM, so any software workaround would require some amazing hack. If you do end up creating such a hack, I'd love to hear the story ... and both cringe and cheer at your creative solution!

Thanks again for the last update, letting us all know it's related to a failing assertion in the ROM, and good luck!

@Jason2866
Copy link
Contributor

Jason2866 commented Nov 28, 2022

@henrygab Imho it should be possible to solve with the stub. Since the stub does not have the need to use the (faulty?) rom routines. Everything needed can be baked in the stub code.
@radimkarnis Maybe this is the fix for?

@daviddohm
Copy link

I thought I had found an answer on an unrelated forum (forum shown below).

While it doesn't fail with the "Invalid head of packet (0x6F):" error immediately, read_flash fails at 2097152 (14%) regardless of what baud rate I attempt.

e.g. "esptool -b 115200 read_flash 0 0xE00000 flash_contents.bin" running on ubuntu 18.04.

https://forum.micropython.org/viewtopic.php?t=7138
" on a 16MB chip, the size should be changed to 0xE00000. "

@henrygab
Copy link
Author

@radimkarnis -- Monthly request for an update.

Can you verify if the potential fix Jason2866 found will be sufficient to resolve the issue? It does appear to be a bug in the code, and would seem to be directly related. If this is the right fix, can you push for it to be integrated into a release ASAP?

@dobairoland
Copy link
Collaborator

I'm working on this actively. That potential fix with other similar ones solves only the 16 MB boundary issue. I thought that I will fix it together with the 32 MB support issue but since that is more complicated, I'll separate it and prepare this one earlier.

@radimkarnis
Copy link
Collaborator

@henrygab although the potential fix @Jason2866 made fixes the issue of not being able to read/write the last byte of 16M flash, it doesn't explain the behavior you reported. This isn't related. Nevertheless, I have tried it and it still fails exactly as you described.

@henrygab
Copy link
Author

Bummer! Would have been great if such a simple root cause. Happy holidays and new year!

@radimkarnis
Copy link
Collaborator

Wishing you happy holidays and a bright 2023 from your friends at Espressif!

@dobairoland dobairoland reopened this Dec 28, 2022
Jason2866 added a commit to Jason2866/esptool that referenced this issue Dec 28, 2022
* fix(setup): Use latest reedsolo package which can be installed with Python3.10 and Cython

Closes espressif#711

* feat(ci): Publish development releases with custom pipeline

* fix(ci): The development release job should not run by default

Gitlab rules:if adds the job if any of the rules are true.

* fix(ci): Merge two "ci" directories and build_tools into one

* fix(secure download mode): Fix SDM detection on S2/S3

* fix(secure download mode): Reconnect if ROM refuses to respond

Closes espressif#813

* fix(flasher_stub): Correct boundaries for SPIWrite4B and SPIRead4B

SPIWrite4B and SPIRead4B functions are required for flash sizes bigger
than 16MB. This fix corrects the boundaries so SPIWrite and SPIRead
would be used for the whole 16MB area.

The octal flash support for 32 MB chips
(espressif#795) will be added in a
follow-up commit.

Closes espressif#745

Co-authored-by: Roland Dobai <roland@espressif.com>
Co-authored-by: radim.karnis <radim.karnis@espressif.com>
Jason2866 added a commit to Jason2866/esptool that referenced this issue Dec 28, 2022
* Tasmota changes

* stubs updated

* S3 16MB fix (#4)

* fix(setup): Use latest reedsolo package which can be installed with Python3.10 and Cython

Closes espressif#711

* feat(ci): Publish development releases with custom pipeline

* fix(ci): The development release job should not run by default

Gitlab rules:if adds the job if any of the rules are true.

* fix(ci): Merge two "ci" directories and build_tools into one

* fix(secure download mode): Fix SDM detection on S2/S3

* fix(secure download mode): Reconnect if ROM refuses to respond

Closes espressif#813

* fix(flasher_stub): Correct boundaries for SPIWrite4B and SPIRead4B

SPIWrite4B and SPIRead4B functions are required for flash sizes bigger
than 16MB. This fix corrects the boundaries so SPIWrite and SPIRead
would be used for the whole 16MB area.

The octal flash support for 32 MB chips
(espressif#795) will be added in a
follow-up commit.

Closes espressif#745

Co-authored-by: Roland Dobai <roland@espressif.com>
Co-authored-by: radim.karnis <radim.karnis@espressif.com>

* Update stub_flasher_32s3beta2.json

* Update build_esptool.yml

* Update build_esptool.yml

* stubs updated

Co-authored-by: Github BUILD <github-actions@github.com>
Co-authored-by: Roland Dobai <roland@espressif.com>
Co-authored-by: radim.karnis <radim.karnis@espressif.com>
Jason2866 added a commit to tasmota/esptool that referenced this issue Dec 28, 2022
* S3 16MB fix (#4)

* fix(setup): Use latest reedsolo package which can be installed with Python3.10 and Cython

Closes espressif#711

* feat(ci): Publish development releases with custom pipeline

* fix(ci): The development release job should not run by default

Gitlab rules:if adds the job if any of the rules are true.

* fix(ci): Merge two "ci" directories and build_tools into one

* fix(secure download mode): Fix SDM detection on S2/S3

* fix(secure download mode): Reconnect if ROM refuses to respond

Closes espressif#813

* fix(flasher_stub): Correct boundaries for SPIWrite4B and SPIRead4B

SPIWrite4B and SPIRead4B functions are required for flash sizes bigger
than 16MB. This fix corrects the boundaries so SPIWrite and SPIRead
would be used for the whole 16MB area.

The octal flash support for 32 MB chips
(espressif#795) will be added in a
follow-up commit.

Closes espressif#745

Co-authored-by: Roland Dobai <roland@espressif.com>
Co-authored-by: radim.karnis <radim.karnis@espressif.com>

* Update stub_flasher_32s3beta2.json

* Update build_esptool.yml

* Update build_esptool.yml

* stubs updated

Co-authored-by: Github BUILD <github-actions@github.com>
Co-authored-by: Roland Dobai <roland@espressif.com>
Co-authored-by: radim.karnis <radim.karnis@espressif.com>

* stubs updated

* stubs updated

Co-authored-by: Github BUILD <github-actions@github.com>
Co-authored-by: Roland Dobai <roland@espressif.com>
Co-authored-by: radim.karnis <radim.karnis@espressif.com>
dobairoland added a commit to espressif/esptool-legacy-flasher-stub that referenced this issue May 30, 2024
SPIWrite4B and SPIRead4B functions are required for flash sizes bigger
than 16MB. This fix corrects the boundaries so SPIWrite and SPIRead
would be used for the whole 16MB area.

The octal flash support for 32 MB chips
(espressif/esptool#795) will be added in a
follow-up commit.

Closes espressif/esptool#745
dobairoland added a commit to espressif/esptool-legacy-flasher-stub that referenced this issue May 30, 2024
Octal flash support tested up to 32MB. Quad flash support is limited to
16MB at this moment.

Closes espressif/esptool#795

Closes espressif/esptool#745

The next release will solve espressif/esp-idf#10323 as well.
@JedidiahPaterson
Copy link

Just wondering if anyone has a fix to this?

I am getting a failure right at 2MB

(idf5.1_py3.8_env) $ esptool.py --chip esp32s3 --port=/dev/ttyACM0 -b 115200 --no-stub read_flash 0x0b0000 0x181000 test.bin
esptool.py v4.7.dev1
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-S3 (QFN56) (revision v0.2)
Features: WiFi, BLE, Embedded PSRAM 8MB (AP_3v3)
Crystal is 40MHz
MAC: 30:30:f9:57:30:ec
Enabling default SPI flash mode...
1376256 (87 %)
A fatal error occurred: Failed to read flash block (result was 01090000: CRC or checksum was invalid)

the failure address + the offset = 2MB seems weird

I can do the verify_flash command

esptool.py verify_flash --diff yes 0x0B0000 build/test.bin

which returns the correct response digest matching/mismatching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants