Skip to content

Commit

Permalink
Get uptime info command
Browse files Browse the repository at this point in the history
  • Loading branch information
ChocolateLoverRaj committed Jul 3, 2024
1 parent 980e60e commit 94f055f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
51 changes: 51 additions & 0 deletions crosec/src/commands/get_uptime_info.rs
Original file line number Diff line number Diff line change
@@ -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: AsRawFd>(file: &mut File) -> EcCmdResult<EcResponseUptimeInfo> {
ec_command_bytemuck(CrosEcCmd::GetUptimeInfo, 0, &(), file.as_raw_fd())
}
4 changes: 3 additions & 1 deletion crosec/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub enum CrosEcCmd {
ChargeControl = 0x0096,
ConsoleSnapshot = 0x0097,
ConsoleRead = 0x0098,
GetUptimeInfo = 0x0121,
FpMode = 0x0402,
FpInfo = 0x0403,
FpFrame = 0x0404,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions ectool/src/get_uptime_info_command.rs
Original file line number Diff line number Diff line change
@@ -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<Device>) -> 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(())
}
6 changes: 6 additions & 0 deletions ectool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -125,6 +127,9 @@ enum Commands {
/// Uploads template from stdin
FpUploadTemplate,
FpGetEncryptionStatus,
GetUptimeInfo {
device: Option<Device>,
},
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 94f055f

Please sign in to comment.