Skip to content

Commit 1f5c346

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 <dhs@frame.work>
1 parent 438f9dc commit 1f5c346

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

framework_lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ build = "build.rs"
1414

1515
[features]
1616
default = ["hidapi", "rusb"]
17+
readonly = [ ]
1718
rusb = ["dep:rusb"]
1819
hidapi = ["dep:hidapi"]
1920
uefi = [ "lazy_static/spin_no_std" ]

framework_lib/src/commandline/mod.rs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,73 @@ pub struct Cli {
221221

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

229293
fn print_single_pd_details(pd: &PdController) {

framework_tool/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ edition = "2021"
1212
name = "framework_tool"
1313
path = "src/main.rs"
1414

15+
[features]
16+
default = [ ]
17+
readonly = [ "framework_lib/readonly" ]
18+
1519
[dependencies.framework_lib]
1620
path = "../framework_lib"
1721

framework_uefi/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ rust-version = "1.74"
1414
name = "uefitool"
1515
path = "src/main.rs"
1616

17+
[features]
18+
default = [ ]
19+
readonly = [ "framework_lib/readonly" ]
20+
1721
[dependencies]
1822
uefi = { version = "0.20", features = ["alloc"] }
1923
uefi-services = "0.17"

0 commit comments

Comments
 (0)