Repository navigation
Only assume Secure Download Mode when the ROM rejects ReadReg - #1145
SergioGasquez wants to merge 2 commits into
Conversation
|
/hil esp32 esp32s2 esp32c6 esp32s3 |
|
/hil sdm |
|
Triggered chips HIL for PR #1145. Revision: Chips: Run: https://github.com/esp-rs/espflash/actions/runs/44135570248 Status: ✅ HIL run succeeded. |
|
Triggered sdm HIL for PR #1145. Revision: Chips: Run: https://github.com/esp-rs/espflash/actions/runs/44135695744 Status: ✅ HIL run succeeded. |
aafc0fb to
7f9dd9f
Compare
detect_sdm treated any ReadReg error, including timeouts, as Secure Download Mode. Like esptool, only a rejected command now means SDM; other errors are returned as connection errors. Fixes esp-rs#1139
7f9dd9f to
117b0de
Compare
| // Secure Download Mode, other errors mean that the chip is not answering. | ||
| match connection.read_reg(CHIP_DETECT_MAGIC_REG_ADDR) { | ||
| Ok(_) => {} | ||
| Err(Error::RomError(_)) => { |
There was a problem hiding this comment.
esptool only treats Secure Download Mode as a ReadReg reply whose opcode does not match and whose error is 0x05 (https://github.com/espressif/esptool/blob/6ec584a39e046c63f507d8022cb0b7df25e2d4de/esptool/loader.py#L615), but command() skips those frames until it times out, so this arm never runs and an SDM chip on this path fails to connect.
Description
Fixes #1139.
When
GET_SECURITY_INFOfails,detect_sdmreads0x40001000and assumed Secure Download Mode on any error, including timeouts. A chip that is not answering, e.g. with--before no-reset-no-syncwhile the application runs, got a false "Secure Download Mode is enabled on this chip" warning, took the SDM code paths, and then failed with a second timeout.Like esptool (
read_regraisesUnsupportedCommandErroronly for a nonzero status), only a ROM reply that rejectsReadReg(Error::RomError) now means SDM. Other errors, such as timeouts and I/O errors, are returned fromFlasher::connectas connection errors.An AI tool generated a significant part of this change. It is tested on the host and on local hardware, see Testing.
Testing
detect_sdmover a pseudo-terminal pair, with a device that rejectsGetSecurityInfolike the ESP32 ROM: a rejectedReadRegsets SDM, an answeredReadRegdoes not, and aReadRegtimeout returns a connection timeout error without setting SDM.espflash reset, thenboard-info --before no-reset-no-sync --chip <chip>) on ESP32-C5, ESP32-S3, ESP32-C6 (USB-Serial-JTAG), ESP32-C61, ESP32-C2 and ESP32-H2 (CP2102N):WARN Secure Download Mode is enabled on this chip, then aReadRegorGetSecurityInfotimeout after ~9.1 s.Timeout while running ReadReg commandafter ~6.1 s.--before no-reset-no-sync --no-stubagainst a chip left in the ROM loader (--no-stub --after no-reset) and plainboard-infostill work on all six boards, with no SDM reported.cargo xtask run-tests allpassed on ESP32-C5, ESP32-S3, ESP32-C6, ESP32-C61 and ESP32-H2. On ESP32-C2 (CP2102N),watchdog reset after flashingfailed in 2 of 4 full runs and passed 3/3 when run alone; the C2 answersGET_SECURITY_INFO, so it never reaches the changed path.GET_SECURITY_INFOfails and theReadRegpath runs on every connect. The HIL rig covers ESP32 and ESP32-S2.