Skip to content

--version: Add revision of mainboard #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<SMBiosInformation>();
let bios = bios_entries.first().unwrap();
println!(" Version: {}", bios.version());
println!(" Release Date: {}", bios.release_date());
} else {
println!(" Version: Unknown");
}

println!("EC Firmware");
Expand Down
36 changes: 35 additions & 1 deletion framework_lib/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,7 +216,7 @@ pub fn get_smbios() -> Option<SMBiosData> {
}
}

fn get_product_name() -> Option<String> {
pub fn get_product_name() -> Option<String> {
// On FreeBSD we can short-circuit and avoid parsing SMBIOS
#[cfg(target_os = "freebsd")]
if let Ok(product) = kenv_get("smbios.system.product") {
Expand All @@ -225,6 +226,7 @@ fn get_product_name() -> Option<String> {
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| {
Expand All @@ -237,6 +239,38 @@ fn get_product_name() -> Option<String> {
})
}

pub fn get_baseboard_version() -> Option<ConfigDigit0> {
// 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(<ConfigDigit0 as FromPrimitive>::from_u8)
{
return version_config;
} else {
error!(" Invalid BaseBoard Version: {}'", version);
}
}
}
None
})
}

pub fn get_platform() -> Option<Platform> {
#[cfg(feature = "uefi")]
let mut cached_platform = CACHED_PLATFORM.lock();
Expand Down