diff --git a/README.md b/README.md index dc4fd6d63a3226e1b069877cf5e401fa769c8c02..bb30122b4bfd5c23fae50bfce767c170d5bafb92 100644 --- a/README.md +++ b/README.md @@ -50,15 +50,13 @@ Options: ⯠bb-imager-cli flash sd --help Flash an SD card with customizable settings for BeagleBoard devices -Usage: bb-imager-cli flash sd [OPTIONS] <--img-local <IMG_LOCAL>|--img-remote <IMG_REMOTE>> <DST> +Usage: bb-imager-cli flash sd [OPTIONS] <IMG> <DST> Arguments: + <IMG> Local path to image file. Can be compressed (xz) or extracted file <DST> The destination device (e.g., `/dev/sdX` or specific device identifiers) Options: - --img-local <IMG_LOCAL> Path to the image file to flash. Supports both raw and compressed (e.g., xz) formats - --img-remote <IMG_REMOTE> URL to remote image file to flash. Supports both raw and compressed (e.g., xz) formats - --img-sha256 <IMG_SHA256> Checksum for remote image --no-verify Disable checksum verification post-flash --hostname <HOSTNAME> Set a custom hostname for the device (e.g., "beaglebone") --timezone <TIMEZONE> Set the timezone for the device (e.g., "America/New_York") @@ -72,18 +70,8 @@ Options: -h, --help Print help ``` -## Flashing Remote image +## Flashing image ```shell -⯠bb-imager-cli flash bcf --image-remote $IMG_URL --image-sha256 $IMG_SHA256 /dev/ttyACM0 -[1] Preparing -[2] Verifying [█████████████████████████████████████████████████████████████████████████████████████████████████████████████] [100 %] -[3] Flashing [█████████████████████████████████████████████████████████████████████████████████████████████████████████████] [100 %] -[4] Verifying -``` - -## Flashing Local image - -```shell -⯠bb-imager-cli flash --quiet bcf $DESTINATION --img-local $IMG_PATH /dev/ttyACM0 +⯠bb-imager-cli flash --quiet bcf $IMG_PATH /dev/ttyACM0 ``` diff --git a/bb-imager-cli/src/cli.rs b/bb-imager-cli/src/cli.rs index dae8f7889f86399cc1a58f72abac82151eb8ad13..b82896e8e563e752ca6fee4069a0e3cb4aa9c131 100644 --- a/bb-imager-cli/src/cli.rs +++ b/bb-imager-cli/src/cli.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; -use clap::{Args, Parser, Subcommand, ValueEnum}; -use url::Url; +use clap::{Parser, Subcommand, ValueEnum}; #[derive(Parser, Debug)] #[command(version, about)] @@ -55,8 +54,8 @@ pub enum Commands { pub enum TargetCommands { /// Flash BeagleConnect Freedom. Bcf { - #[command(flatten)] - img: SelectedImage, + /// Local path to image file. Can be compressed (xz) or extracted file + img: PathBuf, /// The destination device (e.g., `/dev/sdX` or specific device identifiers). dst: String, @@ -67,8 +66,8 @@ pub enum TargetCommands { }, /// Flash an SD card with customizable settings for BeagleBoard devices. Sd { - #[command(flatten)] - img: SelectedImage, + /// Local path to image file. Can be compressed (xz) or extracted file + img: PathBuf, /// The destination device (e.g., `/dev/sdX` or specific device identifiers). dst: PathBuf, @@ -109,8 +108,8 @@ pub enum TargetCommands { }, /// Flash MSP430 on BeagleConnectFreedom. Msp430 { - #[command(flatten)] - img: SelectedImage, + /// Local path to image file. Can be compressed (xz) or extracted file + img: PathBuf, /// The destination device (e.g., `/dev/sdX` or specific device identifiers). dst: String, @@ -118,8 +117,8 @@ pub enum TargetCommands { /// Flash MSPM0 on Pocketbeagle2. #[cfg(feature = "pb2_mspm0")] Pb2Mspm0 { - #[command(flatten)] - img: SelectedImage, + /// Local path to image file. Can be compressed (xz) or extracted file + img: PathBuf, /// Do not persist EEPROM contents #[arg(long)] @@ -139,23 +138,3 @@ pub enum DestinationsTarget { #[cfg(feature = "pb2_mspm0")] Pb2Mspm0, } - -#[derive(Args, Debug)] -pub struct SelectedImage { - #[command(flatten)] - pub img: OsImage, - #[arg(long, requires = "img_remote")] - /// Checksum for remote image. - pub img_sha256: Option<String>, -} - -#[derive(Args, Debug)] -#[group(required = true, multiple = false)] -pub struct OsImage { - #[arg(long)] - /// Path to the image file to flash. Supports both raw and compressed (e.g., xz) formats. - pub img_local: Option<PathBuf>, - #[arg(long, requires = "img_sha256")] - /// URL to remote image file to flash. Supports both raw and compressed (e.g., xz) formats. - pub img_remote: Option<Url>, -} diff --git a/bb-imager-cli/src/main.rs b/bb-imager-cli/src/main.rs index c1e70a251a8067daeddcee9306fb611fbea48f5c..ef87540365a57101994de130050f498b4aefa16d 100644 --- a/bb-imager-cli/src/main.rs +++ b/bb-imager-cli/src/main.rs @@ -1,6 +1,6 @@ mod cli; -use bb_imager::DownloadFlashingStatus; +use bb_imager::{DownloadFlashingStatus, SelectedImage}; use clap::{CommandFactory, Parser}; use cli::{Commands, DestinationsTarget, Opt, TargetCommands}; use std::{ffi::CString, path::PathBuf}; @@ -107,7 +107,7 @@ async fn flash(target: TargetCommands, quite: bool) { } => { let customization = bb_imager::flasher::FlashingBcfConfig { verify: !no_verify }; bb_imager::FlashingConfig::BeagleConnectFreedom { - img: img.into(), + img: SelectedImage::Local(img), port: dst, customization, } @@ -136,18 +136,18 @@ async fn flash(target: TargetCommands, quite: bool) { .update_wifi(wifi); bb_imager::FlashingConfig::LinuxSd { - img: img.into(), + img: SelectedImage::Local(img), dst, customization, } } TargetCommands::Msp430 { img, dst } => bb_imager::FlashingConfig::Msp430 { - img: img.into(), + img: SelectedImage::Local(img), port: CString::new(dst).expect("Failed to parse destination"), }, #[cfg(feature = "pb2_mspm0")] TargetCommands::Pb2Mspm0 { no_eeprom, img } => bb_imager::FlashingConfig::Pb2Mspm0 { - img: img.into(), + img: SelectedImage::Local(img), persist_eeprom: !no_eeprom, }, }; @@ -296,16 +296,3 @@ impl From<DestinationsTarget> for bb_imager::Flasher { } } } - -impl From<cli::SelectedImage> for bb_imager::SelectedImage { - fn from(value: cli::SelectedImage) -> Self { - match (value.img.img_local, value.img.img_remote, value.img_sha256) { - (Some(p), None, None) => Self::local(p), - (None, Some(u), Some(c)) => { - let sha = const_hex::decode_to_array(c).expect("Invalid SHA256"); - Self::remote(String::new(), u, sha) - } - _ => unreachable!(), - } - } -}