iPXE
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   ( 30 * TICKS_PER_SEC )
 Timeout for autoexec script downloads.
#define EFI_AUTOEXEC_SYNC_TIMEOUT   ( 1 * TICKS_PER_SEC )
 Timeout for autoexec pending operation completion.
#define EFI_AUTOEXEC_NAME   "autoexec.ipxe"
 Autoexec script image name.

Functions

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

Variables

static struct efi_autoexec_loader efi_autoexec_loaders []
 Autoexec script loaders.

Detailed Description

EFI autoexec script.

Definition in file efi_autoexec.c.

Macro Definition Documentation

◆ EFI_AUTOEXEC_TIMEOUT

#define EFI_AUTOEXEC_TIMEOUT   ( 30 * TICKS_PER_SEC )

Timeout for autoexec script downloads.

Definition at line 47 of file efi_autoexec.c.

Referenced by efi_autoexec_filesystem(), and efi_autoexec_network().

◆ EFI_AUTOEXEC_SYNC_TIMEOUT

#define EFI_AUTOEXEC_SYNC_TIMEOUT   ( 1 * TICKS_PER_SEC )

Timeout for autoexec pending operation completion.

Definition at line 50 of file efi_autoexec.c.

Referenced by efi_autoexec_network().

◆ EFI_AUTOEXEC_NAME

#define EFI_AUTOEXEC_NAME   "autoexec.ipxe"

Autoexec script image name.

Definition at line 53 of file efi_autoexec.c.

Referenced by efi_autoexec_filesystem(), and efi_autoexec_network().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ efi_autoexec_filesystem()

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 76 of file efi_autoexec.c.

76 {
77 EFI_HANDLE device = efi_loaded_image->DeviceHandle;
78 int rc;
79
80 /* Check that we were loaded from a filesystem */
81 if ( handle != device ) {
82 DBGC ( device, "EFI %s is not the file system handle\n",
84 return -ENOTTY;
85 }
86
87 /* Try loading from loaded image directory, if supported */
88 if ( ( rc = imgacquire ( "file:" EFI_AUTOEXEC_NAME,
89 EFI_AUTOEXEC_TIMEOUT, image ) ) == 0 )
90 return 0;
91
92 /* Try loading from root directory, if supported */
93 if ( ( rc = imgacquire ( "file:/" EFI_AUTOEXEC_NAME,
94 EFI_AUTOEXEC_TIMEOUT, image ) ) == 0 )
95 return 0;
96
97 return rc;
98}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define EFI_AUTOEXEC_TIMEOUT
Timeout for autoexec script downloads.
#define EFI_AUTOEXEC_NAME
Autoexec script image name.
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition efi_debug.c:652
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition efi_init.c:39
#define DBGC(...)
Definition compiler.h:505
#define ENOTTY
Inappropriate I/O control operation.
Definition errno.h:595
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition imgmgmt.c:143
#define EFI_HANDLE
Definition efi.h:53
uint16_t handle
Handle.
Definition smbios.h:5
A hardware device.
Definition device.h:77
An executable image.
Definition image.h:24

References DBGC, EFI_AUTOEXEC_NAME, EFI_AUTOEXEC_TIMEOUT, EFI_HANDLE, efi_handle_name(), efi_loaded_image, ENOTTY, handle, imgacquire(), and rc.

◆ efi_autoexec_network()

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 107 of file efi_autoexec.c.

107 {
108 EFI_HANDLE device = efi_loaded_image->DeviceHandle;
109 struct net_device *netdev;
110 int rc;
111
112 /* Create temporary network device */
113 if ( ( rc = mnptemp_create ( handle, &netdev ) ) != 0 ) {
114 DBGC ( device, "EFI %s could not create net device: %s\n",
116 goto err_create;
117 }
118
119 /* Do nothing unless we have a usable current working URI */
120 if ( ! cwuri ) {
121 DBGC ( device, "EFI %s has no current working URI\n",
123 rc = -ENOTTY;
124 goto err_cwuri;
125 }
126
127 /* Open network device */
128 if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
129 DBGC ( device, "EFI %s could not open net device: %s\n",
131 goto err_open;
132 }
133
134 /* Attempt download from current working URI, then from root */
136 image ) != 0 ) &&
138 image ) != 0 ) ) {
139 DBGC ( device, "EFI %s could not download [/]%s: %s\n",
141 strerror ( rc ) );
142 goto err_acquire;
143 }
144
145 err_acquire:
146 /* Ensure network exchanges have completed */
148 err_open:
149 err_cwuri:
151 err_create:
152 return rc;
153}
struct uri * cwuri
Current working URI.
Definition cwuri.c:39
#define EFI_AUTOEXEC_SYNC_TIMEOUT
Timeout for autoexec pending operation completion.
static struct net_device * netdev
Definition gdbudp.c:53
void mnptemp_destroy(struct net_device *netdev)
Destroy temporary MNP network device.
Definition mnpnet.c:541
int mnptemp_create(EFI_HANDLE handle, struct net_device **netdev)
Create temporary MNP network device.
Definition mnpnet.c:504
int netdev_open(struct net_device *netdev)
Open network device.
Definition netdevice.c:866
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A network device.
Definition netdevice.h:353
int sync(unsigned long timeout)
Wait for pending operations to complete.
Definition sync.c:74

References cwuri, DBGC, EFI_AUTOEXEC_NAME, EFI_AUTOEXEC_SYNC_TIMEOUT, EFI_AUTOEXEC_TIMEOUT, EFI_HANDLE, 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 172 of file efi_autoexec.c.

172 {
173 EFI_HANDLE device = efi_loaded_image->DeviceHandle;
175 struct efi_autoexec_loader *loader;
176 struct image *image;
177 unsigned int i;
178 int rc;
179
180 /* Use first applicable loader */
181 for ( i = 0 ; i < ( sizeof ( efi_autoexec_loaders ) /
182 sizeof ( efi_autoexec_loaders[0] ) ) ; i ++ ) {
183
184 /* Locate required protocol for this loader */
185 loader = &efi_autoexec_loaders[i];
186 if ( ( rc = efi_locate_device ( device, loader->protocol,
187 &handle, 0 ) ) != 0 ) {
188 DBGC ( device, "EFI %s found no %s: %s\n",
190 efi_guid_ntoa ( loader->protocol ),
191 strerror ( rc ) );
192 continue;
193 }
194 DBGC ( device, "EFI %s found %s on ",
196 efi_guid_ntoa ( loader->protocol ) );
197 DBGC ( device, "%s\n", efi_handle_name ( handle ) );
198
199 /* Try loading */
200 if ( ( rc = loader->load ( handle, &image ) ) != 0 )
201 continue;
202
203 /* Discard zero-length images */
204 if ( ! image->len ) {
205 DBGC ( device, "EFI %s discarding zero-length %s\n",
208 return -ENOENT;
209 }
210
211 DBGC ( device, "EFI %s loaded %s (%zd bytes)\n",
213 return 0;
214 }
215
216 return -ENOENT;
217}
static struct efi_autoexec_loader efi_autoexec_loaders[]
Autoexec script loaders.
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition efi_guid.c:726
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:46
#define ENOENT
No such file or directory.
Definition errno.h:515
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:358
An EFI autoexec script loader.
EFI_GUID * protocol
Required protocol GUID.
int(* load)(EFI_HANDLE handle, struct image **image)
Load autoexec script.
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:56

References DBGC, efi_autoexec_loaders, efi_guid_ntoa(), EFI_HANDLE, 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:
= {
{
},
{
},
}
static int efi_autoexec_filesystem(EFI_HANDLE handle, struct image **image)
Load autoexec script from filesystem.
static int efi_autoexec_network(EFI_HANDLE handle, struct image **image)
Load autoexec script via temporary network device.
EFI_GUID efi_simple_file_system_protocol_guid
Simple file system protocol GUID.
Definition efi_guid.c:337
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition efi_guid.c:285

Autoexec script loaders.

Definition at line 156 of file efi_autoexec.c.

156 {
157 {
160 },
161 {
163 .load = efi_autoexec_network,
164 },
165};

Referenced by efi_autoexec_load().