56#define EFI_MEDIA_ID_MAGIC 0x69505845
59#define LINUX_INITRD_VENDOR_GUID \
60 { 0x5568e427, 0x68fc, 0x4f3d, \
61 { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } }
187 const void *
data,
size_t len ) {
263 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) pad\n",
273 name_len = ( cpio_len -
sizeof ( cpio ) );
275 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s header\n",
286 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s\n",
304 const wchar_t *wname,
313 DBGC ( file,
"EFIFILE %s opened via %ls\n",
340 const wchar_t *wname,
356 DBGC (
file,
"EFIFILE %s opened via %ls\n",
375 char buf[
wcslen ( wname ) + 1 ];
381 snprintf ( buf,
sizeof ( buf ),
"%ls", wname );
385 while ( *
name ==
'\\' ) {
391 while ( ( *
name ==
'\\' ) || ( *
name ==
'.' ) )
400 DBGC ( file,
"EFIFILE %s is not a directory\n",
407 DBGC ( file,
"EFIFILE %s cannot be opened in mode %#08llx\n",
432 DBGC ( file,
"EFIFILE %ls does not exist\n", wname );
486 *
base = ( base_len + ( name_len + 1 ) *
sizeof (
wchar_t ) );
519 info.FileSize = file_len;
520 info.PhysicalSize = file_len;
594 DBGC (
file,
"EFIFILE %s read [%#08zx,%#08zx)\n",
614 DBGC (
file,
"EFIFILE %s cannot write [%#08zx, %#08zx)\n",
616 ( (
size_t ) (
file->pos + *
len ) ) );
636 if ( position == 0xffffffffffffffffULL )
642 if ( position >
len ) {
643 DBGC (
file,
"EFIFILE %s cannot seek to %#08llx of %#08zx\n",
649 file->pos = position;
650 DBGC (
file,
"EFIFILE %s position set to %#08zx\n",
667 *position =
file->pos;
691 DBGC ( file,
"EFIFILE %s get file information\n",
696 sizeof ( *
type ) ) == 0 ) {
699 DBGC ( file,
"EFIFILE %s get file system information\n",
701 memset ( &fsinfo, 0,
sizeof ( fsinfo ) );
710 DBGC ( file,
"EFIFILE %s cannot get information of type %s\n",
730 DBGC (
file,
"EFIFILE %s cannot set information of type %s\n",
772 DBGC (
file,
"EFIFILE %s load at %p+%#zx\n",
777 if ( file_len > max_len ) {
853 .name =
"initrd.magic",
885 ( extended ?
"extended " :
"" ) );
895 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
907 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
923 .MediaPresent =
TRUE,
944 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
955 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
1004 DBGC (
file,
"EFIFILE %s could not locate %s: %s\n",
1016 DBGC (
file,
"EFIFILE %s could not claim %s: %s\n",
1022 DBGC (
file,
"EFIFILE %s claimed %s",
1054 DBGC (
file,
"EFIFILE %s could not install %s: %s\n",
1060 DBGC (
file,
"EFIFILE %s installed as %s\n",
1077 if ( !
file->handle )
1089 DBGC (
file,
"EFIFILE %s could not uninstall %s: %s\n",
1099 DBGC (
file,
"EFIFILE %s could not uninstall %s: %s\n",
1142 DBGC (
handle,
"Could not install simple file system "
1167 &diskio ) ) != 0 ) {
1168 DBGC (
handle,
"Could not open disk I/O protocol: %s\n",
1177 goto err_initrd_claim;
1184 goto err_initrd_install;
1237 DBGC (
handle,
"Could not uninstall simple file system "
unsigned char BOOLEAN
Logical Boolean.
UINT64 UINTN
Unsigned value of native width.
unsigned long long UINT64
8-byte unsigned value.
unsigned short CHAR16
2-byte Character.
unsigned int UINT32
4-byte unsigned value.
#define NULL
NULL pointer (VOID *)
#define VOID
Undeclared type.
Block IO protocol as defined in the UEFI 2.0 specification.
#define EFI_BLOCK_IO_PROTOCOL_REVISION
struct _EFI_BLOCK_IO_PROTOCOL EFI_BLOCK_IO_PROTOCOL
#define MEDIA_DEVICE_PATH
#define END_ENTIRE_DEVICE_PATH_SUBTYPE
#define END_DEVICE_PATH_TYPE
#define MEDIA_VENDOR_DP
Media vendor device path subtype.
Disk IO protocol as defined in the UEFI 2.0 specification.
#define EFI_DISK_IO_PROTOCOL_REVISION
struct _EFI_DISK_IO_PROTOCOL EFI_DISK_IO_PROTOCOL
Provides a GUID and a data structure that can be used with EFI_FILE_PROTOCOL.SetInfo() and EFI_FILE_P...
#define SIZE_OF_EFI_FILE_INFO
The FileName field of the EFI_FILE_INFO data structure is variable length.
Provides a GUID and a data structure that can be used with EFI_FILE_PROTOCOL.GetInfo() or EFI_FILE_PR...
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
The VolumeLabel field of the EFI_FILE_SYSTEM_INFO data structure is variable length.
Load File protocol as defined in the UEFI 2.0 specification.
struct _EFI_LOAD_FILE2_PROTOCOL EFI_LOAD_FILE2_PROTOCOL
SimpleFileSystem protocol as defined in the UEFI 2.0 specification.
struct _EFI_FILE_PROTOCOL EFI_FILE_PROTOCOL
struct _EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
#define EFI_FILE_PROTOCOL_REVISION
#define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
#define EFI_FILE_DIRECTORY
#define EFI_FILE_MODE_READ
#define EFI_FILE_READ_ONLY
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
UINT64 EFI_LBA
Logical block address.
#define EFI_WRITE_PROTECTED
Enumeration of EFI_STATUS.
#define EFI_NO_MEDIA
Enumeration of EFI_STATUS.
#define EFI_NOT_FOUND
Enumeration of EFI_STATUS.
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
#define EFI_BUFFER_TOO_SMALL
Enumeration of EFI_STATUS.
#define EFI_OUT_OF_RESOURCES
Enumeration of EFI_STATUS.
#define EFI_WARN_DELETE_FAILURE
Enumeration of EFI_STATUS.
struct arbelprm_rc_send_wqe rc
#define assert(condition)
Assert a condition at run-time.
uint16_t offset
Offset to command line.
size_t cpio_header(struct image *image, unsigned int index, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
static size_t cpio_pad_len(size_t len)
Get CPIO header zero-padding length.
static const char * cpio_name(struct image *image)
Get CPIO image name.
static unsigned short vendor
static EFI_STATUS EFIAPI efi_block_io_reset(EFI_BLOCK_IO_PROTOCOL *block_io, BOOLEAN verify __unused)
Reset EFI block device.
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
static EFI_STATUS EFIAPI efi_file_read(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data)
Read from file.
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.
static size_t efi_file_read_image(struct efi_file_reader *reader)
Read from image-backed file.
static EFI_STATUS EFIAPI efi_file_open_volume(EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *filesystem __unused, EFI_FILE_PROTOCOL **file)
Open root directory.
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
static void efi_file_image(struct efi_file *file, struct image *image)
Associate file with image.
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 EFI_STATUS EFIAPI efi_block_io_reset(EFI_BLOCK_IO_PROTOCOL *this __unused, BOOLEAN extended)
Dummy block I/O reset.
static void efi_file_path_uninstall(struct efi_file_path *file)
Uninstall fixed device path file.
static EFI_STATUS EFIAPI efi_file_delete(EFI_FILE_PROTOCOL *this)
Close and delete file.
static EFI_STATUS EFIAPI efi_file_get_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN *len, VOID *data)
Get file information.
static EFI_STATUS efi_file_info(struct efi_file *file, UINTN *len, VOID *data)
Return file information structure.
static size_t efi_file_len(struct efi_file *file)
Get length of EFI file.
static size_t efi_file_read_chunk(struct efi_file_reader *reader, const void *data, size_t len)
Read chunk of EFI file.
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.
static EFI_BLOCK_IO_MEDIA efi_block_io_media
Dummy block I/O media.
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
static int efi_file_path_install(struct efi_file_path *file)
Install fixed device path file.
static EFI_STATUS efi_file_open_image(struct image *image, const wchar_t *wname, EFI_FILE_PROTOCOL **new)
Open image-backed file.
static struct efi_file_path efi_file_initrd
Magic initrd file.
#define LINUX_INITRD_VENDOR_GUID
Linux initrd fixed device path vendor GUID.
static void efi_file_free(struct refcnt *refcnt)
Free EFI file.
static EFI_STATUS EFIAPI efi_file_set_info(EFI_FILE_PROTOCOL *this, EFI_GUID *type, UINTN len __unused, VOID *data __unused)
Set file information.
int efi_file_install(EFI_HANDLE handle)
Install EFI simple file system protocol.
static EFI_STATUS EFIAPI efi_file_open(EFI_FILE_PROTOCOL *this, EFI_FILE_PROTOCOL **new, CHAR16 *wname, UINT64 mode, UINT64 attributes __unused)
Open file.
static EFI_STATUS efi_file_read_dir(struct efi_file *file, UINTN *len, VOID *data)
Read directory entry.
void efi_file_uninstall(EFI_HANDLE handle)
Uninstall EFI simple file system protocol.
static struct efi_file efi_file_root
Root directory.
static struct image * efi_file_find(const char *name)
Find EFI file image.
static EFI_STATUS EFIAPI efi_block_io_flush_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused)
Dummy block I/O flush.
static int efi_file_path_claim(struct efi_file_path *file)
Claim use of fixed device path.
static EFI_STATUS EFIAPI efi_file_write(EFI_FILE_PROTOCOL *this, UINTN *len, VOID *data __unused)
Write to file.
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_MEDIA_ID_MAGIC
EFI media ID.
static EFI_STATUS efi_file_open_fixed(struct efi_file *file, const wchar_t *wname, EFI_FILE_PROTOCOL **new)
Open fixed file.
static struct @155172135212117201227002307145202243102020027056 efi_file_initrd_path
Linux initrd fixed device path.
static const char * efi_file_name(struct efi_file *file)
Get EFI file name (for debugging)
static EFI_STATUS EFIAPI efi_file_flush(EFI_FILE_PROTOCOL *this)
Flush file modified data.
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.
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
static EFI_STATUS EFIAPI efi_file_set_position(EFI_FILE_PROTOCOL *this, UINT64 position)
Set file position.
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.
static EFI_STATUS EFIAPI efi_file_close(EFI_FILE_PROTOCOL *this)
Close file.
static EFI_STATUS EFIAPI efi_file_get_position(EFI_FILE_PROTOCOL *this, UINT64 *position)
Get file position.
static size_t efi_file_read_initrd(struct efi_file_reader *reader)
Read from magic initrd file.
EFI_GUID efi_load_file2_protocol_guid
Load file 2 protocol GUID.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
EFI_GUID efi_file_system_info_id
File system information GUID.
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
EFI_GUID efi_file_info_id
File information GUID.
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
int efi_snprintf(wchar_t *wbuf, size_t wsize, const char *fmt,...)
Write a formatted string to a buffer.
uint8_t filesystem
System type.
uint32_t type
Operating system type.
uint8_t data[48]
Additional event data.
uint16_t mode
Acceleration mode.
#define __unused
Declare a variable or data structure as unused.
uint64_t lba
Starting block number.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
struct image * find_image_tag(struct image_tag *tag)
Find image by tag.
static struct image * image_get(struct image *image)
Increment reference count on an image.
static void image_put(struct image *image)
Decrement reference count on an image.
#define for_each_image(image)
Iterate over all registered images.
struct image_tag selected_image
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
#define DBGC_EFI_OPENERS(...)
EFI_SYSTEM_TABLE * efi_systab
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
Initial ramdisk (initrd) reshuffling.
#define INITRD_ALIGN
Initial ramdisk chunk alignment.
void * zalloc(size_t size)
Allocate cleared memory.
uint32_t end
Ending offset.
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
static void(* free)(struct refcnt *refcnt))
#define REF_INIT(free_fn)
Initialise a static reference counter.
#define ref_get(refcnt)
Get additional reference to object.
#define ref_put(refcnt)
Drop reference to object.
#define ref_init(refcnt, free)
Initialise a reference counter.
#define container_of(ptr, type, field)
Get containing structure.
char * strerror(int errno)
Retrieve string representation of error number.
int strncasecmp(const char *first, const char *second, size_t max)
Compare case-insensitive strings.
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
char * strrchr(const char *src, int character)
Find rightmost character within a string.
size_t strlen(const char *src)
Get length of string.
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
EFI_LOCATE_DEVICE_PATH LocateDevicePath
This protocol can be used on any device handle to obtain generic path/location information concerning...
BOOLEAN ReadOnly
TRUE if the volume only supports read access.
UINT64 VolumeSize
The number of bytes managed by the file system.
UINT64 Size
The size of the EFI_FILE_SYSTEM_INFO structure, including the Null-terminated VolumeLabel string.
The Vendor Device Path allows the creation of vendor-defined Device Paths.
An EFI fixed device path file.
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
struct efi_file file
EFI file.
EFI_HANDLE handle
EFI handle.
An EFI virtual file reader.
struct efi_file * file
EFI file.
size_t len
Length of output data buffer.
void * data
Output data buffer.
size_t pos
Position within virtual file.
size_t(* read)(struct efi_file_reader *reader)
Read from file.
const char * name
Filename.
EFI_FILE_PROTOCOL file
EFI file protocol.
struct refcnt refcnt
Reference count.
EFI_LOAD_FILE2_PROTOCOL load
EFI load file protocol.
struct image * image
Image (if any)
size_t pos
Current file position.
const void * data
Read-only data.
size_t len
Length of raw file image.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
size_t wcslen(const wchar_t *string)
Calculate length of wide-character string.