Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions framework_lib/src/chromium_ec/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub enum EcCommands {
ChargeState = 0x00A0,
ChargeCurrentLimit = 0x00A1,
HibernationDelay = 0x00A8,
S0ixCounter = 0x00AB,
/// List the features supported by the firmware
GetFeatures = 0x000D,
/// Force reboot, causes host reboot as well
Expand Down
19 changes: 19 additions & 0 deletions framework_lib/src/chromium_ec/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,25 @@ impl EcRequest<EcResponseHibernationDelay> for EcRequesetHibernationDelay {
}
}

#[repr(C, packed)]
pub struct EcRequestS0ixCounter {
/// If 0x01 then reset the counter, otherwise get it
pub flags: u32,
}

#[repr(C, packed)]
pub struct EcResponseS0ixCounter {
pub s0ix_counter: u32,
}

pub const EC_S0IX_COUNTER_RESET: u32 = 0x01;

impl EcRequest<EcResponseS0ixCounter> for EcRequestS0ixCounter {
fn command_id() -> EcCommands {
EcCommands::S0ixCounter
}
}

/// Supported features
#[derive(Debug, FromPrimitive)]
pub enum EcFeatureCode {
Expand Down
13 changes: 13 additions & 0 deletions framework_lib/src/chromium_ec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,19 @@ impl CrosEc {
Ok(res.hibernation_delay)
}

pub fn reset_s0ix_counter(&self) -> EcResult<()> {
EcRequestS0ixCounter {
flags: EC_S0IX_COUNTER_RESET,
}
.send_command(self)?;
Ok(())
}

pub fn get_s0ix_counter(&self) -> EcResult<u32> {
let res = EcRequestS0ixCounter { flags: 0 }.send_command(self)?;
Ok(res.s0ix_counter)
}

/// Check features supported by the firmware
pub fn get_features(&self) -> EcResult<()> {
let data = EcRequestGetFeatures {}.send_command(self)?;
Expand Down
4 changes: 4 additions & 0 deletions framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ struct ClapCli {
#[arg(long)]
uptimeinfo: bool,

#[arg(long)]
s0ix_counter: bool,

/// Hash a file of arbitrary data
#[arg(long)]
hash: Option<std::path::PathBuf>,
Expand Down Expand Up @@ -458,6 +461,7 @@ pub fn parse(args: &[String]) -> Cli {
reboot_ec: args.reboot_ec,
ec_hib_delay: args.ec_hib_delay,
uptimeinfo: args.uptimeinfo,
s0ix_counter: args.s0ix_counter,
hash: args.hash.map(|x| x.into_os_string().into_string().unwrap()),
driver: args.driver,
pd_addrs,
Expand Down
8 changes: 8 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub struct Cli {
pub reboot_ec: Option<RebootEcArg>,
pub ec_hib_delay: Option<Option<u32>>,
pub uptimeinfo: bool,
pub s0ix_counter: bool,
pub hash: Option<String>,
pub pd_addrs: Option<(u16, u16, u16)>,
pub pd_ports: Option<(u8, u8, u8)>,
Expand Down Expand Up @@ -297,6 +298,7 @@ pub fn parse(args: &[String]) -> Cli {
reboot_ec: cli.reboot_ec,
// ec_hib_delay
uptimeinfo: cli.uptimeinfo,
s0ix_counter: cli.s0ix_counter,
hash: cli.hash,
pd_addrs: cli.pd_addrs,
pd_ports: cli.pd_ports,
Expand Down Expand Up @@ -1178,6 +1180,12 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
print_err(ec.get_ec_hib_delay());
} else if args.uptimeinfo {
print_err(ec.get_uptime_info());
} else if args.s0ix_counter {
if let Some(counter) = print_err(ec.get_s0ix_counter()) {
println!("s0ix_counter: {}", counter);
} else {
println!("s0ix_counter: Unknown");
}
} else if args.test {
println!("Self-Test");
let result = selftest(&ec);
Expand Down
4 changes: 4 additions & 0 deletions framework_lib/src/commandline/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn parse(args: &[String]) -> Cli {
reboot_ec: None,
ec_hib_delay: None,
uptimeinfo: false,
s0ix_counter: false,
hash: None,
// This is the only driver that works on UEFI
driver: Some(CrosEcDriverType::Portio),
Expand Down Expand Up @@ -497,6 +498,9 @@ pub fn parse(args: &[String]) -> Cli {
} else if arg == "--uptimeinfo" {
cli.uptimeinfo = true;
found_an_option = true;
} else if arg == "--s0ix-counter" {
cli.s0ix_counter = true;
found_an_option = true;
} else if arg == "-t" || arg == "--test" {
cli.test = true;
found_an_option = true;
Expand Down