diff --git a/.github/workflows/unit_tests-aarch64-darwin.yaml b/.github/workflows/unit_tests-aarch64-darwin.yaml index 3a10a23..892292c 100644 --- a/.github/workflows/unit_tests-aarch64-darwin.yaml +++ b/.github/workflows/unit_tests-aarch64-darwin.yaml @@ -19,7 +19,7 @@ jobs: uses: Homebrew/actions/setup-homebrew@master - name: Install dependencies - run: brew tap slp/krunkit && brew install virglrenderer clang-format libkrun-efi + run: brew tap slp/krun && brew install virglrenderer clang-format libkrun - name: Build run: cargo build --release --verbose diff --git a/edk2/KRUN_EFI.silent.fd b/edk2/KRUN_EFI.silent.fd new file mode 100644 index 0000000..6ae840f Binary files /dev/null and b/edk2/KRUN_EFI.silent.fd differ diff --git a/src/cmdline.rs b/src/cmdline.rs index a5bc57e..bd81e85 100644 --- a/src/cmdline.rs +++ b/src/cmdline.rs @@ -59,6 +59,10 @@ pub struct Args { /// Path of log file #[arg(long = "log-file")] pub log_file: Option, + + /// Firmware path. + #[arg(long, short)] + pub firmware_path: Option, } /// Parse the input string into a hash map of key value pairs, associating the argument with its diff --git a/src/context.rs b/src/context.rs index 3cad6fd..028617d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -8,6 +8,7 @@ use crate::{ }; use std::os::fd::{AsRawFd, RawFd}; +use std::path::PathBuf; use std::{convert::TryFrom, ptr, thread}; use std::{ ffi::{c_char, CString}, @@ -18,10 +19,11 @@ use std::{ use anyhow::{anyhow, Context}; use env_logger::{Builder, Env, Target}; -#[link(name = "krun-efi")] +#[link(name = "krun")] extern "C" { fn krun_create_ctx() -> i32; fn krun_init_log(target: RawFd, level: u32, style: u32, options: u32) -> i32; + fn krun_set_firmware(ctx_id: u32, c_firmware_path: *const c_char) -> i32; fn krun_set_gpu_options2(ctx_id: u32, virgl_flags: u32, shm_size: u64) -> i32; fn krun_set_vm_config(ctx_id: u32, num_vcpus: u8, ram_mib: u32) -> i32; fn krun_set_smbios_oem_strings(ctx_id: u32, oem_strings: *const *const c_char) -> i32; @@ -50,6 +52,23 @@ pub const KRUN_LOG_STYLE_AUTO: u32 = 0; pub const KRUN_LOG_OPTION_ENV: u32 = 0; pub const KRUN_LOG_OPTION_NO_ENV: u32 = 1; +fn get_firmware_path() -> Option { + let exec_path = std::env::current_exe().ok()?; + let base_dir = exec_path.parent()?.parent()?; + let fw_path = base_dir.join("share/krunkit/KRUN_EFI.silent.fd"); + if fw_path.exists() { + return Some(fw_path); + } + // This is useful for testing directly from a cloned repo. + let base_dir = base_dir.parent()?; + let fw_path = base_dir.join("edk2/KRUN_EFI.silent.fd"); + if fw_path.exists() { + Some(fw_path) + } else { + None + } +} + /// A wrapper of all data used to configure the krun VM. pub struct KrunContext { id: u32, @@ -113,6 +132,18 @@ impl TryFrom for KrunContext { // Safe to unwrap, as it's already ensured that id >= 0. let id = u32::try_from(id).unwrap(); + let fw_path = match args.firmware_path { + Some(ref path) => CString::new(path.to_str().unwrap()).unwrap(), + None => match get_firmware_path() { + Some(path) => CString::new(path.to_str().unwrap()).unwrap(), + None => return Err(anyhow!("can't find a firmware to load")), + }, + }; + + if unsafe { krun_set_firmware(id, fw_path.as_ptr()) } < 0 { + return Err(anyhow!("unable to configure the firmware to be loaded")); + } + // Set the krun VM's number of vCPUs and amount of memory allocated. if args.cpus == 0 { return Err(anyhow!("vcpus must be a minimum of 1 (0 is invalid)")); diff --git a/src/status.rs b/src/status.rs index 3b23aef..4eb2235 100644 --- a/src/status.rs +++ b/src/status.rs @@ -13,7 +13,7 @@ use std::{ use anyhow::{anyhow, Context}; -#[link(name = "krun-efi")] +#[link(name = "krun")] extern "C" { fn krun_get_shutdown_eventfd(ctx_id: u32) -> i32; } diff --git a/src/virtio.rs b/src/virtio.rs index 2a9436e..7032e08 100644 --- a/src/virtio.rs +++ b/src/virtio.rs @@ -41,7 +41,7 @@ const SOCK_TYPE_UNIX_SOCKET_PATH: &str = "unixSocketPath"; const SOCK_TYPE_UNIXGRAM: &str = "unixgram"; const SOCK_TYPE_UNIXSTREAM: &str = "unixstream"; -#[link(name = "krun-efi")] +#[link(name = "krun")] extern "C" { fn krun_add_disk2( ctx_id: u32,