From 49fc8dcdc3f16d77ec0900af9245f57a56f7652a Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 12 Jan 2007 10:08:27 +0000 Subject: [PATCH] Use dhcp(), imgfetch() etc. to boot rather than dhcp_test(). --- src/usr/autoboot.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c index 97024ee3..ebafde7e 100644 --- a/src/usr/autoboot.c +++ b/src/usr/autoboot.c @@ -20,8 +20,12 @@ #include #include #include +#include +#include #include #include +#include +#include #include /** @file @@ -30,8 +34,6 @@ * */ -void test_dhcp ( struct net_device *netdev ); - /** * Identify the boot network device * @@ -75,15 +77,43 @@ static struct net_device * next_netdev ( void ) { * @v netdev Network device */ void netboot ( struct net_device *netdev ) { + char filename[256]; + struct image *image; + int rc; /* Open device and display device status */ - if ( ifopen ( netdev ) != 0 ) + if ( ( rc = ifopen ( netdev ) != 0 ) ) return; ifstat ( netdev ); - test_dhcp ( netdev ); - + /* Configure device via DHCP */ + if ( ( rc = dhcp ( netdev ) != 0 ) ) + return; route(); + + /* Try to download and boot whatever we are given as a filename */ + 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 ); + if ( ( rc = imgfetch ( filename, NULL, &image ) ) != 0 ) { + printf ( "Could not retrieve %s: %s\n", + filename, strerror ( rc ) ); + return; + } + if ( ( rc = imgload ( image ) ) != 0 ) { + printf ( "Could not load %s: %s\n", image->name, + strerror ( rc ) ); + return; + } + if ( ( rc = imgexec ( image ) ) != 0 ) { + printf ( "Could not execute %s: %s\n", image->name, + strerror ( rc ) ); + return; + } } /**