mirror of https://github.com/ipxe/ipxe.git
Allow an AoE boot to be directed via DHCP, so that we have a proof of
concept demo that actually does something useful.pull/1/head
parent
3085f03ad4
commit
a92d242008
|
@ -1,4 +1,5 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <vsprintf.h>
|
#include <vsprintf.h>
|
||||||
#include <console.h>
|
#include <console.h>
|
||||||
#include <gpxe/netdevice.h>
|
#include <gpxe/netdevice.h>
|
||||||
|
@ -12,13 +13,39 @@ static struct aoe_device test_aoedev = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
int test_aoeboot ( struct net_device *netdev ) {
|
static int aoe_parse ( const char *aoename, struct aoe_session *aoe ) {
|
||||||
|
char *ptr = ( ( char * ) aoename );
|
||||||
|
|
||||||
|
if ( *ptr++ != 'e' )
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
aoe->major = strtoul ( ptr, &ptr, 10 );
|
||||||
|
if ( *ptr++ != '.' )
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
aoe->minor = strtoul ( ptr, &ptr, 10 );
|
||||||
|
if ( *ptr )
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_aoeboot ( struct net_device *netdev, const char *aoename,
|
||||||
|
unsigned int drivenum ) {
|
||||||
struct int13_drive drive;
|
struct int13_drive drive;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
test_aoedev.aoe.netdev = netdev;
|
printf ( "Attempting to boot from AoE device %s via %s\n",
|
||||||
|
aoename, netdev_name ( netdev ) );
|
||||||
|
|
||||||
|
if ( ( rc = aoe_parse ( aoename, &test_aoedev.aoe ) ) != 0 ) {
|
||||||
|
printf ( "Invalid AoE device name \"%s\"\n", aoename );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
printf ( "Initialising AoE device e%d.%d\n",
|
printf ( "Initialising AoE device e%d.%d\n",
|
||||||
test_aoedev.aoe.major, test_aoedev.aoe.minor );
|
test_aoedev.aoe.major, test_aoedev.aoe.minor );
|
||||||
|
test_aoedev.aoe.netdev = netdev;
|
||||||
if ( ( rc = init_aoedev ( &test_aoedev ) ) != 0 ) {
|
if ( ( rc = init_aoedev ( &test_aoedev ) ) != 0 ) {
|
||||||
printf ( "Could not reach AoE device e%d.%d\n",
|
printf ( "Could not reach AoE device e%d.%d\n",
|
||||||
test_aoedev.aoe.major, test_aoedev.aoe.minor );
|
test_aoedev.aoe.major, test_aoedev.aoe.minor );
|
||||||
|
@ -26,6 +53,7 @@ int test_aoeboot ( struct net_device *netdev ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
memset ( &drive, 0, sizeof ( drive ) );
|
memset ( &drive, 0, sizeof ( drive ) );
|
||||||
|
drive.drive = drivenum;
|
||||||
drive.blockdev = &test_aoedev.ata.blockdev;
|
drive.blockdev = &test_aoedev.ata.blockdev;
|
||||||
register_int13_drive ( &drive );
|
register_int13_drive ( &drive );
|
||||||
printf ( "Registered AoE device e%d.%d as BIOS drive %#02x\n",
|
printf ( "Registered AoE device e%d.%d as BIOS drive %#02x\n",
|
||||||
|
|
|
@ -9,6 +9,7 @@ int test_dhcp ( struct net_device *netdev ) {
|
||||||
struct in_addr address = { htonl ( 0 ) };
|
struct in_addr address = { htonl ( 0 ) };
|
||||||
struct in_addr netmask = { htonl ( 0 ) };
|
struct in_addr netmask = { htonl ( 0 ) };
|
||||||
struct in_addr gateway = { INADDR_NONE };
|
struct in_addr gateway = { INADDR_NONE };
|
||||||
|
char filename[256];
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Bring IP interface up with address 0.0.0.0 */
|
/* Bring IP interface up with address 0.0.0.0 */
|
||||||
|
@ -34,8 +35,14 @@ int test_dhcp ( struct net_device *netdev ) {
|
||||||
printf ( " netmask %s", inet_ntoa ( netmask ) );
|
printf ( " netmask %s", inet_ntoa ( netmask ) );
|
||||||
printf ( " gateway %s\n", inet_ntoa ( gateway ) );
|
printf ( " gateway %s\n", inet_ntoa ( gateway ) );
|
||||||
|
|
||||||
printf ( "Lease time is %ld seconds\n",
|
dhcp_snprintf ( filename, sizeof ( filename ),
|
||||||
find_global_dhcp_num_option ( DHCP_LEASE_TIME ) );
|
find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
|
||||||
|
if ( ! filename[0] ) {
|
||||||
|
printf ( "No filename specified!\n" );
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf ( "Bootfile name %s\n", filename );
|
||||||
|
|
||||||
/* Remove old IP address configuration */
|
/* Remove old IP address configuration */
|
||||||
del_ipv4_address ( netdev );
|
del_ipv4_address ( netdev );
|
||||||
|
@ -45,6 +52,19 @@ int test_dhcp ( struct net_device *netdev ) {
|
||||||
gateway ) ) != 0 )
|
gateway ) ) != 0 )
|
||||||
goto out_no_del_ipv4;
|
goto out_no_del_ipv4;
|
||||||
|
|
||||||
|
/* Proof of concept: check for "aoe:" prefix and if found, do
|
||||||
|
* test AoE boot with AoE options.
|
||||||
|
*/
|
||||||
|
if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
|
||||||
|
unsigned int drivenum;
|
||||||
|
|
||||||
|
drivenum = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
|
||||||
|
test_aoeboot ( netdev, &filename[4], drivenum );
|
||||||
|
} else {
|
||||||
|
printf ( "Don't know how to boot %s\n", filename );
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
/* Unregister and free DHCP options */
|
/* Unregister and free DHCP options */
|
||||||
unregister_dhcp_options ( dhcp.options );
|
unregister_dhcp_options ( dhcp.options );
|
||||||
free_dhcp_options ( dhcp.options );
|
free_dhcp_options ( dhcp.options );
|
||||||
|
|
Loading…
Reference in New Issue