Browse Source

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 years ago
parent
commit
a92d242008
2 changed files with 52 additions and 4 deletions
  1. 30
    2
      src/tests/aoeboot.c
  2. 22
    2
      src/tests/dhcptest.c

+ 30
- 2
src/tests/aoeboot.c View File

1
 #include <stdint.h>
1
 #include <stdint.h>
2
+#include <stdlib.h>
2
 #include <vsprintf.h>
3
 #include <vsprintf.h>
3
 #include <console.h>
4
 #include <console.h>
4
 #include <gpxe/netdevice.h>
5
 #include <gpxe/netdevice.h>
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
 	struct int13_drive drive;
35
 	struct int13_drive drive;
17
 	int rc;
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
 	printf ( "Initialising AoE device e%d.%d\n",
46
 	printf ( "Initialising AoE device e%d.%d\n",
21
 		 test_aoedev.aoe.major, test_aoedev.aoe.minor );
47
 		 test_aoedev.aoe.major, test_aoedev.aoe.minor );
48
+	test_aoedev.aoe.netdev = netdev;
22
 	if ( ( rc = init_aoedev ( &test_aoedev ) ) != 0 ) {
49
 	if ( ( rc = init_aoedev ( &test_aoedev ) ) != 0 ) {
23
 		printf ( "Could not reach AoE device e%d.%d\n",
50
 		printf ( "Could not reach AoE device e%d.%d\n",
24
 			 test_aoedev.aoe.major, test_aoedev.aoe.minor );
51
 			 test_aoedev.aoe.major, test_aoedev.aoe.minor );
26
 	}
53
 	}
27
 
54
 
28
 	memset ( &drive, 0, sizeof ( drive ) );
55
 	memset ( &drive, 0, sizeof ( drive ) );
56
+	drive.drive = drivenum;
29
 	drive.blockdev = &test_aoedev.ata.blockdev;
57
 	drive.blockdev = &test_aoedev.ata.blockdev;
30
 	register_int13_drive ( &drive );
58
 	register_int13_drive ( &drive );
31
 	printf ( "Registered AoE device e%d.%d as BIOS drive %#02x\n",
59
 	printf ( "Registered AoE device e%d.%d as BIOS drive %#02x\n",

+ 22
- 2
src/tests/dhcptest.c View File

9
 	struct in_addr address = { htonl ( 0 ) };
9
 	struct in_addr address = { htonl ( 0 ) };
10
 	struct in_addr netmask = { htonl ( 0 ) };
10
 	struct in_addr netmask = { htonl ( 0 ) };
11
 	struct in_addr gateway = { INADDR_NONE };
11
 	struct in_addr gateway = { INADDR_NONE };
12
+	char filename[256];
12
 	int rc;
13
 	int rc;
13
 
14
 
14
 	/* Bring IP interface up with address 0.0.0.0 */
15
 	/* Bring IP interface up with address 0.0.0.0 */
34
 	printf ( " netmask %s", inet_ntoa ( netmask ) );
35
 	printf ( " netmask %s", inet_ntoa ( netmask ) );
35
 	printf ( " gateway %s\n", inet_ntoa ( gateway ) );
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
 	/* Remove old IP address configuration */
47
 	/* Remove old IP address configuration */
41
 	del_ipv4_address ( netdev );
48
 	del_ipv4_address ( netdev );
45
 				       gateway ) ) != 0 )
52
 				       gateway ) ) != 0 )
46
 		goto out_no_del_ipv4;
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
 	/* Unregister and free DHCP options */
68
 	/* Unregister and free DHCP options */
49
 	unregister_dhcp_options ( dhcp.options );
69
 	unregister_dhcp_options ( dhcp.options );
50
 	free_dhcp_options ( dhcp.options );
70
 	free_dhcp_options ( dhcp.options );

Loading…
Cancel
Save