From 17195e1a460e8978790f11eec80c5db3ed3f3d02 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Mon, 11 Aug 2025 00:23:41 +0000 Subject: [PATCH] vmm: Enable firmware boot for riscv64 Implement firmware boot (UEFI boot) for riscv64 architecture. Signed-off-by: Ruoqing He --- vmm/src/vm.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 60ad39bc2..e8354c5cd 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1085,6 +1085,15 @@ impl Vm { Ok(EntryPoint { entry_addr }) } + #[cfg(target_arch = "riscv64")] + fn load_firmware(mut firmware: &File, memory_manager: Arc>) -> Result<()> { + let uefi_flash = memory_manager.lock().as_ref().unwrap().uefi_flash(); + let mem = uefi_flash.memory(); + arch::riscv64::uefi::load_uefi(mem.deref(), arch::layout::UEFI_START, &mut firmware) + .map_err(Error::UefiLoad)?; + Ok(()) + } + #[cfg(target_arch = "riscv64")] fn load_kernel( firmware: Option, @@ -1108,17 +1117,17 @@ impl Vm { // If failed, retry to load it as UEFI binary. // As the UEFI binary is formatless, it must be the last option to try. Err(linux_loader::loader::Error::Pe(InvalidImageMagicNumber)) => { - // TODO: UEFI for riscv64 is scheduled to next stage. - unimplemented!() + Self::load_firmware(&kernel, memory_manager)?; + arch::layout::UEFI_START } Err(e) => { return Err(Error::KernelLoad(e)); } } } - (Some(_firmware), None) => { - // TODO: UEFI for riscv64 is scheduled to next stage. - unimplemented!() + (Some(firmware), None) => { + Self::load_firmware(&firmware, memory_manager)?; + arch::layout::UEFI_START } _ => return Err(Error::InvalidPayload), };