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

Fix direct-boot image check for ESP32-S3 #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion espflash/src/chip/esp32/esp32c2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ChipType for Esp32c2 {
flash_size,
flash_freq,
)?)),
ImageFormatId::DirectBoot => Ok(Box::new(Esp32DirectBootFormat::new(image)?)),
ImageFormatId::DirectBoot => Ok(Box::new(Esp32DirectBootFormat::new(image, 0)?)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion espflash/src/chip/esp32/esp32c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl ChipType for Esp32c3 {
flash_freq,
)?)),
(ImageFormatId::DirectBoot, None | Some(3..)) => {
Ok(Box::new(Esp32DirectBootFormat::new(image)?))
Ok(Box::new(Esp32DirectBootFormat::new(image, 0)?))
}
_ => Err(
UnsupportedImageFormatError::new(image_format, Chip::Esp32c3, chip_revision).into(),
Expand Down
2 changes: 1 addition & 1 deletion espflash/src/chip/esp32/esp32s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ChipType for Esp32s3 {
flash_size,
flash_freq,
)?)),
ImageFormatId::DirectBoot => Ok(Box::new(Esp32DirectBootFormat::new(image)?)),
ImageFormatId::DirectBoot => Ok(Box::new(Esp32DirectBootFormat::new(image, 0x400)?)),
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions espflash/src/image_format/esp32directboot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::{
};
use std::iter::once;

/// Image format for esp32 family chips using a 2nd stage bootloader
/// Image format for esp32 family chips not using a 2nd stage bootloader
pub struct Esp32DirectBootFormat<'a> {
segment: RomSegment<'a>,
}

impl<'a> Esp32DirectBootFormat<'a> {
pub fn new(image: &'a dyn FirmwareImage<'a>) -> Result<Self, Error> {
pub fn new(image: &'a dyn FirmwareImage<'a>, magic_offset: usize) -> Result<Self, Error> {
let mut segment = image
.segments_with_load_addresses()
.map(|mut segment| {
Expand All @@ -27,7 +27,9 @@ impl<'a> Esp32DirectBootFormat<'a> {
segment.pad_align(4);

if segment.addr != 0
|| segment.data()[0..8] != [0x1d, 0x04, 0xdb, 0xae, 0x1d, 0x04, 0xdb, 0xae]
|| (segment.data().len() >= magic_offset + 8
&& segment.data()[magic_offset..][..8]
!= [0x1d, 0x04, 0xdb, 0xae, 0x1d, 0x04, 0xdb, 0xae])
{
return Err(Error::InvalidDirectBootBinary);
}
Expand Down