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 1113 of file efi_file.c.

1113  {
1115  union {
1116  EFI_DISK_IO_PROTOCOL *diskio;
1117  void *interface;
1118  } diskio;
1119  struct image *image;
1120  EFI_STATUS efirc;
1121  int rc;
1122 
1123  /* Reset root directory state */
1124  efi_file_root.pos = 0;
1125 
1126  /* Install the simple file system protocol, block I/O
1127  * protocol, and disk I/O protocol. We don't have a block
1128  * device, but large parts of the EDK2 codebase make the
1129  * assumption that file systems are normally attached to block
1130  * devices, and so we create a dummy block device on the same
1131  * handle just to keep things looking normal.
1132  */
1133  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1134  &handle,
1140  &efi_simple_file_system_protocol, NULL ) ) != 0 ) {
1141  rc = -EEFI ( efirc );
1142  DBGC ( handle, "Could not install simple file system "
1143  "protocols: %s\n", strerror ( rc ) );
1144  goto err_install;
1145  }
1146 
1147  /* The FAT filesystem driver has a bug: if a block device
1148  * contains no FAT filesystem but does have an
1149  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL instance, the FAT driver
1150  * will assume that it must have previously installed the
1151  * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL. This causes the FAT
1152  * driver to claim control of our device, and to refuse to
1153  * stop driving it, which prevents us from later uninstalling
1154  * correctly.
1155  *
1156  * Work around this bug by opening the disk I/O protocol
1157  * ourselves, thereby preventing the FAT driver from opening
1158  * it.
1159  *
1160  * Note that the alternative approach of opening the block I/O
1161  * protocol (and thereby in theory preventing DiskIo from
1162  * attaching to the block I/O protocol) causes an endless loop
1163  * of calls to our DRIVER_STOP method when starting the EFI
1164  * shell. I have no idea why this is.
1165  */
1166  if ( ( efirc = bs->OpenProtocol ( handle, &efi_disk_io_protocol_guid,
1167  &diskio.interface, efi_image_handle,
1168  handle,
1169  EFI_OPEN_PROTOCOL_BY_DRIVER ) ) != 0){
1170  rc = -EEFI ( efirc );
1171  DBGC ( handle, "Could not open disk I/O protocol: %s\n",
1172  strerror ( rc ) );
1174  goto err_open;
1175  }
1176  assert ( diskio.diskio == &efi_disk_io_protocol );
1177 
1178  /* Claim Linux initrd fixed device path */
1179  if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 )
1180  goto err_initrd_claim;
1181 
1182  /* Install Linux initrd fixed device path file if non-empty */
1183  for_each_image ( image ) {
1184  if ( image->flags & IMAGE_HIDDEN )
1185  continue;
1186  if ( ( rc = efi_file_path_install ( &efi_file_initrd ) ) != 0 )
1187  goto err_initrd_install;
1188  break;
1189  }
1190 
1191  return 0;
1192 
1194  err_initrd_install:
1195  err_initrd_claim:
1198  err_open:
1200  handle,
1207  err_install:
1208  return rc;
1209 }
unsigned int flags
Flags.
Definition: image.h:36
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:1036
static void efi_file_path_uninstall(struct efi_file_path *file)
Uninstall fixed device path file.
Definition: efi_file.c:1068
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:924
#define DBGC(...)
Definition: compiler.h:505
#define EFI_OPEN_PROTOCOL_BY_DRIVER
Definition: UefiSpec.h:1347
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1996
#define DBGC_EFI_OPENERS(...)
Definition: efi.h:321
An executable image.
Definition: image.h:24
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:956
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:163
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:303
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:1917
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:1997
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:119
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:1986
static int efi_file_path_claim(struct efi_file_path *file)
Claim use of fixed device path.
Definition: efi_file.c:977
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition: efi_file.c:870
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 1216 of file efi_file.c.

1216  {
1218  EFI_STATUS efirc;
1219  int rc;
1220 
1221  /* Uninstall Linux initrd fixed device path file */
1223 
1224  /* Close our own disk I/O protocol */
1227 
1228  /* We must install the file system protocol first, since
1229  * otherwise the EDK2 code will attempt to helpfully uninstall
1230  * it when the block I/O protocol is uninstalled, leading to a
1231  * system lock-up.
1232  */
1233  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1234  handle,
1240  &efi_block_io_protocol, NULL ) ) != 0 ) {
1241  rc = -EEFI ( efirc );
1242  DBGC ( handle, "Could not uninstall simple file system "
1243  "protocols: %s\n", strerror ( rc ) );
1244  /* Oh dear */
1245  }
1246 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:1068
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition: efi_file.c:924
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1987
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition: efi_file.c:956
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition: efi_guid.c:163
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:303
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1917
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:1997
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:119
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:870
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().