|
1 | | -use clap::{Parser, Subcommand}; |
| 1 | +use clap::{Parser, Subcommand, ValueEnum}; |
2 | 2 |
|
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 | +} |
4 | 9 |
|
5 | 10 | #[derive(Subcommand, Debug)] |
6 | 11 | enum MeCommand { |
7 | 12 | /// Clean up (CS)ME partitions and related platform features |
8 | 13 | 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>, |
9 | 47 | /// File to read |
10 | 48 | file_name: String, |
11 | 49 | }, |
@@ -45,16 +83,56 @@ struct Cli { |
45 | 83 | } |
46 | 84 |
|
47 | 85 | fn main() { |
| 86 | + println!("Intel Firmware Tool 🔧"); |
48 | 87 | // Default to log level "info". Otherwise, you get no "regular" logs. |
49 | 88 | let env = env_logger::Env::default().default_filter_or("info"); |
50 | 89 | env_logger::Builder::from_env(env).init(); |
51 | | - info!("Intel Firmware Tool"); |
52 | 90 |
|
53 | 91 | let Cli { cmd, verbose: _ } = Cli::parse(); |
54 | 92 | match cmd { |
55 | 93 | Command::Bg(_) => todo!(), |
56 | 94 | 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 | + } |
58 | 136 | MeCommand::Show { file_name } => todo!("show {file_name}"), |
59 | 137 | }, |
60 | 138 | } |
|
0 commit comments