Skip to content

Commit b01bb71

Browse files
authored
Fix SDM detection for P4 (#972)
1 parent 23222d5 commit b01bb71

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[alias]
22
xtask = "run --package xtask --"
3+
xrun = "run --package espflash --"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717

1818
- Corrected eFuse BLOCK0 definitions for ESP32-C2, ESP32-C3, and ESP32-S3 (#961)
19+
- Fixed Secure Download Mode detection on ESP32-P4 (#972)
1920

2021
### Removed
2122

espflash/src/connection/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl SecurityInfo {
8787
])
8888
}
8989

90-
fn security_flag_status(&self, flag_name: &str) -> bool {
90+
pub(crate) fn security_flag_status(&self, flag_name: &str) -> bool {
9191
if let Some(&flag) = Self::security_flag_map().get(flag_name) {
9292
(self.flags & flag) != 0
9393
} else {

espflash/src/flasher/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,13 @@ impl Flasher {
12531253

12541254
#[cfg(feature = "serialport")]
12551255
fn detect_sdm(connection: &mut Connection) {
1256-
if connection.read_reg(CHIP_DETECT_MAGIC_REG_ADDR).is_err() {
1256+
if let Ok(security_info) = connection.security_info(false) {
1257+
// Newer chips tell us if SDM is enabled.
1258+
connection.secure_download_mode =
1259+
security_info.security_flag_status("SECURE_DOWNLOAD_ENABLE");
1260+
} else if connection.read_reg(CHIP_DETECT_MAGIC_REG_ADDR).is_err() {
1261+
// On older chips, we have to guess by reading something. On these chips, there
1262+
// is always something readable at 0x40001000.
12571263
log::warn!("Secure Download Mode is enabled on this chip");
12581264
connection.secure_download_mode = true;
12591265
}

0 commit comments

Comments
 (0)