在U-Boot根目录下建立uip文件夹,将uip0.9中的这些文件复制进去。
uip
├── Makefile
├── uip_arch.c
├── uip_arch.h
├── uip_arp.c
├── uip_arp.h
├── uip.c
├── uipdemo.c
├── uipdemo.h
├── uip.h
└── uipopt.h
红色标注部分为新建文件:
新建uipdemo.h,内容为:
//The configuration for the application:新建uipdemo.c,内容为:
#define UIP_APPCALL example2_app
#define UIP_APPSTATE_SIZE sizeof(struct example2_state)
struct example2_state {
enum {WELCOME_SENT, WELCOME_ACKED} state;
};
void example2_init(void);
void example2_app(void);
#include "uip.h"void example2_init(void) {uip_listen(HTONS(2345));}void example2_app(void) {struct example2_state *s;s = (struct example2_state *)uip_conn->appstate;if(uip_connected()) {s->state = WELCOME_SENT;uip_send("Welcome!\n", 9);return;}if(uip_acked() && s->state == WELCOME_SENT) {s->state = WELCOME_ACKED;}if(uip_newdata()) {uip_send("ok\n", 3);}if(uip_rexmit()) {switch(s->state) {case WELCOME_SENT:uip_send("Welcome!\n", 9);break;case WELCOME_ACKED:uip_send("ok\n", 3);break;}}}其中uipopt.h为uip的参数配置文件,这里需要修改一项配置:
int uipdemo_is_running = 0;在文件尾部添加函数实体:
int arptimer = 0;
void NetSendDemo(void);
void NetReceiveDemo(volatile uchar * inpkt, int len);
void DemoHandler(void);
int NetLoopDemo(void);
/********************************************************************************** * * UIPDEMO section */#define BUF((struct uip_eth_hdr *)&uip_buf[0])void NetSendDemo( void ){volatile uchar *tmpbuf = NetTxPacket;int i;for ( i = 0; i <40 + UIP_LLH_LEN; i++ ) {tmpbuf[i] = uip_buf[i];}for( ; i到这里net/net.c文件保存,修改完成。type == htons( UIP_ETHTYPE_IP ) ) {uip_arp_ipin();uip_input();if ( uip_len > 0 ) {uip_arp_out();NetSendDemo();}} else if( BUF->type == htons( UIP_ETHTYPE_ARP ) ) {uip_arp_arpin();if ( uip_len > 0 ) {NetSendDemo();}}}void DemoHandler(void) { // int i; for (i = 0; i 0) { uip_arp_out(); NetSendDemo(); } } // TODO: check this if (++arptimer == 20) { uip_arp_timer(); arptimer = 0; }}/* ************************************* * * UIPDEMO for UIP TEST * ***************************************/int NetLoopDemo(void){DECLARE_GLOBAL_DATA_PTR;bd_t *bd = gd->bd;unsigned short int ip[2];unsigned char ethinit_attempt = 0;struct uip_eth_addr eaddr;#ifdef CONFIG_NET_MULTINetRestarted = 0;NetDevExists = 0;#endif/* XXX problem with bss workaround */NetArpWaitPacketMAC= NULL;NetArpWaitTxPacket= NULL;NetArpWaitPacketIP= 0;NetArpWaitReplyIP= 0;NetArpWaitTxPacket= NULL;#ifdef DEBUG printf("File: %s, Func: %s, Line: %d\n", __FILE__,__FUNCTION__ , __LINE__);#endif // if ( !NetTxPacket ) {inti;BUFFER_ELEM *buf;/* *Setup packet buffers, aligned correctly. */buf = rt2880_free_buf_entry_dequeue( &rt2880_free_buf_list ); NetTxPacket = buf->pbuf;debug( "\n NetTxPacket = 0x%08X \n", NetTxPacket );for ( i = 0; i pbuf;printf( "\n NetRxPackets[%d] = 0x%08X\n",i,NetRxPackets[i] );}}NetTxPacket = KSEG1ADDR( NetTxPacket );printf("\n KSEG1ADDR(NetTxPacket) = 0x%08X \n",NetTxPacket);if ( !NetArpWaitTxPacket ) {NetArpWaitTxPacket = &NetArpWaitPacketBuf[0] + ( PKTALIGN - 1 );NetArpWaitTxPacket -= ( ulong )NetArpWaitTxPacket % PKTALIGN;NetArpWaitTxPacketSize = 0;}printf("\n NetLoopHttpd,call eth_halt ! \n");eth_halt();#ifdef CONFIG_NET_MULTIeth_set_current();#endifwhile( ethinit_attempt <10 ) {if ( eth_init( bd ) ) {ethinit_attempt = 0;break;} else {ethinit_attempt++;eth_halt();udelay( 1000000 );}}if ( ethinit_attempt > 0 ) {eth_halt();printf( "## Error: couldn't initialize eth (cable disconnected?)!\n\n" );return( -1 );}// get MAC address#ifdef CONFIG_NET_MULTImemcpy( NetOurEther, eth_get_dev()->enetaddr, 6 );#elsememcpy( NetOurEther, bd->bi_enetaddr, 6 );#endifeaddr.addr[0] = NetOurEther[0];eaddr.addr[1] = NetOurEther[1];eaddr.addr[2] = NetOurEther[2];eaddr.addr[3] = NetOurEther[3];eaddr.addr[4] = NetOurEther[4];eaddr.addr[5] = NetOurEther[5];// set MAC addressuip_setethaddr( eaddr );// set ip and other addresses// TODO: do we need this with uIP stack?NetCopyIP( &NetOurIP, &bd->bi_ip_addr );NetOurGatewayIP= getenv_IPaddr( "gatewayip" );NetOurSubnetMask= getenv_IPaddr( "netmask" );#ifdef CONFIG_NET_VLANNetOurVLAN= getenv_VLAN( "vlan" );NetOurNativeVLAN= getenv_VLAN( "nvlan" );#endif// start server...IPaddr_t tmp_ip_addr = ntohl( bd->bi_ip_addr );printf( "server is starting at IP: %ld.%ld.%ld.%ld\n", ( tmp_ip_addr & 0xff000000 ) >> 24, ( tmp_ip_addr & 0x00ff0000 ) >> 16, ( tmp_ip_addr & 0x0000ff00 ) >> 8, ( tmp_ip_addr & 0x000000ff ) ); //uip inituip_init();// set local host ip addressip[0] = htons( ( tmp_ip_addr & 0xFFFF0000 ) >> 16 );ip[1] = htons( tmp_ip_addr & 0x0000FFFF );uip_sethostaddr( ip );// set network mask (255.255.255.0 -> local network)ip[0] = htons( ( ( 0xFFFFFF00 & 0xFFFF0000 ) >> 16 ) );ip[1] = htons( ( 0xFFFFFF00 & 0x0000FFFF ) );uip_setnetmask( ip );// should we also set default router ip address?//uip_setdraddr(); //demo initexample2_init(); //set uipdeom_is_running uipdemo_is_running = 1;// infinite loopfor ( ; ; ) {/* *Check the ethernet for a new packet. *The ethernet receive routine will process it. */if ( eth_rx() > 0 ) {DemoHandler();}}return 0;}修改NetReceive函数,在局部变量定义结束后添加: if ( uipdemo_is_running ) { NetReceiveDemo( inpkt, len ); return; }
case '5':
printf("System Enter UIPDEMO.\n");
eth_initialize(gd->bd);
NetLoopDemo();
break;
接下来修改两个Makefile文件:
根目录下的Makefile: LIBS变量增加 uip/uip.a#修改完成,保存退出。
# Makefile for uIP demo
#
include $(TOPDIR)/config.mk
LIB = uip.a
OBJS += uip.o uip_arch.o uip_arp.o uipdemo.o
all: $(LIB)
$(LIB): $(START) $(OBJS)
$(AR) crv $@ $(OBJS)
#########################################################################
.depend: Makefile $(OBJS:.o=.c)
$(CC) -M $(CFLAGS) $(OBJS:.o=.c) > $@
sinclude .depend
#########################################################################
Set info->start[0]=BF000000然后ping 192.168.1.2
flash_protect ON: from 0xBF030000 to 0xBF030FFF
============================================
Ralink UBoot Version: 3.6.0.0
--------------------------------------------
ASIC 3052_MP2 (Port5<->None)
DRAM component: 128 Mbits SDR
DRAM bus: 32 bit
Total memory: 32 MBytes
Flash component: NOR Flash
Date:Oct 3 2016 Time:19:36:10
============================================
icache: sets:256, ways:4, linesz:32 ,total:32768
dcache: sets:128, ways:4, linesz:32 ,total:16384
##### The CPU freq = 384 MHZ ####
estimate memory size =16 Mbytes
Please choose the operation:
1: Load system code to SDRAM via TFTP.
2: Load system code then write to Flash via TFTP.
3: Boot system code via Flash (default).
4: Entr boot command line interface.
5: Entr UIP_DEMO.
7: Load Boot Loader code then write to Flash via Serial.
9: Load Boot Loader code then write to Flash via TFTP.
You choosed 5
0
System Enter UIPDEMO.
NetTxPacket = 0x80FE5780
NetRxPackets[0] = 0x80FE5D80
NetRxPackets[1] = 0x80FE6380
NetRxPackets[2] = 0x80FE6980
NetRxPackets[3] = 0x80FE6F80
NetRxPackets[4] = 0x80FE7580
NetRxPackets[5] = 0x80FE7B80
NetRxPackets[6] = 0x80FE8180
NetRxPackets[7] = 0x80FE8780
NetRxPackets[8] = 0x80FE8D80
NetRxPackets[9] = 0x80FE9380
NetRxPackets[10] = 0x80FE9980
NetRxPackets[11] = 0x80FE9F80
NetRxPackets[12] = 0x80FEA580
NetRxPackets[13] = 0x80FEAB80
NetRxPackets[14] = 0x80FEB180
NetRxPackets[15] = 0x80FEB780
NetRxPackets[16] = 0x80FEBD80
NetRxPackets[17] = 0x80FEC380
NetRxPackets[18] = 0x80FEC980
NetRxPackets[19] = 0x80FECF80
NetRxPackets[20] = 0x80FED580
NetRxPackets[21] = 0x80FEDB80
NetRxPackets[22] = 0x80FEE180
NetRxPackets[23] = 0x80FEE780
KSEG1ADDR(NetTxPacket) = 0xA0FE5780
NetLoopHttpd,call eth_halt !
Trying Eth0 (10/100-M)
Waitting for RX_DMA_BUSY status Start... done
Header Payload scatter function is Disable !!
ETH_STATE_ACTIVE!!
server is starting at IP: 192.168.1.2
OK,到这里uIP在U-Boot上面的移植已经完成,基本验证了uIP在U-Boot上运行的可行性,下一步就是在这个基础上继续添加httpd功能,实现web failsafe功能,也就是打造传说中的"不死U-Boot"。
----------------------------------
SDK下载地址: https://github.com/aggresss/RFDemo