started testing. BOOTP crashes at ip_send() ?
This commit is contained in:
@@ -8,8 +8,6 @@
|
||||
#ifndef _NIF_H
|
||||
#define _NIF_H
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
/*
|
||||
* Maximum number of supported protoocls: IP, ARP, RARP
|
||||
*/
|
||||
@@ -40,23 +38,12 @@ typedef struct NIF_t
|
||||
unsigned int f_err;
|
||||
} NIF;
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
NIF *
|
||||
nif_init (NIF *);
|
||||
extern NIF *nif_init (NIF *);
|
||||
extern int nif_protocol_exist (NIF *, uint16_t);
|
||||
extern void nif_protocol_handler (NIF *, uint16_t, NBUF *);
|
||||
extern void *nif_get_protocol_info (NIF *, uint16_t);
|
||||
extern int nif_bind_protocol (NIF *, uint16_t, void (*)(NIF *, NBUF *), void *);
|
||||
|
||||
int
|
||||
nif_protocol_exist (NIF *, uint16_t);
|
||||
|
||||
void
|
||||
nif_protocol_handler (NIF *, uint16_t, NBUF *);
|
||||
|
||||
void *
|
||||
nif_get_protocol_info (NIF *, uint16_t);
|
||||
|
||||
int
|
||||
nif_bind_protocol (NIF *, uint16_t, void (*)(NIF *, NBUF *), void *);
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
#endif /* _NIF_H */
|
||||
|
||||
@@ -218,12 +218,13 @@ void arp_request(NIF *nif, uint8_t *pa)
|
||||
arp_frame_hdr *arpframe;
|
||||
int i, result;
|
||||
|
||||
|
||||
xprintf("%s\r\n", __FUNCTION__);
|
||||
|
||||
pNbuf = nbuf_alloc();
|
||||
if (pNbuf == NULL)
|
||||
{
|
||||
#if defined(DEBUG_PRINT)
|
||||
printf("ARP: arp_request couldn't allocate Tx buffer\n");
|
||||
#endif
|
||||
xprintf("ARP: arp_request couldn't allocate Tx buffer\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,15 +56,22 @@ void bootp_request(NIF *nif, uint8_t *pa)
|
||||
|
||||
nbuf->length = BOOTP_PACKET_LEN;
|
||||
|
||||
/* setup reply handler */
|
||||
udp_bind_port(BOOTP_CLIENT_PORT, bootp_handler);
|
||||
|
||||
for (i = 0; i < MAX_TRIES; i++)
|
||||
{
|
||||
/* Send the BOOTP request */
|
||||
result = udp_send(connection.nif, broadcast, BOOTP_CLIENT_PORT,
|
||||
BOOTP_SERVER_PORT, nbuf);
|
||||
xprintf("sent bootp request\r\n");
|
||||
if (result == true)
|
||||
break;
|
||||
}
|
||||
|
||||
/* release handler */
|
||||
udp_free_port(BOOTP_CLIENT_PORT);
|
||||
|
||||
if (result == 0)
|
||||
nbuf_free(nbuf);
|
||||
}
|
||||
@@ -85,6 +92,7 @@ void bootp_handler(NIF *nif, NBUF *nbuf)
|
||||
|
||||
if (rx_p->type == BOOTP_TYPE_BOOTREPLY && rx_p->xid == XID)
|
||||
{
|
||||
xprintf("received bootp reply\r\n");
|
||||
/* seems to be valid */
|
||||
|
||||
}
|
||||
|
||||
@@ -1025,7 +1025,7 @@ void fec1_tx_frame(void)
|
||||
* 1 success
|
||||
* 0 otherwise
|
||||
*/
|
||||
int fec_send (uint8_t ch, NIF *nif, uint8_t *dst, uint8_t *src, uint16_t type, NBUF *nbuf)
|
||||
int fec_send(uint8_t ch, NIF *nif, uint8_t *dst, uint8_t *src, uint16_t type, NBUF *nbuf)
|
||||
{
|
||||
FECBD *pTxBD;
|
||||
|
||||
|
||||
13
net/ip.c
13
net/ip.c
@@ -147,6 +147,9 @@ int ip_send(NIF *nif, uint8_t *dest, uint8_t *src, uint8_t protocol, NBUF *pNbuf
|
||||
/*
|
||||
* Determine the hardware address of the recipient
|
||||
*/
|
||||
IP_ADDR bc = { 255, 255, 255, 255};
|
||||
if (memcmp(bc, dest, 4) != 0)
|
||||
{
|
||||
route = ip_resolve_route(nif, dest);
|
||||
if (route == NULL)
|
||||
{
|
||||
@@ -154,13 +157,11 @@ int ip_send(NIF *nif, uint8_t *dest, uint8_t *src, uint8_t protocol, NBUF *pNbuf
|
||||
dest[0], dest[1], dest[2], dest[3]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
route = bc;
|
||||
|
||||
return nif->send(nif,
|
||||
route,
|
||||
&nif->hwa[0],
|
||||
ETH_FRM_IP,
|
||||
pNbuf
|
||||
);
|
||||
return nif->send(nif, route, &nif->hwa[0], ETH_FRM_IP, pNbuf);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_PRINT)
|
||||
|
||||
10
net/nbuf.c
10
net/nbuf.c
@@ -40,9 +40,9 @@ int nbuf_init(void)
|
||||
queue_init(&nbuf_queue[i]);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PRINT
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("Creating %d net buffers of %d bytes\n",NBUF_MAX,NBUF_SZ);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
for (i = 0; i < NBUF_MAX; ++i)
|
||||
{
|
||||
@@ -50,6 +50,7 @@ int nbuf_init(void)
|
||||
nbuf = (NBUF *) driver_mem_alloc(sizeof(NBUF));
|
||||
if (!nbuf)
|
||||
{
|
||||
xprintf("failed to allocate nbuf\r\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -69,10 +70,7 @@ int nbuf_init(void)
|
||||
queue_add(&nbuf_queue[NBUF_FREE], (QNODE *)nbuf);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_PRINT
|
||||
printf("NBUF allocation complete\n");
|
||||
nbuf_debug_dump();
|
||||
#endif
|
||||
xprintf("NBUF allocation complete\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
14
sys/BaS.c
14
sys/BaS.c
@@ -42,6 +42,7 @@
|
||||
#include "eth.h"
|
||||
#include "nbuf.h"
|
||||
#include "nif.h"
|
||||
#include "fec.h"
|
||||
|
||||
/* imported routines */
|
||||
extern int mmu_init();
|
||||
@@ -366,6 +367,19 @@ void BaS(void)
|
||||
xprintf("BaS initialization finished, enable interrupts\r\n");
|
||||
enable_coldfire_interrupts();
|
||||
|
||||
nbuf_init();
|
||||
uint8_t mac[6] = {0x00, 0x04, 0x9f, 0x01, 0x01, 0x01}; /* this is a Freescale MAC address */
|
||||
uint8_t bc[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; /* this is a Freescale MAC address */
|
||||
fec_eth_setup(0, FEC_MODE_MII, FEC_MII_100BASE_TX, FEC_MII_FULL_DUPLEX, mac);
|
||||
nif_init(&nif1);
|
||||
nif1.mtu = ETH_MTU;
|
||||
nif1.send = fec0_send;
|
||||
memcpy(nif1.hwa, mac, 6);
|
||||
memcpy(nif1.broadcast, bc, 6);
|
||||
bootp_request(&nif1, 0);
|
||||
|
||||
|
||||
|
||||
xprintf("call EmuTOS\r\n");
|
||||
ROM_HEADER* os_header = (ROM_HEADER*)TOS;
|
||||
os_header->initial_pc();
|
||||
|
||||
@@ -307,7 +307,7 @@ static int init_count = 0;
|
||||
|
||||
int driver_mem_init(void)
|
||||
{
|
||||
if (! init_count == 0)
|
||||
if (init_count == 0)
|
||||
{
|
||||
#ifdef USE_RADEON_MEMORY
|
||||
driver_mem_buffer = (void *) offscreen_reserved();
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "dma.h"
|
||||
#include "mod_devicetable.h"
|
||||
#include "pci_ids.h"
|
||||
#include "driver_mem.h"
|
||||
#include "usb.h"
|
||||
|
||||
#define UNUSED(x) (void)(x) /* Unused variable */
|
||||
@@ -1126,6 +1127,7 @@ void initialize_hardware(void)
|
||||
}
|
||||
|
||||
#endif /* MACHINE_FIREBEE */
|
||||
driver_mem_init();
|
||||
init_pci();
|
||||
|
||||
/* do not try to init USB for now on the Firebee, it hangs the machine */
|
||||
|
||||
343
usb/usb_mem.c
343
usb/usb_mem.c
@@ -1,343 +0,0 @@
|
||||
/*
|
||||
* driver_mem.c
|
||||
*
|
||||
* based from Emutos / BDOS
|
||||
*
|
||||
* Copyright (c) 2001 Lineo, Inc.
|
||||
*
|
||||
* Authors: Karl T. Braun, Martin Doering, Laurent Vogel
|
||||
*
|
||||
* This file is distributed under the GPL, version 2 or at your
|
||||
* option any later version.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bas_string.h"
|
||||
#include "bas_printf.h"
|
||||
#include "usb.h"
|
||||
#include "exceptions.h" /* set_ipl() */
|
||||
|
||||
#if MACHINE_FIREBEE
|
||||
#include "firebee.h"
|
||||
#elif MACHINE_M5484LITE
|
||||
#include "m5484l.h"
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#undef DRIVER_MEM_DEBUG
|
||||
|
||||
#ifdef DRIVER_MEM_DEBUG
|
||||
#define dbg(fmt, args...) xprintf(fmt, ##args)
|
||||
#else
|
||||
#define dbg(fmt, args...)
|
||||
#endif
|
||||
|
||||
extern void *info_fvdi;
|
||||
extern long offscren_reserved(void);
|
||||
|
||||
extern uint8_t driver_mem[DRIVER_MEM_SIZE]; /* defined in linker control file */
|
||||
|
||||
/* MD - Memory Descriptor */
|
||||
|
||||
#define MD struct _md_
|
||||
|
||||
MD
|
||||
{
|
||||
MD *m_link;
|
||||
long m_start;
|
||||
long m_length;
|
||||
void *m_own;
|
||||
};
|
||||
|
||||
/* MPB - Memory Partition Block */
|
||||
|
||||
#define MPB struct _mpb
|
||||
|
||||
MPB
|
||||
{
|
||||
MD *mp_mfl;
|
||||
MD *mp_mal;
|
||||
MD *mp_rover;
|
||||
};
|
||||
|
||||
#define MAXMD 256
|
||||
|
||||
static MD tab_md[MAXMD];
|
||||
static MPB pmd;
|
||||
|
||||
static void *xmgetblk(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAXMD; i++)
|
||||
{
|
||||
if (tab_md[i].m_own == NULL)
|
||||
{
|
||||
tab_md[i].m_own = (void*)1L;
|
||||
return(&tab_md[i]);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void xmfreblk(void *m)
|
||||
{
|
||||
int i = (int)(((long) m - (long) tab_md) / sizeof(MD));
|
||||
if ((i > 0) && (i < MAXMD))
|
||||
{
|
||||
tab_md[i].m_own = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static MD *ffit(long amount, MPB *mp)
|
||||
{
|
||||
MD *p, *q, *p1; /* free list is composed of MD's */
|
||||
int maxflg;
|
||||
long maxval;
|
||||
|
||||
if (amount != -1)
|
||||
{
|
||||
amount += 15; /* 16 bytes alignment */
|
||||
amount &= 0xFFFFFFF0;
|
||||
}
|
||||
|
||||
if ((q = mp->mp_rover) == 0) /* get rotating pointer */
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
maxval = 0;
|
||||
maxflg = ((amount == -1) ? TRUE : FALSE) ;
|
||||
p = q->m_link; /* start with next MD */
|
||||
do /* search the list for an MD with enough space */
|
||||
{
|
||||
if (p == 0)
|
||||
{
|
||||
/* at end of list, wrap back to start */
|
||||
q = (MD *) &mp->mp_mfl; /* q => mfl field */
|
||||
p = q->m_link; /* p => 1st MD */
|
||||
}
|
||||
if ((!maxflg) && (p->m_length >= amount))
|
||||
{
|
||||
/* big enough */
|
||||
if (p->m_length == amount)
|
||||
{
|
||||
q->m_link = p->m_link; /* take the whole thing */
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
* break it up - 1st allocate a new
|
||||
* MD to describe the remainder
|
||||
*/
|
||||
p1 = xmgetblk();
|
||||
if (p1 == NULL)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* init new MD */
|
||||
p1->m_length = p->m_length - amount;
|
||||
p1->m_start = p->m_start + amount;
|
||||
p1->m_link = p->m_link;
|
||||
p->m_length = amount; /* adjust allocated block */
|
||||
q->m_link = p1;
|
||||
}
|
||||
/* link allocate block into allocated list,
|
||||
mark owner of block, & adjust rover */
|
||||
p->m_link = mp->mp_mal;
|
||||
mp->mp_mal = p;
|
||||
mp->mp_rover = (q == (MD *) &mp->mp_mfl ? q->m_link : q);
|
||||
return(p); /* got some */
|
||||
}
|
||||
else if (p->m_length > maxval)
|
||||
maxval = p->m_length;
|
||||
p = ( q=p )->m_link;
|
||||
} while(q != mp->mp_rover);
|
||||
|
||||
/*
|
||||
* return either the max, or 0 (error)
|
||||
*/
|
||||
if (maxflg)
|
||||
{
|
||||
maxval -= 15; /* 16 bytes alignment */
|
||||
if (maxval < 0)
|
||||
{
|
||||
maxval = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxval &= 0xFFFFFFF0;
|
||||
}
|
||||
}
|
||||
return(maxflg ? (MD *) maxval : 0);
|
||||
}
|
||||
|
||||
static void freeit(MD *m, MPB *mp)
|
||||
{
|
||||
MD *p, *q;
|
||||
|
||||
q = 0;
|
||||
for (p = mp->mp_mfl; p ; p = (q = p) -> m_link)
|
||||
{
|
||||
if (m->m_start <= p->m_start)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
m->m_link = p;
|
||||
|
||||
if (q)
|
||||
{
|
||||
q->m_link = m;
|
||||
}
|
||||
else
|
||||
{
|
||||
mp->mp_mfl = m;
|
||||
}
|
||||
|
||||
if (!mp->mp_rover)
|
||||
{
|
||||
mp->mp_rover = m;
|
||||
}
|
||||
|
||||
if (p)
|
||||
{
|
||||
if (m->m_start + m->m_length == p->m_start)
|
||||
{
|
||||
/* join to higher neighbor */
|
||||
m->m_length += p->m_length;
|
||||
m->m_link = p->m_link;
|
||||
if (p == mp->mp_rover)
|
||||
{
|
||||
mp->mp_rover = m;
|
||||
}
|
||||
xmfreblk(p);
|
||||
}
|
||||
}
|
||||
if (q)
|
||||
{
|
||||
if (q->m_start + q->m_length == m->m_start)
|
||||
{
|
||||
/* join to lower neighbor */
|
||||
q->m_length += m->m_length;
|
||||
q->m_link = m->m_link;
|
||||
if (m == mp->mp_rover)
|
||||
{
|
||||
mp->mp_rover = q;
|
||||
}
|
||||
xmfreblk(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int driver_mem_free(void *addr)
|
||||
{
|
||||
int level;
|
||||
MD *p, **q;
|
||||
MPB *mpb;
|
||||
mpb = &pmd;
|
||||
level = set_ipl(7);
|
||||
|
||||
for(p = *(q = &mpb->mp_mal); p; p = *(q = &p->m_link))
|
||||
{
|
||||
if ((long) addr == p->m_start)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!p)
|
||||
{
|
||||
set_ipl(level);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
*q = p->m_link;
|
||||
freeit(p, mpb);
|
||||
set_ipl(level);
|
||||
|
||||
dbg("driver_mem_free(0x%08X)\r\n", addr);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void *driver_mem_alloc(long amount)
|
||||
{
|
||||
void *ret = NULL;
|
||||
int level;
|
||||
MD *m;
|
||||
|
||||
if (amount == -1L)
|
||||
{
|
||||
return((void *)ffit(-1L, &pmd));
|
||||
}
|
||||
|
||||
if (amount <= 0 )
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
if ((amount & 1))
|
||||
{
|
||||
amount++;
|
||||
}
|
||||
|
||||
level = set_ipl(7);
|
||||
m = ffit(amount, &pmd);
|
||||
|
||||
if (m != NULL)
|
||||
{
|
||||
ret = (void *)m->m_start;
|
||||
}
|
||||
set_ipl(level);
|
||||
dbg("driver_mem_alloc(%d) = 0x%08X\r\n", amount, ret);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int usb_mem_init(void)
|
||||
{
|
||||
#ifdef USE_RADEON_MEMORY
|
||||
driver_mem_buffer = (void *) offscren_reserved();
|
||||
if (driver_mem_buffer == NULL)
|
||||
#endif
|
||||
memset(driver_mem_buffer, 0, DRIVER_MEM_BUFFER_SIZE);
|
||||
|
||||
if (driver_mem_buffer == NULL)
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
|
||||
pmd.mp_mfl = pmd.mp_rover = &tab_md[0];
|
||||
tab_md[0].m_link = (MD *) NULL;
|
||||
tab_md[0].m_start = ((long) driver_mem_buffer + 15) & ~15;
|
||||
tab_md[0].m_length = DRIVER_MEM_BUFFER_SIZE;
|
||||
tab_md[0].m_own = (void *) 1L;
|
||||
pmd.mp_mal = (MD *) NULL;
|
||||
memset(driver_mem_buffer, 0, tab_md[0].m_length);
|
||||
dbg("driver memory buffer at 0x%08X size %d\r\n", tab_md[0].m_start, tab_md[0].m_length);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
void usb_mem_stop(void)
|
||||
{
|
||||
#ifndef CONFIG_USB_MEM_NO_CACHE
|
||||
#ifdef USE_RADEON_MEMORY
|
||||
if (driver_mem_buffer == (void *) offscren_reserved())
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +55,19 @@ void *memset(void *s, int c, size_t n)
|
||||
}
|
||||
|
||||
|
||||
int memcmp(const char *s1, const char *s2, size_t max)
|
||||
{
|
||||
int i;
|
||||
int cmp;
|
||||
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
cmp = (*s1 - *s2);
|
||||
if (cmp != 0) return cmp;
|
||||
}
|
||||
return cmp;
|
||||
}
|
||||
|
||||
int strncmp(const char *s1, const char *s2, size_t max)
|
||||
{
|
||||
int i;
|
||||
|
||||
Reference in New Issue
Block a user