From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by mx.groups.io with SMTP id smtpd.web12.10945.1583134196557642091 for ; Sun, 01 Mar 2020 23:29:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=GvHR/J46; spf=pass (domain: linaro.org, ip: 209.85.128.65, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wm1-f65.google.com with SMTP id z12so9834645wmi.4 for ; Sun, 01 Mar 2020 23:29:56 -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=IgbKq1+dCa9xAh2A8QL4u22gf7fQWEsTR3xwL3kw1k4=; b=GvHR/J469N3pE5wyEFJb4BBdJ86kD7DOss/L4pxHUI3b/9ezotzJcxIKAWigQgcYsb M9gV1jtL8Q8J7/D1dDpe7lnZ6HqeFy+e+U9kF36h4NxrXv8Xo5DY1lAsIqWmojt29zPG 9XinR1XfiX+l/mD6qqZLk/gGOhJ+Cl2RbzoPSHPQm+MU/MEyPHKP4hMIH2NZZJKfLOLD YMBzOrDvLbhnMB9cWaBZixbsX/UmYtuMuarVqvufAoFZoNimXcezWnmmJqwJRMVw3N8z jm1BQiGh220MSlfMBxqMRt62akp3vlDJwNJaKKyskUVou7zTTS0XDyPfBM7DbvIn/Jkx WwuA== 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=IgbKq1+dCa9xAh2A8QL4u22gf7fQWEsTR3xwL3kw1k4=; b=kDjwIQHPmYswzfnFY/Lo8kHlnugoms1eAI89PTtE4v46GiS3SG+QD5L9sTnE/TeKFf ymq5hxdbXiB57+2W6DOfmeiGRbeCs9Qpi5jdtASWVGOI4nTBqVfF404Cm7m1jJG1iRGM SJRjFPlcZieM9ANd17o38K0xZNC+rfqoYHPVU+X6Qo10Qs6YyB/4jlb0dTtMuMXHN13t n6irf+aAXfG/qfuPhRqbDNxYbFjerYoq6MxSMDDDX90Q6nquCykEv3LcQ3X9DxR7F0cG jGKfUU63ReDZV9HoPQf7cmi8qo3B3gtHKyy7eA65PTSfvS2nOQkGSEdDVOPWnpWhCo1K pIFw== X-Gm-Message-State: ANhLgQ2udMuQjsHN3ZxGP5YIe1gmH20SWOZzM+I41uv1wzwcMZu9wGYQ uEgD1ku2bvoqUNjVa5jcxCfZms6AqvbeWw== X-Google-Smtp-Source: ADFU+vulRVLrN3kpcaDPEu0pA/o449gsPlP7N4X9BLsBYzbR0KAzL2a+/S5qsqx3FlTosxhghI5tBg== X-Received: by 2002:a1c:4681:: with SMTP id t123mr9425671wma.86.1583134194867; Sun, 01 Mar 2020 23:29:54 -0800 (PST) Return-Path: Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id z131sm6347153wmg.25.2020.03.01.23.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 23:29:54 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [PATCH 12/13] OvmfPkg/QemuKernelLoaderFsDxe: add support for new Linux initrd device path Date: Mon, 2 Mar 2020 08:29:35 +0100 Message-Id: <20200302072936.29221-13-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200302072936.29221-1-ard.biesheuvel@linaro.org> References: <20200302072936.29221-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 --- 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 77d8fedb738a..415946edf22a 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, + IN 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. @@ -945,6 +1003,7 @@ QemuKernelLoaderFsDxeEntrypoint ( KERNEL_BLOB *KernelBlob; EFI_STATUS Status; EFI_HANDLE FileSystemHandle; + EFI_HANDLE InitrdLoadFile2Handle; if (!QemuFwCfgIsAvailable ()) { return EFI_NOT_FOUND; @@ -989,8 +1048,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 f4b50c265027..737f9b87a7c7 100644 --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf @@ -28,6 +28,7 @@ [LibraryClasses] BaseLib BaseMemoryLib DebugLib + DevicePathLib MemoryAllocationLib UefiBootServicesTableLib QemuFwCfgLib @@ -42,6 +43,7 @@ [Guids] [Protocols] gEfiDevicePathProtocolGuid ## PRODUCES + gEfiLoadFile2ProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## PRODUCES [Depex] -- 2.17.1