diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f5604d..1d0a73a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,36 +3,36 @@ on: push: jobs: - freebsd-cross-build: - name: Cross-Build for FreeBSD - runs-on: 'ubuntu-24.04' - env: - CARGO_NET_GIT_FETCH_WITH_CLI: true - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y libudev-dev libhidapi-dev - - - name: Setup Rust toolchain - run: | - rm rust-toolchain.toml - rustup target add x86_64-unknown-freebsd - rustup show - - - name: Install cross compilation tool - run: cargo install cross - - - name: Build FreeBSD tool - run: cross build --target=x86_64-unknown-freebsd --no-default-features -p framework_lib - - - name: Upload FreeBSD App - uses: actions/upload-artifact@v4 - with: - name: framework_tool_freebsd - path: target/x86_64-unknown-freebsd/debug/framework_tool +# freebsd-cross-build: +# name: Cross-Build for FreeBSD +# runs-on: 'ubuntu-24.04' +# env: +# CARGO_NET_GIT_FETCH_WITH_CLI: true +# steps: +# - uses: actions/checkout@v4 +# +# - name: Install dependencies +# run: | +# sudo apt-get update +# sudo apt-get install -y libudev-dev libhidapi-dev +# +# - name: Setup Rust toolchain +# run: | +# rm rust-toolchain.toml +# rustup target add x86_64-unknown-freebsd +# rustup show +# +# - name: Install cross compilation tool +# run: cargo install cross +# +# - name: Build FreeBSD tool +# run: cross build --target=x86_64-unknown-freebsd --no-default-features -p framework_lib +# +# - name: Upload FreeBSD App +# uses: actions/upload-artifact@v4 +# with: +# name: framework_tool_freebsd +# path: target/x86_64-unknown-freebsd/debug/framework_tool build: name: Build Linux @@ -65,44 +65,44 @@ jobs: name: framework_tool path: target/debug/framework_tool - build-uefi: - name: Build UEFI - runs-on: ubuntu-24.04 - env: - CARGO_NET_GIT_FETCH_WITH_CLI: true - steps: - - uses: actions/checkout@v4 - - - name: Setup Rust toolchain - run: rustup show - - - name: Build UEFI application (no ESP) - run: | - make -C framework_uefi build/x86_64-unknown-uefi/boot.efi - mv framework_uefi/build/x86_64-unknown-uefi/boot.efi framework_tool_full.efi - make -C framework_uefi FEATURES=readonly build/x86_64-unknown-uefi/boot.efi - cp framework_uefi/build/x86_64-unknown-uefi/boot.efi framework_tool.efi - - - name: Upload UEFI App - uses: actions/upload-artifact@v4 - with: - name: framework_efi.zip - path: ./*.efi - - - name: Install mtools to build ESP and ISO (Linux) - run: sudo apt-get install -y mtools genisoimage - - - name: Build ESP (Linux) - run: make -C framework_uefi - - - name: Build ISO (Linux) - run: make -C framework_uefi iso - - - name: Upload UEFI App ISO - uses: actions/upload-artifact@v4 - with: - name: UEFI-Shell-fwk.iso - path: framework_uefi/build/x86_64-unknown-uefi/UEFI-Shell-fwk.iso +# build-uefi: +# name: Build UEFI +# runs-on: ubuntu-24.04 +# env: +# CARGO_NET_GIT_FETCH_WITH_CLI: true +# steps: +# - uses: actions/checkout@v4 +# +# - name: Setup Rust toolchain +# run: rustup show +# +# - name: Build UEFI application (no ESP) +# run: | +# make -C framework_uefi build/x86_64-unknown-uefi/boot.efi +# mv framework_uefi/build/x86_64-unknown-uefi/boot.efi framework_tool_full.efi +# make -C framework_uefi FEATURES=readonly build/x86_64-unknown-uefi/boot.efi +# cp framework_uefi/build/x86_64-unknown-uefi/boot.efi framework_tool.efi +# +# - name: Upload UEFI App +# uses: actions/upload-artifact@v4 +# with: +# name: framework_efi.zip +# path: ./*.efi +# +# - name: Install mtools to build ESP and ISO (Linux) +# run: sudo apt-get install -y mtools genisoimage +# +# - name: Build ESP (Linux) +# run: make -C framework_uefi +# +# - name: Build ISO (Linux) +# run: make -C framework_uefi iso +# +# - name: Upload UEFI App ISO +# uses: actions/upload-artifact@v4 +# with: +# name: UEFI-Shell-fwk.iso +# path: framework_uefi/build/x86_64-unknown-uefi/UEFI-Shell-fwk.iso build-windows: name: Build Windows diff --git a/Cargo.lock b/Cargo.lock index 8a41533..29db52a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,12 +75,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" -[[package]] -name = "bit_field" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4" - [[package]] name = "bitflags" version = "1.3.2" @@ -240,33 +234,21 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" -[[package]] -name = "convert_case" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - [[package]] name = "core-foundation" -version = "0.6.4" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" dependencies = [ - "core-foundation-sys 0.6.2", + "core-foundation-sys", "libc", ] [[package]] name = "core-foundation-sys" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" - -[[package]] -name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" @@ -331,19 +313,6 @@ dependencies = [ "syn 2.0.98", ] -[[package]] -name = "derive_more" -version = "0.99.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version", - "syn 1.0.107", -] - [[package]] name = "digest" version = "0.10.7" @@ -420,20 +389,17 @@ dependencies = [ "lazy_static", "libc", "log", - "nix 0.29.0", + "nix", "no-std-compat", "num", "num-derive", "num-traits", - "plain", "redox_hwio", "regex", "rusb", "sha2", "smbios-lib", "spin 0.9.8", - "uefi", - "uefi-services", "windows 0.59.0", "windows-version", "wmi", @@ -450,16 +416,6 @@ dependencies = [ "winresource", ] -[[package]] -name = "framework_uefi" -version = "0.4.5" -dependencies = [ - "framework_lib", - "log", - "uefi", - "uefi-services", -] - [[package]] name = "futures" version = "0.3.30" @@ -568,6 +524,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "git2" version = "0.15.0" @@ -584,8 +551,10 @@ dependencies = [ [[package]] name = "guid-create" version = "0.4.1" -source = "git+https://github.com/FrameworkComputer/guid-create?branch=no-rand#84c3ad2e8b64a12beebb460804a65da55434cfd9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "738068c48cd875ab1ff0bb5de7fa448cb88769ce74783f4eb964257e693f8a19" dependencies = [ + "rand", "winapi", ] @@ -627,7 +596,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", - "core-foundation-sys 0.8.4", + "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", @@ -666,12 +635,12 @@ dependencies = [ [[package]] name = "io-kit-sys" -version = "0.1.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f21dcc74995dd4cd090b147e79789f8d65959cbfb5f0b118002db869ea3bd0a0" +checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b" dependencies = [ - "core-foundation-sys 0.6.2", - "mach 0.2.3", + "core-foundation-sys", + "mach2", ] [[package]] @@ -781,19 +750,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] -name = "mach" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86dd2487cdfea56def77b88438a2c915fb45113c5319bfe7e14306ca4cd0b0e1" -dependencies = [ - "libc", -] - -[[package]] -name = "mach" -version = "0.3.2" +name = "mach2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +checksum = "d640282b302c0bb0a2a8e0233ead9035e3bed871f0b7e81fe4a1ec829765db44" dependencies = [ "libc", ] @@ -804,29 +764,6 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - -[[package]] -name = "nix" -version = "0.25.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "libc", - "memoffset", - "pin-utils", -] - [[package]] name = "nix" version = "0.29.0" @@ -950,10 +887,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] -name = "plain" -version = "0.2.3" +name = "ppv-lite86" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro2" @@ -965,41 +905,51 @@ dependencies = [ ] [[package]] -name = "ptr_meta" -version = "0.2.0" +name = "quote" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcada80daa06c42ed5f48c9a043865edea5dc44cbf9ac009fda3b89526e28607" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ - "ptr_meta_derive", + "proc-macro2", ] [[package]] -name = "ptr_meta_derive" -version = "0.2.0" +name = "rand" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca9224df2e20e7c5548aeb5f110a0f3b77ef05f8585139b7148b59056168ed2" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.107", + "libc", + "rand_chacha", + "rand_core", ] [[package]] -name = "quote" -version = "1.0.38" +name = "rand_chacha" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "proc-macro2", + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", ] [[package]] name = "redox_hwio" version = "0.1.6" -source = "git+https://github.com/FrameworkComputer/rust-hwio?branch=freebsd#9bcff4277d8f3d7dce2b12c6ad81d092ae35c4ba" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eb516ad341a84372b5b15a5a35cf136ba901a639c8536f521b108253d7fce74" dependencies = [ "lazy_static", - "nix 0.25.1", ] [[package]] @@ -1139,16 +1089,16 @@ dependencies = [ [[package]] name = "smbios-lib" -version = "0.9.1" -source = "git+https://github.com/FrameworkComputer/smbios-lib.git?branch=no-std#b3e2fff8a6f4b8c2d729467cbbf0c8c41974cd1c" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c18320ad3d997a100cb948fc020111936c530eddfde947f467083730e39e72" dependencies = [ "core-foundation", - "core-foundation-sys 0.6.2", + "core-foundation-sys", "getopts", "io-kit-sys", "libc", - "mach 0.3.2", - "no-std-compat", + "mach2", "serde", "serde_json", ] @@ -1302,49 +1252,6 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" -[[package]] -name = "ucs2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad643914094137d475641b6bab89462505316ec2ce70907ad20102d28a79ab8" -dependencies = [ - "bit_field", -] - -[[package]] -name = "uefi" -version = "0.20.0" -source = "git+https://github.com/FrameworkComputer/uefi-rs?branch=merged#76130a0f1c1585012e598b8c514526bac09c68e0" -dependencies = [ - "bitflags 1.3.2", - "derive_more", - "log", - "ptr_meta", - "ucs2", - "uefi-macros", -] - -[[package]] -name = "uefi-macros" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0caeb0e7b31b9f1f347e541106be10aa8c66c76fa722a3298a4cd21433fabd4" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.107", -] - -[[package]] -name = "uefi-services" -version = "0.17.0" -source = "git+https://github.com/FrameworkComputer/uefi-rs?branch=merged#76130a0f1c1585012e598b8c514526bac09c68e0" -dependencies = [ - "cfg-if", - "log", - "uefi", -] - [[package]] name = "unicode-bidi" version = "0.3.13" @@ -1421,6 +1328,12 @@ dependencies = [ "libc", ] +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasm-bindgen" version = "0.2.84" @@ -1839,3 +1752,23 @@ dependencies = [ "windows 0.59.0", "windows-core", ] + +[[package]] +name = "zerocopy" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", +] diff --git a/Cargo.toml b/Cargo.toml index d8108e1..bb7010d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ members = [ # Linux and Windows tool to inspect and customize the system "framework_tool", # UEFI tool to inspect and customize the system - "framework_uefi", + #"framework_uefi", # Catchall library that we'll probably want to split up further "framework_lib", ] @@ -19,9 +19,9 @@ default-members = [ "framework_tool", ] -[patch.crates-io] -uefi = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" } -uefi-services = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" } +#[patch.crates-io] +#uefi = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" } +#uefi-services = { git = "https://github.com/FrameworkComputer/uefi-rs", branch = "merged" } [profile.release] lto = true diff --git a/framework_lib/Cargo.toml b/framework_lib/Cargo.toml index 348b6bc..a46cfc0 100644 --- a/framework_lib/Cargo.toml +++ b/framework_lib/Cargo.toml @@ -34,33 +34,40 @@ spin = { version = "0.9.8" } no-std-compat = { version = "0.4.1", features = [ "alloc" ] } hidapi = { version = "2.6.3", features = [ "windows-native" ], optional = true } rusb = { version = "0.9.4", optional = true } -guid-create = { git = "https://github.com/FrameworkComputer/guid-create", branch = "no-rand", default-features = false } -[target.'cfg(target_os = "uefi")'.dependencies] -uefi = { version = "0.20", features = ["alloc"] } -uefi-services = "0.17" -plain = "0.2.3" -redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false } -smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std", default-features = false } +#[target.'cfg(target_os = "uefi")'.dependencies] +#uefi = { version = "0.20", features = ["alloc"] } +#uefi-services = "0.17" +#plain = "0.2.3" +#redox_hwio = { version = "0.1.6", default-features = false } +#smbios-lib-no-std = { package = "smbios-lib", git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std", default-features = false } +#guid-create-no-std = { package = "guid-create", git = "https://github.com/FrameworkComputer/guid-create", branch = "no_std", default-features = false } [target.'cfg(windows)'.dependencies] wmi = "0.15.0" -smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std" } +smbios-lib = "0.9.2" env_logger = "0.11" clap = { version = "4.5", features = ["derive", "cargo"] } clap-num = { version = "1.2.0" } clap-verbosity-flag = { version = "2.2.1" } windows-version = "0.1.4" +guid-create = "0.4.1" [target.'cfg(unix)'.dependencies] libc = "0.2.155" nix = { version = "0.29.0", features = ["ioctl", "user"] } -redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd" } -smbios-lib = { git = "https://github.com/FrameworkComputer/smbios-lib.git", branch = "no-std" } +smbios-lib = "0.9.2" env_logger = "0.11" clap = { version = "4.5", features = ["derive", "cargo"] } clap-num = { version = "1.2.0" } clap-verbosity-flag = { version = "2.2.1" } +guid-create = "0.4.1" + +[target.'cfg(target_os="linux")'.dependencies] +redox_hwio = "0.1.6" + +#[target.'cfg(target_os="freebsd")'.dependencies] +#redox_hwio_freebsd = { package = "redox_hwio", git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd" } [target.'cfg(windows)'.dependencies.windows] version = "0.59.0" diff --git a/framework_lib/src/capsule.rs b/framework_lib/src/capsule.rs index e2dff32..a222968 100644 --- a/framework_lib/src/capsule.rs +++ b/framework_lib/src/capsule.rs @@ -10,8 +10,8 @@ use std::prelude::v1::*; +use crate::guid::CGuid; use core::prelude::rust_2021::derive; -use guid_create::Guid; #[cfg(not(feature = "uefi"))] use std::fs::File; #[cfg(not(feature = "uefi"))] @@ -21,7 +21,7 @@ use std::io::prelude::*; #[repr(C)] pub struct EfiCapsuleHeader { /// A GUID that defines the contents of a capsule. - pub capsule_guid: Guid, + pub capsule_guid: CGuid, /// The size of the capsule header. This may be larger than the size of /// the EFI_CAPSULE_HEADER since CapsuleGuid may imply @@ -205,14 +205,14 @@ mod tests { let data = fs::read(capsule_path).unwrap(); let cap = parse_capsule_header(&data).unwrap(); let expected_header = EfiCapsuleHeader { - capsule_guid: Guid::from(esrt::WINUX_GUID), + capsule_guid: CGuid::from(esrt::WINUX_GUID), header_size: 28, flags: 65536, capsule_image_size: 676898, }; assert_eq!(cap, expected_header); - assert_eq!(cap.capsule_guid, Guid::from(esrt::WINUX_GUID)); + assert_eq!(cap.capsule_guid, CGuid::from(esrt::WINUX_GUID)); let ux_header = parse_ux_header(&data); assert_eq!( ux_header, diff --git a/framework_lib/src/chromium_ec/portio.rs b/framework_lib/src/chromium_ec/portio.rs index d76f8a6..3b55dda 100644 --- a/framework_lib/src/chromium_ec/portio.rs +++ b/framework_lib/src/chromium_ec/portio.rs @@ -4,8 +4,10 @@ use alloc::string::ToString; use alloc::vec; use alloc::vec::Vec; use core::convert::TryInto; -#[cfg(not(windows))] +#[cfg(all(not(windows), not(target_os = "freebsd")))] use hwio::{Io, Pio}; +#[cfg(target_os = "freebsd")] +use hwio_freebsd::{Io, Pio}; #[cfg(target_os = "linux")] use libc::ioperm; use log::Level; diff --git a/framework_lib/src/chromium_ec/portio_mec.rs b/framework_lib/src/chromium_ec/portio_mec.rs index 1f855d0..0cbd3bc 100644 --- a/framework_lib/src/chromium_ec/portio_mec.rs +++ b/framework_lib/src/chromium_ec/portio_mec.rs @@ -4,7 +4,10 @@ use alloc::vec::Vec; use log::Level; +#[cfg(all(not(windows), not(target_os = "freebsd")))] use hwio::{Io, Pio}; +#[cfg(target_os = "freebsd")] +use hwio_freebsd::{Io, Pio}; #[cfg(target_os = "linux")] use libc::ioperm; diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 8644026..8fd3fb2 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -3,11 +3,15 @@ //! Can be easily re-used from any OS or UEFI shell. //! We have implemented both in the `framework_tool` and `framework_uefi` crates. +use crate::guid::CGuid; use alloc::format; use alloc::string::String; use alloc::string::ToString; use alloc::vec::Vec; -use guid_create::{Guid, GUID}; +#[cfg(not(feature = "uefi"))] +use guid_create::GUID; +#[cfg(feature = "uefi")] +use guid_create_no_std::GUID; use log::Level; use num_traits::FromPrimitive; @@ -65,6 +69,9 @@ use crate::util::{self, Config, Platform, PlatformFamily}; use hidapi::HidApi; use sha2::{Digest, Sha256, Sha384, Sha512}; //use smbioslib::*; +#[cfg(feature = "uefi")] +use smbios_lib_no_std::{DefinedStruct, SMBiosInformation}; +#[cfg(not(feature = "uefi"))] use smbioslib::{DefinedStruct, SMBiosInformation}; use crate::chromium_ec::{CrosEc, CrosEcDriverType, HardwareDeviceType}; @@ -1270,7 +1277,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { println!(" Size: {:>20} B", data.len()); println!(" Size: {:>20} KB", data.len() / 1024); if let Some(header) = analyze_capsule(&data) { - if header.capsule_guid == Guid::from(esrt::WINUX_GUID) { + if header.capsule_guid == CGuid::from(esrt::WINUX_GUID) { let ux_header = capsule::parse_ux_header(&data); if let Some(dump_path) = &args.dump { // TODO: Better error handling, rather than just panicking diff --git a/framework_lib/src/esrt/mod.rs b/framework_lib/src/esrt/mod.rs index aa517bf..e555f40 100644 --- a/framework_lib/src/esrt/mod.rs +++ b/framework_lib/src/esrt/mod.rs @@ -14,8 +14,12 @@ use log::{debug, error, info, trace}; use std::prelude::v1::*; +use crate::guid::CGuid; use core::prelude::v1::derive; -use guid_create::{Guid, GUID}; +#[cfg(not(feature = "uefi"))] +use guid_create::GUID; +#[cfg(feature = "uefi")] +use guid_create_no_std::GUID; #[cfg(target_os = "linux")] use std::fs; @@ -193,7 +197,7 @@ pub enum FrameworkGuidKind { Unknown, } -pub fn match_guid_kind(guid: &Guid) -> FrameworkGuidKind { +pub fn match_guid_kind(guid: &CGuid) -> FrameworkGuidKind { match GUID::from(*guid) { TGL_BIOS_GUID => FrameworkGuidKind::TglBios, ADL_BIOS_GUID => FrameworkGuidKind::AdlBios, @@ -292,7 +296,7 @@ impl UpdateStatus { // TODO: Decode into proper Rust types #[derive(Clone)] pub struct EsrtResourceEntry { - pub fw_class: Guid, + pub fw_class: CGuid, pub fw_type: u32, // ResourceType pub fw_version: u32, pub lowest_supported_fw_version: u32, @@ -364,7 +368,7 @@ fn esrt_from_sysfs(dir: &Path) -> io::Result { let last_attempt_version = fs::read_to_string(path.join("last_attempt_version"))?; let last_attempt_status = fs::read_to_string(path.join("last_attempt_status"))?; let esrt = EsrtResourceEntry { - fw_class: Guid::from( + fw_class: CGuid::from( GUID::parse(fw_class.trim()).expect("Kernel provided wrong value"), ), fw_type: fw_type @@ -436,7 +440,7 @@ pub fn get_esrt() -> Option { let ver_str = caps.get(2).unwrap().as_str().to_string(); let guid = GUID::parse(guid_str.trim()).expect("Kernel provided wrong value"); - let guid_kind = match_guid_kind(&Guid::from(guid)); + let guid_kind = match_guid_kind(&CGuid::from(guid)); let ver = u32::from_str_radix(&ver_str, 16).unwrap(); debug!("ESRT Entry {}", i); debug!(" Name: {:?}", guid_kind); @@ -456,7 +460,7 @@ pub fn get_esrt() -> Option { // TODO: The missing fields are present in Device Manager // So there must be a way to get at them let esrt = EsrtResourceEntry { - fw_class: Guid::from(guid), + fw_class: CGuid::from(guid), fw_type, fw_version: ver, // TODO: Not exposed by windows @@ -543,7 +547,7 @@ pub fn get_esrt() -> Option { for table in config_tables { // TODO: Why aren't they the same type? //debug!("Table: {:?}", table); - let table_guid: Guid = unsafe { std::mem::transmute(table.guid) }; + let table_guid: CGuid = unsafe { std::mem::transmute(table.guid) }; let table_guid = GUID::from(table_guid); match table_guid { SYSTEM_RESOURCE_TABLE_GUID => unsafe { diff --git a/framework_lib/src/guid.rs b/framework_lib/src/guid.rs new file mode 100644 index 0000000..e52de03 --- /dev/null +++ b/framework_lib/src/guid.rs @@ -0,0 +1,56 @@ +use alloc::fmt; + +#[cfg(not(feature = "uefi"))] +use guid_create::GUID; +#[cfg(feature = "uefi")] +use guid_create_no_std::GUID; + +// Until https://github.com/kurtlawrence/guid-create/pull/20 is merged + +impl From for GUID { + fn from(item: CGuid) -> Self { + GUID::build_from_components(item.a, item.b, item.c, &item.d) + } +} + +impl From for CGuid { + fn from(item: GUID) -> Self { + CGuid { + a: item.data1(), + b: item.data2(), + c: item.data3(), + d: item.data4(), + } + } +} + +impl fmt::Display for CGuid { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "{:08X}-{:04X}-{:04X}-{:04X}-{:08X}{:04X}", + self.a, + self.b, + self.c, + u16::from_be_bytes(self.d[0..2].try_into().unwrap()), + u32::from_be_bytes(self.d[2..6].try_into().unwrap()), + u16::from_be_bytes(self.d[6..8].try_into().unwrap()), + ) + } +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Hash)] +#[repr(C)] +pub struct CGuid { + /// The low field of the timestamp. + a: u32, + /// The middle field of the timestamp. + b: u16, + /// The high field of the timestamp multiplexed with the version number. + c: u16, + /// Contains, in this order: + /// - The high field of the clock sequence multiplexed with the variant. + /// - The low field of the clock sequence. + /// - The spatially unique node identifier. + d: [u8; 8], +} diff --git a/framework_lib/src/lib.rs b/framework_lib/src/lib.rs index 05adf8f..bfb8b5a 100644 --- a/framework_lib/src/lib.rs +++ b/framework_lib/src/lib.rs @@ -38,6 +38,7 @@ pub mod commandline; pub mod csme; pub mod ec_binary; pub mod esrt; +pub mod guid; mod os_specific; pub mod power; pub mod smbios; diff --git a/framework_lib/src/smbios.rs b/framework_lib/src/smbios.rs index 144ad21..08fe2af 100644 --- a/framework_lib/src/smbios.rs +++ b/framework_lib/src/smbios.rs @@ -9,6 +9,9 @@ use crate::util::Config; pub use crate::util::{Platform, PlatformFamily}; use num_derive::FromPrimitive; use num_traits::FromPrimitive; +#[cfg(feature = "uefi")] +use smbios_lib_no_std::*; +#[cfg(not(feature = "uefi"))] use smbioslib::*; #[cfg(feature = "uefi")] use spin::Mutex;