From cb308d0fbfa5cf1dc18eed70ff3be15feeb3c23e Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 16:33:13 +0800 Subject: [PATCH 1/8] gh-actions: Build on Ubuntu 24.04 Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fddeffd..da9c25c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: build: name: Build Linux and UEFI - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: @@ -129,7 +129,7 @@ jobs: lints: name: Lints - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: @@ -152,7 +152,7 @@ jobs: # Just make sure doc generation works doc: name: Generate docs - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: CARGO_NET_GIT_FETCH_WITH_CLI: true # Fail if warnings are produced From e80e5382ba52eb46e594cbbfc93aefb51861af03 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 16:36:16 +0800 Subject: [PATCH 2/8] gh-actions: Update to v4 actions Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da9c25c..a75bfea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: env: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install dependencies run: | @@ -60,7 +60,7 @@ jobs: run: cargo run -- --help - name: Upload Linux App - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: framework_tool path: target/debug/framework_tool @@ -69,7 +69,7 @@ jobs: run: make -C framework_uefi build/x86_64-unknown-uefi/boot.efi - name: Upload UEFI App - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: framework.efi path: framework_uefi/build/x86_64-unknown-uefi/boot.efi @@ -86,7 +86,7 @@ jobs: env: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup Rust toolchain run: rustup show @@ -101,7 +101,7 @@ jobs: run: cargo run --no-default-features --features "windows" -- --help - name: Upload Windows App - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: framework_tool.exe path: target/debug/framework_tool.exe @@ -114,7 +114,7 @@ jobs: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: - name: Checkout sources - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install dependencies run: | @@ -133,7 +133,7 @@ jobs: env: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install dependencies run: | @@ -158,7 +158,7 @@ jobs: # Fail if warnings are produced RUSTDOCFLAGS: -Dwarnings steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install dependencies run: | From 40950b4eb266b5b7e7c842f0d855ea9b94f4b968 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 16:48:37 +0800 Subject: [PATCH 3/8] Allow building without hidapi Useful for FreeBSD crossbuild, but we also don't have support for it in UEFI right now. Signed-off-by: Daniel Schaefer --- framework_lib/Cargo.toml | 10 ++++++---- framework_lib/src/ccgx/mod.rs | 2 +- framework_lib/src/commandline/mod.rs | 16 ++++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/framework_lib/Cargo.toml b/framework_lib/Cargo.toml index 2e0fe96..e857efc 100644 --- a/framework_lib/Cargo.toml +++ b/framework_lib/Cargo.toml @@ -9,12 +9,14 @@ build = "build.rs" default = ["linux"] # Linux/FreeBSD unix = ["std", "raw_pio", "smbios", "dep:nix", "dep:libc"] -linux = ["unix", "linux_pio", "cros_ec_driver"] -freebsd = ["unix", "freebsd_pio"] +linux = ["unix", "linux_pio", "cros_ec_driver", "hidapi"] +freebsd = ["unix", "freebsd_pio", "hidapi"] +cross_freebsd = ["unix", "freebsd_pio"] # Windows does not have the cros_ec driver nor raw port I/O access to userspace -windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio"] +windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio", "hidapi"] smbios = ["dep:smbios-lib"] -std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:hidapi", "dep:rusb"] +std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:rusb"] +hidapi = ["dep:hidapi"] uefi = [ "dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services", # Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!` diff --git a/framework_lib/src/ccgx/mod.rs b/framework_lib/src/ccgx/mod.rs index 9fcbc34..1c46e6c 100644 --- a/framework_lib/src/ccgx/mod.rs +++ b/framework_lib/src/ccgx/mod.rs @@ -11,7 +11,7 @@ use self::device::{PdController, PdPort}; pub mod binary; pub mod device; -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "hidapi")] pub mod hid; const FW1_METADATA_ROW: u32 = 0x1FE; diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index f92af6e..b58487d 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -27,7 +27,7 @@ use crate::capsule_content::{ find_bios_version, find_ec_in_bios_cap, find_pd_in_bios_cap, find_retimer_version, }; use crate::ccgx::device::{PdController, PdPort}; -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "hidapi")] use crate::ccgx::hid::{check_ccg_fw_version, find_devices, DP_CARD_PID, HDMI_CARD_PID}; use crate::ccgx::{self, SiliconId::*}; use crate::chromium_ec; @@ -48,7 +48,7 @@ use crate::smbios::{dmidecode_string_val, get_smbios, is_framework}; use crate::uefi::enable_page_break; use crate::util; use crate::util::Config; -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "hidapi")] use hidapi::HidApi; use sha2::{Digest, Sha256, Sha384, Sha512}; //use smbioslib::*; @@ -197,7 +197,7 @@ fn print_pd_details(ec: &CrosEc) { print_single_pd_details(&pd_23); } -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "hidapi")] const NOT_SET: &str = "NOT SET"; #[cfg(not(feature = "uefi"))] @@ -205,7 +205,7 @@ fn print_audio_card_details() { check_synaptics_fw_version(); } -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "hidapi")] fn print_dp_hdmi_details() { match HidApi::new() { Ok(api) => { @@ -270,7 +270,7 @@ fn print_tool_version() { } // TODO: Check if HDMI card is same -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "hidapi")] fn flash_dp_hdmi_card(pd_bin_path: &str) { let data = match fs::read(pd_bin_path) { Ok(data) => Some(data), @@ -616,12 +616,12 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { } else if args.pd_info { print_pd_details(&ec); } else if args.dp_hdmi_info { - #[cfg(not(feature = "uefi"))] + #[cfg(feature = "hidapi")] print_dp_hdmi_details(); } else if let Some(pd_bin_path) = &args.dp_hdmi_update { - #[cfg(not(feature = "uefi"))] + #[cfg(feature = "hidapi")] flash_dp_hdmi_card(pd_bin_path); - #[cfg(feature = "uefi")] + #[cfg(not(feature = "hidapi"))] let _ = pd_bin_path; } else if args.audio_card_info { #[cfg(not(feature = "uefi"))] From 3d4b856e19b1bebc3dcba32992e79c1269ad4ba6 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 18:11:40 +0800 Subject: [PATCH 4/8] Cargo.toml: default_features to default-features ``` warning: framework-system/framework_lib/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition ``` Signed-off-by: Daniel Schaefer --- framework_lib/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework_lib/Cargo.toml b/framework_lib/Cargo.toml index e857efc..2c1dc47 100644 --- a/framework_lib/Cargo.toml +++ b/framework_lib/Cargo.toml @@ -42,9 +42,9 @@ built = { version = "0.5", features = ["chrono", "git2"] } [dependencies] lazy_static = "1.4.0" -sha2 = { version = "0.10.6", default_features = false, features = [ "force-soft" ] } +sha2 = { version = "0.10.6", default-features = false, features = [ "force-soft" ] } regex = { version = "1.10.0", default-features = false } -redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default_features = false } +redox_hwio = { git = "https://github.com/FrameworkComputer/rust-hwio", branch = "freebsd", default-features = false } libc = { version = "0.2.155", optional = true } clap = { version = "4.0", features = ["derive"], optional = true } clap-verbosity-flag = { version = "2.0.1", optional = true } From b79d8fc29068bf542dd44e5ebc56d96b092936ac Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 18:43:01 +0800 Subject: [PATCH 5/8] freebsd: Fix ioctl_readwrite compilation Signed-off-by: Daniel Schaefer --- Cargo.lock | 2 +- framework_lib/src/esrt/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c0c3f6..f92c74b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -841,7 +841,7 @@ dependencies = [ [[package]] name = "redox_hwio" version = "0.1.6" -source = "git+https://github.com/FrameworkComputer/rust-hwio?branch=freebsd#9e6e7529ffd6caf7aa6a17be1eca6756b302f736" +source = "git+https://github.com/FrameworkComputer/rust-hwio?branch=freebsd#9bcff4277d8f3d7dce2b12c6ad81d092ae35c4ba" dependencies = [ "lazy_static", "nix", diff --git a/framework_lib/src/esrt/mod.rs b/framework_lib/src/esrt/mod.rs index 163db7d..da41d0f 100644 --- a/framework_lib/src/esrt/mod.rs +++ b/framework_lib/src/esrt/mod.rs @@ -341,7 +341,7 @@ pub fn get_esrt() -> Option { #[cfg(target_os = "freebsd")] #[repr(C)] -struct EfiGetTableIoc { +pub struct EfiGetTableIoc { buf: *mut u8, uuid: [u8; 16], table_len: usize, From d4153e2ecebb1f3aaf53b244e4a0d98f4450ce72 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 18:49:46 +0800 Subject: [PATCH 6/8] Allow building with rusb Signed-off-by: Daniel Schaefer --- framework_lib/Cargo.toml | 10 ++++++---- framework_lib/src/commandline/mod.rs | 6 +++--- framework_lib/src/lib.rs | 2 +- framework_lib/src/util.rs | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/framework_lib/Cargo.toml b/framework_lib/Cargo.toml index 2c1dc47..09c2e2b 100644 --- a/framework_lib/Cargo.toml +++ b/framework_lib/Cargo.toml @@ -9,13 +9,15 @@ build = "build.rs" default = ["linux"] # Linux/FreeBSD unix = ["std", "raw_pio", "smbios", "dep:nix", "dep:libc"] -linux = ["unix", "linux_pio", "cros_ec_driver", "hidapi"] -freebsd = ["unix", "freebsd_pio", "hidapi"] +linux = ["unix", "linux_pio", "cros_ec_driver", "hidapi", "rusb"] +freebsd = ["unix", "freebsd_pio", "hidapi", "rusb"] +# hidapi and rusb don't seem to build in the cross container at the moment cross_freebsd = ["unix", "freebsd_pio"] # Windows does not have the cros_ec driver nor raw port I/O access to userspace -windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio", "hidapi"] +windows = ["std", "smbios", "dep:windows", "win_driver", "raw_pio", "hidapi", "rusb"] smbios = ["dep:smbios-lib"] -std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std", "dep:rusb"] +std = ["dep:clap", "dep:clap-verbosity-flag", "dep:env_logger", "smbios-lib?/std"] +rusb = ["dep:rusb"] hidapi = ["dep:hidapi"] uefi = [ "dep:plain", "raw_pio", "smbios", "lazy_static/spin_no_std", "dep:uefi", "dep:uefi-services", diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index b58487d..13c7da5 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -19,7 +19,7 @@ use std::fs; #[cfg(all(not(feature = "uefi"), feature = "std"))] use std::io::prelude::*; -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "rusb")] use crate::audio_card::check_synaptics_fw_version; use crate::built_info; use crate::capsule; @@ -200,7 +200,7 @@ fn print_pd_details(ec: &CrosEc) { #[cfg(feature = "hidapi")] const NOT_SET: &str = "NOT SET"; -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "rusb")] fn print_audio_card_details() { check_synaptics_fw_version(); } @@ -624,7 +624,7 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 { #[cfg(not(feature = "hidapi"))] let _ = pd_bin_path; } else if args.audio_card_info { - #[cfg(not(feature = "uefi"))] + #[cfg(feature = "rusb")] print_audio_card_details(); } else if args.privacy { if let Some((mic, cam)) = print_err(ec.get_privacy_info()) { diff --git a/framework_lib/src/lib.rs b/framework_lib/src/lib.rs index 640f38f..40be376 100644 --- a/framework_lib/src/lib.rs +++ b/framework_lib/src/lib.rs @@ -12,7 +12,7 @@ extern crate lazy_static; #[macro_use] extern crate log; -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "rusb")] pub mod audio_card; #[cfg(feature = "uefi")] diff --git a/framework_lib/src/util.rs b/framework_lib/src/util.rs index 8bcdb5c..8312d6a 100644 --- a/framework_lib/src/util.rs +++ b/framework_lib/src/util.rs @@ -96,7 +96,7 @@ pub unsafe fn any_as_u8_slice(p: &T) -> &[u8] { } /// Convert any type to a mut u8 slice (Like a C byte buffer) -#[cfg(not(feature = "uefi"))] +#[cfg(feature = "rusb")] pub unsafe fn any_as_mut_u8_slice(p: &mut T) -> &mut [u8] { let len = ::std::mem::size_of::(); ::std::slice::from_raw_parts_mut((p as *mut T) as *mut u8, len) From 941d37c18a1e05a37fca93b7f30acbdbf6ee6283 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 18:54:41 +0800 Subject: [PATCH 7/8] gh-actions: Add FreeBSD cross compilation Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 57 +++++++++++++++++++--------------------- Cross.toml | 7 +++++ 2 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 Cross.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a75bfea..a643e88 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,36 +3,33 @@ on: push: jobs: -# Won't work because pkg-config can't find hidapi. -# I changed build.rs to search for 'hidapi-libusb', which is how it's installed -# on Ubuntu. But that still can't find it. -# freebsd-cross-build: -# name: Cross-Build for FreeBSD -# runs-on: 'ubuntu-22.04' -# env: -# CARGO_NET_GIT_FETCH_WITH_CLI: true -# steps: -# - uses: actions/checkout@v3 - -# - name: Install dependencies -# run: | -# sudo apt-get update -# sudo apt-get install -y libudev-dev libhidapi-dev - -# - name: Setup Rust toolchain -# run: 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 --features unix - -# - name: Upload FreeBSD App -# uses: actions/upload-artifact@v3 -# 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: 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 --features cross_freebsd + + - 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 and UEFI diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..00c2218 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,7 @@ +[target.x86_64-unknown-freebsd] +image = "ghcr.io/cross-rs/x86_64-unknown-freebsd:main" +pre-build = [""" +export FREEBSD_MIRROR=$(/freebsd-fetch-best-mirror.sh) && +/freebsd-setup-packagesite.sh && +/freebsd-install-package.sh hidapi +"""] From f9589f9fad1b8fc1fa62bcecab1a7ef36db15c90 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Wed, 31 Jul 2024 19:07:37 +0800 Subject: [PATCH 8/8] gh-actions: Update cross toolchain Signed-off-by: Daniel Schaefer --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a643e88..bdadf0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,10 @@ jobs: sudo apt-get install -y libudev-dev libhidapi-dev - name: Setup Rust toolchain - run: rustup show + run: | + rm rust-toolchain.toml + rustup toolchain install 1.75.0-x86_64-unknown-freebsd + rustup show - name: Install cross compilation tool run: cargo install cross