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  union {
1118  EFI_DISK_IO_PROTOCOL *diskio;
1119  void *interface;
1120  } diskio;
1121  struct image *image;
1122  EFI_STATUS efirc;
1123  int rc;
1124 
1125  /* Reset root directory state */
1126  efi_file_root.pos = 0;
1127 
1128  /* Install the simple file system protocol, block I/O
1129  * protocol, and disk I/O protocol. We don't have a block
1130  * device, but large parts of the EDK2 codebase make the
1131  * assumption that file systems are normally attached to block
1132  * devices, and so we create a dummy block device on the same
1133  * handle just to keep things looking normal.
1134  */
1135  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1136  &handle,
1142  &efi_simple_file_system_protocol, NULL ) ) != 0 ) {
1143  rc = -EEFI ( efirc );
1144  DBGC ( handle, "Could not install simple file system "
1145  "protocols: %s\n", strerror ( rc ) );
1146  goto err_install;
1147  }
1148 
1149  /* The FAT filesystem driver has a bug: if a block device
1150  * contains no FAT filesystem but does have an
1151  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instance, the FAT driver
1152  * will assume that it must have previously installed the
1153  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. This causes the FAT
1154  * driver to claim control of our device, and to refuse to
1155  * stop driving it, which prevents us from later uninstalling
1156  * correctly.
1157  *
1158  * Work around this bug by opening the disk I/O protocol
1159  * ourselves, thereby preventing the FAT driver from opening
1160  * it.
1161  *
1162  * Note that the alternative approach of opening the block I/O
1163  * protocol (and thereby in theory preventing DiskIo from
1164  * attaching to the block I/O protocol) causes an endless loop
1165  * of calls to our DRIVER_STOP method when starting the EFI
1166  * shell. I have no idea why this is.
1167  */
1168  if ( ( efirc = bs->OpenProtocol ( handle, &efi_disk_io_protocol_guid,
1169  &diskio.interface, efi_image_handle,
1170  handle,
1171  EFI_OPEN_PROTOCOL_BY_DRIVER ) ) != 0){
1172  rc = -EEFI ( efirc );
1173  DBGC ( handle, "Could not open disk I/O protocol: %s\n",
1174  strerror ( rc ) );
1176  goto err_open;
1177  }
1178  assert ( diskio.diskio == &efi_disk_io_protocol );
1179 
1180  /* Claim Linux initrd fixed device path */
1181  if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 )
1182  goto err_initrd_claim;
1183 
1184  /* Install Linux initrd fixed device path file if non-empty */
1185  for_each_image ( image ) {
1186  if ( image->flags & IMAGE_HIDDEN )
1187  continue;
1188  if ( ( rc = efi_file_path_install ( &efi_file_initrd ) ) != 0 )
1189  goto err_initrd_install;
1190  break;
1191  }
1192 
1193  return 0;
1194 
1196  err_initrd_install:
1197  err_initrd_claim:
1200  err_open:
1202  handle,
1209  err_install:
1210  return rc;
1211 }
unsigned int flags
Flags.
Definition: image.h:36
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:171
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:926
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1357
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:2009
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:322
An executable image.
Definition: image.h:24
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:958
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:164
size_t pos
Current file position.
Definition: efi_file.c:86
static struct efi_file_path efi_file_initrd
Magic initrd file.
Definition: efi_file.c:107
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:124
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:304
static struct efi_file efi_file_root
Root directory.
Definition: efi_file.c:106
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:172
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
Definition: image.h:73
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:120
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1999
static int efi_file_path_claim(struct efi_file_path *file)
Claim use of fixed device path.
Definition: efi_file.c:979
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:872
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, DBGC_EFI_OPENERS, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, 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_image_handle, EFI_OPEN_PROTOCOL_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_BOOT_SERVICES::OpenProtocol, 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 1218 of file efi_file.c.

1218  {
1220  EFI_STATUS efirc;
1221  int rc;
1222 
1223  /* Uninstall Linux initrd fixed device path file */
1225 
1226  /* Close our own disk I/O protocol */
1229 
1230  /* We must install the file system protocol first, since
1231  * otherwise the EDK2 code will attempt to helpfully uninstall
1232  * it when the block I/O protocol is uninstalled, leading to a
1233  * system lock-up.
1234  */
1235  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1236  handle,
1242  &efi_block_io_protocol, NULL ) ) != 0 ) {
1243  rc = -EEFI ( efirc );
1244  DBGC ( handle, "Could not uninstall simple file system "
1245  "protocols: %s\n", strerror ( rc ) );
1246  /* Oh dear */
1247  }
1248 }
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:171
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:926
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:2000
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:958
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:164
static struct efi_file_path efi_file_initrd
Magic initrd file.
Definition: efi_file.c:107
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:304
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1930
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:34
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:120
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:872
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseProtocol, DBGC, EEFI, efi_block_io_protocol, efi_block_io_protocol_guid, efi_disk_io_protocol, efi_disk_io_protocol_guid, efi_file_initrd, efi_file_path_uninstall(), efi_image_handle, 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().