Skip to content

Commit 5214d64

Browse files
committed
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.
1 parent 53c6f8a commit 5214d64

File tree

6 files changed

+31
-23
lines changed

6 files changed

+31
-23
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "humility"
1717
#
1818
# Be sure to check in and push all of the files that change. Happy versioning!
1919
#
20-
version = "0.11.11"
20+
version = "0.11.12"
2121
authors = ["Bryan Cantrill <[email protected]>"]
2222
edition = "2018"
2323
license = "MPL-2.0"

cmd/flash/src/lib.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ fn force_openocd(
121121
};
122122

123123
let payload = match &config.program {
124-
FlashProgram::OpenOcd(payload) => payload,
125-
_ => {
124+
Some(FlashProgram::OpenOcd(payload)) => payload,
125+
Some(other) => {
126126
bail!(
127127
"cannot force OpenOCD for non-OpenOCD \
128-
flash configuration: {:?}",
129-
config.program
128+
flash configuration: {other:?}",
129+
);
130+
}
131+
None => {
132+
bail!(
133+
"cannot force OpenOCD, this archive was \
134+
built after support was removed"
130135
);
131136
}
132137
};

humility-core/src/hubris.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const OXIDE_NT_HUBRIS_ARCHIVE: u32 = OXIDE_NT_BASE + 1;
4040
const OXIDE_NT_HUBRIS_REGISTERS: u32 = OXIDE_NT_BASE + 2;
4141
const OXIDE_NT_HUBRIS_TASK: u32 = OXIDE_NT_BASE + 3;
4242

43-
const MAX_HUBRIS_VERSION: u32 = 8;
43+
const MAX_HUBRIS_VERSION: u32 = 9;
4444

4545
#[derive(Default, Debug, Serialize)]
4646
pub struct HubrisManifest {
@@ -498,8 +498,12 @@ pub enum FlashArgument {
498498

499499
#[derive(Debug, Deserialize)]
500500
pub struct HubrisFlashMeta {
501-
pub program: FlashProgram,
501+
/// Legacy flash program. Not included in new archives.
502+
pub program: Option<FlashProgram>,
503+
/// Arguments for legacy flash program, or empty if not used.
504+
#[serde(default)]
502505
pub args: Vec<FlashArgument>,
506+
/// Chip name used by probe-rs.
503507
pub chip: Option<String>,
504508
}
505509

@@ -1548,25 +1552,20 @@ impl HubrisArchive {
15481552
}};
15491553
}
15501554

1551-
let mut flash = String::new();
1552-
1553-
archive
1554-
.by_name("img/flash.ron")
1555-
.map_err(|_| {
1556-
anyhow!(
1555+
let flash_ron = archive.by_name("img/flash.ron").map_err(|_| {
1556+
anyhow!(
15571557
"could not find img/flash.ron in archive; \
15581558
does archive pre-date addition of flash information?"
15591559
)
1560-
})?
1561-
.read_to_string(&mut flash)?;
1560+
})?;
15621561

1563-
let config: HubrisFlashMeta = ron::from_str(&flash)?;
1562+
let config: HubrisFlashMeta = ron::de::from_reader(flash_ron)?;
15641563

15651564
// This is incredibly ugly! It also gives us backwards compatibility!
15661565
let chip: Option<String> = match config.chip {
15671566
Some(ref chip) => Some(chip.to_string()),
15681567
None => match &config.program {
1569-
FlashProgram::PyOcd(args) => {
1568+
Some(FlashProgram::PyOcd(args)) => {
15701569
let s69 = regex::Regex::new(r"lpc55s69").unwrap();
15711570
let s28 = regex::Regex::new(r"lpc55s28").unwrap();
15721571
let mut c: Option<String> = None;
@@ -1589,7 +1588,7 @@ impl HubrisArchive {
15891588
}
15901589
c
15911590
}
1592-
FlashProgram::OpenOcd(ref a) => match a {
1591+
Some(FlashProgram::OpenOcd(ref a)) => match a {
15931592
FlashProgramConfig::Payload(d) => {
15941593
let h7 =
15951594
regex::Regex::new(r"find target/stm32h7").unwrap();
@@ -1624,6 +1623,10 @@ impl HubrisArchive {
16241623
}
16251624
_ => bail!("Unexpected config?"),
16261625
},
1626+
None => {
1627+
bail!("archive flash.ron is missing both probe-rs chip \
1628+
name and legacy flash config");
1629+
}
16271630
},
16281631
};
16291632

tests/cmd/chip.trycmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For more information try --help
1313

1414
```
1515
$ humility --chip this-can-be-anything -V
16-
humility 0.11.11
16+
humility 0.11.12
1717

1818
```
1919

@@ -28,7 +28,7 @@ For more information try --help
2828

2929
```
3030
$ humility -c apx432 -V
31-
humility 0.11.11
31+
humility 0.11.12
3232

3333
```
3434

tests/cmd/version.trycmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ Long version flag:
22

33
```
44
$ humility --version
5-
humility 0.11.11
5+
humility 0.11.12
66

77
```
88

99
Short version flag:
1010

1111
```
1212
$ humility -V
13-
humility 0.11.11
13+
humility 0.11.12
1414

1515
```

0 commit comments

Comments
 (0)