52 #define EFI_MEDIA_ID_MAGIC 0x69505845 241 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) pad\n",
252 pad_len = ( cpio_len -
sizeof ( cpio ) - name_len );
253 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s header\n",
266 DBGC ( file,
"EFIFILE %s [%#08zx,%#08zx) %s\n",
322 char buf[
wcslen ( wname ) + 1 ];
328 snprintf ( buf,
sizeof ( buf ),
"%ls", wname );
332 while ( *
name ==
'\\' ) {
338 if ( (
name[0] ==
'\0' ) || (
name[0] ==
'.' ) )
343 DBGC ( file,
"EFIFILE %s is not a directory\n",
350 DBGC ( file,
"EFIFILE %s cannot be opened in mode %#08llx\n",
362 DBGC ( file,
"EFIFILE %s does not exist\n",
name );
367 new_file =
zalloc (
sizeof ( *new_file ) );
372 sizeof ( new_file->
file ) );
374 *
new = &new_file->
file;
430 *
base = ( base_len + ( name_len + 1 ) *
sizeof (
wchar_t ) );
463 info.FileSize = file_len;
464 info.PhysicalSize = file_len;
491 if (
index-- == 0 ) {
530 DBGC (
file,
"EFIFILE %s read [%#08zx,%#08zx)\n",
550 DBGC (
file,
"EFIFILE %s cannot write [%#08zx, %#08zx)\n",
552 ( (
size_t ) (
file->pos + *
len ) ) );
572 if ( position == 0xffffffffffffffffULL )
578 if ( position >
len ) {
579 DBGC (
file,
"EFIFILE %s cannot seek to %#08llx of %#08zx\n",
585 file->pos = position;
586 DBGC (
file,
"EFIFILE %s position set to %#08zx\n",
603 *position =
file->pos;
627 DBGC ( file,
"EFIFILE %s get file information\n",
632 sizeof ( *
type ) ) == 0 ) {
635 DBGC ( file,
"EFIFILE %s get file system information\n",
637 memset ( &fsinfo, 0,
sizeof ( fsinfo ) );
646 DBGC ( file,
"EFIFILE %s cannot get information of type %s\n",
666 DBGC (
file,
"EFIFILE %s cannot set information of type %s\n",
724 .name =
"initrd.magic",
754 ( extended ?
"extended " :
"" ) );
764 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
776 "%p+%zx\n", MediaId, ( (
unsigned long long )
lba ),
792 .MediaPresent =
TRUE,
813 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
824 "%p+%zx\n", MediaId, ( (
unsigned long long )
offset ),
870 DBGC (
handle,
"Could not install simple file system " 899 DBGC (
handle,
"Could not open disk I/O protocol: %s\n",
951 DBGC (
handle,
"Could not uninstall simple file system " 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.
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
size_t cpio_name_len(struct image *image)
Get CPIO image filename.
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.
struct image * current_image
Currently-executing image.
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.
uint32_t lba
Start address.
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.
Disk IO protocol as defined in the UEFI 2.0 specification.
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.
static EFI_STATUS efi_file_open_fixed(struct efi_file *file, EFI_FILE_PROTOCOL **new)
Open fixed file.
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.
#define DBGC_EFI_OPENERS(...)
#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.
#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.
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.
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 len
Length of output data buffer.
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.
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
UINT64 EFI_LBA
Logical block address.
static userptr_t size_t offset
Offset of the first segment within the content.
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
static size_t efi_file_read_chunk(struct efi_file_reader *reader, userptr_t data, size_t len)
Read chunk of EFI file.
uint8_t filesystem
System type.
This protocol is used to abstract Block I/O interfaces.
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 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))
union aes_table_entry entry[256]
Table entries, indexed by S(N)
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.
struct list_head images
List of registered images.
static struct efi_file efi_file_initrd
Magic initrd file.
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.
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.
UINT64 UINTN
Unsigned value of native width.
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
uint16_t base
Base address.
#define EFI_WARN_DELETE_FAILURE
Enumeration of EFI_STATUS.
#define EFI_MEDIA_ID_MAGIC
EFI media ID.
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.
#define __unused
Declare a variable or data structure as unused.
static EFI_STATUS EFIAPI efi_file_delete(EFI_FILE_PROTOCOL *this)
Close and delete file.
#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.
struct image * image
Image (if any)
#define REF_INIT(free_fn)
Initialise a static reference counter.
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.
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
static EFI_STATUS EFIAPI efi_block_io_flush_blocks(EFI_BLOCK_IO_PROTOCOL *this __unused)
Dummy block I/O flush.
struct arbelprm_port_state_change_st data
Message.
UINT64 Revision
The revision to which the block IO interface adheres.
uint64_t index
Index of the first segment within the content.
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.
struct list_head list
List of registered images.
static size_t efi_file_read_initrd(struct efi_file_reader *reader)
Read from magic initrd file.
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.
const char * name
Filename.
#define ref_put(refcnt)
Drop reference to object.
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
The VolumeLabel field of the EFI_FILE_SYSTEM_INFO data structure is variable length.
unsigned long userptr_t
A pointer to a user buffer.
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
size_t cpio_header(struct image *image, struct cpio_header *cpio)
Construct CPIO header for image, if applicable.
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.