iPXE
Data Structures | Functions | Variables
efi_block.c File Reference

EFI block device protocols. More...

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ipxe/refcnt.h>
#include <ipxe/list.h>
#include <ipxe/uri.h>
#include <ipxe/interface.h>
#include <ipxe/blockdev.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/retry.h>
#include <ipxe/timer.h>
#include <ipxe/process.h>
#include <ipxe/sanboot.h>
#include <ipxe/iso9660.h>
#include <ipxe/acpi.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/Protocol/BlockIo.h>
#include <ipxe/efi/Protocol/SimpleFileSystem.h>
#include <ipxe/efi/Protocol/AcpiTable.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_strings.h>
#include <ipxe/efi/efi_snp.h>
#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_null.h>
#include <ipxe/efi/efi_block.h>

Go to the source code of this file.

Data Structures

struct  efi_block_data
 EFI SAN device private data. More...
 
struct  efi_acpi_table
 An installed ACPI table. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 EFI_REQUEST_PROTOCOL (EFI_ACPI_TABLE_PROTOCOL, &acpi)
 
static int efi_block_rw (struct san_device *sandev, uint64_t lba, void *data, size_t len, int(*sandev_rw)(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer))
 Read from or write to EFI block device. More...
 
static EFI_STATUS EFIAPI efi_block_io_reset (EFI_BLOCK_IO_PROTOCOL *block_io, BOOLEAN verify __unused)
 Reset EFI block device. More...
 
static EFI_STATUS EFIAPI efi_block_io_read (EFI_BLOCK_IO_PROTOCOL *block_io, UINT32 media __unused, EFI_LBA lba, UINTN len, VOID *data)
 Read from EFI block device. More...
 
static EFI_STATUS EFIAPI efi_block_io_write (EFI_BLOCK_IO_PROTOCOL *block_io, UINT32 media __unused, EFI_LBA lba, UINTN len, VOID *data)
 Write to EFI block device. More...
 
static EFI_STATUS EFIAPI efi_block_io_flush (EFI_BLOCK_IO_PROTOCOL *block_io)
 Flush data to EFI block device. More...
 
static void efi_block_connect (struct san_device *sandev)
 Connect all possible drivers to EFI block device. More...
 
static int efi_block_hook (unsigned int drive, struct uri **uris, unsigned int count, unsigned int flags)
 Hook EFI block device. More...
 
static void efi_block_unhook (unsigned int drive)
 Unhook EFI block device. More...
 
static LIST_HEAD (efi_acpi_tables)
 List of installed ACPI tables. More...
 
static int efi_block_install (struct acpi_header *hdr)
 Install ACPI table. More...
 
static int efi_block_describe (void)
 Describe EFI block devices. More...
 
static int efi_block_boot_image (struct san_device *sandev, EFI_HANDLE handle, const char *filename, EFI_HANDLE *image)
 Try booting from child device of EFI block device. More...
 
static int efi_block_boot (unsigned int drive, const char *filename)
 Boot from EFI block device. More...
 
 PROVIDE_SANBOOT (efi, san_hook, efi_block_hook)
 
 PROVIDE_SANBOOT (efi, san_unhook, efi_block_unhook)
 
 PROVIDE_SANBOOT (efi, san_describe, efi_block_describe)
 
 PROVIDE_SANBOOT (efi, san_boot, efi_block_boot)
 

Variables

static EFI_ACPI_TABLE_PROTOCOLacpi
 ACPI table protocol protocol. More...
 
static wchar_t efi_block_boot_filename [] = EFI_REMOVABLE_MEDIA_FILE_NAME
 Boot filename. More...
 

Detailed Description

EFI block device protocols.

Definition in file efi_block.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ EFI_REQUEST_PROTOCOL()

EFI_REQUEST_PROTOCOL ( EFI_ACPI_TABLE_PROTOCOL  ,
acpi 
)

◆ efi_block_rw()

static int efi_block_rw ( struct san_device sandev,
uint64_t  lba,
void *  data,
size_t  len,
int(*)(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer sandev_rw 
)
static

Read from or write to EFI block device.

Parameters
sandevSAN device
lbaStarting LBA
dataData buffer
lenSize of buffer
sandev_rwSAN device read/write method
Return values
rcReturn status code

Definition at line 92 of file efi_block.c.

96  {
97  struct efi_block_data *block = sandev->priv;
98  unsigned int count;
99  int rc;
100 
101  /* Sanity check */
102  count = ( len / block->media.BlockSize );
103  if ( ( count * block->media.BlockSize ) != len ) {
104  DBGC ( sandev, "EFIBLK %#02x impossible length %#zx\n",
105  sandev->drive, len );
106  return -EINVAL;
107  }
108 
109  /* Read from / write to block device */
110  if ( ( rc = sandev_rw ( sandev, lba, count,
111  virt_to_user ( data ) ) ) != 0 ) {
112  DBGC ( sandev, "EFIBLK %#02x I/O failed: %s\n",
113  sandev->drive, strerror ( rc ) );
114  return rc;
115  }
116 
117  return 0;
118 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t lba
Start address.
Definition: scsi.h:23
struct san_device * sandev
SAN device.
Definition: efi_block.c:71
static int sandev_rw(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer, int(*block_rw)(struct interface *control, struct interface *data, uint64_t lba, unsigned int count, userptr_t buffer, size_t len))
Read from or write to SAN device.
Definition: sanboot.c:587
uint16_t block
Definition: tftp.h:12
#define DBGC(...)
Definition: compiler.h:505
EFI SAN device private data.
Definition: efi_block.c:69
unsigned int drive
Drive number.
Definition: sanboot.h:54
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint32_t len
Length.
Definition: ena.h:14
void * priv
Driver private data.
Definition: sanboot.h:78
uint16_t count
Number of entries.
Definition: ena.h:22
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References block, count, data, DBGC, san_device::drive, EINVAL, lba, len, san_device::priv, rc, efi_block_data::sandev, sandev_rw(), strerror(), and virt_to_user().

Referenced by efi_block_io_read(), and efi_block_io_write().

◆ efi_block_io_reset()

static EFI_STATUS EFIAPI efi_block_io_reset ( EFI_BLOCK_IO_PROTOCOL block_io,
BOOLEAN verify  __unused 
)
static

Reset EFI block device.

Parameters
block_ioBlock I/O protocol
verifyPerform extended verification
Return values
efircEFI status code

Definition at line 127 of file efi_block.c.

128  {
129  struct efi_block_data *block =
131  struct san_device *sandev = block->sandev;
132  int rc;
133 
134  DBGC2 ( sandev, "EFIBLK %#02x reset\n", sandev->drive );
135  efi_snp_claim();
136  rc = sandev_reset ( sandev );
137  efi_snp_release();
138  return EFIRC ( rc );
139 }
int sandev_reset(struct san_device *sandev)
Reset SAN device.
Definition: sanboot.c:565
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint16_t block
Definition: tftp.h:12
EFI_BLOCK_IO_PROTOCOL block_io
Block I/O protocol.
Definition: efi_block.c:77
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition: efi_snp.h:88
EFI SAN device private data.
Definition: efi_block.c:69
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
unsigned int drive
Drive number.
Definition: sanboot.h:54
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:96
A SAN device.
Definition: sanboot.h:47
#define DBGC2(...)
Definition: compiler.h:522
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:159

References block, efi_block_data::block_io, container_of, DBGC2, san_device::drive, efi_snp_claim(), efi_snp_release(), EFIRC, rc, and sandev_reset().

Referenced by efi_block_hook().

◆ efi_block_io_read()

static EFI_STATUS EFIAPI efi_block_io_read ( EFI_BLOCK_IO_PROTOCOL block_io,
UINT32 media  __unused,
EFI_LBA  lba,
UINTN  len,
VOID data 
)
static

Read from EFI block device.

Parameters
block_ioBlock I/O protocol
mediaMedia identifier
lbaStarting LBA
lenSize of buffer
dataData buffer
Return values
efircEFI status code

Definition at line 152 of file efi_block.c.

153  {
154  struct efi_block_data *block =
156  struct san_device *sandev = block->sandev;
157  int rc;
158 
159  DBGC2 ( sandev, "EFIBLK %#02x read LBA %#08llx to %p+%#08zx\n",
160  sandev->drive, lba, data, ( ( size_t ) len ) );
161  efi_snp_claim();
162  rc = efi_block_rw ( sandev, lba, data, len, sandev_read );
163  efi_snp_release();
164  return EFIRC ( rc );
165 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t lba
Start address.
Definition: scsi.h:23
uint16_t block
Definition: tftp.h:12
EFI_BLOCK_IO_PROTOCOL block_io
Block I/O protocol.
Definition: efi_block.c:77
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition: efi_snp.h:88
static int efi_block_rw(struct san_device *sandev, uint64_t lba, void *data, size_t len, int(*sandev_rw)(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer))
Read from or write to EFI block device.
Definition: efi_block.c:92
EFI SAN device private data.
Definition: efi_block.c:69
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
unsigned int drive
Drive number.
Definition: sanboot.h:54
int sandev_read(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer)
Read from SAN device.
Definition: sanboot.c:636
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:96
A SAN device.
Definition: sanboot.h:47
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:159

References block, efi_block_data::block_io, container_of, data, DBGC2, san_device::drive, efi_block_rw(), efi_snp_claim(), efi_snp_release(), EFIRC, lba, len, rc, and sandev_read().

Referenced by efi_block_hook().

◆ efi_block_io_write()

static EFI_STATUS EFIAPI efi_block_io_write ( EFI_BLOCK_IO_PROTOCOL block_io,
UINT32 media  __unused,
EFI_LBA  lba,
UINTN  len,
VOID data 
)
static

Write to EFI block device.

Parameters
block_ioBlock I/O protocol
mediaMedia identifier
lbaStarting LBA
lenSize of buffer
dataData buffer
Return values
efircEFI status code

Definition at line 178 of file efi_block.c.

179  {
180  struct efi_block_data *block =
182  struct san_device *sandev = block->sandev;
183  int rc;
184 
185  DBGC2 ( sandev, "EFIBLK %#02x write LBA %#08llx from %p+%#08zx\n",
186  sandev->drive, lba, data, ( ( size_t ) len ) );
187  efi_snp_claim();
188  rc = efi_block_rw ( sandev, lba, data, len, sandev_write );
189  efi_snp_release();
190  return EFIRC ( rc );
191 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint32_t lba
Start address.
Definition: scsi.h:23
uint16_t block
Definition: tftp.h:12
EFI_BLOCK_IO_PROTOCOL block_io
Block I/O protocol.
Definition: efi_block.c:77
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition: efi_snp.h:88
static int efi_block_rw(struct san_device *sandev, uint64_t lba, void *data, size_t len, int(*sandev_rw)(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer))
Read from or write to EFI block device.
Definition: efi_block.c:92
EFI SAN device private data.
Definition: efi_block.c:69
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
unsigned int drive
Drive number.
Definition: sanboot.h:54
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:96
A SAN device.
Definition: sanboot.h:47
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
int sandev_write(struct san_device *sandev, uint64_t lba, unsigned int count, userptr_t buffer)
Write to SAN device.
Definition: sanboot.c:656
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:159

References block, efi_block_data::block_io, container_of, data, DBGC2, san_device::drive, efi_block_rw(), efi_snp_claim(), efi_snp_release(), EFIRC, lba, len, rc, and sandev_write().

Referenced by efi_block_hook().

◆ efi_block_io_flush()

static EFI_STATUS EFIAPI efi_block_io_flush ( EFI_BLOCK_IO_PROTOCOL block_io)
static

Flush data to EFI block device.

Parameters
block_ioBlock I/O protocol
Return values
efircEFI status code

Definition at line 200 of file efi_block.c.

200  {
201  struct efi_block_data *block =
203  struct san_device *sandev = block->sandev;
204 
205  DBGC2 ( sandev, "EFIBLK %#02x flush\n", sandev->drive );
206 
207  /* Nothing to do */
208  return 0;
209 }
uint16_t block
Definition: tftp.h:12
EFI_BLOCK_IO_PROTOCOL block_io
Block I/O protocol.
Definition: efi_block.c:77
EFI SAN device private data.
Definition: efi_block.c:69
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
unsigned int drive
Drive number.
Definition: sanboot.h:54
A SAN device.
Definition: sanboot.h:47
#define DBGC2(...)
Definition: compiler.h:522

References block, efi_block_data::block_io, container_of, DBGC2, and san_device::drive.

Referenced by efi_block_hook().

◆ efi_block_connect()

static void efi_block_connect ( struct san_device sandev)
static

Connect all possible drivers to EFI block device.

Parameters
sandevSAN device

Definition at line 216 of file efi_block.c.

216  {
218  struct efi_block_data *block = sandev->priv;
219  EFI_STATUS efirc;
220  int rc;
221 
222  /* Try to connect all possible drivers to this block device */
223  if ( ( efirc = bs->ConnectController ( block->handle, NULL,
224  NULL, TRUE ) ) != 0 ) {
225  rc = -EEFI ( efirc );
226  DBGC ( sandev, "EFIBLK %#02x could not connect drivers: %s\n",
227  sandev->drive, strerror ( rc ) );
228  /* May not be an error; may already be connected */
229  }
230  DBGC2 ( sandev, "EFIBLK %#02x supports protocols:\n", sandev->drive );
231  DBGC2_EFI_PROTOCOLS ( sandev, block->handle );
232 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:167
struct san_device * sandev
SAN device.
Definition: efi_block.c:71
uint16_t block
Definition: tftp.h:12
#define DBGC(...)
Definition: compiler.h:505
EFI SAN device private data.
Definition: efi_block.c:69
unsigned int drive
Drive number.
Definition: sanboot.h:54
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_CONNECT_CONTROLLER ConnectController
Definition: UefiSpec.h:1899
#define TRUE
Definition: tlan.h:46
#define DBGC2(...)
Definition: compiler.h:522
void * priv
Driver private data.
Definition: sanboot.h:78
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define DBGC2_EFI_PROTOCOLS(...)
Definition: efi.h:299
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References block, EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::ConnectController, DBGC, DBGC2, DBGC2_EFI_PROTOCOLS, san_device::drive, EEFI, efi_systab, NULL, san_device::priv, rc, efi_block_data::sandev, strerror(), and TRUE.

Referenced by efi_block_boot(), and efi_block_hook().

◆ efi_block_hook()

static int efi_block_hook ( unsigned int  drive,
struct uri **  uris,
unsigned int  count,
unsigned int  flags 
)
static

Hook EFI block device.

Parameters
driveDrive number
urisList of URIs
countNumber of URIs
flagsFlags
Return values
driveDrive number, or negative error

Definition at line 243 of file efi_block.c.

244  {
246  struct san_device *sandev;
247  struct efi_block_data *block;
248  int leak = 0;
249  EFI_STATUS efirc;
250  int rc;
251 
252  /* Sanity check */
253  if ( ! count ) {
254  DBG ( "EFIBLK has no URIs\n" );
255  rc = -ENOTTY;
256  goto err_no_uris;
257  }
258 
259  /* Allocate and initialise structure */
260  sandev = alloc_sandev ( uris, count, sizeof ( *block ) );
261  if ( ! sandev ) {
262  rc = -ENOMEM;
263  goto err_alloc;
264  }
265  block = sandev->priv;
266  block->sandev = sandev;
267  block->media.MediaPresent = 1;
268  block->media.LogicalBlocksPerPhysicalBlock = 1;
269  block->block_io.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION3;
270  block->block_io.Media = &block->media;
271  block->block_io.Reset = efi_block_io_reset;
272  block->block_io.ReadBlocks = efi_block_io_read;
273  block->block_io.WriteBlocks = efi_block_io_write;
274  block->block_io.FlushBlocks = efi_block_io_flush;
275 
276  /* Register SAN device */
277  if ( ( rc = register_sandev ( sandev, drive, flags ) ) != 0 ) {
278  DBGC ( sandev, "EFIBLK %#02x could not register: %s\n",
279  drive, strerror ( rc ) );
280  goto err_register;
281  }
282 
283  /* Update media descriptor */
284  block->media.BlockSize =
286  block->media.LastBlock =
287  ( ( sandev->capacity.blocks >> sandev->blksize_shift ) - 1 );
288 
289  /* Construct device path */
290  if ( ! sandev->active ) {
291  rc = -ENODEV;
292  DBGC ( sandev, "EFIBLK %#02x not active after registration\n",
293  drive );
294  goto err_active;
295  }
296  block->path = efi_describe ( &sandev->active->block );
297  if ( ! block->path ) {
298  rc = -ENODEV;
299  DBGC ( sandev, "EFIBLK %#02x has no device path\n", drive );
300  goto err_describe;
301  }
302  DBGC ( sandev, "EFIBLK %#02x has device path %s\n",
303  drive, efi_devpath_text ( block->path ) );
304 
305  /* Install protocols */
306  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
307  &block->handle,
308  &efi_block_io_protocol_guid, &block->block_io,
310  NULL ) ) != 0 ) {
311  rc = -EEFI ( efirc );
312  DBGC ( sandev, "EFIBLK %#02x could not install protocols: %s\n",
313  sandev->drive, strerror ( rc ) );
314  goto err_install;
315  }
316 
317  /* Connect all possible protocols */
319 
320  return drive;
321 
322  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
323  block->handle,
324  &efi_block_io_protocol_guid, &block->block_io,
326  NULL ) ) != 0 ) {
327  DBGC ( sandev, "EFIBLK %#02x could not uninstall protocols: "
328  "%s\n", sandev->drive, strerror ( -EEFI ( efirc ) ) );
329  leak = 1;
330  }
331  efi_nullify_block ( &block->block_io );
332  err_install:
333  if ( ! leak ) {
334  free ( block->path );
335  block->path = NULL;
336  }
337  err_describe:
338  err_active:
340  err_register:
341  if ( ! leak )
342  sandev_put ( sandev );
343  err_alloc:
344  err_no_uris:
345  if ( leak ) {
346  DBGC ( sandev, "EFIBLK %#02x nullified and leaked\n",
347  sandev->drive );
348  }
349  return rc;
350 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:167
struct san_device * sandev
SAN device.
Definition: efi_block.c:71
uint16_t block
Definition: tftp.h:12
void unregister_sandev(struct san_device *sandev)
Unregister SAN device.
Definition: sanboot.c:925
#define DBGC(...)
Definition: compiler.h:505
struct interface block
Underlying block device interface.
Definition: sanboot.h:36
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1915
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition: sanboot.h:202
static EFI_STATUS EFIAPI efi_block_io_write(EFI_BLOCK_IO_PROTOCOL *block_io, UINT32 media __unused, EFI_LBA lba, UINTN len, VOID *data)
Write to EFI block device.
Definition: efi_block.c:178
uint8_t drive
Drive number.
Definition: int13.h:16
EFI SAN device private data.
Definition: efi_block.c:69
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define EFI_BLOCK_IO_PROTOCOL_REVISION3
Definition: BlockIo.h:212
unsigned int drive
Drive number.
Definition: sanboot.h:54
int register_sandev(struct san_device *sandev, unsigned int drive, unsigned int flags)
Register SAN device.
Definition: sanboot.c:868
unsigned int blksize_shift
Block size shift.
Definition: sanboot.h:73
uint64_t blocks
Total number of blocks.
Definition: blockdev.h:20
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:375
static EFI_STATUS EFIAPI efi_block_io_reset(EFI_BLOCK_IO_PROTOCOL *block_io, BOOLEAN verify __unused)
Reset EFI block device.
Definition: efi_block.c:127
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
#define ENODEV
No such device.
Definition: errno.h:509
A SAN device.
Definition: sanboot.h:47
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
struct block_device_capacity capacity
Raw block device capacity.
Definition: sanboot.h:66
static EFI_STATUS EFIAPI efi_block_io_read(EFI_BLOCK_IO_PROTOCOL *block_io, UINT32 media __unused, EFI_LBA lba, UINTN len, VOID *data)
Read from EFI block device.
Definition: efi_block.c:152
EFI_DEVICE_PATH_PROTOCOL * efi_describe(struct interface *intf)
Describe object as an EFI device path.
Definition: efi_path.c:491
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:108
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
static EFI_STATUS EFIAPI efi_block_io_flush(EFI_BLOCK_IO_PROTOCOL *block_io)
Flush data to EFI block device.
Definition: efi_block.c:200
void efi_nullify_block(EFI_BLOCK_IO_PROTOCOL *block)
Nullify block I/O protocol.
Definition: efi_null.c:354
void * priv
Driver private data.
Definition: sanboot.h:78
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
EFI_SYSTEM_TABLE * efi_systab
struct san_path * active
Current active path.
Definition: sanboot.h:83
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static void efi_block_connect(struct san_device *sandev)
Connect all possible drivers to EFI block device.
Definition: efi_block.c:216
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct san_device * alloc_sandev(struct uri **uris, unsigned int count, size_t priv_size)
Allocate SAN device.
Definition: sanboot.c:825
size_t blksize
Block size.
Definition: blockdev.h:22
uint8_t flags
Flags.
Definition: ena.h:18

References san_device::active, alloc_sandev(), block_device_capacity::blksize, san_device::blksize_shift, block, san_path::block, block_device_capacity::blocks, EFI_SYSTEM_TABLE::BootServices, san_device::capacity, count, DBG, DBGC, drive, san_device::drive, EEFI, efi_block_connect(), efi_block_io_flush(), efi_block_io_protocol_guid, EFI_BLOCK_IO_PROTOCOL_REVISION3, efi_block_io_read(), efi_block_io_reset(), efi_block_io_write(), efi_describe(), efi_device_path_protocol_guid, efi_devpath_text(), efi_nullify_block(), efi_systab, ENODEV, ENOMEM, ENOTTY, flags, free, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, NULL, san_device::priv, rc, register_sandev(), efi_block_data::sandev, sandev_put(), strerror(), EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and unregister_sandev().

◆ efi_block_unhook()

static void efi_block_unhook ( unsigned int  drive)
static

Unhook EFI block device.

Parameters
driveDrive number

Definition at line 357 of file efi_block.c.

357  {
359  struct san_device *sandev;
360  struct efi_block_data *block;
361  int leak = efi_shutdown_in_progress;
362  EFI_STATUS efirc;
363 
364  /* Find SAN device */
365  sandev = sandev_find ( drive );
366  if ( ! sandev ) {
367  DBG ( "EFIBLK cannot find drive %#02x\n", drive );
368  return;
369  }
370  block = sandev->priv;
371 
372  /* Uninstall protocols */
373  if ( ( ! efi_shutdown_in_progress ) &&
374  ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
375  block->handle,
376  &efi_block_io_protocol_guid, &block->block_io,
378  NULL ) ) != 0 ) ) {
379  DBGC ( sandev, "EFIBLK %#02x could not uninstall protocols: "
380  "%s\n", sandev->drive, strerror ( -EEFI ( efirc ) ) );
381  leak = 1;
382  }
383  efi_nullify_block ( &block->block_io );
384 
385  /* Free device path */
386  if ( ! leak ) {
387  free ( block->path );
388  block->path = NULL;
389  }
390 
391  /* Unregister SAN device */
393 
394  /* Drop reference to drive */
395  if ( ! leak )
396  sandev_put ( sandev );
397 
398  /* Report leakage, if applicable */
399  if ( leak && ( ! efi_shutdown_in_progress ) ) {
400  DBGC ( sandev, "EFIBLK %#02x nullified and leaked\n",
401  sandev->drive );
402  }
403 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:167
struct san_device * sandev
SAN device.
Definition: efi_block.c:71
uint16_t block
Definition: tftp.h:12
void unregister_sandev(struct san_device *sandev)
Unregister SAN device.
Definition: sanboot.c:925
#define DBGC(...)
Definition: compiler.h:505
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition: sanboot.h:202
uint8_t drive
Drive number.
Definition: int13.h:16
EFI SAN device private data.
Definition: efi_block.c:69
unsigned int drive
Drive number.
Definition: sanboot.h:54
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
A SAN device.
Definition: sanboot.h:47
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
struct san_device * sandev_find(unsigned int drive)
Find SAN device by drive number.
Definition: sanboot.c:100
EFI_GUID efi_block_io_protocol_guid
Block I/O protocol GUID.
Definition: efi_guid.c:108
void efi_nullify_block(EFI_BLOCK_IO_PROTOCOL *block)
Nullify block I/O protocol.
Definition: efi_null.c:354
void * priv
Driver private data.
Definition: sanboot.h:78
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:54

References block, EFI_SYSTEM_TABLE::BootServices, DBG, DBGC, drive, san_device::drive, EEFI, efi_block_io_protocol_guid, efi_device_path_protocol_guid, efi_nullify_block(), efi_shutdown_in_progress, efi_systab, free, NULL, san_device::priv, efi_block_data::sandev, sandev_find(), sandev_put(), strerror(), EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and unregister_sandev().

◆ LIST_HEAD()

static LIST_HEAD ( efi_acpi_tables  )
static

List of installed ACPI tables.

◆ efi_block_install()

static int efi_block_install ( struct acpi_header hdr)
static

Install ACPI table.

Parameters
hdrACPI description header
Return values
rcReturn status code

Definition at line 422 of file efi_block.c.

422  {
423  size_t len = le32_to_cpu ( hdr->length );
424  struct efi_acpi_table *installed;
425  EFI_STATUS efirc;
426  int rc;
427 
428  /* Allocate installed table record */
429  installed = zalloc ( sizeof ( *installed ) );
430  if ( ! installed ) {
431  rc = -ENOMEM;
432  goto err_alloc;
433  }
434 
435  /* Fill in common parameters */
436  strncpy ( hdr->oem_id, "FENSYS", sizeof ( hdr->oem_id ) );
437  strncpy ( hdr->oem_table_id, "iPXE", sizeof ( hdr->oem_table_id ) );
438 
439  /* Fix up ACPI checksum */
441 
442  /* Install table */
443  if ( ( efirc = acpi->InstallAcpiTable ( acpi, hdr, len,
444  &installed->key ) ) != 0 ){
445  rc = -EEFI ( efirc );
446  DBGC ( acpi, "EFIBLK could not install %s: %s\n",
447  acpi_name ( hdr->signature ), strerror ( rc ) );
448  DBGC2_HDA ( acpi, 0, hdr, len );
449  goto err_install;
450  }
451 
452  /* Add to list of installed tables */
453  list_add_tail ( &installed->list, &efi_acpi_tables );
454 
455  DBGC ( acpi, "EFIBLK installed %s as ACPI table %#lx\n",
456  acpi_name ( hdr->signature ),
457  ( ( unsigned long ) installed->key ) );
458  DBGC2_HDA ( acpi, 0, hdr, len );
459  return 0;
460 
461  list_del ( &installed->list );
462  err_install:
463  free ( installed );
464  err_alloc:
465  return rc;
466 }
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:167
EFI_ACPI_TABLE_INSTALL_ACPI_TABLE InstallAcpiTable
Definition: AcpiTable.h:122
UINTN key
Table key.
Definition: efi_block.c:410
#define le32_to_cpu(value)
Definition: byteswap.h:113
struct golan_inbox_hdr hdr
Message header.
Definition: CIB_PRM.h:28
#define DBGC(...)
Definition: compiler.h:505
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:332
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:62
void acpi_fix_checksum(struct acpi_header *acpi)
Fix up ACPI table checksum.
Definition: acpi.c:76
#define DBGC2_HDA(...)
Definition: compiler.h:523
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct list_head list
List of installed tables.
Definition: efi_block.c:408
uint32_t len
Length.
Definition: ena.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition: acpi.h:190
An installed ACPI table.
Definition: efi_block.c:406

References acpi, acpi_fix_checksum(), acpi_name(), DBGC, DBGC2_HDA, EEFI, ENOMEM, free, hdr, _EFI_ACPI_TABLE_PROTOCOL::InstallAcpiTable, efi_acpi_table::key, le32_to_cpu, len, efi_acpi_table::list, list_add_tail, list_del, rc, strerror(), strncpy(), and zalloc().

Referenced by efi_block_describe().

◆ efi_block_describe()

static int efi_block_describe ( void  )
static

Describe EFI block devices.

Return values
rcReturn status code

Definition at line 473 of file efi_block.c.

473  {
474  struct efi_acpi_table *installed;
475  struct efi_acpi_table *tmp;
476  UINTN key;
477  EFI_STATUS efirc;
478  int rc;
479 
480  /* Sanity check */
481  if ( ! acpi ) {
482  DBG ( "EFIBLK has no ACPI table protocol\n" );
483  return -ENOTSUP;
484  }
485 
486  /* Uninstall any existing ACPI tables */
487  list_for_each_entry_safe ( installed, tmp, &efi_acpi_tables, list ) {
488  key = installed->key;
489  if ( ( efirc = acpi->UninstallAcpiTable ( acpi, key ) ) != 0 ) {
490  rc = -EEFI ( efirc );
491  DBGC ( acpi, "EFIBLK could not uninstall ACPI table "
492  "%#lx: %s\n", ( ( unsigned long ) key ),
493  strerror ( rc ) );
494  /* Continue anyway */
495  }
496  list_del ( &installed->list );
497  free ( installed );
498  }
499 
500  /* Install ACPI tables */
501  if ( ( rc = acpi_install ( efi_block_install ) ) != 0 ) {
502  DBGC ( acpi, "EFIBLK could not install ACPI tables: %s\n",
503  strerror ( rc ) );
504  return rc;
505  }
506 
507  return 0;
508 }
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:167
UINTN key
Table key.
Definition: efi_block.c:410
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
EFI_ACPI_TABLE_UNINSTALL_ACPI_TABLE UninstallAcpiTable
Definition: AcpiTable.h:123
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:62
static int efi_block_install(struct acpi_header *hdr)
Install ACPI table.
Definition: efi_block.c:422
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:447
int acpi_install(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition: acpi.c:357
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint8_t * tmp
Definition: entropy.h:156
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
struct list_head list
List of installed tables.
Definition: efi_block.c:408
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
An installed ACPI table.
Definition: efi_block.c:406
union @376 key
Sense key.
Definition: scsi.h:18

References acpi, acpi_install(), DBG, DBGC, EEFI, efi_block_install(), ENOTSUP, free, key, efi_acpi_table::key, efi_acpi_table::list, list_del, list_for_each_entry_safe, rc, strerror(), tmp, and _EFI_ACPI_TABLE_PROTOCOL::UninstallAcpiTable.

◆ efi_block_boot_image()

static int efi_block_boot_image ( struct san_device sandev,
EFI_HANDLE  handle,
const char *  filename,
EFI_HANDLE image 
)
static

Try booting from child device of EFI block device.

Parameters
sandevSAN device
handleEFI handle
filenameFilename (or NULL to use default)
imageImage handle to fill in
Return values
rcReturn status code

Definition at line 519 of file efi_block.c.

520  {
522  struct efi_block_data *block = sandev->priv;
523  union {
525  void *interface;
526  } path;
527  EFI_DEVICE_PATH_PROTOCOL *boot_path;
528  FILEPATH_DEVICE_PATH *filepath;
530  size_t prefix_len;
531  size_t filepath_len;
532  size_t boot_path_len;
533  EFI_STATUS efirc;
534  int rc;
535 
536  /* Identify device path */
537  if ( ( efirc = bs->OpenProtocol ( handle,
539  &path.interface, efi_image_handle,
540  handle,
542  DBGC ( sandev, "EFIBLK %#02x found filesystem with no device "
543  "path??", sandev->drive );
544  rc = -EEFI ( efirc );
545  goto err_open_device_path;
546  }
547 
548  /* Check if this device is a child of our block device */
549  prefix_len = efi_path_len ( block->path );
550  if ( memcmp ( path.path, block->path, prefix_len ) != 0 ) {
551  /* Not a child device */
552  rc = -ENOTTY;
553  goto err_not_child;
554  }
555  DBGC ( sandev, "EFIBLK %#02x found child device %s\n",
556  sandev->drive, efi_devpath_text ( path.path ) );
557 
558  /* Construct device path for boot image */
559  end = efi_path_end ( path.path );
560  prefix_len = ( ( ( void * ) end ) - ( ( void * ) path.path ) );
561  filepath_len = ( SIZE_OF_FILEPATH_DEVICE_PATH +
562  ( filename ?
563  ( ( strlen ( filename ) + 1 /* NUL */ ) *
564  sizeof ( filepath->PathName[0] ) ) :
565  sizeof ( efi_block_boot_filename ) ) );
566  boot_path_len = ( prefix_len + filepath_len + sizeof ( *end ) );
567  boot_path = zalloc ( boot_path_len );
568  if ( ! boot_path ) {
569  rc = -ENOMEM;
570  goto err_alloc_path;
571  }
572  memcpy ( boot_path, path.path, prefix_len );
573  filepath = ( ( ( void * ) boot_path ) + prefix_len );
574  filepath->Header.Type = MEDIA_DEVICE_PATH;
575  filepath->Header.SubType = MEDIA_FILEPATH_DP;
576  filepath->Header.Length[0] = ( filepath_len & 0xff );
577  filepath->Header.Length[1] = ( filepath_len >> 8 );
578  if ( filename ) {
579  efi_sprintf ( filepath->PathName, "%s", filename );
580  } else {
582  sizeof ( efi_block_boot_filename ) );
583  }
584  end = ( ( ( void * ) filepath ) + filepath_len );
585  end->Type = END_DEVICE_PATH_TYPE;
587  end->Length[0] = sizeof ( *end );
588  DBGC ( sandev, "EFIBLK %#02x trying to load %s\n",
589  sandev->drive, efi_devpath_text ( boot_path ) );
590 
591  /* Try loading boot image from this device */
592  *image = NULL;
593  if ( ( efirc = bs->LoadImage ( FALSE, efi_image_handle, boot_path,
594  NULL, 0, image ) ) != 0 ) {
595  rc = -EEFI ( efirc );
596  DBGC ( sandev, "EFIBLK %#02x could not load image: %s\n",
597  sandev->drive, strerror ( rc ) );
598  if ( efirc == EFI_SECURITY_VIOLATION )
599  bs->UnloadImage ( *image );
600  goto err_load_image;
601  }
602 
603  /* Success */
604  rc = 0;
605 
606  err_load_image:
607  free ( boot_path );
608  err_alloc_path:
609  err_not_child:
610  err_open_device_path:
611  return rc;
612 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:167
#define END_DEVICE_PATH_TYPE
Definition: DevicePath.h:1327
struct san_device * sandev
SAN device.
Definition: efi_block.c:71
EFI_IMAGE_LOAD LoadImage
Definition: UefiSpec.h:1883
uint16_t block
Definition: tftp.h:12
#define DBGC(...)
Definition: compiler.h:505
size_t efi_path_len(EFI_DEVICE_PATH_PROTOCOL *path)
Find length of device path (excluding terminator)
Definition: efi_path.c:67
EFI_IMAGE_UNLOAD UnloadImage
Definition: UefiSpec.h:1886
An executable image.
Definition: image.h:24
This protocol can be used on any device handle to obtain generic path/location information concerning...
Definition: DevicePath.h:51
CHAR16 PathName[1]
A NULL-terminated Path string including directory and file names.
Definition: DevicePath.h:1041
EFI_DEVICE_PATH_PROTOCOL Header
Definition: DevicePath.h:1037
EFI SAN device private data.
Definition: efi_block.c:69
EFI_DEVICE_PATH_PROTOCOL * path
Device path protocol.
Definition: efi_block.c:79
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
An object interface.
Definition: interface.h:124
unsigned int drive
Drive number.
Definition: sanboot.h:54
#define SIZE_OF_FILEPATH_DEVICE_PATH
Definition: DevicePath.h:1044
const char * efi_devpath_text(EFI_DEVICE_PATH_PROTOCOL *path)
Get textual representation of device path.
Definition: efi_debug.c:375
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define efi_sprintf(buf, fmt,...)
Write a formatted string to a buffer.
Definition: efi_strings.h:43
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
static wchar_t efi_block_boot_filename[]
Boot filename.
Definition: efi_block.c:66
#define MEDIA_DEVICE_PATH
Definition: DevicePath.h:946
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
#define EFI_SECURITY_VIOLATION
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:146
#define END_ENTIRE_DEVICE_PATH_SUBTYPE
Definition: DevicePath.h:1328
UINT8 Length[2]
Specific Device Path data.
Definition: DevicePath.h:64
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
void * priv
Driver private data.
Definition: sanboot.h:78
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
UINT8 SubType
Varies by Type 0xFF End Entire Device Path, or 0x01 End This Instance of a Device Path and start a ne...
Definition: DevicePath.h:59
uint32_t end
Ending offset.
Definition: netvsc.h:18
#define FALSE
Definition: tlan.h:45
UINT8 Type
0x01 Hardware Device Path.
Definition: DevicePath.h:52
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
uint16_t handle
Handle.
Definition: smbios.h:16
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
EFI_DEVICE_PATH_PROTOCOL * efi_path_end(EFI_DEVICE_PATH_PROTOCOL *path)
Find end of device path.
Definition: efi_path.c:49
#define MEDIA_FILEPATH_DP
File Path Media Device Path SubType.
Definition: DevicePath.h:1035

References block, EFI_SYSTEM_TABLE::BootServices, DBGC, san_device::drive, EEFI, efi_block_boot_filename, efi_device_path_protocol_guid, efi_devpath_text(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_path_end(), efi_path_len(), EFI_SECURITY_VIOLATION, efi_sprintf, efi_systab, end, END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, ENOMEM, ENOTTY, FALSE, free, handle, FILEPATH_DEVICE_PATH::Header, EFI_DEVICE_PATH_PROTOCOL::Length, EFI_BOOT_SERVICES::LoadImage, MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP, memcmp(), memcpy(), NULL, EFI_BOOT_SERVICES::OpenProtocol, efi_block_data::path, FILEPATH_DEVICE_PATH::PathName, san_device::priv, rc, efi_block_data::sandev, SIZE_OF_FILEPATH_DEVICE_PATH, strerror(), strlen(), EFI_DEVICE_PATH_PROTOCOL::SubType, EFI_DEVICE_PATH_PROTOCOL::Type, EFI_BOOT_SERVICES::UnloadImage, and zalloc().

Referenced by efi_block_boot().

◆ efi_block_boot()

static int efi_block_boot ( unsigned int  drive,
const char *  filename 
)
static

Boot from EFI block device.

Parameters
driveDrive number
filenameFilename (or NULL to use default)
Return values
rcReturn status code

Definition at line 621 of file efi_block.c.

621  {
623  struct san_device *sandev;
624  EFI_HANDLE *handles;
626  UINTN count;
627  unsigned int i;
628  EFI_STATUS efirc;
629  int rc;
630 
631  /* Find SAN device */
632  sandev = sandev_find ( drive );
633  if ( ! sandev ) {
634  DBG ( "EFIBLK cannot find drive %#02x\n", drive );
635  rc = -ENODEV;
636  goto err_sandev_find;
637  }
638 
639  /* Release SNP devices */
640  efi_snp_release();
641 
642  /* Connect all possible protocols */
643  efi_block_connect ( sandev );
644 
645  /* Locate all handles supporting the Simple File System protocol */
646  if ( ( efirc = bs->LocateHandleBuffer (
648  NULL, &count, &handles ) ) != 0 ) {
649  rc = -EEFI ( efirc );
650  DBGC ( sandev, "EFIBLK %#02x cannot locate file systems: %s\n",
651  sandev->drive, strerror ( rc ) );
652  goto err_locate_file_systems;
653  }
654 
655  /* Try booting from any available child device containing a
656  * suitable boot image. This is something of a wild stab in
657  * the dark, but should end up conforming to user expectations
658  * most of the time.
659  */
660  rc = -ENOENT;
661  for ( i = 0 ; i < count ; i++ ) {
662  if ( ( rc = efi_block_boot_image ( sandev, handles[i], filename,
663  &image ) ) != 0 )
664  continue;
665  DBGC ( sandev, "EFIBLK %#02x found boot image\n",
666  sandev->drive );
667  efirc = bs->StartImage ( image, NULL, NULL );
668  rc = ( efirc ? -EEFI ( efirc ) : 0 );
669  bs->UnloadImage ( image );
670  DBGC ( sandev, "EFIBLK %#02x boot image returned: %s\n",
671  sandev->drive, strerror ( rc ) );
672  break;
673  }
674 
675  bs->FreePool ( handles );
676  err_locate_file_systems:
677  efi_snp_claim();
678  err_sandev_find:
679  return rc;
680 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
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:167
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
EFI_IMAGE_UNLOAD UnloadImage
Definition: UefiSpec.h:1886
An executable image.
Definition: image.h:24
uint8_t drive
Drive number.
Definition: int13.h:16
static void efi_snp_claim(void)
Claim network devices for use by iPXE.
Definition: efi_snp.h:88
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:232
unsigned int drive
Drive number.
Definition: sanboot.h:54
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define ENODEV
No such device.
Definition: errno.h:509
static void efi_snp_release(void)
Release network devices for use via SNP.
Definition: efi_snp.h:96
A SAN device.
Definition: sanboot.h:47
EFI_IMAGE_START StartImage
Definition: UefiSpec.h:1884
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
static int efi_block_boot_image(struct san_device *sandev, EFI_HANDLE handle, const char *filename, EFI_HANDLE *image)
Try booting from child device of EFI block device.
Definition: efi_block.c:519
struct san_device * sandev_find(unsigned int drive)
Find SAN device by drive number.
Definition: sanboot.c:100
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
uint16_t count
Number of entries.
Definition: ena.h:22
Retrieve the set of handles from the handle database that support a specified protocol.
Definition: UefiSpec.h:1448
EFI_SYSTEM_TABLE * efi_systab
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
static void efi_block_connect(struct san_device *sandev)
Connect all possible drivers to EFI block device.
Definition: efi_block.c:216
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:55
EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer
Definition: UefiSpec.h:1913

References EFI_SYSTEM_TABLE::BootServices, ByProtocol, count, DBG, DBGC, drive, san_device::drive, EEFI, efi_block_boot_image(), efi_block_connect(), efi_simple_file_system_protocol_guid, efi_snp_claim(), efi_snp_release(), efi_systab, ENODEV, ENOENT, EFI_BOOT_SERVICES::FreePool, EFI_BOOT_SERVICES::LocateHandleBuffer, NULL, rc, sandev_find(), EFI_BOOT_SERVICES::StartImage, strerror(), and EFI_BOOT_SERVICES::UnloadImage.

◆ PROVIDE_SANBOOT() [1/4]

PROVIDE_SANBOOT ( efi  ,
san_hook  ,
efi_block_hook   
)

◆ PROVIDE_SANBOOT() [2/4]

PROVIDE_SANBOOT ( efi  ,
san_unhook  ,
efi_block_unhook   
)

◆ PROVIDE_SANBOOT() [3/4]

PROVIDE_SANBOOT ( efi  ,
san_describe  ,
efi_block_describe   
)

◆ PROVIDE_SANBOOT() [4/4]

PROVIDE_SANBOOT ( efi  ,
san_boot  ,
efi_block_boot   
)

Variable Documentation

◆ acpi

◆ efi_block_boot_filename

wchar_t efi_block_boot_filename[] = EFI_REMOVABLE_MEDIA_FILE_NAME
static

Boot filename.

Definition at line 66 of file efi_block.c.

Referenced by efi_block_boot_image().