From d3981d211d2aaae8a3e8374bb1b6459b99347022 Mon Sep 17 00:00:00 2001 From: ICRA Date: Sun, 29 Nov 2026 13:28:05 +0500 Subject: [PATCH] Update uefi crate to 0.41 --- Cargo.lock | 567 ++++++++++++++----------------- Changelog.md | 3 +- examples/basic/Cargo.lock | 193 ++++++----- examples/basic/Cargo.toml | 4 +- examples/basic/kernel/Cargo.toml | 6 +- tests/test_kernels/Cargo.lock | 16 +- uefi/Cargo.toml | 11 +- uefi/src/graphics.rs | 125 +++++++ uefi/src/io.rs | 133 ++++++++ uefi/src/main.rs | 451 ++++-------------------- uefi/src/memory_descriptor.rs | 12 +- uefi/src/page_tables.rs | 77 +++++ uefi/src/protocols.rs | 68 ++++ uefi/src/system_info.rs | 43 +++ 14 files changed, 886 insertions(+), 823 deletions(-) create mode 100644 uefi/src/graphics.rs create mode 100644 uefi/src/io.rs create mode 100644 uefi/src/page_tables.rs create mode 100644 uefi/src/protocols.rs create mode 100644 uefi/src/system_info.rs diff --git a/Cargo.lock b/Cargo.lock index 4c1a99f4..6ecb42b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "anyhow" -version = "1.0.102" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902" [[package]] name = "arrayvec" @@ -23,12 +23,6 @@ dependencies = [ "critical-section", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bincode" version = "1.3.3" @@ -40,9 +34,9 @@ dependencies = [ [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "cb2907cc03d08cdb1c6724ad0670ce67c4a71e1c45a6d7635224011714cfc4b1" [[package]] name = "bitflags" @@ -52,15 +46,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.13.1" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "bitvec" -version = "1.0.1" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837" dependencies = [ "funty", "radium", @@ -136,7 +130,7 @@ dependencies = [ "bootloader_api", "log", "rsdp", - "serde-json-core", + "serde-json-core 0.5.1", "usize_conversions", "x86_64", ] @@ -168,8 +162,9 @@ dependencies = [ "bootloader-x86_64-common", "bootloader_api", "log", - "serde-json-core", + "serde-json-core 0.7.0", "uefi", + "uefi-raw", "x86_64", ] @@ -189,17 +184,23 @@ dependencies = [ "strip-ansi-escapes", ] +[[package]] +name = "bumpalo" +version = "3.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" + [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" [[package]] name = "conquer-once" @@ -224,18 +225,18 @@ checksum = "413d67b29ef1021b4d60f4aa1e925ca031751e213832b4b1d588fae623c05c60" [[package]] name = "crc" -version = "3.0.1" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d" dependencies = [ "crc-catalog", ] [[package]] name = "crc-catalog" -version = "2.2.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" +checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" [[package]] name = "critical-section" @@ -243,17 +244,11 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" -[[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - [[package]] name = "errno" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776" dependencies = [ "libc", "windows-sys", @@ -261,9 +256,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "fatfs" @@ -276,23 +271,41 @@ dependencies = [ "log", ] -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "libc", @@ -301,15 +314,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", "libc", "r-efi", - "wasip2", - "wasip3", ] [[package]] @@ -318,7 +329,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8283e7331b8c93b9756e0cfdbcfb90312852f953c6faf9bf741e684cc3b6ad69" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", "crc", "log", "uuid", @@ -334,20 +345,14 @@ dependencies = [ ] [[package]] -name = "hashbrown" -version = "0.15.5" +name = "hash32" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" dependencies = [ - "foldhash", + "byteorder", ] -[[package]] -name = "hashbrown" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" - [[package]] name = "heapless" version = "0.7.17" @@ -355,53 +360,45 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" dependencies = [ "atomic-polyfill", - "hash32", + "hash32 0.2.1", "rustc_version", "spin", "stable_deref_trait", ] [[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - -[[package]] -name = "indexmap" -version = "2.14.0" +name = "heapless" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +checksum = "411fdef4df93751117bd9ef8caa0e7f99c65dafec5bd84313eb8e2fdd75e32f2" dependencies = [ - "equivalent", - "hashbrown 0.17.1", - "serde", + "hash32 0.3.1", "serde_core", + "stable_deref_trait", ] [[package]] name = "itoa" -version = "1.0.8" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b02a5381cc465bd3041d84623d0fa3b66738b52b8e2fc3bab8ad63ab032f4a" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" [[package]] -name = "leb128fmt" -version = "0.1.0" +name = "js-sys" +version = "0.3.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] [[package]] name = "libc" -version = "0.2.186" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "linux-raw-sys" @@ -417,19 +414,18 @@ checksum = "955be5d0ca0465caf127165acb47964f911e2bc26073e865deb8be7189302faf" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ - "autocfg", "scopeguard", ] [[package]] name = "log" -version = "0.4.19" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" [[package]] name = "mbr-nostd" @@ -442,9 +438,9 @@ dependencies = [ [[package]] name = "mbrman" -version = "0.5.2" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c487024623ae38584610237dd1be8932bb2b324474b23c37a25f9fbe6bf5e9e" +checksum = "b1fc3bff63c208d4a14301c6cb807af2d1a0760052584ce3f9a737b55fb85498" dependencies = [ "bincode", "bitvec", @@ -453,6 +449,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + [[package]] name = "noto-sans-mono-bitmap" version = "0.1.6" @@ -478,55 +480,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa50141d081512ab30fd9e7e7692476866df5098b028536ad6680212e717fa8d" [[package]] -name = "ppv-lite86" -version = "0.2.17" +name = "pin-project-lite" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" [[package]] -name = "prettyplease" -version = "0.2.37" +name = "ppv-lite86" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "proc-macro2", - "syn", + "zerocopy", ] [[package]] name = "proc-macro2" -version = "1.0.106" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" dependencies = [ "unicode-ident", ] [[package]] name = "ptr_meta" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9a0cf95a1196af61d4f1cbdab967179516d9a4a4312af1f31948f8f6224a79" +checksum = "743da816b98c921cdbe8628ef7381b76f25ecf4da599fc80aca90eae7ef70cc0" dependencies = [ "ptr_meta_derive", ] [[package]] name = "ptr_meta_derive" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7347867d0a7e1208d93b46767be83e2b8f978c3dad35f775ac8d8847551d6fe1" +checksum = "1c8d9ca532f185d5d4db7a7c9d51420b452168ea1c2b913953281bd6fe1fcbd0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.10", ] [[package]] name = "quote" -version = "1.0.45" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" dependencies = [ "proc-macro2", ] @@ -545,9 +546,9 @@ checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" [[package]] name = "rand" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" dependencies = [ "libc", "rand_chacha", @@ -570,7 +571,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.2.17", ] [[package]] @@ -593,29 +594,29 @@ dependencies = [ [[package]] name = "rsdp" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d3add2fc55ef37511bcf81a08ee7a09eff07b23aae38b06a29024a38c604b1" +checksum = "1ed5f33bb98eace335c13cdd159fbfc73ce203b597981a76832dfbb9cbd8101b" dependencies = [ "log", ] [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", "errno", "libc", "linux-raw-sys", @@ -624,33 +625,33 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.13" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc31bd9b61a32c31f9650d18add92aa83a49ba979c143eefd27fe7177b05bd5f" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" [[package]] name = "ryu" -version = "1.0.14" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe232bdf6be8c8de797b22184ee71118d63780ea42ac85b61d1baa6d3b782ae9" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "semver" -version = "1.0.17" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" [[package]] name = "serde" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" dependencies = [ "serde_core", "serde_derive", @@ -658,60 +659,79 @@ dependencies = [ [[package]] name = "serde-big-array" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3323f09a748af288c3dc2474ea6803ee81f118321775bffa3ac8f7e65c5e90e7" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" dependencies = [ "serde", ] [[package]] name = "serde-json-core" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58ec3c8fe427f45ee3aaa0ebb9f0d9ab8ae9ad05d12047fe7249ae5ea9374ff0" +checksum = "3c9e1ab533c0bc414c34920ec7e5f097101d126ed5eac1a1aac711222e0bbb33" dependencies = [ - "heapless", + "heapless 0.7.17", + "ryu", + "serde", +] + +[[package]] +name = "serde-json-core" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e6795fbc00a1b26d78c7a0dbda143215d9dd0ee27c8a63ae0e1ccd6b83706" +dependencies = [ + "heapless 0.9.4", "ryu", "serde", ] [[package]] name = "serde_core" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.228" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.10", ] [[package]] name = "serde_json" -version = "1.0.100" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1e14e89be7aa4c4b78bdbdc9eb5bf8517829a600ae8eaa39a6e1d960b5185c" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", - "ryu", + "memchr", "serde", + "serde_core", + "zmij", ] +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "spin" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" dependencies = [ "lock_api", ] @@ -727,9 +747,9 @@ dependencies = [ [[package]] name = "stable_deref_trait" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "strip-ansi-escapes" @@ -742,9 +762,20 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.117" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" dependencies = [ "proc-macro2", "quote", @@ -764,7 +795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.2", + "getrandom 0.4.3", "once_cell", "rustix", "windows-sys", @@ -871,31 +902,31 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.41" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c16a64ba9387ef3fdae4f9c1a7f07a0997fce91985c0336f1ddc1822b3b37802" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.41" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d14928354b01c4d6a4f0e549069adef399a284e7995c7ccca94e8a07a5346c59" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.119", ] [[package]] name = "uart_16550" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9c24d1751f909d9e2d192475ca5527964e13dbc3126ce20c288dfa8f3a3e734" +checksum = "e1da273f7d8d9a37950980a0b75e680169c4cc47de6ed7dccf3749cbaf5976e2" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", ] [[package]] @@ -909,11 +940,11 @@ dependencies = [ [[package]] name = "uefi" -version = "0.38.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8f2e1b4a439d82899da4dc0ee8ac742db07a9ff493bc4f31d345c24e12e17e9" +checksum = "368cef7d94514897e6dad4350945c7910a9f5bf9021191d1c58ee3ec09962697" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", "cfg-if", "log", "ptr_meta", @@ -925,22 +956,22 @@ dependencies = [ [[package]] name = "uefi-macros" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4687412b5ac74d245d5bfb1733ede50c31be19bf8a4b6a967a29b451bab49e67" +checksum = "643efa8b64be89780bc498b290fab04337c7c4d171cc82cce2e133a74616dcc4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 3.0.10", ] [[package]] name = "uefi-raw" -version = "0.15.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8868c2fb03f31e55ccf9b47f72e17097bb88c45306cb82f5a2258935520c72d6" +checksum = "3636327a6d88a38c0f2567fb695ec7ba27b3483d1877730486605aa0866da201" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", "uguid", ] @@ -952,15 +983,9 @@ checksum = "0c8352f8c05e47892e7eaf13b34abd76a7f4aeaf817b716e88789381927f199c" [[package]] name = "unicode-ident" -version = "1.0.10" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73" - -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" [[package]] name = "usize_conversions" @@ -970,17 +995,19 @@ checksum = "f70329e2cbe45d6c97a5112daad40c34cd9a4e18edb5a2a18fefeb584d8d25e5" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.4.0" +version = "1.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be" +checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64" dependencies = [ - "getrandom 0.2.10", + "getrandom 0.4.3", + "js-sys", + "wasm-bindgen", ] [[package]] @@ -1002,9 +1029,9 @@ dependencies = [ [[package]] name = "vte_generate_state_changes" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d257817081c7dffcdbab24b9e62d2def62e2ff7d00b1c20062551e6cccc145ff" +checksum = "2e369bee1b05d510a7b4ed645f5faa90619e05437111783ea5848f28d97d3c2e" dependencies = [ "proc-macro2", "quote", @@ -1012,60 +1039,52 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "wasip2" -version = "1.0.3+wasi-0.2.9" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" -dependencies = [ - "wit-bindgen 0.57.1", -] +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +name = "wasm-bindgen" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" dependencies = [ - "wit-bindgen 0.51.0", + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", ] [[package]] -name = "wasm-encoder" -version = "0.244.0" +name = "wasm-bindgen-macro" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" dependencies = [ - "leb128fmt", - "wasmparser", + "quote", + "wasm-bindgen-macro-support", ] [[package]] -name = "wasm-metadata" -version = "0.244.0" +name = "wasm-bindgen-macro-support" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.10", + "wasm-bindgen-shared", ] [[package]] -name = "wasmparser" -version = "0.244.0" +name = "wasm-bindgen-shared" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" dependencies = [ - "bitflags 2.13.1", - "hashbrown 0.15.5", - "indexmap", - "semver", + "unicode-ident", ] [[package]] @@ -1083,100 +1102,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen" -version = "0.57.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags 2.13.1", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - [[package]] name = "wyz" version = "0.5.1" @@ -1193,7 +1118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4ec631e1a81d50e46c35a4a00322bd076c47491b64c2fb10a7ffa89002c697" dependencies = [ "bit_field", - "bitflags 2.13.1", + "bitflags 2.13.2", "const_fn", "rustversion", "volatile", @@ -1213,3 +1138,29 @@ name = "zero" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fe21bcc34ca7fe6dd56cc2cb1261ea59d6b93620215aefb5ea6032265527784" + +[[package]] +name = "zerocopy" +version = "0.8.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba8a86aee14fc8cc6c208af60854b3d4ab7185a9a369a12c648faa2716ff42a" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89bca3b96ceb3cfcb4572790402f977442270d252b9a8504ebc258760c55f94" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Changelog.md b/Changelog.md index 3e308d51..c431ec2a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,6 @@ # Unreleased +- Bump `uefi` from `0.38` to `0.41` - When booting on UEFI, whatever is written to the UEFI console (e.g., via the SIMPLE_TEXT_OUTPUT_PROTOCOL) is no longer replicated to the serial device. The bootloader's own logger now takes full ownership of the @@ -272,7 +273,7 @@ See our [migration guides](docs/migration/README.md) for details. # 0.10.0 – 2021-04-06 - Rewrite for UEFI support ([#130](https://github.com/rust-osdev/bootloader/pull/130)) - - Includes a new build process that no longer uses the `bootimage` crate. See the Readme for details. + - Includes a new build process that no longer uses the `bootimage` crate. See the Readme for details. # 0.9.19 _(backport) – 2021-08-09 diff --git a/examples/basic/Cargo.lock b/examples/basic/Cargo.lock index 74f02b41..651f125e 100644 --- a/examples/basic/Cargo.lock +++ b/examples/basic/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "anyhow" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902" [[package]] name = "base16ct" @@ -16,9 +16,9 @@ checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" [[package]] name = "base64" -version = "0.22.1" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" [[package]] name = "basic" @@ -40,9 +40,9 @@ dependencies = [ [[package]] name = "bit_field" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" +checksum = "cb2907cc03d08cdb1c6724ad0670ce67c4a71e1c45a6d7635224011714cfc4b1" [[package]] name = "bitflags" @@ -52,9 +52,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.13.1" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "bitvec" @@ -79,9 +79,9 @@ dependencies = [ [[package]] name = "bootloader" -version = "0.11.16" +version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "873ecb966ce2cf2d9e56247422f892f7daee8dbdac58945035d348885e582b74" +checksum = "d861319d747a01da5d4d680500b7f808607f902a286b476bd51f991612e39d8e" dependencies = [ "anyhow", "bootloader-boot-config", @@ -95,24 +95,24 @@ dependencies = [ [[package]] name = "bootloader-boot-config" -version = "0.11.16" +version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae46c9f7079e4d28b86015cdc2588c7e3d77441fe96449858c44644a78960f34" +checksum = "4b688f587df1a3157a22f82d5f6426e8625d13d0706a4672424398aaee7e33cd" dependencies = [ "serde", ] [[package]] name = "bootloader_api" -version = "0.11.16" +version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "895bece39f47cd2063425b9361c0be662c7e2cf0922471ea16312d853600feb3" +checksum = "49f4c2ef60a76c1858ef43c30b6b95c2f5ee4d7c4f9bc47409c3a8dc8910adb9" [[package]] name = "bumpalo" -version = "3.20.3" +version = "3.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" [[package]] name = "byteorder" @@ -122,15 +122,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.12.1" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" +checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" [[package]] name = "cc" -version = "1.3.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89588d05638b5b4594a3348a2d6c20277e43a7f5c5202b05cc56888475a47b8" +checksum = "95e45cf2980b2d467be49a9ed942c9179b701063a7ca3d037de7ee9bd67f8d66" dependencies = [ "find-msvc-tools", "shlex", @@ -138,15 +138,15 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" [[package]] name = "const-oid" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" +checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a" [[package]] name = "const_fn" @@ -156,9 +156,9 @@ checksum = "413d67b29ef1021b4d60f4aa1e925ca031751e213832b4b1d588fae623c05c60" [[package]] name = "cpufeatures" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" dependencies = [ "libc", ] @@ -200,9 +200,9 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776" dependencies = [ "libc", "windows-sys 0.61.2", @@ -227,9 +227,9 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.29" +version = "0.2.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +checksum = "e1255e7a9f1902190d4c10a75f2f7f495d3d3ce13e9ba26e6c48683a0f4dbed7" dependencies = [ "cfg-if", "libc", @@ -237,9 +237,9 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.9" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8" [[package]] name = "funty" @@ -249,21 +249,21 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures-core" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cd50c473c80f6d7c3670a752354b8e569b1a7cbfdc0419ec88e5edad85e0dc7" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" [[package]] name = "futures-task" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b231ed28831efb4a61a08580c4bc233ec56bc009f4cd8f52da2c3cb97df0c109" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" [[package]] name = "futures-util" -version = "0.3.33" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a77a90a256fce34da66415271e30f94ee91c57b04b8a2c042d9cf3220179deaa" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ "futures-core", "futures-task", @@ -299,7 +299,7 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8283e7331b8c93b9756e0cfdbcfb90312852f953c6faf9bf741e684cc3b6ad69" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", "crc", "log", "uuid", @@ -307,9 +307,9 @@ dependencies = [ [[package]] name = "http" -version = "1.4.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6970f50e31d6fc17d3fa27329444bfa74e196cf62e95052a3f6fee181dba6425" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" dependencies = [ "bytes", "itoa", @@ -323,24 +323,24 @@ checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" [[package]] name = "hybrid-array" -version = "0.4.13" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818356c5132c1fede50f837ca96afbe78ff42413047f4abb886217845e1b6c8c" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" dependencies = [ "typenum", ] [[package]] name = "itoa" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" [[package]] name = "js-sys" -version = "0.3.103" +version = "0.3.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" dependencies = [ "cfg-if", "futures-util", @@ -358,9 +358,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.187" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7743783ea728ef5c31194c6590797eed286449b4a4e87d626d8a51f0a94e732" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "linux-raw-sys" @@ -376,9 +376,9 @@ checksum = "955be5d0ca0465caf127165acb47964f911e2bc26073e865deb8be7189302faf" [[package]] name = "log" -version = "0.4.33" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" [[package]] name = "lzma-rs" @@ -437,9 +437,9 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pin-project-lite" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" [[package]] name = "proc-macro2" @@ -487,11 +487,11 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", "errno", "libc", "linux-raw-sys", @@ -500,9 +500,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.42" +version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c54fcab019b409d04215d3a17cb438fd7fbf192ee61461f20f4fe18704bc138" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ "log", "once_cell", @@ -515,18 +515,18 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "764899a24af3980067ee14bc143654f297b22eaebfe3c7b6b211920a5a59b046" +checksum = "102f35f7de7b06d8c61f1cff6592f5253e0dea431c74867aad5dfd70f44663fb" dependencies = [ "zeroize", ] [[package]] name = "rustls-webpki" -version = "0.103.13" +version = "0.103.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" +checksum = "e3a0760a887c14823fca5a1c970b01d47c328c696c0c64829d1df50e8f853fd5" dependencies = [ "ring", "rustls-pki-types", @@ -575,14 +575,14 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.2", + "syn 3.0.10", ] [[package]] name = "serde_json" -version = "1.0.151" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", "memchr", @@ -593,9 +593,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +checksum = "5b0e5c7d67bc53f435386b2130fdc900488c5703770f6d8a4633060e34288a27" dependencies = [ "cfg-if", "cpufeatures", @@ -633,9 +633,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.2" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a207d6d6a2b7fc470b80443726053f18a2481b7e1eee970597051596567987a3" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" dependencies = [ "proc-macro2", "quote", @@ -700,18 +700,18 @@ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "uart_16550" -version = "0.6.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ee77075ecbc5e1c9b1236d03ff013dd77c7bb06da181c5c44f1f39b6cf3ff2" +checksum = "a97f2587e2352cdee51c1f55c3eef6ddd4bcb08a9119bfbce800dd4a198fc42a" dependencies = [ - "bitflags 2.13.1", + "bitflags 2.13.2", ] [[package]] name = "unicode-ident" -version = "1.0.24" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" [[package]] name = "untrusted" @@ -721,9 +721,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "ureq" -version = "3.3.0" +version = "3.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea7109cdcd5864d4eeb1b58a1648dc9bf520360d7af16ec26d0a9354bafcfc0" +checksum = "3ac5cecf619ca81f66a96482db09687c9f7465af65f4300a8c30cca05bd5a59d" dependencies = [ "base64", "log", @@ -737,9 +737,9 @@ dependencies = [ [[package]] name = "ureq-proto" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e994ba84b0bd1b1b0cf92878b7ef898a5c1760108fe7b6010327e274917a808c" +checksum = "622dce33c252115466d83f63e9744a18f12b4406aae51a01c15ad8fcf1185eb3" dependencies = [ "base64", "http", @@ -755,9 +755,9 @@ checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" [[package]] name = "uuid" -version = "1.24.0" +version = "1.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf3923a6f5c4c6382e0b653c4117f48d631ea17f38ed86e2a828e6f7412f5239" +checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64" dependencies = [ "getrandom 0.4.3", "js-sys", @@ -778,12 +778,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasm-bindgen" -version = "0.2.126" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" dependencies = [ "cfg-if", - "once_cell", "rustversion", "wasm-bindgen-macro", "wasm-bindgen-shared", @@ -791,9 +790,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.126" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -801,31 +800,31 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.126" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.10", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.126" +version = "0.2.130" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" dependencies = [ "unicode-ident", ] [[package]] name = "webpki-roots" -version = "1.0.9" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +checksum = "7265c9301c16a8711c992c2d8da90ee77ef54b1ed51482d6dfeb00dc756b1297" dependencies = [ "rustls-pki-types", ] @@ -934,7 +933,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4ec631e1a81d50e46c35a4a00322bd076c47491b64c2fb10a7ffa89002c697" dependencies = [ "bit_field", - "bitflags 2.13.1", + "bitflags 2.13.2", "const_fn", "rustversion", "volatile", @@ -942,9 +941,9 @@ dependencies = [ [[package]] name = "xattr" -version = "1.6.1" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +checksum = "963d6fab92d5504b971dc8bd90ca743c2575e590bc8071ea5bc571598667ae08" dependencies = [ "libc", "rustix", @@ -952,9 +951,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.9.0" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa" [[package]] name = "zmij" diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml index 1bcde379..cdad3d8f 100644 --- a/examples/basic/Cargo.toml +++ b/examples/basic/Cargo.toml @@ -8,8 +8,8 @@ version = "0.1.0" edition = "2024" [dependencies] -ovmf-prebuilt = "0.2.4" +ovmf-prebuilt = "0.2" [build-dependencies] kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" } -bootloader = "0.11.12" +bootloader = "0.11.17" diff --git a/examples/basic/kernel/Cargo.toml b/examples/basic/kernel/Cargo.toml index 2ec60ce8..92fc0119 100644 --- a/examples/basic/kernel/Cargo.toml +++ b/examples/basic/kernel/Cargo.toml @@ -4,6 +4,6 @@ version = "0.1.0" edition = "2024" [dependencies] -bootloader_api = "0.11.12" -uart_16550 = "0.8.0" -x86_64 = "0.15.2" +bootloader_api = "0.11" +uart_16550 = "0.9" +x86_64 = "0.15" diff --git a/tests/test_kernels/Cargo.lock b/tests/test_kernels/Cargo.lock index ba73a5b0..ded05c0e 100644 --- a/tests/test_kernels/Cargo.lock +++ b/tests/test_kernels/Cargo.lock @@ -4,15 +4,15 @@ version = 4 [[package]] name = "bit_field" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" +checksum = "cb2907cc03d08cdb1c6724ad0670ce67c4a71e1c45a6d7635224011714cfc4b1" [[package]] name = "bitflags" -version = "2.13.0" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "bootloader_api" @@ -26,9 +26,9 @@ checksum = "413d67b29ef1021b4d60f4aa1e925ca031751e213832b4b1d588fae623c05c60" [[package]] name = "rustversion" -version = "1.0.19" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" [[package]] name = "test_kernel_config_file" @@ -140,9 +140,9 @@ dependencies = [ [[package]] name = "uart_16550" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9c24d1751f909d9e2d192475ca5527964e13dbc3126ce20c288dfa8f3a3e734" +checksum = "e1da273f7d8d9a37950980a0b75e680169c4cc47de6ed7dccf3749cbaf5976e2" dependencies = [ "bitflags", ] diff --git a/uefi/Cargo.toml b/uefi/Cargo.toml index 252f546c..e9f1ae27 100644 --- a/uefi/Cargo.toml +++ b/uefi/Cargo.toml @@ -6,13 +6,12 @@ description = "UEFI bootloader for x86_64" license.workspace = true repository.workspace = true -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] bootloader_api = { workspace = true } bootloader-x86_64-common = { workspace = true } bootloader-boot-config = { workspace = true } -log = "0.4.14" -x86_64 = "0.15.2" -serde-json-core = "0.5.0" -uefi = "0.38.0" +log = "0.4" +x86_64 = "0.15" +serde-json-core = "0.7" +uefi = "0.41" +uefi-raw = "0.17" diff --git a/uefi/src/graphics.rs b/uefi/src/graphics.rs new file mode 100644 index 00000000..3e27efe4 --- /dev/null +++ b/uefi/src/graphics.rs @@ -0,0 +1,125 @@ +use bootloader_api::info::{self, FrameBufferInfo}; +use bootloader_boot_config::BootConfig; +use bootloader_x86_64_common::{RawFrameBufferInfo, init_logger}; +use core::slice; +use uefi::{ + Identify, + boot::{self, OpenProtocolAttributes, OpenProtocolParams, SearchType}, + prelude::Handle, + proto::console::{ + gop::{GraphicsOutput, PixelFormat}, + serial::Serial, + }, +}; +use x86_64::PhysAddr; + +pub fn init_graphic(image_handle: Handle, config: &BootConfig) -> Option { + let gop_handle = boot::get_handle_for_protocol::() + .map_err(|e| log::error!("No GOP handle found: {e:?}")) + .ok()?; + + let mut gop = unsafe { + boot::open_protocol::( + OpenProtocolParams { + handle: gop_handle, + agent: image_handle, + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + .map_err(|e| log::error!("Failed to open GOP: {e:?}")) + .ok()? + }; + + let mode = { + let min_h = config + .frame_buffer + .minimum_framebuffer_height + .map(|v| usize::try_from(v).unwrap()); + let min_w = config + .frame_buffer + .minimum_framebuffer_width + .map(|v| usize::try_from(v).unwrap()); + + match (min_h, min_w) { + (Some(h), Some(w)) => gop.modes().find(|m| { + let (mw, mh) = m.info().resolution(); + mh >= h && mw >= w + }), + (Some(h), None) => gop.modes().find(|m| m.info().resolution().1 >= h), + (None, Some(w)) => gop.modes().find(|m| m.info().resolution().0 >= w), + _ => None, + } + }; + + if let Some(mode) = mode { + gop.set_mode(&mode).expect("Failed to set GOP display mode"); + } + + let mode_info = gop.current_mode_info(); + let (width, height) = mode_info.resolution(); + let stride = mode_info.stride(); + + let pixel_format = match mode_info.pixel_format() { + PixelFormat::Rgb => info::PixelFormat::Rgb, + PixelFormat::Bgr => info::PixelFormat::Bgr, + PixelFormat::Bitmask | PixelFormat::BltOnly => { + panic!("Bitmask and BltOnly pixel formats are not supported") + } + }; + + let mut pat = x86_64::registers::model_specific::Msr::new(0x277); + let mut pat_value = unsafe { pat.read() }; + + let mut wc_slot = None; + for i in 0..8 { + let type_byte = (pat_value >> (i * 8)) & 0xFF; + if type_byte == 0x01 { + wc_slot = Some(i); + break; + } + } + + if wc_slot.is_none() { + pat_value = (pat_value & !(0xFF << 32)) | (0x01 << 32); + unsafe { pat.write(pat_value) }; + } + + let mut framebuffer = gop.frame_buffer(); + let fb_size = framebuffer.size(); + let bytes_per_pixel = if stride > 0 && height > 0 { + (fb_size / (stride * height)).max(4) + } else { + 4 + }; + let slice = unsafe { slice::from_raw_parts_mut(framebuffer.as_mut_ptr(), fb_size) }; + + let info = FrameBufferInfo { + byte_len: fb_size, + width, + height, + pixel_format, + bytes_per_pixel, + stride, + }; + + // Added solely to ensure integration tests pass by detaching the UEFI serial driver from COM1. + if let Ok(handles) = boot::locate_handle_buffer(SearchType::ByProtocol(&Serial::GUID)) { + for handle in handles.iter() { + let _ = boot::disconnect_controller(*handle, None, None); + } + } + + init_logger( + slice, + info, + config.log_level, + config.frame_buffer_logging, + config.serial_logging, + ); + + Some(RawFrameBufferInfo { + addr: PhysAddr::new(framebuffer.as_mut_ptr() as u64), + info, + }) +} diff --git a/uefi/src/io.rs b/uefi/src/io.rs new file mode 100644 index 00000000..6d02fca8 --- /dev/null +++ b/uefi/src/io.rs @@ -0,0 +1,133 @@ +use crate::protocols::locate_and_open_protocol; +use bootloader_x86_64_common::Kernel; +use core::{net::IpAddr, ptr, slice}; +use uefi::{ + CStr8, CStr16, + boot::{self, AllocateType, MemoryType}, + prelude::Handle, + proto::{ + media::{ + file::{File, FileAttribute, FileInfo, FileMode}, + fs::SimpleFileSystem, + }, + network::pxe::BaseCode, + }, +}; + +#[derive(Clone, Copy, Debug)] +pub enum BootMode { + Disk, + Tftp, +} + +pub fn load_kernel(image: Handle, boot_mode: BootMode) -> Option> { + let slice = load_file(image, "kernel-x86_64\0", boot_mode)?; + Some(Kernel::parse(slice)) +} + +pub fn load_config_file(image: Handle, boot_mode: BootMode) -> Option<&'static mut [u8]> { + load_file(image, "boot.json\0", boot_mode) +} + +pub fn load_ramdisk(image: Handle, boot_mode: BootMode) -> Option<&'static mut [u8]> { + load_file(image, "ramdisk\0", boot_mode) +} + +fn load_file(image: Handle, filename: &str, boot_mode: BootMode) -> Option<&'static mut [u8]> { + match boot_mode { + BootMode::Disk => load_from_disk(filename, image), + BootMode::Tftp => load_from_tftp(filename, image), + } +} + +fn load_from_disk(name: &str, image: Handle) -> Option<&'static mut [u8]> { + let mut fs_raw = locate_and_open_protocol::(image)?; + let fs = &mut *fs_raw; + + let mut root = fs + .open_volume() + .map_err(|e| log::error!("open_volume failed: {e:?}")) + .ok()?; + + let mut buf = [0u16; 256]; + let name_trimmed = name.trim_end_matches('\0'); + assert!(name_trimmed.len() < 256, "filename too long"); + + let filename = CStr16::from_str_with_buf(name_trimmed, &mut buf) + .expect("Failed to convert filename to UTF-16"); + + let file_handle = root + .open(filename, FileMode::Read, FileAttribute::empty()) + .ok()?; + + let mut file = match file_handle.into_type().unwrap() { + uefi::proto::media::file::FileType::Regular(f) => f, + uefi::proto::media::file::FileType::Dir(_) => { + log::error!("Expected file, got directory: {name}"); + return None; + } + }; + + let mut info_buf = [0u8; 512]; + let file_info: &mut FileInfo = file + .get_info(&mut info_buf) + .map_err(|e| log::error!("get_info failed: {e:?}")) + .ok()?; + let file_size = usize::try_from(file_info.file_size()).unwrap(); + + let ptr = allocate_pages(file_size)?; + let slice = unsafe { slice::from_raw_parts_mut(ptr, file_size) }; + file.read(slice) + .map_err(|e| log::error!("file read failed: {e:?}")) + .ok()?; + + Some(slice) +} + +fn load_from_tftp(name: &str, image: Handle) -> Option<&'static mut [u8]> { + let mut base_code_raw = locate_and_open_protocol::(image)?; + let base_code = &mut *base_code_raw; + + let mode = base_code.mode(); + assert!( + mode.dhcp_ack_received(), + "DHCP ACK not received — TFTP boot unavailable" + ); + + let packet_ptr = core::ptr::from_ref::(mode.dhcp_ack()); + let dhcpv4_ptr = packet_ptr.cast::(); + let dhcpv4 = unsafe { &*dhcpv4_ptr }; + let server_ip: IpAddr = IpAddr::V4(core::net::Ipv4Addr::from(dhcpv4.bootp_si_addr)); + + assert!(name.len() < 256, "TFTP filename too long"); + let filename = CStr8::from_bytes_with_nul(name.as_bytes()) + .expect("filename must be null-terminated ASCII"); + + let file_size = base_code + .tftp_get_file_size(&server_ip, filename) + .map_err(|e| log::error!("tftp_get_file_size failed: {e:?}")) + .ok()?; + + let kernel_size = usize::try_from(file_size).expect("file size overflows usize"); + let ptr = allocate_pages(kernel_size)?; + let slice = unsafe { slice::from_raw_parts_mut(ptr, kernel_size) }; + + base_code + .tftp_read_file(&server_ip, filename, Some(slice)) + .map_err(|e| log::error!("tftp_read_file failed: {e:?}")) + .ok()?; + + Some(slice) +} + +fn allocate_pages(size: usize) -> Option<*mut u8> { + let pages = size.div_ceil(4096); + let nn_ptr = boot::allocate_pages(AllocateType::AnyPages, MemoryType::LOADER_DATA, pages) + .map_err(|e| log::error!("allocate_pages failed: {e:?}")) + .ok()?; + + let ptr = nn_ptr.as_ptr(); + + unsafe { ptr::write_bytes(ptr, 0, size) }; + Some(ptr) +} diff --git a/uefi/src/main.rs b/uefi/src/main.rs index 928a290d..54e7c479 100644 --- a/uefi/src/main.rs +++ b/uefi/src/main.rs @@ -2,71 +2,44 @@ #![no_main] #![deny(unsafe_op_in_unsafe_fn)] +mod graphics; +mod io; +mod memory_descriptor; +mod page_tables; +mod protocols; +mod system_info; + use crate::memory_descriptor::UefiMemoryDescriptor; -use bootloader_api::info::FrameBufferInfo; use bootloader_boot_config::BootConfig; use bootloader_x86_64_common::{ - Kernel, RawFrameBufferInfo, SystemInfo, legacy_memory_region::LegacyFrameAllocator, + legacy_memory_region::LegacyFrameAllocator, load_and_switch_to_kernel, }; -use core::net::Ipv4Addr; -use core::{ptr, slice}; -use uefi::boot::SearchType; -use uefi::mem::memory_map::{MemoryMap, MemoryMapMut}; -use uefi::proto::console::serial::Serial; -use uefi::table::cfg::ConfigTableEntry; +use io::BootMode; use uefi::{ - CStr8, CStr16, Identify, boot, - boot::{AllocateType, MemoryType}, - cstr8, cstr16, - prelude::{Status, entry}, - proto::{ - ProtocolPointer, - console::gop::{GraphicsOutput, PixelFormat}, - device_path::DevicePath, - loaded_image::LoadedImage, - media::file::{File, FileAttribute, FileInfo, FileMode}, - network::pxe::{BaseCode, DhcpV4Packet}, - }, -}; -use x86_64::{ - PhysAddr, VirtAddr, - structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB}, + boot, helpers, + mem::memory_map::{MemoryMap, MemoryMapMut}, + prelude::{Handle, Status, entry}, }; -mod memory_descriptor; - -struct BootFile { - disk: &'static CStr16, - tftp: &'static CStr8, +#[entry] +fn efi_main() -> Status { + helpers::init().unwrap(); + let image = boot::image_handle(); + main_inner(image) } -const KERNEL_FILE: BootFile = BootFile { - disk: cstr16!("kernel-x86_64"), - tftp: cstr8!("kernel-x86_64"), -}; -const CONFIG_FILE: BootFile = BootFile { - disk: cstr16!("boot.json"), - tftp: cstr8!("boot.json"), -}; -const RAMDISK_FILE: BootFile = BootFile { - disk: cstr16!("ramdisk"), - tftp: cstr8!("ramdisk"), -}; - -#[entry] -fn main() -> Status { +fn main_inner(image: Handle) -> Status { let mut boot_mode = BootMode::Disk; - - let mut kernel = load_kernel(boot_mode); + let mut kernel = io::load_kernel(image, boot_mode); if kernel.is_none() { - // Try TFTP boot boot_mode = BootMode::Tftp; - kernel = load_kernel(boot_mode); + kernel = io::load_kernel(image, boot_mode); } - let kernel = kernel.expect("Failed to load kernel"); + let kernel = kernel.expect("Failed to load kernel from disk or TFTP"); - let config_file = load_config_file(boot_mode); + let config_file = io::load_config_file(image, boot_mode); let mut error_loading_config: Option = None; + let mut config: BootConfig = match config_file .as_deref() .map(serde_json_core::from_slice) @@ -80,375 +53,77 @@ fn main() -> Status { }; #[allow(deprecated)] - if config.frame_buffer.minimum_framebuffer_height.is_none() { - config.frame_buffer.minimum_framebuffer_height = - kernel.config.frame_buffer.minimum_framebuffer_height; - } - #[allow(deprecated)] - if config.frame_buffer.minimum_framebuffer_width.is_none() { - config.frame_buffer.minimum_framebuffer_width = - kernel.config.frame_buffer.minimum_framebuffer_width; + { + if config.frame_buffer.minimum_framebuffer_height.is_none() { + config.frame_buffer.minimum_framebuffer_height = + kernel.config.frame_buffer.minimum_framebuffer_height; + } + if config.frame_buffer.minimum_framebuffer_width.is_none() { + config.frame_buffer.minimum_framebuffer_width = + kernel.config.frame_buffer.minimum_framebuffer_width; + } } - let framebuffer = init_logger(&config); - log::info!("UEFI bootloader started"); + let framebuffer = graphics::init_graphic(image, &config); - if let Some(framebuffer) = framebuffer { - log::info!("Using framebuffer at {:#x}", framebuffer.addr); + log::info!("UEFI bootloader started"); + if let Some(fb) = &framebuffer { + log::info!("Framebuffer at {:#x}", fb.addr); } - if let Some(err) = error_loading_config { - log::warn!("Failed to deserialize the config file {:?}", err); + log::warn!("Config parse error: {err:?}"); } else { - log::info!("Reading configuration from disk was successful"); + log::info!("Boot config loaded successfully"); } - log::info!("Trying to load ramdisk via {:?}", boot_mode); - // Ramdisk must load from same source, or not at all. - let ramdisk = load_ramdisk(boot_mode); - + log::info!("Loading ramdisk via {boot_mode:?}"); + let ramdisk = io::load_ramdisk(image, boot_mode); log::info!( "{}", - match ramdisk { - Some(_) => "Loaded ramdisk", - None => "Ramdisk not found.", + if ramdisk.is_some() { + "Ramdisk loaded" + } else { + "Ramdisk not found" } ); - log::trace!("exiting boot services"); - let mut memory_map = unsafe { boot::exit_boot_services(None) }; + log::trace!("Exiting boot services"); + let mut memory_map = unsafe { boot::exit_boot_services(Some(boot::MemoryType::LOADER_DATA)) }; memory_map.sort(); let mut frame_allocator = LegacyFrameAllocator::new(memory_map.entries().copied().map(UefiMemoryDescriptor)); let max_phys_addr = frame_allocator.max_phys_addr(); - let page_tables = create_page_tables(&mut frame_allocator, max_phys_addr, framebuffer.as_ref()); - let mut ramdisk_len = 0u64; - let ramdisk_addr = if let Some(rd) = ramdisk { - ramdisk_len = rd.len() as u64; - Some(rd.as_ptr() as usize as u64) - } else { - None - }; - let system_info = SystemInfo { - framebuffer, - rsdp_addr: { - uefi::system::with_config_table(|config_entries| { - // look for an ACPI2 RSDP first - let acpi2_rsdp = config_entries - .iter() - .find(|entry| matches!(entry.guid, ConfigTableEntry::ACPI2_GUID)); - // if no ACPI2 RSDP is found, look for a ACPI1 RSDP - let rsdp = acpi2_rsdp.or_else(|| { - config_entries - .iter() - .find(|entry| matches!(entry.guid, ConfigTableEntry::ACPI_GUID)) - }); - rsdp.map(|entry| PhysAddr::new(entry.address as u64)) - }) - }, - ramdisk_addr, - ramdisk_len, - }; - - bootloader_x86_64_common::load_and_switch_to_kernel( - kernel, - config, - frame_allocator, - page_tables, - system_info, - ); -} - -#[derive(Clone, Copy, Debug)] -pub enum BootMode { - Disk, - Tftp, -} - -fn load_ramdisk(boot_mode: BootMode) -> Option<&'static mut [u8]> { - load_file_from_boot_method(&RAMDISK_FILE, boot_mode) -} - -fn load_config_file(boot_mode: BootMode) -> Option<&'static mut [u8]> { - load_file_from_boot_method(&CONFIG_FILE, boot_mode) -} - -fn load_kernel(boot_mode: BootMode) -> Option> { - let kernel_slice = load_file_from_boot_method(&KERNEL_FILE, boot_mode)?; - Some(Kernel::parse(kernel_slice)) -} - -fn load_file_from_boot_method( - filename: &BootFile, - boot_mode: BootMode, -) -> Option<&'static mut [u8]> { - match boot_mode { - BootMode::Disk => load_file_from_disk(filename.disk), - BootMode::Tftp => load_file_from_tftp_boot_server(filename.tftp), - } -} - -fn load_file_from_disk(name: &CStr16) -> Option<&'static mut [u8]> { - let mut file_system = boot::get_image_file_system(boot::image_handle()).ok()?; - - let mut root = file_system.open_volume().unwrap(); - let file_handle_result = root.open(name, FileMode::Read, FileAttribute::empty()); - let file_handle = file_handle_result.ok()?; - - let mut file = match file_handle.into_type().unwrap() { - uefi::proto::media::file::FileType::Regular(f) => f, - uefi::proto::media::file::FileType::Dir(_) => panic!(), - }; - - let mut buf = [0; 500]; - let file_info: &mut FileInfo = file.get_info(&mut buf).unwrap(); - let file_size = usize::try_from(file_info.file_size()).unwrap(); - - let file_slice = allocate_loader_data(file_size); - file.read(file_slice).unwrap(); - - Some(file_slice) -} - -/// Try to load a kernel from a TFTP boot server. -fn load_file_from_tftp_boot_server(name: &CStr8) -> Option<&'static mut [u8]> { - let mut base_code = open_pxe_base_code()?; - - // Find the TFTP boot server. - let mode = base_code.mode(); - let dhcpv4: &DhcpV4Packet = mode.dhcp_ack().as_ref(); - let server_ip = Ipv4Addr::from_octets(dhcpv4.bootp_si_addr); - - // Determine the kernel file size. - let file_size = base_code.tftp_get_file_size(&server_ip.into(), name).ok()?; - let kernel_size = usize::try_from(file_size).expect("The file size should fit into usize"); - - // Allocate some memory for the kernel file. - let slice = allocate_loader_data(kernel_size); - - // Load the kernel file. - base_code - .tftp_read_file(&server_ip.into(), name, Some(slice)) - .expect("Failed to read kernel file from the TFTP boot server"); - - Some(slice) -} - -fn allocate_loader_data(size: usize) -> &'static mut [u8] { - let mut ptr = boot::allocate_pages( - AllocateType::AnyPages, - MemoryType::LOADER_DATA, - ((size - 1) / 4096) + 1, - ) - .expect("Failed to allocate memory for the file"); - unsafe { ptr::write_bytes(ptr.as_ptr(), 0, size) }; - unsafe { slice::from_raw_parts_mut(ptr.as_ptr(), size) } -} - -/// Opens PXE Base Code for the device path that loaded this image. -/// -/// Firmware may expose multiple PXE handles. Resolving through the loaded -/// image's device path keeps TFTP reads tied to the booting network device. -fn open_pxe_base_code() -> Option> { - let base_code = locate_and_open_protocol_from_image_device_path::()?; - base_code.mode().dhcp_ack_received().then_some(base_code) -} - -fn locate_and_open_protocol_from_image_device_path() --> Option> { - let image_handle = boot::image_handle(); - let loaded_image = boot::open_protocol_exclusive::(image_handle).ok()?; - let device_handle = loaded_image.device()?; - let device_path = boot::open_protocol_exclusive::(device_handle).ok()?; - let handle = boot::locate_device_path::

(&mut &*device_path).ok()?; - boot::open_protocol_exclusive::

(handle).ok() -} - -/// Creates page table abstraction types for both the bootloader and kernel page tables. -fn create_page_tables( - frame_allocator: &mut impl FrameAllocator, - max_phys_addr: PhysAddr, - frame_buffer: Option<&RawFrameBufferInfo>, -) -> bootloader_x86_64_common::PageTables { - // UEFI identity-maps all memory, so the offset between physical and virtual addresses is 0 - let phys_offset = VirtAddr::new(0); - - // copy the currently active level 4 page table, because it might be read-only - log::trace!("switching to new level 4 table"); - let bootloader_page_table = { - let old_table = { - let frame = x86_64::registers::control::Cr3::read().0; - let ptr: *const PageTable = (phys_offset + frame.start_address().as_u64()).as_ptr(); - unsafe { &*ptr } - }; - let new_frame = frame_allocator - .allocate_frame() - .expect("Failed to allocate frame for new level 4 table"); - let new_table: &mut PageTable = { - let ptr: *mut PageTable = - (phys_offset + new_frame.start_address().as_u64()).as_mut_ptr(); - // create a new, empty page table - unsafe { - ptr.write(PageTable::new()); - &mut *ptr - } - }; - - // copy the pml4 entries for all identity mapped memory. - let end_addr = VirtAddr::new(max_phys_addr.as_u64() - 1); - for p4 in 0..=usize::from(end_addr.p4_index()) { - new_table[p4] = old_table[p4].clone(); - } - - // copy the pml4 entry for the frame buffer (the frame buffer is not - // necessarily part of the identity mapping). - if let Some(frame_buffer) = frame_buffer { - let start_addr = VirtAddr::new(frame_buffer.addr.as_u64()); - let end_addr = start_addr + frame_buffer.info.byte_len as u64; - for p4 in usize::from(start_addr.p4_index())..=usize::from(end_addr.p4_index()) { - new_table[p4] = old_table[p4].clone(); - } - } - - // the first level 4 table entry is now identical, so we can just load the new one - unsafe { - x86_64::registers::control::Cr3::write( - new_frame, - x86_64::registers::control::Cr3Flags::empty(), - ); - OffsetPageTable::new(&mut *new_table, phys_offset) - } - }; + let page_tables = + page_tables::create_page_tables(&mut frame_allocator, max_phys_addr, framebuffer.as_ref()); - // create a new page table hierarchy for the kernel - let (kernel_page_table, kernel_level_4_frame) = { - // get an unused frame for new level 4 page table - let frame: PhysFrame = frame_allocator.allocate_frame().expect("no unused frames"); - log::info!("New page table at: {:#?}", &frame); - // get the corresponding virtual address - let addr = phys_offset + frame.start_address().as_u64(); - // initialize a new page table - let ptr = addr.as_mut_ptr(); - unsafe { *ptr = PageTable::new() }; - let level_4_table = unsafe { &mut *ptr }; - ( - unsafe { OffsetPageTable::new(level_4_table, phys_offset) }, - frame, - ) - }; - - bootloader_x86_64_common::PageTables { - bootloader: bootloader_page_table, - kernel: kernel_page_table, - kernel_level_4_frame, - } -} - -fn init_logger(config: &BootConfig) -> Option { - let gop_handle = boot::get_handle_for_protocol::().ok()?; - let mut gop = boot::open_protocol_exclusive::(gop_handle).ok()?; - - let mode = { - let modes = gop.modes(); - match ( - config - .frame_buffer - .minimum_framebuffer_height - .map(|v| usize::try_from(v).unwrap()), - config - .frame_buffer - .minimum_framebuffer_width - .map(|v| usize::try_from(v).unwrap()), - ) { - (Some(height), Some(width)) => modes - .filter(|m| { - let res = m.info().resolution(); - res.1 >= height && res.0 >= width - }) - .last(), - (Some(height), None) => modes.filter(|m| m.info().resolution().1 >= height).last(), - (None, Some(width)) => modes.filter(|m| m.info().resolution().0 >= width).last(), - _ => None, - } - }; - if let Some(mode) = mode { - gop.set_mode(&mode) - .expect("Failed to apply the desired display mode"); - } + let config_table_raw = + uefi::system::with_config_table(<[uefi::table::cfg::ConfigTableEntry]>::as_ptr) + .cast::(); + let config_table_len = + uefi::system::with_config_table(<[uefi::table::cfg::ConfigTableEntry]>::len); + let config_table = unsafe { core::slice::from_raw_parts(config_table_raw, config_table_len) }; - let mode_info = gop.current_mode_info(); - let mut framebuffer = gop.frame_buffer(); - let slice = unsafe { slice::from_raw_parts_mut(framebuffer.as_mut_ptr(), framebuffer.size()) }; - let info = FrameBufferInfo { - byte_len: framebuffer.size(), - width: mode_info.resolution().0, - height: mode_info.resolution().1, - pixel_format: match mode_info.pixel_format() { - PixelFormat::Rgb => bootloader_api::info::PixelFormat::Rgb, - PixelFormat::Bgr => bootloader_api::info::PixelFormat::Bgr, - PixelFormat::Bitmask | PixelFormat::BltOnly => { - panic!("Bitmask and BltOnly framebuffers are not supported") - } - }, - bytes_per_pixel: 4, - stride: mode_info.stride(), - }; + let system_info = system_info::build_system_info(config_table, framebuffer, ramdisk); - // Disconnect the UEFI console from the serial device. - // Our own logger takes full ownership of the serial device. - if let Ok(handles) = boot::locate_handle_buffer(SearchType::ByProtocol(&Serial::GUID)) { - for handle in handles.iter() { - let _ = boot::disconnect_controller(*handle, None, None); - } - } - bootloader_x86_64_common::init_logger( - slice, - info, - config.log_level, - config.frame_buffer_logging, - config.serial_logging, - ); - - Some(RawFrameBufferInfo { - addr: PhysAddr::new(framebuffer.as_mut_ptr() as u64), - info, - }) -} - -#[cfg(target_os = "uefi")] -fn uefi_stdout_available() -> bool { - uefi::table::system_table_raw() - .map(|st| { - // SAFETY: The UEFI entry macro sets this pointer before calling - // `main`, and `system_table_raw` only returns a non-null pointer. - let st = unsafe { st.as_ref() }; - !st.boot_services.is_null() && !st.stdout.is_null() - }) - .unwrap_or(false) + load_and_switch_to_kernel(kernel, config, frame_allocator, page_tables, system_info); } #[cfg(target_os = "uefi")] #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { use core::arch::asm; - use core::fmt::Write; - - if uefi_stdout_available() { - uefi::system::with_stdout(|stdout| { - let _ = stdout.clear(); - let _ = writeln!(stdout, "{}", info); - }); - } unsafe { - bootloader_x86_64_common::logger::LOGGER - .get() - .map(|l| l.force_unlock()) - }; - log::error!("{}", info); + use bootloader_x86_64_common::logger::LOGGER; + + if let Some(l) = LOGGER.get() { + l.force_unlock() + } + } + log::error!("PANIC: {info}"); loop { unsafe { asm!("cli; hlt") }; diff --git a/uefi/src/memory_descriptor.rs b/uefi/src/memory_descriptor.rs index 7dfb859e..a4adfa66 100644 --- a/uefi/src/memory_descriptor.rs +++ b/uefi/src/memory_descriptor.rs @@ -30,16 +30,8 @@ impl LegacyMemoryRegion for UefiMemoryDescriptor { MemoryType::LOADER_CODE | MemoryType::LOADER_DATA | MemoryType::BOOT_SERVICES_CODE - | MemoryType::BOOT_SERVICES_DATA => { - // we don't need this data anymore after the bootloader - // passes control to the kernel - true - } - MemoryType::RUNTIME_SERVICES_CODE | MemoryType::RUNTIME_SERVICES_DATA => { - // the UEFI standard specifies that these should be presevered - // by the bootloader and operating system - false - } + | MemoryType::BOOT_SERVICES_DATA => true, + MemoryType::RUNTIME_SERVICES_CODE | MemoryType::RUNTIME_SERVICES_DATA => false, _ => false, } } diff --git a/uefi/src/page_tables.rs b/uefi/src/page_tables.rs new file mode 100644 index 00000000..8c39f84f --- /dev/null +++ b/uefi/src/page_tables.rs @@ -0,0 +1,77 @@ +use bootloader_x86_64_common::{PageTables, RawFrameBufferInfo}; +use x86_64::{ + PhysAddr, VirtAddr, + structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB}, +}; + +pub fn create_page_tables( + frame_allocator: &mut impl FrameAllocator, + max_phys_addr: PhysAddr, + frame_buffer: Option<&RawFrameBufferInfo>, +) -> PageTables { + let phys_offset = VirtAddr::new(0); + + log::trace!("Switching to new level-4 page table"); + + let bootloader_page_table = { + let old_table = { + let frame = x86_64::registers::control::Cr3::read().0; + let ptr: *const PageTable = (phys_offset + frame.start_address().as_u64()).as_ptr(); + unsafe { &*ptr } + }; + + let new_frame = frame_allocator + .allocate_frame() + .expect("Failed to allocate frame for bootloader L4 table"); + + let new_table: &mut PageTable = { + let ptr: *mut PageTable = + (phys_offset + new_frame.start_address().as_u64()).as_mut_ptr(); + unsafe { + ptr.write(PageTable::new()); + &mut *ptr + } + }; + + let end_addr = VirtAddr::new(max_phys_addr.as_u64().saturating_sub(1)); + for p4 in 0..=usize::from(end_addr.p4_index()) { + new_table[p4] = old_table[p4].clone(); + } + + if let Some(fb) = frame_buffer { + let fb_start = VirtAddr::new(fb.addr.as_u64()); + let fb_end = fb_start + fb.info.byte_len as u64; + for p4 in usize::from(fb_start.p4_index())..=usize::from(fb_end.p4_index()) { + new_table[p4] = old_table[p4].clone(); + } + } + + unsafe { + x86_64::registers::control::Cr3::write( + new_frame, + x86_64::registers::control::Cr3Flags::empty(), + ); + OffsetPageTable::new(&mut *new_table, phys_offset) + } + }; + + let (kernel_page_table, kernel_level_4_frame) = { + let frame: PhysFrame = frame_allocator + .allocate_frame() + .expect("No free frames for kernel L4 table"); + + log::info!("Kernel page table frame: {frame:#?}"); + + let ptr: *mut PageTable = (phys_offset + frame.start_address().as_u64()).as_mut_ptr(); + unsafe { + *ptr = PageTable::new(); + (OffsetPageTable::new(&mut *ptr, phys_offset), frame) + } + }; + + PageTables { + bootloader: bootloader_page_table, + kernel: kernel_page_table, + kernel_level_4_frame, + } +} diff --git a/uefi/src/protocols.rs b/uefi/src/protocols.rs new file mode 100644 index 00000000..fc47ec5a --- /dev/null +++ b/uefi/src/protocols.rs @@ -0,0 +1,68 @@ +use core::ops::Deref; +use uefi::{ + boot::{self, OpenProtocolAttributes, OpenProtocolParams, ScopedProtocol}, + prelude::Handle, + proto::{ProtocolPointer, device_path::DevicePath, loaded_image::LoadedImage}, +}; + +pub fn open_device_path_protocol(image: Handle) -> Option> { + let loaded_image = unsafe { + boot::open_protocol::( + OpenProtocolParams { + handle: image, + agent: image, + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + } + .map_err(|e| log::error!("Failed to open LoadedImage protocol: {e:?}")) + .ok()?; + + let device_handle = loaded_image.deref().device()?; + + let device_path = unsafe { + boot::open_protocol::( + OpenProtocolParams { + handle: device_handle, + agent: image, + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + } + .map_err(|e| log::error!("Failed to open DevicePath protocol: {e:?}")) + .ok()?; + + Some(device_path) +} + +pub fn locate_and_open_protocol(image: Handle) -> Option> { + let device_path = open_device_path_protocol(image)?; + let mut device_path_ref = &*device_path; + + let fs_handle = boot::locate_device_path::

(&mut device_path_ref) + .map_err(|e| log::error!("locate_device_path failed: {e:?}")) + .ok()?; + + let proto = unsafe { + boot::open_protocol::

( + OpenProtocolParams { + handle: fs_handle, + agent: image, + controller: None, + }, + OpenProtocolAttributes::GetProtocol, + ) + } + .map_err(|e| { + log::error!( + "Failed to open protocol {}: {:?}", + core::any::type_name::

(), + e + ); + }) + .ok()?; + + Some(proto) +} diff --git a/uefi/src/system_info.rs b/uefi/src/system_info.rs new file mode 100644 index 00000000..3195e718 --- /dev/null +++ b/uefi/src/system_info.rs @@ -0,0 +1,43 @@ +use bootloader_x86_64_common::{RawFrameBufferInfo, SystemInfo}; +use uefi::Guid; +use uefi::table::cfg::ConfigTableEntry; +use x86_64::PhysAddr; + +pub fn build_system_info( + config_table: &[uefi_raw::table::configuration::ConfigurationTable], + framebuffer: Option, + ramdisk: Option<&'static mut [u8]>, +) -> SystemInfo { + let (ramdisk_addr, ramdisk_len) = match ramdisk { + Some(rd) => (Some(rd.as_ptr() as u64), rd.len() as u64), + None => (None, 0), + }; + + let rsdp_addr = { + let mut entries = config_table.iter(); + + let acpi2_guid = Guid::from_bytes(ConfigTableEntry::ACPI2_GUID.to_bytes()); + let acpi_guid = Guid::from_bytes(ConfigTableEntry::ACPI_GUID.to_bytes()); + + let acpi2 = entries.find(|e| { + let entry_guid = Guid::from_bytes(e.vendor_guid.to_bytes()); + entry_guid == acpi2_guid + }); + + let rsdp = acpi2.or_else(|| { + config_table.iter().find(|e| { + let entry_guid = Guid::from_bytes(e.vendor_guid.to_bytes()); + entry_guid == acpi_guid + }) + }); + + rsdp.map(|e| PhysAddr::new(e.vendor_table as u64)) + }; + + SystemInfo { + framebuffer, + rsdp_addr, + ramdisk_addr, + ramdisk_len, + } +}