Skip to content

Commit c5dd07d

Browse files
committed
Add --feature readonly, to build a bin without risky commands
``` > cargo build --features readonly && sudo ./target/debug/framework_tool --dump-ec-flash ec.bin && ls -l ec.bin Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s ls: cannot access 'ec.bin': No such file or directory > cargo build && sudo ./target/debug/framework_tool --dump-ec-flash ec.bin && ls -l ec.bin Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s Dumping to ec.bin -rw-r--r--. 1 root root 524288 May 10 09:24 ec.bin ``` Signed-off-by: Daniel Schaefer <[email protected]>
1 parent bb2982b commit c5dd07d

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

framework_lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ build = "build.rs"
99

1010
[features]
1111
default = ["hidapi", "rusb"]
12+
readonly = [ ]
1213
rusb = ["dep:rusb"]
1314
hidapi = ["dep:hidapi"]
1415
uefi = [ "lazy_static/spin_no_std" ]

framework_lib/src/commandline/mod.rs

+66-2
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,73 @@ pub struct Cli {
212212

213213
pub fn parse(args: &[String]) -> Cli {
214214
#[cfg(feature = "uefi")]
215-
return uefi::parse(args);
215+
let cli = uefi::parse(args);
216216
#[cfg(not(feature = "uefi"))]
217-
return clap_std::parse(args);
217+
let cli = clap_std::parse(args);
218+
219+
if cfg!(feature = "readonly") {
220+
// Initialize a new Cli with no arguments
221+
// Set all arguments that are readonly/safe
222+
// We explicitly only cope the safe ones so that if we add new arguments in the future,
223+
// which might be unsafe, we can't forget to exclude them from the safe set.
224+
// TODO: Instead of silently ignoring blocked command, we should remind the user
225+
Cli {
226+
verbosity: cli.verbosity,
227+
versions: cli.versions,
228+
version: cli.version,
229+
esrt: cli.esrt,
230+
device: cli.device,
231+
power: cli.power,
232+
thermal: cli.thermal,
233+
sensors: cli.sensors,
234+
// fansetduty
235+
// fansetrpm
236+
// autofanctrl
237+
privacy: cli.privacy,
238+
pd_info: cli.version,
239+
dp_hdmi_info: cli.dp_hdmi_info,
240+
// dp_hdmi_update
241+
audio_card_info: cli.audio_card_info,
242+
pd_bin: cli.pd_bin,
243+
ec_bin: cli.ec_bin,
244+
capsule: cli.capsule,
245+
dump: cli.dump,
246+
h2o_capsule: cli.h2o_capsule,
247+
// dump_ec_flash
248+
// flash_ec
249+
// flash_ro_ec
250+
driver: cli.driver,
251+
test: cli.test,
252+
intrusion: cli.intrusion,
253+
inputdeck: cli.inputdeck,
254+
inputdeck_mode: cli.inputdeck_mode,
255+
expansion_bay: cli.expansion_bay,
256+
// charge_limit
257+
// charge_current_limit
258+
get_gpio: cli.get_gpio,
259+
fp_led_level: cli.fp_led_level,
260+
fp_brightness: cli.fp_brightness,
261+
kblight: cli.kblight,
262+
rgbkbd: cli.rgbkbd,
263+
// tablet_mode
264+
// touchscreen_enable
265+
stylus_battery: cli.stylus_battery,
266+
console: cli.console,
267+
reboot_ec: cli.reboot_ec,
268+
// ec_hib_delay
269+
hash: cli.hash,
270+
pd_addrs: cli.pd_addrs,
271+
pd_ports: cli.pd_ports,
272+
help: cli.help,
273+
info: cli.info,
274+
// allupdate
275+
paginate: cli.paginate,
276+
// raw_command
277+
..Default::default()
278+
}
279+
} else {
280+
cli
281+
}
218282
}
219283

220284
fn print_single_pd_details(pd: &PdController) {

framework_tool/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "framework_tool"
33
version = "0.4.1"
44
edition = "2021"
55

6+
[features]
7+
default = [ ]
8+
readonly = [ "framework_lib/readonly" ]
9+
610
[dependencies.framework_lib]
711
path = "../framework_lib"
812

framework_uefi/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ rust-version = "1.74"
99
name = "uefitool"
1010
path = "src/main.rs"
1111

12+
[features]
13+
default = [ ]
14+
readonly = [ "framework_lib/readonly" ]
15+
1216
[dependencies]
1317
uefi = { version = "0.20", features = ["alloc"] }
1418
uefi-services = "0.17"

0 commit comments

Comments
 (0)