QemuKernel.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /** @file
  2. Try to run Linux kernel.
  3. Copyright (c) 2022 Loongson Technology Corporation Limited. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Glossary:
  6. - mem - Memory
  7. - Bpi - Boot Parameter Interface
  8. - FwCfg - FirmWare Configure
  9. **/
  10. #include <Library/QemuLoadImageLib.h>
  11. #include <Library/ReportStatusCodeLib.h>
  12. #include <Library/BaseLib.h>
  13. #include <Library/BaseMemoryLib.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/DevicePathLib.h>
  16. #include <Library/MemoryAllocationLib.h>
  17. #include <Library/UefiBootServicesTableLib.h>
  18. #include <Library/UefiLib.h>
  19. #include <Library/UefiRuntimeServicesTableLib.h>
  20. /**
  21. Download the kernel, the initial ramdisk, and the kernel command line from
  22. QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two
  23. image files, and load and start the kernel from it.
  24. The kernel will be instructed via its command line to load the initrd from
  25. the same Simple FileSystem.
  26. @retval EFI_NOT_FOUND Kernel image was not found.
  27. @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
  28. @retval EFI_PROTOCOL_ERROR Unterminated kernel command line.
  29. @return Error codes from any of the underlying
  30. functions. On success, the function doesn't
  31. return.
  32. **/
  33. EFI_STATUS
  34. TryRunningQemuKernel (
  35. VOID
  36. )
  37. {
  38. EFI_STATUS Status;
  39. EFI_HANDLE KernelImageHandle;
  40. Status = QemuLoadKernelImage (&KernelImageHandle);
  41. if (EFI_ERROR (Status)) {
  42. return Status;
  43. }
  44. //
  45. // Signal the EFI_EVENT_GROUP_READY_TO_BOOT event.
  46. //
  47. EfiSignalEventReadyToBoot ();
  48. REPORT_STATUS_CODE (
  49. EFI_PROGRESS_CODE,
  50. (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)
  51. );
  52. //
  53. // Start the image.
  54. //
  55. Status = QemuStartKernelImage (&KernelImageHandle);
  56. if (EFI_ERROR (Status)) {
  57. DEBUG ((
  58. DEBUG_ERROR,
  59. "%a: QemuStartKernelImage(): %r\n",
  60. __FUNCTION__,
  61. Status
  62. ));
  63. }
  64. QemuUnloadKernelImage (KernelImageHandle);
  65. return Status;
  66. }