Skip to content

Commit bd3550e

Browse files
authored
Merge pull request #1410 from v4zha/edition-3
loading UEFI using ovmf_prebuilt=0.2.3 with ovmf_code and ovmf_vars
2 parents ce01059 + ecb60ec commit bd3550e

File tree

1 file changed

+16
-8
lines changed
  • blog/content/edition-3/posts/02-booting

1 file changed

+16
-8
lines changed

blog/content/edition-3/posts/02-booting/index.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,27 +1011,35 @@ Now we can create our `qemu-uefi` executable at `src/bin/qemu-uefi.rs`:
10111011
10121012
```rust ,hl_lines=3-15
10131013
// src/bin/qemu-uefi.rs
1014-
10151014
use std::{
1016-
env,
1017-
process::{self, Command},
1015+
env, process::{self, Command}
10181016
};
10191017
1018+
use ovmf_prebuilt::{Arch, FileType, Prebuilt, Source};
1019+
10201020
fn main() {
1021+
let prebuilt =
1022+
Prebuilt::fetch(Source::LATEST, "target/ovmf").unwrap();
1023+
let ovmf_code = prebuilt.get_file(Arch::X64, FileType::Code);
1024+
let ovmf_vars = prebuilt.get_file(Arch::X64, FileType::Vars);
10211025
let mut qemu = Command::new("qemu-system-x86_64");
1022-
qemu.arg("-drive");
1023-
qemu.arg(format!("format=raw,file={}", env!("UEFI_IMAGE")));
1024-
qemu.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi());
1026+
qemu.args([
1027+
"-drive",
1028+
&format!("format=raw,if=pflash,readonly=on,file={}", ovmf_code.display()),
1029+
"-drive",
1030+
&format!("format=raw,if=pflash,file={}", ovmf_vars.display()),
1031+
"-drive",
1032+
&format!("format=raw,file={}", env!("UEFI_IMAGE")),
1033+
]);
10251034
let exit_status = qemu.status().unwrap();
10261035
process::exit(exit_status.code().unwrap_or(-1));
10271036
}
10281037
```
10291038
10301039
It's very similar to our `qemu-bios` executable.
1031-
The only two differences are that it passes an additional `-bios` argument and that it uses the `UEFI_IMAGE` instead of the `BIOS_IMAGE`.
1040+
The only two differences are that it passes two additional `-drive if=pflash,..` arguments to load UEFI firmware (`OVMF_CODE.fd`) and writable NVRAM (`OVMF_VARS.fd`), and that it uses the `UEFI_IMAGE` instead of the `BIOS_IMAGE`.
10321041
Using a quick `cargo run --bin qemu-uefi`, we can confirm that it works as intended.
10331042
1034-
10351043
### Screen Output
10361044
10371045
While we see some screen output from the bootloader, our kernel still does nothing.

0 commit comments

Comments
 (0)