Pārlūkot izejas kodu

Split the (quick hack) boot logic out from main.c to autoboot.c, add a

"boot" command to attempt booting from within the command shell, fall back
to shell if boot fails for any reason.
tags/v0.9.3
Michael Brown 18 gadus atpakaļ
vecāks
revīzija
84202d89f0
7 mainītis faili ar 85 papildinājumiem un 14 dzēšanām
  1. 1
    0
      src/Makefile
  2. 2
    1
      src/config.h
  3. 3
    0
      src/core/config.c
  4. 6
    13
      src/core/main.c
  5. 21
    0
      src/hci/commands/boot_cmd.c
  6. 12
    0
      src/include/gpxe/autoboot.h
  7. 40
    0
      src/usr/autoboot.c

+ 1
- 0
src/Makefile Parādīt failu

@@ -146,6 +146,7 @@ SRCDIRS		+= tests
146 146
 SRCDIRS		+= crypto
147 147
 SRCDIRS		+= hci hci/commands hci/tui
148 148
 SRCDIRS		+= hci/mucurses hci/mucurses/widgets
149
+SRCDIRS		+= usr
149 150
 
150 151
 # NON_AUTO_SRCS lists files that are excluded from the normal
151 152
 # automatic build system.

+ 2
- 1
src/config.h Parādīt failu

@@ -115,8 +115,9 @@
115 115
  * Command-line commands to include
116 116
  *
117 117
  */
118
+#define	BOOT_CMD		/* Automatic booting */
118 119
 #define	NVO_CMD			/* Non-volatile option storage commands */
119
-#define CONFIG_CMD		/* Option configuration console */
120
+#define	CONFIG_CMD		/* Option configuration console */
120 121
 
121 122
 /* @END general.h */ 
122 123
 

+ 3
- 0
src/core/config.c Parādīt failu

@@ -143,6 +143,9 @@ REQUIRE_OBJECT ( pxe );
143 143
  * Drag in all requested commands
144 144
  *
145 145
  */
146
+#ifdef BOOT_CMD
147
+REQUIRE_OBJECT ( boot_cmd );
148
+#endif
146 149
 #ifdef NVO_CMD
147 150
 REQUIRE_OBJECT ( nvo_cmd );
148 151
 #endif

+ 6
- 13
src/core/main.c Parādīt failu

@@ -150,26 +150,19 @@ void test_dhcp ( struct net_device *netdev );
150 150
 MAIN - Kick off routine
151 151
 **************************************************************************/
152 152
 int main ( void ) {
153
-	struct net_device *netdev;
154 153
 
155 154
 	/* Call all registered initialisation functions */
156 155
 	init_heap();
157 156
 	call_init_fns ();
158 157
 	probe_devices();
159 158
 
160
-	if ( shell_banner() ) {
161
-		shell();
159
+	/* Try autobooting if we're not going straight to the shell */
160
+	if ( ! shell_banner() ) {
161
+		autoboot();
162 162
 	}
163
-
164
-	netdev = next_netdev ();
165
-	if ( netdev ) {
166
-		test_dhcp ( netdev );
167
-	} else {
168
-		printf ( "No network device found\n" );
169
-	}
170
-
171
-	printf ( "Press any key to exit\n" );
172
-	getchar();
163
+	
164
+	/* Autobooting failed or the user wanted the shell */
165
+	shell();
173 166
 
174 167
 	remove_devices();
175 168
 	call_exit_fns ();

+ 21
- 0
src/hci/commands/boot_cmd.c Parādīt failu

@@ -0,0 +1,21 @@
1
+#include <vsprintf.h>
2
+#include <gpxe/command.h>
3
+#include <gpxe/autoboot.h>
4
+
5
+static int boot_exec ( int argc, char **argv ) {
6
+
7
+	if ( argc != 1 ) {
8
+		printf ( "Usage: %s\n"
9
+			 "Attempts to boot the system\n", argv[0] );
10
+		return 1;
11
+	}
12
+
13
+	autoboot();
14
+
15
+	return 0;
16
+}
17
+
18
+struct command boot_command __command = {
19
+	.name = "boot",
20
+	.exec = boot_exec,
21
+};

+ 12
- 0
src/include/gpxe/autoboot.h Parādīt failu

@@ -0,0 +1,12 @@
1
+#ifndef _GPXE_AUTOBOOT_H
2
+#define _GPXE_AUTOBOOT_H
3
+
4
+/** @file
5
+ *
6
+ * Automatic booting
7
+ *
8
+ */
9
+
10
+extern void autoboot ( void );
11
+
12
+#endif /* _GPXE_AUTOBOOT_H */

+ 40
- 0
src/usr/autoboot.c Parādīt failu

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (C) 2006 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
+
19
+#include <vsprintf.h>
20
+#include <gpxe/autoboot.h>
21
+
22
+/** @file
23
+ *
24
+ * Automatic booting
25
+ *
26
+ */
27
+
28
+#include <gpxe/netdevice.h>
29
+void test_dhcp ( struct net_device *netdev );
30
+
31
+void autoboot ( void ) {
32
+	struct net_device *netdev;
33
+
34
+	netdev = next_netdev ();
35
+	if ( netdev ) {
36
+		test_dhcp ( netdev );
37
+	} else {
38
+		printf ( "No network device found\n" );
39
+	}
40
+}

Notiek ielāde…
Atcelt
Saglabāt