Skip to content

Commit b96a342

Browse files
committed
Merge remote-tracking branch 'public/main' into flash-ec
2 parents 09ea9a1 + 459323c commit b96a342

File tree

8 files changed

+121
-39
lines changed

8 files changed

+121
-39
lines changed

Cargo.lock

+20-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework_lib/Cargo.toml

+2-2
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 = [
1818
"dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services",
1919
# Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!`
@@ -38,7 +38,7 @@ built = { version = "0.5", features = ["chrono", "git2"] }
3838
[dependencies]
3939
lazy_static = "1.4.0"
4040
sha2 = { version = "0.10.6", default_features = false, features = [ "force-soft" ] }
41-
regex = { version = "1.6.0", optional = true } # TODO: Can update to 1.7.0
41+
regex = { version = "1.10.0", default-features = false }
4242
redox_hwio = { version = "0.1.5", default_features = false }
4343
libc = { version = "0.2.137", optional = true }
4444
clap = { version = "4.0", features = ["derive"], optional = true }

framework_lib/src/commandline/clap_std.rs

+5
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,
@@ -151,6 +155,7 @@ pub fn parse(args: &[String]) -> Cli {
151155
version: args.version,
152156
esrt: args.esrt,
153157
power: args.power,
158+
thermal: args.thermal,
154159
pdports: args.pdports,
155160
pd_info: args.pd_info,
156161
dp_hdmi_info: args.dp_hdmi_info,

framework_lib/src/commandline/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use alloc::string::String;
77
use alloc::string::ToString;
88
use alloc::vec::Vec;
99
use log::Level;
10+
use num_traits::FromPrimitive;
1011

1112
#[cfg(not(feature = "uefi"))]
1213
pub mod clap_std;
@@ -41,6 +42,7 @@ use crate::ec_binary;
4142
use crate::esrt;
4243
use crate::power;
4344
use crate::smbios;
45+
use crate::smbios::ConfigDigit0;
4446
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
4547
#[cfg(feature = "uefi")]
4648
use crate::uefi::enable_page_break;
@@ -118,6 +120,7 @@ pub struct Cli {
118120
pub version: bool,
119121
pub esrt: bool,
120122
pub power: bool,
123+
pub thermal: bool,
121124
pub pdports: bool,
122125
pub privacy: bool,
123126
pub pd_info: bool,
@@ -585,6 +588,8 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
585588
}
586589
} else if args.power {
587590
power::get_and_print_power_info(&ec);
591+
} else if args.thermal {
592+
power::print_thermal(&ec);
588593
} else if args.pdports {
589594
power::get_and_print_pd_info(&ec);
590595
} else if args.info {
@@ -763,6 +768,7 @@ Options:
763768
--version Show tool version information (Add -vv for more detailed information)
764769
--esrt Display the UEFI ESRT table
765770
--power Show current power status (battery and AC)
771+
--thermal Show current power status (battery and AC)
766772
--pdports Show information about USB-C PD ports
767773
--info Show info from SMBIOS (Only on UEFI)
768774
--pd-info Show details about the PD controllers
@@ -904,7 +910,16 @@ fn smbios_info() {
904910
DefinedStruct::SystemInformation(data) => {
905911
println!("System Information");
906912
if let Some(version) = dmidecode_string_val(&data.version()) {
907-
println!(" Version: {}", version);
913+
// Assumes it's ASCII, which is guaranteed by SMBIOS
914+
let config_digit0 = &version[0..1];
915+
let config_digit0 = u8::from_str_radix(config_digit0, 16).unwrap();
916+
if let Some(version_config) =
917+
<ConfigDigit0 as FromPrimitive>::from_u8(config_digit0)
918+
{
919+
println!(" Version: {:?} ({})", version_config, version);
920+
} else {
921+
println!(" Version: {}", version);
922+
}
908923
}
909924
if let Some(manufacturer) = dmidecode_string_val(&data.manufacturer()) {
910925
println!(" Manufacturer: {}", manufacturer);

framework_lib/src/commandline/uefi.rs

+4
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,
@@ -124,6 +125,9 @@ pub fn parse(args: &[String]) -> Cli {
124125
} else if arg == "--power" {
125126
cli.power = true;
126127
found_an_option = true;
128+
} else if arg == "--thermal" {
129+
cli.thermal = true;
130+
found_an_option = true;
127131
} else if arg == "--pdports" {
128132
cli.pdports = true;
129133
found_an_option = true;

framework_lib/src/ec_binary.rs

-26
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

+54-2
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];

framework_lib/src/smbios.rs

+20
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::prelude::v1::*;
66
use std::io::ErrorKind;
77

88
use crate::util::Platform;
9+
use num_derive::FromPrimitive;
910
use smbioslib::*;
1011
#[cfg(feature = "uefi")]
1112
use spin::Mutex;
@@ -18,6 +19,25 @@ static CACHED_PLATFORM: Mutex<Option<Option<Platform>>> = Mutex::new(None);
1819
// TODO: Should cache SMBIOS and values gotten from it
1920
// SMBIOS is fixed after boot. Oh, so maybe not cache when we're running in UEFI
2021

22+
#[repr(u8)]
23+
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy)]
24+
pub enum ConfigDigit0 {
25+
Poc1 = 0x01,
26+
Proto1 = 0x02,
27+
Proto2 = 0x03,
28+
Evt1 = 0x04,
29+
Evt2 = 0x05,
30+
Dvt1 = 0x07,
31+
Dvt2 = 0x08,
32+
Pvt = 0x09,
33+
MassProduction = 0x0A,
34+
MassProductionB = 0x0B,
35+
MassProductionC = 0x0C,
36+
MassProductionD = 0x0D,
37+
MassProductionE = 0x0E,
38+
MassProductionF = 0x0F,
39+
}
40+
2141
/// Check whether the manufacturer in the SMBIOS says Framework
2242
pub fn is_framework() -> bool {
2343
let smbios = if let Some(smbios) = get_smbios() {

0 commit comments

Comments
 (0)