-
Notifications
You must be signed in to change notification settings - Fork 26
Add --host-command to send raw EC host commands #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,7 +43,7 @@ use crate::chromium_ec::commands::RgbS; | |||||||||
| use crate::chromium_ec::commands::TabletModeOverride; | ||||||||||
| use crate::chromium_ec::EcResponseStatus; | ||||||||||
| use crate::chromium_ec::{print_err, EcFlashType}; | ||||||||||
| use crate::chromium_ec::{EcError, EcResult}; | ||||||||||
| use crate::chromium_ec::{CrosEcDriver, EcError, EcResult}; | ||||||||||
| use crate::csme; | ||||||||||
| use crate::ec_binary; | ||||||||||
| use crate::esrt::{self, ResourceType}; | ||||||||||
|
|
@@ -230,8 +230,7 @@ pub struct Cli { | |||||||||
| // UEFI only | ||||||||||
| pub allupdate: bool, | ||||||||||
| pub paginate: bool, | ||||||||||
| // TODO: This is not actually implemented yet | ||||||||||
| pub raw_command: Vec<String>, | ||||||||||
| pub host_command: Option<(u16, u8, Vec<u8>)>, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| pub fn parse(args: &[String]) -> Cli { | ||||||||||
|
|
@@ -316,7 +315,7 @@ pub fn parse(args: &[String]) -> Cli { | |||||||||
| nvidia: cli.nvidia, | ||||||||||
| // allupdate | ||||||||||
| paginate: cli.paginate, | ||||||||||
| // raw_command | ||||||||||
| // host_command | ||||||||||
| ..Default::default() | ||||||||||
| } | ||||||||||
| } else { | ||||||||||
|
|
@@ -1603,9 +1602,18 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { | |||||||||
| } else { | ||||||||||
| println!("Not all EC versions support this comand.") | ||||||||||
| }; | ||||||||||
| // TODO: | ||||||||||
| //} else if arg == "-raw-command" { | ||||||||||
| // raw_command(&args[1..]); | ||||||||||
| } else if let Some((command_id, command_version, ref data)) = args.host_command { | ||||||||||
| match ec.send_command(command_id, command_version, data) { | ||||||||||
|
Comment on lines
+1605
to
+1606
|
||||||||||
| } else if let Some((command_id, command_version, ref data)) = args.host_command { | |
| match ec.send_command(command_id, command_version, data) { | |
| } else if let Some((command_id, command_version, data)) = args.host_command.as_ref() { | |
| match ec.send_command(*command_id, *command_version, data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won’t compile
no it does build
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,7 +98,7 @@ pub fn parse(args: &[String]) -> Cli { | |
| info: false, | ||
| meinfo: None, | ||
| nvidia: false, | ||
| raw_command: vec![], | ||
| host_command: None, | ||
| }; | ||
|
|
||
| if args.len() == 0 { | ||
|
|
@@ -708,8 +708,39 @@ pub fn parse(args: &[String]) -> Cli { | |
| None | ||
| }; | ||
| found_an_option = true; | ||
| } else if arg == "--raw-command" { | ||
| cli.raw_command = args[1..].to_vec(); | ||
| } else if arg == "--host-command" { | ||
| cli.host_command = if args.len() > i + 2 { | ||
| let cmd_id = parse_hex_or_dec_u16(&args[i + 1]); | ||
| let version = parse_hex_or_dec_u8(&args[i + 2]); | ||
| if let (Some(cmd_id), Some(version)) = (cmd_id, version) { | ||
| let mut data = Vec::new(); | ||
| let mut parse_error = false; | ||
| for j in (i + 3)..args.len() { | ||
| if args[j].starts_with('-') { | ||
| break; | ||
| } | ||
| if let Some(byte) = parse_hex_or_dec_u8(&args[j]) { | ||
| data.push(byte); | ||
| } else { | ||
| println!("Invalid data byte for --host-command: '{}'", args[j]); | ||
| parse_error = true; | ||
| break; | ||
| } | ||
| } | ||
| if parse_error { | ||
| None | ||
| } else { | ||
| Some((cmd_id, version, data)) | ||
| } | ||
| } else { | ||
|
Comment on lines
+722
to
+735
|
||
| println!("Invalid values for --host-command. Usage: --host-command <CMD_ID> <VERSION> [DATA...]"); | ||
| None | ||
| } | ||
| } else { | ||
| println!("--host-command requires at least two arguments: <CMD_ID> <VERSION>"); | ||
| None | ||
| }; | ||
| found_an_option = true; | ||
| } else if arg == "--compare-version" { | ||
| cli.compare_version = if args.len() > i + 1 { | ||
| Some(args[i + 1].clone()) | ||
|
|
@@ -817,3 +848,19 @@ pub fn parse(args: &[String]) -> Cli { | |
|
|
||
| cli | ||
| } | ||
|
|
||
| fn parse_hex_or_dec_u16(s: &str) -> Option<u16> { | ||
| if let Some(hex) = s.strip_prefix("0x").or_else(|| s.strip_prefix("0X")) { | ||
| u16::from_str_radix(hex, 16).ok() | ||
| } else { | ||
| s.parse::<u16>().ok() | ||
| } | ||
| } | ||
|
|
||
| fn parse_hex_or_dec_u8(s: &str) -> Option<u8> { | ||
| if let Some(hex) = s.strip_prefix("0x").or_else(|| s.strip_prefix("0X")) { | ||
| u8::from_str_radix(hex, 16).ok() | ||
| } else { | ||
| s.parse::<u8>().ok() | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.