Skip to content

Commit def3a53

Browse files
Merge pull request #88 from FrameworkComputer/stable
2 parents d94eb93 + f861150 commit def3a53

File tree

6 files changed

+52
-26
lines changed

6 files changed

+52
-26
lines changed

Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework_lib/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ linux = ["linux_pio", "unix"]
1212
windows = ["std", "smbios", "dep:windows", "win_driver"]
1313
smbios = ["dep:smbios-lib"]
1414
std = ["dep:regex", "dep:clap", "smbios-lib?/std", "dep:hidapi", "dep:rusb"]
15-
uefi = ["dep:redox_dmi", "dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services"]
15+
uefi = ["dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services"]
1616

1717
# EC communication via Port I/O on Linux
1818
linux_pio = ["dep:libc"]
@@ -37,7 +37,6 @@ num-traits = { version = "0.2", default-features = false }
3737
log = "0.4"
3838
uefi = { version = "0.20", features = ["alloc"], optional = true }
3939
uefi-services = { version = "0.17", optional = true }
40-
redox_dmi = { version = "0.1.5", optional = true }
4140
plain = { version = "0.2.3", optional = true }
4241
spin = { version = "0.9.4", optional = false }
4342
hidapi = { version = "2.1.0", optional = true }

framework_lib/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! A library to interact with [Framework Computer](https://frame.work) hardware and building tools to do so.
22
33
#![cfg_attr(feature = "uefi", no_std)]
4-
#![feature(prelude_import)]
54

65
extern crate alloc;
76
#[cfg(feature = "uefi")]

framework_lib/src/uefi/mod.rs

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,68 @@ pub fn enable_page_break() {
9999
}
100100
}
101101

102+
#[repr(packed)]
103+
pub struct Smbios {
104+
pub anchor: [u8; 4],
105+
pub checksum: u8,
106+
pub length: u8,
107+
pub major_version: u8,
108+
pub minor_version: u8,
109+
pub max_structure_size: u16,
110+
pub revision: u8,
111+
pub formatted: [u8; 5],
112+
pub inter_anchor: [u8; 5],
113+
pub inter_checksum: u8,
114+
pub table_length: u16,
115+
pub table_address: u32,
116+
pub structure_count: u16,
117+
pub bcd_revision: u8,
118+
}
119+
120+
impl Smbios {
121+
pub fn checksum_valid(&self) -> bool {
122+
let mut sum: u8 = self.anchor.iter().sum::<u8>();
123+
sum += self.checksum;
124+
sum += self.length;
125+
sum += self.major_version;
126+
sum += self.minor_version;
127+
sum += self.max_structure_size as u8;
128+
sum += self.revision;
129+
sum += self.formatted.iter().sum::<u8>();
130+
sum == 0
131+
}
132+
}
133+
134+
pub struct Smbios3 {
135+
pub anchor: [u8; 5],
136+
pub checksum: u8,
137+
pub length: u8,
138+
pub major_version: u8,
139+
pub minor_version: u8,
140+
pub docrev: u8,
141+
pub revision: u8,
142+
_reserved: u8,
143+
pub table_length: u32,
144+
pub table_address: u64,
145+
}
146+
102147
pub fn smbios_data() -> Option<Vec<u8>> {
103148
let st = unsafe { uefi_services::system_table().as_ref() };
104149
let config_tables = st.config_table();
105150

106151
for table in config_tables {
107152
let table_data = match table.guid {
108153
SMBIOS3_GUID => unsafe {
109-
let smbios = &*(table.address as *const dmi::Smbios);
110-
// TODO: Seems to be invalid. Is the calculation correct?
111-
//smbios.is_valid();
154+
let smbios = &*(table.address as *const Smbios3);
155+
assert!(smbios.anchor == *b"_SM3_");
112156
Some(slice::from_raw_parts(
113157
smbios.table_address as *const u8,
114158
smbios.table_length as usize,
115159
))
116160
},
117161
SMBIOS_GUID => unsafe {
118-
let smbios = &*(table.address as *const dmi::Smbios);
119-
// TODO: Seems to be invalid. Is the calculation correct?
120-
//smbios.is_valid();
162+
let smbios = &*(table.address as *const Smbios);
163+
assert!(smbios.checksum_valid());
121164
Some(slice::from_raw_parts(
122165
smbios.table_address as *const u8,
123166
smbios.table_length as usize,

framework_uefi/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ $(BUILD)/efi.img: $(BUILD)/boot.efi
4242
$(BUILD)/boot.efi: ../Cargo.lock $(SRC_DIR)/Cargo.toml $(SRC_DIR)/src/*
4343
mkdir -p $(BUILD)
4444
cargo rustc \
45-
-Z build-std=core,alloc \
46-
-Z build-std-features=compiler-builtins-mem \
4745
--target $(TARGET) \
4846
--release \
4947
-- \

rust-toolchain.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# Can't use stable rust yet, since we need to support the UEFI target
2-
# UEFI will be supported in stable, soon.
3-
# Once rust-1.68 is released, we can use stable.
41
[toolchain]
5-
# 2022-12-26
6-
channel = "nightly-2023-03-18"
2+
profile = "default"
3+
channel = "1.68.2"
74
components = ["rust-src", "clippy", "rustfmt"]
85
targets = ["x86_64-unknown-uefi"]

0 commit comments

Comments
 (0)