Skip to content

Commit 6c08eda

Browse files
committed
reviews
1 parent dd0a7a1 commit 6c08eda

File tree

5 files changed

+71
-27
lines changed

5 files changed

+71
-27
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ env_logger = "0.11.8"
1111
log = "0.4.27"
1212
serde = { version = "1.0.217", features = ["derive"] }
1313
serde_yaml = "0.9.34"
14-
libc = "0.2.152"

xtask/src/efuse_generator.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,39 @@ use std::{
88
process::Command,
99
};
1010

11-
use clap::Args;
11+
use clap::{Args, Parser};
1212

13-
use crate::Result;
13+
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
14+
15+
// ----------------------------------------------------------------------------
16+
// Command-line Interface
17+
18+
#[derive(Debug, Parser)]
19+
enum Cli {
20+
/// Generate eFuse field definitions
21+
GenerateEfuseFields(GenerateEfuseFieldsArgs),
22+
}
1423

1524
#[derive(Debug, Args)]
16-
pub struct GenerateEfuseFieldsArgs {
25+
pub(crate) struct GenerateEfuseFieldsArgs {
1726
/// Local path to the `esptool` repository
18-
pub esptool_path: PathBuf,
27+
esptool_path: PathBuf,
1928
}
2029

30+
const HEADER: &str = r#"
31+
//! eFuse field definitions for the $CHIP
32+
//!
33+
//! This file was automatically generated, please do not edit it manually!
34+
//!
35+
//! Generated: $DATE
36+
//! Version: $VERSION
37+
38+
#![allow(unused)]
39+
40+
use super::EfuseField;
41+
42+
"#;
43+
2144
type EfuseFields = HashMap<String, EfuseYaml>;
2245

2346
#[derive(Debug, serde::Deserialize)]
@@ -61,19 +84,7 @@ impl Ord for EfuseAttrs {
6184
}
6285
}
6386

64-
const HEADER: &str = r#"
65-
//! This file was automatically generated, please do not edit it manually!
66-
//!
67-
//! Generated: $DATE
68-
//! Version: $VERSION
69-
70-
#![allow(unused)]
71-
72-
use super::EfuseField;
73-
74-
"#;
75-
76-
pub fn generate_efuse_fields(workspace: &Path, args: GenerateEfuseFieldsArgs) -> Result<()> {
87+
pub(crate) fn generate_efuse_fields(workspace: &Path, args: GenerateEfuseFieldsArgs) -> Result<()> {
7788
let efuse_yaml_path = args
7889
.esptool_path
7990
.join("espefuse")
@@ -98,7 +109,8 @@ fn parse_efuse_fields(efuse_yaml_path: &Path) -> Result<EfuseFields> {
98109
// TODO: We can probably handle this better, e.g. by defining a `Chip` enum
99110
// which can be iterated over, but for now this is good enough.
100111
const CHIPS: &[&str] = &[
101-
"esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4", "esp32s2", "esp32s3",
112+
"esp32", "esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32h2", "esp32p4", "esp32s2",
113+
"esp32s3",
102114
];
103115

104116
let mut efuse_fields = EfuseFields::new();
@@ -131,12 +143,11 @@ fn process_efuse_definitions(efuse_fields: &mut EfuseFields) -> Result<()> {
131143
let mac_attrs = yaml.fields.get("MAC").unwrap();
132144

133145
let mut mac0_attrs = mac_attrs.clone();
134-
mac0_attrs.start = 0;
135146
mac0_attrs.len = 32;
136147

137148
let mut mac1_attrs = mac_attrs.clone();
138-
mac1_attrs.word += 1;
139-
mac1_attrs.start = 32;
149+
mac1_attrs.start = mac0_attrs.start + 32;
150+
mac1_attrs.word = mac1_attrs.start / 32;
140151
mac1_attrs.len = 16;
141152

142153
yaml.fields.remove("MAC").unwrap();
@@ -158,7 +169,7 @@ fn process_efuse_definitions(efuse_fields: &mut EfuseFields) -> Result<()> {
158169
fn generate_efuse_definitions(espflash_path: &Path, efuse_fields: EfuseFields) -> Result<()> {
159170
let targets_efuse_path = espflash_path
160171
.join("src")
161-
.join("targets")
172+
.join("target")
162173
.join("efuse")
163174
.canonicalize()?;
164175

@@ -175,6 +186,7 @@ fn generate_efuse_definitions(espflash_path: &Path, efuse_fields: EfuseFields) -
175186
writer,
176187
"{}",
177188
HEADER
189+
.replace("$CHIP", &chip)
178190
.replace(
179191
"$DATE",
180192
&chrono::Utc::now().format("%Y-%m-%d %H:%M").to_string()
@@ -239,10 +251,12 @@ fn generate_efuse_constants(
239251
description,
240252
} = attrs;
241253

254+
let description = description.replace('[', "\\[").replace(']', "\\]");
255+
242256
writeln!(writer, "/// {description}")?;
243257
writeln!(
244258
writer,
245-
"pub(crate) const {name}: EfuseField = EfuseField::new({block}, {word}, {start}, {len});",
259+
"pub const {name}: EfuseField = EfuseField::new({block}, {word}, {start}, {len});"
246260
)?;
247261
}
248262

xtask/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum Cli {
1717
/// Generate eFuse field definitions
1818
GenerateEfuseFields(efuse_generator::GenerateEfuseFieldsArgs),
1919

20-
/// Run espflash tests (replacing bash scripts)
20+
/// Run espflash tests
2121
RunTests(test_runner::RunTestsArgs),
2222
}
2323

xtask/src/test_runner.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{
1313
};
1414

1515
use clap::Args;
16+
use log::info;
1617

1718
use crate::Result;
1819

@@ -193,7 +194,38 @@ impl TestRunner {
193194
}
194195

195196
fn create_espflash_command(&self, args: &[&str]) -> Command {
196-
let mut cmd = Command::new("espflash");
197+
let debug_path = PathBuf::from("target/debug/espflash");
198+
let release_path = PathBuf::from("target/release/espflash");
199+
200+
// Determine which binary to use
201+
let espflash_path = if release_path.exists() {
202+
release_path
203+
} else if debug_path.exists() {
204+
debug_path
205+
} else {
206+
// Neither exists — build release
207+
info!("espflash binary not found, building in release mode...");
208+
let status = Command::new("cargo")
209+
.args(["build", "--release", "-p", "espflash"])
210+
.stdout(Stdio::inherit())
211+
.stderr(Stdio::inherit())
212+
.status()
213+
.expect("Failed to run cargo build for espflash");
214+
215+
if !status.success() {
216+
panic!("Failed to build espflash (release)");
217+
}
218+
219+
// Confirm it was built
220+
if release_path.exists() {
221+
release_path
222+
} else {
223+
panic!("espflash binary still not found after build");
224+
}
225+
};
226+
227+
// Create the command
228+
let mut cmd = Command::new(espflash_path);
197229
cmd.args(args);
198230
cmd
199231
}

0 commit comments

Comments
 (0)