autoboot.h File Reference

Automatic booting. More...

#include <gpxe/in.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
void autoboot (void)
 Boot the system.
int boot_next_server_and_filename (struct in_addr next_server, const char *filename)
 Boot using next-server and filename.
int boot_root_path (const char *root_path)
 Boot using root path.
int pxe_menu_boot (struct net_device *netdev) __attribute__((weak))
 Boot using PXE boot menu.

Variables

int shutdown_exit_flags
 Shutdown flags for exit.


Detailed Description

Automatic booting.

Definition in file autoboot.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

void autoboot ( void   ) 

Boot the system.

Definition at line 215 of file autoboot.c.

References close_all_netdevs(), find_boot_netdev(), for_each_netdev, netboot(), netdev, and printf().

Referenced by autoboot_exec(), and main().

00215                        {
00216         struct net_device *boot_netdev;
00217         struct net_device *netdev;
00218 
00219         /* If we have an identifable boot device, try that first */
00220         close_all_netdevs();
00221         if ( ( boot_netdev = find_boot_netdev() ) )
00222                 netboot ( boot_netdev );
00223 
00224         /* If that fails, try booting from any of the other devices */
00225         for_each_netdev ( netdev ) {
00226                 if ( netdev == boot_netdev )
00227                         continue;
00228                 close_all_netdevs();
00229                 netboot ( netdev );
00230         }
00231 
00232         printf ( "No more network devices\n" );
00233 }

int boot_next_server_and_filename ( struct in_addr  next_server,
const char *  filename 
)

Boot using next-server and filename.

Parameters:
filename Boot filename
Return values:
rc Return status code

Definition at line 60 of file autoboot.c.

References alloc_image(), ENOMEM, image_put(), imgexec(), imgfetch(), inet_ntoa(), parse_uri(), register_and_autoload_image(), snprintf(), strlen(), uri_encode(), uri_is_absolute(), and URI_PATH.

Referenced by netboot(), and pxe_menu_boot().

00061                                                            {
00062         struct uri *uri;
00063         struct image *image;
00064         char buf[ 23 /* tftp://xxx.xxx.xxx.xxx/ */ +
00065                   ( 3 * strlen(filename) ) /* completely URI-encoded */
00066                   + 1 /* NUL */ ];
00067         int filename_is_absolute;
00068         int rc;
00069 
00070         /* Construct URI */
00071         uri = parse_uri ( filename );
00072         if ( ! uri )
00073                 return -ENOMEM;
00074         filename_is_absolute = uri_is_absolute ( uri );
00075         uri_put ( uri );
00076         if ( ! filename_is_absolute ) {
00077                 /* Construct a tftp:// URI for the filename.  We can't
00078                  * just rely on the current working URI, because the
00079                  * relative URI resolution will remove the distinction
00080                  * between filenames with and without initial slashes,
00081                  * which is significant for TFTP.
00082                  */
00083                 snprintf ( buf, sizeof ( buf ), "tftp://%s/",
00084                            inet_ntoa ( next_server ) );
00085                 uri_encode ( filename, buf + strlen ( buf ),
00086                              sizeof ( buf ) - strlen ( buf ), URI_PATH );
00087                 filename = buf;
00088         }
00089 
00090         image = alloc_image();
00091         if ( ! image )
00092                 return -ENOMEM;
00093         if ( ( rc = imgfetch ( image, filename,
00094                                register_and_autoload_image ) ) != 0 ) {
00095                 goto done;
00096         }
00097         if ( ( rc = imgexec ( image ) ) != 0 )
00098                 goto done;
00099 
00100  done:
00101         image_put ( image );
00102         return rc;
00103 }

int boot_root_path ( const char *  root_path  ) 

Boot using root path.

Parameters:
root_path Root path
Return values:
rc Return status code

Definition at line 111 of file autoboot.c.

References sanboot_protocol::boot, ENOTSUP, for_each_table_entry, sanboot_protocol::prefix, SANBOOT_PROTOCOLS, strlen(), and strncmp().

Referenced by netboot(), and sanboot_exec().

00111                                              {
00112         struct sanboot_protocol *sanboot;
00113 
00114         /* Quick hack */
00115         for_each_table_entry ( sanboot, SANBOOT_PROTOCOLS ) {
00116                 if ( strncmp ( root_path, sanboot->prefix,
00117                                strlen ( sanboot->prefix ) ) == 0 ) {
00118                         return sanboot->boot ( root_path );
00119                 }
00120         }
00121 
00122         return -ENOTSUP;
00123 }

int pxe_menu_boot ( struct net_device netdev  ) 

Boot using PXE boot menu.

Return values:
rc Return status code
Note that a success return status indicates that a PXE boot menu item has been selected, and that the DHCP session should perform a boot server request/ack.

Definition at line 345 of file pxemenu.c.

References assert, boot_next_server_and_filename(), fetch_ipv4_setting(), fetch_string_setting(), find_settings(), free(), pxe_menu::items, pxe_menu_parse(), pxe_menu_prompt_and_select(), pxebs(), PXEBS_SETTINGS_NAME, pxe_menu::selection, and pxe_menu_item::type.

Referenced by netboot().

00345                                                 {
00346         struct pxe_menu *menu;
00347         unsigned int pxe_type;
00348         struct settings *pxebs_settings;
00349         struct in_addr next_server;
00350         char filename[256];
00351         int rc;
00352 
00353         /* Parse and allocate boot menu */
00354         if ( ( rc = pxe_menu_parse ( &menu ) ) != 0 )
00355                 return rc;
00356 
00357         /* Make selection from boot menu */
00358         if ( ( rc = pxe_menu_prompt_and_select ( menu ) ) != 0 ) {
00359                 free ( menu );
00360                 return rc;
00361         }
00362         pxe_type = menu->items[menu->selection].type;
00363 
00364         /* Free boot menu */
00365         free ( menu );
00366 
00367         /* Return immediately if local boot selected */
00368         if ( ! pxe_type )
00369                 return 0;
00370 
00371         /* Attempt PXE Boot Server Discovery */
00372         if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 )
00373                 return rc;
00374 
00375         /* Attempt boot */
00376         pxebs_settings = find_settings ( PXEBS_SETTINGS_NAME );
00377         assert ( pxebs_settings );
00378         fetch_ipv4_setting ( pxebs_settings, &next_server_setting,
00379                              &next_server );
00380         fetch_string_setting ( pxebs_settings, &filename_setting,
00381                                filename, sizeof ( filename ) );
00382         return boot_next_server_and_filename ( next_server, filename );
00383 }


Variable Documentation

Shutdown flags for exit.

Definition at line 43 of file autoboot.c.

Referenced by keep_san(), and main().


Generated on Tue Apr 6 20:01:53 2010 for gPXE by  doxygen 1.5.7.1