Skip to content

Commit cb5314e

Browse files
committed
Require --force to flash both PD images and hide PD flashing from docs
Flashing both PD firmware images at once leaves no known-good image to fall back to. Like --flash-ec, require --force for it. Without --force, suggest flashing only the backup image and jumping to it to test it. Hide --flash-pd01, --flash-pd23 and --pd-image from --help, the man page and the shell completions. clap_complete does not honor hidden args, so filter them out before generating completions. This also drops the already hidden --ps2-enable, --generate-completions and --generate-manpage from the completions. Update the PD flashing example to the backup-then-jump flow. Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 0bbd6c2 commit cb5314e

7 files changed

Lines changed: 78 additions & 54 deletions

File tree

‎EXAMPLES_ADVANCED.md‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@ Error: "Fail"
357357

358358
### Flash
359359

360-
By default both images are updated. With `--pd-image main` or
361-
`--pd-image backup` only one of them is written. If the selected image is the
362-
one currently running, the controller is switched to the other one first.
360+
Flash only the backup image and jump to it to test the new firmware. The main
361+
image stays untouched, so a reset of the PD controller boots the known-good
362+
firmware again. With `--pd-image main` the main image is written instead.
363+
If the selected image is the one currently running, the controller is switched
364+
to the other one first.
363365

364366
```
365-
# Only update the backup firmware on PD 0 (right side)
367+
# Update the backup firmware on PD 0 (right side)
366368
> sudo framework_tool --flash-pd01 pd-1.0.09.bin --pd-image backup
367369
Device
368370
Silicon ID: 0x3E81
@@ -391,8 +393,16 @@ Controller is running MainFw
391393
FW1 (Backup) Version: Base: 3.8.50.00A, App: 1.0.09
392394
FW2 (Main) Version: Base: 3.8.50.00A, App: 1.0.0A
393395
394-
# Update both images on PD 1 (left side)
395-
> sudo framework_tool --flash-pd23 pd-1.0.09.bin
396+
# Boot the new backup firmware on PD 0 to test it
397+
> sudo framework_tool --pd-jump-backup 0
398+
Jumping PD 0 to backup firmware...
399+
Current mode: MainFw, jumping to BackupFw
400+
Disabling PD ports
401+
Jumping from MainFw to BackupFw
402+
Now running BackupFw
403+
404+
# Once it works, update the main image too
405+
> sudo framework_tool --flash-pd01 pd-1.0.09.bin --pd-image main
396406
```
397407

398408
### Switch between the firmwares

‎framework_lib/src/commandline/clap_std.rs‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,16 @@ struct ClapCli {
301301
stylus_battery: bool,
302302

303303
/// Flash PD controller 01
304-
#[arg(long)]
304+
#[arg(long, hide = true)]
305305
flash_pd01: Option<std::path::PathBuf>,
306306

307307
/// Flash PD controller 23
308-
#[arg(long)]
308+
#[arg(long, hide = true)]
309309
flash_pd23: Option<std::path::PathBuf>,
310310

311311
/// Which PD firmware image to flash with --flash-pd01/--flash-pd23
312312
#[clap(value_enum)]
313-
#[arg(long, default_value = "both")]
313+
#[arg(long, default_value = "both", hide = true)]
314314
pd_image: Option<PdImageArg>,
315315

316316
/// Validate PD controller 01 firmware and compare with a file
@@ -505,6 +505,20 @@ Flash EC RW firmware:
505505
.PP
506506
"#;
507507

508+
/// Rebuild the command with only the visible arguments.
509+
/// clap_complete does not honor `hide = true`, so hidden args would otherwise
510+
/// show up in the generated shell completions.
511+
fn without_hidden_args(cmd: &clap::Command) -> clap::Command {
512+
let visible: Vec<Arg> = cmd
513+
.get_arguments()
514+
.filter(|a| !a.is_hide_set())
515+
.cloned()
516+
.collect();
517+
clap::Command::new("framework_tool")
518+
.disable_version_flag(true)
519+
.args(visible)
520+
}
521+
508522
/// Generate a man page from the clap definition and print it to stdout
509523
fn generate_manpage(cmd: clap::Command) {
510524
let cmd = cmd.long_about(MANPAGE_DESCRIPTION);
@@ -538,7 +552,8 @@ pub fn parse(args: &[String]) -> Cli {
538552
if let Some(shell_arg) = args.iter().position(|a| a == "--generate-completions") {
539553
if let Some(shell_str) = args.get(shell_arg + 1) {
540554
if let Ok(shell) = shell_str.parse::<Shell>() {
541-
generate(shell, &mut cli, "framework_tool", &mut io::stdout());
555+
let mut visible = without_hidden_args(&cli);
556+
generate(shell, &mut visible, "framework_tool", &mut io::stdout());
542557
std::process::exit(0);
543558
}
544559
}

‎framework_lib/src/commandline/mod.rs‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,11 +2233,17 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
22332233
}
22342234
}
22352235
} else if let Some(pd_bin_path) = &args.flash_pd01 {
2236+
if !pd_flash_allowed(args, "--flash-pd01", 0) {
2237+
return -1;
2238+
}
22362239
if let Err(err) = flash_pd(PdPort::Right01, pd_bin_path, args.pd_image, &ec) {
22372240
println!("Failed to flash PD 01: {:?}", err);
22382241
return -1;
22392242
}
22402243
} else if let Some(pd_bin_path) = &args.flash_pd23 {
2244+
if !pd_flash_allowed(args, "--flash-pd23", 1) {
2245+
return -1;
2246+
}
22412247
if let Err(err) = flash_pd(PdPort::Left23, pd_bin_path, args.pd_image, &ec) {
22422248
println!("Failed to flash PD 23: {:?}", err);
22432249
return -1;
@@ -2303,9 +2309,6 @@ Options:
23032309
--flash-ro-ec <FLASH_EC> Flash EC with new firmware from file
23042310
--flash-rw-ec <FLASH_EC> Flash EC with new firmware from file
23052311
--reboot-ec Control EC RO/RW jump [possible values: reboot, jump-ro, jump-rw, cancel-jump, disable-jump]
2306-
--flash-pd01 <FLASH_PD01> Flash PD controller 01
2307-
--flash-pd23 <FLASH_PD23> Flash PD controller 23
2308-
--pd-image <PD_IMAGE> Which PD firmware image to flash [default: both] [possible values: main, backup, both]
23092312
--validate-pd01 <VALIDATE_PD01> Validate PD controller 01 firmware and compare with a file
23102313
--validate-pd23 <VALIDATE_PD23> Validate PD controller 23 firmware and compare with a file
23112314
--ec-hib-delay [<SECONDS>] Get or set EC hibernate delay (S5 to G3)
@@ -3126,6 +3129,20 @@ fn load_pd_firmware(
31263129
Ok((fw_file, fw_bin))
31273130
}
31283131

3132+
/// Flashing both PD images at once leaves no known-good image to fall back to.
3133+
/// Only allow it with --force, otherwise suggest flashing just the backup image
3134+
/// and jumping to it.
3135+
fn pd_flash_allowed(args: &Cli, flash_flag: &str, pd_num: u8) -> bool {
3136+
if args.force || !matches!(args.pd_image, None | Some(PdImageArg::Both)) {
3137+
return true;
3138+
}
3139+
error!("Flashing both PD firmware images at once is unsafe");
3140+
println!("Flash only the backup image and jump to it to test it instead:");
3141+
println!(" framework_tool {} <file> --pd-image backup", flash_flag);
3142+
println!(" framework_tool --pd-jump-backup {}", pd_num);
3143+
false
3144+
}
3145+
31293146
fn flash_pd(
31303147
port: PdPort,
31313148
pd_bin_path: &str,

‎framework_tool/completions/bash/framework_tool‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _framework_tool() {
2323

2424
case "${cmd}" in
2525
framework_tool)
26-
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --smartbattery --smartbattery-auth --thermal --thermalget --thermalset --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-chromebook --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --pd-jump-boot --pd-jump-backup --pd-jump-main --pd-validate --pd-dump-fw --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --ps2-enable --tablet-mode --touchscreen-enable --haptic-intensity --click-force --stylus-battery --flash-pd01 --flash-pd23 --pd-image --validate-pd01 --validate-pd23 --console --reboot-ec --ec-hib-delay --sysinfo --uptimeinfo --s0ix-counter --hello --protoinfo --switches --port80read --panicinfo --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --validate-gpu-descriptor-file --nvidia --host-command --generate-completions --generate-manpage --help"
26+
opts="-v -q -t -f -h --flash-gpu-descriptor --verbose --quiet --versions --version --features --esrt --device --compare-version --power --smartbattery --smartbattery-auth --thermal --thermalget --thermalset --sensors --fansetduty --fansetrpm --autofanctrl --pdports --pdports-chromebook --info --meinfo --pd-info --pd-reset --pd-disable --pd-enable --pd-jump-boot --pd-jump-backup --pd-jump-main --pd-validate --pd-dump-fw --dp-hdmi-info --dp-hdmi-update --audio-card-info --privacy --pd-bin --ec-bin --capsule --dump --h2o-capsule --dump-ec-flash --flash-full-ec --flash-ec --flash-ro-ec --flash-rw-ec --intrusion --inputdeck --inputdeck-mode --expansion-bay --charge-limit --charge-current-limit --charge-rate-limit --get-gpio --fp-led-level --fp-brightness --kblight --remap-key --rgbkbd --tablet-mode --touchscreen-enable --haptic-intensity --click-force --stylus-battery --validate-pd01 --validate-pd23 --console --reboot-ec --ec-hib-delay --sysinfo --uptimeinfo --s0ix-counter --hello --protoinfo --switches --port80read --panicinfo --hash --driver --pd-addrs --pd-ports --test --test-retimer --boardid --force --dry-run --flash-gpu-descriptor-file --dump-gpu-descriptor-file --validate-gpu-descriptor-file --nvidia --host-command --help"
2727
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
2828
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
2929
return 0
@@ -181,10 +181,6 @@ _framework_tool() {
181181
COMPREPLY=($(compgen -f "${cur}"))
182182
return 0
183183
;;
184-
--ps2-enable)
185-
COMPREPLY=($(compgen -W "true false" -- "${cur}"))
186-
return 0
187-
;;
188184
--tablet-mode)
189185
COMPREPLY=($(compgen -W "auto tablet laptop" -- "${cur}"))
190186
return 0
@@ -201,18 +197,6 @@ _framework_tool() {
201197
COMPREPLY=($(compgen -W "low medium high" -- "${cur}"))
202198
return 0
203199
;;
204-
--flash-pd01)
205-
COMPREPLY=($(compgen -f "${cur}"))
206-
return 0
207-
;;
208-
--flash-pd23)
209-
COMPREPLY=($(compgen -f "${cur}"))
210-
return 0
211-
;;
212-
--pd-image)
213-
COMPREPLY=($(compgen -W "main backup both" -- "${cur}"))
214-
return 0
215-
;;
216200
--validate-pd01)
217201
COMPREPLY=($(compgen -f "${cur}"))
218202
return 0
@@ -265,10 +249,6 @@ _framework_tool() {
265249
COMPREPLY=($(compgen -f "${cur}"))
266250
return 0
267251
;;
268-
--generate-completions)
269-
COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}"))
270-
return 0
271-
;;
272252
*)
273253
COMPREPLY=()
274254
;;

‎framework_tool/completions/fish/framework_tool.fish‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ complete -c framework_tool -l fp-brightness -d 'Get or set fingerprint LED brigh
5050
complete -c framework_tool -l kblight -d 'Set keyboard backlight percentage or get, if no value provided' -r
5151
complete -c framework_tool -l remap-key -d 'Remap a key by changing the scancode' -r
5252
complete -c framework_tool -l rgbkbd -d 'Set the color of <key> to <RGB>. Multiple colors for adjacent keys can be set at once. <key> <RGB> [<RGB> ...] Example: 0 0xFF000 0x00FF00 0x0000FF' -r
53-
complete -c framework_tool -l ps2-enable -d 'Control PS2 touchpad emulation (DEBUG COMMAND, if touchpad not working, reboot system)' -r -f -a "true\t''
54-
false\t''"
5553
complete -c framework_tool -l tablet-mode -d 'Set tablet mode override' -r -f -a "auto\t''
5654
tablet\t''
5755
laptop\t''"
@@ -65,11 +63,6 @@ complete -c framework_tool -l haptic-intensity -d 'Set touchpad haptic feedback
6563
complete -c framework_tool -l click-force -d 'Set touchpad click force / sensitivity' -r -f -a "low\t''
6664
medium\t''
6765
high\t''"
68-
complete -c framework_tool -l flash-pd01 -d 'Flash PD controller 01' -r -F
69-
complete -c framework_tool -l flash-pd23 -d 'Flash PD controller 23' -r -F
70-
complete -c framework_tool -l pd-image -d 'Which PD firmware image to flash with --flash-pd01/--flash-pd23' -r -f -a "main\t''
71-
backup\t''
72-
both\t''"
7366
complete -c framework_tool -l validate-pd01 -d 'Validate PD controller 01 firmware and compare with a file' -r -F
7467
complete -c framework_tool -l validate-pd23 -d 'Validate PD controller 23 firmware and compare with a file' -r -F
7568
complete -c framework_tool -l console -d 'Get EC console, choose whether recent or to follow the output' -r -f -a "recent\t''
@@ -90,11 +83,6 @@ complete -c framework_tool -l flash-gpu-descriptor-file -d 'File to write to the
9083
complete -c framework_tool -l dump-gpu-descriptor-file -d 'File to dump the gpu EEPROM to' -r -F
9184
complete -c framework_tool -l validate-gpu-descriptor-file -d 'File to validate the gpu EEPROM against' -r -F
9285
complete -c framework_tool -l host-command -d 'Send an EC host command. Args: <CMD_ID> <VERSION> [DATA...]' -r
93-
complete -c framework_tool -l generate-completions -d 'Generate shell completions and print to stdout' -r -f -a "bash\t''
94-
elvish\t''
95-
fish\t''
96-
powershell\t''
97-
zsh\t''"
9886
complete -c framework_tool -s v -l verbose -d 'Increase logging verbosity'
9987
complete -c framework_tool -s q -l quiet -d 'Decrease logging verbosity'
10088
complete -c framework_tool -l versions -d 'List current firmware versions'
@@ -131,5 +119,4 @@ complete -c framework_tool -l boardid -d 'Print all board IDs'
131119
complete -c framework_tool -s f -l force -d 'Force execution of an unsafe command - may render your hardware unbootable!'
132120
complete -c framework_tool -l dry-run -d 'Simulate execution of a command (e.g. --flash-ec)'
133121
complete -c framework_tool -l nvidia -d 'Show NVIDIA GPU information (Laptop 16 only)'
134-
complete -c framework_tool -l generate-manpage -d 'Generate man page and print to stdout'
135122
complete -c framework_tool -s h -l help -d 'Print help'

‎framework_tool/completions/zsh/_framework_tool‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@ _framework_tool() {
5353
'--kblight=[Set keyboard backlight percentage or get, if no value provided]::KBLIGHT:_default' \
5454
'*--remap-key=[Remap a key by changing the scancode]:REMAP_KEY:_default:REMAP_KEY:_default:REMAP_KEY:_default' \
5555
'*--rgbkbd=[Set the color of <key> to <RGB>. Multiple colors for adjacent keys can be set at once. <key> <RGB> \[<RGB> ...\] Example\: 0 0xFF000 0x00FF00 0x0000FF]:START:_default:START:_default' \
56-
'--ps2-enable=[Control PS2 touchpad emulation (DEBUG COMMAND, if touchpad not working, reboot system)]:PS2_ENABLE:(true false)' \
5756
'--tablet-mode=[Set tablet mode override]:TABLET_MODE:(auto tablet laptop)' \
5857
'--touchscreen-enable=[Enable/disable touchscreen]:TOUCHSCREEN_ENABLE:(true false)' \
5958
'--haptic-intensity=[Set touchpad haptic feedback intensity]:INTENSITY:(0 25 50 75 100)' \
6059
'--click-force=[Set touchpad click force / sensitivity]:CLICK_FORCE:(low medium high)' \
61-
'--flash-pd01=[Flash PD controller 01]:FLASH_PD01:_files' \
62-
'--flash-pd23=[Flash PD controller 23]:FLASH_PD23:_files' \
63-
'--pd-image=[Which PD firmware image to flash with --flash-pd01/--flash-pd23]:PD_IMAGE:(main backup both)' \
6460
'--validate-pd01=[Validate PD controller 01 firmware and compare with a file]:VALIDATE_PD01:_files' \
6561
'--validate-pd23=[Validate PD controller 23 firmware and compare with a file]:VALIDATE_PD23:_files' \
6662
'--console=[Get EC console, choose whether recent or to follow the output]:CONSOLE:(recent follow)' \
@@ -74,7 +70,6 @@ _framework_tool() {
7470
'--dump-gpu-descriptor-file=[File to dump the gpu EEPROM to]:DUMP_GPU_DESCRIPTOR_FILE:_files' \
7571
'--validate-gpu-descriptor-file=[File to validate the gpu EEPROM against]:VALIDATE_GPU_DESCRIPTOR_FILE:_files' \
7672
'*--host-command=[Send an EC host command. Args\: <CMD_ID> <VERSION> \[DATA...\]]:HOST_COMMAND:_default:HOST_COMMAND:_default' \
77-
'--generate-completions=[Generate shell completions and print to stdout]:SHELL:(bash elvish fish powershell zsh)' \
7873
'*-v[Increase logging verbosity]' \
7974
'*--verbose[Increase logging verbosity]' \
8075
'(-v --verbose)*-q[Decrease logging verbosity]' \
@@ -115,7 +110,6 @@ _framework_tool() {
115110
'--force[Force execution of an unsafe command - may render your hardware unbootable!]' \
116111
'--dry-run[Simulate execution of a command (e.g. --flash-ec)]' \
117112
'--nvidia[Show NVIDIA GPU information (Laptop 16 only)]' \
118-
'--generate-manpage[Generate man page and print to stdout]' \
119113
'-h[Print help]' \
120114
'--help[Print help]' \
121115
&& ret=0

0 commit comments

Comments
 (0)