Skip to content

Commit

Permalink
Remove direct boot (#577)
Browse files Browse the repository at this point in the history
* Remove the `DirectBoot` image format

* Refactor the `ImageFormat` trait out of existence

* Update `README.md`

* Update `CHANGELOG.md`

* Remove test binaries for direct boot and ESP8266
  • Loading branch information
jessebraham authored Feb 6, 2024
1 parent 1cde4fc commit 8814e83
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 682 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

- Remove support for the ESP8266 (#576)
- Remove the direct boot image format (#577)

## [2.1.0] - 2023-10-03

Expand Down
9 changes: 0 additions & 9 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use espflash::{
},
error::Error as EspflashError,
flasher::{parse_partition_table, FlashData, FlashSettings},
image_format::ImageFormatKind,
logging::initialize_logger,
targets::{Chip, XtalFrequency},
update::check_for_update,
Expand Down Expand Up @@ -185,9 +184,6 @@ struct FlashArgs {
#[derive(Debug, Args)]
#[non_exhaustive]
struct SaveImageArgs {
/// Image format to flash
#[arg(long, value_enum)]
pub format: Option<ImageFormatKind>,
#[clap(flatten)]
build_args: BuildArgs,
#[clap(flatten)]
Expand Down Expand Up @@ -327,7 +323,6 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
bootloader,
partition_table,
args.flash_args.partition_table_offset,
args.flash_args.format,
args.flash_args.target_app_partition,
flash_settings,
args.flash_args.min_chip_rev,
Expand Down Expand Up @@ -557,9 +552,6 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
// Since we have no `Flasher` instance and as such cannot print the board
// information, we will print whatever information we _do_ have.
println!("Chip type: {}", args.save_image_args.chip);
if let Some(format) = args.format {
println!("Image format: {:?}", format);
}
println!("Merge: {}", args.save_image_args.merge);
println!("Skip padding: {}", args.save_image_args.skip_padding);
if let Some(path) = &args.save_image_args.bootloader {
Expand All @@ -579,7 +571,6 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
bootloader.as_deref(),
partition_table.as_deref(),
args.save_image_args.partition_table_offset,
args.format,
args.save_image_args.target_app_partition,
flash_settings,
args.save_image_args.min_chip_rev,
Expand Down
9 changes: 0 additions & 9 deletions espflash/src/bin/espflash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use espflash::{
},
error::Error,
flasher::{parse_partition_table, FlashData, FlashSettings},
image_format::ImageFormatKind,
logging::initialize_logger,
targets::{Chip, XtalFrequency},
update::check_for_update,
Expand Down Expand Up @@ -126,9 +125,6 @@ struct FlashArgs {
struct SaveImageArgs {
/// ELF image to flash
image: PathBuf,
/// Image format to flash
#[arg(long, value_enum)]
format: Option<ImageFormatKind>,
/// Flashing configuration
#[clap(flatten)]
pub flash_config_args: FlashConfigArgs,
Expand Down Expand Up @@ -262,7 +258,6 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
bootloader,
partition_table,
args.flash_args.partition_table_offset,
args.flash_args.format,
args.flash_args.target_app_partition,
flash_settings,
args.flash_args.min_chip_rev,
Expand Down Expand Up @@ -324,9 +319,6 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
// Since we have no `Flasher` instance and as such cannot print the board
// information, we will print whatever information we _do_ have.
println!("Chip type: {}", args.save_image_args.chip);
if let Some(format) = args.format {
println!("Image format: {:?}", format);
}
println!("Merge: {}", args.save_image_args.merge);
println!("Skip padding: {}", args.save_image_args.skip_padding);
if let Some(path) = &bootloader {
Expand All @@ -346,7 +338,6 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
bootloader,
partition_table,
args.save_image_args.partition_table_offset,
args.format,
args.save_image_args.target_app_partition,
flash_settings,
args.save_image_args.min_chip_rev,
Expand Down
4 changes: 0 additions & 4 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::{
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSize, Flasher,
ProgressCallbacks,
},
image_format::ImageFormatKind,
interface::Interface,
targets::{Chip, XtalFrequency},
};
Expand Down Expand Up @@ -140,9 +139,6 @@ pub struct FlashArgs {
/// Erase specified data partitions
#[arg(long, value_name = "PARTS", value_enum, value_delimiter = ',')]
pub erase_data_parts: Option<Vec<DataType>>,
/// Image format to flash
#[arg(long, value_enum)]
pub format: Option<ImageFormatKind>,
/// Logging format.
#[arg(long, short = 'L', default_value = "serial", requires = "monitor")]
pub log_format: LogFormat,
Expand Down
106 changes: 5 additions & 101 deletions espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ use std::{
io,
};

use miette::Diagnostic;
use slip_codec::SlipError;
use strum::{FromRepr, VariantNames};
use thiserror::Error;

#[cfg(feature = "cli")]
use crate::cli::monitor::parser::esp_defmt::DefmtError;
#[cfg(feature = "serialport")]
use crate::interface::SerialConfigError;
use crate::{
command::CommandType,
flasher::{FlashFrequency, FlashSize},
image_format::ImageFormatKind,
targets::Chip,
};

use miette::Diagnostic;
use slip_codec::SlipError;
use strum::{FromRepr, VariantNames};
use thiserror::Error;

/// All possible errors returned by espflash
#[derive(Debug, Diagnostic, Error)]
#[non_exhaustive]
Expand Down Expand Up @@ -107,16 +106,6 @@ pub enum Error {
#[diagnostic(code(espflash::invalid_bootloader_path))]
InvalidBootloaderPath,

#[error("Binary is not set up correctly to support direct boot")]
#[diagnostic(
code(espflash::invalid_direct_boot),
help(
"See the following page for documentation on how to set up your binary for direct boot:\
https://github.com/espressif/esp32c3-direct-boot-example"
)
)]
InvalidDirectBootBinary,

#[error("The flash size '{0}' is invalid")]
#[diagnostic(
code(espflash::invalid_flash_size),
Expand Down Expand Up @@ -165,13 +154,6 @@ pub enum Error {
)]
SerialNotFound(String),

#[error("Unrecognized image format '{0}'")]
#[diagnostic(
code(espflash::unknown_format),
help("The following image formats are supported: {}", ImageFormatKind::VARIANTS.join(", "))
)]
UnknownImageFormat(String),

#[error("The {chip} does not support {feature}")]
#[diagnostic(code(espflash::unsupported_feature))]
UnsupportedFeature { chip: Chip, feature: String },
Expand Down Expand Up @@ -221,10 +203,6 @@ pub enum Error {
#[diagnostic(transparent)]
RomError(#[from] RomError),

#[error(transparent)]
#[diagnostic(transparent)]
UnsupportedImageFormat(#[from] UnsupportedImageFormatError),

#[cfg(feature = "serialport")]
#[error(transparent)]
#[diagnostic(transparent)]
Expand Down Expand Up @@ -517,80 +495,6 @@ impl From<&'static str> for ElfError {
}
}

/// Unsupported image format error
#[derive(Debug)]
pub struct UnsupportedImageFormatError {
format: ImageFormatKind,
chip: Chip,
revision: Option<(u32, u32)>,
context: Option<String>,
}

impl UnsupportedImageFormatError {
pub fn new(format: ImageFormatKind, chip: Chip, revision: Option<(u32, u32)>) -> Self {
Self {
format,
chip,
revision,
context: None,
}
}

/// Return a comma-separated list of supported image formats
fn supported_formats(&self) -> String {
self.chip
.into_target()
.supported_image_formats()
.iter()
.map(|format| format.into())
.collect::<Vec<&'static str>>()
.join(", ")
}

/// Update the context of the unsupported image format error
pub fn with_context(mut self, ctx: String) -> Self {
self.context.replace(ctx);

self
}
}

impl std::error::Error for UnsupportedImageFormatError {}

impl Display for UnsupportedImageFormatError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(
f,
"Image format {} is not supported by the {}",
self.format, self.chip
)?;

if let Some((major, minor)) = self.revision {
write!(f, " revision v{major}.{minor}")?;
}

Ok(())
}
}

impl Diagnostic for UnsupportedImageFormatError {
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
Some(Box::new("espflash::unsupported_image_format"))
}

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
if let Some(ref ctx) = self.context {
Some(Box::new(ctx))
} else {
Some(Box::new(format!(
"The following image formats are supported by the {}: {}",
self.chip,
self.supported_formats()
)))
}
}
}

pub(crate) trait ResultExt {
/// Mark an error as having occurred during the flashing stage
fn flashing(self) -> Self;
Expand Down
13 changes: 0 additions & 13 deletions espflash/src/flasher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use crate::{
command::{Command, CommandType},
elf::{ElfFirmwareImage, FirmwareImage, RomSegment},
error::{ConnectionError, Error, ResultExt},
image_format::ImageFormatKind,
targets::{Chip, XtalFrequency},
};
#[cfg(feature = "serialport")]
Expand Down Expand Up @@ -285,7 +284,6 @@ pub struct FlashDataBuilder<'a> {
bootloader_path: Option<&'a Path>,
partition_table_path: Option<&'a Path>,
partition_table_offset: Option<u32>,
image_format: Option<ImageFormatKind>,
target_app_partition: Option<String>,
flash_settings: FlashSettings,
min_chip_rev: u16,
Expand All @@ -297,7 +295,6 @@ impl<'a> Default for FlashDataBuilder<'a> {
bootloader_path: Default::default(),
partition_table_path: Default::default(),
partition_table_offset: Default::default(),
image_format: Default::default(),
target_app_partition: Default::default(),
flash_settings: FlashSettings::default(),
min_chip_rev: Default::default(),
Expand Down Expand Up @@ -329,12 +326,6 @@ impl<'a> FlashDataBuilder<'a> {
self
}

/// Sets the image format.
pub fn with_image_format(mut self, image_format: ImageFormatKind) -> Self {
self.image_format = Some(image_format);
self
}

/// Sets the label of the target app partition.
pub fn with_target_app_partition(mut self, target_app_partition: String) -> Self {
self.target_app_partition = Some(target_app_partition);
Expand All @@ -359,7 +350,6 @@ impl<'a> FlashDataBuilder<'a> {
self.bootloader_path,
self.partition_table_path,
self.partition_table_offset,
self.image_format,
self.target_app_partition,
self.flash_settings,
self.min_chip_rev,
Expand All @@ -374,7 +364,6 @@ pub struct FlashData {
pub bootloader: Option<Vec<u8>>,
pub partition_table: Option<PartitionTable>,
pub partition_table_offset: Option<u32>,
pub image_format: Option<ImageFormatKind>,
pub target_app_partition: Option<String>,
pub flash_settings: FlashSettings,
pub min_chip_rev: u16,
Expand All @@ -385,7 +374,6 @@ impl FlashData {
bootloader: Option<&Path>,
partition_table: Option<&Path>,
partition_table_offset: Option<u32>,
image_format: Option<ImageFormatKind>,
target_app_partition: Option<String>,
flash_settings: FlashSettings,
min_chip_rev: u16,
Expand All @@ -412,7 +400,6 @@ impl FlashData {
bootloader,
partition_table,
partition_table_offset,
image_format,
target_app_partition,
flash_settings,
min_chip_rev,
Expand Down
Loading

0 comments on commit 8814e83

Please sign in to comment.