Browse Source

[autoboot] Split main control flow out of main() into a new function ipxe()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
033f4c92ca
3 changed files with 98 additions and 82 deletions
  1. 2
    82
      src/core/main.c
  2. 1
    0
      src/include/usr/autoboot.h
  3. 95
    0
      src/usr/autoboot.c

+ 2
- 82
src/core/main.c View File

@@ -14,56 +14,18 @@ Literature dealing with the network protocols:
14 14
 
15 15
 FILE_LICENCE ( GPL2_OR_LATER );
16 16
 
17
+#include <stddef.h>
17 18
 #include <stdio.h>
18
-#include <stdlib.h>
19 19
 #include <ipxe/init.h>
20
-#include <ipxe/features.h>
21
-#include <ipxe/shell.h>
22
-#include <ipxe/image.h>
23
-#include <ipxe/keys.h>
24
-#include <ipxe/version.h>
25
-#include <usr/prompt.h>
26 20
 #include <usr/autoboot.h>
27 21
 #include <config/general.h>
28 22
 
29
-#define NORMAL	"\033[0m"
30
-#define BOLD	"\033[1m"
31
-#define CYAN	"\033[36m"
32
-
33
-/** The "scriptlet" setting */
34
-struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
35
-	.name = "scriptlet",
36
-	.description = "Boot scriptlet",
37
-	.tag = DHCP_EB_SCRIPTLET,
38
-	.type = &setting_type_string,
39
-};
40
-
41
-/**
42
- * Prompt for shell entry
43
- *
44
- * @ret	enter_shell		User wants to enter shell
45
- */
46
-static int shell_banner ( void ) {
47
-
48
-	/* Skip prompt if timeout is zero */
49
-	if ( BANNER_TIMEOUT <= 0 )
50
-		return 0;
51
-
52
-	/* Prompt user */
53
-	printf ( "\n" );
54
-	return ( prompt ( "Press Ctrl-B for the iPXE command line...",
55
-			  ( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
56
-}
57
-
58 23
 /**
59 24
  * Main entry point
60 25
  *
61 26
  * @ret rc		Return status code
62 27
  */
63 28
 __asmcall int main ( void ) {
64
-	struct feature *feature;
65
-	struct image *image;
66
-	char *scriptlet;
67 29
 
68 30
 	/* Some devices take an unreasonably long time to initialise */
69 31
 	printf ( PRODUCT_SHORT_NAME " initialising devices..." );
@@ -71,49 +33,7 @@ __asmcall int main ( void ) {
71 33
 	startup();
72 34
 	printf ( "ok\n" );
73 35
 
74
-	/*
75
-	 * Print welcome banner
76
-	 *
77
-	 *
78
-	 * If you wish to brand this build of iPXE, please do so by
79
-	 * defining the string PRODUCT_NAME in config/general.h.
80
-	 *
81
-	 * While nothing in the GPL prevents you from removing all
82
-	 * references to iPXE or http://ipxe.org, we prefer you not to
83
-	 * do so.
84
-	 *
85
-	 */
86
-	printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
87
-		 NORMAL " -- Open Source Network Boot Firmware -- "
88
-		 CYAN "http://ipxe.org" NORMAL "\n"
89
-		 "Features:", product_version );
90
-	for_each_table_entry ( feature, FEATURES )
91
-		printf ( " %s", feature->name );
92
-	printf ( "\n" );
93
-
94
-	/* Boot system */
95
-	if ( ( image = first_image() ) != NULL ) {
96
-		/* We have an embedded image; execute it */
97
-		image_exec ( image );
98
-	} else if ( shell_banner() ) {
99
-		/* User wants shell; just give them a shell */
100
-		shell();
101
-	} else {
102
-		fetch_string_setting_copy ( NULL, &scriptlet_setting,
103
-					    &scriptlet );
104
-		if ( scriptlet ) {
105
-			/* User has defined a scriptlet; execute it */
106
-			system ( scriptlet );
107
-			free ( scriptlet );
108
-		} else {
109
-			/* Try booting.  If booting fails, offer the
110
-			 * user another chance to enter the shell.
111
-			 */
112
-			autoboot();
113
-			if ( shell_banner() )
114
-				shell();
115
-		}
116
-	}
36
+	ipxe ( NULL );
117 37
 
118 38
 	shutdown_exit();
119 39
 

+ 1
- 0
src/include/usr/autoboot.h View File

@@ -31,6 +31,7 @@ extern struct uri *
31 31
 fetch_next_server_and_filename ( struct settings *settings );
32 32
 extern int netboot ( struct net_device *netdev );
33 33
 extern int autoboot ( void );
34
+extern void ipxe ( struct net_device *netdev );
34 35
 
35 36
 extern int pxe_menu_boot ( struct net_device *netdev );
36 37
 

+ 95
- 0
src/usr/autoboot.c View File

@@ -30,11 +30,18 @@ FILE_LICENCE ( GPL2_OR_LATER );
30 30
 #include <ipxe/uri.h>
31 31
 #include <ipxe/open.h>
32 32
 #include <ipxe/init.h>
33
+#include <ipxe/keys.h>
34
+#include <ipxe/version.h>
35
+#include <ipxe/shell.h>
36
+#include <ipxe/features.h>
37
+#include <ipxe/image.h>
33 38
 #include <usr/ifmgmt.h>
34 39
 #include <usr/route.h>
35 40
 #include <usr/dhcpmgmt.h>
36 41
 #include <usr/imgmgmt.h>
42
+#include <usr/prompt.h>
37 43
 #include <usr/autoboot.h>
44
+#include <config/general.h>
38 45
 
39 46
 /** @file
40 47
  *
@@ -47,6 +54,18 @@ FILE_LICENCE ( GPL2_OR_LATER );
47 54
 #define EINFO_ENOENT_BOOT \
48 55
 	__einfo_uniqify ( EINFO_ENOENT, 0x01, "Nothing to boot" )
49 56
 
57
+#define NORMAL	"\033[0m"
58
+#define BOLD	"\033[1m"
59
+#define CYAN	"\033[36m"
60
+
61
+/** The "scriptlet" setting */
62
+struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
63
+	.name = "scriptlet",
64
+	.description = "Boot scriptlet",
65
+	.tag = DHCP_EB_SCRIPTLET,
66
+	.type = &setting_type_string,
67
+};
68
+
50 69
 /**
51 70
  * Perform PXE menu boot when PXE stack is not available
52 71
  */
@@ -423,3 +442,79 @@ int autoboot ( void ) {
423 442
 	printf ( "No more network devices\n" );
424 443
 	return rc;
425 444
 }
445
+
446
+/**
447
+ * Prompt for shell entry
448
+ *
449
+ * @ret	enter_shell	User wants to enter shell
450
+ */
451
+static int shell_banner ( void ) {
452
+
453
+	/* Skip prompt if timeout is zero */
454
+	if ( BANNER_TIMEOUT <= 0 )
455
+		return 0;
456
+
457
+	/* Prompt user */
458
+	printf ( "\n" );
459
+	return ( prompt ( "Press Ctrl-B for the iPXE command line...",
460
+			  ( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
461
+}
462
+
463
+/**
464
+ * Main iPXE flow of execution
465
+ *
466
+ * @v netdev		Network device, or NULL
467
+ */
468
+void ipxe ( struct net_device *netdev ) {
469
+	struct feature *feature;
470
+	struct image *image;
471
+	char *scriptlet;
472
+
473
+	/*
474
+	 * Print welcome banner
475
+	 *
476
+	 *
477
+	 * If you wish to brand this build of iPXE, please do so by
478
+	 * defining the string PRODUCT_NAME in config/general.h.
479
+	 *
480
+	 * While nothing in the GPL prevents you from removing all
481
+	 * references to iPXE or http://ipxe.org, we prefer you not to
482
+	 * do so.
483
+	 *
484
+	 */
485
+	printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE %s"
486
+		 NORMAL " -- Open Source Network Boot Firmware -- "
487
+		 CYAN "http://ipxe.org" NORMAL "\n"
488
+		 "Features:", product_version );
489
+	for_each_table_entry ( feature, FEATURES )
490
+		printf ( " %s", feature->name );
491
+	printf ( "\n" );
492
+
493
+	/* Boot system */
494
+	if ( ( image = first_image() ) != NULL ) {
495
+		/* We have an embedded image; execute it */
496
+		image_exec ( image );
497
+	} else if ( shell_banner() ) {
498
+		/* User wants shell; just give them a shell */
499
+		shell();
500
+	} else {
501
+		fetch_string_setting_copy ( NULL, &scriptlet_setting,
502
+					    &scriptlet );
503
+		if ( scriptlet ) {
504
+			/* User has defined a scriptlet; execute it */
505
+			system ( scriptlet );
506
+			free ( scriptlet );
507
+		} else {
508
+			/* Try booting.  If booting fails, offer the
509
+			 * user another chance to enter the shell.
510
+			 */
511
+			if ( netdev ) {
512
+				netboot ( netdev );
513
+			} else {
514
+				autoboot();
515
+			}
516
+			if ( shell_banner() )
517
+				shell();
518
+		}
519
+	}
520
+}

Loading…
Cancel
Save