From 1117009119ac3205810f9f3752fd2a381a37e3b3 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Mon, 5 May 2025 09:47:45 +0800 Subject: [PATCH] --version: Add revision of mainboard ``` > framework_tool.exe --versions Mainboard Hardware Type: Laptop 13 (AMD Ryzen AI 300 Series) Revision: MassProduction [...] ``` Signed-off-by: Daniel Schaefer --- framework_lib/src/commandline/mod.rs | 13 ++++++++++ framework_lib/src/smbios.rs | 36 +++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 88fd1e6..97bf7f7 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -350,12 +350,25 @@ fn print_stylus_battery_level() { } fn print_versions(ec: &CrosEc) { + println!("Mainboard Hardware"); + if let Some(ver) = smbios::get_product_name() { + println!(" Type: {}", ver); + } else { + println!(" Type: Unknown"); + } + if let Some(ver) = smbios::get_baseboard_version() { + println!(" Revision: {:?}", ver); + } else { + println!(" Revision: Unknown"); + } println!("UEFI BIOS"); if let Some(smbios) = get_smbios() { let bios_entries = smbios.collect::(); let bios = bios_entries.first().unwrap(); println!(" Version: {}", bios.version()); println!(" Release Date: {}", bios.release_date()); + } else { + println!(" Version: Unknown"); } println!("EC Firmware"); diff --git a/framework_lib/src/smbios.rs b/framework_lib/src/smbios.rs index 1345b39..5e71351 100644 --- a/framework_lib/src/smbios.rs +++ b/framework_lib/src/smbios.rs @@ -8,6 +8,7 @@ use std::io::ErrorKind; use crate::util::Config; pub use crate::util::Platform; use num_derive::FromPrimitive; +use num_traits::FromPrimitive; use smbioslib::*; #[cfg(feature = "uefi")] use spin::Mutex; @@ -215,7 +216,7 @@ pub fn get_smbios() -> Option { } } -fn get_product_name() -> Option { +pub fn get_product_name() -> Option { // On FreeBSD we can short-circuit and avoid parsing SMBIOS #[cfg(target_os = "freebsd")] if let Ok(product) = kenv_get("smbios.system.product") { @@ -225,6 +226,7 @@ fn get_product_name() -> Option { let smbios = get_smbios(); if smbios.is_none() { println!("Failed to find SMBIOS"); + return None; } let mut smbios = smbios.into_iter().flatten(); smbios.find_map(|undefined_struct| { @@ -237,6 +239,38 @@ fn get_product_name() -> Option { }) } +pub fn get_baseboard_version() -> Option { + // TODO: On FreeBSD we can short-circuit and avoid parsing SMBIOS + // #[cfg(target_os = "freebsd")] + // if let Ok(product) = kenv_get("smbios.system.product") { + // return Some(product); + // } + + let smbios = get_smbios(); + if smbios.is_none() { + error!("Failed to find SMBIOS"); + return None; + } + let mut smbios = smbios.into_iter().flatten(); + smbios.find_map(|undefined_struct| { + if let DefinedStruct::BaseBoardInformation(data) = undefined_struct.defined_struct() { + if let Some(version) = dmidecode_string_val(&data.version()) { + // Assumes it's ASCII, which is guaranteed by SMBIOS + let config_digit0 = &version[0..1]; + let config_digit0 = u8::from_str_radix(config_digit0, 16); + if let Ok(version_config) = + config_digit0.map(::from_u8) + { + return version_config; + } else { + error!(" Invalid BaseBoard Version: {}'", version); + } + } + } + None + }) +} + pub fn get_platform() -> Option { #[cfg(feature = "uefi")] let mut cached_platform = CACHED_PLATFORM.lock();