47 QEMU_KERNEL_LOADER_FS_MEDIA_GUID
55 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
66 QEMU_KERNEL_LOADER_FS_MEDIA_GUID
68 END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
75GetQemuKernelLoaderBlobSize (
85 Status = Root->Open (Root, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
86 if (EFI_ERROR (Status)) {
91 if (EFI_ERROR (Status)) {
95 if (FileSize > MAX_UINTN) {
96 Status = EFI_UNSUPPORTED;
100 *Size = (
UINTN)FileSize;
103 FileHandle->Close (FileHandle);
109ReadWholeQemuKernelLoaderBlob (
120 Status = Root->Open (Root, &FileHandle, FileName, EFI_FILE_MODE_READ, 0);
121 if (EFI_ERROR (Status)) {
126 Status = FileHandle->Read (FileHandle, &ReadSize, Buffer);
127 if (EFI_ERROR (Status)) {
131 if (ReadSize != Size) {
132 Status = EFI_PROTOCOL_ERROR;
138 FileHandle->Close (FileHandle);
174 UINTN CommandLineSize;
181 Status =
gBS->LoadImage (
193 case EFI_SECURITY_VIOLATION:
197 Status = EFI_ACCESS_DENIED;
202 Status == EFI_NOT_FOUND ? DEBUG_INFO : DEBUG_ERROR,
203 "%a: LoadImage(): %r\n",
213 Status =
gBS->OpenProtocol (
215 &gEfiLoadedImageProtocolGuid,
216 (VOID **)&KernelLoadedImage,
219 EFI_OPEN_PROTOCOL_GET_PROTOCOL
228 Status =
gBS->LocateDevicePath (
229 &gEfiSimpleFileSystemProtocolGuid,
233 if (EFI_ERROR (Status)) {
237 Status =
gBS->HandleProtocol (
239 &gEfiSimpleFileSystemProtocolGuid,
242 if (EFI_ERROR (Status)) {
246 Status = FsProtocol->OpenVolume (FsVolumeHandle, &Root);
247 if (EFI_ERROR (Status)) {
251 Status = GetQemuKernelLoaderBlobSize (Root, L
"cmdline", &CommandLineSize);
252 if (EFI_ERROR (Status)) {
256 if (CommandLineSize == 0) {
260 if (CommandLine ==
NULL) {
261 Status = EFI_OUT_OF_RESOURCES;
265 Status = ReadWholeQemuKernelLoaderBlob (
271 if (EFI_ERROR (Status)) {
272 goto FreeCommandLine;
278 if (CommandLine[CommandLineSize - 1] !=
'\0') {
281 "%a: kernel command line is not NUL-terminated\n",
284 Status = EFI_PROTOCOL_ERROR;
285 goto FreeCommandLine;
291 KernelLoadedImage->
LoadOptionsSize = (UINT32)((CommandLineSize - 1) * 2);
294 Status = GetQemuKernelLoaderBlobSize (Root, L
"initrd", &InitrdSize);
295 if (EFI_ERROR (Status)) {
296 goto FreeCommandLine;
299 if (InitrdSize > 0) {
319 Status = EFI_OUT_OF_RESOURCES;
320 goto FreeCommandLine;
327 (CommandLineSize == 0) ?
"" : CommandLine,
328 (InitrdSize == 0) ?
"" :
" initrd=initrd"
332 "%a: command line: \"%s\"\n",
338 *ImageHandle = KernelImageHandle;
342 if (CommandLineSize > 0) {
349 if (EFI_ERROR (Status)) {
350 gBS->UnloadImage (KernelImageHandle);
377 return gBS->StartImage (
406 Status =
gBS->OpenProtocol (
408 &gEfiLoadedImageProtocolGuid,
409 (VOID **)&KernelLoadedImage,
412 EFI_OPEN_PROTOCOL_GET_PROTOCOL
414 if (EFI_ERROR (Status)) {
415 return EFI_INVALID_PARAMETER;
425 return gBS->UnloadImage (ImageHandle);
#define MEDIA_FILEPATH_DP
#define MEDIA_VENDOR_DP
Media vendor device path subtype.
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI FileHandleGetSize(IN EFI_FILE_HANDLE FileHandle, OUT UINT64 *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)
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)
VOID CloseFile(IN EFI_FILE_HANDLE FileHandle)
VOID * LoadOptions
A pointer to the image's binary load options.
UINT32 LoadOptionsSize
The size in bytes of LoadOptions.