common/cmd_cache.c
net/net.c
net/tftp.c
int do_usend(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
//usend d43d7e45371c 192.168.1.134 1234 1234 hhaa
char eth[6]={0xd4 ,0x3d ,0x7e ,0x45 ,0x37, 0x1c};
int dport,sport;
int len;
_getmac(argv[1],eth);
dport = _atoi(argv[3]);
sport = _atoi(argv[4]);
len = _strlen(argv[5]);
printf("mac %x %x %x %x %x %x\n",eth[0],eth[1],eth[2],eth[3],eth[4],eth[5]);
printf("dst %s\n",argv[2]);
printf("dport %d sport %d\n",dport,sport);
printf("string %s\n",argv[5]);
printf("len=%d\n",len);
udp_send( eth,argv[2] ,dport,sport,argv[5],len);
printf("do_udptest\n");
return 0;
}
U_BOOT_CMD (usend, 6, 1, do_usend,
"loadable FPGA image support",
"[operation type] [device number] [image address] [image size]\n"
);
char _ctoi(char c)
{
if(c>='0'&&c<='9')return c-'0';
if(c>='a'&&c<='f')return c-'a'+10;
return 0;
}
int _atoi(char* s)
{
unsigned int a=0;
unsigned int b=0;
int i=0;
while(s[i]){
a*=10;
a+=_ctoi(s[i]);
i++;
}
return a;
}
int _atox(char* s)
{
unsigned int a=0;
unsigned int b=0;
int i=0;
while(s[i]){
a<<=4;
a|=_ctoi(s[i]);
i++;
if(i>=8)break;
}
return a;
}
int _strlen(char*s)
{
int i=0;
while(s[i]){
i++;
}
return i;
}
void _getmac(char* s,char* eth)
{
unsigned char a=0;
int i=0;
while(s[i]){
a<<=4;
a|=_ctoi(s[i]);
if((i&1)==1){
eth[i>>1]=a;
a=0;
}
i++;
}
}
common/cmd_net.c
int udp_send (const char* remorteth,const char* remoteip,int remoteport,int thisport,const char* data,int datalength)
{
if (NetLoop_udpsend(remorteth,remoteip, remoteport, thisport, data, datalength)< 0) {
show_boot_progress (-81);
return 1;
}
/* flush cache */
//flush_cache(load_addr, size);
return 0;
}
net/net.c
int
NetLoop_udpsend(const char* remoteeth,const char* remoteip,int remoteport,int thisport,const char* data,int datalength)
{
bd_t *bd = gd->bd;
/* XXX problem with bss workaround */
NetTxPacket = NULL;
NetTryCount = 1;
if (!NetTxPacket) {
int i;
/*
* Setup packet buffers, aligned correctly.
*/
NetTxPacket = &PktBuf[0] + (PKTALIGN - 1);
NetTxPacket -= (ulong)NetTxPacket % PKTALIGN;
for (i = 0; i < PKTBUFSRX; i++)
NetRxPackets[i] = NetTxPacket + (i+1)*PKTSIZE_ALIGN;
}
printf("NetLoop_udpsend 1");
eth_halt();
if (eth_init(bd) < 0) {
eth_halt();
return -1;
}
restart:
eth_getenv_enetaddr("ethaddr", NetOurEther);
/*
* Start the ball rolling with the given start function. From
* here on, this code is a state machine driven by received
* packets and timer events.
*/
NetInitLoop(TFTP);
printf("NetLoop_udpsend 2");
switch (net_check_prereq(TFTP)) {
case 1:
/* network not configured */
eth_halt();
return -1;
case 0:
udpSend(remoteeth,remoteip, remoteport, thisport, data, datalength);
eth_halt();
break;
}
printf("netloop ok\n");
return 0;
}
net/tftp.c
void
udpSend(const char* remoteeth,const char*remoteip, int remoteport,int thisport, const char* data,int datalength)
{
volatile uchar *pkt;
volatile uchar *xp;
int len = 0;
volatile ushort *s;
IPaddr_t RemoteIP;
RemoteIP = string_to_ip(remoteip);
/*
* We will always be sending some sort of packet, so
* cobble together the packet headers now.
*/
pkt = NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE;
memcpy(pkt,data,datalength);
printf("udpSend 1");
NetSendUDPPacket(remoteeth, RemoteIP, remoteport,thisport, datalength);
}