123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
-
-
- #include <string.h>
- #include <stdio.h>
- #include <errno.h>
- #include <gpxe/netdevice.h>
- #include <gpxe/dhcp.h>
- #include <gpxe/image.h>
- #include <usr/ifmgmt.h>
- #include <usr/route.h>
- #include <usr/dhcpmgmt.h>
- #include <usr/imgmgmt.h>
- #include <usr/autoboot.h>
-
-
-
-
- static struct net_device * find_boot_netdev ( void ) {
- return NULL;
- }
-
-
- static struct net_device * next_netdev ( void ) {
- static struct net_device *last_netdev = NULL;
- struct net_device *netdev;
-
- for_each_netdev ( netdev ) {
- if ( ! last_netdev ) {
- last_netdev = netdev;
- return netdev;
- }
- if ( last_netdev == netdev )
- last_netdev = NULL;
- }
-
- last_netdev = NULL;
- return NULL;
- }
-
-
- void netboot ( struct net_device *netdev ) {
- char filename[256];
- struct image *image;
- int rc;
-
-
- if ( ( rc = ifopen ( netdev ) ) != 0 )
- return;
- ifstat ( netdev );
-
-
- if ( ( rc = dhcp ( netdev ) ) != 0 )
- return;
- route();
-
-
- dhcp_snprintf ( filename, sizeof ( filename ),
- find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
- if ( ! filename[0] ) {
- printf ( "No boot filename\n" );
- return;
- }
- printf ( "Booting \"%s\"\n", filename );
- image = alloc_image();
- if ( ! image ) {
- printf ( "Out of memory\n" );
- return;
- }
- if ( ( rc = imgfetch ( image, filename, 0 ) ) != 0 ) {
- printf ( "Could not retrieve %s: %s\n",
- filename, strerror ( rc ) );
- image_put ( image );
- return;
- }
- if ( ( rc = imgload ( image ) ) != 0 ) {
- printf ( "Could not load %s: %s\n", image->name,
- strerror ( rc ) );
- image_put ( image );
- return;
- }
- if ( ( rc = imgexec ( image ) ) != 0 ) {
- printf ( "Could not execute %s: %s\n", image->name,
- strerror ( rc ) );
- image_put ( image );
- return;
- }
- }
-
-
- static void close_all_netdevs ( void ) {
- struct net_device *netdev;
-
- for_each_netdev ( netdev ) {
- ifclose ( netdev );
- }
- }
-
-
- void autoboot ( void ) {
- struct net_device *boot_netdev;
- struct net_device *netdev;
-
-
- close_all_netdevs();
- if ( ( boot_netdev = find_boot_netdev() ) )
- netboot ( boot_netdev );
-
-
- for_each_netdev ( netdev ) {
- if ( netdev == boot_netdev )
- continue;
- close_all_netdevs();
- netboot ( netdev );
- }
-
- printf ( "No more network devices\n" );
- }
|