54 #define EFI_MEDIA_ID_MAGIC 0x69505845 57 #define LINUX_INITRD_VENDOR_GUID \ 58 { 0x5568e427, 0x68fc, 0x4f3d, \ 59 { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } } 261 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) pad\n",
271 name_len = ( cpio_len -
sizeof ( cpio ) );
273 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s header\n",
287 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s\n",
305 const wchar_t *wname,
314 DBGC ( file,
"EFIFILE %s opened via %ls\n",
341 const wchar_t *wname,
357 DBGC (
file,
"EFIFILE %s opened via %ls\n",
376 char buf[
wcslen ( wname ) + 1 ];
382 snprintf ( buf,
sizeof ( buf ),
"%ls", wname );
386 while ( *
name ==
'\\' ) {
392 if ( (
name[0] ==
'\0' ) || (
name[0] ==
'.' ) )
397 DBGC ( file,
"EFIFILE %s is not a directory\n",
404 DBGC ( file,
"EFIFILE %s cannot be opened in mode %#08llx\n",
429 DBGC ( file,
"EFIFILE %ls does not exist\n", wname );
483 *
base = ( base_len + ( name_len + 1 ) *
sizeof (
wchar_t ) );
516 info.FileSize = file_len;
517 info.PhysicalSize = file_len;
591 DBGC (
file,
"EFIFILE %s read [%#08zx,%#08zx)\n",
611 DBGC (
file,
"EFIFILE %s cannot write [%#08zx, %#08zx)\n",
613 ( (
size_t ) (
file->pos + *
len ) ) );
633 if ( position == 0xffffffffffffffffULL )
639 if ( position >
len ) {
640 DBGC (
file,
"EFIFILE %s cannot seek to %#08llx of %#08zx\n",
646 file->pos = position;
647 DBGC (
file,
"EFIFILE %s position set to %#08zx\n",
664 *position =
file->pos;
688 DBGC ( file,
"EFIFILE %s get file information\n",
693 sizeof ( *
type ) ) == 0 ) {
696 DBGC ( file,
"EFIFILE %s get file system information\n",
698 memset ( &fsinfo, 0,
sizeof ( fsinfo ) );
707 DBGC ( file,
"EFIFILE %s cannot get information of type %s\n",
727 DBGC (
file,
"EFIFILE %s cannot set information of type %s\n",
769 DBGC (
file,
"EFIFILE %s load at %p+%#zx\n",
774 if ( file_len > max_len ) {
850 .name =
"initrd.magic",
882 ( extended ?
"extended " :
"" ) );
892 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
904 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
920 .MediaPresent =
TRUE,
941 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
952 "%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",
1144 DBGC (
handle,
"Could not install simple file system " 1173 DBGC (
handle,
"Could not open disk I/O protocol: %s\n",
1182 goto err_initrd_claim;
1189 goto err_initrd_install;
1244 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.
userptr_t data
Raw file image.
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.
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.
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 __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
static struct image * image_get(struct image *image)
Increment reference count on an image.
This protocol provides control over block devices.
#define EFI_OPEN_PROTOCOL_BY_DRIVER
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
EFI_CLOSE_PROTOCOL CloseProtocol
#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.
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.
static struct @429 efi_file_initrd_path
Linux initrd fixed device path.
uint32_t userptr_t
A pointer to a user buffer.
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.
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.
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.
EFI_HANDLE_PROTOCOL HandleProtocol
#define EFI_DISK_IO_PROTOCOL_REVISION
static size_t efi_file_read_chunk(struct efi_file_reader *reader, userptr_t data, size_t len)
Read chunk of EFI file.
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.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
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.
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
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.
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.
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
#define INITRD_ALIGN
Alignment for CPIO archives within an initrd.
#define EFI_NOT_FOUND
Enumeration of EFI_STATUS.
#define UNULL
Equivalent of NULL for user pointers.
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)
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
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.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
UINT8 Type
0x01 Hardware Device Path.
uint16_t offset
Offset to command line.
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
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.
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.