Browse Source

Try booting from the "boot" network device first (i.e. the one which we

were loaded from).  The code to identify this device isn't present yet,
but the code to act upon the knowledge is.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
78ded6604a
1 changed files with 80 additions and 7 deletions
  1. 80
    7
      src/usr/autoboot.c

+ 80
- 7
src/usr/autoboot.c View File

@@ -17,6 +17,7 @@
17 17
  */
18 18
 
19 19
 #include <string.h>
20
+#include <errno.h>
20 21
 #include <vsprintf.h>
21 22
 #include <gpxe/netdevice.h>
22 23
 #include <usr/ifmgmt.h>
@@ -30,21 +31,93 @@
30 31
 
31 32
 void test_dhcp ( struct net_device *netdev );
32 33
 
33
-void autoboot ( void ) {
34
+/**
35
+ * Identify the boot network device
36
+ *
37
+ * @ret netdev		Boot network device
38
+ */
39
+static struct net_device * find_boot_netdev ( void ) {
40
+	return NULL;
41
+}
42
+
43
+/**
44
+ * Get the next network device to try
45
+ *
46
+ * @ret netdev		'Next' network device
47
+ *
48
+ * This function will cycle through all registered network devices in
49
+ * order, returning NULL.
50
+ *
51
+ * This function should be safe against registration/deregistration of
52
+ * net devices between calls to next_netdev().
53
+ */
54
+static struct net_device * next_netdev ( void ) {
55
+	static struct net_device *last_netdev = NULL;
34 56
 	struct net_device *netdev;
35
-	int rc;
36 57
 
37 58
 	for_each_netdev ( netdev ) {
59
+		if ( ! last_netdev ) {
60
+			last_netdev = netdev;
61
+			return netdev;
62
+		}
63
+		if ( last_netdev == netdev )
64
+			last_netdev = NULL;
65
+	}
38 66
 
39
-		if ( ( rc = ifopen ( netdev ) ) != 0 )
40
-			continue;
67
+	last_netdev = NULL;
68
+	return NULL;
69
+}
70
+
71
+/**
72
+ * Boot from a network device
73
+ *
74
+ * @v netdev		Network device
75
+ */
76
+void netboot ( struct net_device *netdev ) {
77
+
78
+	/* Open device and display device status */
79
+	if ( ifopen ( netdev ) != 0 )
80
+		return;
81
+	ifstat ( netdev );
41 82
 
42
-		ifstat ( netdev );
83
+	test_dhcp ( netdev );
84
+}
85
+
86
+/**
87
+ * Close all open net devices
88
+ *
89
+ * Called before a fresh boot attempt in order to free up memory.  We
90
+ * don't just close the device immediately after the boot fails,
91
+ * because there may still be TCP connections in the process of
92
+ * closing.
93
+ */
94
+static void close_all_netdevs ( void ) {
95
+	struct net_device *netdev;
43 96
 
44
-		test_dhcp ( netdev );
45
-		
97
+	for_each_netdev ( netdev ) {
46 98
 		ifclose ( netdev );
47 99
 	}
100
+}
101
+
102
+/**
103
+ * Boot the system
104
+ */
105
+void autoboot ( void ) {
106
+	struct net_device *boot_netdev;
107
+	struct net_device *netdev;
108
+
109
+	/* If we have an identifable boot device, try that first */
110
+	close_all_netdevs();
111
+	if ( ( boot_netdev = find_boot_netdev() ) )
112
+		netboot ( boot_netdev );
113
+
114
+	/* If that fails, try booting from any of the other devices */
115
+	for_each_netdev ( netdev ) {
116
+		if ( netdev == boot_netdev )
117
+			continue;
118
+		close_all_netdevs();
119
+		netboot ( netdev );
120
+	}
48 121
 
49 122
 	printf ( "No more network devices\n" );
50 123
 }

Loading…
Cancel
Save