From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55524+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55524+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415974; cv=none; d=zohomail.com; s=zohoarc; b=jXuaMg5OIWyiNdUNd1pcw2bR7DFG4cEI3x1uMsAyqe0Pmlt+XDMsbd+79qQVSsNIWUd+lUpGVUvxAF2RV1taS1mqv4RvWTwsYMw22ntQr4YWmZUsamLVi1/Es7ax3+McnqOGNODB9JjTFFfzlnk6ldnAbis2RqsQyeacD8cdZWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415974; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=I39/UDfLPrUxOiiA3bVNy+eWHTjyFBKu9t5lKKlcuHs=; b=n1YV+R/zPkY/iMAGeNw8Eqn+SxHUgOV5U+1Xqly0DV850DFZDOOXTF2/WVTt9ylS8dK46665kUxu518kHlM6ZwFW0Td1yhcFKkucyFPAbm1PDqmOtbmlnC9HRaQqzu9AmmNU7XZIVs5Ovl0Xbajh3HWQAAmfs50PlFBp28b3o0o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55524+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415974147283.20872442569294; Thu, 5 Mar 2020 05:46:14 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id GY13YY1788612xNzzw93gENY; Thu, 05 Mar 2020 05:46:13 -0800 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web11.12598.1583415972896948308 for ; Thu, 05 Mar 2020 05:46:13 -0800 X-Received: by mail-wr1-f67.google.com with SMTP id r7so7114338wro.2 for ; Thu, 05 Mar 2020 05:46:12 -0800 (PST) X-Gm-Message-State: jSDw54FCCHrJfueHhetnWsd4x1787277AA= X-Google-Smtp-Source: ADFU+vu0bBCfmJRulJfNZY3AQPDIMP/73FG3kqOO9h35TqUTy4iO0wunBPMA62bRSdeXJX092ruzMg== X-Received: by 2002:a5d:4dc7:: with SMTP id f7mr7399435wru.72.1583415971091; Thu, 05 Mar 2020 05:46:11 -0800 (PST) X-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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:10 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 01/14] OvmfPkg: add GUID for the QEMU kernel loader fs media device path Date: Thu, 5 Mar 2020 14:45:54 +0100 Message-Id: <20200305134607.20125-2-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415973; bh=p+UPAbURXb6qLX/Jha/4ph2Vi3yMDokh5TolHNvK4UA=; h=Cc:Date:From:Reply-To:Subject:To; b=wGyHFv4/csdfk/TT75Ul4TQ8/sqkH4862b+PBKyDwunuT1Jn+7QBH2vinsLTw3j2tZ9 grIi1HZqDZ2MN71yPMeFBg72NitBc2cUYAgdtWluVTjalMH9MKZn4C+AczmrS1Q+GVGMU fXRuDLs0R0WjUVfJXa7AMKnZX4y7T6nkjBQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In an upcoming patch, we will introduce a separate DXE driver that exposes the virtual SimpleFileSystem implementation that carries the kernel and initrd passed via the QEMU command line, and a separate library that consumes it, to be incorporated into the boot manager. Since the GUID used for the SimpleFileSystem implementation's device path will no longer be for internal use only, create a well defined GUID to identify the media device path. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Include/Guid/QemuKernelLoaderFsMedia.h | 18 ++++++++++++++++++ OvmfPkg/OvmfPkg.dec | 1 + 2 files changed, 19 insertions(+) diff --git a/OvmfPkg/Include/Guid/QemuKernelLoaderFsMedia.h b/OvmfPkg/Inclu= de/Guid/QemuKernelLoaderFsMedia.h new file mode 100644 index 000000000000..225c3c494613 --- /dev/null +++ b/OvmfPkg/Include/Guid/QemuKernelLoaderFsMedia.h @@ -0,0 +1,18 @@ +/** @file + GUID definition for the QEMU LoaderFs media device path, containing the + kernel, initrd and command line as file objects + + Copyright (c) 2020, Arm, Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef QEMU_KERNEL_LOADER_FS_MEDIA_GUID_H__ +#define QEMU_KERNEL_LOADER_FS_MEDIA_GUID_H__ + +#define QEMU_KERNEL_LOADER_FS_MEDIA_GUID \ + {0x1428f772, 0xb64a, 0x441e, {0xb8, 0xc3, 0x9e, 0xbd, 0xd7, 0xf8, 0x93, = 0xc7}} + +extern EFI_GUID gQemuKernelLoaderFsMediaGuid; + +#endif diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 43d16372a270..a21b279d140a 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -87,6 +87,7 @@ [Guids] gEfiLegacyBiosGuid =3D {0x2E3044AC, 0x879F, 0x490F, {0x= 97, 0x60, 0xBB, 0xDF, 0xAF, 0x69, 0x5F, 0x50}} gEfiLegacyDevOrderVariableGuid =3D {0xa56074db, 0x65fe, 0x45f7, {0x= bd, 0x21, 0x2d, 0x2b, 0xdd, 0x8e, 0x96, 0x52}} gLinuxEfiInitrdMediaGuid =3D {0x5568e427, 0x68fc, 0x4f3d, {0x= ac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68}} + gQemuKernelLoaderFsMediaGuid =3D {0x1428f772, 0xb64a, 0x441e, {0x= b8, 0xc3, 0x9e, 0xbd, 0xd7, 0xf8, 0x93, 0xc7}} =20 [Ppis] # PPI whose presence in the PPI database signals that the TPM base addre= ss --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55524): https://edk2.groups.io/g/devel/message/55524 Mute This Topic: https://groups.io/mt/71749513/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55526+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55526+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415976; cv=none; d=zohomail.com; s=zohoarc; b=NrSrT7h9irR4RWwwjXoeT+BkB3nJN7AATrsyrtQ3p7QApnN3k2+W+x9XSOR1Q8mjqtOJ9rZaZVuc79rJoNGOkv4sz4RAFYi69TUfki0EvB2mSjMT0uBTAqdFjo9c96FJEwzfKbKIRwCTgAJd4AeTXXUjYAI6i+A6gnSH+2wZn8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415976; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=V/9Svrqfl3QhP1Hb7XHiDEldASeENPPQpkvKpPDqjmg=; b=d4PWkHuW2a0XdXBAl3CLkmGAv+SDwfE6+qKGwvrYDPw74FARdB6julsSU/wyuP38BJ4JvtgPTi29Cg0BE2DCYPbzUhY0er9gfXTihy+nRtVvIzVuQV+cSaX7qVsLE/HVXAIkygekhEQ9M9N2qwniHEIfVdzRNdWRPUzTRlxgNUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55526+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415976676671.04953386792; Thu, 5 Mar 2020 05:46:16 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id E2jFYY1788612xuJshNKwI8O; Thu, 05 Mar 2020 05:46:16 -0800 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web11.12599.1583415975296147741 for ; Thu, 05 Mar 2020 05:46:15 -0800 X-Received: by mail-wr1-f67.google.com with SMTP id v2so7071281wrp.12 for ; Thu, 05 Mar 2020 05:46:15 -0800 (PST) X-Gm-Message-State: ts4fSz5O3ySEIlP5uwsDtnTOx1787277AA= X-Google-Smtp-Source: ADFU+vvryOOPDEa5CgmkxeOjbuSXuyjpS6nnFT/c2U1S4qghb+o5kLfU+xyp/rLW+UL0Lg/YFsYKEA== X-Received: by 2002:adf:9071:: with SMTP id h104mr10470442wrh.359.1583415972470; Thu, 05 Mar 2020 05:46:12 -0800 (PST) X-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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:11 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 02/14] OvmfPkg: export abstract QEMU blob filesystem in standalone driver Date: Thu, 5 Mar 2020 14:45:55 +0100 Message-Id: <20200305134607.20125-3-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415976; bh=2DdUpzPPjnIWRv7NUlHRCkTbQVZlgel6R+/RVIKGClI=; h=Cc:Date:From:Reply-To:Subject:To; b=uGwvKs4HK87iPG+BMyDOGvb7yrovRzNiuG7vgqSrNEE/CJlwnDDyYCoqUO/z//4yz12 mvssHAGNZW4mArDCol1zIq5iX/Po7xSPh50goiiFPqXo06sC1osfnaH3UmbcRjPAYnJCq BAc8AWmrj5/0v2k1T/JF/doWLzmVMisM8mc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Expose the existing implementation of an abstract filesystem exposing the blobs passed to QEMU via the command line via a standalone DXE driver. Notable difference with the original code is the switch to a new vendor GUIDed media device path, as opposed to a vendor GUID hardware device path, which is not entirely appropriate for pure software constructs. Since we are using the GetTime() runtime service in a DXE_DRIVER type module, we need to DEPEX explicitly on gEfiRealTimeClockArchProtocolGuid. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 979 ++++++++++++= ++++++++ OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf | 48 + 2 files changed, 1027 insertions(+) diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPk= g/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c new file mode 100644 index 000000000000..e4539ec2fbe5 --- /dev/null +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c @@ -0,0 +1,979 @@ +/** @file + DXE driver to expose the 'kernel', 'initrd' and 'cmdline' blobs + provided by QEMU as files in an abstract file system + + Copyright (C) 2014-2016, Red Hat, Inc. + Copyright (C) 2020, Arm, Limited. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +// Static data that hosts the fw_cfg blobs and serves file requests. +// +typedef enum { + KernelBlobTypeKernel, + KernelBlobTypeInitrd, + KernelBlobTypeCommandLine, + KernelBlobTypeMax +} KERNEL_BLOB_TYPE; + +typedef struct { + FIRMWARE_CONFIG_ITEM CONST SizeKey; + FIRMWARE_CONFIG_ITEM CONST DataKey; + CONST CHAR16 * CONST Name; + UINT32 Size; + UINT8 *Data; +} KERNEL_BLOB; + +STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] =3D { + { QemuFwCfgItemKernelSize, QemuFwCfgItemKernelData, L"kernel" = }, + { QemuFwCfgItemInitrdSize, QemuFwCfgItemInitrdData, L"initrd" = }, + { QemuFwCfgItemCommandLineSize, QemuFwCfgItemCommandLineData, L"cmdline"= } +}; + +STATIC UINT64 mTotalBlobBytes; + +// +// Device path for the handle that incorporates our "EFI stub filesystem". +// +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH VenMediaNode; + EFI_DEVICE_PATH_PROTOCOL EndNode; +} SINGLE_VENMEDIA_NODE_DEVPATH; +#pragma pack () + +STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mFileSystemDevicePath =3D { + { + { + MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, + { sizeof (VENDOR_DEVICE_PATH) } + }, + QEMU_KERNEL_LOADER_FS_MEDIA_GUID + }, { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL) } + } +}; + +// +// The "file in the EFI stub filesystem" abstraction. +// +STATIC EFI_TIME mInitTime; + +#define STUB_FILE_SIG SIGNATURE_64 ('S', 'T', 'U', 'B', 'F', 'I', 'L', 'E') + +typedef struct { + UINT64 Signature; // Carries STUB_FILE_SIG. + + KERNEL_BLOB_TYPE BlobType; // Index into mKernelBlob. KernelBlobTypeMax + // denotes the root directory of the filesy= stem. + + UINT64 Position; // Byte position for regular files; + // next directory entry to return for the r= oot + // directory. + + EFI_FILE_PROTOCOL File; // Standard protocol interface. +} STUB_FILE; + +#define STUB_FILE_FROM_FILE(FilePointer) \ + CR (FilePointer, STUB_FILE, File, STUB_FILE_SIG) + +// +// Tentative definition of the file protocol template. The initializer +// (external definition) will be provided later. +// +STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate; + + +// +// Protocol member functions for File. +// + +/** + Opens a new file relative to the source file's location. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that= is + the file handle to the source location. This wou= ld + typically be an open handle to a directory. + + @param[out] NewHandle A pointer to the location to return the opened h= andle + for the new file. + + @param[in] FileName The Null-terminated string of the name of the fi= le to + be opened. The file name may contain the followi= ng + path modifiers: "\", ".", and "..". + + @param[in] OpenMode The mode to open the file. The only valid + combinations that the file may be opened with ar= e: + Read, Read/Write, or Create/Read/Write. + + @param[in] Attributes Only valid for EFI_FILE_MODE_CREATE, in which ca= se + these are the attribute bits for the newly creat= ed + file. + + @retval EFI_SUCCESS The file was opened. + @retval EFI_NOT_FOUND The specified file could not be found on t= he + device. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or= the + medium is no longer supported. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or o= pen a + file for write when the media is + write-protected. + @retval EFI_ACCESS_DENIED The service denied access to the file. + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to ope= n the + file. + @retval EFI_VOLUME_FULL The volume is full. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ + CONST STUB_FILE *StubFile; + UINTN BlobType; + STUB_FILE *NewStubFile; + + // + // We're read-only. + // + switch (OpenMode) { + case EFI_FILE_MODE_READ: + break; + + case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE: + case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE: + return EFI_WRITE_PROTECTED; + + default: + return EFI_INVALID_PARAMETER; + } + + // + // Only the root directory supports opening files in it. + // + StubFile =3D STUB_FILE_FROM_FILE (This); + if (StubFile->BlobType !=3D KernelBlobTypeMax) { + return EFI_UNSUPPORTED; + } + + // + // Locate the file. + // + for (BlobType =3D 0; BlobType < KernelBlobTypeMax; ++BlobType) { + if (StrCmp (FileName, mKernelBlob[BlobType].Name) =3D=3D 0) { + break; + } + } + if (BlobType =3D=3D KernelBlobTypeMax) { + return EFI_NOT_FOUND; + } + + // + // Found it. + // + NewStubFile =3D AllocatePool (sizeof *NewStubFile); + if (NewStubFile =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + NewStubFile->Signature =3D STUB_FILE_SIG; + NewStubFile->BlobType =3D (KERNEL_BLOB_TYPE)BlobType; + NewStubFile->Position =3D 0; + CopyMem (&NewStubFile->File, &mEfiFileProtocolTemplate, + sizeof mEfiFileProtocolTemplate); + *NewHandle =3D &NewStubFile->File; + + return EFI_SUCCESS; +} + + +/** + Closes a specified file handle. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the= file + handle to close. + + @retval EFI_SUCCESS The file was closed. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileClose ( + IN EFI_FILE_PROTOCOL *This + ) +{ + FreePool (STUB_FILE_FROM_FILE (This)); + return EFI_SUCCESS; +} + + +/** + Close and delete the file handle. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the + handle to the file to delete. + + @retval EFI_SUCCESS The file was closed and deleted, and the + handle was closed. + @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was= not + deleted. + +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileDelete ( + IN EFI_FILE_PROTOCOL *This + ) +{ + FreePool (STUB_FILE_FROM_FILE (This)); + return EFI_WARN_DELETE_FAILURE; +} + + +/** + Helper function that formats an EFI_FILE_INFO structure into the + user-allocated buffer, for any valid KERNEL_BLOB_TYPE value (including + KernelBlobTypeMax, which stands for the root directory). + + The interface follows the EFI_FILE_GET_INFO -- and for directories, the + EFI_FILE_READ -- interfaces. + + @param[in] BlobType The KERNEL_BLOB_TYPE value identifying the f= w_cfg + blob backing the STUB_FILE that information = is + being requested about. If BlobType equals + KernelBlobTypeMax, then information will be + provided about the root directory of the + filesystem. + + @param[in,out] BufferSize On input, the size of Buffer. On output, the + amount of data returned in Buffer. In both ca= ses, + the size is measured in bytes. + + @param[out] Buffer A pointer to the data buffer to return. The + buffer's type is EFI_FILE_INFO. + + @retval EFI_SUCCESS The information was returned. + @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to store the + EFI_FILE_INFO structure. BufferSize has be= en + updated with the size needed to complete t= he + request. +**/ +STATIC +EFI_STATUS +ConvertKernelBlobTypeToFileInfo ( + IN KERNEL_BLOB_TYPE BlobType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + CONST CHAR16 *Name; + UINT64 FileSize; + UINT64 Attribute; + + UINTN NameSize; + UINTN FileInfoSize; + EFI_FILE_INFO *FileInfo; + UINTN OriginalBufferSize; + + if (BlobType =3D=3D KernelBlobTypeMax) { + // + // getting file info about the root directory + // + Name =3D L"\\"; + FileSize =3D KernelBlobTypeMax; + Attribute =3D EFI_FILE_READ_ONLY | EFI_FILE_DIRECTORY; + } else { + CONST KERNEL_BLOB *Blob; + + Blob =3D &mKernelBlob[BlobType]; + Name =3D Blob->Name; + FileSize =3D Blob->Size; + Attribute =3D EFI_FILE_READ_ONLY; + } + + NameSize =3D (StrLen(Name) + 1) * 2; + FileInfoSize =3D OFFSET_OF (EFI_FILE_INFO, FileName) + NameSize; + ASSERT (FileInfoSize >=3D sizeof *FileInfo); + + OriginalBufferSize =3D *BufferSize; + *BufferSize =3D FileInfoSize; + if (OriginalBufferSize < *BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + FileInfo =3D (EFI_FILE_INFO *)Buffer; + FileInfo->Size =3D FileInfoSize; + FileInfo->FileSize =3D FileSize; + FileInfo->PhysicalSize =3D FileSize; + FileInfo->Attribute =3D Attribute; + + CopyMem (&FileInfo->CreateTime, &mInitTime, sizeof mInitTime); + CopyMem (&FileInfo->LastAccessTime, &mInitTime, sizeof mInitTime); + CopyMem (&FileInfo->ModificationTime, &mInitTime, sizeof mInitTime); + CopyMem (FileInfo->FileName, Name, NameSize); + + return EFI_SUCCESS; +} + + +/** + Reads data from a file, or continues scanning a directory. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance t= hat + is the file handle to read data from. + + @param[in,out] BufferSize On input, the size of the Buffer. On output, = the + amount of data returned in Buffer. In both ca= ses, + the size is measured in bytes. If the read go= es + beyond the end of the file, the read length is + truncated to the end of the file. + + If This is a directory, the function reads the + directory entry at the current position and + returns the entry (as EFI_FILE_INFO) in Buffe= r. If + there are no more directory entries, the + BufferSize is set to zero on output. + + @param[out] Buffer The buffer into which the data is read. + + @retval EFI_SUCCESS Data was read. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted + file. + @retval EFI_DEVICE_ERROR On entry, the current file position is bey= ond + the end of the file. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to store the + current directory entry as a EFI_FILE_INFO + structure. BufferSize has been updated wit= h the + size needed to complete the request, and t= he + directory position has not been advanced. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileRead ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + STUB_FILE *StubFile; + CONST KERNEL_BLOB *Blob; + UINT64 Left; + + StubFile =3D STUB_FILE_FROM_FILE (This); + + // + // Scanning the root directory? + // + if (StubFile->BlobType =3D=3D KernelBlobTypeMax) { + EFI_STATUS Status; + + if (StubFile->Position =3D=3D KernelBlobTypeMax) { + // + // Scanning complete. + // + *BufferSize =3D 0; + return EFI_SUCCESS; + } + + Status =3D ConvertKernelBlobTypeToFileInfo ( + (KERNEL_BLOB_TYPE)StubFile->Position, + BufferSize, + Buffer); + if (EFI_ERROR (Status)) { + return Status; + } + + ++StubFile->Position; + return EFI_SUCCESS; + } + + // + // Reading a file. + // + Blob =3D &mKernelBlob[StubFile->BlobType]; + if (StubFile->Position > Blob->Size) { + return EFI_DEVICE_ERROR; + } + + Left =3D Blob->Size - StubFile->Position; + if (*BufferSize > Left) { + *BufferSize =3D (UINTN)Left; + } + if (Blob->Data !=3D NULL) { + CopyMem (Buffer, Blob->Data + StubFile->Position, *BufferSize); + } + StubFile->Position +=3D *BufferSize; + return EFI_SUCCESS; +} + + +/** + Writes data to a file. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance t= hat + is the file handle to write data to. + + @param[in,out] BufferSize On input, the size of the Buffer. On output, = the + amount of data actually written. In both case= s, + the size is measured in bytes. + + @param[in] Buffer The buffer of data to write. + + @retval EFI_SUCCESS Data was written. + @retval EFI_UNSUPPORTED Writes to open directory files are not + supported. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted = file. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write-protected. + @retval EFI_ACCESS_DENIED The file was opened read only. + @retval EFI_VOLUME_FULL The volume is full. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileWrite ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer + ) +{ + STUB_FILE *StubFile; + + StubFile =3D STUB_FILE_FROM_FILE (This); + return (StubFile->BlobType =3D=3D KernelBlobTypeMax) ? + EFI_UNSUPPORTED : + EFI_WRITE_PROTECTED; +} + + +/** + Returns a file's current position. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that i= s the + file handle to get the current position on. + + @param[out] Position The address to return the file's current position + value. + + @retval EFI_SUCCESS The position was returned. + @retval EFI_UNSUPPORTED The request is not valid on open directories. + @retval EFI_DEVICE_ERROR An attempt was made to get the position from a + deleted file. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileGetPosition ( + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position + ) +{ + STUB_FILE *StubFile; + + StubFile =3D STUB_FILE_FROM_FILE (This); + if (StubFile->BlobType =3D=3D KernelBlobTypeMax) { + return EFI_UNSUPPORTED; + } + + *Position =3D StubFile->Position; + return EFI_SUCCESS; +} + + +/** + Sets a file's current position. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is= the + file handle to set the requested position on. + + @param[in] Position The byte position from the start of the file to set= . For + regular files, MAX_UINT64 means "seek to end". For + directories, zero means "rewind directory scan". + + @retval EFI_SUCCESS The position was set. + @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on o= pen + directories. + @retval EFI_DEVICE_ERROR An attempt was made to set the position of a + deleted file. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileSetPosition ( + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position + ) +{ + STUB_FILE *StubFile; + KERNEL_BLOB *Blob; + + StubFile =3D STUB_FILE_FROM_FILE (This); + + if (StubFile->BlobType =3D=3D KernelBlobTypeMax) { + if (Position =3D=3D 0) { + // + // rewinding a directory scan is allowed + // + StubFile->Position =3D 0; + return EFI_SUCCESS; + } + return EFI_UNSUPPORTED; + } + + // + // regular file seek + // + Blob =3D &mKernelBlob[StubFile->BlobType]; + if (Position =3D=3D MAX_UINT64) { + // + // seek to end + // + StubFile->Position =3D Blob->Size; + } else { + // + // absolute seek from beginning -- seeking past the end is allowed + // + StubFile->Position =3D Position; + } + return EFI_SUCCESS; +} + + +/** + Returns information about a file. + + @param[in] This A pointer to the EFI_FILE_PROTOCOL insta= nce + that is the file handle the requested + information is for. + + @param[in] InformationType The type identifier GUID for the informa= tion + being requested. The following informati= on + types are supported, storing the + corresponding structures in Buffer: + + - gEfiFileInfoGuid: EFI_FILE_INFO + + - gEfiFileSystemInfoGuid: + EFI_FILE_SYSTEM_INFO + + - gEfiFileSystemVolumeLabelInfoIdGuid: + EFI_FILE_SYSTEM_VOLUME_LABEL + + @param[in,out] BufferSize On input, the size of Buffer. On output,= the + amount of data returned in Buffer. In bo= th + cases, the size is measured in bytes. + + @param[out] Buffer A pointer to the data buffer to return. = The + buffer's type is indicated by + InformationType. + + @retval EFI_SUCCESS The information was returned. + @retval EFI_UNSUPPORTED The InformationType is not known. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to store the + information structure requested by + InformationType. BufferSize has been updat= ed + with the size needed to complete the reque= st. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileGetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + CONST STUB_FILE *StubFile; + UINTN OriginalBufferSize; + + StubFile =3D STUB_FILE_FROM_FILE (This); + + if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { + return ConvertKernelBlobTypeToFileInfo (StubFile->BlobType, BufferSize, + Buffer); + } + + OriginalBufferSize =3D *BufferSize; + + if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { + EFI_FILE_SYSTEM_INFO *FileSystemInfo; + + *BufferSize =3D sizeof *FileSystemInfo; + if (OriginalBufferSize < *BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + FileSystemInfo =3D (EFI_FILE_SYSTEM_INFO *)Buffer; + FileSystemInfo->Size =3D sizeof *FileSystemInfo; + FileSystemInfo->ReadOnly =3D TRUE; + FileSystemInfo->VolumeSize =3D mTotalBlobBytes; + FileSystemInfo->FreeSpace =3D 0; + FileSystemInfo->BlockSize =3D 1; + FileSystemInfo->VolumeLabel[0] =3D L'\0'; + + return EFI_SUCCESS; + } + + if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid))= { + EFI_FILE_SYSTEM_VOLUME_LABEL *FileSystemVolumeLabel; + + *BufferSize =3D sizeof *FileSystemVolumeLabel; + if (OriginalBufferSize < *BufferSize) { + return EFI_BUFFER_TOO_SMALL; + } + + FileSystemVolumeLabel =3D (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer; + FileSystemVolumeLabel->VolumeLabel[0] =3D L'\0'; + + return EFI_SUCCESS; + } + + return EFI_UNSUPPORTED; +} + + +/** + Sets information about a file. + + @param[in] File A pointer to the EFI_FILE_PROTOCOL instance = that + is the file handle the information is for. + + @param[in] InformationType The type identifier for the information being + set. + + @param[in] BufferSize The size, in bytes, of Buffer. + + @param[in] Buffer A pointer to the data buffer to write. The + buffer's type is indicated by InformationTyp= e. + + @retval EFI_SUCCESS The information was set. + @retval EFI_UNSUPPORTED The InformationType is not known. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the + media is read-only. + @retval EFI_WRITE_PROTECTED InformationType is + EFI_FILE_PROTOCOL_SYSTEM_INFO_ID and the m= edia + is read only. + @retval EFI_WRITE_PROTECTED InformationType is + EFI_FILE_SYSTEM_VOLUME_LABEL_ID and the me= dia + is read-only. + @retval EFI_ACCESS_DENIED An attempt is made to change the name of a= file + to a file that is already present. + @retval EFI_ACCESS_DENIED An attempt is being made to change the + EFI_FILE_DIRECTORY Attribute. + @retval EFI_ACCESS_DENIED An attempt is being made to change the siz= e of + a directory. + @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the + file was opened read-only and an attempt is + being made to modify a field other than + Attribute. + @retval EFI_VOLUME_FULL The volume is full. + @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the= type + indicated by InformationType. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileSetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + return EFI_WRITE_PROTECTED; +} + + +/** + Flushes all modified data associated with a file to a device. + + @param [in] This A pointer to the EFI_FILE_PROTOCOL instance that is the + file handle to flush. + + @retval EFI_SUCCESS The data was flushed. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write-protected. + @retval EFI_ACCESS_DENIED The file was opened read-only. + @retval EFI_VOLUME_FULL The volume is full. +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileFlush ( + IN EFI_FILE_PROTOCOL *This + ) +{ + return EFI_WRITE_PROTECTED; +} + +// +// External definition of the file protocol template. +// +STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate =3D { + EFI_FILE_PROTOCOL_REVISION, // revision 1 + StubFileOpen, + StubFileClose, + StubFileDelete, + StubFileRead, + StubFileWrite, + StubFileGetPosition, + StubFileSetPosition, + StubFileGetInfo, + StubFileSetInfo, + StubFileFlush, + NULL, // OpenEx, revision 2 + NULL, // ReadEx, revision 2 + NULL, // WriteEx, revision 2 + NULL // FlushEx, revision 2 +}; + + +// +// Protocol member functions for SimpleFileSystem. +// + +/** + Open the root directory on a volume. + + @param[in] This A pointer to the volume to open the root directory on. + + @param[out] Root A pointer to the location to return the opened file ha= ndle + for the root directory in. + + @retval EFI_SUCCESS The device was opened. + @retval EFI_UNSUPPORTED This volume does not support the requested= file + system type. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_ACCESS_DENIED The service denied access to the file. + @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of + resources. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or= the + medium is no longer supported. Any existing + file handles for this volume are no longer + valid. To access the files on the new medi= um, + the volume must be reopened with OpenVolum= e(). +**/ +STATIC +EFI_STATUS +EFIAPI +StubFileSystemOpenVolume ( + IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **Root + ) +{ + STUB_FILE *StubFile; + + StubFile =3D AllocatePool (sizeof *StubFile); + if (StubFile =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + StubFile->Signature =3D STUB_FILE_SIG; + StubFile->BlobType =3D KernelBlobTypeMax; + StubFile->Position =3D 0; + CopyMem (&StubFile->File, &mEfiFileProtocolTemplate, + sizeof mEfiFileProtocolTemplate); + *Root =3D &StubFile->File; + + return EFI_SUCCESS; +} + +STATIC CONST EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mFileSystem =3D { + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION, + StubFileSystemOpenVolume +}; + + +// +// Utility functions. +// + +/** + Populate a blob in mKernelBlob. + + param[in,out] Blob Pointer to the KERNEL_BLOB element in mKernelBlob th= at is + to be filled from fw_cfg. + + @retval EFI_SUCCESS Blob has been populated. If fw_cfg reporte= d a + size of zero for the blob, then Blob->Data= has + been left unchanged. + + @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Blob->Data. +**/ +STATIC +EFI_STATUS +FetchBlob ( + IN OUT KERNEL_BLOB *Blob + ) +{ + UINT32 Left; + + // + // Read blob size. + // + QemuFwCfgSelectItem (Blob->SizeKey); + Blob->Size =3D QemuFwCfgRead32 (); + if (Blob->Size =3D=3D 0) { + return EFI_SUCCESS; + } + + // + // Read blob. + // + Blob->Data =3D AllocatePool (Blob->Size); + if (Blob->Data =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to allocate %Ld bytes for \"%s\"\n", + __FUNCTION__, (INT64)Blob->Size, Blob->Name)); + return EFI_OUT_OF_RESOURCES; + } + + DEBUG ((DEBUG_INFO, "%a: loading %Ld bytes for \"%s\"\n", __FUNCTION__, + (INT64)Blob->Size, Blob->Name)); + QemuFwCfgSelectItem (Blob->DataKey); + + Left =3D Blob->Size; + do { + UINT32 Chunk; + + Chunk =3D (Left < SIZE_1MB) ? Left : SIZE_1MB; + QemuFwCfgReadBytes (Chunk, Blob->Data + (Blob->Size - Left)); + Left -=3D Chunk; + DEBUG ((DEBUG_VERBOSE, "%a: %Ld bytes remaining for \"%s\"\n", + __FUNCTION__, (INT64)Left, Blob->Name)); + } while (Left > 0); + return EFI_SUCCESS; +} + + +// +// The entry point of the feature. +// + +/** + Download the kernel, the initial ramdisk, and the kernel command line fr= om + QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two + image files. + + @retval EFI_NOT_FOUND Kernel image was not found. + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + @retval EFI_PROTOCOL_ERROR Unterminated kernel command line. + + @return Error codes from any of the underlying + functions. On success, the function doesn't + return. +**/ +EFI_STATUS +EFIAPI +QemuKernelLoaderFsDxeEntrypoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + UINTN BlobType; + KERNEL_BLOB *CurrentBlob; + KERNEL_BLOB *KernelBlob; + EFI_STATUS Status; + EFI_HANDLE FileSystemHandle; + + if (!QemuFwCfgIsAvailable ()) { + return EFI_NOT_FOUND; + } + + Status =3D gRT->GetTime (&mInitTime, NULL /* Capabilities */); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: GetTime(): %r\n", __FUNCTION__, Status)); + return Status; + } + + // + // Fetch all blobs. + // + for (BlobType =3D 0; BlobType < KernelBlobTypeMax; ++BlobType) { + CurrentBlob =3D &mKernelBlob[BlobType]; + Status =3D FetchBlob (CurrentBlob); + if (EFI_ERROR (Status)) { + goto FreeBlobs; + } + mTotalBlobBytes +=3D CurrentBlob->Size; + } + KernelBlob =3D &mKernelBlob[KernelBlobTypeKernel]; + + if (KernelBlob->Data =3D=3D NULL) { + Status =3D EFI_NOT_FOUND; + goto FreeBlobs; + } + + // + // Create a new handle with a single VenMedia() node device path protoco= l on + // it, plus a custom SimpleFileSystem protocol on it. + // + FileSystemHandle =3D NULL; + Status =3D gBS->InstallMultipleProtocolInterfaces (&FileSystemHandle, + &gEfiDevicePathProtocolGuid, &mFileSystemDevicePat= h, + &gEfiSimpleFileSystemProtocolGuid, &mFileSystem, + NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: InstallMultipleProtocolInterfaces(): %r\n", + __FUNCTION__, Status)); + goto FreeBlobs; + } + + return EFI_SUCCESS; + +FreeBlobs: + while (BlobType > 0) { + CurrentBlob =3D &mKernelBlob[--BlobType]; + if (CurrentBlob->Data !=3D NULL) { + FreePool (CurrentBlob->Data); + CurrentBlob->Size =3D 0; + CurrentBlob->Data =3D NULL; + } + } + + return Status; +} diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf b/Ovmf= Pkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf new file mode 100644 index 000000000000..5ba88063def0 --- /dev/null +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf @@ -0,0 +1,48 @@ +## @file +# DXE driver to expose the 'kernel', 'initrd' and 'cmdline' blobs +# provided by QEMU as files in an abstract file system +# +# Copyright (C) 2014-2016, Red Hat, Inc. +# Copyright (C) 2020, Arm, Limited. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D QemuKernelLoaderFsDxe + FILE_GUID =3D 806040ca-dad9-4978-a3b4-2d2ab0c8a48f + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D QemuKernelLoaderFsDxeEntrypoint + +[Sources] + QemuKernelLoaderFsDxe.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + QemuFwCfgLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiRuntimeServicesTableLib + +[Guids] + gEfiFileInfoGuid + gEfiFileSystemInfoGuid + gEfiFileSystemVolumeLabelInfoIdGuid + gQemuKernelLoaderFsMediaGuid + +[Protocols] + gEfiDevicePathProtocolGuid ## PRODUCES + gEfiSimpleFileSystemProtocolGuid ## PRODUCES + +[Depex] + gEfiRealTimeClockArchProtocolGuid --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55526): https://edk2.groups.io/g/devel/message/55526 Mute This Topic: https://groups.io/mt/71749516/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55525+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55525+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415976; cv=none; d=zohomail.com; s=zohoarc; b=iUstuAZFvwORPKZ2KiORVA6JxMgQ/EhyC3Xq4tW7pWrwg4PWzzOrEuF/qMDHzrIpnGMBFttdrSwd94A+cfXuZuTPJ0bCAYQ3U2faEAlBmEeTLxmKVVQPSX/9jZGKgQvSohSt55LFjTUayZD/mlgjNCYOF0rSMYfc+lFMQkeIs4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415976; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=EMRSB/GQFW/saOO6LIpeKWS+acI/jzh780y+TZ8jFbk=; b=R7FnqYMEB2Tg3sf461HoGC0Y+AENWd09qXgghH1NAUhG60HM9jQnI1y0C771cXixZMgnCegiiaxl1NCE6Gpa+drrUM2s9D3jh7cNOBM+Awk50uEkdWIRXuEV54KZDprk2gbCb+YqwAK9zpRjcQIAvhyNS8Y14t5Zh7BZOzbu7pM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55525+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415976536536.0503475346393; Thu, 5 Mar 2020 05:46:16 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4LCJYY1788612xywEyn0zKTN; Thu, 05 Mar 2020 05:46:16 -0800 X-Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web12.12578.1583415975462209453 for ; Thu, 05 Mar 2020 05:46:15 -0800 X-Received: by mail-wr1-f66.google.com with SMTP id x7so7111242wrr.0 for ; Thu, 05 Mar 2020 05:46:15 -0800 (PST) X-Gm-Message-State: SLLAmk9gfaqjP4dGJNOtjvy7x1787277AA= X-Google-Smtp-Source: ADFU+vuI71Mmqe/Up0omth0cslkU6IOuFwbBef3hdG6qjxe01gTzmyV+d5bYZc1Sdl0qhqiGp2o8wA== X-Received: by 2002:adf:e7c8:: with SMTP id e8mr10199899wrn.298.1583415973588; Thu, 05 Mar 2020 05:46:13 -0800 (PST) X-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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:12 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 03/14] OvmfPkg: introduce QemuLoadImageLib library class Date: Thu, 5 Mar 2020 14:45:56 +0100 Message-Id: <20200305134607.20125-4-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415976; bh=CL156sSlPdySMP1DOd5hhUIaFdNjeeN2Mwafm/I6vDc=; h=Cc:Date:From:Reply-To:Subject:To; b=xb3Af8VvwqCEVgzHZsvwe6kQkXyEfKkr2PlHdCGy/4muVKVQZbTaeFhu6gfT0S1FwiH EL9QTxzB7T5wBmwj6FUsXXjj2NpxNSsIZvN5Tdx7pHUcUgLV1akYOVAlLrzuojktPK+ty iQq8cBYUqpkE8CvOhXYVuDdkfugbK5OaSOM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce the QemuLoadImageLib library class that we will instantiate to load the kernel image passed via the QEMU command line using the standard LoadImage boot service. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Include/Library/QemuLoadImageLib.h | 84 ++++++++++++++++++++ OvmfPkg/OvmfPkg.dec | 5 ++ 2 files changed, 89 insertions(+) diff --git a/OvmfPkg/Include/Library/QemuLoadImageLib.h b/OvmfPkg/Include/L= ibrary/QemuLoadImageLib.h new file mode 100644 index 000000000000..746b74f73c40 --- /dev/null +++ b/OvmfPkg/Include/Library/QemuLoadImageLib.h @@ -0,0 +1,84 @@ +/** @file + Load a kernel image and command line passed to QEMU via + the command line + + Copyright (C) 2020, Arm, Limited. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef QEMU_LOAD_IMAGE_LIB_H__ +#define QEMU_LOAD_IMAGE_LIB_H__ + +#include +#include + +#include + +/** + Download the kernel, the initial ramdisk, and the kernel command line fr= om + QEMU's fw_cfg. The kernel will be instructed via its command line to load + the initrd from the same Simple FileSystem where the kernel was loaded f= rom. + + @param[out] ImageHandle The image handle that was allocated for + loading the image + + @retval EFI_SUCCESS The image was loaded successfully. + @retval EFI_NOT_FOUND Kernel image was not found. + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + @retval EFI_PROTOCOL_ERROR Unterminated kernel command line. + @retval EFI_ACCESS_DENIED The underlying LoadImage boot service call + returned EFI_SECURITY_VIOLATION, and the i= mage + was unloaded again. + + @return Error codes from any of the underlying + functions. +**/ +EFI_STATUS +EFIAPI +QemuLoadKernelImage ( + OUT EFI_HANDLE *ImageHandle + ); + +/** + Transfer control to a kernel image loaded with QemuLoadKernelImage () + + @param[in,out] ImageHandle Handle of image to be started. May assum= e a + different value on return if the image w= as + reloaded. + + @retval EFI_INVALID_PARAMETER ImageHandle is either an invalid image h= andle + or the image has already been initialize= d with + StartImage + @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the + image should not be started. + + @return Error codes returned by the started imag= e. + On success, the function doesn't return. +**/ +EFI_STATUS +EFIAPI +QemuStartKernelImage ( + IN OUT EFI_HANDLE *ImageHandle + ); + +/** + Unloads an image loaded with QemuLoadKernelImage (). + + @param ImageHandle Handle that identifies the image to be + unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_UNSUPPORTED The image has been started, and does not + support unload. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + + @return Exit code from the image's unload functi= on. +**/ +EFI_STATUS +EFIAPI +QemuUnloadKernelImage ( + IN EFI_HANDLE ImageHandle + ); + +#endif diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index a21b279d140a..055caaa43041 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -58,6 +58,11 @@ [LibraryClasses] # QemuBootOrderLib|Include/Library/QemuBootOrderLib.h =20 + ## @libraryclass Load a kernel image and command line passed to QEMU v= ia + # the command line + # + QemuLoadImageLib|Include/Library/QemuLoadImageLib.h + ## @libraryclass Serialize (and deserialize) variables # SerializeVariablesLib|Include/Library/SerializeVariablesLib.h --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55525): https://edk2.groups.io/g/devel/message/55525 Mute This Topic: https://groups.io/mt/71749515/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55527+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55527+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415978; cv=none; d=zohomail.com; s=zohoarc; b=OLpytDTR/33FsJVwziHDnG4GgAo5xfKwVNJna53mCA+tBMDEd1Bgd9vU7p+8XNpKAzG+JDvHbPvHOS2SWW2FdDrZ0Xxfm526iF+Qb/69d5VEs6te9OUZYowUSzyUQIzpDY4Xh4l68KY8j3XLMoAe+gGyD8JrrJ3yvfzlzL7+FRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415978; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=SuA13cg0zMdQW3ZeQF49Xas5z6JnHmSTnlju5tGz5rk=; b=WzlGFmaxOQp9uIUrop8qqImI8cWtRUwoX7XTZsJbcOxo2BeHKWK+WA6Fp1V9TStSYBfGC2EYx8vfMzH3XyFEV3zOYgWxSaw/WPZGvA0wgvK5JWoWrXQpufuTKZIRhql4neQA5ZjBIjo1rl6/UkbvN2TUyum4wfiaPrqadOmFvZU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55527+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415978136482.79393346549193; Thu, 5 Mar 2020 05:46:18 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id CgprYY1788612xq5UU19EQ5Y; Thu, 05 Mar 2020 05:46:17 -0800 X-Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.groups.io with SMTP id smtpd.web10.12693.1583415977078035500 for ; Thu, 05 Mar 2020 05:46:17 -0800 X-Received: by mail-wm1-f67.google.com with SMTP id i9so6373071wml.4 for ; Thu, 05 Mar 2020 05:46:16 -0800 (PST) X-Gm-Message-State: KsJK6RPhsrOFMLt1b2oChBK4x1787277AA= X-Google-Smtp-Source: ADFU+vt14ECUjYkLg//TPwAnEO3NX5zmGG9v/m2dRE4SJYee6ORuxPbXzci+kD+dXdgrATSg3juPdA== X-Received: by 2002:a05:600c:2255:: with SMTP id a21mr5550937wmm.91.1583415975102; Thu, 05 Mar 2020 05:46:15 -0800 (PST) X-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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:14 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 04/14] OvmfPkg: provide a generic implementation of QemuLoadImageLib Date: Thu, 5 Mar 2020 14:45:57 +0100 Message-Id: <20200305134607.20125-5-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415977; bh=o3ADkjP/AWFyS5ZZATmBP8TflWrWMr32DMIuagick+k=; h=Cc:Date:From:Reply-To:Subject:To; b=mSR/C5c+EscOuX6VSzRebcAZ1de4hVrcMnXenKqjk2ko/L1eO4sSkTE8pZEbfxdZdW1 VJ50IXy52QoIs/1VDFOIe3rrYLIcEMPfPyXtD/HcmmSCLYslq9dZkyNiRK8RRMztn2xRp c8N6eEKPd1C+6YFw3kZ6sLaff493510YCWI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement QemuLoadImageLib, and make it load the image provided by the QEMU_EFI_LOADER_FS_MEDIA_GUID/kernel device path that we implemented in a preceding patch in a separate DXE driver, using only the standard LoadImage and StartImage boot services. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c | 276 = ++++++++++++++++++++ OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf | 38 = +++ 2 files changed, 314 insertions(+) diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLi= b.c b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c new file mode 100644 index 000000000000..f7f9a205f99d --- /dev/null +++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.c @@ -0,0 +1,276 @@ +/** @file + Generic implementation of QemuLoadImageLib library class interface. + + Copyright (c) 2020, ARM Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma pack (1) +typedef struct { + EFI_DEVICE_PATH_PROTOCOL FilePathHeader; + CHAR16 FilePath[ARRAY_SIZE (L"kernel")]; +} KERNEL_FILE_DEVPATH; + +typedef struct { + VENDOR_DEVICE_PATH VenMediaNode; + KERNEL_FILE_DEVPATH FileNode; + EFI_DEVICE_PATH_PROTOCOL EndNode; +} KERNEL_VENMEDIA_FILE_DEVPATH; +#pragma pack () + +STATIC CONST KERNEL_VENMEDIA_FILE_DEVPATH mKernelDevicePath =3D { + { + { + 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"kernel", + }, { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL) } + } +}; + +/** + Download the kernel, the initial ramdisk, and the kernel command line fr= om + QEMU's fw_cfg. The kernel will be instructed via its command line to load + the initrd from the same Simple FileSystem where the kernel was loaded f= rom. + + @param[out] ImageHandle The image handle that was allocated for + loading the image + + @retval EFI_SUCCESS The image was loaded successfully. + @retval EFI_NOT_FOUND Kernel image was not found. + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + @retval EFI_PROTOCOL_ERROR Unterminated kernel command line. + @retval EFI_ACCESS_DENIED The underlying LoadImage boot service call + returned EFI_SECURITY_VIOLATION, and the i= mage + was unloaded again. + + @return Error codes from any of the underlying + functions. +**/ +EFI_STATUS +EFIAPI +QemuLoadKernelImage ( + OUT EFI_HANDLE *ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HANDLE KernelImageHandle; + EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage; + UINTN CommandLineSize; + CHAR8 *CommandLine; + UINTN InitrdSize; + + // + // Load the image. This should call back into the QEMU EFI loader file s= ystem. + // + Status =3D gBS->LoadImage ( + FALSE, // BootPolicy: exact match req= uired + gImageHandle, // ParentImageHandle + (EFI_DEVICE_PATH_PROTOCOL *)&mKernelDevicePath, + NULL, // SourceBuffer + 0, // SourceSize + &KernelImageHandle + ); + switch (Status) { + case EFI_SUCCESS: + break; + + case EFI_SECURITY_VIOLATION: + // + // In this case, the image was loaded but failed to authenticate. + // + Status =3D EFI_ACCESS_DENIED; + goto UnloadImage; + + default: + DEBUG ((DEBUG_ERROR, "%a: LoadImage(): %r\n", __FUNCTION__, Status)); + return Status; + } + + // + // Construct the kernel command line. + // + Status =3D gBS->OpenProtocol ( + KernelImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **)&KernelLoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + ASSERT_EFI_ERROR (Status); + + QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize); + CommandLineSize =3D (UINTN)QemuFwCfgRead32 (); + + if (CommandLineSize =3D=3D 0) { + KernelLoadedImage->LoadOptionsSize =3D 0; + } else { + CommandLine =3D AllocatePool (CommandLineSize); + if (CommandLine =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto UnloadImage; + } + + QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); + QemuFwCfgReadBytes (CommandLineSize, CommandLine); + + // + // Verify NUL-termination of the command line. + // + if (CommandLine[CommandLineSize - 1] !=3D '\0') { + DEBUG ((DEBUG_ERROR, "%a: kernel command line is not NUL-terminated\= n", + __FUNCTION__)); + Status =3D EFI_PROTOCOL_ERROR; + goto FreeCommandLine; + } + + // + // Drop the terminating NUL, convert to UTF-16. + // + KernelLoadedImage->LoadOptionsSize =3D (CommandLineSize - 1) * 2; + } + + QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); + InitrdSize =3D (UINTN)QemuFwCfgRead32 (); + + if (InitrdSize > 0) { + // + // Append ' initrd=3Dinitrd' in UTF-16. + // + KernelLoadedImage->LoadOptionsSize +=3D sizeof (L" initrd=3Dinitrd") -= 2; + } + + if (KernelLoadedImage->LoadOptionsSize =3D=3D 0) { + KernelLoadedImage->LoadOptions =3D NULL; + } else { + // + // NUL-terminate in UTF-16. + // + KernelLoadedImage->LoadOptionsSize +=3D 2; + + KernelLoadedImage->LoadOptions =3D AllocatePool ( + KernelLoadedImage->LoadOptionsSize); + if (KernelLoadedImage->LoadOptions =3D=3D NULL) { + KernelLoadedImage->LoadOptionsSize =3D 0; + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeCommandLine; + } + + UnicodeSPrintAsciiFormat ( + KernelLoadedImage->LoadOptions, + KernelLoadedImage->LoadOptionsSize, + "%a%a", + (CommandLineSize =3D=3D 0) ? "" : CommandLine, + (InitrdSize =3D=3D 0) ? "" : " initrd=3Dinitrd" + ); + DEBUG ((DEBUG_INFO, "%a: command line: \"%s\"\n", __FUNCTION__, + (CHAR16 *)KernelLoadedImage->LoadOptions)); + } + + *ImageHandle =3D KernelImageHandle; + return EFI_SUCCESS; + +FreeCommandLine: + if (CommandLineSize > 0) { + FreePool (CommandLine); + } +UnloadImage: + gBS->UnloadImage (KernelImageHandle); + + return Status; +} + +/** + Transfer control to a kernel image loaded with QemuLoadKernelImage () + + @param[in,out] ImageHandle Handle of image to be started. May assum= e a + different value on return if the image w= as + reloaded. + + @retval EFI_INVALID_PARAMETER ImageHandle is either an invalid image h= andle + or the image has already been initialize= d with + StartImage + @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the + image should not be started. + + @return Error codes returned by the started image +**/ +EFI_STATUS +EFIAPI +QemuStartKernelImage ( + IN OUT EFI_HANDLE *ImageHandle + ) +{ + return gBS->StartImage ( + *ImageHandle, + NULL, // ExitDataSize + NULL // ExitData + ); +} + +/** + Unloads an image loaded with QemuLoadKernelImage (). + + @param ImageHandle Handle that identifies the image to be + unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_UNSUPPORTED The image has been started, and does not + support unload. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + + @return Exit code from the image's unload functi= on. +**/ +EFI_STATUS +EFIAPI +QemuUnloadKernelImage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage; + EFI_STATUS Status; + + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **)&KernelLoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + if (KernelLoadedImage->LoadOptions !=3D NULL) { + FreePool (KernelLoadedImage->LoadOptions); + KernelLoadedImage->LoadOptions =3D NULL; + } + KernelLoadedImage->LoadOptionsSize =3D 0; + + return gBS->UnloadImage (ImageHandle); +} diff --git a/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLi= b.inf b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf new file mode 100644 index 000000000000..b262cb926a4d --- /dev/null +++ b/OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoadImageLib.inf @@ -0,0 +1,38 @@ +## @file +# Generic implementation of QemuLoadImageLib library class interface. +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D GenericQemuLoadImageLib + FILE_GUID =3D 9e3e28da-c7b5-4f85-841a-84e6a9a1f1a0 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D QemuLoadImageLib|DXE_DRIVER + +[Sources] + GenericQemuLoadImageLib.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + PrintLib + QemuFwCfgLib + UefiBootServicesTableLib + +[Protocols] + gEfiDevicePathProtocolGuid + gEfiLoadedImageProtocolGuid + +[Guids] + gQemuKernelLoaderFsMediaGuid --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55527): https://edk2.groups.io/g/devel/message/55527 Mute This Topic: https://groups.io/mt/71749517/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55528+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55528+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415978; cv=none; d=zohomail.com; s=zohoarc; b=I2MZksJxXHxrpEMFrLrgj5sBOrIQCLTavlh6Am4D3dawuDlutepAU3+IZBy70hFWeWnB23y8WhhUFXcFW424/mXNxv98rnzHuNYLmd4+hSg5a4Bni546hgDHKZLGSp9owCmNmNbsfYPfRyEpz/DbiFL3aVqSZvGDQ9MeATMOoa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415978; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=kP5sT9FRcWsBA2jUuHTkSNYLecf+uF3UJ68Y6yCahnE=; b=QGZ0ltijoqRU6WFvjj0GrVbCAIYoV1x48XkQ+rQ+I0KM8ooFsDwbcjLgTb4wzzLcV/muwXnPfSEr5CjusHkkHxPdjeXyqRUywv+dlVNcyvIHwEott3aDt3WGO08XbcpwcqaZDcczVViR9SI4A+nLUTRC1mRamDeCeLj23GppsyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55528+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415978794422.30500002597773; Thu, 5 Mar 2020 05:46:18 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Mo34YY1788612x6luiGV0DJm; Thu, 05 Mar 2020 05:46:18 -0800 X-Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by mx.groups.io with SMTP id smtpd.web09.12510.1583415977767016011 for ; Thu, 05 Mar 2020 05:46:18 -0800 X-Received: by mail-wm1-f46.google.com with SMTP id a25so7131166wmm.0 for ; Thu, 05 Mar 2020 05:46:17 -0800 (PST) X-Gm-Message-State: KVmN36ZcsCZ9TDbnYbDQFUhBx1787277AA= X-Google-Smtp-Source: ADFU+vuCs48K3xAXxRFV6x/0fgE6grktG3N6dV+4AsDaiuO+8Q87Eo9Bl0RXMg1XCnlw8D1DlCzpFg== X-Received: by 2002:a1c:4c13:: with SMTP id z19mr9531278wmf.75.1583415976116; Thu, 05 Mar 2020 05:46:16 -0800 (PST) X-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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:15 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 05/14] ArmVirtPkg: incorporate the new QEMU kernel loader driver and library Date: Thu, 5 Mar 2020 14:45:58 +0100 Message-Id: <20200305134607.20125-6-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415978; bh=6D1Iu6tJ7Q7yoKp1DiRV+gN2D948JZnTHTuEg/u8+JA=; h=Cc:Date:From:Reply-To:Subject:To; b=fN+27Y83uBsRuTxCdDrSpI8L1cps7nIZ1ex/nhS6MhIaD/M7Ako9eGZvXXeZ7E03Bna 3aUfYQ0eFSyW4JZjDmsNkMYgEs01hpKYkxSeyF2WYCSupps55IZyFVoRcevLVI/clI5mL wj2LZkx9X6ei+yF4Ju7QejJmefZr5vza/bc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the QEMU loader DXE driver and client library to the build for our QEMU targeted implementations in ArmVirtPkg. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- ArmVirtPkg/ArmVirtQemu.dsc | 2 ++ ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 + ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 ++ 3 files changed, 5 insertions(+) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 5e5f71e7fe8a..8c77fc46427b 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -58,6 +58,7 @@ [LibraryClasses.common] VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf =20 ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibN= ull.inf =20 @@ -427,6 +428,7 @@ [Components.common] NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf } + OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf =20 # # Networking stack diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index 2a17583593ef..aaba0b1c8840 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -114,6 +114,7 @@ [FV.FvMain] INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe= .inf INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf INF MdeModulePkg/Application/UiApp/UiApp.inf + INF OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf =20 # # Networking stack diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index 37e19dfbd0db..4d82a77213ec 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -56,6 +56,7 @@ [LibraryClasses.common] VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf =20 ArmVirtMemInfoLib|ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoL= ib.inf =20 @@ -362,6 +363,7 @@ [Components.common] NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf } + OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf =20 # # Networking stack --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55528): https://edk2.groups.io/g/devel/message/55528 Mute This Topic: https://groups.io/mt/71749518/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55529+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55529+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415981; cv=none; d=zohomail.com; s=zohoarc; b=nyLWA6bfoDyw+ITN6u9IheM21JgTd9z6gNre3N9gtS4UkjR1jTq+sOKLC//9LjyOxgBSVxoxmjYu71RMMyo54DGZHnmHV79b0TcWLm/W4nrzXKeyBhVPaejS5EFGcJcGVPI6Ukntj3Z0BGkotGV5g29kMDttZbnwYBOLz7No0t4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415981; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=eWbW+CMIeLSlVIdRP0x7hOXDvRwsa5wUOUwhxUoCiYk=; b=KskttpapaPskU4TwOF153fMbBbQun0JI2z3EwdYqlxgf+x7ctuemKdEqDlFiPGEnDkSjo59fc9KmKhP0WLB4bI+hlrIIw3wzVkQlRZlkVsUV7I1w1oFPwXvI99LsIXTqx5hENOb/doxDyiePBu2PaTzbbPYzMRhs7048XXAfrsA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55529+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415981888296.86070701475705; Thu, 5 Mar 2020 05:46:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id dZxwYY1788612xV09BQBi0wZ; Thu, 05 Mar 2020 05:46:21 -0800 X-Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by mx.groups.io with SMTP id smtpd.web12.12581.1583415980236707234 for ; Thu, 05 Mar 2020 05:46:20 -0800 X-Received: by mail-wr1-f43.google.com with SMTP id z15so7123937wrl.1 for ; Thu, 05 Mar 2020 05:46:20 -0800 (PST) X-Gm-Message-State: A8JzUsWNO2YZCQpErGlkJ6chx1787277AA= X-Google-Smtp-Source: ADFU+vuRFodHwlieHz28byTureOy39y0wuH+0IxKqx8X1NFeQAKac+N2sMUamjZtGo2XO4pWcV9FXw== X-Received: by 2002:adf:eccd:: with SMTP id s13mr9932329wro.278.1583415977467; Thu, 05 Mar 2020 05:46:17 -0800 (PST) X-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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:16 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 06/14] ArmVirtPkg/PlatformBootManagerLib: switch to separate QEMU loader Date: Thu, 5 Mar 2020 14:45:59 +0100 Message-Id: <20200305134607.20125-7-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415981; bh=S3tvJHY49LzSL8SuXde7+ymGL52ty9IBMjv7YNYB6a4=; h=Cc:Date:From:Reply-To:Subject:To; b=u63ZQbS2axMENBQVq5bH2bk1PFcazz8ApFjf0W0AwqdFvKCn1B/e8+C/ChoKEqwBonG qa5AdZDRZ/XuwMTNpVBXzbbM394t6VIqEf3M9+RyyDjpA6hqS8OdxNZuNjZdTqhvg3wtI CCLwn1mVKYBPI/QBQL/VByzP3u7o5drdHoY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Drop the QEMU loader file system implementation inside this library, and switch to the separate QemuLoadImageLib library and the associated driver to expose the kernel and initrd passed via the QEMU command line. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | = 9 +- ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c | 106= 1 +------------------- 2 files changed, 7 insertions(+), 1063 deletions(-) diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerL= ib.inf b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.i= nf index 6fe0a1bb122b..11f52e019bc3 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -44,9 +44,8 @@ [LibraryClasses] MemoryAllocationLib PcdLib PlatformBmPrintScLib - PrintLib QemuBootOrderLib - QemuFwCfgLib + QemuLoadImageLib ReportStatusCodeLib UefiBootManagerLib UefiBootServicesTableLib @@ -64,19 +63,13 @@ [Pcd] gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut =20 [Guids] - gEfiFileInfoGuid - gEfiFileSystemInfoGuid - gEfiFileSystemVolumeLabelInfoIdGuid gEfiEndOfDxeEventGroupGuid gEfiGlobalVariableGuid gRootBridgesConnectedEventGroupGuid gUefiShellFileGuid =20 [Protocols] - gEfiDevicePathProtocolGuid gEfiFirmwareVolume2ProtocolGuid gEfiGraphicsOutputProtocolGuid - gEfiLoadedImageProtocolGuid gEfiPciRootBridgeIoProtocolGuid - gEfiSimpleFileSystemProtocolGuid gVirtioDeviceProtocolGuid diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c b/ArmVi= rtPkg/Library/PlatformBootManagerLib/QemuKernel.c index d3851fd75fa5..e9c110a0ed75 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c +++ b/ArmVirtPkg/Library/PlatformBootManagerLib/QemuKernel.c @@ -9,887 +9,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 -#include -#include -#include -#include -#include +#include #include -#include -#include -#include =20 #include "PlatformBm.h" =20 -// -// Static data that hosts the fw_cfg blobs and serves file requests. -// -typedef enum { - KernelBlobTypeKernel, - KernelBlobTypeInitrd, - KernelBlobTypeCommandLine, - KernelBlobTypeMax -} KERNEL_BLOB_TYPE; - -typedef struct { - FIRMWARE_CONFIG_ITEM CONST SizeKey; - FIRMWARE_CONFIG_ITEM CONST DataKey; - CONST CHAR16 * CONST Name; - UINT32 Size; - UINT8 *Data; -} KERNEL_BLOB; - -STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] =3D { - { QemuFwCfgItemKernelSize, QemuFwCfgItemKernelData, L"kernel" = }, - { QemuFwCfgItemInitrdSize, QemuFwCfgItemInitrdData, L"initrd" = }, - { QemuFwCfgItemCommandLineSize, QemuFwCfgItemCommandLineData, L"cmdline"= } -}; - -STATIC UINT64 mTotalBlobBytes; - -// -// Device path for the handle that incorporates our "EFI stub filesystem".= The -// GUID is arbitrary and need not be standardized or advertized. -// -#pragma pack(1) -typedef struct { - VENDOR_DEVICE_PATH VenHwNode; - EFI_DEVICE_PATH_PROTOCOL EndNode; -} SINGLE_VENHW_NODE_DEVPATH; -#pragma pack() - -STATIC CONST SINGLE_VENHW_NODE_DEVPATH mFileSystemDevicePath =3D { - { - { HARDWARE_DEVICE_PATH, HW_VENDOR_DP, { sizeof (VENDOR_DEVICE_PATH) } = }, - { - 0xb0fae7e7, 0x6b07, 0x49d0, - { 0x9e, 0x5b, 0x3b, 0xde, 0xc8, 0x3b, 0x03, 0x9d } - } - }, - - { - END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, - { sizeof (EFI_DEVICE_PATH_PROTOCOL) } - } -}; - -// -// The "file in the EFI stub filesystem" abstraction. -// -STATIC EFI_TIME mInitTime; - -#define STUB_FILE_SIG SIGNATURE_64 ('S', 'T', 'U', 'B', 'F', 'I', 'L', 'E') - -typedef struct { - UINT64 Signature; // Carries STUB_FILE_SIG. - - KERNEL_BLOB_TYPE BlobType; // Index into mKernelBlob. KernelBlobTypeMax - // denotes the root directory of the filesy= stem. - - UINT64 Position; // Byte position for regular files; - // next directory entry to return for the r= oot - // directory. - - EFI_FILE_PROTOCOL File; // Standard protocol interface. -} STUB_FILE; - -#define STUB_FILE_FROM_FILE(FilePointer) \ - CR (FilePointer, STUB_FILE, File, STUB_FILE_SIG) - -// -// Tentative definition of the file protocol template. The initializer -// (external definition) will be provided later. -// -STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate; - - -// -// Protocol member functions for File. -// - -/** - Opens a new file relative to the source file's location. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that= is - the file handle to the source location. This wou= ld - typically be an open handle to a directory. - - @param[out] NewHandle A pointer to the location to return the opened h= andle - for the new file. - - @param[in] FileName The Null-terminated string of the name of the fi= le to - be opened. The file name may contain the followi= ng - path modifiers: "\", ".", and "..". - - @param[in] OpenMode The mode to open the file. The only valid - combinations that the file may be opened with ar= e: - Read, Read/Write, or Create/Read/Write. - - @param[in] Attributes Only valid for EFI_FILE_MODE_CREATE, in which ca= se - these are the attribute bits for the newly creat= ed - file. - - @retval EFI_SUCCESS The file was opened. - @retval EFI_NOT_FOUND The specified file could not be found on t= he - device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it or= the - medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or o= pen a - file for write when the media is - write-protected. - @retval EFI_ACCESS_DENIED The service denied access to the file. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to ope= n the - file. - @retval EFI_VOLUME_FULL The volume is full. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileOpen ( - IN EFI_FILE_PROTOCOL *This, - OUT EFI_FILE_PROTOCOL **NewHandle, - IN CHAR16 *FileName, - IN UINT64 OpenMode, - IN UINT64 Attributes - ) -{ - CONST STUB_FILE *StubFile; - UINTN BlobType; - STUB_FILE *NewStubFile; - - // - // We're read-only. - // - switch (OpenMode) { - case EFI_FILE_MODE_READ: - break; - - case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE: - case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE: - return EFI_WRITE_PROTECTED; - - default: - return EFI_INVALID_PARAMETER; - } - - // - // Only the root directory supports opening files in it. - // - StubFile =3D STUB_FILE_FROM_FILE (This); - if (StubFile->BlobType !=3D KernelBlobTypeMax) { - return EFI_UNSUPPORTED; - } - - // - // Locate the file. - // - for (BlobType =3D 0; BlobType < KernelBlobTypeMax; ++BlobType) { - if (StrCmp (FileName, mKernelBlob[BlobType].Name) =3D=3D 0) { - break; - } - } - if (BlobType =3D=3D KernelBlobTypeMax) { - return EFI_NOT_FOUND; - } - - // - // Found it. - // - NewStubFile =3D AllocatePool (sizeof *NewStubFile); - if (NewStubFile =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - NewStubFile->Signature =3D STUB_FILE_SIG; - NewStubFile->BlobType =3D (KERNEL_BLOB_TYPE)BlobType; - NewStubFile->Position =3D 0; - CopyMem (&NewStubFile->File, &mEfiFileProtocolTemplate, - sizeof mEfiFileProtocolTemplate); - *NewHandle =3D &NewStubFile->File; - - return EFI_SUCCESS; -} - - -/** - Closes a specified file handle. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the= file - handle to close. - - @retval EFI_SUCCESS The file was closed. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileClose ( - IN EFI_FILE_PROTOCOL *This - ) -{ - FreePool (STUB_FILE_FROM_FILE (This)); - return EFI_SUCCESS; -} - - -/** - Close and delete the file handle. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the - handle to the file to delete. - - @retval EFI_SUCCESS The file was closed and deleted, and the - handle was closed. - @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was= not - deleted. - -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileDelete ( - IN EFI_FILE_PROTOCOL *This - ) -{ - FreePool (STUB_FILE_FROM_FILE (This)); - return EFI_WARN_DELETE_FAILURE; -} - - -/** - Helper function that formats an EFI_FILE_INFO structure into the - user-allocated buffer, for any valid KERNEL_BLOB_TYPE value (including - KernelBlobTypeMax, which stands for the root directory). - - The interface follows the EFI_FILE_GET_INFO -- and for directories, the - EFI_FILE_READ -- interfaces. - - @param[in] BlobType The KERNEL_BLOB_TYPE value identifying the f= w_cfg - blob backing the STUB_FILE that information = is - being requested about. If BlobType equals - KernelBlobTypeMax, then information will be - provided about the root directory of the - filesystem. - - @param[in,out] BufferSize On input, the size of Buffer. On output, the - amount of data returned in Buffer. In both ca= ses, - the size is measured in bytes. - - @param[out] Buffer A pointer to the data buffer to return. The - buffer's type is EFI_FILE_INFO. - - @retval EFI_SUCCESS The information was returned. - @retval EFI_BUFFER_TOO_SMALL BufferSize is too small to store the - EFI_FILE_INFO structure. BufferSize has be= en - updated with the size needed to complete t= he - request. -**/ -STATIC -EFI_STATUS -ConvertKernelBlobTypeToFileInfo ( - IN KERNEL_BLOB_TYPE BlobType, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - CONST CHAR16 *Name; - UINT64 FileSize; - UINT64 Attribute; - - UINTN NameSize; - UINTN FileInfoSize; - EFI_FILE_INFO *FileInfo; - UINTN OriginalBufferSize; - - if (BlobType =3D=3D KernelBlobTypeMax) { - // - // getting file info about the root directory - // - Name =3D L"\\"; - FileSize =3D KernelBlobTypeMax; - Attribute =3D EFI_FILE_READ_ONLY | EFI_FILE_DIRECTORY; - } else { - CONST KERNEL_BLOB *Blob; - - Blob =3D &mKernelBlob[BlobType]; - Name =3D Blob->Name; - FileSize =3D Blob->Size; - Attribute =3D EFI_FILE_READ_ONLY; - } - - NameSize =3D (StrLen(Name) + 1) * 2; - FileInfoSize =3D OFFSET_OF (EFI_FILE_INFO, FileName) + NameSize; - ASSERT (FileInfoSize >=3D sizeof *FileInfo); - - OriginalBufferSize =3D *BufferSize; - *BufferSize =3D FileInfoSize; - if (OriginalBufferSize < *BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - FileInfo =3D (EFI_FILE_INFO *)Buffer; - FileInfo->Size =3D FileInfoSize; - FileInfo->FileSize =3D FileSize; - FileInfo->PhysicalSize =3D FileSize; - FileInfo->Attribute =3D Attribute; - - CopyMem (&FileInfo->CreateTime, &mInitTime, sizeof mInitTime); - CopyMem (&FileInfo->LastAccessTime, &mInitTime, sizeof mInitTime); - CopyMem (&FileInfo->ModificationTime, &mInitTime, sizeof mInitTime); - CopyMem (FileInfo->FileName, Name, NameSize); - - return EFI_SUCCESS; -} - - -/** - Reads data from a file, or continues scanning a directory. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance t= hat - is the file handle to read data from. - - @param[in,out] BufferSize On input, the size of the Buffer. On output, = the - amount of data returned in Buffer. In both ca= ses, - the size is measured in bytes. If the read go= es - beyond the end of the file, the read length is - truncated to the end of the file. - - If This is a directory, the function reads the - directory entry at the current position and - returns the entry (as EFI_FILE_INFO) in Buffe= r. If - there are no more directory entries, the - BufferSize is set to zero on output. - - @param[out] Buffer The buffer into which the data is read. - - @retval EFI_SUCCESS Data was read. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted - file. - @retval EFI_DEVICE_ERROR On entry, the current file position is bey= ond - the end of the file. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to store the - current directory entry as a EFI_FILE_INFO - structure. BufferSize has been updated wit= h the - size needed to complete the request, and t= he - directory position has not been advanced. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileRead ( - IN EFI_FILE_PROTOCOL *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - STUB_FILE *StubFile; - CONST KERNEL_BLOB *Blob; - UINT64 Left; - - StubFile =3D STUB_FILE_FROM_FILE (This); - - // - // Scanning the root directory? - // - if (StubFile->BlobType =3D=3D KernelBlobTypeMax) { - EFI_STATUS Status; - - if (StubFile->Position =3D=3D KernelBlobTypeMax) { - // - // Scanning complete. - // - *BufferSize =3D 0; - return EFI_SUCCESS; - } - - Status =3D ConvertKernelBlobTypeToFileInfo ( - (KERNEL_BLOB_TYPE)StubFile->Position, - BufferSize, - Buffer); - if (EFI_ERROR (Status)) { - return Status; - } - - ++StubFile->Position; - return EFI_SUCCESS; - } - - // - // Reading a file. - // - Blob =3D &mKernelBlob[StubFile->BlobType]; - if (StubFile->Position > Blob->Size) { - return EFI_DEVICE_ERROR; - } - - Left =3D Blob->Size - StubFile->Position; - if (*BufferSize > Left) { - *BufferSize =3D (UINTN)Left; - } - if (Blob->Data !=3D NULL) { - CopyMem (Buffer, Blob->Data + StubFile->Position, *BufferSize); - } - StubFile->Position +=3D *BufferSize; - return EFI_SUCCESS; -} - - -/** - Writes data to a file. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance t= hat - is the file handle to write data to. - - @param[in,out] BufferSize On input, the size of the Buffer. On output, = the - amount of data actually written. In both case= s, - the size is measured in bytes. - - @param[in] Buffer The buffer of data to write. - - @retval EFI_SUCCESS Data was written. - @retval EFI_UNSUPPORTED Writes to open directory files are not - supported. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted = file. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write-protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_VOLUME_FULL The volume is full. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileWrite ( - IN EFI_FILE_PROTOCOL *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer - ) -{ - STUB_FILE *StubFile; - - StubFile =3D STUB_FILE_FROM_FILE (This); - return (StubFile->BlobType =3D=3D KernelBlobTypeMax) ? - EFI_UNSUPPORTED : - EFI_WRITE_PROTECTED; -} - - -/** - Returns a file's current position. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that i= s the - file handle to get the current position on. - - @param[out] Position The address to return the file's current position - value. - - @retval EFI_SUCCESS The position was returned. - @retval EFI_UNSUPPORTED The request is not valid on open directories. - @retval EFI_DEVICE_ERROR An attempt was made to get the position from a - deleted file. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileGetPosition ( - IN EFI_FILE_PROTOCOL *This, - OUT UINT64 *Position - ) -{ - STUB_FILE *StubFile; - - StubFile =3D STUB_FILE_FROM_FILE (This); - if (StubFile->BlobType =3D=3D KernelBlobTypeMax) { - return EFI_UNSUPPORTED; - } - - *Position =3D StubFile->Position; - return EFI_SUCCESS; -} - - -/** - Sets a file's current position. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is= the - file handle to set the requested position on. - - @param[in] Position The byte position from the start of the file to set= . For - regular files, MAX_UINT64 means "seek to end". For - directories, zero means "rewind directory scan". - - @retval EFI_SUCCESS The position was set. - @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on o= pen - directories. - @retval EFI_DEVICE_ERROR An attempt was made to set the position of a - deleted file. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileSetPosition ( - IN EFI_FILE_PROTOCOL *This, - IN UINT64 Position - ) -{ - STUB_FILE *StubFile; - KERNEL_BLOB *Blob; - - StubFile =3D STUB_FILE_FROM_FILE (This); - - if (StubFile->BlobType =3D=3D KernelBlobTypeMax) { - if (Position =3D=3D 0) { - // - // rewinding a directory scan is allowed - // - StubFile->Position =3D 0; - return EFI_SUCCESS; - } - return EFI_UNSUPPORTED; - } - - // - // regular file seek - // - Blob =3D &mKernelBlob[StubFile->BlobType]; - if (Position =3D=3D MAX_UINT64) { - // - // seek to end - // - StubFile->Position =3D Blob->Size; - } else { - // - // absolute seek from beginning -- seeking past the end is allowed - // - StubFile->Position =3D Position; - } - return EFI_SUCCESS; -} - - -/** - Returns information about a file. - - @param[in] This A pointer to the EFI_FILE_PROTOCOL insta= nce - that is the file handle the requested - information is for. - - @param[in] InformationType The type identifier GUID for the informa= tion - being requested. The following informati= on - types are supported, storing the - corresponding structures in Buffer: - - - gEfiFileInfoGuid: EFI_FILE_INFO - - - gEfiFileSystemInfoGuid: - EFI_FILE_SYSTEM_INFO - - - gEfiFileSystemVolumeLabelInfoIdGuid: - EFI_FILE_SYSTEM_VOLUME_LABEL - - @param[in,out] BufferSize On input, the size of Buffer. On output,= the - amount of data returned in Buffer. In bo= th - cases, the size is measured in bytes. - - @param[out] Buffer A pointer to the data buffer to return. = The - buffer's type is indicated by - InformationType. - - @retval EFI_SUCCESS The information was returned. - @retval EFI_UNSUPPORTED The InformationType is not known. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to store the - information structure requested by - InformationType. BufferSize has been updat= ed - with the size needed to complete the reque= st. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileGetInfo ( - IN EFI_FILE_PROTOCOL *This, - IN EFI_GUID *InformationType, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer - ) -{ - CONST STUB_FILE *StubFile; - UINTN OriginalBufferSize; - - StubFile =3D STUB_FILE_FROM_FILE (This); - - if (CompareGuid (InformationType, &gEfiFileInfoGuid)) { - return ConvertKernelBlobTypeToFileInfo (StubFile->BlobType, BufferSize, - Buffer); - } - - OriginalBufferSize =3D *BufferSize; - - if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { - EFI_FILE_SYSTEM_INFO *FileSystemInfo; - - *BufferSize =3D sizeof *FileSystemInfo; - if (OriginalBufferSize < *BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - FileSystemInfo =3D (EFI_FILE_SYSTEM_INFO *)Buffer; - FileSystemInfo->Size =3D sizeof *FileSystemInfo; - FileSystemInfo->ReadOnly =3D TRUE; - FileSystemInfo->VolumeSize =3D mTotalBlobBytes; - FileSystemInfo->FreeSpace =3D 0; - FileSystemInfo->BlockSize =3D 1; - FileSystemInfo->VolumeLabel[0] =3D L'\0'; - - return EFI_SUCCESS; - } - - if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid))= { - EFI_FILE_SYSTEM_VOLUME_LABEL *FileSystemVolumeLabel; - - *BufferSize =3D sizeof *FileSystemVolumeLabel; - if (OriginalBufferSize < *BufferSize) { - return EFI_BUFFER_TOO_SMALL; - } - - FileSystemVolumeLabel =3D (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer; - FileSystemVolumeLabel->VolumeLabel[0] =3D L'\0'; - - return EFI_SUCCESS; - } - - return EFI_UNSUPPORTED; -} - - -/** - Sets information about a file. - - @param[in] File A pointer to the EFI_FILE_PROTOCOL instance = that - is the file handle the information is for. - - @param[in] InformationType The type identifier for the information being - set. - - @param[in] BufferSize The size, in bytes, of Buffer. - - @param[in] Buffer A pointer to the data buffer to write. The - buffer's type is indicated by InformationTyp= e. - - @retval EFI_SUCCESS The information was set. - @retval EFI_UNSUPPORTED The InformationType is not known. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the - media is read-only. - @retval EFI_WRITE_PROTECTED InformationType is - EFI_FILE_PROTOCOL_SYSTEM_INFO_ID and the m= edia - is read only. - @retval EFI_WRITE_PROTECTED InformationType is - EFI_FILE_SYSTEM_VOLUME_LABEL_ID and the me= dia - is read-only. - @retval EFI_ACCESS_DENIED An attempt is made to change the name of a= file - to a file that is already present. - @retval EFI_ACCESS_DENIED An attempt is being made to change the - EFI_FILE_DIRECTORY Attribute. - @retval EFI_ACCESS_DENIED An attempt is being made to change the siz= e of - a directory. - @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the - file was opened read-only and an attempt is - being made to modify a field other than - Attribute. - @retval EFI_VOLUME_FULL The volume is full. - @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the= type - indicated by InformationType. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileSetInfo ( - IN EFI_FILE_PROTOCOL *This, - IN EFI_GUID *InformationType, - IN UINTN BufferSize, - IN VOID *Buffer - ) -{ - return EFI_WRITE_PROTECTED; -} - - -/** - Flushes all modified data associated with a file to a device. - - @param [in] This A pointer to the EFI_FILE_PROTOCOL instance that is the - file handle to flush. - - @retval EFI_SUCCESS The data was flushed. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write-protected. - @retval EFI_ACCESS_DENIED The file was opened read-only. - @retval EFI_VOLUME_FULL The volume is full. -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileFlush ( - IN EFI_FILE_PROTOCOL *This - ) -{ - return EFI_WRITE_PROTECTED; -} - -// -// External definition of the file protocol template. -// -STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate =3D { - EFI_FILE_PROTOCOL_REVISION, // revision 1 - StubFileOpen, - StubFileClose, - StubFileDelete, - StubFileRead, - StubFileWrite, - StubFileGetPosition, - StubFileSetPosition, - StubFileGetInfo, - StubFileSetInfo, - StubFileFlush, - NULL, // OpenEx, revision 2 - NULL, // ReadEx, revision 2 - NULL, // WriteEx, revision 2 - NULL // FlushEx, revision 2 -}; - - -// -// Protocol member functions for SimpleFileSystem. -// - -/** - Open the root directory on a volume. - - @param[in] This A pointer to the volume to open the root directory on. - - @param[out] Root A pointer to the location to return the opened file ha= ndle - for the root directory in. - - @retval EFI_SUCCESS The device was opened. - @retval EFI_UNSUPPORTED This volume does not support the requested= file - system type. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_ACCESS_DENIED The service denied access to the file. - @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of - resources. - @retval EFI_MEDIA_CHANGED The device has a different medium in it or= the - medium is no longer supported. Any existing - file handles for this volume are no longer - valid. To access the files on the new medi= um, - the volume must be reopened with OpenVolum= e(). -**/ -STATIC -EFI_STATUS -EFIAPI -StubFileSystemOpenVolume ( - IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, - OUT EFI_FILE_PROTOCOL **Root - ) -{ - STUB_FILE *StubFile; - - StubFile =3D AllocatePool (sizeof *StubFile); - if (StubFile =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - StubFile->Signature =3D STUB_FILE_SIG; - StubFile->BlobType =3D KernelBlobTypeMax; - StubFile->Position =3D 0; - CopyMem (&StubFile->File, &mEfiFileProtocolTemplate, - sizeof mEfiFileProtocolTemplate); - *Root =3D &StubFile->File; - - return EFI_SUCCESS; -} - -STATIC CONST EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mFileSystem =3D { - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION, - StubFileSystemOpenVolume -}; - - -// -// Utility functions. -// - -/** - Populate a blob in mKernelBlob. - - param[in,out] Blob Pointer to the KERNEL_BLOB element in mKernelBlob th= at is - to be filled from fw_cfg. - - @retval EFI_SUCCESS Blob has been populated. If fw_cfg reporte= d a - size of zero for the blob, then Blob->Data= has - been left unchanged. - - @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for Blob->Data. -**/ -STATIC -EFI_STATUS -FetchBlob ( - IN OUT KERNEL_BLOB *Blob - ) -{ - UINT32 Left; - - // - // Read blob size. - // - QemuFwCfgSelectItem (Blob->SizeKey); - Blob->Size =3D QemuFwCfgRead32 (); - if (Blob->Size =3D=3D 0) { - return EFI_SUCCESS; - } - - // - // Read blob. - // - Blob->Data =3D AllocatePool (Blob->Size); - if (Blob->Data =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "%a: failed to allocate %Ld bytes for \"%s\"\n", - __FUNCTION__, (INT64)Blob->Size, Blob->Name)); - return EFI_OUT_OF_RESOURCES; - } - - DEBUG ((EFI_D_INFO, "%a: loading %Ld bytes for \"%s\"\n", __FUNCTION__, - (INT64)Blob->Size, Blob->Name)); - QemuFwCfgSelectItem (Blob->DataKey); - - Left =3D Blob->Size; - do { - UINT32 Chunk; - - Chunk =3D (Left < SIZE_1MB) ? Left : SIZE_1MB; - QemuFwCfgReadBytes (Chunk, Blob->Data + (Blob->Size - Left)); - Left -=3D Chunk; - DEBUG ((EFI_D_VERBOSE, "%a: %Ld bytes remaining for \"%s\"\n", - __FUNCTION__, (INT64)Left, Blob->Name)); - } while (Left > 0); - return EFI_SUCCESS; -} - - // // The entry point of the feature. // @@ -916,159 +40,14 @@ TryRunningQemuKernel ( VOID ) { - UINTN BlobType; - KERNEL_BLOB *CurrentBlob; - KERNEL_BLOB *KernelBlob, *InitrdBlob, *CommandLineBlob; EFI_STATUS Status; - EFI_HANDLE FileSystemHandle; - EFI_DEVICE_PATH_PROTOCOL *KernelDevicePath; EFI_HANDLE KernelImageHandle; - EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage; =20 - Status =3D gRT->GetTime (&mInitTime, NULL /* Capabilities */); + Status =3D QemuLoadKernelImage (&KernelImageHandle); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a: GetTime(): %r\n", __FUNCTION__, Status)); return Status; } =20 - // - // Fetch all blobs. - // - for (BlobType =3D 0; BlobType < KernelBlobTypeMax; ++BlobType) { - CurrentBlob =3D &mKernelBlob[BlobType]; - Status =3D FetchBlob (CurrentBlob); - if (EFI_ERROR (Status)) { - goto FreeBlobs; - } - mTotalBlobBytes +=3D CurrentBlob->Size; - } - KernelBlob =3D &mKernelBlob[KernelBlobTypeKernel]; - InitrdBlob =3D &mKernelBlob[KernelBlobTypeInitrd]; - CommandLineBlob =3D &mKernelBlob[KernelBlobTypeCommandLine]; - - if (KernelBlob->Data =3D=3D NULL) { - Status =3D EFI_NOT_FOUND; - goto FreeBlobs; - } - - // - // Create a new handle with a single VenHw() node device path protocol o= n it, - // plus a custom SimpleFileSystem protocol on it. - // - FileSystemHandle =3D NULL; - Status =3D gBS->InstallMultipleProtocolInterfaces (&FileSystemHandle, - &gEfiDevicePathProtocolGuid, &mFileSystemDevicePat= h, - &gEfiSimpleFileSystemProtocolGuid, &mFileSystem, - NULL); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a: InstallMultipleProtocolInterfaces(): %r\n", - __FUNCTION__, Status)); - goto FreeBlobs; - } - - // - // Create a device path for the kernel image to be loaded from that will= call - // back into our file system. - // - KernelDevicePath =3D FileDevicePath (FileSystemHandle, KernelBlob->Name); - if (KernelDevicePath =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "%a: failed to allocate kernel device path\n", - __FUNCTION__)); - Status =3D EFI_OUT_OF_RESOURCES; - goto UninstallProtocols; - } - - // - // Load the image. This should call back into our file system. - // - Status =3D gBS->LoadImage ( - FALSE, // BootPolicy: exact match required - gImageHandle, // ParentImageHandle - KernelDevicePath, - NULL, // SourceBuffer - 0, // SourceSize - &KernelImageHandle - ); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a: LoadImage(): %r\n", __FUNCTION__, Status)); - if (Status !=3D EFI_SECURITY_VIOLATION) { - goto FreeKernelDevicePath; - } - // - // From the resource allocation perspective, EFI_SECURITY_VIOLATION me= ans - // "success", so we must roll back the image loading. - // - goto UnloadKernelImage; - } - - // - // Construct the kernel command line. - // - Status =3D gBS->OpenProtocol ( - KernelImageHandle, - &gEfiLoadedImageProtocolGuid, - (VOID **)&KernelLoadedImage, - gImageHandle, // AgentHandle - NULL, // ControllerHandle - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - ASSERT_EFI_ERROR (Status); - - if (CommandLineBlob->Data =3D=3D NULL) { - KernelLoadedImage->LoadOptionsSize =3D 0; - } else { - // - // Verify NUL-termination of the command line. - // - if (CommandLineBlob->Data[CommandLineBlob->Size - 1] !=3D '\0') { - DEBUG ((EFI_D_ERROR, "%a: kernel command line is not NUL-terminated\= n", - __FUNCTION__)); - Status =3D EFI_PROTOCOL_ERROR; - goto UnloadKernelImage; - } - - // - // Drop the terminating NUL, convert to UTF-16. - // - KernelLoadedImage->LoadOptionsSize =3D (CommandLineBlob->Size - 1) * 2; - } - - if (InitrdBlob->Data !=3D NULL) { - // - // Append ' initrd=3D' in UTF-16. - // - KernelLoadedImage->LoadOptionsSize +=3D - (8 + StrLen(InitrdBlob->Name)) * 2; - } - - if (KernelLoadedImage->LoadOptionsSize =3D=3D 0) { - KernelLoadedImage->LoadOptions =3D NULL; - } else { - // - // NUL-terminate in UTF-16. - // - KernelLoadedImage->LoadOptionsSize +=3D 2; - - KernelLoadedImage->LoadOptions =3D AllocatePool ( - KernelLoadedImage->LoadOptionsSize); - if (KernelLoadedImage->LoadOptions =3D=3D NULL) { - KernelLoadedImage->LoadOptionsSize =3D 0; - Status =3D EFI_OUT_OF_RESOURCES; - goto UnloadKernelImage; - } - - UnicodeSPrintAsciiFormat ( - KernelLoadedImage->LoadOptions, - KernelLoadedImage->LoadOptionsSize, - "%a%a%s", - (CommandLineBlob->Data =3D=3D NULL) ? "" : (CHAR8 *)CommandLineBlob= ->Data, - (InitrdBlob->Data =3D=3D NULL) ? "" : " initrd=3D", - (InitrdBlob->Data =3D=3D NULL) ? L"" : InitrdBlob->Name - ); - DEBUG ((EFI_D_INFO, "%a: command line: \"%s\"\n", __FUNCTION__, - (CHAR16 *)KernelLoadedImage->LoadOptions)); - } - // // Signal the EFI_EVENT_GROUP_READY_TO_BOOT event. // @@ -1080,41 +59,13 @@ TryRunningQemuKernel ( // // Start the image. // - Status =3D gBS->StartImage ( - KernelImageHandle, - NULL, // ExitDataSize - NULL // ExitData - ); + Status =3D QemuStartKernelImage (&KernelImageHandle); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a: StartImage(): %r\n", __FUNCTION__, Status)); + DEBUG ((DEBUG_ERROR, "%a: QemuStartKernelImage(): %r\n", __FUNCTION__, + Status)); } =20 - if (KernelLoadedImage->LoadOptions !=3D NULL) { - FreePool (KernelLoadedImage->LoadOptions); - } - KernelLoadedImage->LoadOptionsSize =3D 0; - -UnloadKernelImage: - gBS->UnloadImage (KernelImageHandle); - -FreeKernelDevicePath: - FreePool (KernelDevicePath); - -UninstallProtocols: - gBS->UninstallMultipleProtocolInterfaces (FileSystemHandle, - &gEfiSimpleFileSystemProtocolGuid, &mFileSystem, - &gEfiDevicePathProtocolGuid, &mFileSystemDevicePath, - NULL); - -FreeBlobs: - while (BlobType > 0) { - CurrentBlob =3D &mKernelBlob[--BlobType]; - if (CurrentBlob->Data !=3D NULL) { - FreePool (CurrentBlob->Data); - CurrentBlob->Size =3D 0; - CurrentBlob->Data =3D NULL; - } - } + QemuUnloadKernelImage (KernelImageHandle); =20 return Status; } --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55529): https://edk2.groups.io/g/devel/message/55529 Mute This Topic: https://groups.io/mt/71749519/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55530+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55530+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415981; cv=none; d=zohomail.com; s=zohoarc; b=K2MbK3+qDKxSivqx9ekaHAHPb5JxwJRvJwpLWE/zeHOGg5eZYx2g3K/oetdWYsl67o+U26UCuL1XHwY/2OLCMp31ujM9PkSETpfmmUHKEo9vGkNIbTfrZ531OPExlAhAs1A2dAyAdhy+QcOey9E0eF/58qGr+BSrvFmaQw4Uebo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415981; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=hWvdVukoVuyjkGf2Ujb3/z5RLQjS8HNLBAONynMoJZ8=; b=Mc85MPAiTHWBOJEE8EiPC4y1jlhWERi3Wfd5ak2FTCkMxqHFr5yo7nKYZZNmvvMlDaXN0wzNU5IdevWyIznFC90rvo+DHP+cXDYzIuq2BKmQRMCUyk/e2VqAGe2fdyp3jQnJ4i1IJqfIXjJsXmCNUWs0LoP9v/zyOyzkx8a5COM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55530+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415981819344.19010638996997; Thu, 5 Mar 2020 05:46:21 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PzYwYY1788612xE3ViP09pN5; Thu, 05 Mar 2020 05:46:21 -0800 X-Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by mx.groups.io with SMTP id smtpd.web10.12695.1583415980443440111 for ; Thu, 05 Mar 2020 05:46:20 -0800 X-Received: by mail-wr1-f67.google.com with SMTP id 6so1664127wre.4 for ; Thu, 05 Mar 2020 05:46:20 -0800 (PST) X-Gm-Message-State: yiiuAvf2R70SOQL5k3SxGMBix1787277AA= X-Google-Smtp-Source: ADFU+vsjOyWKELbvKbfRfzhTEuueP0+okyNqHGhQVXOqB73HRds8WbBEPaegxfgH47WCF0paNH06AA== X-Received: by 2002:adf:b345:: with SMTP id k5mr10912101wrd.55.1583415978697; Thu, 05 Mar 2020 05:46:18 -0800 (PST) X-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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:17 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 07/14] OvmfPkg/QemuKernelLoaderFsDxe: don't expose kernel command line Date: Thu, 5 Mar 2020 14:46:00 +0100 Message-Id: <20200305134607.20125-8-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415981; bh=/IfUowI5H2oUySAg1hKksmmGSOC2Vwaz8wr1NB1xE38=; h=Cc:Date:From:Reply-To:Subject:To; b=BVE/ZB56IsiTJOG7QM1Evik7jFfb1+JAZ+kTSdCHbFlmNLvnKliepx/pnK0Le7iVYst /O2Ig9O4rLo6VrhXvQCZz9Dv4eJifnZxy3vZG+TPxwO2hNyBC9h0cFf4RD0IKW1CHGYLm WgERtUGFryIn6g25fq/ly1YL0FEXYZ+wRw4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have no need for exposing the kernel command line as a file, so remove support for that. Since the remaining blobs (kernel and initrd) are typically much larger than a page, switch to the page based allocator for blobs at the same time. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPk= g/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c index e4539ec2fbe5..dc86a48af378 100644 --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c @@ -30,7 +30,6 @@ typedef enum { KernelBlobTypeKernel, KernelBlobTypeInitrd, - KernelBlobTypeCommandLine, KernelBlobTypeMax } KERNEL_BLOB_TYPE; =20 @@ -45,7 +44,6 @@ typedef struct { STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] =3D { { QemuFwCfgItemKernelSize, QemuFwCfgItemKernelData, L"kernel" = }, { QemuFwCfgItemInitrdSize, QemuFwCfgItemInitrdData, L"initrd" = }, - { QemuFwCfgItemCommandLineSize, QemuFwCfgItemCommandLineData, L"cmdline"= } }; =20 STATIC UINT64 mTotalBlobBytes; @@ -865,7 +863,7 @@ FetchBlob ( // // Read blob. // - Blob->Data =3D AllocatePool (Blob->Size); + Blob->Data =3D AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)Blob->Size)); if (Blob->Data =3D=3D NULL) { DEBUG ((DEBUG_ERROR, "%a: failed to allocate %Ld bytes for \"%s\"\n", __FUNCTION__, (INT64)Blob->Size, Blob->Name)); @@ -969,7 +967,8 @@ QemuKernelLoaderFsDxeEntrypoint ( while (BlobType > 0) { CurrentBlob =3D &mKernelBlob[--BlobType]; if (CurrentBlob->Data !=3D NULL) { - FreePool (CurrentBlob->Data); + FreePages (CurrentBlob->Data, + EFI_SIZE_TO_PAGES ((UINTN)CurrentBlob->Size)); CurrentBlob->Size =3D 0; CurrentBlob->Data =3D NULL; } --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55530): https://edk2.groups.io/g/devel/message/55530 Mute This Topic: https://groups.io/mt/71749520/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55531+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55531+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415983; cv=none; d=zohomail.com; s=zohoarc; b=D3v0EgFbDpEVwpivOukdgzCe7fcaj1AT5TA1KFx/Q6BVW52pkzMqtXQC1sCrDyqY4ttcs2gQdj68TO1HkjNgkSkGFStWseLd5MOWwRZ8xUpouc1gzLK8tsJH/vnaApntYS/vzuLsYa3wLZrezG4fMhdtmgQDlqtNovNTiZOdJ+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415983; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=qMcGWUaovfn1TRfG4Y3KimRfhw1vZ6gNLuUguHBbyoQ=; b=DBKQ1ZTp+um18T8NWnXZNu3n10bO7wBB5flfjpBhH8k7NHrdnBxHAxKZ+H15WdkbcgpdM6gRxwouVtBOxzfCVuZA2Y9EI0ViOpgZj6W/Kwr53ONM6ZTiZmVLDka+GnWs0lrbsW4GcygiSLmVfw3gMkfeOVpTZmls6Ns+LdqQKks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55531+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415983097148.57328113363053; Thu, 5 Mar 2020 05:46:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PQOgYY1788612xLEKlnBYKIC; Thu, 05 Mar 2020 05:46:22 -0800 X-Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web11.12601.1583415982098614378 for ; Thu, 05 Mar 2020 05:46:22 -0800 X-Received: by mail-wm1-f68.google.com with SMTP id a25so7131335wmm.0 for ; Thu, 05 Mar 2020 05:46:21 -0800 (PST) X-Gm-Message-State: Mm3JaACqEksDbv6elUzPwM72x1787277AA= X-Google-Smtp-Source: ADFU+vtNa5ZBINmPeBLoze6JgzSfbrSV6VdF0qhX4SxxbqwbC78ayPVcdj6I4LxhSByPYO+GegSqsA== X-Received: by 2002:a7b:cb12:: with SMTP id u18mr9833483wmj.153.1583415980217; Thu, 05 Mar 2020 05:46:20 -0800 (PST) X-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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:19 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 08/14] OvmfPkg/QemuKernelLoaderFsDxe: add support for the kernel setup block Date: Thu, 5 Mar 2020 14:46:01 +0100 Message-Id: <20200305134607.20125-9-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415982; bh=/yE7gVQ4doOhPytDGgF1iSIvncGL234x875xfy63fzY=; h=Cc:Date:From:Reply-To:Subject:To; b=nXvb4oeq6McfsgTKXAlrauV/sF8AyEiQzVPN/+0PyLvqCNUPxih227eGFMbcopvIX+f tAsR9HkDGmclfQkSYT+pf0uTuTRweaQAvuzx0iIPnZx7F0W/ej3ZcuLhJH3mve1E3JktU dcUi5E76a2ZX1CZm9QDcsslCij1MSBkfR0I= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On x86, the kernel image consists of a setup block and the actual kernel, and QEMU presents these as separate blobs, whereas on disk (and in terms of PE/COFF image signing), they consist of a single image. So add support to our FS loader driver to expose files via the abstract file system that consist of up to two concatenated blobs, and redefine the kernel file so it consists of the setup and kernel blobs, on every architecture (on non-x86, the setup block is simply 0 bytes and is therefore ignored implicitly) Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c | 74 ++++++++++++++-= ----- 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c b/OvmfPk= g/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c index dc86a48af378..8ccb1983170c 100644 --- a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c +++ b/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.c @@ -34,16 +34,29 @@ typedef enum { } KERNEL_BLOB_TYPE; =20 typedef struct { - FIRMWARE_CONFIG_ITEM CONST SizeKey; - FIRMWARE_CONFIG_ITEM CONST DataKey; - CONST CHAR16 * CONST Name; - UINT32 Size; - UINT8 *Data; + CONST CHAR16 Name[8]; + struct { + FIRMWARE_CONFIG_ITEM CONST SizeKey; + FIRMWARE_CONFIG_ITEM CONST DataKey; + UINT32 Size; + } FwCfgItem[2]; + UINT32 Size; + UINT8 *Data; } KERNEL_BLOB; =20 STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] =3D { - { QemuFwCfgItemKernelSize, QemuFwCfgItemKernelData, L"kernel" = }, - { QemuFwCfgItemInitrdSize, QemuFwCfgItemInitrdData, L"initrd" = }, + { + L"kernel", + { + { QemuFwCfgItemKernelSetupSize, QemuFwCfgItemKernelSetupData, }, + { QemuFwCfgItemKernelSize, QemuFwCfgItemKernelData, }, + } + }, { + L"initrd", + { + { QemuFwCfgItemInitrdSize, QemuFwCfgItemInitrdData, }, + } + } }; =20 STATIC UINT64 mTotalBlobBytes; @@ -850,12 +863,21 @@ FetchBlob ( ) { UINT32 Left; + UINTN Idx; + UINT8 *ChunkData; =20 // // Read blob size. // - QemuFwCfgSelectItem (Blob->SizeKey); - Blob->Size =3D QemuFwCfgRead32 (); + Blob->Size =3D 0; + for (Idx =3D 0; Idx < ARRAY_SIZE (Blob->FwCfgItem); Idx++) { + if (Blob->FwCfgItem[Idx].SizeKey =3D=3D 0) { + break; + } + QemuFwCfgSelectItem (Blob->FwCfgItem[Idx].SizeKey); + Blob->FwCfgItem[Idx].Size =3D QemuFwCfgRead32 (); + Blob->Size +=3D Blob->FwCfgItem[Idx].Size; + } if (Blob->Size =3D=3D 0) { return EFI_SUCCESS; } @@ -872,18 +894,28 @@ FetchBlob ( =20 DEBUG ((DEBUG_INFO, "%a: loading %Ld bytes for \"%s\"\n", __FUNCTION__, (INT64)Blob->Size, Blob->Name)); - QemuFwCfgSelectItem (Blob->DataKey); - - Left =3D Blob->Size; - do { - UINT32 Chunk; - - Chunk =3D (Left < SIZE_1MB) ? Left : SIZE_1MB; - QemuFwCfgReadBytes (Chunk, Blob->Data + (Blob->Size - Left)); - Left -=3D Chunk; - DEBUG ((DEBUG_VERBOSE, "%a: %Ld bytes remaining for \"%s\"\n", - __FUNCTION__, (INT64)Left, Blob->Name)); - } while (Left > 0); + + ChunkData =3D Blob->Data; + for (Idx =3D 0; Idx < ARRAY_SIZE (Blob->FwCfgItem); Idx++) { + if (Blob->FwCfgItem[Idx].DataKey =3D=3D 0) { + break; + } + QemuFwCfgSelectItem (Blob->FwCfgItem[Idx].DataKey); + + Left =3D Blob->FwCfgItem[Idx].Size; + while (Left > 0) { + UINT32 Chunk; + + Chunk =3D (Left < SIZE_1MB) ? Left : SIZE_1MB; + QemuFwCfgReadBytes (Chunk, ChunkData + Blob->FwCfgItem[Idx].Size - L= eft); + Left -=3D Chunk; + DEBUG ((DEBUG_VERBOSE, "%a: %Ld bytes remaining for \"%s\" (%d)\n", + __FUNCTION__, (INT64)Left, Blob->Name, (INT32)Idx)); + } + + ChunkData +=3D Blob->FwCfgItem[Idx].Size; + } + return EFI_SUCCESS; } =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55531): https://edk2.groups.io/g/devel/message/55531 Mute This Topic: https://groups.io/mt/71749521/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55532+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55532+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415985; cv=none; d=zohomail.com; s=zohoarc; b=X1kzM4DiUr7ZXHLEKTpchD1dfQWEh3RsXJr1eggAzySdNr2BWW2jeUOSfcmiG/CKnGTVnWsLtxNTiePYkBBKn7XiMxMp9cTD1D6assfomFjnE7Kh4pB170ktZhzq4g1vziCMzTuBsxgmS9OpOPIBAYeCPn3wZX8Ert/KRMG/p7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415985; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=U1qubNTSH6b7lX9BuDUVymOMKhtKAfhKWJH7oYcDmTo=; b=PEfjY5ZAYz/epAEqZ7ONxEdxt03lXrH5ll7HshHLTgy7sbrYZmFhp5Vxsc0WC8A979GQdV+gjdx0UDXIoBxuxTr4uGgRtZdysJtSG0v22C9TN9GVDM14M0eLyJfLAZFNiQv3GEyiH2DZooJ44EUUDUFlnODjXn5Snf7zX0j392E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55532+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415985106370.4618606917485; Thu, 5 Mar 2020 05:46:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id HpnbYY1788612xvBlBLdXjqU; Thu, 05 Mar 2020 05:46:24 -0800 X-Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.groups.io with SMTP id smtpd.web12.12585.1583415983816780287 for ; Thu, 05 Mar 2020 05:46:24 -0800 X-Received: by mail-wm1-f67.google.com with SMTP id a5so6387959wmb.0 for ; Thu, 05 Mar 2020 05:46:23 -0800 (PST) X-Gm-Message-State: RnEIiFF2WVBWSeLwF7Y04UzMx1787277AA= X-Google-Smtp-Source: ADFU+vtmnHowMni1GXkAFkkFp5u8y+joIAm2gm7BnrovRvAWpDZKtq5bOCFVrqDzQYduX1HDyCZ0NQ== X-Received: by 2002:a7b:cb42:: with SMTP id v2mr9957683wmj.170.1583415981735; Thu, 05 Mar 2020 05:46:21 -0800 (PST) X-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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:20 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 09/14] OvmfPkg: create protocol and GUID header for loaded x86 Linux kernels Date: Thu, 5 Mar 2020 14:46:02 +0100 Message-Id: <20200305134607.20125-10-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415984; bh=uITtKMCV44MVn0DNgCbZ+tm8m8BWqe9XVZafdP0uIzU=; h=Cc:Date:From:Reply-To:Subject:To; b=LcSdb21qKvvg+rOGnK5edhoti0wuCfxyIH0Ta+HQYlagbOr+0Sijhty6Kjel/8Xf8bd wYHervO4GjYlinDN5cuDEiY+6kBdBhJt7joXQshf4oBIR6K+zfGIF3f44YvNHM6lYnnT2 P9mJY3k0jNfdMyvtyGG5UPyLe49T8/6V4WM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In preparation of moving the legacy x86 loading to an implementation of the QEMU load image library class, introduce a protocol header and GUID that we will use to identify legacy loaded x86 Linux kernels in the protocol database. Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Include/Protocol/OvmfLoadedX86LinuxKernel.h | 32 ++++++++++++ OvmfPkg/OvmfPkg.dec | 53 ++++++++++-------= --- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/OvmfPkg/Include/Protocol/OvmfLoadedX86LinuxKernel.h b/OvmfPkg/= Include/Protocol/OvmfLoadedX86LinuxKernel.h new file mode 100644 index 000000000000..01cfd9d189b4 --- /dev/null +++ b/OvmfPkg/Include/Protocol/OvmfLoadedX86LinuxKernel.h @@ -0,0 +1,32 @@ +/** @file + Protocol/GUID definition to describe a x86 Linux kernel image loaded + into memory. + + Note that this protocol is considered internal ABI, and may be change + structure at any time without regard for backward compatibility. + + Copyright (c) 2020, Arm, Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef OVMF_LOADED_X86_LINUX_KERNEL_H__ +#define OVMF_LOADED_X86_LINUX_KERNEL_H__ + +#define OVMF_LOADED_X86_LINUX_KERNEL_PROTOCOL_GUID \ + {0xa3edc05d, 0xb618, 0x4ff6, {0x95, 0x52, 0x76, 0xd7, 0x88, 0x63, 0x43, = 0xc8}} + +typedef struct { + VOID *SetupBuf; + VOID *KernelBuf; + CHAR8 *CommandLine; + VOID *InitrdData; + UINTN SetupSize; + UINTN KernelInitialSize; + UINTN InitrdSize; + UINTN CommandLineSize; +} OVMF_LOADED_X86_LINUX_KERNEL; + +extern EFI_GUID gOvmfLoadedX86LinuxKernelProtocolGuid; + +#endif diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 055caaa43041..913345d49e1f 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -80,38 +80,39 @@ [LibraryClasses] XenPlatformLib|Include/Library/XenPlatformLib.h =20 [Guids] - gUefiOvmfPkgTokenSpaceGuid =3D {0x93bb96af, 0xb9f2, 0x4eb8, {0x= 94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}} - gEfiXenInfoGuid =3D {0xd3b46f3b, 0xd441, 0x1244, {0x= 9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}} - gOvmfPkKek1AppPrefixGuid =3D {0x4e32566d, 0x8e9e, 0x4f52, {0x= 81, 0xd3, 0x5b, 0xb9, 0x71, 0x5f, 0x97, 0x27}} - gOvmfPlatformConfigGuid =3D {0x7235c51c, 0x0c80, 0x4cab, {0x= 87, 0xac, 0x3b, 0x08, 0x4a, 0x63, 0x04, 0xb1}} - gVirtioMmioTransportGuid =3D {0x837dca9e, 0xe874, 0x4d82, {0x= b2, 0x9a, 0x23, 0xfe, 0x0e, 0x23, 0xd1, 0xe2}} - gQemuRamfbGuid =3D {0x557423a1, 0x63ab, 0x406c, {0x= be, 0x7e, 0x91, 0xcd, 0xbc, 0x08, 0xc4, 0x57}} - gXenBusRootDeviceGuid =3D {0xa732241f, 0x383d, 0x4d9c, {0x= 8a, 0xe1, 0x8e, 0x09, 0x83, 0x75, 0x89, 0xd7}} - gRootBridgesConnectedEventGroupGuid =3D {0x24a2d66f, 0xeedd, 0x4086, {0x= 90, 0x42, 0xf2, 0x6e, 0x47, 0x97, 0xee, 0x69}} - gMicrosoftVendorGuid =3D {0x77fa9abd, 0x0359, 0x4d32, {0x= bd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b}} - gEfiLegacyBiosGuid =3D {0x2E3044AC, 0x879F, 0x490F, {0x= 97, 0x60, 0xBB, 0xDF, 0xAF, 0x69, 0x5F, 0x50}} - gEfiLegacyDevOrderVariableGuid =3D {0xa56074db, 0x65fe, 0x45f7, {0x= bd, 0x21, 0x2d, 0x2b, 0xdd, 0x8e, 0x96, 0x52}} - gLinuxEfiInitrdMediaGuid =3D {0x5568e427, 0x68fc, 0x4f3d, {0x= ac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68}} - gQemuKernelLoaderFsMediaGuid =3D {0x1428f772, 0xb64a, 0x441e, {0x= b8, 0xc3, 0x9e, 0xbd, 0xd7, 0xf8, 0x93, 0xc7}} + gUefiOvmfPkgTokenSpaceGuid =3D {0x93bb96af, 0xb9f2, 0x4eb8, {= 0x94, 0x62, 0xe0, 0xba, 0x74, 0x56, 0x42, 0x36}} + gEfiXenInfoGuid =3D {0xd3b46f3b, 0xd441, 0x1244, {= 0x9a, 0x12, 0x0, 0x12, 0x27, 0x3f, 0xc1, 0x4d}} + gOvmfPkKek1AppPrefixGuid =3D {0x4e32566d, 0x8e9e, 0x4f52, {= 0x81, 0xd3, 0x5b, 0xb9, 0x71, 0x5f, 0x97, 0x27}} + gOvmfPlatformConfigGuid =3D {0x7235c51c, 0x0c80, 0x4cab, {= 0x87, 0xac, 0x3b, 0x08, 0x4a, 0x63, 0x04, 0xb1}} + gVirtioMmioTransportGuid =3D {0x837dca9e, 0xe874, 0x4d82, {= 0xb2, 0x9a, 0x23, 0xfe, 0x0e, 0x23, 0xd1, 0xe2}} + gQemuRamfbGuid =3D {0x557423a1, 0x63ab, 0x406c, {= 0xbe, 0x7e, 0x91, 0xcd, 0xbc, 0x08, 0xc4, 0x57}} + gXenBusRootDeviceGuid =3D {0xa732241f, 0x383d, 0x4d9c, {= 0x8a, 0xe1, 0x8e, 0x09, 0x83, 0x75, 0x89, 0xd7}} + gRootBridgesConnectedEventGroupGuid =3D {0x24a2d66f, 0xeedd, 0x4086, {= 0x90, 0x42, 0xf2, 0x6e, 0x47, 0x97, 0xee, 0x69}} + gMicrosoftVendorGuid =3D {0x77fa9abd, 0x0359, 0x4d32, {= 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b}} + gEfiLegacyBiosGuid =3D {0x2E3044AC, 0x879F, 0x490F, {= 0x97, 0x60, 0xBB, 0xDF, 0xAF, 0x69, 0x5F, 0x50}} + gEfiLegacyDevOrderVariableGuid =3D {0xa56074db, 0x65fe, 0x45f7, {= 0xbd, 0x21, 0x2d, 0x2b, 0xdd, 0x8e, 0x96, 0x52}} + gLinuxEfiInitrdMediaGuid =3D {0x5568e427, 0x68fc, 0x4f3d, {= 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68}} + gQemuKernelLoaderFsMediaGuid =3D {0x1428f772, 0xb64a, 0x441e, {= 0xb8, 0xc3, 0x9e, 0xbd, 0xd7, 0xf8, 0x93, 0xc7}} =20 [Ppis] # PPI whose presence in the PPI database signals that the TPM base addre= ss # has been discovered and recorded - gOvmfTpmDiscoveredPpiGuid =3D {0xb9a61ad0, 0x2802, 0x41f3, {0x= b5, 0x13, 0x96, 0x51, 0xce, 0x6b, 0xd5, 0x75}} + gOvmfTpmDiscoveredPpiGuid =3D {0xb9a61ad0, 0x2802, 0x41f3, {= 0xb5, 0x13, 0x96, 0x51, 0xce, 0x6b, 0xd5, 0x75}} =20 [Protocols] - gVirtioDeviceProtocolGuid =3D {0xfa920010, 0x6785, 0x4941, {0x= b6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}} - gXenBusProtocolGuid =3D {0x3d3ca290, 0xb9a5, 0x11e3, {0x= b7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}} - gXenIoProtocolGuid =3D {0x6efac84f, 0x0ab0, 0x4747, {0x= 81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}} - gIoMmuAbsentProtocolGuid =3D {0xf8775d50, 0x8abd, 0x4adf, {0x= 92, 0xac, 0x85, 0x3e, 0x51, 0xf6, 0xc8, 0xdc}} - gEfiLegacy8259ProtocolGuid =3D {0x38321dba, 0x4fe0, 0x4e17, {0x= 8a, 0xec, 0x41, 0x30, 0x55, 0xea, 0xed, 0xc1}} - gEfiFirmwareVolumeProtocolGuid =3D {0x389F751F, 0x1838, 0x4388, {0x= 83, 0x90, 0xcd, 0x81, 0x54, 0xbd, 0x27, 0xf8}} - gEfiIsaAcpiProtocolGuid =3D {0x64a892dc, 0x5561, 0x4536, {0x= 92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55}} - gEfiIsaIoProtocolGuid =3D {0x7ee2bd44, 0x3da0, 0x11d4, {0x= 9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}} - gEfiLegacyBiosProtocolGuid =3D {0xdb9a1e3d, 0x45cb, 0x4abb, {0x= 85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d}} - gEfiLegacyBiosPlatformProtocolGuid =3D {0x783658a3, 0x4172, 0x4421, {0x= a2, 0x99, 0xe0, 0x09, 0x07, 0x9c, 0x0c, 0xb4}} - gEfiLegacyInterruptProtocolGuid =3D {0x31ce593d, 0x108a, 0x485d, {0x= ad, 0xb2, 0x78, 0xf2, 0x1f, 0x29, 0x66, 0xbe}} - gEfiVgaMiniPortProtocolGuid =3D {0xc7735a2f, 0x88f5, 0x4882, {0x= ae, 0x63, 0xfa, 0xac, 0x8c, 0x8b, 0x86, 0xb3}} + gVirtioDeviceProtocolGuid =3D {0xfa920010, 0x6785, 0x4941, {= 0xb6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}} + gXenBusProtocolGuid =3D {0x3d3ca290, 0xb9a5, 0x11e3, {= 0xb7, 0x5d, 0xb8, 0xac, 0x6f, 0x7d, 0x65, 0xe6}} + gXenIoProtocolGuid =3D {0x6efac84f, 0x0ab0, 0x4747, {= 0x81, 0xbe, 0x85, 0x55, 0x62, 0x59, 0x04, 0x49}} + gIoMmuAbsentProtocolGuid =3D {0xf8775d50, 0x8abd, 0x4adf, {= 0x92, 0xac, 0x85, 0x3e, 0x51, 0xf6, 0xc8, 0xdc}} + gEfiLegacy8259ProtocolGuid =3D {0x38321dba, 0x4fe0, 0x4e17, {= 0x8a, 0xec, 0x41, 0x30, 0x55, 0xea, 0xed, 0xc1}} + gEfiFirmwareVolumeProtocolGuid =3D {0x389F751F, 0x1838, 0x4388, {= 0x83, 0x90, 0xcd, 0x81, 0x54, 0xbd, 0x27, 0xf8}} + gEfiIsaAcpiProtocolGuid =3D {0x64a892dc, 0x5561, 0x4536, {= 0x92, 0xc7, 0x79, 0x9b, 0xfc, 0x18, 0x33, 0x55}} + gEfiIsaIoProtocolGuid =3D {0x7ee2bd44, 0x3da0, 0x11d4, {= 0x9a, 0x38, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}} + gEfiLegacyBiosProtocolGuid =3D {0xdb9a1e3d, 0x45cb, 0x4abb, {= 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d}} + gEfiLegacyBiosPlatformProtocolGuid =3D {0x783658a3, 0x4172, 0x4421, {= 0xa2, 0x99, 0xe0, 0x09, 0x07, 0x9c, 0x0c, 0xb4}} + gEfiLegacyInterruptProtocolGuid =3D {0x31ce593d, 0x108a, 0x485d, {= 0xad, 0xb2, 0x78, 0xf2, 0x1f, 0x29, 0x66, 0xbe}} + gEfiVgaMiniPortProtocolGuid =3D {0xc7735a2f, 0x88f5, 0x4882, {= 0xae, 0x63, 0xfa, 0xac, 0x8c, 0x8b, 0x86, 0xb3}} + gOvmfLoadedX86LinuxKernelProtocolGuid =3D {0xa3edc05d, 0xb618, 0x4ff6, {= 0x95, 0x52, 0x76, 0xd7, 0x88, 0x63, 0x43, 0xc8}} =20 [PcdsFixedAtBuild] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase|0x0|UINT32|0 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55532): https://edk2.groups.io/g/devel/message/55532 Mute This Topic: https://groups.io/mt/71749524/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55533+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55533+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415986; cv=none; d=zohomail.com; s=zohoarc; b=ZuAbr28r5XuDfJnMShYrjs8N3FuaHmJhXqwW3UfJpZOMdhpMgoJIx0/u/wtjKsrWsay2iELApii2sz1LfyMhLG9gkWbvB24k9WRROPt/Pffid335Bs6tB0kPRvw8wTvz3T3FMF5A/Y71M+vRDji7F1gm1sSPvl5vi+JUGomnEdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415986; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Ybg2gxRAIlHQFiUrHrJjbQVtAkVY8RBAgrNRSBa65so=; b=ZGZTQKPgdDr2AWosfMv+eHufEi8iWKT7lNV/uQKrI/P45UNnh0KQ9FfJPv0fK56IVfxcq5Va/nUskYVDj1Rg3faL01nvdfjSwMUGB22tVmSxzJeBPtJG8dKqen8fYYm8in2elyNsDgpod3tKTeV9LpRc/g60Zmj0zRg9OhlLyyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55533+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415986186670.6184764851179; Thu, 5 Mar 2020 05:46:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id MESWYY1788612xluTD7BuJ8A; Thu, 05 Mar 2020 05:46:25 -0800 X-Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web10.12696.1583415985094081198 for ; Thu, 05 Mar 2020 05:46:25 -0800 X-Received: by mail-wr1-f66.google.com with SMTP id 6so1664395wre.4 for ; Thu, 05 Mar 2020 05:46:24 -0800 (PST) X-Gm-Message-State: sRVlMevdkEcyMllRDZZ9de1Dx1787277AA= X-Google-Smtp-Source: ADFU+vuOxfNiTCp9nwNwSoQVorHHqLu+SvonFl5MXBp6/nOB/JJGsvRZyIPFJ4sC2gewPoG24BmOpg== X-Received: by 2002:adf:ee02:: with SMTP id y2mr4421738wrn.23.1583415982873; Thu, 05 Mar 2020 05:46:22 -0800 (PST) X-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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:22 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 10/14] OvmfPkg: implement QEMU loader library for X86 with legacy fallback Date: Thu, 5 Mar 2020 14:46:03 +0100 Message-Id: <20200305134607.20125-11-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415985; bh=Wr5vEX4wzETPgL5JhZGq3CsH/8AhYqtyTibc94uPQis=; h=Cc:Date:From:Reply-To:Subject:To; b=jgZgHpi5v7TS5v9JKWDxRQpXFRhs59MHhtjCg7IYPJ6RCi57lq1yvW9KAlt2cxO+oIF 73R7nWyHU18BA/D9wJrAIeF8EPyx6ZqiYCuBbMt9SGmGobh2N8+GBW24RJpNJReHusD3G gXU9xXvG2tlgxXgidDh2Q07zy7pzUuR7Eoc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement another version of QemuLoadImageLib that uses LoadImage and StartImage, but falls back to the legacy Linux loader code if that fails. The logic in the legacy fallback routines is identical to the current QEMU linux loader for X64 and IA32. Note the use of the OVMF_LOADED_X86_LINUX_KERNEL protocol for the legacy loaded image: this makes it possible to expose the LoadImage/StartImage abstraction for the legacy loader, using the EFI paradigm of identifying a loaded image solely by a handle. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c | 567 ++++++++= ++++++++++++ OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf | 42 ++ 2 files changed, 609 insertions(+) diff --git a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c b/Ov= mfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c new file mode 100644 index 000000000000..e5979981ff8f --- /dev/null +++ b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.c @@ -0,0 +1,567 @@ +/** @file + X86 specific implementation of QemuLoadImageLib library class interface + with support for loading mixed mode images and non-EFI stub images + + Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+ Copyright (c) 2020, ARM Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma pack (1) +typedef struct { + EFI_DEVICE_PATH_PROTOCOL FilePathHeader; + CHAR16 FilePath[ARRAY_SIZE (L"kernel")]; +} KERNEL_FILE_DEVPATH; + +typedef struct { + VENDOR_DEVICE_PATH VenMediaNode; + KERNEL_FILE_DEVPATH FileNode; + EFI_DEVICE_PATH_PROTOCOL EndNode; +} KERNEL_VENMEDIA_FILE_DEVPATH; +#pragma pack () + +STATIC CONST KERNEL_VENMEDIA_FILE_DEVPATH mKernelDevicePath =3D { + { + { + 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"kernel", + }, { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL) } + } +}; + +STATIC +VOID +FreeLegacyImage ( + IN OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage + ) +{ + if (LoadedImage->SetupBuf !=3D NULL) { + FreePages (LoadedImage->SetupBuf, + EFI_SIZE_TO_PAGES (LoadedImage->SetupSize)); + } + if (LoadedImage->KernelBuf !=3D NULL) { + FreePages (LoadedImage->KernelBuf, + EFI_SIZE_TO_PAGES (LoadedImage->KernelInitialSize)); + } + if (LoadedImage->CommandLine !=3D NULL) { + FreePages (LoadedImage->CommandLine, + EFI_SIZE_TO_PAGES (LoadedImage->CommandLineSize)); + } + if (LoadedImage->InitrdData !=3D NULL) { + FreePages (LoadedImage->InitrdData, + EFI_SIZE_TO_PAGES (LoadedImage->InitrdSize)); + } +} + +STATIC +EFI_STATUS +QemuLoadLegacyImage ( + OUT EFI_HANDLE *ImageHandle + ) +{ + EFI_STATUS Status; + UINTN KernelSize; + UINTN SetupSize; + OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage; + + QemuFwCfgSelectItem (QemuFwCfgItemKernelSize); + KernelSize =3D (UINTN)QemuFwCfgRead32 (); + + QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize); + SetupSize =3D (UINTN)QemuFwCfgRead32 (); + + if (KernelSize =3D=3D 0 || SetupSize =3D=3D 0) { + DEBUG ((DEBUG_INFO, "qemu -kernel was not used.\n")); + return EFI_NOT_FOUND; + } + + LoadedImage =3D AllocateZeroPool (sizeof (*LoadedImage)); + if (LoadedImage =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + LoadedImage->SetupSize =3D SetupSize; + LoadedImage->SetupBuf =3D LoadLinuxAllocateKernelSetupPages ( + EFI_SIZE_TO_PAGES (LoadedImage->SetupSize)); + if (LoadedImage->SetupBuf =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Unable to allocate memory for kernel setup!\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeImageDesc; + } + + DEBUG ((DEBUG_INFO, "Setup size: 0x%x\n", (UINT32)LoadedImage->SetupSize= )); + DEBUG ((DEBUG_INFO, "Reading kernel setup image ...")); + QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData); + QemuFwCfgReadBytes (LoadedImage->SetupSize, LoadedImage->SetupBuf); + DEBUG ((DEBUG_INFO, " [done]\n")); + + Status =3D LoadLinuxCheckKernelSetup (LoadedImage->SetupBuf, + LoadedImage->SetupSize); + if (EFI_ERROR (Status)) { + goto FreeImage; + } + + Status =3D LoadLinuxInitializeKernelSetup (LoadedImage->SetupBuf); + if (EFI_ERROR (Status)) { + goto FreeImage; + } + + LoadedImage->KernelInitialSize =3D LoadLinuxGetKernelSize ( + LoadedImage->SetupBuf, KernelSize); + if (LoadedImage->KernelInitialSize =3D=3D 0) { + Status =3D EFI_UNSUPPORTED; + goto FreeImage; + } + + LoadedImage->KernelBuf =3D LoadLinuxAllocateKernelPages ( + LoadedImage->SetupBuf, + EFI_SIZE_TO_PAGES (LoadedImage->KernelInitial= Size) + ); + if (LoadedImage->KernelBuf =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Unable to allocate memory for kernel!\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeImage; + } + + DEBUG ((DEBUG_INFO, "Kernel size: 0x%x\n", (UINT32)KernelSize)); + DEBUG ((DEBUG_INFO, "Reading kernel image ...")); + QemuFwCfgSelectItem (QemuFwCfgItemKernelData); + QemuFwCfgReadBytes (KernelSize, LoadedImage->KernelBuf); + DEBUG ((DEBUG_INFO, " [done]\n")); + + QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize); + LoadedImage->CommandLineSize =3D (UINTN)QemuFwCfgRead32 (); + + if (LoadedImage->CommandLineSize > 0) { + LoadedImage->CommandLine =3D LoadLinuxAllocateCommandLinePages ( + EFI_SIZE_TO_PAGES ( + LoadedImage->CommandLineSize)); + QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); + QemuFwCfgReadBytes (LoadedImage->CommandLineSize, LoadedImage->Command= Line); + } + + Status =3D LoadLinuxSetCommandLine (LoadedImage->SetupBuf, + LoadedImage->CommandLine); + if (EFI_ERROR (Status)) { + goto FreeImage; + } + + QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); + LoadedImage->InitrdSize =3D (UINTN)QemuFwCfgRead32 (); + + if (LoadedImage->InitrdSize > 0) { + LoadedImage->InitrdData =3D LoadLinuxAllocateInitrdPages ( + LoadedImage->SetupBuf, + EFI_SIZE_TO_PAGES (LoadedImage->InitrdSize= )); + DEBUG ((DEBUG_INFO, "Initrd size: 0x%x\n", + (UINT32)LoadedImage->InitrdSize)); + DEBUG ((DEBUG_INFO, "Reading initrd image ...")); + QemuFwCfgSelectItem (QemuFwCfgItemInitrdData); + QemuFwCfgReadBytes (LoadedImage->InitrdSize, LoadedImage->InitrdData); + DEBUG ((DEBUG_INFO, " [done]\n")); + } + + Status =3D LoadLinuxSetInitrd (LoadedImage->SetupBuf, LoadedImage->Initr= dData, + LoadedImage->InitrdSize); + if (EFI_ERROR (Status)) { + goto FreeImage; + } + + *ImageHandle =3D NULL; + Status =3D gBS->InstallProtocolInterface (ImageHandle, + &gOvmfLoadedX86LinuxKernelProtocolGuid, EFI_NATIVE_INTER= FACE, + LoadedImage); + if (EFI_ERROR (Status)) { + goto FreeImage; + } + return EFI_SUCCESS; + +FreeImage: + FreeLegacyImage (LoadedImage); +FreeImageDesc: + FreePool (LoadedImage); + return Status; +} + +STATIC +EFI_STATUS +QemuStartLegacyImage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage; + + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gOvmfLoadedX86LinuxKernelProtocolGuid, + (VOID **)&LoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + return LoadLinux (LoadedImage->KernelBuf, LoadedImage->SetupBuf); +} + +STATIC +EFI_STATUS +QemuUnloadLegacyImage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage; + + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gOvmfLoadedX86LinuxKernelProtocolGuid, + (VOID **)&LoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->UninstallProtocolInterface (ImageHandle, + &gOvmfLoadedX86LinuxKernelProtocolGuid, LoadedImage); + ASSERT_EFI_ERROR (Status); + + FreeLegacyImage (LoadedImage); + FreePool (LoadedImage); + return EFI_SUCCESS; +} + +/** + Download the kernel, the initial ramdisk, and the kernel command line fr= om + QEMU's fw_cfg. The kernel will be instructed via its command line to load + the initrd from the same Simple FileSystem where the kernel was loaded f= rom. + + @param[out] ImageHandle The image handle that was allocated for + loading the image + + @retval EFI_SUCCESS The image was loaded successfully. + @retval EFI_NOT_FOUND Kernel image was not found. + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + @retval EFI_PROTOCOL_ERROR Unterminated kernel command line. + + @return Error codes from any of the underlying + functions. +**/ +EFI_STATUS +EFIAPI +QemuLoadKernelImage ( + OUT EFI_HANDLE *ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HANDLE KernelImageHandle; + EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage; + UINTN CommandLineSize; + CHAR8 *CommandLine; + UINTN InitrdSize; + + // + // Load the image. This should call back into the QEMU EFI loader file s= ystem. + // + Status =3D gBS->LoadImage ( + FALSE, // BootPolicy: exact match req= uired + gImageHandle, // ParentImageHandle + (EFI_DEVICE_PATH_PROTOCOL *)&mKernelDevicePath, + NULL, // SourceBuffer + 0, // SourceSize + &KernelImageHandle + ); + switch (Status) { + case EFI_SUCCESS: + break; + + case EFI_NOT_FOUND: + // + // The image does not exist - no -kernel image was supplied via the + // command line so no point in invoking the legacy fallback + // + return EFI_NOT_FOUND; + + case EFI_SECURITY_VIOLATION: + // + // We are running with UEFI secure boot enabled, and the image failed = to + // authenticate. For compatibility reasons, we fall back to the legacy + // loader in this case. Since the image has been loaded, we need to un= load + // it before proceeding + // + gBS->UnloadImage (KernelImageHandle); + // + // Fall through + // + case EFI_UNSUPPORTED: + // + // The image is not natively supported or cross-type supported. Let's = try + // loading it using the loader that parses the bzImage metadata direct= ly. + // + Status =3D QemuLoadLegacyImage (&KernelImageHandle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: QemuLoadLegacyImage(): %r\n", __FUNCTION__, + Status)); + return Status; + } + *ImageHandle =3D KernelImageHandle; + return EFI_SUCCESS; + + default: + DEBUG ((DEBUG_ERROR, "%a: LoadImage(): %r\n", __FUNCTION__, Status)); + return Status; + } + + // + // Construct the kernel command line. + // + Status =3D gBS->OpenProtocol ( + KernelImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **)&KernelLoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + ASSERT_EFI_ERROR (Status); + + QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize); + CommandLineSize =3D (UINTN)QemuFwCfgRead32 (); + + if (CommandLineSize =3D=3D 0) { + KernelLoadedImage->LoadOptionsSize =3D 0; + } else { + CommandLine =3D AllocatePool (CommandLineSize); + if (CommandLine =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto UnloadImage; + } + + QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); + QemuFwCfgReadBytes (CommandLineSize, CommandLine); + + // + // Verify NUL-termination of the command line. + // + if (CommandLine[CommandLineSize - 1] !=3D '\0') { + DEBUG ((DEBUG_ERROR, "%a: kernel command line is not NUL-terminated\= n", + __FUNCTION__)); + Status =3D EFI_PROTOCOL_ERROR; + goto FreeCommandLine; + } + + // + // Drop the terminating NUL, convert to UTF-16. + // + KernelLoadedImage->LoadOptionsSize =3D (CommandLineSize - 1) * 2; + } + + QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); + InitrdSize =3D (UINTN)QemuFwCfgRead32 (); + + if (InitrdSize > 0) { + // + // Append ' initrd=3Dinitrd' in UTF-16. + // + KernelLoadedImage->LoadOptionsSize +=3D sizeof (L" initrd=3Dinitrd") -= 2; + } + + if (KernelLoadedImage->LoadOptionsSize =3D=3D 0) { + KernelLoadedImage->LoadOptions =3D NULL; + } else { + // + // NUL-terminate in UTF-16. + // + KernelLoadedImage->LoadOptionsSize +=3D 2; + + KernelLoadedImage->LoadOptions =3D AllocatePool ( + KernelLoadedImage->LoadOptionsSize); + if (KernelLoadedImage->LoadOptions =3D=3D NULL) { + KernelLoadedImage->LoadOptionsSize =3D 0; + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeCommandLine; + } + + UnicodeSPrintAsciiFormat ( + KernelLoadedImage->LoadOptions, + KernelLoadedImage->LoadOptionsSize, + "%a%a", + (CommandLineSize =3D=3D 0) ? "" : CommandLine, + (InitrdSize =3D=3D 0) ? "" : " initrd=3Dinitrd" + ); + DEBUG ((DEBUG_INFO, "%a: command line: \"%s\"\n", __FUNCTION__, + (CHAR16 *)KernelLoadedImage->LoadOptions)); + } + + *ImageHandle =3D KernelImageHandle; + return EFI_SUCCESS; + +FreeCommandLine: + if (CommandLineSize > 0) { + FreePool (CommandLine); + } +UnloadImage: + gBS->UnloadImage (KernelImageHandle); + + return Status; +} + +/** + Transfer control to a kernel image loaded with QemuLoadKernelImage () + + @param[in,out] ImageHandle Handle of image to be started. May assum= e a + different value on return if the image w= as + reloaded. + + @retval EFI_INVALID_PARAMETER ImageHandle is either an invalid image h= andle + or the image has already been initialize= d with + StartImage + @retval EFI_SECURITY_VIOLATION The current platform policy specifies th= at the + image should not be started. + + @return Error codes returned by the started image +**/ +EFI_STATUS +EFIAPI +QemuStartKernelImage ( + IN OUT EFI_HANDLE *ImageHandle + ) +{ + EFI_STATUS Status; + OVMF_LOADED_X86_LINUX_KERNEL *LoadedImage; + EFI_HANDLE KernelImageHandle; + + Status =3D gBS->OpenProtocol ( + *ImageHandle, + &gOvmfLoadedX86LinuxKernelProtocolGuid, + (VOID **)&LoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + return QemuStartLegacyImage (*ImageHandle); + } + + Status =3D gBS->StartImage ( + *ImageHandle, + NULL, // ExitDataSize + NULL // ExitData + ); +#ifdef MDE_CPU_IA32 + if (Status =3D=3D EFI_UNSUPPORTED) { + // + // On IA32, EFI_UNSUPPORTED means that the image's machine type is X64= while + // we are expecting a IA32 one, and the StartImage () boot service is = unable + // to handle it, either because the image does not have the special .c= ompat + // PE/COFF section that Linux specifies for mixed mode capable images,= or + // because we are running without the support code for that. So load t= he + // image again, using the legacy loader, and unload the normally loaded + // image before starting the legacy one. + // + Status =3D QemuLoadLegacyImage (&KernelImageHandle); + if (EFI_ERROR (Status)) { + // + // Note: no change to (*ImageHandle), the caller will release it. + // + return Status; + } + // + // Swap in the legacy-loaded image. + // + QemuUnloadKernelImage (*ImageHandle); + *ImageHandle =3D KernelImageHandle; + return QemuStartLegacyImage (KernelImageHandle); + } +#endif + return Status; +} + +/** + Unloads an image loaded with QemuLoadKernelImage (). + + @param ImageHandle Handle that identifies the image to be + unloaded. + + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_UNSUPPORTED The image has been started, and does not + support unload. + @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle. + + @return Exit code from the image's unload functi= on. +**/ +EFI_STATUS +EFIAPI +QemuUnloadKernelImage ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_LOADED_IMAGE_PROTOCOL *KernelLoadedImage; + EFI_STATUS Status; + + Status =3D gBS->OpenProtocol ( + ImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **)&KernelLoadedImage, + gImageHandle, // AgentHandle + NULL, // ControllerHandle + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (Status =3D=3D EFI_UNSUPPORTED) { + // + // The handle exists but does not have an instance of the standard loa= ded + // image protocol installed on it. Attempt to unload it as a legacy im= age + // instead. + // + return QemuUnloadLegacyImage (ImageHandle); + } + + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } + + // + // We are unloading a normal, non-legacy loaded image, either on behalf = of + // an external caller, or called from QemuStartKernelImage() on IA32, wh= ile + // switching from the normal to the legacy method to load and start a X64 + // image. + // + if (KernelLoadedImage->LoadOptions !=3D NULL) { + FreePool (KernelLoadedImage->LoadOptions); + KernelLoadedImage->LoadOptions =3D NULL; + } + KernelLoadedImage->LoadOptionsSize =3D 0; + + return gBS->UnloadImage (ImageHandle); +} diff --git a/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf b/= OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf new file mode 100644 index 000000000000..e1615badd2ba --- /dev/null +++ b/OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib.inf @@ -0,0 +1,42 @@ +## @file +# X86 specific implementation of QemuLoadImageLib library class interface +# with support for loading mixed mode images and non-EFI stub images +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D X86QemuLoadImageLib + FILE_GUID =3D 2304df80-e21d-4170-9c3c-113c878f7ac0 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D QemuLoadImageLib|DXE_DRIVER + +[Sources] + X86QemuLoadImageLib.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib + MemoryAllocationLib + LoadLinuxLib + PrintLib + QemuFwCfgLib + ReportStatusCodeLib + UefiBootServicesTableLib + +[Protocols] + gEfiDevicePathProtocolGuid + gEfiLoadedImageProtocolGuid + gOvmfLoadedX86LinuxKernelProtocolGuid + +[Guids] + gQemuKernelLoaderFsMediaGuid --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55533): https://edk2.groups.io/g/devel/message/55533 Mute This Topic: https://groups.io/mt/71749525/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55534+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55534+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415988; cv=none; d=zohomail.com; s=zohoarc; b=OlSJxnMt2TEfGm13lXk5pismI3T2BrjbbViE+G9XJbSaXBE10UhZOGcsHIwLmEtpXzR2ocp/goW9wYUZxr1DEao6UXrbBfX/b20jU5+9uZo+KE5sWN8j2ETw3Wv5jKCy1pTZXolzxh22mqva3ODn2Xih4emHsz+Kky6j/iKGYQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415988; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=nNyabcNQ97fMpsykR5XXkRf9zMqHaz+dlheBXPq6Q0A=; b=aAkzoXGnz8eaYbpKI8YrWvP8rIa73g5iqxUAPKgklKB3iDpU9Akkmf89U0XBNQTOgYDUQa6mmOeyNZlReds6lnEJdfuSc9YqU+yks3P4akwAnD8Ft+DiMlP03NTi4UwpGOuwFock3qEqppCOdj0gtAQIn92IaFVxhPyEPZJB+II= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55534+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415988046440.02215709130815; Thu, 5 Mar 2020 05:46:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ox81YY1788612xJBKWG3vaZc; Thu, 05 Mar 2020 05:46:26 -0800 X-Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by mx.groups.io with SMTP id smtpd.web10.12697.1583415985878933226 for ; Thu, 05 Mar 2020 05:46:26 -0800 X-Received: by mail-wr1-f44.google.com with SMTP id r17so7091175wrj.7 for ; Thu, 05 Mar 2020 05:46:25 -0800 (PST) X-Gm-Message-State: 29ym9KgdT5VV3MxTFePRqqYGx1787277AA= X-Google-Smtp-Source: ADFU+vvzB7Gip79wVftukvyM3DN/cEp5j+3agTuEQjPMDWqjvsqDcdfq99V/LvBSKDCI2j5Tx574cw== X-Received: by 2002:a5d:4083:: with SMTP id o3mr10532207wrp.237.1583415984137; Thu, 05 Mar 2020 05:46:24 -0800 (PST) X-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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:23 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 11/14] OvmfPkg: add new QEMU kernel image loader components Date: Thu, 5 Mar 2020 14:46:04 +0100 Message-Id: <20200305134607.20125-12-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415986; bh=N1b28AXq6UfXy9kUzzQqPVlA0Tx+5Mx5UE/JPLRJaK0=; h=Cc:Date:From:Reply-To:Subject:To; b=TB466tqwc+ks5ylzQuBmIkzPCZ6xNpr62DYsFe/uTFM7ei/hYU7VOlxAotAck3zuqM0 c1tfhRdMpmAXbwdCXU2SSF3Nnfol4JLH5raQdGTpBoqRMnOQr8zv/pOg5Wfjj8aQsKiBH rQh9F+RU2WkDzbdLMEGu5ht6pdJOlgL8Yqc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the components that expose the QEMU abstract loader file system so that we can switch over our PlatformBmLib over to it in a subsequent patch. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.fdf | 1 + 6 files changed, 9 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 53f503b3ed36..ec21d2f3f6cb 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -363,6 +363,7 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf + QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib= .inf !if $(TPM_ENABLE) =3D=3D TRUE Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.i= nf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf @@ -716,6 +717,7 @@ [Components] NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf !endif } + OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf OvmfPkg/Virtio10Dxe/Virtio10.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index 56e3ab3df25a..0e98a4dbd24a 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -243,6 +243,7 @@ [FV.DXEFV] INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.= inf INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf INF MdeModulePkg/Application/UiApp/UiApp.inf +INF OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index d907465752a6..3c80a18c6086 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -367,6 +367,7 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf + QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib= .inf !if $(TPM_ENABLE) =3D=3D TRUE Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.i= nf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf @@ -728,6 +729,7 @@ [Components.X64] NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf !endif } + OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf OvmfPkg/Virtio10Dxe/Virtio10.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index add188723f3e..1dd431d72113 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -244,6 +244,7 @@ [FV.DXEFV] INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.= inf INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf INF MdeModulePkg/Application/UiApp/UiApp.inf +INF OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 0c6582a9ed37..63f1f935f4f3 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -367,6 +367,7 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf + QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib= .inf !if $(TPM_ENABLE) =3D=3D TRUE Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.i= nf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf @@ -726,6 +727,7 @@ [Components] NULL|OvmfPkg/Csm/LegacyBootMaintUiLib/LegacyBootMaintUiLib.inf !endif } + OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf OvmfPkg/Virtio10Dxe/Virtio10.inf OvmfPkg/VirtioBlkDxe/VirtioBlk.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index add188723f3e..1dd431d72113 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -244,6 +244,7 @@ [FV.DXEFV] INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe.= inf INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf INF MdeModulePkg/Application/UiApp/UiApp.inf +INF OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf INF MdeModulePkg/Universal/PrintDxe/PrintDxe.inf INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55534): https://edk2.groups.io/g/devel/message/55534 Mute This Topic: https://groups.io/mt/71749526/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55535+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55535+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415989; cv=none; d=zohomail.com; s=zohoarc; b=AhnOvZHLGoaCJvA+o6ESGgeBggqke7nM/6/xXyQiJWKujg7MIBmJ4lXxQwaigqNJDXAvUk9XaoSm24IbjEKJa2TxfBGCNOLrrcSkBVbRoTJOV2wkL/aoo8eMtJ7C3S/EI66PjYGqWxjdnROdkjTN0oMVEQldcPJeitp7pGzW9Sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415989; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=PBaf8VhRdF+0JrS4cqWSHHhoxEXafl9s0Levy9mLhJM=; b=E3wk2X2XNCBLhc6jSde5UR+8B8aJWOkSpM7LKjI3eNgqkN/QmYo7GojS3vXYfqQmWNhsOLKca/FWGvsxivEAKpznOULkpLq8STy88Wmj/Pw2linzTphz24z0MHy//aTr1r1S51iMAwUXlYPx5ADIJh8O+P4HTi1iaiumJ/QP1Ls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55535+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158341598916023.97990245443873; Thu, 5 Mar 2020 05:46:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6xJMYY1788612xcUEmYNNlC5; Thu, 05 Mar 2020 05:46:28 -0800 X-Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web10.12698.1583415987524382720 for ; Thu, 05 Mar 2020 05:46:27 -0800 X-Received: by mail-wr1-f68.google.com with SMTP id x7so7112023wrr.0 for ; Thu, 05 Mar 2020 05:46:27 -0800 (PST) X-Gm-Message-State: BrxxxaK9fmPWdV8XrNblsjSbx1787277AA= X-Google-Smtp-Source: ADFU+vtxOVCAtGyxpNxhgqq0Vsczk9sa6cjh2Qrb8pv8gMRmZRrUPzn4agopAcstgfXZAOa7Vs2WKA== X-Received: by 2002:a5d:5089:: with SMTP id a9mr10596594wrt.187.1583415985491; Thu, 05 Mar 2020 05:46:25 -0800 (PST) X-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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:24 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 12/14] OvmfPkg/PlatformBootManagerLib: switch to QemuLoadImageLib Date: Thu, 5 Mar 2020 14:46:05 +0100 Message-Id: <20200305134607.20125-13-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415988; bh=4W5F/lynfdcx01TiNxiXx+FwyeYWdSXbKZ+JvyGRdPY=; h=Cc:Date:From:Reply-To:Subject:To; b=TupCJ3goQiMY/iTKaurmmP40yaKzV/lLAJXJUC6LfjSlrZ6gWjflTrLSotQpzCbJhzz lUERQfBwM3k2DOJe9KOtjYDS+NOE6TqdupctmHD+ZNY/40trxa62div3Jv9E6YTx98qNu pi5TbcOMKiCS4pFAxUmZZlClxE+A05JDwrk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Replace the open coded sequence to load Linux on x86 with a short and generic sequence invoking QemuLoadImageLib, which can be provided by a generic version that only supports the LoadImage and StartImage boot services, and one that incorporates the entire legacy loading sequence as well. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 2 +- OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c | 144 ++= ------------------ 2 files changed, 14 insertions(+), 132 deletions(-) diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.= inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index c479f113b92b..e470b9a6a3e5 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -49,7 +49,7 @@ [LibraryClasses] NvVarsFileLib QemuFwCfgLib QemuFwCfgS3Lib - LoadLinuxLib + QemuLoadImageLib QemuBootOrderLib ReportStatusCodeLib UefiLib diff --git a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c b/OvmfPkg/= Library/PlatformBootManagerLib/QemuKernel.c index ddfef925edd3..c6255921779e 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/QemuKernel.c @@ -9,11 +9,8 @@ =20 #include #include -#include -#include -#include +#include #include -#include #include =20 =20 @@ -23,120 +20,11 @@ TryRunningQemuKernel ( ) { EFI_STATUS Status; - UINTN KernelSize; - UINTN KernelInitialSize; - VOID *KernelBuf; - UINTN SetupSize; - VOID *SetupBuf; - UINTN CommandLineSize; - CHAR8 *CommandLine; - UINTN InitrdSize; - VOID* InitrdData; + EFI_HANDLE KernelImageHandle; =20 - SetupBuf =3D NULL; - SetupSize =3D 0; - KernelBuf =3D NULL; - KernelInitialSize =3D 0; - CommandLine =3D NULL; - CommandLineSize =3D 0; - InitrdData =3D NULL; - InitrdSize =3D 0; - - if (!QemuFwCfgIsAvailable ()) { - return EFI_NOT_FOUND; - } - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSize); - KernelSize =3D (UINTN) QemuFwCfgRead64 (); - - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupSize); - SetupSize =3D (UINTN) QemuFwCfgRead64 (); - - if (KernelSize =3D=3D 0 || SetupSize =3D=3D 0) { - DEBUG ((EFI_D_INFO, "qemu -kernel was not used.\n")); - return EFI_NOT_FOUND; - } - - SetupBuf =3D LoadLinuxAllocateKernelSetupPages (EFI_SIZE_TO_PAGES (Setup= Size)); - if (SetupBuf =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel setup!\n")); - return EFI_OUT_OF_RESOURCES; - } - - DEBUG ((EFI_D_INFO, "Setup size: 0x%x\n", (UINT32) SetupSize)); - DEBUG ((EFI_D_INFO, "Reading kernel setup image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemKernelSetupData); - QemuFwCfgReadBytes (SetupSize, SetupBuf); - DEBUG ((EFI_D_INFO, " [done]\n")); - - Status =3D LoadLinuxCheckKernelSetup (SetupBuf, SetupSize); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - Status =3D LoadLinuxInitializeKernelSetup (SetupBuf); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - KernelInitialSize =3D LoadLinuxGetKernelSize (SetupBuf, KernelSize); - if (KernelInitialSize =3D=3D 0) { - Status =3D EFI_UNSUPPORTED; - goto FreeAndReturn; - } - - KernelBuf =3D LoadLinuxAllocateKernelPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (KernelInitialSize)); - if (KernelBuf =3D=3D NULL) { - DEBUG ((EFI_D_ERROR, "Unable to allocate memory for kernel!\n")); - Status =3D EFI_OUT_OF_RESOURCES; - goto FreeAndReturn; - } - - DEBUG ((EFI_D_INFO, "Kernel size: 0x%x\n", (UINT32) KernelSize)); - DEBUG ((EFI_D_INFO, "Reading kernel image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemKernelData); - QemuFwCfgReadBytes (KernelSize, KernelBuf); - DEBUG ((EFI_D_INFO, " [done]\n")); - - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineSize); - CommandLineSize =3D (UINTN) QemuFwCfgRead64 (); - - if (CommandLineSize > 0) { - CommandLine =3D LoadLinuxAllocateCommandLinePages ( - EFI_SIZE_TO_PAGES (CommandLineSize)); - QemuFwCfgSelectItem (QemuFwCfgItemCommandLineData); - QemuFwCfgReadBytes (CommandLineSize, CommandLine); - } else { - CommandLine =3D NULL; - } - - Status =3D LoadLinuxSetCommandLine (SetupBuf, CommandLine); - if (EFI_ERROR (Status)) { - goto FreeAndReturn; - } - - QemuFwCfgSelectItem (QemuFwCfgItemInitrdSize); - InitrdSize =3D (UINTN) QemuFwCfgRead64 (); - - if (InitrdSize > 0) { - InitrdData =3D LoadLinuxAllocateInitrdPages ( - SetupBuf, - EFI_SIZE_TO_PAGES (InitrdSize) - ); - DEBUG ((EFI_D_INFO, "Initrd size: 0x%x\n", (UINT32) InitrdSize)); - DEBUG ((EFI_D_INFO, "Reading initrd image ...")); - QemuFwCfgSelectItem (QemuFwCfgItemInitrdData); - QemuFwCfgReadBytes (InitrdSize, InitrdData); - DEBUG ((EFI_D_INFO, " [done]\n")); - } else { - InitrdData =3D NULL; - } - - Status =3D LoadLinuxSetInitrd (SetupBuf, InitrdData, InitrdSize); + Status =3D QemuLoadKernelImage (&KernelImageHandle); if (EFI_ERROR (Status)) { - goto FreeAndReturn; + return Status; } =20 // @@ -147,22 +35,16 @@ TryRunningQemuKernel ( REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)); =20 - Status =3D LoadLinux (KernelBuf, SetupBuf); + // + // Start the image. + // + Status =3D QemuStartKernelImage (&KernelImageHandle); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: QemuStartKernelImage(): %r\n", __FUNCTION__, + Status)); + } =20 -FreeAndReturn: - if (SetupBuf !=3D NULL) { - FreePages (SetupBuf, EFI_SIZE_TO_PAGES (SetupSize)); - } - if (KernelBuf !=3D NULL) { - FreePages (KernelBuf, EFI_SIZE_TO_PAGES (KernelInitialSize)); - } - if (CommandLine !=3D NULL) { - FreePages (CommandLine, EFI_SIZE_TO_PAGES (CommandLineSize)); - } - if (InitrdData !=3D NULL) { - FreePages (InitrdData, EFI_SIZE_TO_PAGES (InitrdSize)); - } + QemuUnloadKernelImage (KernelImageHandle); =20 return Status; } - --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55535): https://edk2.groups.io/g/devel/message/55535 Mute This Topic: https://groups.io/mt/71749527/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55536+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55536+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415989; cv=none; d=zohomail.com; s=zohoarc; b=TJ4+naSGszYD6msS2h5NelA6rrorxXl20ukDEOYloSTUOt41rxYPO6gbXDIo7h6HpI42WnBH6K91ow4dNPGgLFpCOV5qRGpX5ziXksyCJXbvmNb7ij0EjbO5b3r69vZGPth/LTXnn4u1+q4PgoNXu+3xssviONn8b9Do+uAIShc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415989; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Ri0cZ2KsjIG28e0m8BRzf/hpnvmet2vt0v9zdQuVrfo=; b=kY6klR79gfIjkSJl4+6CsKxPjH3MIzxoIgvzRhCeXzvbchFyPDpT+vBV888sHg4AuwS+qHBfz/I6Vfb1XEH9rqjIqdmTiIMA+1MZTiIzlINEULylYkm0UunkBLYZsNI2huKoMb3f14gAalKaCMQ2Imf27BhQq6dTpY5I5u7Fg1o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55536+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415989460982.7366268262217; Thu, 5 Mar 2020 05:46:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id fXPaYY1788612xBhEww5h8cK; Thu, 05 Mar 2020 05:46:29 -0800 X-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 X-Received: by mail-wr1-f66.google.com with SMTP id j16so7117198wrt.3 for ; Thu, 05 Mar 2020 05:46:28 -0800 (PST) X-Gm-Message-State: 9ItTEIoPf4UfavigyJ419745x1787277AA= 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) X-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: [edk2-devel] [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> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415989; bh=CFDxY3QvJ1Y3qM4M50pTxSwAcH3N2xvluCcSBeJgs2c=; h=Cc:Date:From:Reply-To:Subject:To; b=QYTT4H4jKlJyJ3VdloYkikArIZn8Fmctr05qYBronTSSL6aJ2B9X3Sou2ExdI4owDnj vEosBFOUgg/kJRSx9mFdO3qKvJNomK0zWNxP2aPIIZa7f4s0spaMmjgbIpgMQy2Lpm2Py uGHSwuN+SzQkqbhnZqQ8GV92YKr757puoBg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D2566 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/OvmfPk= g/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 =20 // @@ -84,6 +87,19 @@ STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mFileSystemDev= icePath =3D { } }; =20 +STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mInitrdDevicePath =3D { + { + { + 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 mFileSyst= em =3D { StubFileSystemOpenVolume }; =20 +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 =3D &mKernelBlob[KernelBlobTypeInitrd]; + + ASSERT (InitrdBlob->Size > 0); + + if (BootPolicy) { + return EFI_UNSUPPORTED; + } + + if (BufferSize =3D=3D NULL || !IsDevicePathValid (FilePath, 0)) { + return EFI_INVALID_PARAMETER; + } + + if (FilePath->Type !=3D END_DEVICE_PATH_TYPE || + FilePath->SubType !=3D END_ENTIRE_DEVICE_PATH_SUBTYPE) { + return EFI_NOT_FOUND; + } + + if (Buffer =3D=3D NULL || *BufferSize < InitrdBlob->Size) { + *BufferSize =3D InitrdBlob->Size; + return EFI_BUFFER_TOO_SMALL; + } + + CopyMem (Buffer, InitrdBlob->Data, InitrdBlob->Size); + + *BufferSize =3D InitrdBlob->Size; + return EFI_SUCCESS; +} + +STATIC CONST EFI_LOAD_FILE2_PROTOCOL mInitrdLoadFile2 =3D { + InitrdLoadFile2, +}; =20 // // Utility functions. @@ -949,6 +1007,7 @@ QemuKernelLoaderFsDxeEntrypoint ( KERNEL_BLOB *KernelBlob; EFI_STATUS Status; EFI_HANDLE FileSystemHandle; + EFI_HANDLE InitrdLoadFile2Handle; =20 if (!QemuFwCfgIsAvailable ()) { return EFI_NOT_FOUND; @@ -993,8 +1052,28 @@ QemuKernelLoaderFsDxeEntrypoint ( goto FreeBlobs; } =20 + if (KernelBlob[KernelBlobTypeInitrd].Size > 0) { + InitrdLoadFile2Handle =3D NULL; + Status =3D gBS->InstallMultipleProtocolInterfaces (&InitrdLoadFile2Han= dle, + &gEfiDevicePathProtocolGuid, &mInitrdDevicePath, + &gEfiLoadFile2ProtocolGuid, &mInitrdLoadFile2, + NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: InstallMultipleProtocolInterfaces(): %r\n", + __FUNCTION__, Status)); + goto UninstallFileSystemHandle; + } + } + return EFI_SUCCESS; =20 +UninstallFileSystemHandle: + Status =3D gBS->UninstallMultipleProtocolInterfaces (FileSystemHandle, + &gEfiDevicePathProtocolGuid, &mFileSystemDevicePat= h, + &gEfiSimpleFileSystemProtocolGuid, &mFileSystem, + NULL); + ASSERT_EFI_ERROR (Status); + FreeBlobs: while (BlobType > 0) { CurrentBlob =3D &mKernelBlob[--BlobType]; diff --git a/OvmfPkg/QemuKernelLoaderFsDxe/QemuKernelLoaderFsDxe.inf b/Ovmf= Pkg/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] =20 [Protocols] gEfiDevicePathProtocolGuid ## PRODUCES + gEfiLoadFile2ProtocolGuid ## PRODUCES gEfiSimpleFileSystemProtocolGuid ## PRODUCES =20 [Depex] --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55536): https://edk2.groups.io/g/devel/message/55536 Mute This Topic: https://groups.io/mt/71749528/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Thu May 16 09:38:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55537+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55537+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583415990; cv=none; d=zohomail.com; s=zohoarc; b=bzheTwv/0Ps1+J1w4sNrHARuObUdlZwvClRSJdQnh9zORtBGssWeagM1ZIn4fgKymFIe5UdUQGHhtGWe5E9Xl+3dWLc6XjT6OZUGhw5zp86kFkafUiC4ToRVk959oA0NQ6dtl/7xALglNTEpWYICLhya6foQCFQpdrUSeWF9/y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583415990; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=5hsu/mGoip30BCGC2aPD+d6rjxzznT+5NMNMRk6BYro=; b=LbZeac5NaFAkVsCYOFkspCpitb4nBG1SmRbE80GBIpHzSvcHRkwLNPNRINnem8v3t9DcfaNiLoFpZ34P3Wwuk+RSSvRyxn71Y9jb3yc92zGu/CHd4YSCVLuVO+mRPMwm8MEWVXGGAeR7SOlPyeniqKwLsA1ChNVpWZFjDmC4+Yw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55537+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583415990860397.9767809001561; Thu, 5 Mar 2020 05:46:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id YPDSYY1788612x0DJ6TUXHul; Thu, 05 Mar 2020 05:46:30 -0800 X-Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web11.12604.1583415989761576685 for ; Thu, 05 Mar 2020 05:46:30 -0800 X-Received: by mail-wr1-f68.google.com with SMTP id v11so5134495wrm.9 for ; Thu, 05 Mar 2020 05:46:29 -0800 (PST) X-Gm-Message-State: 2aG0m9MfEcrGhaT6nVO6lXgnx1787277AA= X-Google-Smtp-Source: ADFU+vsSQh9uS286iIf+PwheRQjpJ4So8Bin7kUt3C/CBNgO0wfrEdjo99V4tWQOSUZsWQxsSaSrDQ== X-Received: by 2002:adf:ee4f:: with SMTP id w15mr10919212wro.254.1583415987991; Thu, 05 Mar 2020 05:46:27 -0800 (PST) X-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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2020 05:46:27 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: lersek@redhat.com, Ard Biesheuvel Subject: [edk2-devel] [PATCH v3 14/14] OvmfPkg: use generic QEMU image loader for secure boot enabled builds Date: Thu, 5 Mar 2020 14:46:07 +0100 Message-Id: <20200305134607.20125-15-ard.biesheuvel@linaro.org> In-Reply-To: <20200305134607.20125-1-ard.biesheuvel@linaro.org> References: <20200305134607.20125-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583415990; bh=J5J48iNLKx8Bfu0RXEhKaaoiGdFi9sb2c+EiuTucGpA=; h=Cc:Date:From:Reply-To:Subject:To; b=gJXtMy2siRIhYcumcmlWGUob0v0a4FsMst3wdLHlFl497IeRfJhkev25t/YR9Tj3Vk5 wptExtxuvph7MBiRpCwp4dTWDtw+gplemVUq/KwV7kJ0LcsCJelOJDt/+oL6nANhkq8BK Md0ccpNycCa/FrluMhkrhq/uqnq7tv6IaRQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The QemuLoadImageLib implementation we currently use for all OVMF builds copies the behavior of the QEMU loader code that precedes it, which is to disregard UEFI secure boot policies entirely when it comes to loading kernel images that have been specified on the QEMU command line. This behavior deviates from ArmVirtQemu based builds, which do take UEFI secure boot policies into account, and refuse to load images from the command line that cannot be authenticated. The disparity was originally due to the fact that the QEMU command line kernel loader did not use LoadImage and StartImage at all, but this changed recently, and now, there are only a couple of reasons left to stick with the legacy loader: - it permits loading images that lack a valid PE/COFF header, - it permits loading X64 kernels on IA32 firmware running on a X64 capable system. Since every non-authentic PE/COFF image can trivially be converted into an image that lacks a valid PE/COFF header, the former case can simply not be supported in a UEFI secure boot context. The latter case is highly theoretical, given that one could easily switch to native X64 firmware in a VM scenario. That leaves us with little justification to use the legacy loader at all when UEFI secure boot policies are in effect, so let's switch to the generic loader for UEFI secure boot enabled builds. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2566 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/OvmfPkgIa32.dsc | 4 ++++ OvmfPkg/OvmfPkgIa32X64.dsc | 4 ++++ OvmfPkg/OvmfPkgX64.dsc | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index ec21d2f3f6cb..8916255df4df 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -363,7 +363,11 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf +!else QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib= .inf +!endif !if $(TPM_ENABLE) =3D=3D TRUE Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.i= nf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 3c80a18c6086..342ff96cc279 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -367,7 +367,11 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf +!else QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib= .inf +!endif !if $(TPM_ENABLE) =3D=3D TRUE Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.i= nf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 63f1f935f4f3..1fb2de5e0121 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -367,7 +367,11 @@ [LibraryClasses.common.DXE_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +!if $(SECURE_BOOT_ENABLE) =3D=3D TRUE + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf +!else QemuLoadImageLib|OvmfPkg/Library/X86QemuLoadImageLib/X86QemuLoadImageLib= .inf +!endif !if $(TPM_ENABLE) =3D=3D TRUE Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibTcg/Tpm12DeviceLibTcg.i= nf Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55537): https://edk2.groups.io/g/devel/message/55537 Mute This Topic: https://groups.io/mt/71749529/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-