]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/RiscVVirt/Library/PlatformBootManagerLib/QemuKernel.c
OvmfPkg/RiscVVirt: Add PlatformBootManagerLib library
[mirror_edk2.git] / OvmfPkg / RiscVVirt / Library / PlatformBootManagerLib / QemuKernel.c
1 /** @file
2 Try to load an EFI-stubbed RISC-V Linux kernel from QEMU's fw_cfg.
3
4 This implementation differs from OvmfPkg/Library/LoadLinuxLib. An EFI
5 stub in the subject kernel is a hard requirement here.
6
7 Copyright (C) 2014-2016, Red Hat, Inc.
8
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10 **/
11
12 #include <Library/QemuLoadImageLib.h>
13 #include <Library/ReportStatusCodeLib.h>
14
15 #include "PlatformBm.h"
16
17 //
18 // The entry point of the feature.
19 //
20
21 /**
22 Download the kernel, the initial ramdisk, and the kernel command line from
23 QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two
24 image files, and load and start the kernel from it.
25
26 The kernel will be instructed via its command line to load the initrd from
27 the same Simple FileSystem.
28
29 @retval EFI_NOT_FOUND Kernel image was not found.
30 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
31 @retval EFI_PROTOCOL_ERROR Unterminated kernel command line.
32
33 @return Error codes from any of the underlying
34 functions. On success, the function doesn't
35 return.
36 **/
37 EFI_STATUS
38 EFIAPI
39 TryRunningQemuKernel (
40 VOID
41 )
42 {
43 EFI_STATUS Status;
44 EFI_HANDLE KernelImageHandle;
45
46 Status = QemuLoadKernelImage (&KernelImageHandle);
47 if (EFI_ERROR (Status)) {
48 return Status;
49 }
50
51 //
52 // Signal the EFI_EVENT_GROUP_READY_TO_BOOT event.
53 //
54 EfiSignalEventReadyToBoot ();
55
56 REPORT_STATUS_CODE (
57 EFI_PROGRESS_CODE,
58 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)
59 );
60
61 //
62 // Start the image.
63 //
64 Status = QemuStartKernelImage (&KernelImageHandle);
65 if (EFI_ERROR (Status)) {
66 DEBUG ((
67 DEBUG_ERROR,
68 "%a: QemuStartKernelImage(): %r\n",
69 __FUNCTION__,
70 Status
71 ));
72 }
73
74 QemuUnloadKernelImage (KernelImageHandle);
75
76 return Status;
77 }