@@ -8,16 +8,39 @@ use std::{
8
8
process:: Command ,
9
9
} ;
10
10
11
- use clap:: Args ;
11
+ use clap:: { Args , Parser } ;
12
12
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
+ }
14
23
15
24
#[ derive( Debug , Args ) ]
16
- pub struct GenerateEfuseFieldsArgs {
25
+ pub ( crate ) struct GenerateEfuseFieldsArgs {
17
26
/// Local path to the `esptool` repository
18
- pub esptool_path : PathBuf ,
27
+ esptool_path : PathBuf ,
19
28
}
20
29
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
+
21
44
type EfuseFields = HashMap < String , EfuseYaml > ;
22
45
23
46
#[ derive( Debug , serde:: Deserialize ) ]
@@ -61,19 +84,7 @@ impl Ord for EfuseAttrs {
61
84
}
62
85
}
63
86
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 < ( ) > {
77
88
let efuse_yaml_path = args
78
89
. esptool_path
79
90
. join ( "espefuse" )
@@ -98,7 +109,8 @@ fn parse_efuse_fields(efuse_yaml_path: &Path) -> Result<EfuseFields> {
98
109
// TODO: We can probably handle this better, e.g. by defining a `Chip` enum
99
110
// which can be iterated over, but for now this is good enough.
100
111
const CHIPS : & [ & str ] = & [
101
- "esp32" , "esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" , "esp32p4" , "esp32s2" , "esp32s3" ,
112
+ "esp32" , "esp32c2" , "esp32c3" , "esp32c5" , "esp32c6" , "esp32h2" , "esp32p4" , "esp32s2" ,
113
+ "esp32s3" ,
102
114
] ;
103
115
104
116
let mut efuse_fields = EfuseFields :: new ( ) ;
@@ -131,12 +143,11 @@ fn process_efuse_definitions(efuse_fields: &mut EfuseFields) -> Result<()> {
131
143
let mac_attrs = yaml. fields . get ( "MAC" ) . unwrap ( ) ;
132
144
133
145
let mut mac0_attrs = mac_attrs. clone ( ) ;
134
- mac0_attrs. start = 0 ;
135
146
mac0_attrs. len = 32 ;
136
147
137
148
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 ;
140
151
mac1_attrs. len = 16 ;
141
152
142
153
yaml. fields . remove ( "MAC" ) . unwrap ( ) ;
@@ -158,7 +169,7 @@ fn process_efuse_definitions(efuse_fields: &mut EfuseFields) -> Result<()> {
158
169
fn generate_efuse_definitions ( espflash_path : & Path , efuse_fields : EfuseFields ) -> Result < ( ) > {
159
170
let targets_efuse_path = espflash_path
160
171
. join ( "src" )
161
- . join ( "targets " )
172
+ . join ( "target " )
162
173
. join ( "efuse" )
163
174
. canonicalize ( ) ?;
164
175
@@ -175,6 +186,7 @@ fn generate_efuse_definitions(espflash_path: &Path, efuse_fields: EfuseFields) -
175
186
writer,
176
187
"{}" ,
177
188
HEADER
189
+ . replace( "$CHIP" , & chip)
178
190
. replace(
179
191
"$DATE" ,
180
192
& chrono:: Utc :: now( ) . format( "%Y-%m-%d %H:%M" ) . to_string( )
@@ -239,10 +251,12 @@ fn generate_efuse_constants(
239
251
description,
240
252
} = attrs;
241
253
254
+ let description = description. replace ( '[' , "\\ [" ) . replace ( ']' , "\\ ]" ) ;
255
+
242
256
writeln ! ( writer, "/// {description}" ) ?;
243
257
writeln ! (
244
258
writer,
245
- "pub(crate) const {name}: EfuseField = EfuseField::new({block}, {word}, {start}, {len});" ,
259
+ "pub const {name}: EfuseField = EfuseField::new({block}, {word}, {start}, {len});"
246
260
) ?;
247
261
}
248
262
0 commit comments