From nobody Mon Feb 9 22:37:55 2026 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-