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

Add a test for the Direct Boot image format #276

Merged
merged 1 commit into from
Oct 27, 2022
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
24 changes: 24 additions & 0 deletions espflash/src/image_format/direct_boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,27 @@ impl<'a> ImageFormat<'a> for DirectBootFormat<'a> {
Box::new(once(self.segment.borrow()))
}
}

#[cfg(test)]
pub mod tests {
use std::fs;

use super::*;
use crate::elf::ElfFirmwareImage;

#[test]
fn test_direct_boot_format() {
let input_bytes = fs::read("tests/resources/esp32c3_hal_blinky_db").unwrap();
let expected_bin = fs::read("tests/resources/esp32c3_hal_blinky_db.bin").unwrap();

let image = ElfFirmwareImage::try_from(input_bytes.as_slice()).unwrap();
let flash_image = DirectBootFormat::new(&image, 0).unwrap();

let segments = flash_image.flash_segments().collect::<Vec<_>>();
assert_eq!(segments.len(), 1);

let buf = segments[0].data.as_ref();
assert_eq!(expected_bin.len(), buf.len());
assert_eq!(expected_bin.as_slice(), buf);
}
}
14 changes: 14 additions & 0 deletions espflash/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

This document describes how the test files under `tests/resources` were generated, so that they can be re-generated in the future if needed.

## Direct Boot

```bash
$ git clone https://github.com/esp-rs/esp-hal
$ cd esp-hal/esp32c3-hal/
$ cargo build --release --features=direct-boot --example=blinky
```

The ELF file is located at `target/riscv32imc-unknown-none-elf/examples/blinky`

```bash
$ espflash save-image --format=direct-boot --chip=esp32c3 esp32c3_hal_blinky_db.bin esp32c3_hal_blinky_db
```

## IDF Bootloader

```bash
Expand Down
Binary file added espflash/tests/resources/esp32c3_hal_blinky_db
Binary file not shown.
Binary file not shown.