Network code specific for ieee1275 machines.

Used to parse BOOTP packet from the server and use write/read on the network card.
May be removed later.
This commit is contained in:
Manoel R. Abranches 2010-06-21 19:20:55 -03:00
parent 60cdb895da
commit 8c599704a7
7 changed files with 144 additions and 65 deletions

View file

@ -32,6 +32,7 @@
#include <grub/ieee1275/ofdisk.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/offsets.h>
#include <grub/ieee1275/ofnet.h>
/* The minimal heap size we can live with. */
#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024)
@ -223,13 +224,14 @@ grub_machine_init (void)
grub_ssize_t actual;
grub_ieee1275_init ();
grub_console_init ();
#ifdef __i386__
grub_get_extended_memory ();
#endif
grub_claim_heap ();
grub_ofdisk_init ();
grub_ofnet_init();
/* Process commandline. */
if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args,

View file

@ -22,11 +22,13 @@
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/ieee1275/ofnet.h>
enum grub_ieee1275_parse_type
{
GRUB_PARSE_FILENAME,
GRUB_PARSE_PARTITION,
GRUB_PARSE_DEVICE
};
/* Walk children of 'devpath', calling hook for each. */
@ -366,12 +368,14 @@ grub_ieee1275_parse_args (const char *path, enum grub_ieee1275_parse_type ptype)
ret = grub_strndup (args, (grub_size_t)(comma - args));
}
}
else
else if (!grub_strcmp ("network", type))
{
if (ptype == GRUB_PARSE_DEVICE)
ret = grub_strdup(device);
}
else
{
/* XXX Handle net devices by configuring & registering a grub_net_dev
here, then return its name?
Example path: "net:<server ip>,<file name>,<client ip>,<gateway
ip>,<bootp retries>,<tftp retries>". */
grub_printf ("Unsupported type %s for device %s\n", type, device);
}
@ -381,6 +385,12 @@ fail:
return ret;
}
char *
grub_ieee1275_get_aliasdevname (const char *path)
{
return grub_ieee1275_parse_args (path, GRUB_PARSE_DEVICE);
}
char *
grub_ieee1275_get_filename (const char *path)
{
@ -432,3 +442,51 @@ grub_halt (void)
grub_ieee1275_interpret ("power-off", 0);
grub_ieee1275_interpret ("poweroff", 0);
}
static const struct
{
char *name;
int offset;
}
bootp_response_properties[] =
{
{ .name = "bootp-response", .offset = 0 },
{ .name = "dhcp-response", .offset = 0 },
{ .name = "bootpreply-packet", .offset = 0x2a },
};
#define SIZE(X) ( sizeof (X) / sizeof(X[0]))
grub_bootp_t
grub_getbootp( void )
{
grub_bootp_t packet = grub_malloc(sizeof *packet);
void *bootp_response = NULL;
grub_ssize_t size;
unsigned int i;
// grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
for ( i = 0; i < SIZE(bootp_response_properties); i++)
{
if (grub_ieee1275_get_property_length (grub_ieee1275_chosen,
bootp_response_properties[i].name, &size)>=0)
break;
}
if ( size <0 )
{
grub_printf("Error to get bootp\n");
return NULL;
}
if (grub_ieee1275_get_property (grub_ieee1275_chosen, bootp_response_properties[i].name , bootp_response ,
size, 0) < 0)
{
grub_printf("Error to get bootp\n");
return NULL;
}
packet = (void *) ((int)bootp_response + bootp_response_properties[i].offset);
return packet;
}

View file

@ -95,14 +95,14 @@ grub_load_modules (void)
grub_module_iterate (hook);
}
/*
static void
grub_load_config (void)
{
auto int hook (struct grub_module_header *);
int hook (struct grub_module_header *header)
{
/* Not an embedded config, skip. */
/ Not an embedded config, skip. /
if (header->type != OBJ_TYPE_CONFIG)
return 0;
@ -113,7 +113,7 @@ grub_load_config (void)
grub_module_iterate (hook);
}
*/
/* Write hook for the environment variables of root. Remove surrounding
parentheses, if any. */
static char *
@ -192,7 +192,7 @@ grub_main (void)
grub_register_core_commands ();
grub_load_config ();
//grub_load_config ();
grub_load_normal_mode ();
grub_rescue_run ();
}