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:
parent
60cdb895da
commit
8c599704a7
7 changed files with 144 additions and 65 deletions
|
@ -24,7 +24,8 @@ kernel_img_SOURCES = kern/powerpc/ieee1275/startup.S kern/ieee1275/cmain.c \
|
||||||
kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
|
kern/parser.c kern/partition.c kern/env.c kern/$(target_cpu)/dl.c \
|
||||||
kern/generic/millisleep.c kern/time.c \
|
kern/generic/millisleep.c kern/time.c \
|
||||||
symlist.c kern/$(target_cpu)/cache.S net/ip.c net/tftp.c net/udp.c net/ethernet.c net/arp.c \
|
symlist.c kern/$(target_cpu)/cache.S net/ip.c net/tftp.c net/udp.c net/ethernet.c net/arp.c \
|
||||||
net/ieee1275/interface.c net/interface.c net/protocol.c net/netbuff.c
|
net/ieee1275/interface.c net/interface.c net/protocol.c net/netbuff.c \
|
||||||
|
fs/ieee1275/ofnet.c
|
||||||
kernel_img_CFLAGS = $(COMMON_CFLAGS)
|
kernel_img_CFLAGS = $(COMMON_CFLAGS)
|
||||||
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
|
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
|
||||||
kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x200000,-Bstatic
|
kernel_img_LDFLAGS += $(COMMON_LDFLAGS) -Wl,-N,-S,-Ttext,0x200000,-Bstatic
|
||||||
|
|
|
@ -42,7 +42,8 @@ enum grub_disk_dev_id
|
||||||
GRUB_DISK_DEVICE_PXE_ID,
|
GRUB_DISK_DEVICE_PXE_ID,
|
||||||
GRUB_DISK_DEVICE_SCSI_ID,
|
GRUB_DISK_DEVICE_SCSI_ID,
|
||||||
GRUB_DISK_DEVICE_FILE_ID,
|
GRUB_DISK_DEVICE_FILE_ID,
|
||||||
GRUB_DISK_DEVICE_LUKS_ID
|
GRUB_DISK_DEVICE_LUKS_ID,
|
||||||
|
GRUB_DISK_DEVICE_OFNET_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
struct grub_disk;
|
struct grub_disk;
|
||||||
|
|
|
@ -182,9 +182,8 @@ EXPORT_FUNC(grub_ieee1275_map) (grub_addr_t phys, grub_addr_t virt,
|
||||||
|
|
||||||
char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
|
char *EXPORT_FUNC(grub_ieee1275_encode_devname) (const char *path);
|
||||||
char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
|
char *EXPORT_FUNC(grub_ieee1275_get_filename) (const char *path);
|
||||||
|
|
||||||
int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
|
int EXPORT_FUNC(grub_ieee1275_devices_iterate) (int (*hook)
|
||||||
(struct grub_ieee1275_devalias *
|
(struct grub_ieee1275_devalias *
|
||||||
alias));
|
alias));
|
||||||
|
char *EXPORT_FUNC(grub_ieee1275_get_aliasdevname) (const char *path);
|
||||||
#endif /* ! GRUB_IEEE1275_HEADER */
|
#endif /* ! GRUB_IEEE1275_HEADER */
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <grub/ieee1275/ofdisk.h>
|
#include <grub/ieee1275/ofdisk.h>
|
||||||
#include <grub/ieee1275/ieee1275.h>
|
#include <grub/ieee1275/ieee1275.h>
|
||||||
#include <grub/offsets.h>
|
#include <grub/offsets.h>
|
||||||
|
#include <grub/ieee1275/ofnet.h>
|
||||||
|
|
||||||
/* The minimal heap size we can live with. */
|
/* The minimal heap size we can live with. */
|
||||||
#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024)
|
#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024)
|
||||||
|
@ -223,13 +224,14 @@ grub_machine_init (void)
|
||||||
grub_ssize_t actual;
|
grub_ssize_t actual;
|
||||||
|
|
||||||
grub_ieee1275_init ();
|
grub_ieee1275_init ();
|
||||||
|
|
||||||
grub_console_init ();
|
grub_console_init ();
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
grub_get_extended_memory ();
|
grub_get_extended_memory ();
|
||||||
#endif
|
#endif
|
||||||
grub_claim_heap ();
|
grub_claim_heap ();
|
||||||
grub_ofdisk_init ();
|
grub_ofdisk_init ();
|
||||||
|
grub_ofnet_init();
|
||||||
|
|
||||||
/* Process commandline. */
|
/* Process commandline. */
|
||||||
if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args,
|
if (grub_ieee1275_get_property (grub_ieee1275_chosen, "bootargs", &args,
|
||||||
|
|
|
@ -22,11 +22,13 @@
|
||||||
#include <grub/misc.h>
|
#include <grub/misc.h>
|
||||||
#include <grub/mm.h>
|
#include <grub/mm.h>
|
||||||
#include <grub/ieee1275/ieee1275.h>
|
#include <grub/ieee1275/ieee1275.h>
|
||||||
|
#include <grub/ieee1275/ofnet.h>
|
||||||
|
|
||||||
enum grub_ieee1275_parse_type
|
enum grub_ieee1275_parse_type
|
||||||
{
|
{
|
||||||
GRUB_PARSE_FILENAME,
|
GRUB_PARSE_FILENAME,
|
||||||
GRUB_PARSE_PARTITION,
|
GRUB_PARSE_PARTITION,
|
||||||
|
GRUB_PARSE_DEVICE
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Walk children of 'devpath', calling hook for each. */
|
/* 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));
|
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);
|
grub_printf ("Unsupported type %s for device %s\n", type, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,6 +385,12 @@ fail:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
grub_ieee1275_get_aliasdevname (const char *path)
|
||||||
|
{
|
||||||
|
return grub_ieee1275_parse_args (path, GRUB_PARSE_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
grub_ieee1275_get_filename (const char *path)
|
grub_ieee1275_get_filename (const char *path)
|
||||||
{
|
{
|
||||||
|
@ -432,3 +442,51 @@ grub_halt (void)
|
||||||
grub_ieee1275_interpret ("power-off", 0);
|
grub_ieee1275_interpret ("power-off", 0);
|
||||||
grub_ieee1275_interpret ("poweroff", 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,14 +95,14 @@ grub_load_modules (void)
|
||||||
|
|
||||||
grub_module_iterate (hook);
|
grub_module_iterate (hook);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
static void
|
static void
|
||||||
grub_load_config (void)
|
grub_load_config (void)
|
||||||
{
|
{
|
||||||
auto int hook (struct grub_module_header *);
|
auto int hook (struct grub_module_header *);
|
||||||
int hook (struct grub_module_header *header)
|
int hook (struct grub_module_header *header)
|
||||||
{
|
{
|
||||||
/* Not an embedded config, skip. */
|
/ Not an embedded config, skip. /
|
||||||
if (header->type != OBJ_TYPE_CONFIG)
|
if (header->type != OBJ_TYPE_CONFIG)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ grub_load_config (void)
|
||||||
|
|
||||||
grub_module_iterate (hook);
|
grub_module_iterate (hook);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/* Write hook for the environment variables of root. Remove surrounding
|
/* Write hook for the environment variables of root. Remove surrounding
|
||||||
parentheses, if any. */
|
parentheses, if any. */
|
||||||
static char *
|
static char *
|
||||||
|
@ -192,7 +192,7 @@ grub_main (void)
|
||||||
|
|
||||||
grub_register_core_commands ();
|
grub_register_core_commands ();
|
||||||
|
|
||||||
grub_load_config ();
|
//grub_load_config ();
|
||||||
grub_load_normal_mode ();
|
grub_load_normal_mode ();
|
||||||
grub_rescue_run ();
|
grub_rescue_run ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,55 +1,21 @@
|
||||||
#include <grub/net/ieee1275/interface.h>
|
#include <grub/net/ieee1275/interface.h>
|
||||||
|
#include <grub/time.h>
|
||||||
#include <grub/mm.h>
|
#include <grub/mm.h>
|
||||||
|
#include <grub/net/ethernet.h>
|
||||||
grub_uint32_t get_server_ip (void)
|
#include <grub/net/ip.h>
|
||||||
{
|
#include <grub/net/arp.h>
|
||||||
return bootp_pckt->siaddr;
|
#include <grub/net/netbuff.h>
|
||||||
}
|
#include <grub/ieee1275/ofnet.h>
|
||||||
|
|
||||||
grub_uint32_t get_client_ip (void)
|
|
||||||
{
|
|
||||||
return bootp_pckt->yiaddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_uint8_t* get_server_mac (void)
|
|
||||||
{
|
|
||||||
grub_uint8_t *mac;
|
|
||||||
|
|
||||||
mac = grub_malloc (6 * sizeof(grub_uint8_t));
|
|
||||||
mac[0] = 0x00 ;
|
|
||||||
mac[1] = 0x11 ;
|
|
||||||
mac[2] = 0x25 ;
|
|
||||||
mac[3] = 0xca ;
|
|
||||||
mac[4] = 0x1f ;
|
|
||||||
mac[5] = 0x01 ;
|
|
||||||
|
|
||||||
return mac;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
grub_uint8_t* get_client_mac (void)
|
|
||||||
{
|
|
||||||
grub_uint8_t *mac;
|
|
||||||
|
|
||||||
mac = grub_malloc (6 * sizeof (grub_uint8_t));
|
|
||||||
mac[0] = 0x0a ;
|
|
||||||
mac[1] = 0x11 ;
|
|
||||||
mac[2] = 0xbd ;
|
|
||||||
mac[3] = 0xe3 ;
|
|
||||||
mac[4] = 0xe3 ;
|
|
||||||
mac[5] = 0x04 ;
|
|
||||||
|
|
||||||
return mac;
|
|
||||||
}
|
|
||||||
|
|
||||||
static grub_ieee1275_ihandle_t handle;
|
static grub_ieee1275_ihandle_t handle;
|
||||||
int card_open (void)
|
int card_open (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
grub_ieee1275_open (grub_net->dev , &handle);
|
grub_ieee1275_open (grub_net->dev , &handle);
|
||||||
return 1;//error
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int card_close (void)
|
int card_close (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -59,22 +25,74 @@ int card_close (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int send_card_buffer (void *buffer,int buff_len)
|
int send_card_buffer (struct grub_net_buff *pack)
|
||||||
{
|
{
|
||||||
|
|
||||||
int actual;
|
int actual;
|
||||||
|
//grub_printf("packet size transmited: %d\n",pack->tail - pack->data);
|
||||||
grub_ieee1275_write (handle,buffer,buff_len,&actual);
|
grub_ieee1275_write (handle,pack->data,pack->tail - pack->data,&actual);
|
||||||
|
// grub_printf("actual transmited %d\n",actual);
|
||||||
|
|
||||||
return actual;
|
return actual;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_card_buffer (void *buffer,int buff_len)
|
int get_card_packet (struct grub_net_buff *pack __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
|
|
||||||
int actual;
|
int actual;
|
||||||
|
char *datap;
|
||||||
|
struct iphdr *iph;
|
||||||
|
struct etherhdr *eth;
|
||||||
|
struct arphdr *arph;
|
||||||
|
pack->data = pack->tail = pack->head;
|
||||||
|
datap = pack->data;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
grub_ieee1275_read (handle,datap,sizeof (*eth),&actual);
|
||||||
|
// if (actual <= 0)
|
||||||
|
// grub_millisleep(10);
|
||||||
|
|
||||||
grub_ieee1275_read (handle,buffer,buff_len,&actual);
|
}while (actual <= 0);
|
||||||
|
eth = (struct etherhdr *) datap;
|
||||||
return actual;
|
datap += sizeof(*eth);
|
||||||
|
|
||||||
|
// grub_printf("ethernet eth->dst %x:%x:%x:%x:%x:%x\n",eth->dst[0],
|
||||||
|
// eth->dst[1],eth->dst[2],eth->dst[3],eth->dst[4],eth->dst[5]);
|
||||||
|
// grub_printf("ethernet eth->src %x:%x:%x:%x:%x:%x\n",eth->src[0],eth->src[1],
|
||||||
|
// eth->src[2],eth->src[3],eth->src[4],eth->src[5]);
|
||||||
|
// grub_printf ("eth.type 0x%x\n",eth->type);
|
||||||
|
|
||||||
|
switch (eth->type)
|
||||||
|
{
|
||||||
|
case 0x806:
|
||||||
|
|
||||||
|
grub_ieee1275_read (handle,datap,sizeof (*arph),&actual);
|
||||||
|
arph = (struct arphdr *) datap;
|
||||||
|
|
||||||
|
grub_netbuff_put (pack,sizeof (*eth) + sizeof (*arph));
|
||||||
|
break;
|
||||||
|
case 0x800:
|
||||||
|
grub_ieee1275_read (handle,datap,sizeof (*iph),&actual);
|
||||||
|
iph = (struct iphdr *) datap;
|
||||||
|
datap += sizeof(*iph);
|
||||||
|
|
||||||
|
// grub_printf("ip.src 0x%x\n",iph->src);
|
||||||
|
// grub_printf("ip.dst 0x%x\n",iph->dest);
|
||||||
|
// grub_printf("ip.len 0x%x\n",iph->len);
|
||||||
|
// grub_printf("ip.protocol 0x%x\n",iph->protocol);
|
||||||
|
|
||||||
|
grub_ieee1275_read (handle,datap,iph->len - sizeof (*iph),&actual);
|
||||||
|
|
||||||
|
|
||||||
|
grub_netbuff_put (pack,sizeof (*eth) + iph->len);
|
||||||
|
break;
|
||||||
|
case 0x86DD:
|
||||||
|
grub_printf("Ipv6 not yet implemented.\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
grub_printf("Unknow packet %x\n",eth->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// grub_printf("packsize %d\n",pack->tail - pack->data);
|
||||||
|
return 0;// sizeof (eth) + iph.len;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue