Skip to content

Commit

Permalink
Merge pull request #33 from FrameworkComputer/thermal
Browse files Browse the repository at this point in the history
Add --thermal dump
  • Loading branch information
JohnAZoidberg authored May 11, 2024
2 parents b03685b + 8df33dc commit a8230e7
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 38 deletions.
28 changes: 20 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions framework_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ linux = ["linux_pio", "unix"]
# Windows does not have the cros_ec driver nor raw port I/O access to userspace
windows = ["std", "smbios", "dep:windows", "win_driver"]
smbios = ["dep:smbios-lib"]
std = ["dep:regex", "dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
uefi = ["dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services"]

# EC communication via Port I/O on Linux
Expand All @@ -31,7 +31,7 @@ built = { version = "0.5", features = ["chrono", "git2"] }

[dependencies]
lazy_static = "1.4.0"
regex = { version = "1.6.0", optional = true } # TODO: Can update to 1.7.0
regex = { version = "1.10.0", default-features = false }
redox_hwio = { version = "0.1.5", default_features = false }
libc = { version = "0.2.137", optional = true }
clap = { version = "4.0", features = ["derive"], optional = true }
Expand Down
5 changes: 5 additions & 0 deletions framework_lib/src/commandline/clap_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ struct ClapCli {
#[arg(long)]
power: bool,

/// Print thermal information (Temperatures and Fan speed)
#[arg(long)]
thermal: bool,

/// Show information about USB-C PD ports
#[arg(long)]
pdports: bool,
Expand Down Expand Up @@ -131,6 +135,7 @@ pub fn parse(args: &[String]) -> Cli {
version: args.version,
esrt: args.esrt,
power: args.power,
thermal: args.thermal,
pdports: args.pdports,
pd_info: args.pd_info,
dp_hdmi_info: args.dp_hdmi_info,
Expand Down
4 changes: 4 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub struct Cli {
pub version: bool,
pub esrt: bool,
pub power: bool,
pub thermal: bool,
pub pdports: bool,
pub privacy: bool,
pub pd_info: bool,
Expand Down Expand Up @@ -526,6 +527,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
}
} else if args.power {
power::get_and_print_power_info(&ec);
} else if args.thermal {
power::print_thermal(&ec);
} else if args.pdports {
power::get_and_print_pd_info(&ec);
} else if args.info {
Expand Down Expand Up @@ -676,6 +679,7 @@ Options:
--version Show tool version information (Add -vv for more detailed information)
--esrt Display the UEFI ESRT table
--power Show current power status (battery and AC)
--thermal Show current power status (battery and AC)
--pdports Show information about USB-C PD ports
--info Show info from SMBIOS (Only on UEFI)
--pd-info Show details about the PD controllers
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 @@ -59,6 +59,7 @@ pub fn parse(args: &[String]) -> Cli {
version: false,
esrt: false,
power: false,
thermal: false,
pdports: false,
pd_info: false,
dp_hdmi_info: false,
Expand Down Expand Up @@ -119,6 +120,9 @@ pub fn parse(args: &[String]) -> Cli {
} else if arg == "--power" {
cli.power = true;
found_an_option = true;
} else if arg == "--thermal" {
cli.thermal = true;
found_an_option = true;
} else if arg == "--pdports" {
cli.pdports = true;
found_an_option = true;
Expand Down
26 changes: 0 additions & 26 deletions framework_lib/src/ec_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const EC_RO_VER_OFFSET_ZEPHYR: usize = 0x00180;
const EC_RW_VER_OFFSET_ZEPHYR: usize = 0x40140;
pub const EC_LEN: usize = 0x8_0000;

#[cfg(not(feature = "uefi"))]
#[cfg(feature = "std")]
use regex;

#[cfg(feature = "uefi")]
Expand Down Expand Up @@ -75,29 +73,6 @@ pub fn print_ec_version(ver: &ImageVersionData, ro: bool) {
println!(" Size: {:>20} KB", ver.size / 1024);
}

#[cfg(feature = "uefi")]
fn parse_ec_version(data: &_ImageVersionData) -> Option<ImageVersionData> {
let version = std::str::from_utf8(&data.version)
.ok()?
.trim_end_matches(char::from(0));

// TODO: regex crate does not support no_std

Some(ImageVersionData {
version: version.to_string(),
size: data.size,
rollback_version: data.rollback_version,
details: ImageVersionDetails {
platform: "".to_string(),
major: 0,
minor: 0,
patch: 0,
commit: "".to_string(),
},
})
}

#[cfg(not(feature = "uefi"))]
fn parse_ec_version(data: &_ImageVersionData) -> Option<ImageVersionData> {
let version = std::str::from_utf8(&data.version)
.ok()?
Expand Down Expand Up @@ -146,7 +121,6 @@ fn parse_ec_version(data: &_ImageVersionData) -> Option<ImageVersionData> {
/// commit: "c6c7ac3".to_string(),
/// }));
/// ```
#[cfg(not(feature = "uefi"))]
pub fn parse_ec_version_str(version: &str) -> Option<ImageVersionDetails> {
debug!("Trying to parse version: {:?}", version);
let re = regex::Regex::new(r"([a-z0-9]+)(_v|-)([0-9])\.([0-9])\.([0-9]+)-(ec:)?([0-9a-f]+)")
Expand Down
56 changes: 54 additions & 2 deletions framework_lib/src/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ use crate::ccgx::{AppVersion, Application, BaseVersion, ControllerVersion, MainP
use crate::chromium_ec::command::EcRequestRaw;
use crate::chromium_ec::commands::{EcRequestReadPdVersion, EcRequestUsbPdPowerInfo};
use crate::chromium_ec::{print_err_ref, CrosEc, CrosEcDriver, EcResult};
use crate::smbios;
use crate::smbios::get_platform;
use crate::util::Platform;

/// Maximum length of strings in memmap
const EC_MEMMAP_TEXT_MAX: u16 = 8;

// The offset address of each type of data in mapped memory.
// TODO: Move non-power values to other modules
const _EC_MEMMAP_TEMP_SENSOR: u16 = 0x00; // Temp sensors 0x00 - 0x0f
const _EC_MEMMAP_FAN: u16 = 0x10; // Fan speeds 0x10 - 0x17
const EC_MEMMAP_TEMP_SENSOR: u16 = 0x00; // Temp sensors 0x00 - 0x0f
const EC_MEMMAP_FAN: u16 = 0x10; // Fan speeds 0x10 - 0x17
const _EC_MEMMAP_TEMP_SENSOR_B: u16 = 0x18; // More temp sensors 0x18 - 0x1f
const _EC_MEMMAP_ID: u16 = 0x2120; // 0x20 == 'E', 0x21 == 'C'
const EC_MEMMAP_ID_VERSION: u16 = 0x22; // Version of data in 0x20 - 0x2f
Expand Down Expand Up @@ -159,6 +161,56 @@ pub fn print_memmap_version_info(ec: &CrosEc) {
let _events_ver = ec.read_memory(EC_MEMMAP_EVENTS_VERSION, 2).unwrap();
}

fn in_c(t: u8) -> u8 {
if t == 255 {
t
} else {
t - 73
}
}

pub fn print_thermal(ec: &CrosEc) {
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();

let platform = smbios::get_platform();
match platform {
Some(Platform::IntelGen11) | Some(Platform::IntelGen12) | Some(Platform::IntelGen13) => {
println!(" F75303_Local: {:>4} C", in_c(temps[0]));
println!(" F75303_CPU: {:>4} C", in_c(temps[1]));
println!(" F75303_DDR: {:>4} C", in_c(temps[2]));
println!(" Battery: {:>4} C", in_c(temps[3]));
println!(" PECI: {:>4} C", in_c(temps[4]));
println!(" F57397_VCCGT: {:>4} C", in_c(temps[5]));
}
Some(Platform::Framework13Amd | Platform::Framework16) => {
println!(" F75303_Local: {:>4} C", in_c(temps[0]));
println!(" F75303_CPU: {:>4} C", in_c(temps[1]));
println!(" F75303_DDR: {:>4} C", in_c(temps[2]));
println!(" APU: {:>4} C", in_c(temps[3]));
if matches!(platform, Some(Platform::Framework16)) {
println!(" dGPU VR: {:>4} C", in_c(temps[4]));
println!(" dGPU VRAM: {:>4} C", in_c(temps[5]));
println!(" dGPU AMB: {:>4} C", in_c(temps[6]));
println!(" dGPU temp: {:>4} C", in_c(temps[7]));
}
}
_ => {
println!(" Temp 0: {:>4} C", in_c(temps[0]));
println!(" Temp 1: {:>4} C", in_c(temps[1]));
println!(" Temp 2: {:>4} C", in_c(temps[2]));
println!(" Temp 3: {:>4} C", in_c(temps[3]));
println!(" Temp 4: {:>4} C", in_c(temps[4]));
println!(" Temp 5: {:>4} C", in_c(temps[5]));
println!(" Temp 6: {:>4} C", in_c(temps[6]));
println!(" Temp 7: {:>4} C", in_c(temps[7]));
}
}

let fan0 = u16::from_le_bytes([fans[0], fans[1]]);
println!(" Fan Speed: {:>4} RPM", fan0);
}

// TODO: Use Result
pub fn power_info(ec: &CrosEc) -> Option<PowerInfo> {
let battery_flag = ec.read_memory(EC_MEMMAP_BATT_FLAG, 1)?[0];
Expand Down

0 comments on commit a8230e7

Please sign in to comment.