Skip to content

Commit

Permalink
config_tables: Skip duplicate config table entries
Browse files Browse the repository at this point in the history
  • Loading branch information
fruhland committed Oct 9, 2024
1 parent 745058f commit 3bd0c85
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions towboot/src/boot/config_tables.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! Handle UEFI config tables.
use alloc::collections::BTreeSet;
use alloc::slice;
use alloc::vec::Vec;

use log::{debug, warn};
use multiboot12::information::InfoBuilder;
use acpi::rsdp::Rsdp;
use smbioslib::{SMBiosEntryPoint32, SMBiosEntryPoint64};
use uefi::proto::device_path::media::PartitionSignature::Guid;
use uefi::system::with_config_table;
use uefi::table::cfg::{
ConfigTableEntry, ACPI_GUID, ACPI2_GUID, DEBUG_IMAGE_INFO_GUID,
Expand All @@ -24,8 +27,18 @@ pub(super) fn parse_for_multiboot(info_builder: &mut InfoBuilder) {
let config_tables: Vec<ConfigTableEntry> = with_config_table(|s|
s.iter().cloned().collect()
);

debug!("going through configuration tables...");
let mut handled_guids: BTreeSet<Guid> = BTreeSet::new();

Check failure on line 32 in towboot/src/boot/config_tables.rs

View workflow job for this annotation

GitHub Actions / test

expected type, found variant `Guid`
for table in config_tables {
// We encountered real hardware with multiple ACPI2 entries,
// causing a panic in the multiboot crate.
// As a fix, we store all already handled GUIDs in a set, which we use to skip duplicates.
if handled_guids.contains(&table.guid) {
continue;
}

handled_guids.insert(table.guid);
match table.guid {
ACPI_GUID => handle_acpi(&table, info_builder),
ACPI2_GUID => handle_acpi(&table, info_builder),
Expand Down Expand Up @@ -58,15 +71,12 @@ fn handle_acpi(table: &ConfigTableEntry, info_builder: &mut InfoBuilder) {
);
} else {
unsafe {

Check warning on line 73 in towboot/src/boot/config_tables.rs

View workflow job for this annotation

GitHub Actions / test

unnecessary `unsafe` block
if !RSDP_V2_SET {
info_builder.set_rsdp_v2(
rsdp.signature(), rsdp.checksum(),
rsdp.oem_id().as_bytes()[0..6].try_into().unwrap(),
rsdp.revision(), rsdp.rsdt_address(), rsdp.length(),
rsdp.xsdt_address(), rsdp.ext_checksum(),
);
RSDP_V2_SET = true;
}
info_builder.set_rsdp_v2(
rsdp.signature(), rsdp.checksum(),
rsdp.oem_id().as_bytes()[0..6].try_into().unwrap(),
rsdp.revision(), rsdp.rsdt_address(), rsdp.length(),
rsdp.xsdt_address(), rsdp.ext_checksum(),
);
}
}
}
Expand Down

0 comments on commit 3bd0c85

Please sign in to comment.