Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests-aarch64-darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added edk2/KRUN_EFI.silent.fd
Binary file not shown.
4 changes: 4 additions & 0 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub struct Args {
/// Path of log file
#[arg(long = "log-file")]
pub log_file: Option<PathBuf>,

/// Firmware path.
#[arg(long, short)]
pub firmware_path: Option<PathBuf>,
}

/// Parse the input string into a hash map of key value pairs, associating the argument with its
Expand Down
33 changes: 32 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand Down Expand Up @@ -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<PathBuf> {
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,
Expand Down Expand Up @@ -113,6 +132,18 @@ impl TryFrom<Args> 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)"));
Expand Down
2 changes: 1 addition & 1 deletion src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading