Skip to content

Commit cba8d14

Browse files
committed
draft CLI args
This is based on the output of `me_cleaner -h`. Signed-off-by: Daniel Maslowski <[email protected]>
1 parent 5db09f4 commit cba8d14

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

src/main.rs

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
1-
use clap::{Parser, Subcommand};
1+
use clap::{Parser, Subcommand, ValueEnum};
22

3-
use log::info;
3+
use log::{debug, error, info, trace, warn};
4+
5+
#[derive(Clone, Copy, Debug, ValueEnum)]
6+
enum Partition {
7+
MFS,
8+
}
49

510
#[derive(Subcommand, Debug)]
611
enum MeCommand {
712
/// Clean up (CS)ME partitions and related platform features
813
Clean {
14+
/// File to write output to (cleaned image)
15+
#[clap(long, short = 'O')]
16+
output: Option<String>,
17+
/// Set MeAltDisable or HAP bit in addition (requires a full image)
18+
#[clap(long, short = 'S')]
19+
soft_disable: bool,
20+
/// Set MeAltDisable or HAP bit, nothing else (requires a full image)
21+
#[clap(long, short)]
22+
soft_disable_only: bool,
23+
/// Relocate FTPR partition to top of ME region
24+
#[clap(long, short)]
25+
relocate: bool,
26+
/// Truncuate empty part of the fimrware image
27+
#[clap(long, short)]
28+
truncate: bool,
29+
/// Retain FTPR modules even if they could be removed
30+
#[clap(long, short)]
31+
keep_modules: bool,
32+
/// Comma separated list of partitions to keep unconditionally
33+
#[clap(short, long, value_delimiter = ',')]
34+
whitelist: Option<Vec<Partition>>,
35+
/// Comma separated list of partitions to remove unconditionally
36+
#[clap(short, long, value_delimiter = ',')]
37+
blacklist: Option<Vec<Partition>>,
38+
/// Remove ME/TXE write permissions on other flash regions (requires a full image)
39+
#[clap(long, short)]
40+
descriptor: bool,
41+
/// Extract flash descriptor to a file, adjusting regions when used with truncate (requires a full image)
42+
#[clap(long, short = 'D')]
43+
extract_descriptor: Option<String>,
44+
/// Extract ME region to a file if given a full image
45+
#[clap(long, short = 'M')]
46+
extract_me: Option<String>,
947
/// File to read
1048
file_name: String,
1149
},
@@ -45,16 +83,56 @@ struct Cli {
4583
}
4684

4785
fn main() {
86+
println!("Intel Firmware Tool 🔧");
4887
// Default to log level "info". Otherwise, you get no "regular" logs.
4988
let env = env_logger::Env::default().default_filter_or("info");
5089
env_logger::Builder::from_env(env).init();
51-
info!("Intel Firmware Tool");
5290

5391
let Cli { cmd, verbose: _ } = Cli::parse();
5492
match cmd {
5593
Command::Bg(_) => todo!(),
5694
Command::Me(cmd) => match cmd {
57-
MeCommand::Clean { file_name } => todo!("clean {file_name}"),
95+
MeCommand::Clean {
96+
descriptor,
97+
keep_modules,
98+
relocate,
99+
soft_disable,
100+
soft_disable_only,
101+
truncate,
102+
whitelist,
103+
blacklist,
104+
file_name,
105+
output,
106+
extract_descriptor,
107+
extract_me,
108+
} => {
109+
debug!("Configuration:");
110+
debug!(" Adjust flash descriptor: {descriptor}");
111+
debug!(" Retain FTPR modules: {keep_modules}");
112+
debug!(" Relocate FTPR partition: {relocate}");
113+
debug!(" Truncate empty parts: {truncate}");
114+
let disable_me = soft_disable || soft_disable_only;
115+
debug!(" Soft disable ME: {disable_me}");
116+
debug!("");
117+
if let Some(allowlist) = whitelist {
118+
debug!("Allowlist: {allowlist:?}");
119+
}
120+
if let Some(blocklist) = blacklist {
121+
debug!("Blocklist: {blocklist:?}");
122+
}
123+
debug!("");
124+
if let Some(descriptor_file) = extract_descriptor {
125+
info!("Dump flash descriptor to {descriptor_file}");
126+
}
127+
if let Some(me_file) = extract_me {
128+
info!("Dump ME region to {me_file}");
129+
}
130+
if let Some(out_file) = output {
131+
info!("Output will be written to: {out_file}");
132+
}
133+
info!("Reading {file_name}...");
134+
todo!("clean");
135+
}
58136
MeCommand::Show { file_name } => todo!("show {file_name}"),
59137
},
60138
}

0 commit comments

Comments
 (0)