From fc03f4bad1e89c3eaf80ffef0b2c7fc9cbe9e6aa Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Jan 2026 02:04:03 +0800 Subject: [PATCH 1/2] chromium: Add s0ixcounter EC command Signed-off-by: Daniel Schaefer --- framework_lib/src/chromium_ec/command.rs | 1 + framework_lib/src/chromium_ec/commands.rs | 19 +++++++++++++++++++ framework_lib/src/chromium_ec/mod.rs | 13 +++++++++++++ 3 files changed, 33 insertions(+) diff --git a/framework_lib/src/chromium_ec/command.rs b/framework_lib/src/chromium_ec/command.rs index 56e51664..a5da86e7 100644 --- a/framework_lib/src/chromium_ec/command.rs +++ b/framework_lib/src/chromium_ec/command.rs @@ -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 diff --git a/framework_lib/src/chromium_ec/commands.rs b/framework_lib/src/chromium_ec/commands.rs index 1984d46c..45e7c630 100644 --- a/framework_lib/src/chromium_ec/commands.rs +++ b/framework_lib/src/chromium_ec/commands.rs @@ -641,6 +641,25 @@ impl EcRequest 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 for EcRequestS0ixCounter { + fn command_id() -> EcCommands { + EcCommands::S0ixCounter + } +} + /// Supported features #[derive(Debug, FromPrimitive)] pub enum EcFeatureCode { diff --git a/framework_lib/src/chromium_ec/mod.rs b/framework_lib/src/chromium_ec/mod.rs index fb59e08d..f2d980f6 100644 --- a/framework_lib/src/chromium_ec/mod.rs +++ b/framework_lib/src/chromium_ec/mod.rs @@ -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 { + 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)?; From 0adf8982208a25229901210a676a0e74d4307563 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 14 Jan 2026 02:04:14 +0800 Subject: [PATCH 2/2] Add --s0ix-counter commandline Prints how many times the system was in s0ix since EC reset Signed-off-by: Daniel Schaefer --- framework_lib/src/commandline/clap_std.rs | 4 ++++ framework_lib/src/commandline/mod.rs | 8 ++++++++ framework_lib/src/commandline/uefi.rs | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/framework_lib/src/commandline/clap_std.rs b/framework_lib/src/commandline/clap_std.rs index 1fbc8ad8..8df96ed9 100644 --- a/framework_lib/src/commandline/clap_std.rs +++ b/framework_lib/src/commandline/clap_std.rs @@ -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, @@ -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, diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 545fb8d6..cf45bdbe 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -212,6 +212,7 @@ pub struct Cli { pub reboot_ec: Option, pub ec_hib_delay: Option>, pub uptimeinfo: bool, + pub s0ix_counter: bool, pub hash: Option, pub pd_addrs: Option<(u16, u16, u16)>, pub pd_ports: Option<(u8, u8, u8)>, @@ -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, @@ -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); diff --git a/framework_lib/src/commandline/uefi.rs b/framework_lib/src/commandline/uefi.rs index 52e2cedc..877b7dac 100644 --- a/framework_lib/src/commandline/uefi.rs +++ b/framework_lib/src/commandline/uefi.rs @@ -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), @@ -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;