Skip to content

Commit d15beb5

Browse files
ryankurtemertzt89
andcommitted
Look for stub handshake
Co-authored-by: Timothy Mertz <mertzt89@gmail.com>
1 parent 0b8f61b commit d15beb5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

espflash/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ pub enum ConnectionError {
152152
help("Try hard-resetting the device and try again, if the error persists your rom might be corrupted")
153153
)]
154154
OverSizedPacket,
155+
#[error("Invalid stub handshake response received")]
156+
InvalidStubHandshake,
155157
}
156158

157159
#[derive(Debug, Default, Clone)]

espflash/src/flash_target/ram.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,12 @@ impl FlashTarget for RamTarget {
6767
if reboot {
6868
let entry = self.entry.unwrap_or_default();
6969
connection.with_timeout(CommandType::MemEnd.timeout(), |connection| {
70-
connection.write_command(Command::MemEnd {
70+
connection.command(Command::MemEnd {
7171
no_entry: entry == 0,
7272
entry,
7373
})
74-
})
75-
} else {
76-
Ok(())
74+
})?;
7775
}
76+
Ok(())
7877
}
7978
}

espflash/src/flasher.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const FLASH_SECTORS_PER_BLOCK: usize = FLASH_SECTOR_SIZE / FLASH_BLOCK_SIZE;
2626
// register used for chip detect
2727
const CHIP_DETECT_MAGIC_REG_ADDR: u32 = 0x40001000;
2828

29+
const EXPECTED_STUB_HANDSHAKE: &str = "OHAI";
30+
2931
#[derive(Clone, Copy, Debug, Eq, PartialEq, Display, EnumVariantNames)]
3032
#[repr(u8)]
3133
pub enum FlashSize {
@@ -289,8 +291,10 @@ impl Flasher {
289291

290292
debug!("Stub written...");
291293

292-
// Re-sync connection
293-
self.connection.sync()?;
294+
match self.connection.read(EXPECTED_STUB_HANDSHAKE.len())? {
295+
Some(resp) if resp == EXPECTED_STUB_HANDSHAKE.as_bytes() => Ok(()),
296+
_ => Err(Error::Connection(ConnectionError::InvalidStubHandshake)),
297+
}?;
294298

295299
// Re-detect chip to check stub is up
296300
let magic = self.connection.read_reg(CHIP_DETECT_MAGIC_REG_ADDR)?;

0 commit comments

Comments
 (0)