Преглед изворни кода

Allow an AoE boot to be directed via DHCP, so that we have a proof of

concept demo that actually does something useful.
tags/v0.9.3
Michael Brown пре 18 година
родитељ
комит
a92d242008
2 измењених фајлова са 52 додато и 4 уклоњено
  1. 30
    2
      src/tests/aoeboot.c
  2. 22
    2
      src/tests/dhcptest.c

+ 30
- 2
src/tests/aoeboot.c Прегледај датотеку

@@ -1,4 +1,5 @@
1 1
 #include <stdint.h>
2
+#include <stdlib.h>
2 3
 #include <vsprintf.h>
3 4
 #include <console.h>
4 5
 #include <gpxe/netdevice.h>
@@ -12,13 +13,39 @@ static struct aoe_device test_aoedev = {
12 13
 	},
13 14
 };
14 15
 
15
-int test_aoeboot ( struct net_device *netdev ) {
16
+static int aoe_parse ( const char *aoename, struct aoe_session *aoe ) {
17
+	char *ptr = ( ( char * ) aoename );
18
+
19
+	if ( *ptr++ != 'e' )
20
+		return -EINVAL;
21
+
22
+	aoe->major = strtoul ( ptr, &ptr, 10 );
23
+	if ( *ptr++ != '.' )
24
+		return -EINVAL;
25
+
26
+	aoe->minor = strtoul ( ptr, &ptr, 10 );
27
+	if ( *ptr )
28
+		return -EINVAL;
29
+
30
+	return 0;
31
+}
32
+
33
+int test_aoeboot ( struct net_device *netdev, const char *aoename,
34
+		   unsigned int drivenum ) {
16 35
 	struct int13_drive drive;
17 36
 	int rc;
18 37
 
19
-	test_aoedev.aoe.netdev = netdev;
38
+	printf ( "Attempting to boot from AoE device %s via %s\n",
39
+		 aoename, netdev_name ( netdev ) );
40
+
41
+	if ( ( rc = aoe_parse ( aoename, &test_aoedev.aoe ) ) != 0 ) {
42
+		printf ( "Invalid AoE device name \"%s\"\n", aoename );
43
+		return rc;
44
+	}
45
+
20 46
 	printf ( "Initialising AoE device e%d.%d\n",
21 47
 		 test_aoedev.aoe.major, test_aoedev.aoe.minor );
48
+	test_aoedev.aoe.netdev = netdev;
22 49
 	if ( ( rc = init_aoedev ( &test_aoedev ) ) != 0 ) {
23 50
 		printf ( "Could not reach AoE device e%d.%d\n",
24 51
 			 test_aoedev.aoe.major, test_aoedev.aoe.minor );
@@ -26,6 +53,7 @@ int test_aoeboot ( struct net_device *netdev ) {
26 53
 	}
27 54
 
28 55
 	memset ( &drive, 0, sizeof ( drive ) );
56
+	drive.drive = drivenum;
29 57
 	drive.blockdev = &test_aoedev.ata.blockdev;
30 58
 	register_int13_drive ( &drive );
31 59
 	printf ( "Registered AoE device e%d.%d as BIOS drive %#02x\n",

+ 22
- 2
src/tests/dhcptest.c Прегледај датотеку

@@ -9,6 +9,7 @@ int test_dhcp ( struct net_device *netdev ) {
9 9
 	struct in_addr address = { htonl ( 0 ) };
10 10
 	struct in_addr netmask = { htonl ( 0 ) };
11 11
 	struct in_addr gateway = { INADDR_NONE };
12
+	char filename[256];
12 13
 	int rc;
13 14
 
14 15
 	/* Bring IP interface up with address 0.0.0.0 */
@@ -34,8 +35,14 @@ int test_dhcp ( struct net_device *netdev ) {
34 35
 	printf ( " netmask %s", inet_ntoa ( netmask ) );
35 36
 	printf ( " gateway %s\n", inet_ntoa ( gateway ) );
36 37
 
37
-	printf ( "Lease time is %ld seconds\n",
38
-		 find_global_dhcp_num_option ( DHCP_LEASE_TIME ) );
38
+	dhcp_snprintf ( filename, sizeof ( filename ),
39
+			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
40
+	if ( ! filename[0] ) {
41
+		printf ( "No filename specified!\n" );
42
+		goto out;
43
+	}
44
+	
45
+	printf ( "Bootfile name %s\n", filename );
39 46
 
40 47
 	/* Remove old IP address configuration */
41 48
 	del_ipv4_address ( netdev );
@@ -45,6 +52,19 @@ int test_dhcp ( struct net_device *netdev ) {
45 52
 				       gateway ) ) != 0 )
46 53
 		goto out_no_del_ipv4;
47 54
 
55
+	/* Proof of concept: check for "aoe:" prefix and if found, do
56
+	 * test AoE boot with AoE options.
57
+	 */
58
+	if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
59
+		unsigned int drivenum;
60
+		
61
+		drivenum = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
62
+		test_aoeboot ( netdev, &filename[4], drivenum );
63
+	} else {
64
+		printf ( "Don't know how to boot %s\n", filename );
65
+	}
66
+	
67
+ out:
48 68
 	/* Unregister and free DHCP options */
49 69
 	unregister_dhcp_options ( dhcp.options );
50 70
 	free_dhcp_options ( dhcp.options );

Loading…
Откажи
Сачувај