55 #define EFI_MEDIA_ID_MAGIC 0x69505845 58 #define LINUX_INITRD_VENDOR_GUID \ 59 { 0x5568e427, 0x68fc, 0x4f3d, \ 60 { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } } 186 const void *
data,
size_t len ) {
262 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) pad\n",
272 name_len = ( cpio_len -
sizeof ( cpio ) );
274 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s header\n",
285 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s\n",
303 const wchar_t *wname,
312 DBGC ( file,
"EFIFILE %s opened via %ls\n",
339 const wchar_t *wname,
355 DBGC (
file,
"EFIFILE %s opened via %ls\n",
374 char buf[
wcslen ( wname ) + 1 ];
380 snprintf ( buf,
sizeof ( buf ),
"%ls", wname );
384 while ( *
name ==
'\\' ) {
390 while ( ( *
name ==
'\\' ) || ( *
name ==
'.' ) )
399 DBGC ( file,
"EFIFILE %s is not a directory\n",
406 DBGC ( file,
"EFIFILE %s cannot be opened in mode %#08llx\n",
431 DBGC ( file,
"EFIFILE %ls does not exist\n", wname );
485 *
base = ( base_len + ( name_len + 1 ) *
sizeof (
wchar_t ) );
518 info.FileSize = file_len;
519 info.PhysicalSize = file_len;
593 DBGC (
file,
"EFIFILE %s read [%#08zx,%#08zx)\n",
613 DBGC (
file,
"EFIFILE %s cannot write [%#08zx, %#08zx)\n",
615 ( (
size_t ) (
file->pos + *
len ) ) );
635 if ( position == 0xffffffffffffffffULL )
641 if ( position >
len ) {
642 DBGC (
file,
"EFIFILE %s cannot seek to %#08llx of %#08zx\n",
648 file->pos = position;
649 DBGC (
file,
"EFIFILE %s position set to %#08zx\n",
666 *position =
file->pos;
690 DBGC ( file,
"EFIFILE %s get file information\n",
695 sizeof ( *
type ) ) == 0 ) {
698 DBGC ( file,
"EFIFILE %s get file system information\n",
700 memset ( &fsinfo, 0,
sizeof ( fsinfo ) );
709 DBGC ( file,
"EFIFILE %s cannot get information of type %s\n",
729 DBGC (
file,
"EFIFILE %s cannot set information of type %s\n",
771 DBGC (
file,
"EFIFILE %s load at %p+%#zx\n",
776 if ( file_len > max_len ) {
852 .name =
"initrd.magic",
884 ( extended ?
"extended " :
"" ) );
894 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
906 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
922 .MediaPresent =
TRUE,
943 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
954 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
1003 DBGC (
file,
"EFIFILE %s could not locate %s: %s\n",
1015 DBGC (
file,
"EFIFILE %s could not claim %s: %s\n",
1021 DBGC (
file,
"EFIFILE %s claimed %s",
1053 DBGC (
file,
"EFIFILE %s could not install %s: %s\n",
1059 DBGC (
file,
"EFIFILE %s installed as %s\n",
1076 if ( !
file->handle )
1088 DBGC (
file,
"EFIFILE %s could not uninstall %s: %s\n",
1098 DBGC (
file,
"EFIFILE %s could not uninstall %s: %s\n",
1141 DBGC (
handle,
"Could not install simple file system " 1166 &diskio ) ) != 0 ) {
1167 DBGC (
handle,
"Could not open disk I/O protocol: %s\n",
1176 goto err_initrd_claim;
1183 goto err_initrd_install;
1236 DBGC (
handle,
"Could not uninstall simple file system " VENDOR_DEVICE_PATH vendor
static EFI_STATUS EFIAPI efi_file_set_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN len __unused, VOID *data __unused)
Set file information.
static EFI_STATUS EFIAPI efi_disk_io_read_disk(EFI_DISK_IO_PROTOCOL *this __unused, UINT32 MediaId, UINT64 offset, UINTN len, VOID *data)
Dummy disk I/O read.
void * data
Output data buffer.
struct image_tag selected_image
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
static void efi_file_free(struct refcnt *refcnt)
Free EFI file.
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
struct refcnt refcnt
Reference count.
struct arbelprm_rc_send_wqe rc
static EFI_STATUS EFIAPI efi_file_open(EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new, CHAR16 *wname, UINT64 mode, UINT64 attributes __unused)
Open file.
BOOLEAN ReadOnly
TRUE if the volume only supports read access.
An EFI virtual file reader.
static EFI_STATUS EFIAPI efi_file_get_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN *len, VOID *data)
Get file information.
UINT64 Revision
The version of the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
static EFI_STATUS EFIAPI efi_file_get_position(EFI_FILE_PROTOCOL *this, UINT64 *position)
Get file position.
static int efi_file_path_install(struct efi_file_path *file)
Install fixed device path file.
#define END_DEVICE_PATH_TYPE
char * strrchr(const char *src, int character)
Find rightmost character within a string.
EFI_GUID efi_file_system_info_id
File system information GUID.
128 bit buffer containing a unique identifier value.
#define ref_init(refcnt, free)
Initialise a reference counter.
const void * data
Read-only data.
static EFI_STATUS efi_file_open_image(struct image *image, const wchar_t *wname, EFI_FILE_PROTOCOL **new)
Open image-backed file.
static void efi_file_path_uninstall(struct efi_file_path *file)
Uninstall fixed device path file.
uint16_t mode
Acceleration mode.
Disk IO protocol as defined in the UEFI 2.0 specification.
uint32_t type
Operating system type.
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
static struct image * image_get(struct image *image)
Increment reference count on an image.
This protocol provides control over block devices.
static struct @437 efi_file_initrd_path
Linux initrd fixed device path.
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
void efi_file_uninstall(EFI_HANDLE handle)
Uninstall EFI simple file system protocol.
static EFI_STATUS EFIAPI efi_file_read(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data)
Read from file.
int strncasecmp(const char *first, const char *second, size_t max)
Compare case-insensitive strings.
#define DBGC_EFI_OPENERS(...)
This protocol can be used on any device handle to obtain generic path/location information concerning...
#define EFI_FILE_READ_ONLY
static EFI_STATUS EFIAPI efi_block_io_read_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused, UINT32 MediaId, EFI_LBA lba, UINTN len, VOID *data)
Dummy block I/O read.
#define EFI_BUFFER_TOO_SMALL
Enumeration of EFI_STATUS.
EFI_FILE_PROTOCOL file
EFI file protocol.
#define EFI_FILE_DIRECTORY
#define SIZE_OF_EFI_FILE_INFO
The FileName field of the EFI_FILE_INFO data structure is variable length.
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
static size_t cpio_pad_len(size_t len)
Get CPIO header zero-padding length.
static EFI_STATUS EFIAPI efi_file_load(EFI_LOAD_FILE2_PROTOCOL *this, EFI_DEVICE_PATH_PROTOCOL *path __unused, BOOLEAN boot __unused, UINTN *len, VOID *data)
Load file.
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
size_t wcslen(const wchar_t *string)
Calculate length of wide-character string.
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
#define INITRD_ALIGN
Initial ramdisk chunk alignment.
static size_t efi_file_len(struct efi_file *file)
Get length of EFI file.
int efi_file_install(EFI_HANDLE handle)
Install EFI simple file system protocol.
static EFI_STATUS EFIAPI efi_disk_io_write_disk(EFI_DISK_IO_PROTOCOL *this __unused, UINT32 MediaId, UINT64 offset, UINTN len, VOID *data)
Dummy disk I/O write.
struct image * find_image_tag(struct image_tag *tag)
Find image by tag.
static size_t efi_file_read_image(struct efi_file_reader *reader)
Read from image-backed file.
static EFI_STATUS efi_file_info(struct efi_file *file, UINTN *len, VOID *data)
Return file information structure.
#define MEDIA_VENDOR_DP
Media vendor device path subtype.
size_t pos
Current file position.
struct efi_file * file
EFI file.
static EFI_STATUS EFIAPI efi_file_open_volume(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *filesystem __unused, EFI_FILE_PROTOCOL **file)
Open root directory.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
size_t cpio_header(struct image *image, unsigned int index, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
size_t len
Length of output data buffer.
static struct efi_file_path efi_file_initrd
Magic initrd file.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
SimpleFileSystem protocol as defined in the UEFI 2.0 specification.
static EFI_STATUS efi_file_open_fixed(struct efi_file *file, const wchar_t *wname, EFI_FILE_PROTOCOL **new)
Open fixed file.
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
UINT64 EFI_LBA
Logical block address.
#define __unused
Declare a variable or data structure as unused.
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
The Vendor Device Path allows the creation of vendor-defined Device Paths.
static struct efi_file efi_file_root
Root directory.
int efi_snprintf(wchar_t *wbuf, size_t wsize, const char *fmt,...)
Write a formatted string to a buffer.
#define EFI_DISK_IO_PROTOCOL_REVISION
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
uint8_t filesystem
System type.
This protocol is used to abstract Block I/O interfaces.
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
static EFI_STATUS EFIAPI efi_file_set_position(EFI_FILE_PROTOCOL *this, UINT64 position)
Set file position.
#define EFI_WRITE_PROTECTED
Enumeration of EFI_STATUS.
#define LINUX_INITRD_VENDOR_GUID
Linux initrd fixed device path vendor GUID.
#define for_each_image(image)
Iterate over all registered images.
char * strerror(int errno)
Retrieve string representation of error number.
static EFI_STATUS efi_file_varlen(UINT64 *base, size_t base_len, const char *name, UINTN *len, VOID *data)
Return variable-length data structure.
static void(* free)(struct refcnt *refcnt))
EFI_GUID efi_load_file2_protocol_guid
Load file 2 protocol GUID.
void * zalloc(size_t size)
Allocate cleared memory.
size_t len
Length of raw file image.
#define ref_get(refcnt)
Get additional reference to object.
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
static EFI_STATUS EFIAPI efi_file_close(EFI_FILE_PROTOCOL *this)
Close file.
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
size_t strlen(const char *src)
Get length of string.
uint64_t lba
Starting block number.
static void image_put(struct image *image)
Decrement reference count on an image.
static EFI_STATUS EFIAPI efi_file_flush(EFI_FILE_PROTOCOL *this)
Flush file modified data.
#define MEDIA_DEVICE_PATH
UINT64 UINTN
Unsigned value of native width.
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
UINT64 VolumeSize
The number of bytes managed by the file system.
static EFI_STATUS EFIAPI efi_block_io_write_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused, UINT32 MediaId, EFI_LBA lba, UINTN len, VOID *data)
Dummy block I/O write.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
static EFI_STATUS EFIAPI efi_file_write(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data __unused)
Write to file.
#define VOID
Undeclared type.
unsigned long long UINT64
Provides a GUID and a data structure that can be used with EFI_FILE_PROTOCOL.SetInfo() and EFI_FILE_P...
#define EFI_FILE_PROTOCOL_REVISION
#define EFI_WARN_DELETE_FAILURE
Enumeration of EFI_STATUS.
EFI_DEVICE_PATH_PROTOCOL end
#define EFI_MEDIA_ID_MAGIC
EFI media ID.
EFI_HANDLE handle
EFI handle.
static EFI_STATUS efi_file_read_dir(struct efi_file *file, UINTN *len, VOID *data)
Read directory entry.
size_t pos
Position within virtual file.
EFI_LOAD_FILE2_PROTOCOL load
EFI load file protocol.
static EFI_STATUS EFIAPI efi_file_delete(EFI_FILE_PROTOCOL *this)
Close and delete file.
#define END_ENTIRE_DEVICE_PATH_SUBTYPE
Initial ramdisk (initrd) reshuffling.
#define EFI_NOT_FOUND
Enumeration of EFI_STATUS.
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
EFI_GUID efi_file_info_id
File information GUID.
#define EFI_FILE_MODE_READ
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
Block IO protocol as defined in the UEFI 2.0 specification.
uint8_t data[48]
Additional event data.
struct image * image
Image (if any)
#define REF_INIT(free_fn)
Initialise a static reference counter.
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
static EFI_STATUS EFIAPI efi_block_io_reset(EFI_BLOCK_IO_PROTOCOL *this __unused, BOOLEAN extended)
Dummy block I/O reset.
static size_t efi_file_read_chunk(struct efi_file_reader *reader, const void *data, size_t len)
Read chunk of EFI file.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
UINT8 Type
0x01 Hardware Device Path.
EFI_SYSTEM_TABLE * efi_systab
static int efi_file_path_claim(struct efi_file_path *file)
Claim use of fixed device path.
static EFI_STATUS EFIAPI efi_block_io_flush_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused)
Dummy block I/O flush.
UINT64 Revision
The revision to which the block IO interface adheres.
uint16_t offset
Offset to command line.
size_t(* read)(struct efi_file_reader *reader)
Read from file.
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
An EFI fixed device path file.
static size_t efi_file_read_initrd(struct efi_file_reader *reader)
Read from magic initrd file.
Load File protocol as defined in the UEFI 2.0 specification.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
#define EFI_BLOCK_IO_PROTOCOL_REVISION
UINT64 Revision
The revision to which the disk I/O interface adheres.
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
static struct image * efi_file_find(const char *name)
Find EFI file image.
#define NULL
NULL pointer (VOID *)
UINT64 Size
The size of the EFI_FILE_SYSTEM_INFO structure, including the Null-terminated VolumeLabel string.
Provides a GUID and a data structure that can be used with EFI_FILE_PROTOCOL.GetInfo() or EFI_FILE_PR...
static EFI_BLOCK_IO_MEDIA efi_block_io_media
Dummy block I/O media.
The EFI_FILE_PROTOCOL provides file IO access to supported file systems.
EFI_LOCATE_DEVICE_PATH LocateDevicePath
const char * name
Filename.
#define ref_put(refcnt)
Drop reference to object.
The EFI_LOAD_FILE_PROTOCOL is a simple protocol used to obtain files from arbitrary devices.
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
The VolumeLabel field of the EFI_FILE_SYSTEM_INFO data structure is variable length.
struct efi_file file
EFI file.
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
void * memset(void *dest, int character, size_t len) __nonnull
static const char * cpio_name(struct image *image)
Get CPIO image name.
static void efi_file_image(struct efi_file *file, struct image *image)
Associate file with image.