summaryrefslogtreecommitdiff
path: root/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c')
-rw-r--r--OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c77
1 files changed, 69 insertions, 8 deletions
diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
index b99fb35..608f35e 100644
--- a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
+++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c
@@ -57,6 +57,25 @@ STATIC CONST KERNEL_VENMEDIA_FILE_DEVPATH mKernelDevicePath = {
}
};
+STATIC CONST KERNEL_VENMEDIA_FILE_DEVPATH mShimDevicePath = {
+ {
+ {
+ MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP,
+ { sizeof (VENDOR_DEVICE_PATH) }
+ },
+ QEMU_KERNEL_LOADER_FS_MEDIA_GUID
+ }, {
+ {
+ MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP,
+ { sizeof (KERNEL_FILE_DEVPATH) }
+ },
+ L"shim",
+ }, {
+ END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ { sizeof (EFI_DEVICE_PATH_PROTOCOL) }
+ }
+};
+
STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mQemuKernelLoaderFsDevicePath = {
{
{
@@ -174,6 +193,7 @@ QemuLoadKernelImage (
UINTN CommandLineSize;
CHAR8 *CommandLine;
UINTN InitrdSize;
+ BOOLEAN Shim;
//
// Load the image. This should call back into the QEMU EFI loader file system.
@@ -181,11 +201,35 @@ QemuLoadKernelImage (
Status = gBS->LoadImage (
FALSE, // BootPolicy: exact match required
gImageHandle, // ParentImageHandle
- (EFI_DEVICE_PATH_PROTOCOL *)&mKernelDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)&mShimDevicePath,
NULL, // SourceBuffer
0, // SourceSize
&KernelImageHandle
);
+ if (Status == EFI_SUCCESS) {
+ Shim = TRUE;
+ DEBUG ((DEBUG_INFO, "%a: booting via shim\n", __func__));
+ } else {
+ Shim = FALSE;
+ if (Status == EFI_SECURITY_VIOLATION) {
+ gBS->UnloadImage (KernelImageHandle);
+ }
+
+ if (Status != EFI_NOT_FOUND) {
+ DEBUG ((DEBUG_INFO, "%a: LoadImage(shim): %r\n", __func__, Status));
+ return Status;
+ }
+
+ Status = gBS->LoadImage (
+ FALSE, // BootPolicy: exact match required
+ gImageHandle, // ParentImageHandle
+ (EFI_DEVICE_PATH_PROTOCOL *)&mKernelDevicePath,
+ NULL, // SourceBuffer
+ 0, // SourceSize
+ &KernelImageHandle
+ );
+ }
+
switch (Status) {
case EFI_SUCCESS:
break;
@@ -250,9 +294,14 @@ QemuLoadKernelImage (
Status = GetQemuKernelLoaderBlobSize (Root, L"cmdline", &CommandLineSize);
if (EFI_ERROR (Status)) {
- goto CloseRoot;
+ if (Status == EFI_NOT_FOUND) {
+ CommandLineSize = 0;
+ } else {
+ goto CloseRoot;
+ }
}
+ CommandLine = NULL;
if (CommandLineSize == 0) {
KernelLoadedImage->LoadOptionsSize = 0;
} else {
@@ -293,14 +342,25 @@ QemuLoadKernelImage (
Status = GetQemuKernelLoaderBlobSize (Root, L"initrd", &InitrdSize);
if (EFI_ERROR (Status)) {
- goto FreeCommandLine;
+ if (Status == EFI_NOT_FOUND) {
+ InitrdSize = 0;
+ } else {
+ goto FreeCommandLine;
+ }
}
if (InitrdSize > 0) {
//
- // Append ' initrd=initrd' in UTF-16.
+ // Prefix ' initrd=initrd' in UTF-16.
+ //
+ KernelLoadedImage->LoadOptionsSize += sizeof (L"initrd=initrd ") - 2;
+ }
+
+ if (Shim) {
+ //
+ // Prefix 'kernel ' in UTF-16.
//
- KernelLoadedImage->LoadOptionsSize += sizeof (L" initrd=initrd") - 2;
+ KernelLoadedImage->LoadOptionsSize += sizeof (L"kernel ") - 2;
}
if (KernelLoadedImage->LoadOptionsSize == 0) {
@@ -323,9 +383,10 @@ QemuLoadKernelImage (
UnicodeSPrintAsciiFormat (
KernelLoadedImage->LoadOptions,
KernelLoadedImage->LoadOptionsSize,
- "%a%a",
- (CommandLineSize == 0) ? "" : CommandLine,
- (InitrdSize == 0) ? "" : " initrd=initrd"
+ "%a%a%a",
+ (Shim == FALSE) ? "" : "kernel ",
+ (InitrdSize == 0) ? "" : "initrd=initrd ",
+ (CommandLineSize == 0) ? "" : CommandLine
);
DEBUG ((
DEBUG_INFO,