QemuKernel.c 1.9 KB

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