From 94f055f390d94df56ef9ea837b7e29a5101dff45 Mon Sep 17 00:00:00 2001 From: Rajas Paranjpe <52586855+ChocolateLoverRaj@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:32:22 -0700 Subject: [PATCH] Get uptime info command --- crosec/src/commands/get_uptime_info.rs | 51 ++++++++++++++++++++++++++ crosec/src/commands/mod.rs | 4 +- ectool/src/get_uptime_info_command.rs | 12 ++++++ ectool/src/main.rs | 6 +++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 crosec/src/commands/get_uptime_info.rs create mode 100644 ectool/src/get_uptime_info_command.rs diff --git a/crosec/src/commands/get_uptime_info.rs b/crosec/src/commands/get_uptime_info.rs new file mode 100644 index 0000000..0f54fee --- /dev/null +++ b/crosec/src/commands/get_uptime_info.rs @@ -0,0 +1,51 @@ +use std::os::fd::AsRawFd; + +use bytemuck::{Pod, Zeroable}; + +use crate::{ec_command::ec_command_bytemuck, EcCmdResult}; + +use super::CrosEcCmd; + +#[repr(C)] +#[derive(Pod, Zeroable, Clone, Copy, Debug)] +pub struct EcResponseUptimeInfo { + /// Number of milliseconds since the last EC boot. Sysjump resets + /// typically do not restart the EC's time_since_boot epoch. + /// + /// WARNING: The EC's sense of time is much less accurate than the AP's + /// sense of time, in both phase and frequency. This timebase is similar + /// to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. + pub time_since_ec_boot_ms: u32, + + /// Number of times the AP was reset by the EC since the last EC boot. + /// Note that the AP may be held in reset by the EC during the initial + /// boot sequence, such that the very first AP boot may count as more + /// than one here. + pub ap_resets_since_ec_boot: u32, + + /// The set of flags which describe the EC's most recent reset. + /// See EC_RESET_FLAG_* for details. + pub ec_reset_flags: u32, + + /// Empty log entries have both the cause and timestamp set to zero. + pub recent_ap_reset: [ApResetLogEntry; 4], +} + +#[repr(C)] +#[derive(Pod, Zeroable, Clone, Copy, Debug)] +pub struct ApResetLogEntry { + /// See enum chipset_{reset,shutdown}_reason for details. + pub reset_cause: u16, + + /// Reserved for protocol growth. + pub reserved: u16, + + /// The time of the reset's assertion, in milliseconds since the + /// last EC boot, in the same epoch as time_since_ec_boot_ms. + /// Set to zero if the log entry is empty. + pub reset_time_ms: u32, +} + +pub fn ec_cmd_get_uptime_info(file: &mut File) -> EcCmdResult { + ec_command_bytemuck(CrosEcCmd::GetUptimeInfo, 0, &(), file.as_raw_fd()) +} diff --git a/crosec/src/commands/mod.rs b/crosec/src/commands/mod.rs index 1a86ca6..5bde990 100644 --- a/crosec/src/commands/mod.rs +++ b/crosec/src/commands/mod.rs @@ -16,6 +16,7 @@ pub enum CrosEcCmd { ChargeControl = 0x0096, ConsoleSnapshot = 0x0097, ConsoleRead = 0x0098, + GetUptimeInfo = 0x0121, FpMode = 0x0402, FpInfo = 0x0403, FpFrame = 0x0404, @@ -29,8 +30,8 @@ pub enum CrosEcCmd { pub mod board_version; pub mod charge_control; pub mod fp_download; -pub mod fp_info; pub mod fp_get_encryption_status; +pub mod fp_info; pub mod fp_mode; pub mod fp_set_seed; pub mod fp_stats; @@ -39,6 +40,7 @@ pub mod get_chip_info; pub mod get_cmd_versions; pub mod get_features; pub mod get_protocol_info; +pub mod get_uptime_info; pub mod hello; pub mod read_mem; pub mod set_fan_target_rpm; diff --git a/ectool/src/get_uptime_info_command.rs b/ectool/src/get_uptime_info_command.rs new file mode 100644 index 0000000..82a588c --- /dev/null +++ b/ectool/src/get_uptime_info_command.rs @@ -0,0 +1,12 @@ +use std::fs::File; + +use crosec::commands::get_uptime_info::ec_cmd_get_uptime_info; + +use crate::Device; + +pub fn get_uptime_info_commnad(device: Option) -> color_eyre::Result<()> { + let mut file = File::open(device.unwrap_or_default().get_path())?; + let uptime_info = ec_cmd_get_uptime_info(&mut file)?; + println!("Uptime info: {uptime_info:#?}"); + Ok(()) +} diff --git a/ectool/src/main.rs b/ectool/src/main.rs index fd18481..31978ef 100644 --- a/ectool/src/main.rs +++ b/ectool/src/main.rs @@ -14,6 +14,7 @@ use crosec::commands::get_protocol_info::get_protocol_info; use crosec::wait_event::{event::EcMkbpEventType, wait_event_sync}; use fp_download_subcommand::{fp_download_subcommand, FpDownloadSubcommand}; use fp_upload_template_command::fp_upload_template_command; +use get_uptime_info_command::get_uptime_info_commnad; use num_traits::cast::FromPrimitive; use crate::fp_get_encryption_status_command::fp_get_encryption_status_command; @@ -38,6 +39,7 @@ mod check_seed; mod fp_download_subcommand; mod fp_get_encryption_status_command; mod fp_upload_template_command; +mod get_uptime_info_command; #[derive(Parser)] #[command(version, about)] @@ -125,6 +127,9 @@ enum Commands { /// Uploads template from stdin FpUploadTemplate, FpGetEncryptionStatus, + GetUptimeInfo { + device: Option, + }, } fn main() -> Result<()> { @@ -275,6 +280,7 @@ fn main() -> Result<()> { Commands::FpDownload { command } => fp_download_subcommand(command)?, Commands::FpUploadTemplate => fp_upload_template_command()?, Commands::FpGetEncryptionStatus => fp_get_encryption_status_command()?, + Commands::GetUptimeInfo { device } => get_uptime_info_commnad(device)?, } Ok(())