47 QEMU_KERNEL_LOADER_FS_MEDIA_GUID
55 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
66 if (LoadedImage->SetupBuf !=
NULL) {
68 LoadedImage->SetupBuf,
73 if (LoadedImage->KernelBuf !=
NULL) {
75 LoadedImage->KernelBuf,
80 if (LoadedImage->CommandLine !=
NULL) {
82 LoadedImage->CommandLine,
87 if (LoadedImage->InitrdData !=
NULL) {
89 LoadedImage->InitrdData,
112 if ((KernelSize == 0) || (SetupSize == 0)) {
113 DEBUG ((DEBUG_INFO,
"qemu -kernel was not used.\n"));
114 return EFI_NOT_FOUND;
118 if (LoadedImage ==
NULL) {
119 return EFI_OUT_OF_RESOURCES;
122 LoadedImage->SetupSize = SetupSize;
126 if (LoadedImage->SetupBuf ==
NULL) {
127 DEBUG ((DEBUG_ERROR,
"Unable to allocate memory for kernel setup!\n"));
128 Status = EFI_OUT_OF_RESOURCES;
132 DEBUG ((DEBUG_INFO,
"Setup size: 0x%x\n", (UINT32)LoadedImage->SetupSize));
133 DEBUG ((DEBUG_INFO,
"Reading kernel setup image ..."));
136 DEBUG ((DEBUG_INFO,
" [done]\n"));
139 LoadedImage->SetupBuf,
140 LoadedImage->SetupSize
142 if (EFI_ERROR (Status)) {
147 if (EFI_ERROR (Status)) {
152 LoadedImage->SetupBuf,
155 if (LoadedImage->KernelInitialSize == 0) {
156 Status = EFI_UNSUPPORTED;
161 LoadedImage->SetupBuf,
164 if (LoadedImage->KernelBuf ==
NULL) {
165 DEBUG ((DEBUG_ERROR,
"Unable to allocate memory for kernel!\n"));
166 Status = EFI_OUT_OF_RESOURCES;
170 DEBUG ((DEBUG_INFO,
"Kernel size: 0x%x\n", (UINT32)KernelSize));
171 DEBUG ((DEBUG_INFO,
"Reading kernel image ..."));
174 DEBUG ((DEBUG_INFO,
" [done]\n"));
179 if (LoadedImage->CommandLineSize > 0) {
182 LoadedImage->CommandLineSize
185 if (LoadedImage->CommandLine ==
NULL) {
186 DEBUG ((DEBUG_ERROR,
"Unable to allocate memory for kernel command line!\n"));
187 Status = EFI_OUT_OF_RESOURCES;
196 LoadedImage->SetupBuf,
197 LoadedImage->CommandLine
199 if (EFI_ERROR (Status)) {
206 if (LoadedImage->InitrdSize > 0) {
208 LoadedImage->SetupBuf,
211 if (LoadedImage->InitrdData ==
NULL) {
212 DEBUG ((DEBUG_ERROR,
"Unable to allocate memory for initrd!\n"));
213 Status = EFI_OUT_OF_RESOURCES;
219 "Initrd size: 0x%x\n",
220 (UINT32)LoadedImage->InitrdSize
222 DEBUG ((DEBUG_INFO,
"Reading initrd image ..."));
225 DEBUG ((DEBUG_INFO,
" [done]\n"));
229 LoadedImage->SetupBuf,
230 LoadedImage->InitrdData,
231 LoadedImage->InitrdSize
233 if (EFI_ERROR (Status)) {
238 Status =
gBS->InstallProtocolInterface (
240 &gOvmfLoadedX86LinuxKernelProtocolGuid,
244 if (EFI_ERROR (Status)) {
251 FreeLegacyImage (LoadedImage);
259QemuStartLegacyImage (
266 Status =
gBS->OpenProtocol (
268 &gOvmfLoadedX86LinuxKernelProtocolGuid,
269 (VOID **)&LoadedImage,
272 EFI_OPEN_PROTOCOL_GET_PROTOCOL
274 if (EFI_ERROR (Status)) {
275 return EFI_INVALID_PARAMETER;
278 return LoadLinux (LoadedImage->KernelBuf, LoadedImage->SetupBuf);
283QemuUnloadLegacyImage (
290 Status =
gBS->OpenProtocol (
292 &gOvmfLoadedX86LinuxKernelProtocolGuid,
293 (VOID **)&LoadedImage,
296 EFI_OPEN_PROTOCOL_GET_PROTOCOL
298 if (EFI_ERROR (Status)) {
299 return EFI_INVALID_PARAMETER;
302 Status =
gBS->UninstallProtocolInterface (
304 &gOvmfLoadedX86LinuxKernelProtocolGuid,
309 FreeLegacyImage (LoadedImage);
339 UINTN CommandLineSize;
351 Status =
gBS->LoadImage (
368 return EFI_NOT_FOUND;
370 case EFI_SECURITY_VIOLATION:
375 gBS->UnloadImage (KernelImageHandle);
379 case EFI_ACCESS_DENIED:
387 case EFI_UNSUPPORTED:
392 Status = QemuLoadLegacyImage (&KernelImageHandle);
393 if (EFI_ERROR (Status)) {
396 "%a: QemuLoadLegacyImage(): %r\n",
403 *ImageHandle = KernelImageHandle;
407 DEBUG ((DEBUG_ERROR,
"%a: LoadImage(): %r\n", __func__, Status));
414 Status =
gBS->OpenProtocol (
416 &gEfiLoadedImageProtocolGuid,
417 (VOID **)&KernelLoadedImage,
420 EFI_OPEN_PROTOCOL_GET_PROTOCOL
427 if (CommandLineSize == 0) {
431 if (CommandLine ==
NULL) {
432 Status = EFI_OUT_OF_RESOURCES;
442 if (CommandLine[CommandLineSize - 1] !=
'\0') {
445 "%a: kernel command line is not NUL-terminated\n",
448 Status = EFI_PROTOCOL_ERROR;
449 goto FreeCommandLine;
455 KernelLoadedImage->
LoadOptionsSize = (UINT32)((CommandLineSize - 1) * 2);
461 if (InitrdSize > 0) {
481 Status = EFI_OUT_OF_RESOURCES;
482 goto FreeCommandLine;
489 (CommandLineSize == 0) ?
"" : CommandLine,
490 (InitrdSize == 0) ?
"" :
" initrd=initrd"
494 "%a: command line: \"%s\"\n",
500 *ImageHandle = KernelImageHandle;
504 if (CommandLineSize > 0) {
509 if (EFI_ERROR (Status)) {
510 gBS->UnloadImage (KernelImageHandle);
540 Status =
gBS->OpenProtocol (
542 &gOvmfLoadedX86LinuxKernelProtocolGuid,
543 (VOID **)&LoadedImage,
546 EFI_OPEN_PROTOCOL_GET_PROTOCOL
548 if (!EFI_ERROR (Status)) {
549 return QemuStartLegacyImage (*ImageHandle);
552 Status =
gBS->StartImage (
558 if (Status == EFI_UNSUPPORTED) {
570 Status = QemuLoadLegacyImage (&KernelImageHandle);
571 if (EFI_ERROR (Status)) {
582 *ImageHandle = KernelImageHandle;
583 return QemuStartLegacyImage (KernelImageHandle);
612 Status =
gBS->OpenProtocol (
614 &gEfiLoadedImageProtocolGuid,
615 (VOID **)&KernelLoadedImage,
618 EFI_OPEN_PROTOCOL_GET_PROTOCOL
620 if (Status == EFI_UNSUPPORTED) {
626 return QemuUnloadLegacyImage (ImageHandle);
629 if (EFI_ERROR (Status)) {
630 return EFI_INVALID_PARAMETER;
646 return gBS->UnloadImage (ImageHandle);
#define MEDIA_FILEPATH_DP
#define MEDIA_VENDOR_DP
Media vendor device path subtype.
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI LoadLinuxInitializeKernelSetup(IN VOID *KernelSetup)
VOID *EFIAPI LoadLinuxAllocateCommandLinePages(IN UINTN Pages)
UINTN EFIAPI LoadLinuxGetKernelSize(IN VOID *KernelSetup, IN UINTN KernelSize)
VOID *EFIAPI LoadLinuxAllocateKernelPages(IN VOID *KernelSetup, IN UINTN Pages)
EFI_STATUS EFIAPI LoadLinuxSetCommandLine(IN OUT VOID *KernelSetup, IN CHAR8 *CommandLine)
EFI_STATUS EFIAPI LoadLinux(IN VOID *Kernel, IN OUT VOID *KernelSetup)
EFI_STATUS EFIAPI LoadLinuxCheckKernelSetup(IN VOID *KernelSetup, IN UINTN KernelSetupSize)
VOID *EFIAPI LoadLinuxAllocateKernelSetupPages(IN UINTN Pages)
VOID *EFIAPI LoadLinuxAllocateInitrdPages(IN VOID *KernelSetup, IN UINTN Pages)
EFI_STATUS EFIAPI LoadLinuxSetInitrd(IN OUT VOID *KernelSetup, IN VOID *Initrd, IN UINTN InitrdSize)
UINTN EFIAPI UnicodeSPrintAsciiFormat(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define ARRAY_SIZE(Array)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT32 EFIAPI QemuFwCfgRead32(VOID)
VOID EFIAPI QemuFwCfgReadBytes(IN UINTN Size, IN VOID *Buffer OPTIONAL)
VOID EFIAPI QemuFwCfgSelectItem(IN FIRMWARE_CONFIG_ITEM QemuFwCfgItem)
#define EFI_SIZE_TO_PAGES(Size)
EFI_STATUS EFIAPI QemuLoadKernelImage(OUT EFI_HANDLE *ImageHandle)
EFI_STATUS EFIAPI QemuStartKernelImage(IN OUT EFI_HANDLE *ImageHandle)
EFI_STATUS EFIAPI QemuUnloadKernelImage(IN EFI_HANDLE ImageHandle)
VOID * LoadOptions
A pointer to the image's binary load options.
UINT32 LoadOptionsSize
The size in bytes of LoadOptions.