iPXE
Macros | Functions | Variables
autoboot.c File Reference

Automatic booting. More...

#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <ipxe/netdevice.h>
#include <ipxe/vlan.h>
#include <ipxe/dhcp.h>
#include <ipxe/settings.h>
#include <ipxe/image.h>
#include <ipxe/sanboot.h>
#include <ipxe/uri.h>
#include <ipxe/open.h>
#include <ipxe/init.h>
#include <ipxe/keys.h>
#include <ipxe/version.h>
#include <ipxe/shell.h>
#include <ipxe/features.h>
#include <ipxe/timer.h>
#include <usr/ifmgmt.h>
#include <usr/route.h>
#include <usr/imgmgmt.h>
#include <usr/prompt.h>
#include <usr/autoboot.h>
#include <config/general.h>
#include <config/branding.h>

Go to the source code of this file.

Macros

#define ENOENT_BOOT   __einfo_error ( EINFO_ENOENT_BOOT )
 
#define EINFO_ENOENT_BOOT   __einfo_uniqify ( EINFO_ENOENT, 0x01, "Nothing to boot" )
 
#define NORMAL   "\033[0m"
 
#define BOLD   "\033[1m"
 
#define CYAN   "\033[36m"
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
const struct setting scriptlet_setting __setting (SETTING_MISC, scriptlet)
 The "scriptlet" setting. More...
 
__weak int pxe_menu_boot (struct net_device *netdev __unused)
 Perform PXE menu boot when PXE stack is not available. More...
 
const struct setting keep_san_setting __setting (SETTING_SANBOOT_EXTRA, keep-san)
 The "keep-san" setting. More...
 
const struct setting skip_san_boot_setting __setting (SETTING_SANBOOT_EXTRA, skip-san-boot)
 The "skip-san-boot" setting. More...
 
int uriboot (struct uri *filename, struct uri **root_paths, unsigned int root_path_count, int drive, const char *san_filename, unsigned int flags)
 Boot from filename and root-path URIs. More...
 
static void close_other_netdevs (struct net_device *netdev)
 Close all but one network device. More...
 
struct urifetch_next_server_and_filename (struct settings *settings)
 Fetch next-server and filename settings into a URI. More...
 
static struct urifetch_root_path (struct settings *settings)
 Fetch root-path setting into a URI. More...
 
static char * fetch_san_filename (struct settings *settings)
 Fetch san-filename setting. More...
 
static int have_pxe_menu (void)
 Check whether or not we have a usable PXE menu. More...
 
int netboot (struct net_device *netdev)
 Boot from a network device. More...
 
static int is_autoboot_busloc (struct net_device *netdev)
 Test if network device matches the autoboot device bus type and location. More...
 
void set_autoboot_busloc (unsigned int bus_type, unsigned int location)
 Identify autoboot device by bus type and location. More...
 
static int is_autoboot_ll_addr (struct net_device *netdev)
 Test if network device matches the autoboot device link-layer address. More...
 
void set_autoboot_ll_addr (const void *ll_addr, size_t len, unsigned int vlan)
 Identify autoboot device by link-layer address. More...
 
static int autoboot (void)
 Boot the system. More...
 
static int shell_banner (void)
 Prompt for shell entry. More...
 
int ipxe (struct net_device *netdev)
 Main iPXE flow of execution. More...
 

Variables

static uint8_t autoboot_ll_addr [MAX_LL_ADDR_LEN]
 Link-layer address of preferred autoboot device, if known. More...
 
static unsigned int autoboot_vlan
 VLAN tag of preferred autoboot device, if known. More...
 
static struct device_description autoboot_desc
 Device location of preferred autoboot device, if known. More...
 
static int(* is_autoboot_device )(struct net_device *netdev)
 Autoboot device tester. More...
 

Detailed Description

Automatic booting.

Definition in file autoboot.c.

Macro Definition Documentation

◆ ENOENT_BOOT

#define ENOENT_BOOT   __einfo_error ( EINFO_ENOENT_BOOT )

Definition at line 71 of file autoboot.c.

◆ EINFO_ENOENT_BOOT

#define EINFO_ENOENT_BOOT   __einfo_uniqify ( EINFO_ENOENT, 0x01, "Nothing to boot" )

Definition at line 72 of file autoboot.c.

◆ NORMAL

#define NORMAL   "\033[0m"

Definition at line 75 of file autoboot.c.

◆ BOLD

#define BOLD   "\033[1m"

Definition at line 76 of file autoboot.c.

◆ CYAN

#define CYAN   "\033[36m"

Definition at line 77 of file autoboot.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __setting() [1/3]

const struct setting scriptlet_setting __setting ( SETTING_MISC  ,
scriptlet   
)

The "scriptlet" setting.

◆ pxe_menu_boot()

__weak int pxe_menu_boot ( struct net_device *netdev  __unused)

Perform PXE menu boot when PXE stack is not available.

Definition at line 90 of file autoboot.c.

90  {
91  return -ENOTSUP;
92 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

Referenced by netboot().

◆ __setting() [2/3]

const struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA  ,
keep-  san 
)

The "keep-san" setting.

◆ __setting() [3/3]

const struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA  ,
skip-san-  boot 
)

The "skip-san-boot" setting.

◆ uriboot()

int uriboot ( struct uri filename,
struct uri **  root_paths,
unsigned int  root_path_count,
int  drive,
const char *  san_filename,
unsigned int  flags 
)

Boot from filename and root-path URIs.

Parameters
filenameFilename
root_pathsRoot path(s)
root_path_countNumber of root paths
driveSAN drive (if applicable)
san_filenameSAN filename (or NULL to use default)
flagsBoot action flags
Return values
rcReturn status code

The somewhat tortuous flow of control in this function exists in order to ensure that the "sanboot" command remains identical in function to a SAN boot via a DHCP-specified root path, and to provide backwards compatibility for the "keep-san" and "skip-san-boot" options.

Definition at line 129 of file autoboot.c.

131  {
132  struct image *image;
133  int rc;
134 
135  /* Hook SAN device, if applicable */
136  if ( root_path_count ) {
137  drive = san_hook ( drive, root_paths, root_path_count,
139  SAN_NO_DESCRIBE : 0 ) );
140  if ( drive < 0 ) {
141  rc = drive;
142  printf ( "Could not open SAN device: %s\n",
143  strerror ( rc ) );
144  goto err_san_hook;
145  }
146  printf ( "Registered SAN device %#02x\n", drive );
147  }
148 
149  /* Describe SAN device, if applicable */
150  if ( ! ( flags & URIBOOT_NO_SAN_DESCRIBE ) ) {
151  if ( ( rc = san_describe() ) != 0 ) {
152  printf ( "Could not describe SAN devices: %s\n",
153  strerror ( rc ) );
154  goto err_san_describe;
155  }
156  }
157 
158  /* Allow a root-path-only boot with skip-san enabled to succeed */
159  rc = 0;
160 
161  /* Attempt filename boot if applicable */
162  if ( filename ) {
163  if ( ( rc = imgdownload ( filename, 0, &image ) ) != 0 )
164  goto err_download;
165  imgstat ( image );
167  if ( ( rc = image_exec ( image ) ) != 0 ) {
168  printf ( "Could not boot image: %s\n",
169  strerror ( rc ) );
170  /* Fall through to (possibly) attempt a SAN boot
171  * as a fallback. If no SAN boot is attempted,
172  * our status will become the return status.
173  */
174  } else {
175  /* Always print an extra newline, because we
176  * don't know where the NBP may have left the
177  * cursor.
178  */
179  printf ( "\n" );
180  }
181  }
182 
183  /* Attempt SAN boot if applicable */
184  if ( ! ( flags & URIBOOT_NO_SAN_BOOT ) ) {
185  if ( fetch_intz_setting ( NULL, &skip_san_boot_setting) == 0 ) {
186  printf ( "Booting%s%s from SAN device %#02x\n",
187  ( san_filename ? " " : "" ),
188  ( san_filename ? san_filename : "" ), drive );
189  rc = san_boot ( drive, san_filename );
190  printf ( "Boot from SAN device %#02x failed: %s\n",
191  drive, strerror ( rc ) );
192  } else {
193  printf ( "Skipping boot from SAN device %#02x\n",
194  drive );
195  /* Avoid overwriting a possible failure status
196  * from a filename boot.
197  */
198  }
199  }
200 
201  err_download:
202  err_san_describe:
203  /* Unhook SAN device, if applicable */
204  if ( ! ( flags & URIBOOT_NO_SAN_UNHOOK ) ) {
205  if ( fetch_intz_setting ( NULL, &keep_san_setting ) == 0 ) {
206  san_unhook ( drive );
207  printf ( "Unregistered SAN device %#02x\n", drive );
208  } else {
209  printf ( "Preserving SAN device %#02x\n", drive );
210  }
211  }
212  err_san_hook:
213  return rc;
214 }
long fetch_intz_setting(struct settings *settings, const struct setting *setting)
Fetch value of signed integer setting, or zero.
Definition: settings.c:1053
unsigned int flags
Flags.
Definition: image.h:36
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int san_describe(void)
Describe SAN devices for SAN-booted operating system.
int san_hook(unsigned int drive, struct uri **uris, unsigned int count, unsigned int flags)
Hook SAN device.
int san_boot(unsigned int drive, const char *filename)
Attempt to boot from a SAN device.
An executable image.
Definition: image.h:24
uint8_t drive
Drive number.
Definition: int13.h:16
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition: image.h:73
int image_exec(struct image *image)
Execute image.
Definition: image.c:333
void imgstat(struct image *image)
Display status of an image.
Definition: imgmgmt.c:158
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
Device should not be included in description tables.
Definition: sanboot.h:95
void san_unhook(unsigned int drive)
Unhook SAN device.
int imgdownload(struct uri *uri, unsigned long timeout, struct image **image)
Download a new image.
Definition: imgmgmt.c:51
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t flags
Flags.
Definition: ena.h:18

References drive, fetch_intz_setting(), flags, image::flags, IMAGE_AUTO_UNREGISTER, image_exec(), imgdownload(), imgstat(), NULL, printf(), rc, san_boot(), san_describe(), san_hook(), SAN_NO_DESCRIBE, san_unhook(), strerror(), URIBOOT_NO_SAN_BOOT, URIBOOT_NO_SAN_DESCRIBE, and URIBOOT_NO_SAN_UNHOOK.

Referenced by netboot(), pxe_menu_boot(), and sanboot_core_exec().

◆ close_other_netdevs()

static void close_other_netdevs ( struct net_device netdev)
static

Close all but one network device.

Called before a fresh boot attempt in order to free up memory. We don't just close the device immediately after the boot fails, because there may still be TCP connections in the process of closing.

Definition at line 224 of file autoboot.c.

224  {
225  struct net_device *other;
226 
227  for_each_netdev ( other ) {
228  if ( other != netdev )
229  ifclose ( other );
230  }
231 }
void ifclose(struct net_device *netdev)
Close network device.
Definition: ifmgmt.c:82
static struct net_device * netdev
Definition: gdbudp.c:52
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:538
A network device.
Definition: netdevice.h:352

References for_each_netdev, ifclose(), and netdev.

Referenced by netboot().

◆ fetch_next_server_and_filename()

struct uri* fetch_next_server_and_filename ( struct settings settings)

Fetch next-server and filename settings into a URI.

Parameters
settingsSettings block
Return values
uriURI, or NULL on failure

Definition at line 239 of file autoboot.c.

239  {
240  union {
241  struct sockaddr sa;
242  struct sockaddr_in sin;
243  } next_server;
244  char *raw_filename = NULL;
245  struct uri *uri = NULL;
246  char *filename;
247 
248  /* Initialise server address */
249  memset ( &next_server, 0, sizeof ( next_server ) );
250 
251  /* If we have a filename, fetch it along with the next-server
252  * setting from the same settings block.
253  */
254  if ( fetch_setting ( settings, &filename_setting, &settings,
255  NULL, NULL, 0 ) >= 0 ) {
256  fetch_string_setting_copy ( settings, &filename_setting,
257  &raw_filename );
258  fetch_ipv4_setting ( settings, &next_server_setting,
259  &next_server.sin.sin_addr );
260  }
261  if ( ! raw_filename )
262  goto err_fetch;
263 
264  /* Populate server address */
265  if ( next_server.sin.sin_addr.s_addr ) {
266  next_server.sin.sin_family = AF_INET;
267  printf ( "Next server: %s\n",
268  inet_ntoa ( next_server.sin.sin_addr ) );
269  }
270 
271  /* Expand filename setting */
272  filename = expand_settings ( raw_filename );
273  if ( ! filename )
274  goto err_expand;
275  if ( filename[0] )
276  printf ( "Filename: %s\n", filename );
277 
278  /* Construct URI */
279  uri = pxe_uri ( &next_server.sa, filename );
280  if ( ! uri )
281  goto err_parse;
282 
283  err_parse:
284  free ( filename );
285  err_expand:
286  free ( raw_filename );
287  err_fetch:
288  return uri;
289 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:912
struct uri * pxe_uri(struct sockaddr *sa_server, const char *filename)
Construct URI from server address and filename.
Definition: uri.c:808
IPv4 socket address.
Definition: in.h:82
char * expand_settings(const char *string)
Expand variables within string.
Definition: settings.c:2297
struct sockaddr sa
Definition: syslog.c:55
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:873
Generalized socket address structure.
Definition: socket.h:96
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:658
A settings block.
Definition: settings.h:132
A Uniform Resource Identifier.
Definition: uri.h:64
struct sockaddr_in sin
Definition: syslog.c:57
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
void * memset(void *dest, int character, size_t len) __nonnull

References AF_INET, expand_settings(), fetch_ipv4_setting(), fetch_setting(), fetch_string_setting_copy(), free, inet_ntoa(), memset(), NULL, printf(), pxe_uri(), sa, and sin.

Referenced by netboot(), and pxe_menu_boot().

◆ fetch_root_path()

static struct uri* fetch_root_path ( struct settings settings)
static

Fetch root-path setting into a URI.

Parameters
settingsSettings block
Return values
uriURI, or NULL on failure

Definition at line 297 of file autoboot.c.

297  {
298  struct uri *uri = NULL;
299  char *raw_root_path;
300  char *root_path;
301 
302  /* Fetch root-path setting */
303  fetch_string_setting_copy ( settings, &root_path_setting,
304  &raw_root_path );
305  if ( ! raw_root_path )
306  goto err_fetch;
307 
308  /* Expand filename setting */
309  root_path = expand_settings ( raw_root_path );
310  if ( ! root_path )
311  goto err_expand;
312  if ( root_path[0] )
313  printf ( "Root path: %s\n", root_path );
314 
315  /* Parse root path */
316  uri = parse_uri ( root_path );
317  if ( ! uri )
318  goto err_parse;
319 
320  err_parse:
321  free ( root_path );
322  err_expand:
323  free ( raw_root_path );
324  err_fetch:
325  return uri;
326 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
char * expand_settings(const char *string)
Expand variables within string.
Definition: settings.c:2297
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:873
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
A Uniform Resource Identifier.
Definition: uri.h:64
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:296

References expand_settings(), fetch_string_setting_copy(), free, NULL, parse_uri(), and printf().

Referenced by netboot().

◆ fetch_san_filename()

static char* fetch_san_filename ( struct settings settings)
static

Fetch san-filename setting.

Parameters
settingsSettings block
Return values
san_filenameSAN filename, or NULL on failure

Definition at line 334 of file autoboot.c.

334  {
335  char *raw_san_filename;
336  char *san_filename = NULL;
337 
338  /* Fetch san-filename setting */
339  fetch_string_setting_copy ( settings, &san_filename_setting,
340  &raw_san_filename );
341  if ( ! raw_san_filename )
342  goto err_fetch;
343 
344  /* Expand san-filename setting */
345  san_filename = expand_settings ( raw_san_filename );
346  if ( ! san_filename )
347  goto err_expand;
348  if ( san_filename[0] )
349  printf ( "SAN filename: %s\n", san_filename );
350 
351  err_expand:
352  free ( raw_san_filename );
353  err_fetch:
354  return san_filename;
355 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
char * expand_settings(const char *string)
Expand variables within string.
Definition: settings.c:2297
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:873
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References expand_settings(), fetch_string_setting_copy(), free, NULL, and printf().

Referenced by netboot().

◆ have_pxe_menu()

static int have_pxe_menu ( void  )
static

Check whether or not we have a usable PXE menu.

Return values
have_menuA usable PXE menu is present

Definition at line 362 of file autoboot.c.

362  {
363  struct setting vendor_class_id_setting
364  = { .tag = DHCP_VENDOR_CLASS_ID };
365  struct setting pxe_discovery_control_setting
367  struct setting pxe_boot_menu_setting
368  = { .tag = DHCP_PXE_BOOT_MENU };
369  char buf[ 10 /* "PXEClient" + NUL */ ];
370  unsigned int pxe_discovery_control;
371 
372  fetch_string_setting ( NULL, &vendor_class_id_setting,
373  buf, sizeof ( buf ) );
374  pxe_discovery_control =
375  fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
376 
377  return ( ( strcmp ( buf, "PXEClient" ) == 0 ) &&
378  setting_exists ( NULL, &pxe_boot_menu_setting ) &&
379  ( ! ( ( pxe_discovery_control & PXEBS_SKIP ) &&
380  setting_exists ( NULL, &filename_setting ) ) ) );
381 }
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition: settings.c:841
unsigned long fetch_uintz_setting(struct settings *settings, const struct setting *setting)
Fetch value of unsigned integer setting, or zero.
Definition: settings.c:1068
#define DHCP_PXE_BOOT_MENU
PXE boot menu.
Definition: dhcp.h:124
A setting.
Definition: settings.h:23
static int setting_exists(struct settings *settings, const struct setting *setting)
Check existence of predefined setting.
Definition: settings.h:539
#define DHCP_VENDOR_CLASS_ID
Vendor class identifier.
Definition: dhcp.h:214
Skip discovery if filename present.
Definition: dhcp.h:104
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
#define DHCP_PXE_DISCOVERY_CONTROL
PXE boot server discovery control.
Definition: dhcp.h:93
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References DHCP_PXE_BOOT_MENU, DHCP_PXE_DISCOVERY_CONTROL, DHCP_VENDOR_CLASS_ID, fetch_string_setting(), fetch_uintz_setting(), NULL, PXEBS_SKIP, setting_exists(), strcmp(), and setting::tag.

Referenced by netboot().

◆ netboot()

int netboot ( struct net_device netdev)

Boot from a network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 389 of file autoboot.c.

389  {
390  struct uri *filename;
391  struct uri *root_path;
392  char *san_filename;
393  int rc;
394 
395  /* Close all other network devices */
397 
398  /* Open device and display device status */
399  if ( ( rc = ifopen ( netdev ) ) != 0 )
400  goto err_ifopen;
401  ifstat ( netdev );
402 
403  /* Configure device */
404  if ( ( rc = ifconf ( netdev, NULL, 0 ) ) != 0 )
405  goto err_dhcp;
406  route();
407 
408  /* Try PXE menu boot, if applicable */
409  if ( have_pxe_menu() ) {
410  printf ( "Booting from PXE menu\n" );
411  rc = pxe_menu_boot ( netdev );
412  goto err_pxe_menu_boot;
413  }
414 
415  /* Fetch next server and filename (if any) */
416  filename = fetch_next_server_and_filename ( NULL );
417 
418  /* Fetch root path (if any) */
419  root_path = fetch_root_path ( NULL );
420 
421  /* Fetch SAN filename (if any) */
422  san_filename = fetch_san_filename ( NULL );
423 
424  /* If we have both a filename and a root path, ignore an
425  * unsupported or missing URI scheme in the root path, since
426  * it may represent an NFS root.
427  */
428  if ( filename && root_path &&
429  ( ( ! uri_is_absolute ( root_path ) ) ||
430  ( xfer_uri_opener ( root_path->scheme ) == NULL ) ) ) {
431  printf ( "Ignoring unsupported root path\n" );
432  uri_put ( root_path );
433  root_path = NULL;
434  }
435 
436  /* Check that we have something to boot */
437  if ( ! ( filename || root_path ) ) {
438  rc = -ENOENT_BOOT;
439  printf ( "Nothing to boot: %s\n", strerror ( rc ) );
440  goto err_no_boot;
441  }
442 
443  /* Boot using next server, filename and root path */
444  if ( ( rc = uriboot ( filename, &root_path, ( root_path ? 1 : 0 ),
445  san_default_drive(), san_filename,
446  ( root_path ? 0 : URIBOOT_NO_SAN ) ) ) != 0 )
447  goto err_uriboot;
448 
449  err_uriboot:
450  err_no_boot:
451  free ( san_filename );
452  uri_put ( root_path );
453  uri_put ( filename );
454  err_pxe_menu_boot:
455  err_dhcp:
456  err_ifopen:
457  return rc;
458 }
#define URIBOOT_NO_SAN
Definition: autoboot.h:25
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int ifconf(struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout)
Perform network device configuration.
Definition: ifmgmt.c:274
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
static void close_other_netdevs(struct net_device *netdev)
Close all but one network device.
Definition: autoboot.c:224
static int uri_is_absolute(const struct uri *uri)
URI is an absolute URI.
Definition: uri.h:135
unsigned int san_default_drive(void)
Get default SAN drive number.
Definition: sanboot.c:956
int uriboot(struct uri *filename, struct uri **root_paths, unsigned int root_path_count, int drive, const char *san_filename, unsigned int flags)
Boot from filename and root-path URIs.
Definition: autoboot.c:129
const char * scheme
Scheme.
Definition: uri.h:68
struct uri * fetch_next_server_and_filename(struct settings *settings)
Fetch next-server and filename settings into a URI.
Definition: autoboot.c:239
static struct net_device * netdev
Definition: gdbudp.c:52
void route(void)
Print routing table.
Definition: route.c:39
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static struct uri * fetch_root_path(struct settings *settings)
Fetch root-path setting into a URI.
Definition: autoboot.c:297
static char * fetch_san_filename(struct settings *settings)
Fetch san-filename setting.
Definition: autoboot.c:334
__weak int pxe_menu_boot(struct net_device *netdev __unused)
Perform PXE menu boot when PXE stack is not available.
Definition: autoboot.c:90
int ifopen(struct net_device *netdev)
Open network device.
Definition: ifmgmt.c:65
static int have_pxe_menu(void)
Check whether or not we have a usable PXE menu.
Definition: autoboot.c:362
A Uniform Resource Identifier.
Definition: uri.h:64
struct uri_opener * xfer_uri_opener(const char *scheme)
Find opener for URI scheme.
Definition: open.c:47
void ifstat(struct net_device *netdev)
Print status of network device.
Definition: ifmgmt.c:110
#define ENOENT_BOOT
Definition: autoboot.c:71
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References close_other_netdevs(), ENOENT_BOOT, fetch_next_server_and_filename(), fetch_root_path(), fetch_san_filename(), free, have_pxe_menu(), ifconf(), ifopen(), ifstat(), netdev, NULL, printf(), pxe_menu_boot(), rc, route(), san_default_drive(), uri::scheme, strerror(), uri_is_absolute(), uri_put(), uriboot(), URIBOOT_NO_SAN, and xfer_uri_opener().

Referenced by autoboot(), autoboot_payload(), and ipxe().

◆ is_autoboot_busloc()

static int is_autoboot_busloc ( struct net_device netdev)
static

Test if network device matches the autoboot device bus type and location.

Parameters
netdevNetwork device
Return values
is_autobootNetwork device matches the autoboot device

Definition at line 466 of file autoboot.c.

466  {
467  struct device *dev;
468 
469  for ( dev = netdev->dev ; dev ; dev = dev->parent ) {
470  if ( ( dev->desc.bus_type == autoboot_desc.bus_type ) &&
471  ( dev->desc.location == autoboot_desc.location ) )
472  return 1;
473  }
474  return 0;
475 }
struct device * parent
Bus device.
Definition: device.h:85
A hardware device.
Definition: device.h:73
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int location
Location.
Definition: device.h:29
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
unsigned int bus_type
Bus type.
Definition: device.h:24
static struct device_description autoboot_desc
Device location of preferred autoboot device, if known.
Definition: autoboot.c:65
struct device_description desc
Device description.
Definition: device.h:79

References autoboot_desc, device_description::bus_type, device::desc, net_device::dev, device_description::location, netdev, and device::parent.

Referenced by set_autoboot_busloc().

◆ set_autoboot_busloc()

void set_autoboot_busloc ( unsigned int  bus_type,
unsigned int  location 
)

Identify autoboot device by bus type and location.

Parameters
bus_typeBus type
locationLocation

Definition at line 483 of file autoboot.c.

483  {
484 
485  /* Record autoboot device description */
486  autoboot_desc.bus_type = bus_type;
487  autoboot_desc.location = location;
488 
489  /* Mark autoboot device as present */
491 }
static int(* is_autoboot_device)(struct net_device *netdev)
Autoboot device tester.
Definition: autoboot.c:68
unsigned int location
Location.
Definition: device.h:29
unsigned int bus_type
Bus type.
Definition: device.h:24
static struct device_description autoboot_desc
Device location of preferred autoboot device, if known.
Definition: autoboot.c:65
static int is_autoboot_busloc(struct net_device *netdev)
Test if network device matches the autoboot device bus type and location.
Definition: autoboot.c:466

References autoboot_desc, device_description::bus_type, is_autoboot_busloc(), is_autoboot_device, and device_description::location.

Referenced by pci_autoboot_init().

◆ is_autoboot_ll_addr()

static int is_autoboot_ll_addr ( struct net_device netdev)
static

Test if network device matches the autoboot device link-layer address.

Parameters
netdevNetwork device
Return values
is_autobootNetwork device matches the autoboot device

Definition at line 499 of file autoboot.c.

499  {
500 
501  return ( ( memcmp ( netdev->ll_addr, autoboot_ll_addr,
502  netdev->ll_protocol->ll_addr_len ) == 0 ) &&
503  ( vlan_tag ( netdev ) == autoboot_vlan ) );
504 }
static unsigned int autoboot_vlan
VLAN tag of preferred autoboot device, if known.
Definition: autoboot.c:62
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static uint8_t autoboot_ll_addr[MAX_LL_ADDR_LEN]
Link-layer address of preferred autoboot device, if known.
Definition: autoboot.c:59
static struct net_device * netdev
Definition: gdbudp.c:52
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:73
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References autoboot_ll_addr, autoboot_vlan, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcmp(), netdev, and vlan_tag().

Referenced by set_autoboot_ll_addr().

◆ set_autoboot_ll_addr()

void set_autoboot_ll_addr ( const void *  ll_addr,
size_t  len,
unsigned int  vlan 
)

Identify autoboot device by link-layer address.

Parameters
ll_addrLink-layer address
lenLength of link-layer address
vlanVLAN tag

Definition at line 513 of file autoboot.c.

514  {
515 
516  /* Record autoboot link-layer address (truncated if necessary) */
517  if ( len > sizeof ( autoboot_ll_addr ) )
518  len = sizeof ( autoboot_ll_addr );
519  memcpy ( autoboot_ll_addr, ll_addr, len );
520 
521  /* Record autoboot VLAN tag */
522  autoboot_vlan = vlan;
523 
524  /* Mark autoboot device as present */
526 }
static unsigned int autoboot_vlan
VLAN tag of preferred autoboot device, if known.
Definition: autoboot.c:62
static uint8_t autoboot_ll_addr[MAX_LL_ADDR_LEN]
Link-layer address of preferred autoboot device, if known.
Definition: autoboot.c:59
static int is_autoboot_ll_addr(struct net_device *netdev)
Test if network device matches the autoboot device link-layer address.
Definition: autoboot.c:499
static int(* is_autoboot_device)(struct net_device *netdev)
Autoboot device tester.
Definition: autoboot.c:68
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t len
Length.
Definition: ena.h:14

References autoboot_ll_addr, autoboot_vlan, is_autoboot_device, is_autoboot_ll_addr(), len, and memcpy().

Referenced by efi_set_autoboot_ll_addr().

◆ autoboot()

static int autoboot ( void  )
static

Boot the system.

Definition at line 531 of file autoboot.c.

531  {
532  struct net_device *netdev;
533  int rc = -ENODEV;
534 
535  /* Try booting from each network device. If we have a
536  * specified autoboot device location, then use only devices
537  * matching that location.
538  */
539  for_each_netdev ( netdev ) {
540 
541  /* Skip any non-matching devices, if applicable */
542  if ( is_autoboot_device && ( ! is_autoboot_device ( netdev ) ) )
543  continue;
544 
545  /* Attempt booting from this device */
546  rc = netboot ( netdev );
547  }
548 
549  printf ( "No more network devices\n" );
550  return rc;
551 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int netboot(struct net_device *netdev)
Boot from a network device.
Definition: autoboot.c:389
static int(* is_autoboot_device)(struct net_device *netdev)
Autoboot device tester.
Definition: autoboot.c:68
static struct net_device * netdev
Definition: gdbudp.c:52
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:538
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509

References ENODEV, for_each_netdev, is_autoboot_device, netboot(), netdev, printf(), and rc.

Referenced by ipxe().

◆ shell_banner()

static int shell_banner ( void  )
static

Prompt for shell entry.

Return values
enter_shellUser wants to enter shell

Definition at line 558 of file autoboot.c.

558  {
559 
560  /* Skip prompt if timeout is zero */
561  if ( BANNER_TIMEOUT <= 0 )
562  return 0;
563 
564  /* Prompt user */
565  printf ( "\n" );
566  return ( prompt ( "Press Ctrl-B for the " PRODUCT_SHORT_NAME
567  " command line...",
568  ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ),
569  CTRL_B ) == 0 );
570 }
#define CTRL_B
Definition: keys.h:19
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
#define PRODUCT_SHORT_NAME
Definition: branding.h:28
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define BANNER_TIMEOUT
Definition: general.h:29
int prompt(const char *text, unsigned long timeout, int key)
Prompt for keypress.
Definition: prompt.c:48

References BANNER_TIMEOUT, CTRL_B, printf(), PRODUCT_SHORT_NAME, prompt(), and TICKS_PER_SEC.

Referenced by ipxe().

◆ ipxe()

int ipxe ( struct net_device netdev)

Main iPXE flow of execution.

Parameters
netdevNetwork device, or NULL
Return values
rcReturn status code

Definition at line 578 of file autoboot.c.

578  {
579  struct feature *feature;
580  struct image *image;
581  char *scriptlet;
582  int rc;
583 
584  /*
585  * Print welcome banner
586  *
587  *
588  * If you wish to brand this build of iPXE, please do so by
589  * defining the string PRODUCT_NAME in config/branding.h.
590  *
591  * While nothing in the GPL prevents you from removing all
592  * references to iPXE or https://ipxe.org, we prefer you not
593  * to do so.
594  *
595  */
596  printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD PRODUCT_SHORT_NAME " %s"
597  NORMAL " -- " PRODUCT_TAG_LINE " -- "
598  CYAN PRODUCT_URI NORMAL "\nFeatures:", product_version );
600  printf ( " %s", feature->name );
601  printf ( "\n" );
602 
603  /* Boot system */
604  if ( ( image = first_image() ) != NULL ) {
605  /* We have an embedded image; execute it */
606  return image_exec ( image );
607  } else if ( shell_banner() ) {
608  /* User wants shell; just give them a shell */
609  return shell();
610  } else {
611  fetch_string_setting_copy ( NULL, &scriptlet_setting,
612  &scriptlet );
613  if ( scriptlet ) {
614  /* User has defined a scriptlet; execute it */
615  rc = system ( scriptlet );
616  free ( scriptlet );
617  return rc;
618  } else {
619  /* Try booting. If booting fails, offer the
620  * user another chance to enter the shell.
621  */
622  if ( netdev ) {
623  rc = netboot ( netdev );
624  } else {
625  rc = autoboot();
626  }
627  if ( shell_banner() )
628  rc = shell();
629  return rc;
630  }
631  }
632 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char * name
Feature name.
Definition: features.h:80
#define PRODUCT_SHORT_NAME
Definition: branding.h:28
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
#define FEATURES
Named feature table.
Definition: features.h:84
int netboot(struct net_device *netdev)
Boot from a network device.
Definition: autoboot.c:389
#define NORMAL
Definition: autoboot.c:75
#define PRODUCT_URI
Definition: branding.h:29
int shell(void)
Start command shell.
Definition: shell.c:84
An executable image.
Definition: image.h:24
union ena_feature feature
Feature.
Definition: ena.h:14
#define CYAN
Definition: autoboot.c:77
int image_exec(struct image *image)
Execute image.
Definition: image.c:333
static struct net_device * netdev
Definition: gdbudp.c:52
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:873
static struct image * first_image(void)
Retrieve first image.
Definition: image.h:178
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
const char product_version[]
Product version string.
Definition: version.c:70
static int autoboot(void)
Boot the system.
Definition: autoboot.c:531
#define PRODUCT_TAG_LINE
Definition: branding.h:38
A named feature.
Definition: features.h:78
static int shell_banner(void)
Prompt for shell entry.
Definition: autoboot.c:558
#define PRODUCT_NAME
Definition: branding.h:27
#define BOLD
Definition: autoboot.c:76
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
uint8_t system[ETH_ALEN]
System identifier.
Definition: eth_slow.h:24

References autoboot(), BOLD, CYAN, feature, FEATURES, fetch_string_setting_copy(), first_image(), for_each_table_entry, free, image_exec(), feature::name, netboot(), netdev, NORMAL, NULL, printf(), PRODUCT_NAME, PRODUCT_SHORT_NAME, PRODUCT_TAG_LINE, PRODUCT_URI, product_version, rc, shell(), shell_banner(), and system.

Referenced by efi_snp_load_file(), and main().

Variable Documentation

◆ autoboot_ll_addr

uint8_t autoboot_ll_addr[MAX_LL_ADDR_LEN]
static

Link-layer address of preferred autoboot device, if known.

Definition at line 59 of file autoboot.c.

Referenced by is_autoboot_ll_addr(), and set_autoboot_ll_addr().

◆ autoboot_vlan

unsigned int autoboot_vlan
static

VLAN tag of preferred autoboot device, if known.

Definition at line 62 of file autoboot.c.

Referenced by is_autoboot_ll_addr(), and set_autoboot_ll_addr().

◆ autoboot_desc

struct device_description autoboot_desc
static

Device location of preferred autoboot device, if known.

Definition at line 65 of file autoboot.c.

Referenced by is_autoboot_busloc(), and set_autoboot_busloc().

◆ is_autoboot_device

int( * is_autoboot_device) (struct net_device *netdev)
static

Autoboot device tester.

Definition at line 68 of file autoboot.c.

Referenced by autoboot(), set_autoboot_busloc(), and set_autoboot_ll_addr().