From nobody Thu Apr 18 23:21:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+93883+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93883+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1663296397; cv=none; d=zohomail.com; s=zohoarc; b=h12w3+z4esDY2wSXbTfLC5u0/M6a1KgAZo1jwUf1FAQkT5VVSzWOmmz49txF/tFK84NUJHMAyfVUND4bqUbX38dmGEgjSCYOfpDxThV1Mx/Dhw9HjT858SVtg/y/39S1s8f/X9+tTyCxcYEjyDsbqB4T28YjSN5E/Lk9hRuZrl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663296397; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZwRXotGaE1SGEofz16oGlHNMzfcVmd6rbYYYI6lfuuE=; b=MEejVQ+pTuq9f89DyyvCnKqLpF+TqouP/dc0tlf9l01ujJGL07FEOqlWFANvUvsO1G3ravzQR+5Rg7cqFTrEKHF/CdsTfSRqxLc1AoIMC09+yLTOkLN7O64DGkCmamx5TnlokkqtGnKtln1W/DSfNfAtm5tUxnCnr17r/BJITQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93883+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1663296397223960.4422919839792; Thu, 15 Sep 2022 19:46:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lLRNYY1788612xuyXFTR7cQH; Thu, 15 Sep 2022 19:46:35 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.1787.1663296395045755974 for ; Thu, 15 Sep 2022 19:46:35 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F5451042; Thu, 15 Sep 2022 19:46:41 -0700 (PDT) X-Received: from entos-thunderx2-desktop.shanghai.arm.com (entos-thunderx2-desktop.shanghai.arm.com [10.169.212.232]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 589B23F71A; Thu, 15 Sep 2022 19:46:32 -0700 (PDT) From: "Jianyong Wu" To: devel@edk2.groups.io, Sami.Mujawar@arm.com Cc: ardb+tianocore@kernel.org, justin.he@arm.com, jianyong.wu@arm.com Subject: [edk2-devel] [PATCH 1/3] CloudHv:arm: add kernel load fs driver Date: Fri, 16 Sep 2022 10:46:18 +0800 Message-Id: <20220916024620.114084-2-jianyong.wu@arm.com> In-Reply-To: <20220916024620.114084-1-jianyong.wu@arm.com> References: <20220916024620.114084-1-jianyong.wu@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,jianyong.wu@arm.com X-Gm-Message-State: dQYxZPXgkM28kNlmJcdtqH4yx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1663296395; bh=eqTo0lsBgvIxzUgeSZdRkeF1cvR1jTiHD5ltuq6AnqY=; h=Cc:Date:From:Reply-To:Subject:To; b=PLVsDLERLIbSC406fpj0qxbYJnaEjfg6FqBqkLrr+0bF0HB049HeiIHxJJTzgdzpK4D Yx/Zt9FwzK9JkYvTgyVmu7gCIPHbPUu2iJAtjYz9SqTx8oEPtfJDR+TkW1N/3J2Q/Lk36 4EItiCtiq+Fgu9zreFuY46TsBOHVJOmD66Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1663296398552100007 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is used for supporting direct kernel boot in CloudHv. CloudHv will store kernel image in system ram and pass kernel info through DT. It's firmware's responsibility to fetch the kernel data and create a file device to feed for loadImage Signed-off-by: Jianyong Wu --- .../CloudHvKernelLoaderFsDxe.c | 969 ++++++++++++++++++ .../CloudHvKernelLoaderFsDxe.inf | 56 + 2 files changed, 1025 insertions(+) create mode 100644 ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoader= FsDxe.c create mode 100644 ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoader= FsDxe.inf diff --git a/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.c= b/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.c new file mode 100644 index 0000000000..e4cfcfab72 --- /dev/null +++ b/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.c @@ -0,0 +1,969 @@ +/** @file + DXE driver to expose the 'kernel', 'initrd' and 'cmdline' blobs + provided by Cloud Hypervisor as files in an abstract file system + + Copyright (C) 2022, Arm, Limited. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +// Static data that hosts the data blobs and serves file requests. +// +typedef enum { + KernelBlobTypeKernel, + KernelBlobTypeInitrd, + KernelBlobTypeCommandLine, + KernelBlobTypeMax +} KERNEL_BLOB_TYPE; + +typedef struct { + CONST CHAR16 Name[8]; + UINT32 Size; + UINT8 *Data; +} KERNEL_BLOB; + +STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] =3D { + { + L"kernel", + },{ + L"initrd", + },{ + L"cmdline", + } +}; + +// +// 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) } + } +}; + +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. +// +STATIC EFI_TIME mInitTime; +STATIC UINT64 mTotalBlobBytes; + +#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. KernelBlobType= Max + // denotes the root directory of the file= system. + + UINT64 Position; // Byte position for regular files; + // next directory entry to return for the= root + // directory. + + EFI_FILE_PROTOCOL File; // Standard protocol interface. +} STUB_FILE; + +#define STUB_FILE_FROM_FILE(FilePointer) \ + CR (FilePointer, STUB_FILE, File, STUB_FILE_SIG) + +/** + 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. +**/ +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; +} + +/** + 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; +} + +// +// Protocol member functions for File. +// + +/** + Opens a new file relative to the source file's location. + + (Forward declaration.) + + @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 + ); + +/** + 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_LABE= L *)Buffer; + FileSystemVolumeLabel->VolumeLabel[0] =3D L'\0'; + + return EFI_SUCCESS; + } + + return EFI_UNSUPPORTED; +} + +// +// External definition of the file protocol template. +// +STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate =3D { + EFI_FILE_PROTOCOL_REVISION, // revision 1 + StubFileOpen, + StubFileClose, + StubFileDelete, + StubFileRead, + NULL, + NULL, + NULL, + StubFileGetInfo, + NULL, + NULL, + NULL, // OpenEx, revision 2 + NULL, // ReadEx, revision 2 + NULL, // WriteEx, revision 2 + NULL // FlushEx, revision 2 +}; + +/** + Opens a new file relative to the source file's location. + + (Forward declaration.) + + @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; +} + +// +// 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 +}; + +/** + Load initrd data to memory + + @param[in] This Not used here. + @param[in] FilePath Contain some metadata of file device where h= olds the initrd. + @param[in] BootPolicy Not support here. + @param[in,out] BufferSize On input, contains the memory buff size. + On output, contains the initrd blob size. + @param[out] Buffer A pointer point to memory which contains ini= trd data. + + @retval EFI_UNSUPPORTED Once the Boot Policy is true. + @retval EFI_INVALID_PARAMETER Once there is no BuffSize given or no ava= ilable file device. + @retval EFI_NOT_FOUND File path doesn't match. + @retval EFI_BUFFER_TOO_SMALL Buff size too small. + @retval EFI_SUCCESS Success. +**/ +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, +}; + +/** + Fetch kernel, initrd and commandline into Blob. + + @param Blob On input, choose which blob to be fetched. + On output, carry the full blob info. + + @retval EFI_NOT_FOUND Kernel is not fetched or no chosen node found i= n DT. + @retval EFI_SUCCESS If there is kernel fetched or the Block->Name i= s not kernel. + +**/ +STATIC +EFI_STATUS +FetchBlob ( + IN OUT KERNEL_BLOB *Blob + ) +{ + VOID *DeviceTreeBase; + UINT64 InitrdStart, InitrdEnd; + INT32 Len; + CONST UINT64 *Prop; + INT32 ChosenNode; + + DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddr= ess); + ASSERT (DeviceTreeBase !=3D NULL); + + Blob->Size =3D 0; + + // + // Make sure we have a valid device tree blob + // + ASSERT (fdt_check_header (DeviceTreeBase) =3D=3D 0); + + // + // Find chosen node + // + ChosenNode =3D fdt_path_offset (DeviceTreeBase, "/chosen"); + if (ChosenNode < 0) { + return EFI_NOT_FOUND; + } + + switch (Blob->Name[0]) { + case 'k': + Prop =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,kernel-star= t", &Len); + if ((Prop =3D=3D NULL) || (Len < 0)) { + return EFI_NOT_FOUND; + } + + Blob->Data =3D (UINT8 *)fdt64_to_cpu (ReadUnaligned64 (Prop)); + Prop =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,kerne= l-size", &Len); + if ((Prop =3D=3D NULL) || (Len < 0)) { + return EFI_SUCCESS; + } + + Blob->Size =3D fdt64_to_cpu (ReadUnaligned64 (Prop)); + break; + case 'i': + Prop =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,initrd-star= t", &Len); + if ((Prop =3D=3D NULL) || (Len < 0)) { + return EFI_SUCCESS; + } + + InitrdStart =3D fdt64_to_cpu (ReadUnaligned64 (Prop)); + Blob->Data =3D (UINT8 *)InitrdStart; + Prop =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,init= rd-end", &Len); + if ((Prop =3D=3D NULL) || (Len < 0)) { + return EFI_SUCCESS; + } + + InitrdEnd =3D fdt64_to_cpu (ReadUnaligned64 (Prop)); + Blob->Size =3D InitrdEnd - InitrdStart; + break; + case 'c': + Prop =3D fdt_getprop (DeviceTreeBase, ChosenNode, "bootargs", &Len); + if ((Prop =3D=3D NULL) || (Len < 0)) { + return EFI_SUCCESS; + } + + Blob->Data =3D (UINT8 *)Prop; + Blob->Size =3D Len; + break; + default: + return EFI_SUCCESS; + } + + return EFI_SUCCESS; +} + +// +// The entry point of the feature. +// + +/** + Download the kernel, the initial ramdisk, and the kernel command line fr= om + memory or DT. Construct a minimal SimpleFileSystem that contains the two + image files. + + @param ImageHandle Image handle. + @param SystemTable EFI system table. + + @return Error codes from any of the underlying + functions. On success, the function doesn't + return. +**/ +EFI_STATUS +EFIAPI +CloudHvKernelLoaderFsDxeEntrypoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + UINTN BlobType; + KERNEL_BLOB *CurrentBlob; + KERNEL_BLOB *KernelBlob; + EFI_STATUS Status; + EFI_HANDLE FileSystemHandle; + EFI_HANDLE InitrdLoadFile2Handle; + + 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; + } + + Status =3D VerifyBlob ( + CurrentBlob->Name, + CurrentBlob->Data, + CurrentBlob->Size + ); + 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, + &mFileSystemDevicePath, + &gEfiSimpleFileSystemProtocolGuid, + &mFileSystem, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: InstallMultipleProtocolInterfaces(): %r\n", + __FUNCTION__, + Status + )); + goto FreeBlobs; + } + + if (KernelBlob[KernelBlobTypeInitrd].Size > 0) { + InitrdLoadFile2Handle =3D NULL; + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &InitrdLoadFile2Handle, + &gEfiDevicePathProtocolGuid, + &mInitrdDevicePath, + &gEfiLoadFile2ProtocolGuid, + &mInitrdLoadFile2, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: InstallMultipleProtocolInterfaces(): %r\n", + __FUNCTION__, + Status + )); + goto UninstallFileSystemHandle; + } + } + + return EFI_SUCCESS; + +UninstallFileSystemHandle: + Status =3D gBS->UninstallMultipleProtocolInterfaces ( + FileSystemHandle, + &gEfiDevicePathProtocolGuid, + &mFileSystemDevicePath, + &gEfiSimpleFileSystemProtocolGuid, + &mFileSystem, + NULL + ); + ASSERT_EFI_ERROR (Status); + +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/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.i= nf b/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf new file mode 100644 index 0000000000..b7aa6ebb4e --- /dev/null +++ b/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf @@ -0,0 +1,56 @@ +## @file +# DXE driver to expose the 'kernel', 'initrd' and 'cmdline' blobs +# provided by Cloud Hypervisor as files in an abstract file system +# +# Copyright (C) 2022, Arm, Limited. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D CloudHvKernelLoaderFsDxe + FILE_GUID =3D 57cdf541-2a29-4ae4-97e5-76a4aa2fe090 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D CloudHvKernelLoaderFsDxeEntrypoint + +[Sources] + CloudHvKernelLoaderFsDxe.c + +[Packages] + ArmVirtPkg/ArmVirtPkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DevicePathLib + FdtLib + MemoryAllocationLib + PcdLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiRuntimeServicesTableLib + +[Guids] + gEfiFileInfoGuid + gEfiFileSystemInfoGuid + gEfiFileSystemVolumeLabelInfoIdGuid + gQemuKernelLoaderFsMediaGuid + +[Protocols] + gEfiDevicePathProtocolGuid ## PRODUCES + gEfiLoadFile2ProtocolGuid ## PRODUCES + gEfiSimpleFileSystemProtocolGuid ## PRODUCES + +[Depex] + gEfiRealTimeClockArchProtocolGuid + +[FixedPcd] + gArmVirtTokenSpaceGuid.PcdDeviceTreeInitialBaseAddress --=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 (#93883): https://edk2.groups.io/g/devel/message/93883 Mute This Topic: https://groups.io/mt/93715216/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 Apr 18 23:21:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+93884+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93884+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1663296398; cv=none; d=zohomail.com; s=zohoarc; b=kNqzrwAoOSpxKBufi0uy1HHtBr7Z9aIVD0pTEBUfZSUakr7jGEvz0KfHfPEVua4SrmDlgVI8x9FRO6UMFg6p37wMpDOuIX/RON1RZ9TdaTq5V2tCzdA718CsWzNcv44HVGPWCOjqti06tu1k/l85WRPPtiEG5ORvVIw/6uesaFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663296398; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=BcEAQW3ZBmSu77waO/XC8Fmsmm+X/pynszoFmp9STm0=; b=jHgoS86C/IFZ/iDseBvvpV+O9zeiX9x/JzeSzUe92C7wiLngC4QQA9bFLn1McMJgXyGNiNLA7e1CMdxGIm1SqY4z7DtSoFUELabmAbLXzXCRQFJSQLLfjhOyd2mFuqG45u5f4vZZvuKYYF4Stk9+g54azre9JqjWHNYJ4ps6XCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93884+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1663296398537358.1893267797444; Thu, 15 Sep 2022 19:46:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HyNVYY1788612xjhhfFe9gaK; Thu, 15 Sep 2022 19:46:38 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.1796.1663296397395455513 for ; Thu, 15 Sep 2022 19:46:37 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6CC77ED1; Thu, 15 Sep 2022 19:46:43 -0700 (PDT) X-Received: from entos-thunderx2-desktop.shanghai.arm.com (entos-thunderx2-desktop.shanghai.arm.com [10.169.212.232]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 301273F71A; Thu, 15 Sep 2022 19:46:34 -0700 (PDT) From: "Jianyong Wu" To: devel@edk2.groups.io, Sami.Mujawar@arm.com Cc: ardb+tianocore@kernel.org, justin.he@arm.com, jianyong.wu@arm.com Subject: [edk2-devel] [PATCH 2/3] CloudHv:arm: build hob for kernel image memory as read-only Date: Fri, 16 Sep 2022 10:46:19 +0800 Message-Id: <20220916024620.114084-3-jianyong.wu@arm.com> In-Reply-To: <20220916024620.114084-1-jianyong.wu@arm.com> References: <20220916024620.114084-1-jianyong.wu@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,jianyong.wu@arm.com X-Gm-Message-State: oXeGcWDT0V6n7Gp0gV4eKzpJx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1663296398; bh=FfEsJ57ge/gBMb5alVeBGvAebk6rGUwJbMYX53oVJ/w=; h=Cc:Date:From:Reply-To:Subject:To; b=R+SNEE8wgquwfW8RMX/6RxQUnBUtpaIZdWUMGf0oSh1W1WSdGAbwJ6Cuw7lo1SK/nq4 dm8nXgMVby4rywhd24Mq2qCiZzDkIkqAvCDPUlGIiYZ9a1drUU0CPhwOAIlM6eDYBf/of sM5i4oyYjlLnP84XI0Drk9if7kgOsw+5Flg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1663296400544100009 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As we use memory to pass kernel image, the memory region where kernel image locates should be added into hob as read-only. Signed-off-by: Jianyong Wu --- .../CloudHvVirtMemInfoLib.c | 66 +++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib= .c b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c index 28a0c0b078..d9b7d51a16 100644 --- a/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c +++ b/ArmVirtPkg/Library/CloudHvVirtMemInfoLib/CloudHvVirtMemInfoLib.c @@ -37,13 +37,14 @@ CloudHvVirtMemInfoPeiLibConstructor ( ) { VOID *DeviceTreeBase; - EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; + EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes, ReadOnlyResourceAttribu= tes; INT32 Node, Prev; UINT64 FirMemNodeBase, FirMemNodeSize; - UINT64 CurBase, MemBase; + UINT64 CurBase, MemBase, CurSizeOff; UINT64 CurSize; + UINT64 KernelStart, KernelSize; CONST CHAR8 *Type; - INT32 Len; + INT32 Len, ChosenNode; CONST UINT64 *RegProp; RETURN_STATUS PcdStatus; UINT8 Index; @@ -53,6 +54,8 @@ CloudHvVirtMemInfoPeiLibConstructor ( FirMemNodeBase =3D 0; FirMemNodeSize =3D 0; Index =3D 0; + CurSizeOff =3D 0; + KernelSize =3D 0; MemBase =3D FixedPcdGet64 (PcdSystemMemoryBase); ResourceAttributes =3D ( EFI_RESOURCE_ATTRIBUTE_PRESENT | @@ -60,6 +63,12 @@ CloudHvVirtMemInfoPeiLibConstructor ( EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | EFI_RESOURCE_ATTRIBUTE_TESTED ); + ReadOnlyResourceAttributes =3D ( + EFI_RESOURCE_ATTRIBUTE_PRESENT | + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | + EFI_RESOURCE_ATTRIBUTE_TESTED | + EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED + ); DeviceTreeBase =3D (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddr= ess); if (DeviceTreeBase =3D=3D NULL) { return EFI_NOT_FOUND; @@ -72,6 +81,21 @@ CloudHvVirtMemInfoPeiLibConstructor ( return EFI_NOT_FOUND; } =20 + // + // Try to get kernel image info from DT + // + ChosenNode =3D fdt_path_offset (DeviceTreeBase, "/chosen"); + if (ChosenNode >=3D 0) { + RegProp =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,kernel-sta= rt", &Len); + if ((RegProp !=3D NULL) && (Len > 0)) { + KernelStart =3D (UINT64)fdt64_to_cpu (ReadUnaligned64 (RegProp)); + RegProp =3D fdt_getprop (DeviceTreeBase, ChosenNode, "linux,kern= el-size", &Len); + if ((RegProp !=3D NULL) && (Len > 0)) { + KernelSize =3D (UINT64)fdt64_to_cpu (ReadUnaligned64 (RegProp)); + } + } + } + // // Look for the lowest memory node // @@ -105,11 +129,26 @@ CloudHvVirtMemInfoPeiLibConstructor ( =20 // We should build Hob seperately for the memory node except the f= irst one if (CurBase !=3D MemBase) { + // If kernel image resides in current memory node, build hob fro= m CurBase to the beginning of kernel image. + if ((KernelSize !=3D 0) && (KernelStart >=3D CurBase) && (Kernel= Start + KernelSize <=3D CurBase + CurSize)) { + CurSizeOff =3D CurBase + CurSize - KernelStart; + // align up with 0x1000 + CurSizeOff =3D (CurSizeOff + 0xfff) & ~0xfffUL; + } + BuildResourceDescriptorHob ( EFI_RESOURCE_SYSTEM_MEMORY, ResourceAttributes, CurBase, - CurSize + CurSize - CurSizeOff + ); + + // Add kernel image memory region to hob as read only + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ReadOnlyResourceAttributes, + CurBase + CurSize - CurSizeOff, + CurSizeOff ); } else { FirMemNodeBase =3D CurBase; @@ -146,8 +185,27 @@ CloudHvVirtMemInfoPeiLibConstructor ( return EFI_NOT_FOUND; } =20 + CurSizeOff =3D 0; + // Build hob for the lowest memory node from its base to the beginning o= f kernel image once the kernel image reside here + if ((KernelSize !=3D 0) && (KernelStart >=3D FirMemNodeBase) && (KernelS= tart + KernelSize <=3D FirMemNodeBase + FirMemNodeSize)) { + CurSizeOff =3D FirMemNodeBase + FirMemNodeSize - KernelStart; + // Caution the alignment + CurSizeOff =3D (CurSizeOff + 0xfff) & ~0xfffUL; + + // Add kernel image memory region to hob as read only + BuildResourceDescriptorHob ( + EFI_RESOURCE_SYSTEM_MEMORY, + ReadOnlyResourceAttributes, + FirMemNodeBase + FirMemNodeSize - CurSizeOff, + CurSizeOff + ); + } + + FirMemNodeSize -=3D CurSizeOff; + PcdStatus =3D PcdSet64S (PcdSystemMemorySize, FirMemNodeSize); ASSERT_RETURN_ERROR (PcdStatus); + ASSERT ( (((UINT64)PcdGet64 (PcdFdBaseAddress) + (UINT64)PcdGet32 (PcdFdSize)) <=3D FirMemNodeBase) || --=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 (#93884): https://edk2.groups.io/g/devel/message/93884 Mute This Topic: https://groups.io/mt/93715217/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 Apr 18 23:21:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+93885+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93885+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1663296400; cv=none; d=zohomail.com; s=zohoarc; b=NXRo8zUSj1VZ08TKuc0EJuukf/5/6/bauB31+Z0KgQkMCbtZBMCqH1VPOPdomnrUmogL5yAQYQIjwt0Dck1X4MweODizqISgwBzSgJPYq4pRcK5c5UReLOjnjM93f4gFR/2FcCufde/CUdgdzcxD/RFyhTeOQEPDjXfQIPOqDnk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1663296400; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=z3Vv0nwnpqvhdQLvZpw5cwcWfh4U2P9aELR7rQPX0RI=; b=OVP27+Bq+XD7nEWjqz3BihqdzPIyTBOM8b+C4OV/RAl/TX4yujMxD/+AF2BjIyS3Z6gw3IiH3SI/n/NLqVXjR37RJ9t/wpWLLBX5VTtO0MijkTla02d5pFbGOWrvHmWp818gIZldHo1YuLyCIdqDVPxZ6jSGqVjB12CDMzsGeHs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+93885+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1663296400521854.4296320888409; Thu, 15 Sep 2022 19:46:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id F2fyYY1788612xRJcO96s06u; Thu, 15 Sep 2022 19:46:40 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.1788.1663296399614472368 for ; Thu, 15 Sep 2022 19:46:39 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BA41C1FCD; Thu, 15 Sep 2022 19:46:45 -0700 (PDT) X-Received: from entos-thunderx2-desktop.shanghai.arm.com (entos-thunderx2-desktop.shanghai.arm.com [10.169.212.232]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7D94D3F71A; Thu, 15 Sep 2022 19:46:37 -0700 (PDT) From: "Jianyong Wu" To: devel@edk2.groups.io, Sami.Mujawar@arm.com Cc: ardb+tianocore@kernel.org, justin.he@arm.com, jianyong.wu@arm.com Subject: [edk2-devel] [PATCH 3/3] CloudHv:arm: add kernel load driver into dsc/fdf Date: Fri, 16 Sep 2022 10:46:20 +0800 Message-Id: <20220916024620.114084-4-jianyong.wu@arm.com> In-Reply-To: <20220916024620.114084-1-jianyong.wu@arm.com> References: <20220916024620.114084-1-jianyong.wu@arm.com> Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,jianyong.wu@arm.com X-Gm-Message-State: eQ8a7kJtzXgCzY1IMOWowhhfx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1663296400; bh=olWS4qakJ4kmgrVvminy5ISFkBY5md+ag6yVTMBY3As=; h=Cc:Date:From:Reply-To:Subject:To; b=H7JXPhBMUjwwwCNj1OG1MZD9Qdog26Hal7XgpIQ6xKVPK93jVE5oHxSGcVwmmQ1bmkh v6QMo52Pz4Yiec+gwv03sYMe2Pm5dyDYZc1HMRRLZD6sA+ETq4fY3R3PO4r5v3z2glPZE TdrVtyvYUnfjRGILU3NLyAD5doJqwq4JEYo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1663296402522100013 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" As CloudHv kernel load fs driver is implemented, add it into dsc/fdf. Signed-off-by: Jianyong Wu --- ArmVirtPkg/ArmVirtCloudHv.dsc | 8 +++++++- ArmVirtPkg/ArmVirtCloudHv.fdf | 1 + .../CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index 7ca7a391d9..92ccd4ef12 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -37,13 +37,15 @@ # Virtio Support VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf + QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibMmio.inf + QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf =20 ArmPlatformLib|ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibN= ull.inf =20 TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf - PlatformBootManagerLib|ArmPkg/Library/PlatformBootManagerLib/PlatformBoo= tManagerLib.inf + PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/Platfor= mBootManagerLib.inf PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrin= tScLib.inf CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf @@ -330,6 +332,10 @@ NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanc= eManagerUiLib.inf } + ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf { + + NULL|OvmfPkg/Library/BlobVerifierLibNull/BlobVerifierLibNull.inf + } =20 # # SCSI Bus and Disk Driver diff --git a/ArmVirtPkg/ArmVirtCloudHv.fdf b/ArmVirtPkg/ArmVirtCloudHv.fdf index 81c539590a..15b9c13c59 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.fdf +++ b/ArmVirtPkg/ArmVirtCloudHv.fdf @@ -180,6 +180,7 @@ READ_LOCK_STATUS =3D TRUE INF MdeModulePkg/Universal/DriverHealthManagerDxe/DriverHealthManagerDxe= .inf INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf INF MdeModulePkg/Application/UiApp/UiApp.inf + INF ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf =20 # # SCSI Bus and Disk Driver diff --git a/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.i= nf b/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf index b7aa6ebb4e..f7b53d0747 100644 --- a/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf +++ b/ArmVirtPkg/CloudHvKernelLoaderFsDxe/CloudHvKernelLoaderFsDxe.inf @@ -24,7 +24,6 @@ EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec - UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec =20 [LibraryClasses] BaseLib --=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 (#93885): https://edk2.groups.io/g/devel/message/93885 Mute This Topic: https://groups.io/mt/93715218/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-