david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Attempt a PXE NBP boot as the TFTP test.

This commit is contained in:
Michael Brown 2006-08-09 03:00:11 +00:00
parent f018da8215
commit c9e6c33bba
2 changed files with 21 additions and 19 deletions

View File

@ -57,7 +57,7 @@ static int test_dhcp_hello ( char *helloname ) {
return 0; return 0;
} }
static int test_dhcp_tftp ( char *tftpname ) { static int test_dhcp_tftp ( struct net_device *netdev, char *tftpname ) {
union { union {
struct sockaddr_in sin; struct sockaddr_in sin;
struct sockaddr_tcpip st; struct sockaddr_tcpip st;
@ -69,7 +69,7 @@ static int test_dhcp_tftp ( char *tftpname ) {
find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR, find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR,
&target.sin.sin_addr ); &target.sin.sin_addr );
return test_tftp ( &target.st, tftpname ); return test_tftp ( netdev, &target.st, tftpname );
} }
static int test_dhcp_boot ( struct net_device *netdev, char *filename ) { static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
@ -80,7 +80,7 @@ static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
} else if ( strncmp ( filename, "hello:", 6 ) == 0 ) { } else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
return test_dhcp_hello ( &filename[6] ); return test_dhcp_hello ( &filename[6] );
} else { } else {
return test_dhcp_tftp ( filename ); return test_dhcp_tftp ( netdev, filename );
} }
} }

View File

@ -4,32 +4,34 @@
#include <gpxe/udp.h> #include <gpxe/udp.h>
#include <gpxe/tftp.h> #include <gpxe/tftp.h>
#include <gpxe/async.h> #include <gpxe/async.h>
#include <gpxe/uaccess.h>
#include "pxe.h"
static void test_tftp_callback ( struct tftp_session *tftp __unused, static void test_tftp_callback ( struct tftp_session *tftp, unsigned int block,
unsigned int block __unused,
void *data, size_t len ) { void *data, size_t len ) {
unsigned int i; unsigned long offset = ( ( block - 1 ) * tftp->blksize );
char c; userptr_t pxe_buffer = real_to_user ( 0, 0x7c00 );
for ( i = 0 ; i < len ; i++ ) { copy_to_user ( pxe_buffer, offset, data, len );
c = * ( ( char * ) data + i );
if ( c == '\r' ) {
/* Print nothing */
} else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
putchar ( c );
} else {
putchar ( '.' );
}
}
} }
int test_tftp ( struct sockaddr_tcpip *target, const char *filename ) { int test_tftp ( struct net_device *netdev, struct sockaddr_tcpip *target,
const char *filename ) {
struct tftp_session tftp; struct tftp_session tftp;
int rc;
memset ( &tftp, 0, sizeof ( tftp ) ); memset ( &tftp, 0, sizeof ( tftp ) );
udp_connect ( &tftp.udp, target ); udp_connect ( &tftp.udp, target );
tftp.filename = filename; tftp.filename = filename;
tftp.callback = test_tftp_callback; tftp.callback = test_tftp_callback;
return async_wait ( tftp_get ( &tftp ) ); printf ( "Fetching \"%s\" via TFTP\n", filename );
if ( ( rc = async_wait ( tftp_get ( &tftp ) ) ) != 0 )
return rc;
printf ( "Attempting PXE boot\n" );
pxe_netdev = netdev;
rc = pxe_boot();
printf ( "PXE NBP returned with status %04x\n", rc );
return 0;
} }