iPXE
Functions
efi_file.h File Reference

EFI file protocols. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efi_file_install (EFI_HANDLE handle)
 Install EFI simple file system protocol. More...
 
void efi_file_uninstall (EFI_HANDLE handle)
 Uninstall EFI simple file system protocol. More...
 

Detailed Description

EFI file protocols.

Definition in file efi_file.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_file_install()

int efi_file_install ( EFI_HANDLE  handle)

Install EFI simple file system protocol.

Parameters
handleEFI handle
Return values
rcReturn status code

Definition at line 1115 of file efi_file.c.

1115  {
1117  EFI_DISK_IO_PROTOCOL *diskio;
1118  struct image *image;
1119  EFI_STATUS efirc;
1120  int rc;
1121 
1122  /* Reset root directory state */
1123  efi_file_root.pos = 0;
1124 
1125  /* Install the simple file system protocol, block I/O
1126  * protocol, and disk I/O protocol. We don't have a block
1127  * device, but large parts of the EDK2 codebase make the
1128  * assumption that file systems are normally attached to block
1129  * devices, and so we create a dummy block device on the same
1130  * handle just to keep things looking normal.
1131  */
1132  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1133  &handle,
1139  &efi_simple_file_system_protocol, NULL ) ) != 0 ) {
1140  rc = -EEFI ( efirc );
1141  DBGC ( handle, "Could not install simple file system "
1142  "protocols: %s\n", strerror ( rc ) );
1143  goto err_install;
1144  }
1145 
1146  /* The FAT filesystem driver has a bug: if a block device
1147  * contains no FAT filesystem but does have an
1148  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instance, the FAT driver
1149  * will assume that it must have previously installed the
1150  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. This causes the FAT
1151  * driver to claim control of our device, and to refuse to
1152  * stop driving it, which prevents us from later uninstalling
1153  * correctly.
1154  *
1155  * Work around this bug by opening the disk I/O protocol
1156  * ourselves, thereby preventing the FAT driver from opening
1157  * it.
1158  *
1159  * Note that the alternative approach of opening the block I/O
1160  * protocol (and thereby in theory preventing DiskIo from
1161  * attaching to the block I/O protocol) causes an endless loop
1162  * of calls to our DRIVER_STOP method when starting the EFI
1163  * shell. I have no idea why this is.
1164  */
1166  &diskio ) ) != 0 ) {
1167  DBGC ( handle, "Could not open disk I/O protocol: %s\n",
1168  strerror ( rc ) );
1170  goto err_open;
1171  }
1172  assert ( diskio == &efi_disk_io_protocol );
1173 
1174  /* Claim Linux initrd fixed device path */
1175  if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 )
1176  goto err_initrd_claim;
1177 
1178  /* Install Linux initrd fixed device path file if non-empty */
1179  for_each_image ( image ) {
1180  if ( image->flags & IMAGE_HIDDEN )
1181  continue;
1182  if ( ( rc = efi_file_path_install ( &efi_file_initrd ) ) != 0 )
1183  goto err_initrd_install;
1184  break;
1185  }
1186 
1187  return 0;
1188 
1190  err_initrd_install:
1191  err_initrd_claim:
1193  err_open:
1195  handle,
1202  err_install:
1203  return rc;
1204 }
unsigned int flags
Flags.
Definition: image.h:39
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
static int efi_file_path_install(struct efi_file_path *file)
Install fixed device path file.
Definition: efi_file.c:1038
static void efi_file_path_uninstall(struct efi_file_path *file)
Uninstall fixed device path file.
Definition: efi_file.c:1070
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:928
#define DBGC(...)
Definition: compiler.h:505
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2009
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:344
An executable image.
Definition: image.h:23
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:960
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:188
size_t pos
Current file position.
Definition: efi_file.c:87
static struct efi_file_path efi_file_initrd
Magic initrd file.
Definition: efi_file.c:108
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:278
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:336
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition: efi.h:473
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:107
This protocol is used to abstract Block I/O interfaces.
Definition: DiskIo.h:100
#define for_each_image(image)
Iterate over all registered images.
Definition: image.h:190
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
Definition: image.h:85
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2010
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:144
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
static int efi_file_path_claim(struct efi_file_path *file)
Claim use of fixed device path.
Definition: efi_file.c:981
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:874
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), EFI_SYSTEM_TABLE::BootServices, DBGC, DBGC_EFI_OPENERS, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_close_by_driver(), efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_file_initrd, efi_file_path_claim(), efi_file_path_install(), efi_file_path_uninstall(), efi_file_root, efi_open_by_driver, efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, image::flags, for_each_image, handle, IMAGE_HIDDEN, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, efi_file::pos, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

◆ efi_file_uninstall()

void efi_file_uninstall ( EFI_HANDLE  handle)

Uninstall EFI simple file system protocol.

Parameters
handleEFI handle

Definition at line 1211 of file efi_file.c.

1211  {
1213  EFI_STATUS efirc;
1214  int rc;
1215 
1216  /* Uninstall Linux initrd fixed device path file */
1218 
1219  /* Close our own disk I/O protocol */
1221 
1222  /* We must install the file system protocol first, since
1223  * otherwise the EDK2 code will attempt to helpfully uninstall
1224  * it when the block I/O protocol is uninstalled, leading to a
1225  * system lock-up.
1226  */
1227  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1228  handle,
1234  &efi_block_io_protocol, NULL ) ) != 0 ) {
1235  rc = -EEFI ( efirc );
1236  DBGC ( handle, "Could not uninstall simple file system "
1237  "protocols: %s\n", strerror ( rc ) );
1238  /* Oh dear */
1239  }
1240 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
static void efi_file_path_uninstall(struct efi_file_path *file)
Uninstall fixed device path file.
Definition: efi_file.c:1070
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:928
#define DBGC(...)
Definition: compiler.h:505
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:960
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:188
static struct efi_file_path efi_file_initrd
Magic initrd file.
Definition: efi_file.c:108
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition: efi_open.c:278
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:336
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2010
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:144
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:874
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_close_by_driver(), efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_file_initrd, efi_file_path_uninstall(), efi_simple_file_system_protocol, efi_simple_file_system_protocol_guid, efi_systab, handle, NULL, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().