[U-Boot-Users] Standalone network calls

Ben,
During the work to bring FreeBSD support in U-Boot we came accross a need for standalone network operations to send and receive an ethernet frame. In short, the approach is to have a native FreeBSD loader running on top of U-Boot as a standalone app. U-Boot's networking however, is pretty self-contained and, in particular, does not have a 'receive' primitive that would directly suit such purposes.
Please have a look at the attached patch and let me hear your comments about this direction in general and regarding these changes in particular. The included code actually works - we have a prototype FreeBSD loader running successfully on U-Boot extended in this fashion:
* eth_send() and eth_receive() are exported via the jump table and consumed by the FreeBSD loader
* the loader implements all TCP/IP and related protocols that it requires, so would be using U-Boot networking calls only as elementary send/receive
Beside the newly introduced eth_receive() one needs to export eth_{send,init,halt} too, and some other calls, but they can just be used without changes.
Any comments or suggestions welcome.
kind regards, Rafal
diff --git a/net/eth.c b/net/eth.c index cca9392..ca98dd7 100644 --- a/net/eth.c +++ b/net/eth.c @@ -55,8 +55,15 @@ extern int skge_initialize(bd_t*); extern int tsec_initialize(bd_t*, int, char *); extern int npe_initialize(bd_t *); extern int uec_initialize(int); +extern void (*push_packet)(volatile void *, int); + +static struct { + uchar data[PKTSIZE]; + int length; +} eth_rcv_bufs[PKTBUFSRX];
static struct eth_device *eth_devices, *eth_current; +static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
struct eth_device *eth_get_dev(void) { @@ -408,6 +415,51 @@ int eth_rx(void) return eth_current->recv(eth_current); }
+static void eth_save_packet(volatile void *packet, int length) +{ + volatile char *p = packet; + int i; + + if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current) + return; + + if (PKTSIZE < length) + return; + + for (i = 0; i < length; i++) + eth_rcv_bufs[eth_rcv_last].data[i] = p[i]; + + eth_rcv_bufs[eth_rcv_last].length = length; + eth_rcv_last = (eth_rcv_last+1) % PKTBUFSRX; +} + +int eth_receive(volatile void *packet, int length) +{ + volatile char *p = packet; + void *pp = push_packet; + int i; + + if (eth_rcv_current == eth_rcv_last) { + push_packet = eth_save_packet; + eth_rx(); + push_packet = pp; + + if (eth_rcv_current == eth_rcv_last) + return -1; + } + + if (length < eth_rcv_bufs[eth_rcv_current].length) + return -1; + + length = eth_rcv_bufs[eth_rcv_current].length; + + for (i = 0; i < length; i++) + p[i] = eth_rcv_bufs[eth_rcv_current].data[i]; + + eth_rcv_current = (eth_rcv_current+1) % PKTBUFSRX; + return length; +} + void eth_try_another(int first_restart) { static struct eth_device *first_failed = NULL; diff --git a/net/net.c b/net/net.c index 1d1c98f..a9ee6a4 100644 --- a/net/net.c +++ b/net/net.c @@ -133,6 +133,7 @@ uchar NetBcastAddr[6] = /* Ethernet bca { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; uchar NetEtherNullAddr[6] = { 0, 0, 0, 0, 0, 0 }; +void (*push_packet)(volatile void *, int len) = 0; #if (CONFIG_COMMANDS & CFG_CMD_CDP) uchar NetCDPAddr[6] = /* Ethernet bcast address */ { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc }; @@ -1157,6 +1158,11 @@ NetReceive(volatile uchar * inpkt, int l if (len < ETHER_HDR_SIZE) return;
+ if (push_packet) { + (*push_packet)(inpkt, len); + return; + } + #if (CONFIG_COMMANDS & CFG_CMD_CDP) /* keep track if packet is CDP */ iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;

In message 45F98A77.1070505@semihalf.com you wrote:
During the work to bring FreeBSD support in U-Boot we came accross a need for standalone network operations to send and receive an ethernet frame. In short, the approach is to have a native FreeBSD loader running on top of U-Boot as a standalone app. U-Boot's networking however, is pretty self-contained and, in particular, does not have a 'receive' primitive that would directly suit such purposes.
Acked-by: Wolfgang Denk wd@denx.de
Best regards,
Wolfgang Denk

Rafal,
On Thu, 2007-03-15 at 19:03 +0100, Rafal Jaworowski wrote:
Ben,
<snip>
Any comments or suggestions welcome.
This looks pretty cool. Please do me a favor and re-send with proper sign-off. After you do so, I'll put it in the u-boot-net branch.
The command to use is 'git format-patch'
regards, Ben
participants (3)
-
Ben Warren
-
Rafal Jaworowski
-
Wolfgang Denk