diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fddeffd..bdadf0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,44 +3,44 @@ 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: | + 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 + + - 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 - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 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: | @@ -129,11 +129,11 @@ jobs: lints: name: Lints - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: CARGO_NET_GIT_FETCH_WITH_CLI: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install dependencies run: | @@ -152,13 +152,13 @@ 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 RUSTDOCFLAGS: -Dwarnings steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install dependencies run: | 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/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 +"""] diff --git a/framework_lib/Cargo.toml b/framework_lib/Cargo.toml index 2e0fe96..09c2e2b 100644 --- a/framework_lib/Cargo.toml +++ b/framework_lib/Cargo.toml @@ -9,12 +9,16 @@ 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", "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"] +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:hidapi", "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", # Otherwise I get: `LLVM ERROR: Do not know how to split the result of this operator!` @@ -40,9 +44,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 } 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..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; @@ -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,15 +197,15 @@ 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"))] +#[cfg(feature = "rusb")] 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,15 +616,15 @@ 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"))] + #[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/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, 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)