Skip to content

Commit

Permalink
Make OpenOCD/PyOCD flash config optional in archive.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cbiffle committed Oct 11, 2024
1 parent 53c6f8a commit 5214d64
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
edition = "2018"
license = "MPL-2.0"
Expand Down
13 changes: 9 additions & 4 deletions cmd/flash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
};
Expand Down
29 changes: 16 additions & 13 deletions humility-core/src/hubris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<FlashProgram>,
/// Arguments for legacy flash program, or empty if not used.
#[serde(default)]
pub args: Vec<FlashArgument>,
/// Chip name used by probe-rs.
pub chip: Option<String>,
}

Expand Down Expand Up @@ -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<String> = 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<String> = None;
Expand All @@ -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();
Expand Down Expand Up @@ -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");
}
},
};

Expand Down
4 changes: 2 additions & 2 deletions tests/cmd/chip.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more information try --help

```
$ humility --chip this-can-be-anything -V
humility 0.11.11
humility 0.11.12

```

Expand All @@ -28,7 +28,7 @@ For more information try --help

```
$ humility -c apx432 -V
humility 0.11.11
humility 0.11.12

```

4 changes: 2 additions & 2 deletions tests/cmd/version.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Long version flag:

```
$ humility --version
humility 0.11.11
humility 0.11.12

```

Short version flag:

```
$ humility -V
humility 0.11.11
humility 0.11.12

```

0 comments on commit 5214d64

Please sign in to comment.