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

enable support for loader stubs (via --use-stub arg) #216

Merged
merged 9 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
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
let _ = 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
4 changes: 2 additions & 2 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
Loading