Skip to content

Commit

Permalink
Merge pull request #295 from hermit-os/uefi-ci
Browse files Browse the repository at this point in the history
ci: test UEFI
  • Loading branch information
mkroening authored Feb 8, 2024
2 parents 148735a + a38c040 commit d8f161e
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 31 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ jobs:
name: Run
strategy:
matrix:
target: [x86_64, aarch64, riscv64]
target: [x86_64, x86_64-uefi, aarch64, riscv64]
os: [ubuntu-latest, macos-latest, windows-latest]
exclude:
- target: x86_64-uefi
os: macos-latest
- target: x86_64-uefi
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Install QEMU, NASM (ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install qemu-system-x86 qemu-system-arm qemu-system-misc nasm
sudo apt-get install qemu-system-x86 qemu-system-arm qemu-system-misc ovmf nasm
- name: Install QEMU, NASM (macos)
if: matrix.os == 'macos-latest'
run: |
Expand Down Expand Up @@ -89,7 +94,7 @@ jobs:
- name: Install QEMU
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends qemu-system-x86
sudo apt-get install -y --no-install-recommends qemu-system-x86 ovmf
- uses: actions/checkout@v4
with:
lfs: true
Expand All @@ -112,6 +117,10 @@ jobs:
run: cargo xtask ci qemu --target x86_64 --accel
- name: Run QEMU (hello_world, release)
run: cargo xtask ci qemu --target x86_64 --accel --release
- name: Run UEFI (dev)
run: cargo xtask ci qemu --target x86_64-uefi --accel
- name: Run UEFI (release)
run: cargo xtask ci qemu --target x86_64-uefi --accel --release
- name: Run Firecracker (hello_world, dev)
run: cargo xtask ci firecracker --target x86_64-fc --features fc
- name: Run Firecracker (hello_world, release)
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ spinning_top = "0.3"

[target.'cfg(target_os = "uefi")'.dependencies]
uefi = "0.26"
uefi-services = "0.23"
uefi-services = { version = "0.23", features = ["qemu"] }
qemu-exit = "3"

[target.'cfg(target_arch = "riscv64")'.dependencies]
fdt = "0.1"
Expand Down
7 changes: 6 additions & 1 deletion src/uefi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use qemu_exit::QEMUExit;
use uefi::prelude::*;

// Entry Point of the Uefi Loader
#[entry]
fn loader_main(_handle: Handle, mut system_table: SystemTable<Boot>) -> Status {
uefi_services::init(&mut system_table).unwrap();

Status::SUCCESS
log::info!("Hello, UEFI!");

let custom_exit_success = 3;
let qemu_exit_handle = qemu_exit::X86::new(0xf4, custom_exit_success);
qemu_exit_handle.exit_success()
}
4 changes: 2 additions & 2 deletions xtask/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Artifact {
self.target_dir(),
self.target.triple().as_ref(),
self.profile_path_component().as_ref(),
self.target.build_name().as_ref(),
self.target.image_name().as_ref(),
]
.iter()
.collect::<PathBuf>()
Expand All @@ -61,7 +61,7 @@ impl Artifact {
self.target_dir(),
self.target.name().as_ref(),
self.profile_path_component().as_ref(),
self.target.dist_name().as_ref(),
self.target.image_name().as_ref(),
]
.iter()
.collect::<PathBuf>()
Expand Down
88 changes: 72 additions & 16 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,23 @@ impl Qemu {

let sh = crate::sh()?;

if self.build.target() == Target::X86_64Uefi {
if super::in_ci() {
sh.copy_file("/usr/share/OVMF/OVMF_CODE.fd", "OVMF_CODE.fd")?;
sh.copy_file("/usr/share/OVMF/OVMF_VARS.fd", "OVMF_VARS.fd")?;
}

sh.create_dir("target/esp/efi/boot")?;
sh.copy_file(self.build.dist_object(), "target/esp/efi/boot/bootx64.efi")?;
}

let target = self.build.target();
let arch = target.arch();
let qemu = env::var_os("QEMU").unwrap_or_else(|| format!("qemu-system-{arch}").into());

let dist_object = self.build.dist_object();
let qemu = cmd!(sh, "{qemu}")
.args(&["-display", "none"])
.args(&["-serial", "stdio"])
.arg("-kernel")
.arg(&dist_object)
.args(self.machine_args())
.args(self.cpu_args())
.args(self.memory_args());
Expand Down Expand Up @@ -86,7 +93,7 @@ impl Qemu {

fn cpu_args(&self) -> Vec<String> {
match self.build.target() {
Target::X86_64 | Target::X86_64Fc | Target::X86_64Uefi => {
Target::X86_64 | Target::X86_64Uefi => {
let mut cpu_args = if self.accel {
if cfg!(target_os = "linux") {
vec![
Expand All @@ -102,21 +109,55 @@ impl Qemu {
};
cpu_args.push("-device".to_string());
cpu_args.push("isa-debug-exit,iobase=0xf4,iosize=0x04".to_string());
cpu_args.push("-initrd".to_string());
cpu_args.push(
self.build
.ci_image(&self.image)
.into_os_string()
.into_string()
.unwrap(),
);

match self.build.target() {
Target::X86_64 => {
cpu_args.push("-kernel".to_string());
cpu_args.push(
self.build
.dist_object()
.into_os_string()
.into_string()
.unwrap(),
);
cpu_args.push("-initrd".to_string());
cpu_args.push(
self.build
.ci_image(&self.image)
.into_os_string()
.into_string()
.unwrap(),
);
}
Target::X86_64Uefi => {
cpu_args.push("-drive".to_string());
cpu_args
.push("if=pflash,format=raw,readonly=on,file=OVMF_CODE.fd".to_string());
cpu_args.push("-drive".to_string());
cpu_args
.push("if=pflash,format=raw,readonly=on,file=OVMF_VARS.fd".to_string());
cpu_args.push("-drive".to_string());
cpu_args.push("format=raw,file=fat:rw:target/esp".to_string());
}
_ => unreachable!(),
}
cpu_args
}
Target::X86_64Fc => panic!("unsupported"),
Target::Aarch64 => {
let mut cpu_args = if self.accel {
todo!()
} else {
vec!["-cpu".to_string(), "cortex-a72".to_string()]
vec![
"-cpu".to_string(),
"cortex-a72".to_string(),
"-kernel".to_string(),
self.build
.dist_object()
.into_os_string()
.into_string()
.unwrap(),
]
};
cpu_args.push("-semihosting".to_string());
cpu_args.push("-device".to_string());
Expand All @@ -130,7 +171,16 @@ impl Qemu {
let mut cpu_args = if self.accel {
todo!()
} else {
vec!["-cpu".to_string(), "rv64".to_string()]
vec![
"-cpu".to_string(),
"rv64".to_string(),
"-kernel".to_string(),
self.build
.dist_object()
.into_os_string()
.into_string()
.unwrap(),
]
};
cpu_args.push("-initrd".to_string());
cpu_args.push(
Expand All @@ -150,8 +200,14 @@ impl Qemu {
if self.image == "hello_c" {
memory = memory.max(64);
}
if self.build.target() == Target::Aarch64 {
memory = memory.max(256);
match self.build.target() {
Target::X86_64Uefi => {
memory = memory.max(64);
}
Target::Aarch64 => {
memory = memory.max(256);
}
_ => {}
}
memory
}
Expand Down
9 changes: 1 addition & 8 deletions xtask/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,12 @@ impl Target {
}
}

pub fn build_name(&self) -> &'static str {
pub fn image_name(&self) -> &'static str {
match self {
Self::X86_64Uefi => "hermit-loader.efi",
_ => "hermit-loader",
}
}

pub fn dist_name(&self) -> &'static str {
match self {
Self::X86_64Uefi => "BootX64.efi",
_ => "hermit-loader",
}
}
}

impl FromStr for Target {
Expand Down

0 comments on commit d8f161e

Please sign in to comment.