Skip to content

Commit 9cb62cf

Browse files
committed
archive version 9: now without openocd/pyocd flashing
Humility has historically had support for a --force-openocd flag on the flash subcommand, as a hedge against probe-rs having bugs or limited chip support. In practice, as far as I can tell, we never use it. This support required one of the three giant merge-conflict-prone match statements on which I declared war in #1886. The second such match statement was providing similar support for PyOCD, which Humility appears to have never actually implemented! So this change removes both. Archives built at or after this change can only be flashed (by Humility) using probe-rs. One giant scary match statement remains, but it's in my sights. I have left the openocd.cfg file in the archive because it's useful for debugging, even if we don't use it for _flashing._ (My workflow if I need gdb is typically to flash with Humility via probe-rs, and _then_ fire up openocd.) I've bumped the archive version here so that using such an archive with an older Humility gets you a cogent error. (Otherwise, you get a weird crash about loading flash.ron, no matter what you're trying to do.) Note that this requires a corresponding change in Humility, both to tolerate the absence of the removed fields, and to handle the new archive version. oxidecomputer/humility#514
1 parent ff04d42 commit 9cb62cf

File tree

2 files changed

+7
-182
lines changed

2 files changed

+7
-182
lines changed

build/xtask/src/dist.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub const DEFAULT_KERNEL_STACK: u32 = 1024;
4242
/// that generates the Humility binary necessary for Hubris's CI has run.
4343
/// Once that binary is in place, you should be able to bump this version
4444
/// without breaking CI.
45-
const HUBRIS_ARCHIVE_VERSION: u32 = 8;
45+
const HUBRIS_ARCHIVE_VERSION: u32 = 9;
4646

4747
/// `PackageConfig` contains a bundle of data that's commonly used when
4848
/// building a full app image, grouped together to avoid passing a bunch
@@ -872,10 +872,9 @@ fn build_archive(
872872
// any external configuration files, serialize it, and add it to the
873873
// archive.
874874
//
875-
if let Some(mut config) =
875+
if let Some(config) =
876876
crate::flash::config(cfg.toml.board.as_str(), &chip_dir)?
877877
{
878-
config.flatten()?;
879878
archive.text(
880879
img_dir.join("flash.ron"),
881880
ron::ser::to_string_pretty(

build/xtask/src/flash.rs

+5-179
Original file line numberDiff line numberDiff line change
@@ -3,203 +3,29 @@
33
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

55
use serde::Serialize;
6-
use std::path::{Path, PathBuf};
6+
use std::path::Path;
77

8-
//
9-
// We allow for enough information to be put in the archive for the image to
10-
// be flashed based only on the archive (e.g., by Humility). Because flashing
11-
// is itself a bit of a mess (requiring different programs for different
12-
// targets), this is a bit gritty (e.g., any required external configuration
13-
// files must themselves put in the archive). If these structures need to
14-
// change, be sure to make corresponding changes to Humility.
15-
//
16-
#[derive(Debug, Serialize)]
17-
pub enum FlashProgram {
18-
PyOcd(Vec<FlashArgument>),
19-
OpenOcd(FlashProgramConfig),
20-
}
21-
22-
//
23-
// Enum describing flash programs configuration (e.g., "openocd.cfg" for
24-
// OpenOCD), either as a path in the file system or with the entire contents.
25-
//
26-
#[derive(Debug, Serialize)]
27-
pub enum FlashProgramConfig {
28-
Path(PathBuf),
29-
Payload(String),
30-
}
31-
32-
//
33-
// An enum describing a single command-line argument to the flash program.
34-
//
35-
#[derive(Debug, Serialize)]
36-
pub enum FlashArgument {
37-
// A direct string
38-
Direct(String),
39-
40-
// The filesystem path of the binary flash payload itself
41-
Payload,
42-
43-
// A single argument consisting of a prefix and a suffix. When the
44-
// argument is processed, a single argument should be generated consisting
45-
// of the prefix, the path of the flash, and the suffix, all joined by
46-
// spaces.
47-
FormattedPayload(String, String),
48-
49-
// The filesystem path of the flash program configuration
50-
Config,
51-
}
52-
53-
#[derive(Debug, Serialize)]
8+
#[derive(Debug, Serialize, Default)]
549
pub struct FlashConfig {
10+
/// The name used by probe-rs to identify the chip.
5511
chip: Option<String>,
56-
program: FlashProgram,
57-
args: Vec<FlashArgument>,
58-
}
59-
60-
impl FlashProgramConfig {
61-
fn new(path: PathBuf) -> Self {
62-
FlashProgramConfig::Path(path)
63-
}
6412
}
6513

6614
impl FlashConfig {
67-
fn new(program: FlashProgram) -> Self {
68-
FlashConfig {
69-
chip: None,
70-
program,
71-
args: vec![],
72-
}
73-
}
74-
75-
//
76-
// Add a command-line argument to the flash program
77-
//
78-
fn arg<'a>(&'a mut self, val: &str) -> &'a mut Self {
79-
self.args.push(FlashArgument::Direct(val.to_string()));
80-
self
81-
}
82-
8315
//
8416
// Set the chip
8517
//
8618
fn set_chip(&mut self, val: &str) -> &mut Self {
8719
self.chip = Some(val.to_string());
8820
self
8921
}
90-
91-
//
92-
// Add the path to the payload as an argument to the flash program
93-
//
94-
fn payload(&mut self) -> &mut Self {
95-
self.args.push(FlashArgument::Payload);
96-
self
97-
}
98-
99-
//
100-
// Add a formatted payload as a single argument to the flash program. The
101-
// argument will consists of the specified prefix, followed by the path to
102-
// the payload, followed by the specified suffix.
103-
//
104-
fn formatted_payload<'a>(
105-
&'a mut self,
106-
prefix: &str,
107-
suffix: &str,
108-
) -> &'a mut Self {
109-
self.args.push(FlashArgument::FormattedPayload(
110-
prefix.to_string(),
111-
suffix.to_string(),
112-
));
113-
self
114-
}
115-
116-
//
117-
// Add a flasher configuration file as an argument to the flash program
118-
//
119-
fn config(&mut self) -> &mut Self {
120-
self.args.push(FlashArgument::Config);
121-
self
122-
}
123-
124-
//
125-
// Slurp in any flash program configuration file and flatten it into
126-
// our overall configuration
127-
//
128-
pub fn flatten(&mut self) -> anyhow::Result<()> {
129-
if let FlashProgram::OpenOcd(FlashProgramConfig::Path(path)) =
130-
&self.program
131-
{
132-
let p: PathBuf = path.iter().collect();
133-
let text = std::fs::read_to_string(p)?;
134-
self.program =
135-
FlashProgram::OpenOcd(FlashProgramConfig::Payload(text));
136-
}
137-
138-
Ok(())
139-
}
14022
}
14123

14224
pub fn config(
14325
board: &str,
144-
chip_dir: &Path,
26+
_chip_dir: &Path,
14527
) -> anyhow::Result<Option<FlashConfig>> {
146-
let mut flash = match board {
147-
"lpcxpresso55s69"
148-
| "rot-carrier-1"
149-
| "rot-carrier-2"
150-
| "oxide-rot-1"
151-
| "oxide-rot-1-selfsigned" => {
152-
let chip = if board == "rot-carrier-1" {
153-
"lpc55s28"
154-
} else {
155-
"lpc55s69"
156-
};
157-
158-
let mut args = vec![];
159-
160-
for arg in ["reset", "-t", chip].iter() {
161-
args.push(FlashArgument::Direct(arg.to_string()));
162-
}
163-
164-
let mut flash = FlashConfig::new(FlashProgram::PyOcd(args));
165-
166-
flash
167-
.arg("flash")
168-
.arg("-t")
169-
.arg(chip)
170-
.arg("--format")
171-
.arg("hex")
172-
.payload();
173-
174-
flash
175-
}
176-
177-
"stm32f3-discovery" | "stm32f4-discovery" | "nucleo-h743zi2"
178-
| "nucleo-h753zi" | "gemini-bu-1" | "gimletlet-1" | "gimletlet-2"
179-
| "gimlet-b" | "gimlet-c" | "gimlet-d" | "gimlet-e" | "gimlet-f"
180-
| "psc-b" | "psc-c" | "sidecar-b" | "sidecar-c" | "sidecar-d"
181-
| "stm32g031-nucleo" | "donglet-g030" | "donglet-g031"
182-
| "oxcon2023g0" | "stm32g070-nucleo" | "stm32g0b1-nucleo"
183-
| "medusa-a" | "grapefruit" => {
184-
let cfg = FlashProgramConfig::new(chip_dir.join("openocd.cfg"));
185-
186-
let mut flash = FlashConfig::new(FlashProgram::OpenOcd(cfg));
187-
188-
flash
189-
.arg("-f")
190-
.config()
191-
.arg("-c")
192-
.formatted_payload("program", "verify reset")
193-
.arg("-c")
194-
.arg("exit");
195-
196-
flash
197-
}
198-
_ => {
199-
eprintln!("Warning: unrecognized board, won't know how to flash.");
200-
return Ok(None);
201-
}
202-
};
28+
let mut flash = FlashConfig::default();
20329

20430
flash.set_chip(chip_name(board)?);
20531

0 commit comments

Comments
 (0)