Skip to content

Commit

Permalink
Merge pull request #216 from ryankurte/feature/flash-stubs
Browse files Browse the repository at this point in the history
enable support for loader stubs (via --use-stub arg)
  • Loading branch information
jessebraham committed Aug 17, 2022
2 parents 00c47eb + d15beb5 commit 2c6f25f
Show file tree
Hide file tree
Showing 28 changed files with 498 additions and 49 deletions.
107 changes: 107 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion cargo-espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ pkg-fmt = "zip"
[dependencies]
cargo_metadata = "0.15"
cargo_toml = "0.11"
clap = { version = "3.2", features = ["derive"] }
clap = { version = "3.2", features = ["derive", "env"] }
espflash = { version = "=1.6.1-dev", path = "../espflash" }
log = "0.4.17"
miette = { version = "5.2", features = ["fancy"] }
serde = { version = "1.0", features = ["derive"] }
strum = "0.24"
thiserror = "1.0"
tracing-subscriber = { version = "0.3.11", features = [ "env-filter" ] }
toml = "0.5"
32 changes: 25 additions & 7 deletions cargo-espflash/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ use espflash::{
},
Chip, Config, ImageFormatId,
};
use log::debug;
use miette::{IntoDiagnostic, Result, WrapErr};
use strum::VariantNames;
use tracing_subscriber::{filter::LevelFilter, EnvFilter};

use crate::{
cargo_config::{parse_cargo_config, CargoConfig},
Expand All @@ -28,19 +30,23 @@ mod cargo_config;
mod error;
mod package_metadata;

#[derive(Parser)]
#[derive(Debug, Clone, Parser)]
#[clap(bin_name = "cargo", version, propagate_version = true)]
struct Opts {
#[clap(subcommand)]
subcommand: CargoSubCommand,

/// Log level
#[clap(long, default_value = "info", env)]
log_level: LevelFilter,
}

#[derive(Parser)]
#[derive(Debug, Clone, Parser)]
enum CargoSubCommand {
Espflash(EspFlashOpts),
}

#[derive(Parser)]
#[derive(Debug, Clone, Parser)]
struct EspFlashOpts {
#[clap(flatten)]
flash_opts: FlashOpts,
Expand All @@ -52,7 +58,7 @@ struct EspFlashOpts {
subcommand: Option<SubCommand>,
}

#[derive(Parser)]
#[derive(Debug, Clone, Parser)]
pub enum SubCommand {
/// Display information about the connected board and exit without flashing
BoardInfo(ConnectOpts),
Expand All @@ -64,7 +70,7 @@ pub enum SubCommand {
PartitionTable(PartitionTableOpts),
}

#[derive(Parser)]
#[derive(Debug, Clone, Parser)]
pub struct BuildOpts {
/// Build the application using the release profile
#[clap(long)]
Expand Down Expand Up @@ -100,7 +106,7 @@ pub struct BuildOpts {
pub flash_config_opts: FlashConfigOpts,
}

#[derive(Parser)]
#[derive(Debug, Clone, Parser)]
pub struct SaveImageOpts {
#[clap(flatten)]
pub build_opts: BuildOpts,
Expand All @@ -125,8 +131,20 @@ fn main() -> Result<()> {

check_for_updates(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));

let CargoSubCommand::Espflash(opts) = Opts::parse().subcommand;
// Parse options
let opts = Opts::parse();

// Setup logging
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env().add_directive(opts.log_level.into()))
.init();

// Extract subcommand
let CargoSubCommand::Espflash(opts) = opts.subcommand;

debug!("subcommand options: {:?}", opts);

// Load configuration and metadata
let config = Config::load()?;
let metadata = CargoEspFlashMeta::load("Cargo.toml")?;
let cargo_config = parse_cargo_config(".")?;
Expand Down
6 changes: 5 additions & 1 deletion espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ bin-dir = "{ bin }{ binary-ext }"
pkg-fmt = "zip"

[dependencies]
base64 = "0.13.0"
binread = "2.2"
bytemuck = { version = "1.11", features = ["derive"] }
clap = { version = "3.2", features = ["derive"] }
clap = { version = "3.2", features = ["derive", "env"] }
comfy-table = "6.0"
crossterm = "0.24"
csv = "1.1"
Expand All @@ -40,15 +41,18 @@ directories-next = "2.0"
espmonitor = "0.10"
flate2 = "1.0"
indicatif = "0.17"
log = "0.4.17"
maplit = "1.0"
md5 = "0.7"
miette = { version = "5.2", features = ["fancy"] }
parse_int = "0.6"
regex = "1.6"
serde = { version = "1.0", features = ["derive"] }
serde-hex = "0.1"
serde_json = "1.0.83"
serde_plain = "1.0"
serialport = "4.2"
tracing-subscriber = { version = "0.3.11", features = [ "env-filter" ] }
sha2 = "0.10"
slip-codec = "0.3"
strum = "0.24"
Expand Down
12 changes: 8 additions & 4 deletions espflash/src/chip/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, ops::Range, str::FromStr};

use maplit::hashmap;
use strum_macros::{Display, EnumVariantNames};
use strum_macros::{Display, EnumIter, EnumVariantNames};

pub use self::{
esp32::{Esp32, Esp32Params, Esp32c2, Esp32c3, Esp32s2, Esp32s3},
Expand Down Expand Up @@ -143,7 +143,7 @@ impl SpiRegisters {
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Display, EnumVariantNames)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Display, EnumVariantNames, EnumIter)]
pub enum Chip {
#[strum(serialize = "ESP32")]
Esp32,
Expand Down Expand Up @@ -299,10 +299,14 @@ impl Chip {
Box::new(RamTarget::new(entry))
}

pub fn flash_target(&self, spi_params: SpiAttachParams) -> Box<dyn FlashTarget> {
pub fn flash_target(
&self,
spi_params: SpiAttachParams,
use_stub: bool,
) -> Box<dyn FlashTarget> {
match self {
Chip::Esp8266 => Box::new(Esp8266Target::new()),
_ => Box::new(Esp32Target::new(*self, spi_params)),
_ => Box::new(Esp32Target::new(*self, spi_params, use_stub)),
}
}

Expand Down
Loading

0 comments on commit 2c6f25f

Please sign in to comment.