[ipxe-devel] [PATCH v2 1/3] [autoboot] Enable infrastructure to specify an autoboot device location

Alex Williamson alex.williamson at redhat.com
Tue Feb 25 23:00:23 UTC 2014


Current autoboot will attempt to boot from every netdev created by the
bundled drivers.  This is often not desireable and makes things like
BIOS IPL lists fairly ineffective when hitting an iPXE ROM.  Add
infrastructure for other parts of the stack to specify an autoboot
device description.

This means that all netdevs matching the autoboot device location will
be given priority.  The previous behavior of attempting boot from any
netdev is preserved in the case where no matching netdevs are found,
which includes the case of an autoboot device being unspecified.

Signed-off-by: Alex Williamson <alex.williamson at redhat.com>
---
 src/include/usr/autoboot.h |    3 +++
 src/usr/autoboot.c         |   52 ++++++++++++++++++++++++++++----------------
 2 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/src/include/usr/autoboot.h b/src/include/usr/autoboot.h
index cfa4c41..2148011 100644
--- a/src/include/usr/autoboot.h
+++ b/src/include/usr/autoboot.h
@@ -10,6 +10,7 @@
 FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <ipxe/in.h>
+#include <ipxe/device.h>
 struct net_device;
 struct uri;
 struct settings;
@@ -35,4 +36,6 @@ extern void ipxe ( struct net_device *netdev );
 
 extern int pxe_menu_boot ( struct net_device *netdev );
 
+extern struct device_description autoboot_device;
+
 #endif /* _USR_AUTOBOOT_H */
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index c95a256..c43018a 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -49,6 +49,9 @@ FILE_LICENCE ( GPL2_OR_LATER );
  *
  */
 
+/** Device location of preferred autoboot device */
+struct device_description autoboot_device;
+
 /* Disambiguate the various error causes */
 #define ENOENT_BOOT __einfo_error ( EINFO_ENOENT_BOOT )
 #define EINFO_ENOENT_BOOT \
@@ -74,15 +77,6 @@ __weak int pxe_menu_boot ( struct net_device *netdev __unused ) {
 }
 
 /**
- * Identify the boot network device
- *
- * @ret netdev		Boot network device
- */
-static struct net_device * find_boot_netdev ( void ) {
-	return NULL;
-}
-
-/**
  * Parse next-server and filename into a URI
  *
  * @v next_server	Next-server address
@@ -437,24 +431,44 @@ int netboot ( struct net_device *netdev ) {
 }
 
 /**
+ * Test if netdev is a match for autoboot_device location
+ *
+ * @netdev	Device to test
+ * @ret		non-zero for positive match
+ */
+static int autoboot_device_netdev_match ( struct net_device *netdev ) {
+
+	if ( netdev->dev->desc.bus_type != autoboot_device.bus_type ||
+	     netdev->dev->desc.location != autoboot_device.location )
+		return 0;
+
+	return 1;
+}
+
+/**
  * Boot the system
  */
 int autoboot ( void ) {
-	struct net_device *boot_netdev;
 	struct net_device *netdev;
-	int rc = -ENODEV;
-
-	/* If we have an identifable boot device, try that first */
-	if ( ( boot_netdev = find_boot_netdev() ) )
-		rc = netboot ( boot_netdev );
+	int found_autoboot_device = 0, rc = -ENODEV;
 
-	/* If that fails, try booting from any of the other devices */
+	/* If we have netdevs matching the autoboot device, use only them */
 	for_each_netdev ( netdev ) {
-		if ( netdev == boot_netdev )
-			continue;
-		rc = netboot ( netdev );
+		if ( autoboot_device_netdev_match ( netdev ) ) {
+			rc = netboot ( netdev );
+			found_autoboot_device = 1;
+		}
 	}
 
+	if ( found_autoboot_device ) {
+		printf ( "No more autoboot network devices\n" );
+		return rc;
+	}
+		
+	/* Lacking a specified or matching autoboot device, use anything */
+	for_each_netdev ( netdev )
+		rc = netboot ( netdev );
+
 	printf ( "No more network devices\n" );
 	return rc;
 }




More information about the ipxe-devel mailing list