Add a test for the Direct Boot image format

This commit is contained in:
Jesse Braham
2022-10-27 09:19:23 -07:00
committed by Jesse Braham
parent d3e3426600
commit fbaca200d6
4 changed files with 38 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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

Binary file not shown.

Binary file not shown.