Просмотр исходного кода

Use dhcp(), imgfetch() etc. to boot rather than dhcp_test().

tags/v0.9.3
Michael Brown 18 лет назад
Родитель
Сommit
49fc8dcdc3
1 измененных файлов: 35 добавлений и 5 удалений
  1. 35
    5
      src/usr/autoboot.c

+ 35
- 5
src/usr/autoboot.c Просмотреть файл

@@ -20,8 +20,12 @@
20 20
 #include <errno.h>
21 21
 #include <vsprintf.h>
22 22
 #include <gpxe/netdevice.h>
23
+#include <gpxe/dhcp.h>
24
+#include <gpxe/image.h>
23 25
 #include <usr/ifmgmt.h>
24 26
 #include <usr/route.h>
27
+#include <usr/dhcpmgmt.h>
28
+#include <usr/imgmgmt.h>
25 29
 #include <usr/autoboot.h>
26 30
 
27 31
 /** @file
@@ -30,8 +34,6 @@
30 34
  *
31 35
  */
32 36
 
33
-void test_dhcp ( struct net_device *netdev );
34
-
35 37
 /**
36 38
  * Identify the boot network device
37 39
  *
@@ -75,15 +77,43 @@ static struct net_device * next_netdev ( void ) {
75 77
  * @v netdev		Network device
76 78
  */
77 79
 void netboot ( struct net_device *netdev ) {
80
+	char filename[256];
81
+	struct image *image;
82
+	int rc;
78 83
 
79 84
 	/* Open device and display device status */
80
-	if ( ifopen ( netdev ) != 0 )
85
+	if ( ( rc = ifopen ( netdev ) != 0 ) )
81 86
 		return;
82 87
 	ifstat ( netdev );
83 88
 
84
-	test_dhcp ( netdev );
85
-
89
+	/* Configure device via DHCP */
90
+	if ( ( rc = dhcp ( netdev ) != 0 ) )
91
+		return;
86 92
 	route();
93
+
94
+	/* Try to download and boot whatever we are given as a filename */
95
+	dhcp_snprintf ( filename, sizeof ( filename ),
96
+			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
97
+	if ( ! filename[0] ) {
98
+		printf ( "No boot filename\n" );
99
+		return;
100
+	}
101
+	printf ( "Booting \"%s\"\n", filename );
102
+	if ( ( rc = imgfetch ( filename, NULL, &image ) ) != 0 ) {
103
+		printf ( "Could not retrieve %s: %s\n",
104
+			 filename, strerror ( rc ) );
105
+		return;
106
+	}
107
+	if ( ( rc = imgload ( image ) ) != 0 ) {
108
+		printf ( "Could not load %s: %s\n", image->name,
109
+			 strerror ( rc ) );
110
+		return;
111
+	}
112
+	if ( ( rc = imgexec ( image ) ) != 0 ) {
113
+		printf ( "Could not execute %s: %s\n", image->name,
114
+			 strerror ( rc ) );
115
+		return;
116
+	}
87 117
 }
88 118
 
89 119
 /**

Загрузка…
Отмена
Сохранить