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), };