Browse Source

Attempt a PXE NBP boot as the TFTP test.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
c9e6c33bba
2 changed files with 21 additions and 19 deletions
  1. 3
    3
      src/tests/dhcptest.c
  2. 18
    16
      src/tests/tftptest.c

+ 3
- 3
src/tests/dhcptest.c View File

57
 	return 0;
57
 	return 0;
58
 }
58
 }
59
 
59
 
60
-static int test_dhcp_tftp ( char *tftpname ) {
60
+static int test_dhcp_tftp ( struct net_device *netdev, char *tftpname ) {
61
 	union {
61
 	union {
62
 		struct sockaddr_in sin;
62
 		struct sockaddr_in sin;
63
 		struct sockaddr_tcpip st;
63
 		struct sockaddr_tcpip st;
69
 	find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR,
69
 	find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR,
70
 				       &target.sin.sin_addr );
70
 				       &target.sin.sin_addr );
71
 
71
 
72
-	return test_tftp ( &target.st, tftpname );
72
+	return test_tftp ( netdev, &target.st, tftpname );
73
 }
73
 }
74
 
74
 
75
 static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
75
 static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
80
 	} else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
80
 	} else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
81
 		return test_dhcp_hello ( &filename[6] );
81
 		return test_dhcp_hello ( &filename[6] );
82
 	} else {
82
 	} else {
83
-		return test_dhcp_tftp ( filename );
83
+		return test_dhcp_tftp ( netdev, filename );
84
 	}
84
 	}
85
 }
85
 }
86
 
86
 

+ 18
- 16
src/tests/tftptest.c View File

4
 #include <gpxe/udp.h>
4
 #include <gpxe/udp.h>
5
 #include <gpxe/tftp.h>
5
 #include <gpxe/tftp.h>
6
 #include <gpxe/async.h>
6
 #include <gpxe/async.h>
7
+#include <gpxe/uaccess.h>
8
+#include "pxe.h"
7
 
9
 
8
-static void test_tftp_callback ( struct tftp_session *tftp __unused,
9
-				 unsigned int block __unused,
10
+static void test_tftp_callback ( struct tftp_session *tftp, unsigned int block,
10
 				 void *data, size_t len ) {
11
 				 void *data, size_t len ) {
11
-	unsigned int i;
12
-	char c;
12
+	unsigned long offset = ( ( block - 1 ) * tftp->blksize );
13
+	userptr_t pxe_buffer = real_to_user ( 0, 0x7c00 );
13
 
14
 
14
-	for ( i = 0 ; i < len ; i++ ) {
15
-		c = * ( ( char * ) data + i );
16
-		if ( c == '\r' ) {
17
-			/* Print nothing */
18
-		} else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
19
-			putchar ( c );
20
-		} else {
21
-			putchar ( '.' );
22
-		}
23
-	}	
15
+	copy_to_user ( pxe_buffer, offset, data, len );
24
 }
16
 }
25
 
17
 
26
-int test_tftp ( struct sockaddr_tcpip *target, const char *filename ) {
18
+int test_tftp ( struct net_device *netdev, struct sockaddr_tcpip *target,
19
+		const char *filename ) {
27
 	struct tftp_session tftp;
20
 	struct tftp_session tftp;
21
+	int rc;
28
 
22
 
29
 	memset ( &tftp, 0, sizeof ( tftp ) );
23
 	memset ( &tftp, 0, sizeof ( tftp ) );
30
 	udp_connect ( &tftp.udp, target );
24
 	udp_connect ( &tftp.udp, target );
31
 	tftp.filename = filename;
25
 	tftp.filename = filename;
32
 	tftp.callback = test_tftp_callback;
26
 	tftp.callback = test_tftp_callback;
33
 
27
 
34
-	return async_wait ( tftp_get ( &tftp ) );
28
+	printf ( "Fetching \"%s\" via TFTP\n", filename );
29
+	if ( ( rc = async_wait ( tftp_get ( &tftp ) ) ) != 0 )
30
+		return rc;
31
+
32
+	printf ( "Attempting PXE boot\n" );
33
+	pxe_netdev = netdev;
34
+	rc = pxe_boot();
35
+	printf ( "PXE NBP returned with status %04x\n", rc );
36
+	return 0;
35
 }
37
 }

Loading…
Cancel
Save