iPXE
Macros | Functions | Variables
efi_autoexec.c File Reference

EFI autoexec script. More...

#include <string.h>
#include <errno.h>
#include <ipxe/image.h>
#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_autoexec.h>
#include <ipxe/efi/Protocol/SimpleFileSystem.h>
#include <ipxe/efi/Guid/FileInfo.h>

Go to the source code of this file.

Macros

#define AUTOEXEC_FILENAME   L"autoexec.ipxe"
 Autoexec script filename. More...
 
#define AUTOEXEC_NAME   "autoexec.ipxe"
 Autoexec script image name. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int efi_autoexec_load (EFI_HANDLE device)
 Load autoexec script. More...
 
static void efi_autoexec_startup (void)
 Register autoexec script. More...
 
struct startup_fn efi_autoexec_startup_fn __startup_fn (STARTUP_NORMAL)
 Autoexec script startup function. More...
 

Variables

static void * efi_autoexec
 Autoexec script (if any) More...
 
static size_t efi_autoexec_len
 Autoexec script length. More...
 

Detailed Description

EFI autoexec script.

Definition in file efi_autoexec.c.

Macro Definition Documentation

◆ AUTOEXEC_FILENAME

#define AUTOEXEC_FILENAME   L"autoexec.ipxe"

Autoexec script filename.

Definition at line 42 of file efi_autoexec.c.

◆ AUTOEXEC_NAME

#define AUTOEXEC_NAME   "autoexec.ipxe"

Autoexec script image name.

Definition at line 45 of file efi_autoexec.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_autoexec_load()

int efi_autoexec_load ( EFI_HANDLE  device)

Load autoexec script.

Parameters
deviceDevice handle
Return values
rcReturn status code

Definition at line 59 of file efi_autoexec.c.

59  {
61  static wchar_t name[] = AUTOEXEC_FILENAME;
62  union {
63  void *interface;
65  } u;
66  struct {
68  CHAR16 name[ sizeof ( name ) / sizeof ( name[0] ) ];
69  } info;
71  EFI_FILE_PROTOCOL *file;
72  UINTN size;
73  VOID *data;
74  EFI_STATUS efirc;
75  int rc;
76 
77  /* Sanity check */
78  assert ( efi_autoexec == NULL );
79  assert ( efi_autoexec_len == 0 );
80 
81  /* Open simple file system protocol */
82  if ( ( efirc = bs->OpenProtocol ( device,
84  &u.interface, efi_image_handle,
85  device,
87  rc = -EEFI ( efirc );
88  DBGC ( device, "EFI %s has no filesystem instance: %s\n",
89  efi_handle_name ( device ), strerror ( rc ) );
90  goto err_filesystem;
91  }
92 
93  /* Open root directory */
94  if ( ( efirc = u.fs->OpenVolume ( u.fs, &root ) ) != 0 ) {
95  rc = -EEFI ( efirc );
96  DBGC ( device, "EFI %s could not open volume: %s\n",
97  efi_handle_name ( device ), strerror ( rc ) );
98  goto err_volume;
99  }
100 
101  /* Open autoexec script */
102  if ( ( efirc = root->Open ( root, &file, name,
103  EFI_FILE_MODE_READ, 0 ) ) != 0 ) {
104  rc = -EEFI ( efirc );
105  DBGC ( device, "EFI %s has no %ls: %s\n",
106  efi_handle_name ( device ), name, strerror ( rc ) );
107  goto err_open;
108  }
109 
110  /* Get file information */
111  size = sizeof ( info );
112  if ( ( efirc = file->GetInfo ( file, &efi_file_info_id, &size,
113  &info ) ) != 0 ) {
114  rc = -EEFI ( efirc );
115  DBGC ( device, "EFI %s could not get %ls info: %s\n",
116  efi_handle_name ( device ), name, strerror ( rc ) );
117  goto err_getinfo;
118  }
119  size = info.info.FileSize;
120 
121  /* Ignore zero-length files */
122  if ( ! size ) {
123  rc = -EINVAL;
124  DBGC ( device, "EFI %s has zero-length %ls\n",
125  efi_handle_name ( device ), name );
126  goto err_empty;
127  }
128 
129  /* Allocate temporary copy */
130  if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, size,
131  &data ) ) != 0 ) {
132  rc = -EEFI ( efirc );
133  DBGC ( device, "EFI %s could not allocate %ls: %s\n",
134  efi_handle_name ( device ), name, strerror ( rc ) );
135  goto err_alloc;
136  }
137 
138  /* Read file */
139  if ( ( efirc = file->Read ( file, &size, data ) ) != 0 ) {
140  rc = -EEFI ( efirc );
141  DBGC ( device, "EFI %s could not read %ls: %s\n",
142  efi_handle_name ( device ), name, strerror ( rc ) );
143  goto err_read;
144  }
145 
146  /* Record autoexec script */
147  efi_autoexec = data;
149  data = NULL;
150  DBGC ( device, "EFI %s found %ls\n",
151  efi_handle_name ( device ), name );
152 
153  /* Success */
154  rc = 0;
155 
156  err_read:
157  if ( data )
158  bs->FreePool ( data );
159  err_alloc:
160  err_empty:
161  err_getinfo:
162  file->Close ( file );
163  err_open:
164  root->Close ( root );
165  err_volume:
168  err_filesystem:
169  return rc;
170 }
static size_t efi_autoexec_len
Autoexec script length.
Definition: efi_autoexec.c:51
EFI_FILE_CLOSE Close
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
u32 info
Definition: ar9003_mac.h:67
struct stp_switch root
Root switch.
Definition: stp.h:26
#define DBGC(...)
Definition: compiler.h:505
EFI_FILE_GET_INFO GetInfo
unsigned short CHAR16
Definition: ProcessorBind.h:59
EFI_CLOSE_PROTOCOL CloseProtocol
Definition: UefiSpec.h:1906
A hardware device.
Definition: device.h:73
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:232
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1271
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
uint32_t fs
Definition: librm.h:252
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_HANDLE efi_image_handle
Image handle passed to entry point.
Definition: efi_init.c:33
UINT64 UINTN
Unsigned value of native width.
Definition: ProcessorBind.h:71
#define VOID
Undeclared type.
Definition: Base.h:319
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
EFI_GUID efi_file_info_id
File information GUID.
Definition: efi_guid.c:303
#define EFI_FILE_MODE_READ
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
static void * efi_autoexec
Autoexec script (if any)
Definition: efi_autoexec.c:48
union @17 u
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
#define AUTOEXEC_FILENAME
Autoexec script filename.
Definition: efi_autoexec.c:42
EFI_SYSTEM_TABLE * efi_systab
EFI_OPEN_PROTOCOL OpenProtocol
Definition: UefiSpec.h:1905
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
The EFI_FILE_PROTOCOL provides file IO access to supported file systems.
EFI_ALLOCATE_POOL AllocatePool
Definition: UefiSpec.h:1854

References EFI_BOOT_SERVICES::AllocatePool, assert(), AUTOEXEC_FILENAME, EFI_SYSTEM_TABLE::BootServices, _EFI_FILE_PROTOCOL::Close, EFI_BOOT_SERVICES::CloseProtocol, data, DBGC, EEFI, efi_autoexec, efi_autoexec_len, efi_file_info_id, EFI_FILE_MODE_READ, efi_handle_name(), efi_image_handle, EFI_OPEN_PROTOCOL_GET_PROTOCOL, efi_simple_file_system_protocol_guid, efi_systab, EfiBootServicesData, EINVAL, EFI_BOOT_SERVICES::FreePool, fs, _EFI_FILE_PROTOCOL::GetInfo, info, name, NULL, EFI_BOOT_SERVICES::OpenProtocol, rc, _EFI_FILE_PROTOCOL::Read, root, size, strerror(), u, and VOID.

Referenced by efi_init_application().

◆ efi_autoexec_startup()

static void efi_autoexec_startup ( void  )
static

Register autoexec script.

Definition at line 176 of file efi_autoexec.c.

176  {
179  const char *name = AUTOEXEC_NAME;
180  struct image *image;
181 
182  /* Do nothing if we have no autoexec script */
183  if ( ! efi_autoexec )
184  return;
185 
186  /* Create autoexec image */
189  if ( ! image ) {
190  DBGC ( device, "EFI %s could not create %s\n",
191  efi_handle_name ( device ), name );
192  return;
193  }
194  DBGC ( device, "EFI %s registered %s\n",
195  efi_handle_name ( device ), name );
196 
197  /* Free temporary copy */
198  bs->FreePool ( efi_autoexec );
199  efi_autoexec = NULL;
200 }
static size_t efi_autoexec_len
Autoexec script length.
Definition: efi_autoexec.c:51
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:36
const char * name
Definition: ath9k_hw.c:1984
#define AUTOEXEC_NAME
Autoexec script image name.
Definition: efi_autoexec.c:45
#define DBGC(...)
Definition: compiler.h:505
struct image * image_memory(const char *name, userptr_t data, size_t len)
Create registered image from block of memory.
Definition: image.c:534
An executable image.
Definition: image.h:24
A hardware device.
Definition: device.h:73
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
static void * efi_autoexec
Autoexec script (if any)
Definition: efi_autoexec.c:48
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
EFI_SYSTEM_TABLE * efi_systab
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
Definition: efi.h:50
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:61

References AUTOEXEC_NAME, EFI_SYSTEM_TABLE::BootServices, DBGC, EFI_LOADED_IMAGE_PROTOCOL::DeviceHandle, efi_autoexec, efi_autoexec_len, efi_handle_name(), efi_loaded_image, efi_systab, EFI_BOOT_SERVICES::FreePool, image_memory(), name, NULL, and virt_to_user().

◆ __startup_fn()

struct startup_fn efi_autoexec_startup_fn __startup_fn ( STARTUP_NORMAL  )

Autoexec script startup function.

Variable Documentation

◆ efi_autoexec

void* efi_autoexec
static

Autoexec script (if any)

Definition at line 48 of file efi_autoexec.c.

Referenced by efi_autoexec_load(), and efi_autoexec_startup().

◆ efi_autoexec_len

size_t efi_autoexec_len
static

Autoexec script length.

Definition at line 51 of file efi_autoexec.c.

Referenced by efi_autoexec_load(), and efi_autoexec_startup().