iPXE
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)
 FILE_SECBOOT (PERMITTED)
int efi_file_install (EFI_HANDLE handle)
 Install EFI simple file system protocol.
void efi_file_uninstall (EFI_HANDLE handle)
 Uninstall EFI simple file system protocol.

Detailed Description

EFI file protocols.

Definition in file efi_file.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

References EFI_HANDLE, and handle.

◆ efi_file_install()

int efi_file_install ( EFI_HANDLE handle)
extern

Install EFI simple file system protocol.

Parameters
handleEFI handle
Return values
rcReturn status code

Definition at line 1116 of file efi_file.c.

1116 {
1117 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1118 EFI_DISK_IO_PROTOCOL *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,
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 */
1167 &diskio ) ) != 0 ) {
1168 DBGC ( handle, "Could not open disk I/O protocol: %s\n",
1169 strerror ( rc ) );
1171 goto err_open;
1172 }
1173 assert ( diskio == &efi_disk_io_protocol );
1174
1175 /* Claim Linux initrd fixed device path */
1176 if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 )
1177 goto err_initrd_claim;
1178
1179 /* Install Linux initrd fixed device path file if non-empty */
1180 for_each_image ( image ) {
1181 if ( image->flags & IMAGE_HIDDEN )
1182 continue;
1183 if ( ( rc = efi_file_path_install ( &efi_file_initrd ) ) != 0 )
1184 goto err_initrd_install;
1185 break;
1186 }
1187
1188 return 0;
1189
1191 err_initrd_install:
1192 err_initrd_claim:
1194 err_open:
1196 handle,
1203 err_install:
1204 return rc;
1205}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct _EFI_DISK_IO_PROTOCOL EFI_DISK_IO_PROTOCOL
Definition DiskIo.h:29
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
static EFI_SIMPLE_FILE_SYSTEM_PROTOCOL efi_simple_file_system_protocol
EFI simple file system protocol.
Definition efi_file.c:875
static void efi_file_path_uninstall(struct efi_file_path *file)
Uninstall fixed device path file.
Definition efi_file.c:1071
static EFI_BLOCK_IO_PROTOCOL efi_block_io_protocol
Dummy EFI block I/O protocol.
Definition efi_file.c:929
static int efi_file_path_install(struct efi_file_path *file)
Install fixed device path file.
Definition efi_file.c:1039
static struct efi_file_path efi_file_initrd
Magic initrd file.
Definition efi_file.c:109
static struct efi_file efi_file_root
Root directory.
Definition efi_file.c:108
static int efi_file_path_claim(struct efi_file_path *file)
Claim use of fixed device path.
Definition efi_file.c:982
static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol
Dummy EFI disk I/O protocol.
Definition efi_file.c:961
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition efi_guid.c:145
EFI_GUID efi_disk_io_protocol_guid
Disk I/O protocol GUID.
Definition efi_guid.c:189
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition efi_guid.c:337
void efi_close_by_driver(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for persistent use by a driver.
Definition efi_open.c:279
#define DBGC(...)
Definition compiler.h:505
#define for_each_image(image)
Iterate over all registered images.
Definition image.h:191
#define IMAGE_HIDDEN
Image will be hidden from enumeration.
Definition image.h:86
#define efi_open_by_driver(handle, protocol, interface)
Open protocol for persistent use by a driver.
Definition efi.h:474
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
#define DBGC_EFI_OPENERS(...)
Definition efi.h:345
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition smbios.h:5
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition UefiSpec.h:2011
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition UefiSpec.h:2010
An executable image.
Definition image.h:24
unsigned int flags
Flags.
Definition image.h:40

References assert, 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_HANDLE, 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, rc, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().

◆ efi_file_uninstall()

void efi_file_uninstall ( EFI_HANDLE handle)
extern

Uninstall EFI simple file system protocol.

Parameters
handleEFI handle

Definition at line 1212 of file efi_file.c.

1212 {
1213 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1214 EFI_STATUS efirc;
1215 int rc;
1216
1217 /* Uninstall Linux initrd fixed device path file */
1219
1220 /* Close our own disk I/O protocol */
1222
1223 /* We must install the file system protocol first, since
1224 * otherwise the EDK2 code will attempt to helpfully uninstall
1225 * it when the block I/O protocol is uninstalled, leading to a
1226 * system lock-up.
1227 */
1228 if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1229 handle,
1235 &efi_block_io_protocol, NULL ) ) != 0 ) {
1236 rc = -EEFI ( efirc );
1237 DBGC ( handle, "Could not uninstall simple file system "
1238 "protocols: %s\n", strerror ( rc ) );
1239 /* Oh dear */
1240 }
1241}

References 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_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().