Skip to content

Commit 7b5fb13

Browse files
Merge pull request #127 from FrameworkComputer/baseboard-version
--version: Add revision of mainboard
2 parents 58960fa + 1117009 commit 7b5fb13

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

framework_lib/src/commandline/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,25 @@ fn print_stylus_battery_level() {
350350
}
351351

352352
fn print_versions(ec: &CrosEc) {
353+
println!("Mainboard Hardware");
354+
if let Some(ver) = smbios::get_product_name() {
355+
println!(" Type: {}", ver);
356+
} else {
357+
println!(" Type: Unknown");
358+
}
359+
if let Some(ver) = smbios::get_baseboard_version() {
360+
println!(" Revision: {:?}", ver);
361+
} else {
362+
println!(" Revision: Unknown");
363+
}
353364
println!("UEFI BIOS");
354365
if let Some(smbios) = get_smbios() {
355366
let bios_entries = smbios.collect::<SMBiosInformation>();
356367
let bios = bios_entries.first().unwrap();
357368
println!(" Version: {}", bios.version());
358369
println!(" Release Date: {}", bios.release_date());
370+
} else {
371+
println!(" Version: Unknown");
359372
}
360373

361374
println!("EC Firmware");

framework_lib/src/smbios.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::io::ErrorKind;
88
use crate::util::Config;
99
pub use crate::util::Platform;
1010
use num_derive::FromPrimitive;
11+
use num_traits::FromPrimitive;
1112
use smbioslib::*;
1213
#[cfg(feature = "uefi")]
1314
use spin::Mutex;
@@ -215,7 +216,7 @@ pub fn get_smbios() -> Option<SMBiosData> {
215216
}
216217
}
217218

218-
fn get_product_name() -> Option<String> {
219+
pub fn get_product_name() -> Option<String> {
219220
// On FreeBSD we can short-circuit and avoid parsing SMBIOS
220221
#[cfg(target_os = "freebsd")]
221222
if let Ok(product) = kenv_get("smbios.system.product") {
@@ -225,6 +226,7 @@ fn get_product_name() -> Option<String> {
225226
let smbios = get_smbios();
226227
if smbios.is_none() {
227228
println!("Failed to find SMBIOS");
229+
return None;
228230
}
229231
let mut smbios = smbios.into_iter().flatten();
230232
smbios.find_map(|undefined_struct| {
@@ -237,6 +239,38 @@ fn get_product_name() -> Option<String> {
237239
})
238240
}
239241

242+
pub fn get_baseboard_version() -> Option<ConfigDigit0> {
243+
// TODO: On FreeBSD we can short-circuit and avoid parsing SMBIOS
244+
// #[cfg(target_os = "freebsd")]
245+
// if let Ok(product) = kenv_get("smbios.system.product") {
246+
// return Some(product);
247+
// }
248+
249+
let smbios = get_smbios();
250+
if smbios.is_none() {
251+
error!("Failed to find SMBIOS");
252+
return None;
253+
}
254+
let mut smbios = smbios.into_iter().flatten();
255+
smbios.find_map(|undefined_struct| {
256+
if let DefinedStruct::BaseBoardInformation(data) = undefined_struct.defined_struct() {
257+
if let Some(version) = dmidecode_string_val(&data.version()) {
258+
// Assumes it's ASCII, which is guaranteed by SMBIOS
259+
let config_digit0 = &version[0..1];
260+
let config_digit0 = u8::from_str_radix(config_digit0, 16);
261+
if let Ok(version_config) =
262+
config_digit0.map(<ConfigDigit0 as FromPrimitive>::from_u8)
263+
{
264+
return version_config;
265+
} else {
266+
error!(" Invalid BaseBoard Version: {}'", version);
267+
}
268+
}
269+
}
270+
None
271+
})
272+
}
273+
240274
pub fn get_platform() -> Option<Platform> {
241275
#[cfg(feature = "uefi")]
242276
let mut cached_platform = CACHED_PLATFORM.lock();

0 commit comments

Comments
 (0)