|
@@ -1,53 +1,110 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
1
|
19
|
#include <stdio.h>
|
|
20
|
+#include <getopt.h>
|
2
|
21
|
#include <ipxe/command.h>
|
|
22
|
+#include <ipxe/parseopt.h>
|
3
|
23
|
#include <ipxe/netdevice.h>
|
4
|
24
|
#include <usr/autoboot.h>
|
5
|
25
|
|
6
|
26
|
FILE_LICENCE ( GPL2_OR_LATER );
|
7
|
27
|
|
|
28
|
+/** @file
|
|
29
|
+ *
|
|
30
|
+ * Booting commands
|
|
31
|
+ *
|
|
32
|
+ */
|
|
33
|
+
|
|
34
|
+/** "autoboot" options */
|
|
35
|
+struct autoboot_options {};
|
|
36
|
+
|
|
37
|
+/** "autoboot" option list */
|
|
38
|
+static struct option_descriptor autoboot_opts[] = {};
|
|
39
|
+
|
|
40
|
+/** "autoboot" command descriptor */
|
|
41
|
+static struct command_descriptor autoboot_cmd =
|
|
42
|
+ COMMAND_DESC ( struct autoboot_options, autoboot_opts, 0, 0,
|
|
43
|
+ "",
|
|
44
|
+ "Attempt to boot the system" );
|
|
45
|
+
|
|
46
|
+/**
|
|
47
|
+ * "autoboot" command
|
|
48
|
+ *
|
|
49
|
+ * @v argc Argument count
|
|
50
|
+ * @v argv Argument list
|
|
51
|
+ * @ret rc Return status code
|
|
52
|
+ */
|
8
|
53
|
static int autoboot_exec ( int argc, char **argv ) {
|
|
54
|
+ struct autoboot_options opts;
|
|
55
|
+ int rc;
|
9
|
56
|
|
10
|
|
- if ( argc != 1 ) {
|
11
|
|
- printf ( "Usage:\n"
|
12
|
|
- " %s\n"
|
13
|
|
- "\n"
|
14
|
|
- "Attempts to boot the system\n",
|
15
|
|
- argv[0] );
|
16
|
|
- return 1;
|
17
|
|
- }
|
|
57
|
+ /* Parse options */
|
|
58
|
+ if ( ( rc = parse_options ( argc, argv, &autoboot_cmd, &opts ) ) != 0 )
|
|
59
|
+ return rc;
|
18
|
60
|
|
19
|
|
- autoboot();
|
|
61
|
+ /* Try to boot */
|
|
62
|
+ if ( ( rc = autoboot() ) != 0 )
|
|
63
|
+ return rc;
|
20
|
64
|
|
21
|
|
- /* Can never return success by definition */
|
22
|
|
- return 1;
|
|
65
|
+ return 0;
|
23
|
66
|
}
|
24
|
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
|
+ */
|
25
|
87
|
static int netboot_exec ( int argc, char **argv ) {
|
26
|
|
- const char *netdev_name;
|
|
88
|
+ struct netboot_options opts;
|
27
|
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;
|
28
|
103
|
|
29
|
|
- if ( argc != 2 ) {
|
30
|
|
- printf ( "Usage:\n"
|
31
|
|
- " %s <interface>\n"
|
32
|
|
- "\n"
|
33
|
|
- "Attempts to boot the system from <interface>\n",
|
34
|
|
- argv[0] );
|
35
|
|
- return 1;
|
36
|
|
- }
|
37
|
|
- netdev_name = argv[1];
|
38
|
|
-
|
39
|
|
- netdev = find_netdev ( netdev_name );
|
40
|
|
- if ( ! netdev ) {
|
41
|
|
- printf ( "%s: no such interface\n", netdev_name );
|
42
|
|
- return 1;
|
43
|
|
- }
|
44
|
|
-
|
45
|
|
- netboot ( netdev );
|
46
|
|
-
|
47
|
|
- /* Can never return success by definition */
|
48
|
|
- return 1;
|
|
104
|
+ return 0;
|
49
|
105
|
}
|
50
|
106
|
|
|
107
|
+/** Booting commands */
|
51
|
108
|
struct command autoboot_commands[] __command = {
|
52
|
109
|
{
|
53
|
110
|
.name = "autoboot",
|