]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[autoboot] Merge "netboot" command into "autoboot"
authorMichael Brown <mcb30@ipxe.org>
Mon, 22 Nov 2010 21:04:30 +0000 (21:04 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 22 Nov 2010 21:04:30 +0000 (21:04 +0000)
Allow "autoboot" to accept an optional list of network devices, and
remove the "netboot" command.  This saves around 130 bytes.

The "netboot" command has existed for approximately 48 hours, so its
removal should not cause backwards compatibility issues for anyone.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/hci/commands/autoboot_cmd.c
src/usr/autoboot.c

index 33788682ecce623664ef7c29c3c22f5298176077..6fd34b3a54336dee3b9ae2b811a698d3cade38c4 100644 (file)
@@ -21,6 +21,7 @@
 #include <ipxe/command.h>
 #include <ipxe/parseopt.h>
 #include <ipxe/netdevice.h>
+#include <hci/ifmgmt_cmd.h>
 #include <usr/autoboot.h>
 
 FILE_LICENCE ( GPL2_OR_LATER );
@@ -31,17 +32,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
  *
  */
 
-/** "autoboot" options */
-struct autoboot_options {};
-
-/** "autoboot" option list */
-static struct option_descriptor autoboot_opts[] = {};
-
 /** "autoboot" command descriptor */
 static struct command_descriptor autoboot_cmd =
-       COMMAND_DESC ( struct autoboot_options, autoboot_opts, 0, 0,
-                      "",
-                      "Attempt to boot the system" );
+       COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
+                      "[<interface>...]", "Attempt to boot the system" );
 
 /**
  * "autoboot" command
@@ -51,57 +45,7 @@ static struct command_descriptor autoboot_cmd =
  * @ret rc             Return status code
  */
 static int autoboot_exec ( int argc, char **argv ) {
-       struct autoboot_options opts;
-       int rc;
-
-       /* Parse options */
-       if ( ( rc = parse_options ( argc, argv, &autoboot_cmd, &opts ) ) != 0 )
-               return rc;
-
-       /* Try to boot */
-       if ( ( rc = autoboot() ) != 0 )
-               return rc;
-
-       return 0;
-}
-
-/** "netboot" options */
-struct netboot_options {};
-
-/** "netboot" option list */
-static struct option_descriptor netboot_opts[] = {};
-
-/** "netboot" command descriptor */
-static struct command_descriptor netboot_cmd =
-       COMMAND_DESC ( struct netboot_options, netboot_opts, 1, 1,
-                      "<interface>",
-                      "Attempt to boot the system from <interface>" );
-
-/**
- * "netboot" command
- *
- * @v argc             Argument count
- * @v argv             Argument list
- * @ret rc             Return status code
- */
-static int netboot_exec ( int argc, char **argv ) {
-       struct netboot_options opts;
-       struct net_device *netdev;
-       int rc;
-
-       /* Parse options */
-       if ( ( rc = parse_options ( argc, argv, &netboot_cmd, &opts ) ) != 0 )
-               return rc;
-
-       /* Parse interface */
-       if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
-               return rc;
-
-       /* Try to boot */
-       if ( ( rc = netboot ( netdev ) ) != 0 )
-               return rc;
-
-       return 0;
+       return ifcommon_exec ( argc, argv, &autoboot_cmd, netboot, 0 );
 }
 
 /** Booting commands */
@@ -110,8 +54,4 @@ struct command autoboot_commands[] __command = {
                .name = "autoboot",
                .exec = autoboot_exec,
        },
-       {
-               .name = "netboot",
-               .exec = netboot_exec,
-       },
 };
index c7492ea7c93efbe414656cd47d345d2f7a99193a..738c3ceaaf9f739aead37579baa44ab104b34e86 100644 (file)
@@ -214,6 +214,22 @@ int boot_root_path ( const char *root_path ) {
        return rc;
 }
 
+/**
+ * Close all open net devices
+ *
+ * Called before a fresh boot attempt in order to free up memory.  We
+ * don't just close the device immediately after the boot fails,
+ * because there may still be TCP connections in the process of
+ * closing.
+ */
+static void close_all_netdevs ( void ) {
+       struct net_device *netdev;
+
+       for_each_netdev ( netdev ) {
+               ifclose ( netdev );
+       }
+}
+
 /**
  * Boot from a network device
  *
@@ -232,6 +248,9 @@ int netboot ( struct net_device *netdev ) {
        unsigned int pxe_discovery_control;
        int rc;
 
+       /* Close all other network devices */
+       close_all_netdevs();
+
        /* Open device and display device status */
        if ( ( rc = ifopen ( netdev ) ) != 0 )
                return rc;
@@ -274,22 +293,6 @@ int netboot ( struct net_device *netdev ) {
        return -ENOENT;
 }
 
-/**
- * Close all open net devices
- *
- * Called before a fresh boot attempt in order to free up memory.  We
- * don't just close the device immediately after the boot fails,
- * because there may still be TCP connections in the process of
- * closing.
- */
-static void close_all_netdevs ( void ) {
-       struct net_device *netdev;
-
-       for_each_netdev ( netdev ) {
-               ifclose ( netdev );
-       }
-}
-
 /**
  * Boot the system
  */
@@ -299,7 +302,6 @@ int autoboot ( void ) {
        int rc = -ENODEV;
 
        /* If we have an identifable boot device, try that first */
-       close_all_netdevs();
        if ( ( boot_netdev = find_boot_netdev() ) )
                rc = netboot ( boot_netdev );
 
@@ -307,7 +309,6 @@ int autoboot ( void ) {
        for_each_netdev ( netdev ) {
                if ( netdev == boot_netdev )
                        continue;
-               close_all_netdevs();
                rc = netboot ( netdev );
        }