浏览代码

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

tags/v0.9.3
Michael Brown 18 年前
父节点
当前提交
49fc8dcdc3
共有 1 个文件被更改,包括 35 次插入5 次删除
  1. 35
    5
      src/usr/autoboot.c

+ 35
- 5
src/usr/autoboot.c 查看文件

20
 #include <errno.h>
20
 #include <errno.h>
21
 #include <vsprintf.h>
21
 #include <vsprintf.h>
22
 #include <gpxe/netdevice.h>
22
 #include <gpxe/netdevice.h>
23
+#include <gpxe/dhcp.h>
24
+#include <gpxe/image.h>
23
 #include <usr/ifmgmt.h>
25
 #include <usr/ifmgmt.h>
24
 #include <usr/route.h>
26
 #include <usr/route.h>
27
+#include <usr/dhcpmgmt.h>
28
+#include <usr/imgmgmt.h>
25
 #include <usr/autoboot.h>
29
 #include <usr/autoboot.h>
26
 
30
 
27
 /** @file
31
 /** @file
30
  *
34
  *
31
  */
35
  */
32
 
36
 
33
-void test_dhcp ( struct net_device *netdev );
34
-
35
 /**
37
 /**
36
  * Identify the boot network device
38
  * Identify the boot network device
37
  *
39
  *
75
  * @v netdev		Network device
77
  * @v netdev		Network device
76
  */
78
  */
77
 void netboot ( struct net_device *netdev ) {
79
 void netboot ( struct net_device *netdev ) {
80
+	char filename[256];
81
+	struct image *image;
82
+	int rc;
78
 
83
 
79
 	/* Open device and display device status */
84
 	/* Open device and display device status */
80
-	if ( ifopen ( netdev ) != 0 )
85
+	if ( ( rc = ifopen ( netdev ) != 0 ) )
81
 		return;
86
 		return;
82
 	ifstat ( netdev );
87
 	ifstat ( netdev );
83
 
88
 
84
-	test_dhcp ( netdev );
85
-
89
+	/* Configure device via DHCP */
90
+	if ( ( rc = dhcp ( netdev ) != 0 ) )
91
+		return;
86
 	route();
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
 /**

正在加载...
取消
保存