From d5cfc9b6e7fed8022d0303025b71f6c723d05e07 Mon Sep 17 00:00:00 2001 From: "Cliff L. Biffle" Date: Thu, 10 Oct 2024 11:07:38 -0700 Subject: [PATCH] Make OpenOCD/PyOCD flash config optional in archive. The support for forcing flashing with openocd winds up producing a bunch of extra support code in the build system, for a feature we basically never use anymore. The support for PyOCD has, apparently, never been finished, and does not work. So I'm hoping to remove them from the Hubris build system, but the first step toward that is teaching Humility to behave gracefully if they're omitted from the img/flash.ron file. This change makes the fields optional, and Humility now only requires their presence if the user explicitly asks for the old --force-openocd switch. --- Cargo.lock | 2 +- Cargo.toml | 2 +- cmd/flash/src/lib.rs | 13 +++++++++---- humility-core/src/hubris.rs | 29 ++++++++++++++++------------- tests/cmd/chip.trycmd | 4 ++-- tests/cmd/version.trycmd | 4 ++-- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82dbff4ee..56799c26c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1249,7 +1249,7 @@ dependencies = [ [[package]] name = "humility" -version = "0.11.11" +version = "0.11.12" dependencies = [ "anyhow", "bitfield", diff --git a/Cargo.toml b/Cargo.toml index fb74ef0a5..890b4db79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ name = "humility" # # Be sure to check in and push all of the files that change. Happy versioning! # -version = "0.11.11" +version = "0.11.12" authors = ["Bryan Cantrill "] edition = "2018" license = "MPL-2.0" diff --git a/cmd/flash/src/lib.rs b/cmd/flash/src/lib.rs index 1cb133d79..9ec815c9b 100644 --- a/cmd/flash/src/lib.rs +++ b/cmd/flash/src/lib.rs @@ -121,12 +121,17 @@ fn force_openocd( }; let payload = match &config.program { - FlashProgram::OpenOcd(payload) => payload, - _ => { + Some(FlashProgram::OpenOcd(payload)) => payload, + Some(other) => { bail!( "cannot force OpenOCD for non-OpenOCD \ - flash configuration: {:?}", - config.program + flash configuration: {other:?}", + ); + } + None => { + bail!( + "cannot force OpenOCD, this archive was \ + built after support was removed" ); } }; diff --git a/humility-core/src/hubris.rs b/humility-core/src/hubris.rs index 3cd0a88a5..4a64ed102 100644 --- a/humility-core/src/hubris.rs +++ b/humility-core/src/hubris.rs @@ -40,7 +40,7 @@ const OXIDE_NT_HUBRIS_ARCHIVE: u32 = OXIDE_NT_BASE + 1; const OXIDE_NT_HUBRIS_REGISTERS: u32 = OXIDE_NT_BASE + 2; const OXIDE_NT_HUBRIS_TASK: u32 = OXIDE_NT_BASE + 3; -const MAX_HUBRIS_VERSION: u32 = 8; +const MAX_HUBRIS_VERSION: u32 = 9; #[derive(Default, Debug, Serialize)] pub struct HubrisManifest { @@ -498,8 +498,12 @@ pub enum FlashArgument { #[derive(Debug, Deserialize)] pub struct HubrisFlashMeta { - pub program: FlashProgram, + /// Legacy flash program. Not included in new archives. + pub program: Option, + /// Arguments for legacy flash program, or empty if not used. + #[serde(default)] pub args: Vec, + /// Chip name used by probe-rs. pub chip: Option, } @@ -1548,25 +1552,20 @@ impl HubrisArchive { }}; } - let mut flash = String::new(); - - archive - .by_name("img/flash.ron") - .map_err(|_| { - anyhow!( + let flash_ron = archive.by_name("img/flash.ron").map_err(|_| { + anyhow!( "could not find img/flash.ron in archive; \ does archive pre-date addition of flash information?" ) - })? - .read_to_string(&mut flash)?; + })?; - let config: HubrisFlashMeta = ron::from_str(&flash)?; + let config: HubrisFlashMeta = ron::de::from_reader(flash_ron)?; // This is incredibly ugly! It also gives us backwards compatibility! let chip: Option = match config.chip { Some(ref chip) => Some(chip.to_string()), None => match &config.program { - FlashProgram::PyOcd(args) => { + Some(FlashProgram::PyOcd(args)) => { let s69 = regex::Regex::new(r"lpc55s69").unwrap(); let s28 = regex::Regex::new(r"lpc55s28").unwrap(); let mut c: Option = None; @@ -1589,7 +1588,7 @@ impl HubrisArchive { } c } - FlashProgram::OpenOcd(ref a) => match a { + Some(FlashProgram::OpenOcd(ref a)) => match a { FlashProgramConfig::Payload(d) => { let h7 = regex::Regex::new(r"find target/stm32h7").unwrap(); @@ -1624,6 +1623,10 @@ impl HubrisArchive { } _ => bail!("Unexpected config?"), }, + None => { + bail!("archive flash.ron is missing both probe-rs chip \ + name and legacy flash config"); + } }, }; diff --git a/tests/cmd/chip.trycmd b/tests/cmd/chip.trycmd index 5704a7c8d..7596ca8f2 100644 --- a/tests/cmd/chip.trycmd +++ b/tests/cmd/chip.trycmd @@ -13,7 +13,7 @@ For more information try --help ``` $ humility --chip this-can-be-anything -V -humility 0.11.11 +humility 0.11.12 ``` @@ -28,7 +28,7 @@ For more information try --help ``` $ humility -c apx432 -V -humility 0.11.11 +humility 0.11.12 ``` diff --git a/tests/cmd/version.trycmd b/tests/cmd/version.trycmd index 662cea2fa..a5a5e4e0c 100644 --- a/tests/cmd/version.trycmd +++ b/tests/cmd/version.trycmd @@ -2,7 +2,7 @@ Long version flag: ``` $ humility --version -humility 0.11.11 +humility 0.11.12 ``` @@ -10,6 +10,6 @@ Short version flag: ``` $ humility -V -humility 0.11.11 +humility 0.11.12 ```