TianoCore EDK2 master
|
#include <PiDxe.h>
#include <Guid/FileInfo.h>
#include <Guid/FileSystemInfo.h>
#include <Guid/FileSystemVolumeLabelInfo.h>
#include <Guid/LinuxEfiInitrdMedia.h>
#include <Guid/QemuKernelLoaderFsMedia.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BlobVerifierLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/QemuFwCfgLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/DevicePath.h>
#include <Protocol/LoadFile2.h>
#include <Protocol/SimpleFileSystem.h>
Go to the source code of this file.
Data Structures | |
struct | KERNEL_BLOB |
struct | SINGLE_VENMEDIA_NODE_DEVPATH |
struct | STUB_FILE |
Macros | |
#define | STUB_FILE_SIG SIGNATURE_64 ('S', 'T', 'U', 'B', 'F', 'I', 'L', 'E') |
#define | STUB_FILE_FROM_FILE(FilePointer) CR (FilePointer, STUB_FILE, File, STUB_FILE_SIG) |
Enumerations | |
enum | KERNEL_BLOB_TYPE { KernelBlobTypeKernel , KernelBlobTypeInitrd , KernelBlobTypeCommandLine , KernelBlobTypeMax } |
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
Definition in file QemuKernelLoaderFsDxe.c.
Definition at line 130 of file QemuKernelLoaderFsDxe.c.
#define STUB_FILE_SIG SIGNATURE_64 ('S', 'T', 'U', 'B', 'F', 'I', 'L', 'E') |
Definition at line 115 of file QemuKernelLoaderFsDxe.c.
enum KERNEL_BLOB_TYPE |
Definition at line 34 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS ConvertKernelBlobTypeToFileInfo | ( | IN KERNEL_BLOB_TYPE | BlobType, |
IN OUT UINTN * | BufferSize, | ||
OUT VOID * | Buffer | ||
) |
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.
[in] | BlobType | The KERNEL_BLOB_TYPE value identifying the fw_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. |
[in,out] | BufferSize | On input, the size of Buffer. On output, the amount of data returned in Buffer. In both cases, the size is measured in bytes. |
[out] | Buffer | A pointer to the data buffer to return. The buffer's type is EFI_FILE_INFO. |
EFI_SUCCESS | The information was returned. |
EFI_BUFFER_TOO_SMALL | BufferSize is too small to store the EFI_FILE_INFO structure. BufferSize has been updated with the size needed to complete the request. |
Definition at line 260 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS FetchBlob | ( | IN OUT KERNEL_BLOB * | Blob | ) |
Populate a blob in mKernelBlob.
param[in,out] Blob Pointer to the KERNEL_BLOB element in mKernelBlob that is to be filled from fw_cfg.
EFI_SUCCESS | Blob has been populated. If fw_cfg reported a size of zero for the blob, then Blob->Data has been left unchanged. |
EFI_OUT_OF_RESOURCES | Failed to allocate memory for Blob->Data. |
Definition at line 937 of file QemuKernelLoaderFsDxe.c.
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 | ||
) |
Definition at line 878 of file QemuKernelLoaderFsDxe.c.
EFI_STATUS EFIAPI QemuKernelLoaderFsDxeEntrypoint | ( | IN EFI_HANDLE | ImageHandle, |
IN EFI_SYSTEM_TABLE * | SystemTable | ||
) |
Download the kernel, the initial ramdisk, and the kernel command line from QEMU's fw_cfg. Construct a minimal SimpleFileSystem that contains the two image files.
EFI_NOT_FOUND | Kernel image was not found. |
EFI_OUT_OF_RESOURCES | Memory allocation failed. |
EFI_PROTOCOL_ERROR | Unterminated kernel command line. |
Definition at line 1036 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileClose | ( | IN EFI_FILE_PROTOCOL * | This | ) |
Closes a specified file handle.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to close. |
EFI_SUCCESS | The file was closed. |
Definition at line 199 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileDelete | ( | IN EFI_FILE_PROTOCOL * | This | ) |
Close and delete the file handle.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the handle to the file to delete. |
EFI_SUCCESS | The file was closed and deleted, and the handle was closed. |
EFI_WARN_DELETE_FAILURE | The handle was closed, but the file was not deleted. |
Definition at line 222 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileFlush | ( | IN EFI_FILE_PROTOCOL * | This | ) |
Flushes all modified data associated with a file to a device.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to flush. |
EFI_SUCCESS | The data was flushed. |
EFI_NO_MEDIA | The device has no medium. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
EFI_WRITE_PROTECTED | The file or medium is write-protected. |
EFI_ACCESS_DENIED | The file was opened read-only. |
EFI_VOLUME_FULL | The volume is full. |
Definition at line 715 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileGetInfo | ( | IN EFI_FILE_PROTOCOL * | This, |
IN EFI_GUID * | InformationType, | ||
IN OUT UINTN * | BufferSize, | ||
OUT VOID * | Buffer | ||
) |
Returns information about a file.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle the requested information is for. |
[in] | InformationType | The type identifier GUID for the information being requested. The following information types are supported, storing the corresponding structures in Buffer: |
[in,out] | BufferSize | On input, the size of Buffer. On output, the amount of data returned in Buffer. In both cases, the size is measured in bytes. |
[out] | Buffer | A pointer to the data buffer to return. The buffer's type is indicated by InformationType. |
EFI_SUCCESS | The information was returned. |
EFI_UNSUPPORTED | The InformationType is not known. |
EFI_NO_MEDIA | The device has no medium. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
EFI_BUFFER_TOO_SMALL | The BufferSize is too small to store the information structure requested by InformationType. BufferSize has been updated with the size needed to complete the request. |
Definition at line 586 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileGetPosition | ( | IN EFI_FILE_PROTOCOL * | This, |
OUT UINT64 * | Position | ||
) |
Returns a file's current position.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to get the current position on. |
[out] | Position | The address to return the file's current position value. |
EFI_SUCCESS | The position was returned. |
EFI_UNSUPPORTED | The request is not valid on open directories. |
EFI_DEVICE_ERROR | An attempt was made to get the position from a deleted file. |
Definition at line 469 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileOpen | ( | IN EFI_FILE_PROTOCOL * | This, |
OUT EFI_FILE_PROTOCOL ** | NewHandle, | ||
IN CHAR16 * | FileName, | ||
IN UINT64 | OpenMode, | ||
IN UINT64 | Attributes | ||
) |
Opens a new file relative to the source file's location.
(Forward declaration.)
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to the source location. This would typically be an open handle to a directory. |
[out] | NewHandle | A pointer to the location to return the opened handle for the new file. |
[in] | FileName | The Null-terminated string of the name of the file to be opened. The file name may contain the following path modifiers: "\", ".", and "..". |
[in] | OpenMode | The mode to open the file. The only valid combinations that the file may be opened with are: Read, Read/Write, or Create/Read/Write. |
[in] | Attributes | Only valid for EFI_FILE_MODE_CREATE, in which case these are the attribute bits for the newly created file. |
EFI_SUCCESS | The file was opened. |
EFI_NOT_FOUND | The specified file could not be found on the device. |
EFI_NO_MEDIA | The device has no medium. |
EFI_MEDIA_CHANGED | The device has a different medium in it or the medium is no longer supported. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
EFI_WRITE_PROTECTED | An attempt was made to create a file, or open a file for write when the media is write-protected. |
EFI_ACCESS_DENIED | The service denied access to the file. |
EFI_OUT_OF_RESOURCES | Not enough resources were available to open the file. |
EFI_VOLUME_FULL | The volume is full. |
Definition at line 746 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileRead | ( | IN EFI_FILE_PROTOCOL * | This, |
IN OUT UINTN * | BufferSize, | ||
OUT VOID * | Buffer | ||
) |
Reads data from a file, or continues scanning a directory.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to read data from. |
[in,out] | BufferSize | On input, the size of the Buffer. On output, the amount of data returned in Buffer. In both cases, the size is measured in bytes. If the read goes 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 Buffer. If there are no more directory entries, the BufferSize is set to zero on output.
[out] | Buffer | The buffer into which the data is read. |
EFI_SUCCESS | Data was read. |
EFI_NO_MEDIA | The device has no medium. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_DEVICE_ERROR | An attempt was made to read from a deleted file. |
EFI_DEVICE_ERROR | On entry, the current file position is beyond the end of the file. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
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 with the size needed to complete the request, and the directory position has not been advanced. |
Definition at line 352 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileSetInfo | ( | IN EFI_FILE_PROTOCOL * | This, |
IN EFI_GUID * | InformationType, | ||
IN UINTN | BufferSize, | ||
IN VOID * | Buffer | ||
) |
Sets information about a file.
[in] | File | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle the information is for. |
[in] | InformationType | The type identifier for the information being set. |
[in] | BufferSize | The size, in bytes, of Buffer. |
[in] | Buffer | A pointer to the data buffer to write. The buffer's type is indicated by InformationType. |
EFI_SUCCESS | The information was set. |
EFI_UNSUPPORTED | The InformationType is not known. |
EFI_NO_MEDIA | The device has no medium. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
EFI_WRITE_PROTECTED | InformationType is EFI_FILE_INFO_ID and the media is read-only. |
EFI_WRITE_PROTECTED | InformationType is EFI_FILE_PROTOCOL_SYSTEM_INFO_ID and the media is read only. |
EFI_WRITE_PROTECTED | InformationType is EFI_FILE_SYSTEM_VOLUME_LABEL_ID and the media is read-only. |
EFI_ACCESS_DENIED | An attempt is made to change the name of a file to a file that is already present. |
EFI_ACCESS_DENIED | An attempt is being made to change the EFI_FILE_DIRECTORY Attribute. |
EFI_ACCESS_DENIED | An attempt is being made to change the size of a directory. |
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. |
EFI_VOLUME_FULL | The volume is full. |
EFI_BAD_BUFFER_SIZE | BufferSize is smaller than the size of the type indicated by InformationType. |
Definition at line 688 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileSetPosition | ( | IN EFI_FILE_PROTOCOL * | This, |
IN UINT64 | Position | ||
) |
Sets a file's current position.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to set the requested position on. |
[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". |
EFI_SUCCESS | The position was set. |
EFI_UNSUPPORTED | The seek request for nonzero is not valid on open directories. |
EFI_DEVICE_ERROR | An attempt was made to set the position of a deleted file. |
Definition at line 504 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileSystemOpenVolume | ( | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * | This, |
OUT EFI_FILE_PROTOCOL ** | Root | ||
) |
Open the root directory on a volume.
[in] | This | A pointer to the volume to open the root directory on. |
[out] | Root | A pointer to the location to return the opened file handle for the root directory in. |
EFI_SUCCESS | The device was opened. |
EFI_UNSUPPORTED | This volume does not support the requested file system type. |
EFI_NO_MEDIA | The device has no medium. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
EFI_ACCESS_DENIED | The service denied access to the file. |
EFI_OUT_OF_RESOURCES | The volume was not opened due to lack of resources. |
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 medium, the volume must be reopened with OpenVolume(). |
Definition at line 845 of file QemuKernelLoaderFsDxe.c.
STATIC EFI_STATUS EFIAPI StubFileWrite | ( | IN EFI_FILE_PROTOCOL * | This, |
IN OUT UINTN * | BufferSize, | ||
IN VOID * | Buffer | ||
) |
Writes data to a file.
[in] | This | A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to write data to. |
[in,out] | BufferSize | On input, the size of the Buffer. On output, the amount of data actually written. In both cases, the size is measured in bytes. |
[in] | Buffer | The buffer of data to write. |
EFI_SUCCESS | Data was written. |
EFI_UNSUPPORTED | Writes to open directory files are not supported. |
EFI_NO_MEDIA | The device has no medium. |
EFI_DEVICE_ERROR | The device reported an error. |
EFI_DEVICE_ERROR | An attempt was made to write to a deleted file. |
EFI_VOLUME_CORRUPTED | The file system structures are corrupted. |
EFI_WRITE_PROTECTED | The file or medium is write-protected. |
EFI_ACCESS_DENIED | The file was opened read only. |
EFI_VOLUME_FULL | The volume is full. |
Definition at line 438 of file QemuKernelLoaderFsDxe.c.
STATIC CONST EFI_FILE_PROTOCOL mEfiFileProtocolTemplate |
Definition at line 725 of file QemuKernelLoaderFsDxe.c.
STATIC CONST EFI_SIMPLE_FILE_SYSTEM_PROTOCOL mFileSystem |
Definition at line 870 of file QemuKernelLoaderFsDxe.c.
STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mFileSystemDevicePath |
Definition at line 84 of file QemuKernelLoaderFsDxe.c.
STATIC CONST SINGLE_VENMEDIA_NODE_DEVPATH mInitrdDevicePath |
Definition at line 97 of file QemuKernelLoaderFsDxe.c.
STATIC CONST EFI_LOAD_FILE2_PROTOCOL mInitrdLoadFile2 |
Definition at line 915 of file QemuKernelLoaderFsDxe.c.
Definition at line 113 of file QemuKernelLoaderFsDxe.c.
STATIC KERNEL_BLOB mKernelBlob[KernelBlobTypeMax] |
Definition at line 52 of file QemuKernelLoaderFsDxe.c.
STATIC UINT64 mTotalBlobBytes |
Definition at line 72 of file QemuKernelLoaderFsDxe.c.