From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web09.12512.1583415988415435307 for ; Thu, 05 Mar 2020 05:46:28 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=Du+Ecyev; spf=pass (domain: linaro.org, ip: 209.85.221.66, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f66.google.com with SMTP id j16so7117198wrt.3 for ; Thu, 05 Mar 2020 05:46:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PJlCd8mb8706TnLao/FJI1Hd4Cp8eT5DxnphurShhPM=; b=Du+Ecyevnxyz71Bkv5ddYoHIarU51VSMeYst78uDfhD6ORtPiAuXxGV7pFxR7iHagO qYrz2vt7hk126r+COuixseulhNogpoZ+2/RFlwfLzgkgFfUCHSKTK46/U1F+neapH7D3 goRxkSk7qKzx8To6TmbPcWZbfSNS/jomQvtypnc3YVJOPVi0IU1iXR/o1KZOL+yG7ZI4 CrnzNOqZILfi17xezxaiMw38neJ7ompERRapDBfpD/MJUGig8hdjf7ZPzidhksa+xhLp rDVwpjepXyizzrjicyabdmyYn/o6KSN3HrURgk428rM91YHLL96BKMiPpt7Nr66pPAes XgFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PJlCd8mb8706TnLao/FJI1Hd4Cp8eT5DxnphurShhPM=; b=jxJnjx3uXUtyefVTYkUjdcAsLxtBuoB0t9xM2mtchJnpt3bpaDNux1ZyCA3+a8Z1I5 Ri/89myQZp3CxoH7Y5JZ8dDD+p4Zax8JXMWSPA4eSA5Rgg3NmkHekrvDAg/9hoUCbxLJ qEvNV+FdN3korGEz9KYJgA8X2nTgv79a5GTfUfk9G2T2dvNnh0tYwIWIpN+xMfPzu1B8 CIIaH02Sxur+m8D6q4MDWV+gU67NUMXYId8bTvs0pnBURAvR9GQ7wzyBTrCetgqKAzD3 diDFeBXETfYG28hTOXCDAmSl+6DqphQFNQ9Z8nX5/IhhrDQ4tz3iGT8sKoT1+GkUUBVT vTHw== X-Gm-Message-State: ANhLgQ1Yq/5mo1o+TAeIDnjZsL0L9NwJ/o7joubIYcXiALhsc4AKDnio eOcWwbM5O4RGgpr2XWHioOWhxuMLnqpL9A== X-Google-Smtp-Source: ADFU+vtU0oaYZrLpTtX9Zyhe6hQ8p7hT7lK3n48y5fsJew6gGdIyZeP7opm9m1OnjPFQEx4ub6DqJA== X-Received: by 2002:adf:b345:: with SMTP id k5mr10912762wrd.55.1583415986626; Thu, 05 Mar 2020 05:46:26 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id m19sm9278701wmc.34.2020.03.05.05.46.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:25 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [PATCH v3 13/14] OvmfPkg/QemuKernelLoaderFsDxe: add support for new Linux initrd device path Date: Thu, 5 Mar 2020 14:46:06 +0100 Message-Id: <20200305134607.20125-14-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Linux v5.7 will introduce a new method to load the initial ramdisk (initrd) from the loader, using the LoadFile2 protocol installed on a special vendor GUIDed media device path. Add support for this to our QEMU command line kernel/initrd loader. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 79 ++++++++++++++++++++ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf | 2 + 2 files changed, 81 insertions(+) diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c index 8ccb1983170c..869549f164f0 100644 --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c @@ -13,15 +13,18 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include #include +#include #include // @@ -84,6 +87,19 @@ STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mFileSystemDevicePath = { } }; +STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mInitrdDevicePath = { + { + { + MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, + { sizeof (VENDOR_DEVICE_PATH) } + }, + LINUX_EFI_INITRD_MEDIA_GUID + }, { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL) } + } +}; + // // The "file in the EFI stub filesystem" abstraction. // @@ -839,6 +855,48 @@ STATIC CONST EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mFileSystem = { StubFileSystemOpenVolume }; +STATIC +EFI_STATUS +EFIAPI +InitrdLoadFile2 ( + IN EFI_LOAD_FILE2_PROTOCOL *This, + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + IN BOOLEAN BootPolicy, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer OPTIONAL + ) +{ + CONST KERNEL_BLOB *InitrdBlob = &mKernelBlob[KernelBlobTypeInitrd]; + + ASSERT (InitrdBlob->Size > 0); + + if (BootPolicy) { + return EFI_UNSUPPORTED; + } + + if (BufferSize == NULL || !IsDevicePathValid (FilePath, 0)) { + return EFI_INVALID_PARAMETER; + } + + if (FilePath->Type != END_DEVICE_PATH_TYPE || + FilePath->SubType != END_ENTIRE_DEVICE_PATH_SUBTYPE) { + return EFI_NOT_FOUND; + } + + if (Buffer == NULL || *BufferSize < InitrdBlob->Size) { + *BufferSize = InitrdBlob->Size; + return EFI_BUFFER_TOO_SMALL; + } + + CopyMem (Buffer, InitrdBlob->Data, InitrdBlob->Size); + + *BufferSize = InitrdBlob->Size; + return EFI_SUCCESS; +} + +STATIC CONST EFI_LOAD_FILE2_PROTOCOL mInitrdLoadFile2 = { + InitrdLoadFile2, +}; // // Utility functions. @@ -949,6 +1007,7 @@ QemuKernelLoaderFsDxeEntrypoint ( KERNEL_BLOB *KernelBlob; EFI_STATUS Status; EFI_HANDLE FileSystemHandle; + EFI_HANDLE InitrdLoadFile2Handle; if (!QemuFwCfgIsAvailable ()) { return EFI_NOT_FOUND; @@ -993,8 +1052,28 @@ QemuKernelLoaderFsDxeEntrypoint ( goto FreeBlobs; } + if (KernelBlob[KernelBlobTypeInitrd].Size > 0) { + InitrdLoadFile2Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces (&InitrdLoadFile2Handle, + &gEfiDevicePathProtocolGuid, &mInitrdDevicePath, + &gEfiLoadFile2ProtocolGuid, &mInitrdLoadFile2, + NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: InstallMultipleProtocolInterfaces(): %r\n", + __FUNCTION__, Status)); + goto UninstallFileSystemHandle; + } + } + return EFI_SUCCESS; +UninstallFileSystemHandle: + Status = gBS->UninstallMultipleProtocolInterfaces (FileSystemHandle, + &gEfiDevicePathProtocolGuid, &mFileSystemDevicePath, + &gEfiSimpleFileSystemProtocolGuid, &mFileSystem, + NULL); + ASSERT_EFI_ERROR (Status); + FreeBlobs: while (BlobType > 0) { CurrentBlob = &mKernelBlob[--BlobType]; diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf index 5ba88063def0..7b35adb8e034 100644 --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf @@ -28,6 +28,7 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib + DevicePathLib MemoryAllocationLib QemuFwCfgLib UefiBootServicesTableLib @@ -42,6 +43,7 @@ [Guids] [Protocols] gEfiDevicePathProtocolGuid ## PRODUCES + gEfiLoadFile2ProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## PRODUCES [Depex] -- 2.17.1