iPXE
Data Structures | Macros | Functions | Variables
efi_autoexec.c File Reference

EFI autoexec script. More...

#include <string.h>
#include <errno.h>
#include <ipxe/timer.h>
#include <ipxe/image.h>
#include <ipxe/netdevice.h>
#include <ipxe/uri.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/efi_autoexec.h>
#include <ipxe/efi/mnpnet.h>
#include <usr/imgmgmt.h>
#include <usr/sync.h>

Go to the source code of this file.

Data Structures

struct  efi_autoexec_loader
 An EFI autoexec script loader. More...
 

Macros

#define EFI_AUTOEXEC_TIMEOUT   ( 2 * TICKS_PER_SEC )
 Timeout for autoexec script downloads. More...
 
#define EFI_AUTOEXEC_NAME   "autoexec.ipxe"
 Autoexec script image name. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int efi_autoexec_filesystem (EFI_HANDLE handle, struct image **image)
 Load autoexec script from filesystem. More...
 
static int efi_autoexec_network (EFI_HANDLE handle, struct image **image)
 Load autoexec script via temporary network device. More...
 
int efi_autoexec_load (void)
 Load autoexec script. More...
 

Variables

static struct efi_autoexec_loader efi_autoexec_loaders []
 Autoexec script loaders. More...
 

Detailed Description

EFI autoexec script.

Definition in file efi_autoexec.c.

Macro Definition Documentation

◆ EFI_AUTOEXEC_TIMEOUT

#define EFI_AUTOEXEC_TIMEOUT   ( 2 * TICKS_PER_SEC )

Timeout for autoexec script downloads.

Definition at line 46 of file efi_autoexec.c.

◆ EFI_AUTOEXEC_NAME

#define EFI_AUTOEXEC_NAME   "autoexec.ipxe"

Autoexec script image name.

Definition at line 49 of file efi_autoexec.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_autoexec_filesystem()

static int efi_autoexec_filesystem ( EFI_HANDLE  handle,
struct image **  image 
)
static

Load autoexec script from filesystem.

Parameters
handleSimple filesystem protocol handle
imageImage to fill in
Return values
rcReturn status code

Definition at line 72 of file efi_autoexec.c.

72  {
74  int rc;
75 
76  /* Check that we were loaded from a filesystem */
77  if ( handle != device ) {
78  DBGC ( device, "EFI %s is not the file system handle\n",
79  efi_handle_name ( device ) );
80  return -ENOTTY;
81  }
82 
83  /* Try loading from loaded image directory, if supported */
84  if ( ( rc = imgacquire ( "file:" EFI_AUTOEXEC_NAME,
85  EFI_AUTOEXEC_TIMEOUT, image ) ) == 0 )
86  return 0;
87 
88  /* Try loading from root directory, if supported */
89  if ( ( rc = imgacquire ( "file:/" EFI_AUTOEXEC_NAME,
90  EFI_AUTOEXEC_TIMEOUT, image ) ) == 0 )
91  return 0;
92 
93  return rc;
94 }
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:37
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define EFI_AUTOEXEC_TIMEOUT
Timeout for autoexec script downloads.
Definition: efi_autoexec.c:46
A hardware device.
Definition: device.h:73
#define EFI_AUTOEXEC_NAME
Autoexec script image name.
Definition: efi_autoexec.c:49
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
uint16_t handle
Handle.
Definition: smbios.h:16
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:141
Definition: efi.h:59
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:55

References DBGC, EFI_LOADED_IMAGE_PROTOCOL::DeviceHandle, EFI_AUTOEXEC_NAME, EFI_AUTOEXEC_TIMEOUT, efi_handle_name(), efi_loaded_image, ENOTTY, handle, imgacquire(), and rc.

◆ efi_autoexec_network()

static int efi_autoexec_network ( EFI_HANDLE  handle,
struct image **  image 
)
static

Load autoexec script via temporary network device.

Parameters
handleManaged network protocol service binding handle
imageImage to fill in
Return values
rcReturn status code

Definition at line 103 of file efi_autoexec.c.

103  {
105  struct net_device *netdev;
106  int rc;
107 
108  /* Create temporary network device */
109  if ( ( rc = mnptemp_create ( handle, &netdev ) ) != 0 ) {
110  DBGC ( device, "EFI %s could not create net device: %s\n",
111  efi_handle_name ( device ), strerror ( rc ) );
112  goto err_create;
113  }
114 
115  /* Do nothing unless we have a usable current working URI */
116  if ( ! cwuri ) {
117  DBGC ( device, "EFI %s has no current working URI\n",
118  efi_handle_name ( device ) );
119  rc = -ENOTTY;
120  goto err_cwuri;
121  }
122 
123  /* Open network device */
124  if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
125  DBGC ( device, "EFI %s could not open net device: %s\n",
126  efi_handle_name ( device ), strerror ( rc ) );
127  goto err_open;
128  }
129 
130  /* Attempt download */
132  if ( rc != 0 ) {
133  DBGC ( device, "EFI %s could not download %s: %s\n",
135  strerror ( rc ) );
136  }
137 
138  /* Ensure network exchanges have completed */
140 
141  err_open:
142  err_cwuri:
144  err_create:
145  return rc;
146 }
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:37
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
#define EFI_AUTOEXEC_TIMEOUT
Timeout for autoexec script downloads.
Definition: efi_autoexec.c:46
A hardware device.
Definition: device.h:73
#define EFI_AUTOEXEC_NAME
Autoexec script image name.
Definition: efi_autoexec.c:49
void mnptemp_destroy(struct net_device *netdev)
Destroy temporary MNP network device.
Definition: mnpnet.c:551
int sync(unsigned long timeout)
Wait for pending operations to complete.
Definition: sync.c:73
static struct net_device * netdev
Definition: gdbudp.c:52
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A network device.
Definition: netdevice.h:352
int mnptemp_create(EFI_HANDLE handle, struct net_device **netdev)
Create temporary MNP network device.
Definition: mnpnet.c:514
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
struct uri * cwuri
Current working URI.
Definition: cwuri.c:38
uint16_t handle
Handle.
Definition: smbios.h:16
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:861
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:141
Definition: efi.h:59
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:55

References cwuri, DBGC, EFI_LOADED_IMAGE_PROTOCOL::DeviceHandle, EFI_AUTOEXEC_NAME, EFI_AUTOEXEC_TIMEOUT, efi_handle_name(), efi_loaded_image, ENOTTY, handle, imgacquire(), mnptemp_create(), mnptemp_destroy(), netdev, netdev_open(), rc, strerror(), and sync().

◆ efi_autoexec_load()

int efi_autoexec_load ( void  )

Load autoexec script.

Return values
rcReturn status code

Definition at line 165 of file efi_autoexec.c.

165  {
168  struct efi_autoexec_loader *loader;
169  struct image *image;
170  unsigned int i;
171  int rc;
172 
173  /* Use first applicable loader */
174  for ( i = 0 ; i < ( sizeof ( efi_autoexec_loaders ) /
175  sizeof ( efi_autoexec_loaders[0] ) ) ; i ++ ) {
176 
177  /* Locate required protocol for this loader */
178  loader = &efi_autoexec_loaders[i];
179  if ( ( rc = efi_locate_device ( device, loader->protocol,
180  &handle, 0 ) ) != 0 ) {
181  DBGC ( device, "EFI %s found no %s: %s\n",
183  efi_guid_ntoa ( loader->protocol ),
184  strerror ( rc ) );
185  continue;
186  }
187  DBGC ( device, "EFI %s found %s on ",
189  efi_guid_ntoa ( loader->protocol ) );
190  DBGC ( device, "%s\n", efi_handle_name ( handle ) );
191 
192  /* Try loading */
193  if ( ( rc = loader->load ( handle, &image ) ) != 0 )
194  return rc;
195 
196  /* Discard zero-length images */
197  if ( ! image->len ) {
198  DBGC ( device, "EFI %s discarding zero-length %s\n",
201  return -ENOENT;
202  }
203 
204  DBGC ( device, "EFI %s loaded %s (%zd bytes)\n",
206  return 0;
207  }
208 
209  return -ENOENT;
210 }
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:37
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
An executable image.
Definition: image.h:24
EFI_GUID * protocol
Required protocol GUID.
Definition: efi_autoexec.c:54
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:808
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_debug.c:254
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
size_t len
Length of raw file image.
Definition: image.h:43
static struct efi_autoexec_loader efi_autoexec_loaders[]
Autoexec script loaders.
Definition: efi_autoexec.c:149
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:45
void unregister_image(struct image *image)
Unregister executable image.
Definition: image.c:303
int(* load)(EFI_HANDLE handle, struct image **image)
Load autoexec script.
Definition: efi_autoexec.c:62
uint16_t handle
Handle.
Definition: smbios.h:16
char * name
Name.
Definition: image.h:34
An EFI autoexec script loader.
Definition: efi_autoexec.c:52
Definition: efi.h:59
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:55

References DBGC, EFI_LOADED_IMAGE_PROTOCOL::DeviceHandle, efi_autoexec_loaders, efi_guid_ntoa(), efi_handle_name(), efi_loaded_image, efi_locate_device(), ENOENT, handle, image::len, efi_autoexec_loader::load, image::name, efi_autoexec_loader::protocol, rc, strerror(), and unregister_image().

Referenced by efi_probe().

Variable Documentation

◆ efi_autoexec_loaders

struct efi_autoexec_loader efi_autoexec_loaders[]
static
Initial value:
= {
{
},
{
},
}
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:255
static int efi_autoexec_filesystem(EFI_HANDLE handle, struct image **image)
Load autoexec script from filesystem.
Definition: efi_autoexec.c:72
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition: efi_guid.c:303
static int efi_autoexec_network(EFI_HANDLE handle, struct image **image)
Load autoexec script via temporary network device.
Definition: efi_autoexec.c:103

Autoexec script loaders.

Definition at line 149 of file efi_autoexec.c.

Referenced by efi_autoexec_load().