Browse Source

[autoboot] Merge "netboot" command into "autoboot"

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>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
debbea1123
2 changed files with 23 additions and 82 deletions
  1. 4
    64
      src/hci/commands/autoboot_cmd.c
  2. 19
    18
      src/usr/autoboot.c

+ 4
- 64
src/hci/commands/autoboot_cmd.c View File

@@ -21,6 +21,7 @@
21 21
 #include <ipxe/command.h>
22 22
 #include <ipxe/parseopt.h>
23 23
 #include <ipxe/netdevice.h>
24
+#include <hci/ifmgmt_cmd.h>
24 25
 #include <usr/autoboot.h>
25 26
 
26 27
 FILE_LICENCE ( GPL2_OR_LATER );
@@ -31,17 +32,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 32
  *
32 33
  */
33 34
 
34
-/** "autoboot" options */
35
-struct autoboot_options {};
36
-
37
-/** "autoboot" option list */
38
-static struct option_descriptor autoboot_opts[] = {};
39
-
40 35
 /** "autoboot" command descriptor */
41 36
 static struct command_descriptor autoboot_cmd =
42
-	COMMAND_DESC ( struct autoboot_options, autoboot_opts, 0, 0,
43
-		       "",
44
-		       "Attempt to boot the system" );
37
+	COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
38
+		       "[<interface>...]", "Attempt to boot the system" );
45 39
 
46 40
 /**
47 41
  * "autoboot" command
@@ -51,57 +45,7 @@ static struct command_descriptor autoboot_cmd =
51 45
  * @ret rc		Return status code
52 46
  */
53 47
 static int autoboot_exec ( int argc, char **argv ) {
54
-	struct autoboot_options opts;
55
-	int rc;
56
-
57
-	/* Parse options */
58
-	if ( ( rc = parse_options ( argc, argv, &autoboot_cmd, &opts ) ) != 0 )
59
-		return rc;
60
-
61
-	/* Try to boot */
62
-	if ( ( rc = autoboot() ) != 0 )
63
-		return rc;
64
-
65
-	return 0;
66
-}
67
-
68
-/** "netboot" options */
69
-struct netboot_options {};
70
-
71
-/** "netboot" option list */
72
-static struct option_descriptor netboot_opts[] = {};
73
-
74
-/** "netboot" command descriptor */
75
-static struct command_descriptor netboot_cmd =
76
-	COMMAND_DESC ( struct netboot_options, netboot_opts, 1, 1,
77
-		       "<interface>",
78
-		       "Attempt to boot the system from <interface>" );
79
-
80
-/**
81
- * "netboot" command
82
- *
83
- * @v argc		Argument count
84
- * @v argv		Argument list
85
- * @ret rc		Return status code
86
- */
87
-static int netboot_exec ( int argc, char **argv ) {
88
-	struct netboot_options opts;
89
-	struct net_device *netdev;
90
-	int rc;
91
-
92
-	/* Parse options */
93
-	if ( ( rc = parse_options ( argc, argv, &netboot_cmd, &opts ) ) != 0 )
94
-		return rc;
95
-
96
-	/* Parse interface */
97
-	if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
98
-		return rc;
99
-
100
-	/* Try to boot */
101
-	if ( ( rc = netboot ( netdev ) ) != 0 )
102
-		return rc;
103
-
104
-	return 0;
48
+	return ifcommon_exec ( argc, argv, &autoboot_cmd, netboot, 0 );
105 49
 }
106 50
 
107 51
 /** Booting commands */
@@ -110,8 +54,4 @@ struct command autoboot_commands[] __command = {
110 54
 		.name = "autoboot",
111 55
 		.exec = autoboot_exec,
112 56
 	},
113
-	{
114
-		.name = "netboot",
115
-		.exec = netboot_exec,
116
-	},
117 57
 };

+ 19
- 18
src/usr/autoboot.c View File

@@ -214,6 +214,22 @@ int boot_root_path ( const char *root_path ) {
214 214
 	return rc;
215 215
 }
216 216
 
217
+/**
218
+ * Close all open net devices
219
+ *
220
+ * Called before a fresh boot attempt in order to free up memory.  We
221
+ * don't just close the device immediately after the boot fails,
222
+ * because there may still be TCP connections in the process of
223
+ * closing.
224
+ */
225
+static void close_all_netdevs ( void ) {
226
+	struct net_device *netdev;
227
+
228
+	for_each_netdev ( netdev ) {
229
+		ifclose ( netdev );
230
+	}
231
+}
232
+
217 233
 /**
218 234
  * Boot from a network device
219 235
  *
@@ -232,6 +248,9 @@ int netboot ( struct net_device *netdev ) {
232 248
 	unsigned int pxe_discovery_control;
233 249
 	int rc;
234 250
 
251
+	/* Close all other network devices */
252
+	close_all_netdevs();
253
+
235 254
 	/* Open device and display device status */
236 255
 	if ( ( rc = ifopen ( netdev ) ) != 0 )
237 256
 		return rc;
@@ -274,22 +293,6 @@ int netboot ( struct net_device *netdev ) {
274 293
 	return -ENOENT;
275 294
 }
276 295
 
277
-/**
278
- * Close all open net devices
279
- *
280
- * Called before a fresh boot attempt in order to free up memory.  We
281
- * don't just close the device immediately after the boot fails,
282
- * because there may still be TCP connections in the process of
283
- * closing.
284
- */
285
-static void close_all_netdevs ( void ) {
286
-	struct net_device *netdev;
287
-
288
-	for_each_netdev ( netdev ) {
289
-		ifclose ( netdev );
290
-	}
291
-}
292
-
293 296
 /**
294 297
  * Boot the system
295 298
  */
@@ -299,7 +302,6 @@ int autoboot ( void ) {
299 302
 	int rc = -ENODEV;
300 303
 
301 304
 	/* If we have an identifable boot device, try that first */
302
-	close_all_netdevs();
303 305
 	if ( ( boot_netdev = find_boot_netdev() ) )
304 306
 		rc = netboot ( boot_netdev );
305 307
 
@@ -307,7 +309,6 @@ int autoboot ( void ) {
307 309
 	for_each_netdev ( netdev ) {
308 310
 		if ( netdev == boot_netdev )
309 311
 			continue;
310
-		close_all_netdevs();
311 312
 		rc = netboot ( netdev );
312 313
 	}
313 314
 

Loading…
Cancel
Save