Skip to content

Commit

Permalink
smbios: Decode config digit 0 of serialnumber
Browse files Browse the repository at this point in the history
Can determine what production stage it is.

Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Nov 1, 2023
1 parent b7207a6 commit e217c07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
13 changes: 12 additions & 1 deletion framework_lib/src/commandline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use alloc::string::String;
use alloc::string::ToString;
use alloc::vec::Vec;
use log::Level;
use num_traits::FromPrimitive;

#[cfg(not(feature = "uefi"))]
pub mod clap_std;
Expand Down Expand Up @@ -39,6 +40,7 @@ use crate::ec_binary;
use crate::esrt;
use crate::power;
use crate::smbios;
use crate::smbios::ConfigDigit0;
use crate::smbios::{dmidecode_string_val, get_smbios, is_framework};
#[cfg(feature = "uefi")]
use crate::uefi::enable_page_break;
Expand Down Expand Up @@ -746,7 +748,16 @@ fn smbios_info() {
DefinedStruct::SystemInformation(data) => {
println!("System Information");
if let Some(version) = dmidecode_string_val(&data.version()) {
println!(" Version: {}", 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).unwrap();
if let Some(version_config) =
<ConfigDigit0 as FromPrimitive>::from_u8(config_digit0)
{
println!(" Version: {:?} ({})", version_config, version);
} else {
println!(" Version: {}", version);
}
}
if let Some(manufacturer) = dmidecode_string_val(&data.manufacturer()) {
println!(" Manufacturer: {}", manufacturer);
Expand Down
15 changes: 15 additions & 0 deletions framework_lib/src/smbios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::prelude::v1::*;
use std::io::ErrorKind;

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

#[repr(u8)]
#[derive(Debug, PartialEq, FromPrimitive, Clone, Copy)]
pub enum ConfigDigit0 {
Poc1 = 0x01,
Proto1 = 0x02,
Proto2 = 0x03,
Evt1 = 0x04,
Evt2 = 0x05,
Dvt1 = 0x07,
Dvt2 = 0x08,
Pvt = 0x09,
MassProduction = 0x0A,
}

/// Check whether the manufacturer in the SMBIOS says Framework
pub fn is_framework() -> bool {
let smbios = if let Some(smbios) = get_smbios() {
Expand Down

0 comments on commit e217c07

Please sign in to comment.