|
2 | 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | // file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
4 | 4 |
|
| 5 | +use anyhow::Context as _; |
5 | 6 | use serde::Serialize;
|
6 | 7 | use std::path::Path;
|
7 | 8 |
|
| 9 | +use crate::config::BoardConfig; |
| 10 | + |
8 | 11 | #[derive(Debug, Serialize, Default)]
|
9 | 12 | pub struct FlashConfig {
|
10 | 13 | /// The name used by probe-rs to identify the chip.
|
11 | 14 | chip: Option<String>,
|
12 | 15 | }
|
13 | 16 |
|
14 |
| -impl FlashConfig { |
15 |
| - // |
16 |
| - // Set the chip |
17 |
| - // |
18 |
| - fn set_chip(&mut self, val: &str) -> &mut Self { |
19 |
| - self.chip = Some(val.to_string()); |
20 |
| - self |
21 |
| - } |
22 |
| -} |
23 |
| - |
24 | 17 | pub fn config(
|
25 | 18 | board: &str,
|
26 |
| - _chip_dir: &Path, |
27 |
| -) -> anyhow::Result<Option<FlashConfig>> { |
28 |
| - let mut flash = FlashConfig::default(); |
29 |
| - |
30 |
| - flash.set_chip(chip_name(board)?); |
31 |
| - |
32 |
| - Ok(Some(flash)) |
| 19 | +) -> anyhow::Result<FlashConfig> { |
| 20 | + Ok(FlashConfig { |
| 21 | + chip: chip_name(board)?, |
| 22 | + }) |
33 | 23 | }
|
34 | 24 |
|
35 |
| -pub fn chip_name(board: &str) -> anyhow::Result<&'static str> { |
36 |
| - let b = match board { |
37 |
| - "lpcxpresso55s69" |
38 |
| - | "rot-carrier-2" |
39 |
| - | "oxide-rot-1" |
40 |
| - | "oxide-rot-1-selfsigned" => "LPC55S69JBD100", |
41 |
| - "rot-carrier-1" => "LPC55S28JBD100", |
42 |
| - "stm32f3-discovery" => "STM32F303VCTx", |
43 |
| - "stm32f4-discovery" => "STM32F407VGTx", |
44 |
| - "nucleo-h743zi2" => "STM32H743ZITx", |
45 |
| - "nucleo-h753zi" => "STM32H753ZITx", |
46 |
| - "gemini-bu-1" | "gimletlet-1" | "gimletlet-2" | "gimlet-b" |
47 |
| - | "gimlet-c" | "gimlet-d" | "gimlet-e" | "gimlet-f" | "psc-a" |
48 |
| - | "psc-b" | "psc-c" | "sidecar-b" | "sidecar-c" | "sidecar-d" |
49 |
| - | "medusa-a" | "grapefruit" => "STM32H753ZITx", |
50 |
| - "donglet-g030" => "STM32G030F6Px", |
51 |
| - "donglet-g031" => "STM32G031F8Px", |
52 |
| - "stm32g031-nucleo" => "STM32G031Y8Yx", |
53 |
| - "oxcon2023g0" => "STM32G030J6Mx", |
54 |
| - "stm32g070-nucleo" => "STM32G070KBTx", |
55 |
| - "stm32g0b1-nucleo" => anyhow::bail!( |
56 |
| - "This board is not yet supported by probe-rs, \ |
57 |
| - please use OpenOCD directly" |
58 |
| - ), |
59 |
| - _ => anyhow::bail!("unrecognized board {}", board), |
60 |
| - }; |
61 |
| - |
62 |
| - Ok(b) |
| 25 | +pub fn chip_name(board: &str) -> anyhow::Result<Option<String>> { |
| 26 | + let board_config_path = Path::new("boards") |
| 27 | + .join(format!("{board}.toml")); |
| 28 | + |
| 29 | + let board_config_text = std::fs::read_to_string(&board_config_path) |
| 30 | + .with_context(|| { |
| 31 | + format!("can't access board config at: {}", board_config_path.display()) |
| 32 | + })?; |
| 33 | + |
| 34 | + let board_config: BoardConfig = toml::from_str(&board_config_text) |
| 35 | + .with_context(|| { |
| 36 | + format!("can't parse board config at: {}", board_config_path.display()) |
| 37 | + })?; |
| 38 | + |
| 39 | + if let Some(probe_rs) = &board_config.probe_rs { |
| 40 | + Ok(Some(probe_rs.chip_name.clone())) |
| 41 | + } else { |
| 42 | + // tolerate the section missing for new chips, but we can't provide a |
| 43 | + // chip name in this case. |
| 44 | + Ok(None) |
| 45 | + } |
63 | 46 | }
|
0 commit comments