Skip to content

Commit c63d018

Browse files
committed
allow specifying image format in the projects Cargo.toml
1 parent 3834e83 commit c63d018

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

cargo-espflash/src/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ fn flash(
237237
let image_format = matches
238238
.value_of("format")
239239
.map(ImageFormatId::from_str)
240-
.transpose()
241-
.into_diagnostic()?;
240+
.transpose()?
241+
.or(metadata.format);
242242

243243
// Read the ELF data from the build path and load it to the target.
244244
let elf_data = fs::read(path).into_diagnostic()?;
@@ -368,7 +368,7 @@ fn build(
368368
fn save_image(
369369
matches: &ArgMatches,
370370
_config: Config,
371-
_metadata: CargoEspFlashMeta,
371+
metadata: CargoEspFlashMeta,
372372
cargo_config: CargoConfig,
373373
) -> Result<()> {
374374
let target = cargo_config
@@ -385,8 +385,8 @@ fn save_image(
385385
let image_format = matches
386386
.value_of("format")
387387
.map(ImageFormatId::from_str)
388-
.transpose()
389-
.into_diagnostic()?;
388+
.transpose()?
389+
.or(metadata.format);
390390

391391
let flash_image = chip.get_flash_image(&image, None, None, image_format)?;
392392
let parts: Vec<_> = flash_image.ota_segments().collect();

cargo-espflash/src/package_metadata.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::error::{Error, TomlError};
22
use cargo_toml::Manifest;
3+
use espflash::ImageFormatId;
34
use miette::{IntoDiagnostic, Result, WrapErr};
45
use serde::Deserialize;
56
use std::fs::read_to_string;
@@ -9,6 +10,7 @@ use std::path::Path;
910
pub struct CargoEspFlashMeta {
1011
pub partition_table: Option<String>,
1112
pub bootloader: Option<String>,
13+
pub format: Option<ImageFormatId>,
1214
}
1315

1416
#[derive(Clone, Debug, Default, Deserialize)]

espflash/src/image_format/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub use esp32directboot::*;
99
pub use esp8266::*;
1010

1111
use crate::error::Error;
12+
use serde::Deserialize;
1213
use std::str::FromStr;
1314
use strum_macros::{AsStaticStr, Display, EnumVariantNames};
1415

@@ -46,8 +47,11 @@ pub trait ImageFormat<'a> {
4647
'a: 'b;
4748
}
4849

49-
#[derive(Debug, Copy, Clone, Eq, PartialEq, Display, AsStaticStr, EnumVariantNames)]
50+
#[derive(
51+
Debug, Copy, Clone, Eq, PartialEq, Display, AsStaticStr, EnumVariantNames, Deserialize,
52+
)]
5053
#[strum(serialize_all = "kebab-case")]
54+
#[serde(rename_all = "kebab-case")]
5155
pub enum ImageFormatId {
5256
Bootloader,
5357
DirectBoot,

0 commit comments

Comments
 (0)