Skip to content

Commit a8230e7

Browse files
Merge pull request #33 from FrameworkComputer/thermal
Add --thermal dump
2 parents b03685b + 8df33dc commit a8230e7

File tree

7 files changed

+89
-38
lines changed

7 files changed

+89
-38
lines changed

Cargo.lock

Lines changed: 20 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework_lib/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ linux = ["linux_pio", "unix"]
1313
# Windows does not have the cros_ec driver nor raw port I/O access to userspace
1414
windows = ["std", "smbios", "dep:windows", "win_driver"]
1515
smbios = ["dep:smbios-lib"]
16-
std = ["dep:regex", "dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
16+
std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
1717
uefi = ["dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services"]
1818

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

3232
[dependencies]
3333
lazy_static = "1.4.0"
34-
regex = { version = "1.6.0", optional = true } # TODO: Can update to 1.7.0
34+
regex = { version = "1.10.0", default-features = false }
3535
redox_hwio = { version = "0.1.5", default_features = false }
3636
libc = { version = "0.2.137", optional = true }
3737
clap = { version = "4.0", features = ["derive"], optional = true }

framework_lib/src/commandline/clap_std.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ struct ClapCli {
2929
#[arg(long)]
3030
power: bool,
3131

32+
/// Print thermal information (Temperatures and Fan speed)
33+
#[arg(long)]
34+
thermal: bool,
35+
3236
/// Show information about USB-C PD ports
3337
#[arg(long)]
3438
pdports: bool,
@@ -131,6 +135,7 @@ pub fn parse(args: &[String]) -> Cli {
131135
version: args.version,
132136
esrt: args.esrt,
133137
power: args.power,
138+
thermal: args.thermal,
134139
pdports: args.pdports,
135140
pd_info: args.pd_info,
136141
dp_hdmi_info: args.dp_hdmi_info,

framework_lib/src/commandline/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ pub struct Cli {
114114
pub version: bool,
115115
pub esrt: bool,
116116
pub power: bool,
117+
pub thermal: bool,
117118
pub pdports: bool,
118119
pub privacy: bool,
119120
pub pd_info: bool,
@@ -526,6 +527,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
526527
}
527528
} else if args.power {
528529
power::get_and_print_power_info(&ec);
530+
} else if args.thermal {
531+
power::print_thermal(&ec);
529532
} else if args.pdports {
530533
power::get_and_print_pd_info(&ec);
531534
} else if args.info {
@@ -676,6 +679,7 @@ Options:
676679
--version Show tool version information (Add -vv for more detailed information)
677680
--esrt Display the UEFI ESRT table
678681
--power Show current power status (battery and AC)
682+
--thermal Show current power status (battery and AC)
679683
--pdports Show information about USB-C PD ports
680684
--info Show info from SMBIOS (Only on UEFI)
681685
--pd-info Show details about the PD controllers

framework_lib/src/commandline/uefi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn parse(args: &[String]) -> Cli {
5959
version: false,
6060
esrt: false,
6161
power: false,
62+
thermal: false,
6263
pdports: false,
6364
pd_info: false,
6465
dp_hdmi_info: false,
@@ -119,6 +120,9 @@ pub fn parse(args: &[String]) -> Cli {
119120
} else if arg == "--power" {
120121
cli.power = true;
121122
found_an_option = true;
123+
} else if arg == "--thermal" {
124+
cli.thermal = true;
125+
found_an_option = true;
122126
} else if arg == "--pdports" {
123127
cli.pdports = true;
124128
found_an_option = true;

framework_lib/src/ec_binary.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ const EC_RO_VER_OFFSET_ZEPHYR: usize = 0x00180;
1515
const EC_RW_VER_OFFSET_ZEPHYR: usize = 0x40140;
1616
pub const EC_LEN: usize = 0x8_0000;
1717

18-
#[cfg(not(feature = "uefi"))]
19-
#[cfg(feature = "std")]
2018
use regex;
2119

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

78-
#[cfg(feature = "uefi")]
79-
fn parse_ec_version(data: &_ImageVersionData) -> Option<ImageVersionData> {
80-
let version = std::str::from_utf8(&data.version)
81-
.ok()?
82-
.trim_end_matches(char::from(0));
83-
84-
// TODO: regex crate does not support no_std
85-
86-
Some(ImageVersionData {
87-
version: version.to_string(),
88-
size: data.size,
89-
rollback_version: data.rollback_version,
90-
details: ImageVersionDetails {
91-
platform: "".to_string(),
92-
major: 0,
93-
minor: 0,
94-
patch: 0,
95-
commit: "".to_string(),
96-
},
97-
})
98-
}
99-
100-
#[cfg(not(feature = "uefi"))]
10176
fn parse_ec_version(data: &_ImageVersionData) -> Option<ImageVersionData> {
10277
let version = std::str::from_utf8(&data.version)
10378
.ok()?
@@ -146,7 +121,6 @@ fn parse_ec_version(data: &_ImageVersionData) -> Option<ImageVersionData> {
146121
/// commit: "c6c7ac3".to_string(),
147122
/// }));
148123
/// ```
149-
#[cfg(not(feature = "uefi"))]
150124
pub fn parse_ec_version_str(version: &str) -> Option<ImageVersionDetails> {
151125
debug!("Trying to parse version: {:?}", version);
152126
let re = regex::Regex::new(r"([a-z0-9]+)(_v|-)([0-9])\.([0-9])\.([0-9]+)-(ec:)?([0-9a-f]+)")

framework_lib/src/power.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ use crate::ccgx::{AppVersion, Application, BaseVersion, ControllerVersion, MainP
1111
use crate::chromium_ec::command::EcRequestRaw;
1212
use crate::chromium_ec::commands::{EcRequestReadPdVersion, EcRequestUsbPdPowerInfo};
1313
use crate::chromium_ec::{print_err_ref, CrosEc, CrosEcDriver, EcResult};
14+
use crate::smbios;
1415
use crate::smbios::get_platform;
16+
use crate::util::Platform;
1517

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

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

164+
fn in_c(t: u8) -> u8 {
165+
if t == 255 {
166+
t
167+
} else {
168+
t - 73
169+
}
170+
}
171+
172+
pub fn print_thermal(ec: &CrosEc) {
173+
let temps = ec.read_memory(EC_MEMMAP_TEMP_SENSOR, 0x0F).unwrap();
174+
let fans = ec.read_memory(EC_MEMMAP_FAN, 0x08).unwrap();
175+
176+
let platform = smbios::get_platform();
177+
match platform {
178+
Some(Platform::IntelGen11) | Some(Platform::IntelGen12) | Some(Platform::IntelGen13) => {
179+
println!(" F75303_Local: {:>4} C", in_c(temps[0]));
180+
println!(" F75303_CPU: {:>4} C", in_c(temps[1]));
181+
println!(" F75303_DDR: {:>4} C", in_c(temps[2]));
182+
println!(" Battery: {:>4} C", in_c(temps[3]));
183+
println!(" PECI: {:>4} C", in_c(temps[4]));
184+
println!(" F57397_VCCGT: {:>4} C", in_c(temps[5]));
185+
}
186+
Some(Platform::Framework13Amd | Platform::Framework16) => {
187+
println!(" F75303_Local: {:>4} C", in_c(temps[0]));
188+
println!(" F75303_CPU: {:>4} C", in_c(temps[1]));
189+
println!(" F75303_DDR: {:>4} C", in_c(temps[2]));
190+
println!(" APU: {:>4} C", in_c(temps[3]));
191+
if matches!(platform, Some(Platform::Framework16)) {
192+
println!(" dGPU VR: {:>4} C", in_c(temps[4]));
193+
println!(" dGPU VRAM: {:>4} C", in_c(temps[5]));
194+
println!(" dGPU AMB: {:>4} C", in_c(temps[6]));
195+
println!(" dGPU temp: {:>4} C", in_c(temps[7]));
196+
}
197+
}
198+
_ => {
199+
println!(" Temp 0: {:>4} C", in_c(temps[0]));
200+
println!(" Temp 1: {:>4} C", in_c(temps[1]));
201+
println!(" Temp 2: {:>4} C", in_c(temps[2]));
202+
println!(" Temp 3: {:>4} C", in_c(temps[3]));
203+
println!(" Temp 4: {:>4} C", in_c(temps[4]));
204+
println!(" Temp 5: {:>4} C", in_c(temps[5]));
205+
println!(" Temp 6: {:>4} C", in_c(temps[6]));
206+
println!(" Temp 7: {:>4} C", in_c(temps[7]));
207+
}
208+
}
209+
210+
let fan0 = u16::from_le_bytes([fans[0], fans[1]]);
211+
println!(" Fan Speed: {:>4} RPM", fan0);
212+
}
213+
162214
// TODO: Use Result
163215
pub fn power_info(ec: &CrosEc) -> Option<PowerInfo> {
164216
let battery_flag = ec.read_memory(EC_MEMMAP_BATT_FLAG, 1)?[0];

0 commit comments

Comments
 (0)