Skip to content

Commit 353c6da

Browse files
committed
validate that the image is setup for direct boot
1 parent c63d018 commit 353c6da

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

espflash/src/chip/esp32/esp32.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::Range;
22

33
use super::Esp32Params;
4+
use crate::error::UnsupportedImageFormatError;
45
use crate::{
56
chip::{bytes_to_mac_addr, Chip, ChipType, ReadEFuse, SpiRegisters},
67
connection::Connection,
@@ -126,9 +127,7 @@ impl ChipType for Esp32 {
126127
partition_table,
127128
bootloader,
128129
)?)),
129-
ImageFormatId::DirectBoot => {
130-
todo!()
131-
}
130+
_ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp8266).into()),
132131
}
133132
}
134133

espflash/src/chip/esp32/esp32s2.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::Range;
22

33
use super::Esp32Params;
4+
use crate::error::UnsupportedImageFormatError;
45
use crate::{
56
chip::{bytes_to_mac_addr, ChipType, ReadEFuse, SpiRegisters},
67
connection::Connection,
@@ -103,9 +104,7 @@ impl ChipType for Esp32s2 {
103104
partition_table,
104105
bootloader,
105106
)?)),
106-
ImageFormatId::DirectBoot => {
107-
todo!()
108-
}
107+
_ => Err(UnsupportedImageFormatError::new(image_format, Chip::Esp8266).into()),
109108
}
110109
}
111110

espflash/src/error.rs

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ pub enum Error {
5757
help("The following image formats are {}", ImageFormatId::VARIANTS.join(", "))
5858
)]
5959
UnknownImageFormat(String),
60+
#[error("binary is not setup correct to support direct boot")]
61+
#[diagnostic(
62+
code(espflash::invalid_direct_boot),
63+
help(
64+
"See the following page for documentation on how to setup your binary for direct boot:
65+
https://github.com/espressif/esp32c3-direct-boot-example"
66+
)
67+
)]
68+
InvalidDirectBootBinary,
6069
}
6170

6271
#[derive(Error, Debug, Diagnostic)]

espflash/src/image_format/esp32directboot.rs

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ impl<'a> Esp32DirectBootFormat<'a> {
2626
});
2727
segment.pad_align(4);
2828

29+
if segment.addr != 0
30+
|| segment.data()[0..8] != [0x1d, 0x04, 0xdb, 0xae, 0x1d, 0x04, 0xdb, 0xae]
31+
{
32+
return Err(Error::InvalidDirectBootBinary);
33+
}
34+
2935
Ok(Self {
3036
segment: segment.into(),
3137
})

0 commit comments

Comments
 (0)