--- /dev/null
+/** @file\r
+ Try to load an EFI-stubbed RISC-V Linux kernel from QEMU's fw_cfg.\r
+\r
+ This implementation differs from OvmfPkg/Library/LoadLinuxLib. An EFI\r
+ stub in the subject kernel is a hard requirement here.\r
+\r
+ Copyright (C) 2014-2016, Red Hat, Inc.\r
+\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
+**/\r
+\r
+#include <Library/QemuLoadImageLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+\r
+#include "PlatformBm.h"\r
+\r
+//\r
+// The entry point of the feature.\r
+//\r
+\r
+/**\r
+ Download the kernel, the initial ramdisk, and the kernel command line from\r
+ QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two\r
+ image files, and load and start the kernel from it.\r
+\r
+ The kernel will be instructed via its command line to load the initrd from\r
+ the same Simple FileSystem.\r
+\r
+ @retval EFI_NOT_FOUND Kernel image was not found.\r
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
+ @retval EFI_PROTOCOL_ERROR Unterminated kernel command line.\r
+\r
+ @return Error codes from any of the underlying\r
+ functions. On success, the function doesn't\r
+ return.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TryRunningQemuKernel (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_HANDLE KernelImageHandle;\r
+\r
+ Status = QemuLoadKernelImage (&KernelImageHandle);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Signal the EFI_EVENT_GROUP_READY_TO_BOOT event.\r
+ //\r
+ EfiSignalEventReadyToBoot ();\r
+\r
+ REPORT_STATUS_CODE (\r
+ EFI_PROGRESS_CODE,\r
+ (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)\r
+ );\r
+\r
+ //\r
+ // Start the image.\r
+ //\r
+ Status = QemuStartKernelImage (&KernelImageHandle);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((\r
+ DEBUG_ERROR,\r
+ "%a: QemuStartKernelImage(): %r\n",\r
+ __FUNCTION__,\r
+ Status\r
+ ));\r
+ }\r
+\r
+ QemuUnloadKernelImage (KernelImageHandle);\r
+\r
+ return Status;\r
+}\r