summaryrefslogtreecommitdiffstats
path: root/src/usr/autoboot.c
diff options
context:
space:
mode:
authorMichael Brown2007-07-08 23:01:49 +0200
committerMichael Brown2007-07-08 23:01:49 +0200
commitb94420a52bd2f19336b02bd431e80e59ff30d60b (patch)
tree55cab3f25ec7e2f2726682715146af67280b2298 /src/usr/autoboot.c
parentCode in place to use a hypothetical SCSI interface. (diff)
downloadipxe-b94420a52bd2f19336b02bd431e80e59ff30d60b.tar.gz
ipxe-b94420a52bd2f19336b02bd431e80e59ff30d60b.tar.xz
ipxe-b94420a52bd2f19336b02bd431e80e59ff30d60b.zip
Ready to start testing
Diffstat (limited to 'src/usr/autoboot.c')
-rw-r--r--src/usr/autoboot.c92
1 files changed, 66 insertions, 26 deletions
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index 302e1891..277e8b09 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -44,56 +44,96 @@ static struct net_device * find_boot_netdev ( void ) {
}
/**
- * Boot from a network device
+ * Boot using filename
*
- * @v netdev Network device
+ * @v filename Boot filename
+ * @ret rc Return status code
*/
-void netboot ( struct net_device *netdev ) {
- char filename[256];
+static int boot_filename ( const char *filename ) {
struct image *image;
int rc;
- /* Open device and display device status */
- if ( ( rc = ifopen ( netdev ) ) != 0 )
- return;
- ifstat ( 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 );
image = alloc_image();
if ( ! image ) {
printf ( "Out of memory\n" );
- return;
+ return -ENOMEM;
}
if ( ( rc = imgfetch ( image, filename, 0 ) ) != 0 ) {
printf ( "Could not retrieve %s: %s\n",
filename, strerror ( rc ) );
image_put ( image );
- return;
+ return rc;
}
if ( ( rc = imgload ( image ) ) != 0 ) {
printf ( "Could not load %s: %s\n", image->name,
strerror ( rc ) );
image_put ( image );
- return;
+ return rc;
}
if ( ( rc = imgexec ( image ) ) != 0 ) {
printf ( "Could not execute %s: %s\n", image->name,
strerror ( rc ) );
image_put ( image );
- return;
+ return rc;
+ }
+
+ return 0;
+}
+
+/**
+ * Boot using root path
+ *
+ * @v root_path Root path
+ * @ret rc Return status code
+ */
+static int boot_root_path ( const char *root_path ) {
+ int rc;
+
+ /* Quick hack */
+ if ( ( rc = iscsiboot ( root_path ) ) != 0 )
+ return rc;
+
+ return 0;
+}
+
+/**
+ * Boot from a network device
+ *
+ * @v netdev Network device
+ * @ret rc Return status code
+ */
+int netboot ( struct net_device *netdev ) {
+ char buf[256];
+ int rc;
+
+ /* Open device and display device status */
+ if ( ( rc = ifopen ( netdev ) ) != 0 )
+ return rc;
+ ifstat ( netdev );
+
+ /* Configure device via DHCP */
+ if ( ( rc = dhcp ( netdev ) ) != 0 )
+ return rc;
+ route();
+
+ /* Try to download and boot whatever we are given as a filename */
+ dhcp_snprintf ( buf, sizeof ( buf ),
+ find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
+ if ( buf[0] ) {
+ printf ( "Booting from filename \"%s\"\n", buf );
+ return boot_filename ( buf );
}
+
+ /* No filename; try the root path */
+ dhcp_snprintf ( buf, sizeof ( buf ),
+ find_global_dhcp_option ( DHCP_ROOT_PATH ) );
+ if ( buf[0] ) {
+ printf ( "Booting from root path \"%s\"\n", buf );
+ return boot_root_path ( buf );
+ }
+
+ printf ( "No filename or root path specified\n" );
+ return -ENOENT;
}
/**