Merge pull request #178 from nix-community/update/uefi-rs

deps: update to uefi-rs 0.21.0
This commit is contained in:
Ryan Lahfa 2023-05-20 23:05:27 +02:00 committed by GitHub
commit f9681e3e23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 101 additions and 96 deletions

115
rust/stub/Cargo.lock generated
View File

@ -10,15 +10,9 @@ checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "1.3.2" version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84"
[[package]]
name = "bitflags"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
@ -35,6 +29,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.7" version = "0.2.7"
@ -55,10 +55,23 @@ dependencies = [
] ]
[[package]] [[package]]
name = "digest" name = "derive_more"
version = "0.10.6" version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"rustc_version",
"syn 1.0.109",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"crypto-common", "crypto-common",
@ -89,7 +102,7 @@ dependencies = [
name = "lanzaboote_stub" name = "lanzaboote_stub"
version = "0.3.0" version = "0.3.0"
dependencies = [ dependencies = [
"bitflags 2.2.1", "bitflags",
"goblin", "goblin",
"log", "log",
"sha1_smol", "sha1_smol",
@ -100,9 +113,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.142" version = "0.2.144"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
[[package]] [[package]]
name = "log" name = "log"
@ -121,9 +134,9 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.56" version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -145,18 +158,27 @@ checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.109",
] ]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.26" version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]] [[package]]
name = "scroll" name = "scroll"
version = "0.11.0" version = "0.11.0"
@ -174,9 +196,15 @@ checksum = "bdbda6ac5cd1321e724fa9cee216f3a61885889b896f073b8f82322789c5250e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 1.0.109",
] ]
[[package]]
name = "semver"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
[[package]] [[package]]
name = "sha1_smol" name = "sha1_smol"
version = "1.0.0" version = "1.0.0"
@ -205,6 +233,17 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "syn"
version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "typenum" name = "typenum"
version = "1.16.0" version = "1.16.0"
@ -222,39 +261,59 @@ dependencies = [
[[package]] [[package]]
name = "uefi" name = "uefi"
version = "0.20.0" version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab39d5e7740f21ed4c46d6659f31038bbe3fe7a8be1f702d8a984348837c43b1" checksum = "1b568c22d9ed54fb8695eff4252975063a3fa20281049df911d0237b44b86b6a"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags",
"derive_more",
"log", "log",
"ptr_meta", "ptr_meta",
"ucs2", "ucs2",
"uefi-macros", "uefi-macros",
"uefi-raw",
"uguid",
] ]
[[package]] [[package]]
name = "uefi-macros" name = "uefi-macros"
version = "0.11.0" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0caeb0e7b31b9f1f347e541106be10aa8c66c76fa722a3298a4cd21433fabd4" checksum = "023d94ef8e135d068b9a3bd94614ef2610b2b0419ade0a9d8f3501fa9cd08e95"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.16",
]
[[package]]
name = "uefi-raw"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d5b1c8cd8a8a201bcc0d132f8367f5cb7c38c99a5debe304392d379963776d5"
dependencies = [
"bitflags",
"ptr_meta",
"uguid",
] ]
[[package]] [[package]]
name = "uefi-services" name = "uefi-services"
version = "0.17.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42d8ffbcc532083312224b4540737c1102ede6a81360fa9320a60deff329a3a1" checksum = "de55164b5fc3eddb8619add9fa14d91321bb337507e1f0d065a992060f1ccafc"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"log", "log",
"uefi", "uefi",
] ]
[[package]]
name = "uguid"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "594cc87e268a7b43d625d46c63cf1605d0e61bf66e4b1cd58c058ec0191e1f81"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.8" version = "1.0.8"

View File

@ -7,8 +7,8 @@ publish = false
rust-version = "1.68" rust-version = "1.68"
[dependencies] [dependencies]
uefi = { version = "0.20.0", default-features = false, features = [ "alloc", "global_allocator" ] } uefi = { version = "0.21.0", default-features = false, features = [ "alloc", "global_allocator" ] }
uefi-services = { version = "0.17.0", default-features = false, features = [ "panic_handler", "logger" ] } uefi-services = { version = "0.18.0", default-features = false, features = [ "panic_handler", "logger" ] }
goblin = { version = "0.6.1", default-features = false, features = [ "pe64", "alloc" ]} goblin = { version = "0.6.1", default-features = false, features = [ "pe64", "alloc" ]}
bitflags = "2.2.1" bitflags = "2.2.1"

View File

@ -142,7 +142,7 @@ where
runtime_services.set_variable(name, vendor, attributes, &get_fallback_value()?)?; runtime_services.set_variable(name, vendor, attributes, &get_fallback_value()?)?;
} }
uefi::Status::SUCCESS.into() Ok(())
} }
/// Exports systemd-stub style EFI variables /// Exports systemd-stub style EFI variables

View File

@ -122,7 +122,6 @@ impl InitrdLoader {
let mut proto = Box::pin(LoadFile2Protocol { let mut proto = Box::pin(LoadFile2Protocol {
load_file: raw_load_file, load_file: raw_load_file,
initrd_data, initrd_data,
_no_send_or_sync: Default::default(),
}); });
// Linux finds the right handle by looking for something that // Linux finds the right handle by looking for something that

View File

@ -21,19 +21,9 @@ use pe_loader::Image;
use pe_section::{pe_section, pe_section_as_string}; use pe_section::{pe_section, pe_section_as_string};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
use tpm::tpm_available; use tpm::tpm_available;
use uefi::{ use uefi::{prelude::*, proto::loaded_image::LoadedImage, CStr16, CString16, Result};
prelude::*,
proto::{
loaded_image::LoadedImage,
media::file::{File, FileAttribute, FileMode},
},
CStr16, CString16, Result,
};
use crate::{ use crate::{linux_loader::InitrdLoader, uefi_helpers::booted_image_file};
linux_loader::InitrdLoader,
uefi_helpers::{booted_image_file, read_all},
};
type Hash = sha2::digest::Output<Sha256>; type Hash = sha2::digest::Output<Sha256>;
@ -127,7 +117,7 @@ fn boot_linux_unchecked(
let status = unsafe { kernel.start(handle, &system_table, kernel_cmdline) }; let status = unsafe { kernel.start(handle, &system_table, kernel_cmdline) };
initrd_loader.uninstall(system_table.boot_services())?; initrd_loader.uninstall(system_table.boot_services())?;
status.into() status.to_result()
} }
/// Boot the Linux kernel via the UEFI PE loader. /// Boot the Linux kernel via the UEFI PE loader.
@ -173,7 +163,7 @@ fn boot_linux_uefi(
.status(); .status();
initrd_loader.uninstall(system_table.boot_services())?; initrd_loader.uninstall(system_table.boot_services())?;
status.into() status.to_result()
} }
#[entry] #[entry]
@ -203,33 +193,13 @@ fn main(handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
.boot_services() .boot_services()
.get_image_file_system(handle) .get_image_file_system(handle)
.expect("Failed to get file system handle"); .expect("Failed to get file system handle");
let mut root = file_system
.open_volume()
.expect("Failed to find ESP root directory");
let mut kernel_file = root kernel_data = file_system
.open( .read(&*config.kernel_filename)
&config.kernel_filename, .expect("Failed to read kernel file into memory");
FileMode::Read, initrd_data = file_system
FileAttribute::empty(), .read(&*config.initrd_filename)
) .expect("Failed to read initrd file into memory");
.expect("Failed to open kernel file for reading")
.into_regular_file()
.expect("Kernel is not a regular file");
kernel_data = read_all(&mut kernel_file).expect("Failed to read kernel file into memory");
let mut initrd_file = root
.open(
&config.initrd_filename,
FileMode::Read,
FileAttribute::empty(),
)
.expect("Failed to open initrd for reading")
.into_regular_file()
.expect("Initrd is not a regular file");
initrd_data = read_all(&mut initrd_file).expect("Failed to read kernel file into memory");
} }
let is_kernel_hash_correct = Sha256::digest(&kernel_data) == config.kernel_hash; let is_kernel_hash_correct = Sha256::digest(&kernel_data) == config.kernel_hash;

View File

@ -1,29 +1,6 @@
use core::ffi::c_void; use core::ffi::c_void;
use alloc::vec::Vec; use uefi::{prelude::BootServices, proto::loaded_image::LoadedImage, Result};
use uefi::{
prelude::BootServices,
proto::{loaded_image::LoadedImage, media::file::RegularFile},
Result,
};
/// Read the whole file into a vector.
pub fn read_all(file: &mut RegularFile) -> Result<Vec<u8>> {
let mut buf = Vec::new();
loop {
let mut chunk = [0; 512];
let read_bytes = file.read(&mut chunk).map_err(|e| e.status())?;
if read_bytes == 0 {
break;
}
buf.extend_from_slice(&chunk[0..read_bytes]);
}
Ok(buf)
}
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct PeInMemory { pub struct PeInMemory {