日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UIP协议栈移植到u-boot详解

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UIP协议栈移植到u-boot详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


???????? Author: 楊正? date2014.11.5? Emaily2012ww@gmail.com?QQ: 1209758756

1、uip簡介

?????? Uip網絡是一個簡單好用的嵌入式協議棧,易于移植且消耗的內存空間較少,應用于很多嵌入式產品。uIP 協議棧去掉了完整的TCP/IP系統中不常用的功能,簡化了通訊流程,只保留了網絡通信必須使用的協議,設計重點放在了IP/TCP/ICMP/UDP/ARP這些網絡層和傳輸層的協議上,因此保證了其代碼的通用性和結構的穩定性。由于uIP協議棧專門為嵌入式系統而設計,因此還具有以下優越功能:

(1)代碼非常少,其協議棧代碼不到6K,方便閱讀與移植。

(2)占用的內存數極少,RAM占用僅幾百字節。

(3)它的硬件處理層、協議棧層和應用層共用一個全局緩存區,不存在數據拷貝,而且發送和接收都是依靠這個緩存區,極大的節省了空間和時間。

(4)支持多個主動連接和被動連接并發。

(5)它的源代碼中提供一套實例程序:web 客戶端,web 服務器,Telnet 服務器,電子郵件發送程序(SMTP 客戶端),DNS 主機名解析程序等。

(6)在數據的處理上采用輪循機制,不需要操作系統的支持。由于 uIP 對資源的需求少而且移植容易,大部分的8位微控制器都使用過uIP協議棧, 而且很多著名的嵌入式產品和項目(如衛星,Cisco 路由器,無線傳感器網絡)中均在使用uIP 協議棧。

下面就開始進入移植過程。

2、uip移植

2.1 uip架構

在移植uip之前先簡單看一下uip的大致框架,uIP相當于一個代碼庫,通過一系列的函數實現與底層硬件和高層應用程序之間的通訊,對于整個系統來說它內部的協議組是透明的,從而增加了協議的通用性。uIP協議棧與系統底層和高層應用之間的關系如下:




uIP 協議棧主要提供了三個函數供系統底層調用。即uip_init(), uip_input()和uip_periodic()。其與應用程序的主要接口是UIP_APPCALL( )。

uip_init()是系統初始化時調用的,主要用于初始化協議棧的偵聽端口和默認所有連接是關閉的。當網卡驅動收到一個輸入包時,將其放入全局緩沖區 uip_buf 中,包的大小由全局變量uip_len 約束。同時將調用uip_input()函數,這個函數將會根據包首部的協議處理這個包并在需要時調用應用程序。當uip_input()返回時,一個輸出包同樣放在全局緩沖區uip_buf 里,并把大小賦給uip_len。若uip_len 是0,則說明沒有包要發送;否則調用底層系統的發包函數就會將包發送到網絡上。uIP周期計時用于驅動所有的uIP內部時鐘事件:當周期計時激發,每一個TCP連接都會調用uIP函數uip_periodic()。類似于uip_input()函數,uip_periodic()函數返回時,輸出的IP 包要放到uip_buf 中,供底層系統查詢uip_len 的大小并發送。由于TCP/IP 的應用場景很多,所以應用程序作為單獨的模塊由用戶實現。uIP 協議棧提供一系列接口函數供用戶程序調用,其中大部分函數是作為C的宏命令實現的,主要是為了速度、代碼大小、堆棧和效率的使用。用戶需要將應用層入口程序作為接口提供給uIP協議棧,并將這個函數定義為UIP_APPCALL()。這樣以來,uIP在接受到底層傳來的數據包后,在需要送到上層應用程序處理的地方,調用UIP_APPCALL(),在不用修改協議棧的情況下可以適配不同的應用程序。

?

2.2 UIP移植過程

2.2.1 拷貝UIP-0.9到u-boot-2010.06/net目錄

以u-boot_sources_for_tp-link_AR9331_by_pepe2k為藍本進行移植,將該藍本里面的uip-0.9這個目錄復制到我的u-boot 的u-boot-2010.06/net目錄下,這個uip-0.9里面有這個一些文件:

ap121.h? ctype.h?fsdata.c?? tapdev.c??? uip_arch.h?uip_arp.h?uip.h

ar7240.h??????? flash.h?fsdata.h? httpd.c? main.c???tapdev.h??? cmd_confdefs.h? fs.c????fs.h?????httpd.h? Makefile? uip_arch.c?uip_arp.c??uip.c?????uipopt.h

當然不是所有的文件都用到。拷貝過來以后要修改makefile不然編譯會通不過的,我的makefile修改如下:

CC=g++

CFLAGS=-Wall -O2-fpack-struct -DDUMP=0

?

CFLAGS += -I../../include

?

all: uip

?

uip: uip.o uip_arch.otapdev.o httpd.o main.o fs.o uip_arp.o

#uip: uip.o uip_arch.otapdev.o main.o fs.o uip_arp.o

??? $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

?

%.o: %.c

??? $(CC) $(CFLAGS) -c? $^ -o $@

?

clean:

rm-f *.o *~ *core uip


接下來就進入u-boot-2010.06/net目錄下的net.c文件,其實整個移植過程都是在這個文件里面打轉。

?

2.2.2 在u-boot-2010.06/net/net.c里面添加函數

net.c里面添加NetReceiveHttpd()函數:

void NetReceiveHttpd(volatileuchar * inpkt, int len) {

??? memcpy(uip_buf, (const void *) inpkt, len);

??? uip_len = len;

?

#ifdef ET_DEBUG???? //debug?by yangzheng

??? DBG("NetReceiveHttpd buf->type =%04X\n", ntohs(BUF->type));

#endif

??? if (BUF->type == htons(UIP_ETHTYPE_IP)){

#ifdef ET_DEBUG???? //debug?by yangzheng

??? DBG("buf type isUIP_ETHTYPE_IP\n");

#endif

??????? uip_arp_ipin();?? //處理傳入的ip

??????? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__ );

??????? DBG("uip_len2=%d\n",uip_len);

??????? uip_input();? //從上往下封裝包的函數,這個函數會調用UIP_APPCALL()

??????? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__ );

??????? DBG("uip_len2=%d\n",uip_len);

??????? if (uip_len > 0) {

??????????? DBG("ipin->uip bufferinside data\n");

??????????? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__ );

??????????? uip_arp_out();?? //arp請求發送函數

??????????? NetSendHttpd();?? //調用網卡驅動的發送函數

??????? }

??? } else if (BUF->type ==htons(UIP_ETHTYPE_ARP)) {

#ifdef ET_DEBUG???? //debug?by yangzheng

??? DBG("buf type isUIP_ETHTYPE_ARP\n");

#endif

uip_arp_arpin();? ?//處理arp應答

??????? DBG("uip_len3=%d\n",uip_len);

??????? if (uip_len > 0) {

??????????? DBG("arpin->uip bufferinside data\n");

??????????? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__ );

??????????? NetSendHttpd();

??????? }

??? }

}

在net.c的NetReceive()函數里面還要添加如下代碼,調用NetReceiveHttpd()函數:

?

if(webfailsafe_is_running)

{

NetReceiveHttpd(inpkt,len);? //這個函數上面已經說明

return;

}

?

?

?

?

?

這里有一個函數需要說明一下,因為我在這里徘徊了很久。ARP請求發送函數:

void uip_arp_out(void)(在uip-0.9目錄的uip_arp.c里面定義)。

*==================================================================
*
為傳出的IP包添加以太網頭并看是否需要發送ARP請求.?
*
此函數應該在發送IP包時調用,它會檢查IP包的目的IP地址,看看以太網應該使用什么目的MAC地址.
*
如果目的IP地址是在局域網中(IP地址與子網掩碼的與邏輯決定),函數就會從ARP緩存表中查找有
*
無對應項.若有,就取對應的MAC地址,加上以太網頭,并返回,否則uip_buf[]中的數據包會被替換成一個
*
目的IP在址的ARP請求.原來的IP包會被簡單的仍掉,此函數假設高層協議(TCP)會最終重傳扔掉的包.
*
如果目標IP地址并非一個局域網IP,則會使用默認路由的IP地址.
* uip_len.
函數返回時,uip_buf[]中已經有了一個包,其長度由uip_len指定.

*===================================================================

void?uip_arp_out(void)

{

??? ?struct arp_entry?*tabptr=0;

?

ipaddr[0] =IPBUF->destipaddr[0];

??? ipaddr[1] = IPBUF->destipaddr[1];

???DBG("****************ipaddr[0]=%x******************ipaddr[1]=%x\n",ipaddr[0], ???ipaddr[1]);

??? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__ );

?????

? for(i = 0; i < UIP_ARPTAB_SIZE; ++i) {

??? tabptr = &arp_table[i];

??? if(ipaddr[0] == tabptr->ipaddr[0]&&

?????? ipaddr[1] == tabptr->ipaddr[1])

????? break;

? }

?

?????????if(i?==?UIP_ARPTAB_SIZE)

?? ? ???{

????? ? ???/*?如果遍歷到頭沒找到,將原IP包替換為ARP請求并返回?*/

?????????????

??? memset(BUF->ethhdr.dest.addr, 0xff, 6);

??? memset(BUF->dhwaddr.addr, 0x00, 6);

??? memcpy(BUF->ethhdr.src.addr,uip_ethaddr.addr, 6);

??? memcpy(BUF->shwaddr.addr,uip_ethaddr.addr, 6);

???

??? BUF->dipaddr[0] = ipaddr[0];

??? BUF->dipaddr[1] = ipaddr[1];

??? BUF->sipaddr[0] = uip_hostaddr[0];

??? BUF->sipaddr[1] = uip_hostaddr[1];

??? BUF->opcode = HTONS(ARP_REQUEST); /* ARPrequest. */

??? BUF->hwtype = HTONS(ARP_HWTYPE_ETH);

??? BUF->protocol = HTONS(UIP_ETHTYPE_IP);

??? BUF->hwlen = 6;

??? BUF->protolen = 4;

??? BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP);

??? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__ );

?

??? uip_appdata = &uip_buf[40 +UIP_LLH_LEN];

???

??? uip_len = sizeof(struct arp_hdr);

??? return;

? }

?

? /* Build an ethernet header. */

? memcpy(IPBUF->ethhdr.dest.addr,tabptr->ethaddr.addr, 6);

? memcpy(IPBUF->ethhdr.src.addr,uip_ethaddr.addr, 6);

?

? IPBUF->ethhdr.type =HTONS(UIP_ETHTYPE_IP);

?

? uip_len += sizeof(struct uip_eth_hdr);

}

?

接下來看arp應答函數:uip_arp_arpin()在uip-0.9目錄的uip_arp.c里面定義。

uip_arp_arpin()函數主要是處理ARP應答。這個函數是在設備接收到ARP包時,由驅動程序調用的.如果收到是ARP包是一個對本地主機上次發送的ARP請求的應答,那么就從包中取得自己想要的主機的MAC地址,加入自己的ARP緩存表中.如果收到是一個ARP請求,那就把自己的MAC地址打包成一個ARP應答,發送給請求的主機。

/*-----------------------------------------------------------------------------------*/

/**

?* ARP processing for incoming ARP packets.

?*

?* This function should be called by the devicedriver when an ARP

?* packet has been received. The function willact differently

?* depending on the ARP packet type: if it is areply for a request

?* that we previously sent out, the ARP cachewill be filled in with

?* the values from the ARP reply. If theincoming ARP packet is an ARP

?* request for our IP address, an ARP replypacket is created and put

?* into the uip_buf[] buffer.

?*

?* When the function returns, the value of theglobal variable uip_len

?* indicates whether the device driver shouldsend out a packet or

?* not. If uip_len is zero, no packet should besent. If uip_len is

?* non-zero, it contains the length of theoutbound packet that is

?* present in the uip_buf[] buffer.

?*

?* This function expects an ARP packet with aprepended Ethernet

?* header in the uip_buf[] buffer, and thelength of the packet in the

?* global variable uip_len.

?*/

/*-----------------------------------------------------------------------------------*/

void

uip_arp_arpin(void)

{

? if(uip_len < sizeof(struct arp_hdr)) {

??? uip_len = 0;

??? return;

? }

?

? uip_len = 0;

?

? int ar = HTONS(ARP_REQUEST);

?

? case HTONS(ARP_REQUEST):? //arp請求:1arp應答:2

??? /* ARP request. If it asked for ouraddress, we send out a

?????? reply. */

??? if(BUF->dipaddr[0] == uip_hostaddr[0]&&

?????? BUF->dipaddr[1] == uip_hostaddr[1]) {

????? /* The reply opcode is 2. */

????? BUF->opcode = HTONS(2); ?//回應的操作碼是2

?????

????? //將收到的arp包的發送端以太網地址變為目的以太網地址

????? memcpy(BUF->dhwaddr.addr,BUF->shwaddr.addr, 6);

????? //將自己的以太網地址賦值給arp包的發送端以太網地址

????? memcpy(BUF->shwaddr.addr,uip_ethaddr.addr, 6);

????? memcpy(BUF->ethhdr.src.addr,uip_ethaddr.addr, 6);

????? memcpy(BUF->ethhdr.dest.addr,BUF->dhwaddr.addr, 6);

?????

????? BUF->dipaddr[0] = BUF->sipaddr[0];

????? BUF->dipaddr[1] = BUF->sipaddr[1];

?

????? BUF->sipaddr[0] = uip_hostaddr[0];

????? BUF->sipaddr[1] = uip_hostaddr[1];

?

?

????? BUF->ethhdr.type =HTONS(UIP_ETHTYPE_ARP);?????

????? uip_len = sizeof(struct arp_hdr);

?????

??? }?????

??? break;

? case HTONS(ARP_REPLY):

??? /* ARP reply. We insert or update the ARPtable if it was meant

?????? for us. */

??? if(BUF->dipaddr[0] == uip_hostaddr[0]&&

?????? BUF->dipaddr[1] == uip_hostaddr[1]) {

?

???? ??uip_arp_update(BUF->sipaddr,&BUF->shwaddr);

??? }

??? break;

? }

?

? return;

}

?

net.c里面還要添加如下函數:

#define BUF???????????? ((struct uip_eth_hdr*)&uip_buf[0])

voidNetSendHttpd(void) {

??? volatile uchar *tmpbuf = NetTxPacket;

??? int i;

?

??? for (i = 0; i < 40 + UIP_LLH_LEN; i++) {

??????? tmpbuf[i] = uip_buf[i];

??????? //printf("uip_buf[%d]=%d\n",i, uip_buf[i]);

??? }

?

??? for (; i < uip_len; i++) {

??????? tmpbuf[i] = uip_appdata[i - 40 -UIP_LLH_LEN];

??? }

??? eth_send(NetTxPacket, uip_len);? //這里就是調用uboot里面網卡?驅動的發送函數

??? //NetSendPacket(NetTxPacket, uip_len);

}

?

voidHttpdHandler(void) {??? //

??? int i;

?

??? for (i = 0; i < UIP_CONNS; i++) {

??????? uip_periodic(i);

?

??????? if (uip_len > 0) {

??????????? uip_arp_out();

??????????? NetSendHttpd();

??????? }

??? }

?

??? // TODO: check this

??? if (++arptimer == 20) {

??????? uip_arp_timer();

??????? arptimer = 0;

??? }

}

?

// start http daemon

void HttpdStart(void){

??? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

??? uip_init();??? ?//下面講到

??? httpd_init();

}

?

?

uip協議結合網卡芯片組成嵌入式網卡,硬件提供能力,uip提供策略。由上往下逐步封裝數據,如:

應用層----------傳輸層------------網絡層---------------數據鏈路層---------物理層

應用數據------>tcp封裝頭------>IP封裝頭-----------MAC封裝+尾部------->發送

?

任何事物都需要一個初始化的過程,uip協議棧也不例外,uip協議通過uip_init()來初始化。uip_init()函數里主要的工作是:

1.? uip_state結構體全部清零。

2.? 初始化用于TCP連接的uip_conn結構體,將連接狀態置為close。

3.? 設置用于TCP連接的端口號lastport=1024。

4.? 如果定義了UDP,同樣也要初始化。

/*-----------------------------------------------------------------------------------*/

void

uip_init(void)

{

? for(c = 0; c < UIP_LISTENPORTS; ++c) {

??? uip_listenports[c] = 0;

? }

? for(c = 0; c < UIP_CONNS; ++c) {

??? uip_conns[c].tcpstateflags = CLOSED;

? }

#if UIP_ACTIVE_OPEN

? lastport = 1024;

#endif /*UIP_ACTIVE_OPEN */

?

#if UIP_UDP

? for(c = 0; c < UIP_UDP_CONNS; ++c) {

??? uip_udp_conns[c].lport = 0;

? }

#endif /* UIP_UDP */

?

? /* IPv4 initialization. */

#if UIP_FIXEDADDR == 0

? uip_hostaddr[0] = uip_hostaddr[1] = 0;

#endif /*UIP_FIXEDADDR */

}

/*-----------------------------------------------------------------------------------*/

?

?

net.c里面還要添加NetLoopHttpd(void)函數,這個函數前半部分可以模仿net.c里面的NetLoop()函數。紅色部分是字節序的轉換,在移植過程當中,字節序轉換也是花了很長時間。

int NetLoopHttpd(void){

?????? bd_t *bd = gd->bd;

?????? unsigned short int ip[2];

?????? unsigned char ethinit_attempt = 0;

?????? struct uip_eth_addr eaddr;

?

#ifdef CONFIG_NET_MULTI

?????? NetRestarted = 0;

?????? NetDevExists = 0;

#endif

?

?????? /* XXX problem with bss workaround */

?????? NetArpWaitPacketMAC = NULL;

?????? NetArpWaitTxPacket = NULL;

?????? NetArpWaitPacketIP = 0;

?????? NetArpWaitReplyIP = 0;

?????? NetArpWaitTxPacket = NULL;

?????? NetTxPacket = NULL;

?

?????? if (!NetTxPacket) {

????????????? int i;

????????????? // Setup packet buffers, alignedcorrectly.

????????????? NetTxPacket = &PktBuf[0] +(PKTALIGN - 1);

????????????? NetTxPacket -= (ulong) NetTxPacket% PKTALIGN;

?

????????????? for (i = 0; i < PKTBUFSRX; i++){

???????????????????? NetRxPackets[i] =NetTxPacket + (i + 1) * PKTSIZE_ALIGN;

????????????? }

?????? }

?

?????? if (!NetArpWaitTxPacket) {

????????????? NetArpWaitTxPacket =&NetArpWaitPacketBuf[0] + (PKTALIGN - 1);

????????????? NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;

????????????? NetArpWaitTxPacketSize = 0;

?????? }

?

?????? // restart label

?????? restart:

?

?????? eth_halt();

?

#ifdef CONFIG_NET_MULTI

?????? eth_set_current();

#endif

?

??? int ret = eth_init(bd);

??? DBG("eth_init = %d\n", ret);

?????? while(ethinit_attempt < 10){

????????????? if(!eth_init(bd)){???? //eth_init->!eth_init???? add by yangzheng

??????????? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

???????????????????? ethinit_attempt = 0;

???????????????????? break;

????????????? } else {

???????????????????? ethinit_attempt++;

???????????????????? eth_halt();

???????????????????? milisecdelay(1000);

????????????? }

?????? }

?

?????? if (ethinit_attempt > 0) {

????????????? eth_halt();

????????????? printf("## Error: couldn'tinitialize eth (cable disconnected?)!\n\n");

????????????? return (-1);

?????? }

?

?????? // get MAC address

#ifdefCONFIG_NET_MULTI

?????? memcpy(NetOurEther,eth_get_dev()->enetaddr, 6);

#else

?????? eth_getenv_enetaddr("ethaddr",NetOurEther);

#endif

?

??? //獲取物理地址

?????? eaddr.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];

??? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

??? DBG("%x:%x:%x:%x:%x:%x\n",eaddr.addr[0], eaddr.addr[1], eaddr.addr[2], eaddr.addr[3], eaddr.addr[4],eaddr.addr[5]);

?

?????? // set MAC address

?????? uip_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");

?????? NetOurVLAN =getenv_VLAN("vlan");

?????? NetOurNativeVLAN =getenv_VLAN("nvlan");

?

?????? // start server...

//???? printf("HTTP server is starting at IP:%ld.%ld.%ld.%ld\n", (bd->bi_ip_addr & 0xff000000) >> 24,(bd->bi_ip_addr & 0x00ff0000) >> 16, (bd->bi_ip_addr &0x0000ff00) >> 8, (bd->bi_ip_addr & 0x000000ff));

//?? printf("HTTP server is starting at IP:%ld.%ld.%ld.%ld\n", (bd->bi_ip_addr & 0x000000ff),(bd->bi_ip_addr & 0x0000ff00) >> 8, (bd->bi_ip_addr & 0x00ff0000)>> 16, (bd->bi_ip_addr & 0xff000000) >> 24);

?

??? IPaddr_t x =ntohl(bd->bi_ip_addr); //add ?yangzheng

??? char tmp[22];

??? ip_to_string(bd->bi_ip_addr,tmp);

??? printf("HTTP server is starting at IP: %s\n",tmp);

?

??? DBG("file=%s, func=%s, line=%d\n",__FILE__, __FUNCTION__, __LINE__);

?????? HttpdStart();? //這里就會初始化uiphttp

??? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

?

?????? // set local host ip address

?????? //ip[1] = ((bd->bi_ip_addr &0xFFFF0000) >> 16);

?????? //ip[0] = (bd->bi_ip_addr &0x0000FFFF);

?????? ip[0] = htons(((x& 0xFFFF0000) >> 16));?? //dbgyangzheng

?????? ip[1] = htons((x & 0x0000FFFF));

?

?????? uip_sethostaddr(ip);

?

?????? // set network mask (255.255.255.0 ->local network)

?????? ip[0] = ((0xFFFFFF00 & 0xFFFF0000)>> 16);

?????? ip[1] = (0xFFFFFF00 & 0x0000FFFF);

?????? //ip[0] = htons(0xFFFF); //dbg yangzheng

?????? //ip[1] = htons(0xFF00);

?

?????? uip_setnetmask(ip);

??? ip[0] = 0xFFFF;? //dbg yangzheng

??? ip[1] = 0xFFFF;

??? uip_setdraddr(ip);

?

?????? // should we also set default router ipaddress?

?????? //uip_setdraddr();

?

?????? // show current progress of the process

?????? do_http_progress(WEBFAILSAFE_PROGRESS_START);

?

?????? webfailsafe_is_running = 1;

?

?????? // infinite loop

?????? for (;;) {

?

????????????? // TODO: ??

????????????? WATCHDOG_RESET();

?

????????????? /*

????????????? ?*??? Checkthe ethernet for a new packet.

????????????? ?*??? Theethernet receive routine will process it.

????????????? ?*/

????????????? if (eth_rx() > 0) {

???????????????????? HttpdHandler();

????????????? }

?

????????????? // if CTRL+C was pressed ->return!

????????????? if (ctrlc()) {

???????????????????? eth_halt();

???????????????????? printf("\nWeb failsafemode aborted!\n\n");

???????????????????? return (-1);

????????????? }

?

????????????? // until upload is not completed,get back to the start of the loop

????????????? if(!webfailsafe_ready_for_upgrade) continue;

?

????????????? // stop eth interface

????????????? eth_halt();

?

????????????? // show progress

?????? ???do_http_progress(WEBFAILSAFE_PROGRESS_UPLOAD_READY);

?

????????????? // try to make upgrade!

// try to makeupgrade!

??????? if ( !do_upgrade());??? //這個函數后面會重點說明

??????? {

??????????? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

???????????do_http_progress(WEBFAILSAFE_PROGRESS_UPGRADE_READY);

??????????? do_reset(NULL, 0, 0, NULL);? //這個函數是在uboot里面的

??????????? return 0;

??????? }

#if 0

????????????? if(do_http_upgrade(NetBootFileXferSize, webfailsafe_upgrade_type) >= 0) {

???????????????????? do_http_progress(WEBFAILSAFE_PROGRESS_UPGRADE_READY);

???????????????????? udelay(1000 * 10);

???????????????????? do_reset(0, 0, 0, 0);

???????????????????? return 0;

????????????? }

#endif

????????????? break;

?????? }

?

?????? webfailsafe_is_running = 0;

?????? webfailsafe_ready_for_upgrade = 0;

?????? webfailsafe_upgrade_type =WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE;

?

?????? NetBootFileXferSize = 0;

??? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

?

?????? do_http_progress(WEBFAILSAFE_PROGRESS_UPGRADE_FAILED);

?

?????? // go to restart

?????? goto restart;

?

?????? return -1;

}

?

?

?

下面就說一下do_upgrade()函數。我移植uip協議棧的目的就是通過這個協議來升級uboot,內核,文件系統。這個函數就是將通過網頁上傳到buffer的數據即bin文件寫到Flash里去,那么具體寫的函數可以參考u-boot-2010.06/common/cmd_sf.c里面的函數。(這里解釋一下,上傳的文件時存放在一個buffer里面,而不是直接寫到Flash里面,所以需要用下面這個函數來寫到Flash)我也是參考uboot里面cmd_sf.c文件,添加了如下代碼:

int do_upgrade (void)

{

???DBG("file=%s, func=%s, line=%d\n", __FILE__, __FUNCTION__,__LINE__);

???printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");

???printf("+zmodo_upgrade - upgrade kenel ,rootfilesystem,andAPP\n");

???printf("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");

??? int argc =3;

??? char*argv[10];

?

??? argv[0] ="sf";

???argv[1]="probe";

??? argv[2]="0";

???do_spi_flash_probe(argc - 1, argv + 1);

?

??? argc = 4;

??? argv[0] ="sf";

??? argv[1] ="erase";

??? argv[2] ="0";

??? //argv[3]= "80000";

??? argv[3] ="1000000"; ??//所燒錄文件的大小,我的是燒錄的是整個燒片文件16M

???do_spi_flash_erase(argc - 1, argv + 1);

?

??? argc = 5;

??? argv[0] ="sf";

??? argv[1] ="write";

??? argv[2] ="82000000";

??? argv[3] ="0";

??? //argv[4]= "80000";

??? argv[4] ="1000000";

???do_spi_flash_read_write(argc - 1, argv + 1);

?

??? return 0;

}???????

?

下面三個函數我完全是從u-boot-2010.06/common/cmd_sf.c文件里面拷貝過來的,僅供參考:

static int do_spi_flash_probe(int argc, char*argv[])

{

?????? unsignedint bus = 0;

?????? unsignedint cs;

?????? unsignedint speed = CONFIG_SF_DEFAULT_SPEED;

?????? unsignedint mode = CONFIG_SF_DEFAULT_MODE;

?????? char*endp;

?????? structspi_flash *new;

?

?????? if (argc< 2)

????????????? gotousage;

?

?????? cs =simple_strtoul(argv[1], &endp, 0);

?????? if(*argv[1] == 0 || (*endp != 0 && *endp != ':'))

????????????? gotousage;

?????? if(*endp == ':') {

????????????? if(endp[1] == 0)

???????????????????? gotousage;

?

????????????? bus= cs;

????????????? cs= simple_strtoul(endp + 1, &endp, 0);

????????????? if(*endp != 0)

???????????????????? gotousage;

?????? }

?

?????? if (argc>= 3) {

????????????? speed= simple_strtoul(argv[2], &endp, 0);

????????????? if(*argv[2] == 0 || *endp != 0)

???????????????????? gotousage;

?????? }

?????? if (argc>= 4) {

????????????? mode= simple_strtoul(argv[3], &endp, 16);

????????????? if(*argv[3] == 0 || *endp != 0)

???????????????????? gotousage;

?????? }

?

?????? new =spi_flash_probe(bus, cs, speed, mode);

?????? if(!new) {

????????????? printf("Failedto initialize SPI flash at %u:%u\n", bus, cs);

????????????? return1;

?????? }

?

?????? if(flash)

????????????? spi_flash_free(flash);

?????? flash =new;

?

?????? printf("%uKiB %s at %u:%u is now current device\n",

???????????????????? flash->size>> 10, flash->name, bus, cs);

?

?????? return0;

?

usage:

?????? puts("Usage:sf probe [bus:]cs [hz] [mode]\n");

?????? return1;

}

?

static int do_spi_flash_read_write(int argc, char*argv[])

{

?????? unsignedlong addr;

?????? unsignedlong offset;

?????? unsignedlong len;

?????? void*buf;

?????? char*endp;

?????? int ret;

?????? structmtd_info_ex *spiflash_info = get_spiflash_info();

?

?????? if (argc< 4)

????????????? gotousage;

?

?????? addr =simple_strtoul(argv[1], &endp, 16);

?????? if(*argv[1] == 0 || *endp != 0)

????????????? gotousage;

?????? offset =simple_strtoul(argv[2], &endp, 16);

?????? if(*argv[2] == 0 || *endp != 0)

????????????? gotousage;

?????? len =simple_strtoul(argv[3], &endp, 16);

?????? if(*argv[3] == 0 || *endp != 0)

????????????? gotousage;

????????????? if(offset + len >

????????????? spiflash_info->chipsize* spiflash_info->numchips) {

???????????????????? printf(

???????????????????? "ERROR:read/write area is out of range!\n\n");

???????????????????????????????????????????????? return-1;

????????????? }

?

?????? buf =map_physmem(addr, len, MAP_WRBACK);

?????? if(!buf) {

????????????? puts("Failedto map physical memory\n");

????????????? return1;

?????? }

?

?????? if(strcmp(argv[0], "read") == 0)

????????????? ret= spi_flash_read(flash, offset, len, buf);

?????? else {

????????????? unsignedlong write_start, write_len, write_step;

????????????? intpercent_complete = -1;

????????????? char*pbuf = buf;

?

????????????? write_start= offset;

????????????? write_len?? = len;

????????????? write_step? = spiflash_info->erasesize;

?

????????????? while(len > 0) {

???????????????????? if(len < write_step)

??????????????????????????? write_step= len;

?

???????????????????? ret= spi_flash_write(flash, offset, write_step, pbuf);

???????????????????? if(ret)

??????????????????????????? break;

?

???????????????????? offset+= write_step;

???????????????????? pbuf?? += write_step;

???????????????????? len??? -= write_step;

?

???????????????????? do{

??????????????????????????? unsignedlong long n = (unsigned long long)

?????????????????????????????????? (offset- write_start) * 100;

??????????????????????????? intpercent;

?

??????????????????????????? do_div(n,write_len);

??????????????????????????? percent= (int)n;

?

??????????????????????????? /*output progress message only at whole percent

??????????????????????????? ?* steps to reduce the number of messages

??????????????????????????? ?* printed on (slow) serial consoles

??????????????????????????? ?*/

??????????????????????????? if(percent != percent_complete) {

?????????????????????????????????? percent_complete= percent;

?

?????????????????????????????????? printf("\rWritingat 0x%lx -- %3d%% "

????????????????????????????????????????? "complete.",offset, percent);

??????????????????????????? }

???????????????????? }while (0);

????????????? }

?????? }

?????? puts("\n");

?

?????? unmap_physmem(buf,len);

?

?????? if (ret){

????????????? printf("SPIflash %s failed\n", argv[0]);

????????????? return1;

?????? }

?

?????? return0;

?

usage:

?????? printf("Usage:sf %s addr offset len\n", argv[0]);

?????? return1;

}

?

static int do_spi_flash_erase(int argc, char*argv[])

{

?????? unsignedlong offset;

?????? unsignedlong len;

?????? char*endp;

?????? int ret;

?????? structmtd_info_ex *spiflash_info = get_spiflash_info();

?????? unsignedlong erase_start, erase_len, erase_step;

?????? intpercent_complete = -1;

?

?????? if (argc< 3)

????????????? gotousage;

?

?????? offset =simple_strtoul(argv[1], &endp, 16);

?????? if(*argv[1] == 0 || *endp != 0)

????????????? gotousage;

?????? len =simple_strtoul(argv[2], &endp, 16);

?????? if(*argv[2] == 0 || *endp != 0)

????????????? gotousage;

?

?????? if(offset + len > spiflash_info->chipsize * spiflash_info->numchips) {

????????????? printf("ERROR:erase area is out of range!\n\n");

????????????? return1;

?????? }

?

?????? if(offset & (spiflash_info->erasesize-1)) {

????????????? printf("ERROR:erase start address is not block aligned!\n\n");

????????????? return1;

?????? }

?

?????? if (len& (spiflash_info->erasesize-1)) {

????????????? printf("ERROR:erase length is not block aligned!\n\n");

????????????? return1;

?????? }

?

?????? erase_start= offset;

?????? erase_len?? = len;

?????? erase_step? = spiflash_info->erasesize;

?

?????? while(len > 0) {

????????????? if(len < erase_step)

???????????????????? erase_step= len;

?

????????????? ret= spi_flash_erase(flash, offset, erase_step);

????????????? if(ret) {

???????????????????? printf("SPIflash %s failed\n", argv[0]);

???????????????????? return1;

????????????? }

?

????????????? len-= erase_step;

????????????? offset+= erase_step;

?

????????????? do{

???????????????????? unsignedlong long n = (unsigned long long)

??????????????????????????? (offset- erase_start) * 100;

???????????????????? intpercent;

?

???????????????????? do_div(n,erase_len);

???????????????????? percent= (int)n;

?

???????????????????? /*output progress message only at whole percent

???????????????????? ?* steps to reduce the number of messagesprinted

???????????????????? ?* on (slow) serial consoles

???????????????????? ?*/

???????????????????? if(percent != percent_complete) {

??????????????????????????? percent_complete= percent;

?

??????????????????????????? printf("\rErasingat 0x%lx -- %3d%% complete.",

????????????????????????????????????????? offset,percent);

???????????????????? }

????????????? }while (0);

?????? }

?????? puts("\n");

?

?????? return0;

?

usage:

?????? puts("Usage:sf erase offset len\n");

?????? return1;

}

?

當數據寫到Flash以后,需要重啟單板,所以在net.c里面調用uboot的重啟函數,do_reset(),這個函數在grub模式下執行reset的時候就會被調用,現在把它添加到net.c里面,當上傳的文件寫到Flash之后就會自動重啟單板:

if ( !do_upgrade() );

{???

???? DBG("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);??????do_http_progress(WEBFAILSAFE_PROGRESS_UPGRADE_READY);

???? do_reset (NULL, 0, 0, NULL);

???? return 0;

}???

?

上面do_http_progress()這個函數只是打印文件加載成功或失敗的信息:

int do_http_progress(const int state) {

?

?????? /*toggle LED's here */

?????? switch(state) {

????????????? caseWEBFAILSAFE_PROGRESS_START:

???????????????????? printf("HTTPserver is ready!\n\n");

???????????????????? break;

?

????????????? caseWEBFAILSAFE_PROGRESS_TIMEOUT:

???????????????????? //printf("Waitingfor request...\n");

???????????????????? break;

?

????????????? caseWEBFAILSAFE_PROGRESS_UPLOAD_READY:

???????????????????? printf("HTTPupload is done! Upgrading...\n");

???????????????????? break;

?

????????????? caseWEBFAILSAFE_PROGRESS_UPGRADE_READY:

???????????????????? printf("HTTPugrade is done! Rebooting...\n\n");

???????????????????? break;

?

????????????? caseWEBFAILSAFE_PROGRESS_UPGRADE_FAILED:

???????????????????? printf("##Error: HTTP ugrade failed!\n\n");

???????????????????? //wait 1 sec

???????????????????? milisecdelay(1000);

?

???????????????????? break;

?????? }

?????? return0;

}

?

到這里在net.c里面要添加的函數基本上就完成了,當然還有個別的宏定義,全局變量等一些定義的話,在編譯的時候參考出錯信息來修改添加就可以了。例如我在文件開頭添加了如下信息:

/*--------------------------add byyangzheng---------------------*/

#include <common.h>

#include <spi_flash.h>

?

#include <asm/io.h>

#include <linux/mtd/mtd.h>

?

#ifndef CONFIG_SF_DEFAULT_SPEED

# define CONFIG_SF_DEFAULT_SPEED? 1000000

#endif

#ifndef CONFIG_SF_DEFAULT_MODE

# define CONFIG_SF_DEFAULT_MODE????????? SPI_MODE_3

#endif

?

#define WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE?????????? 0

#define WEBFAILSAFE_PROGRESS_START????????????????? 0

#define WEBFAILSAFE_PROGRESS_TIMEOUT??????????????? 1

#define WEBFAILSAFE_PROGRESS_UPLOAD_READY?????????? 2

#define WEBFAILSAFE_PROGRESS_UPGRADE_FAILED???????? 4

#define WEBFAILSAFE_PROGRESS_UPGRADE_READY????????? 3

#define ET_DEBUG

?

#define milisecdelay(_x)???? udelay((_x) * 1000)

?

#if 0

#define DBG(x...)?printf(x)

#else

#define DBG(x...)??do { } while (0)

#endif

?

static int arptimer = 0;

int??webfailsafe_is_running = 0;

int??webfailsafe_ready_for_upgrade = 0;

int??webfailsafe_upgrade_type = WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE;

unsigned char *webfailsafe_data_pointer = NULL;

extern int do_reset (cmd_tbl_t *cmdtp, int flag, intargc, char *argv[]);

static struct spi_flash *flash;

/*---------------------------------------------------------------*/

?

小結:uip 的移植大部分時間就是用在net.c里面,net.c里面需要修改的東西很多,尤其是字節序的問題也是讓我花了很長時間去轉換,總之net.c需要修改的大致就這么多,可能還有個別地方沒講到,但是那都是小問題,這篇文檔已經說明了移植uip協議的整體思路,那么沒有提及的個別小問題就靠自己分析了,這樣做移植才能有更多收獲。下面還有一點需要完善,我需要系統啟動時,在找不到內核的情況下,自動調用httpd服務程序,然后通過web來升級我的系統,方法如下。

?

2.2.3 在uboot里面添加httpd命令

?????? 首先要知道,uboot里面的那些命令是在哪兒定義的,比如,printenv, tftp, help等。這些命令是在u-boot-2010.06/common的.c文件里面定義的??梢阅7缕渲械囊粋€命令來添加我們的httpd命令,我的代碼添加如下:

[kernel@localhost common]$vim cmd_httpd.c

/*********************************************************************************

?*?????Copyright:? (C) 2014 YangZheng<yz2012ww@gmail.com>?

?*?????????????????All rights reserved.

?*

?*??????Filename:? cmd_httpd.c

?*???Description:? This file

?*????????????????

?*???????Version:? 1.0.0(10/09/2014~)

?*????????Author:? Yang Zheng<yz2012ww@gmail.com>

?*?????ChangeLog:? 1, Release initialversion on "10/09/2014 03:48:07 PM"

?*????????????????

?********************************************************************************/

?

#include<common.h>

#include<command.h>

#include <net.h>

?

extern intNetLoopHttpd(void);

int do_httpd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])

{

??? printf("file=%s, func=%s,line=%d\n", __FILE__, __FUNCTION__, __LINE__);

??? return NetLoopHttpd();? //這里就會調用net.c里面的NetLoopHttpd()函數

}

U_BOOT_CMD(httpd, 1,1, do_httpd, "start www server for firmware recovery\n", NULL);??????????

?

?

然后再添加一個功能,那就是上面提到的,系統啟動找不到內核是就調用httpd服務程序。在u-boot-2010.06/common/cmd_bootm.c的bootm_start()函數里面添加NetLoopHttpd():

extern int NetLoopHttpd(void);

static int bootm_start(cmd_tbl_t *cmdtp, int flag,int argc, char *argv[])

{

??? void??????? *os_hdr;

??? int???? ret;

?

??? memset((void *)&images, 0, sizeof (images));

???images.verify = getenv_yesno ("verify");

?

???bootm_start_lmb();

?

??? /* getkernel image header, start address and length */

??? os_hdr =boot_get_kernel (cmdtp, flag, argc, argv,

???????????&images, &images.os.image_start, &images.os.image_len);

?? ?if (images.os.image_len == 0) {

??????? puts("ERROR: can't get kernel image!\n");?? //找不到內核時會打印這一句信息

??????? puts ("#############start httpdserver!###############\n");

??????? NetLoopHttpd();

??????? return1;

…………

?

2.2.4 展示結果

?????? 終于到了看結果的時候了,有點激動。。。。。

首先在單板上運行httpd服務,在windows的DOS下,使用命令ping命令:


圖1 ?運行httpd


圖2 ping單板

?

使用web升級系統,在瀏覽器地址欄輸入單板ip,就會看到如下圖所示:



圖3 ?web升級界面

點擊選擇文件->升級就開始上傳文件,上傳完以后就會自動寫到Flash了,這里就不再演示,不然我又得再次升級。。。

?

3、總結

3.1 uip協議關鍵庫函數的功能及使用方法

?????? 應用程序必須作為C函數去實現,uIP在任何一個事件發生時調用UIP_APPCALL()。表 1 列出了可能的事件和每個事件的對應測試函數,測試函數用于區別不同的事件。函數是作為C宏命令實現的,將會是零或非零值。注意,某些函數可以在互相連接時發生(即新數據可以在數據確應的同時到達)。

表 1? uIP應用事件和對應的測試參數

一個數據包到達,確定先前發送到數據

uip_acked()

應用程序的新數據包已到達

uip_newdata()

一個遠程主機連接到監聽端口

uip_connected()

一個到達遠程主機的連接建立成功

uip_connected()

計時時間滿重發

uip_rexmit()

計時時間滿周期性輪詢

uip_poll()

遠程主機關閉連接

uip_closed()

遠程主機中斷連接

uip_aborted()

由于太多重傳,連接中斷

uip_timedout()

?

當應用程序調用時,uIP設置全局變量uip_conn去指向當前連接的uip_conn結構,這可以用于區別不同的服務。一個典型的應用是檢查uip_conn->lport (當地TCP端口號)去決定哪個服務連接應該提供。例如,如果值uip_conn->lport等于80,應用程序可以決定啟動一個HTTP服務;若值是23,則是啟動TELNET服務。

?

3.1.1 接收數據

如果uIP測試函數uip_newdata()的值為1,則遠程連接的主機有發送新數據,uip_appdata指針指向實際數據,數據的大小通過uIP函數uip_datalen()獲得。在數據不是被緩沖后,應用程序必須立刻啟動。

?

3.1.2 發送數據

應用程序通過使用uIP函數uip_send()發送數據。uip_send()函數采用兩個參數:一個指針指向發送數據和數據的長度。如果應用程序為了產生要發送的實際數據需要RAM空間,包緩存(通過uip_appdata指針指向)可以用于這方面。在一個時間里應用程序只能在連接中發送一塊數據,所以不可以在每個應用程序啟用中調用uip_send()超過一次,只有上一次調用的數據將會發出后才可以。注意,調用uip_send()后會改變某些全局變量,在應用函數返回前它不能被調用。

?

3.1.3 重發數據

若數據在網絡中丟失,則應用程序必須重新發數據。無論是數據收到還是沒有收到,uIP都保并通知應用程序什么時候察覺出數據丟失了。若測試函數uip_rexmit()為真,則應用程序要重持跟蹤,發上一次發出的數據。重發就好像原來那樣發送,也就是通過uip_send()發送。

?

3.1.4 關閉連接

應用程序通過調用uip_close()關閉當前連接,這會導致連接干凈地關閉。為了指出致命的錯誤,應用程序可以通過中止連接和調用uip_abort()函數完成這項工作。若連接已經被遠端關閉,則測試函數uip_closed()為真,應用程序接著可以做一些必要的清理工作。

?

?

3.1.5 報告出錯

有兩個致命的錯誤可以發生在連接中:連接由遠程主機中止和連接多次重發上一數據而被中止。uIP通過調用函數報告這些問題,應用程序使用兩個測試函數uip_aborted()和uip_timedout() 去測試這些錯誤情況。

?

?

3.1.6 輪詢

當連接空閑時,uIP周期性地輪詢應用程序,應用程序使用測試函數uip_poll()去檢查它是否被輪詢過。

?

3.1.7 監聽端口

uIP維持一個監聽TCP端口列表,通過uip_listen()函數,一個新的監聽端口被打開。當一個連接請求在一個監聽端口到達,uIP產生一個新的連接。若一個新連接產生,則應用程序被調用,測試函數uip_connected()為真。

?

3.1.8 打開連接

作為uIP的0.6版,在uIP里面通過使用uip_connect()函數打開一個新連接。這個函數打開一個新連接到指定的IP地址和端口,返回一個新連接的指針到uip_conn結構。若是沒有空余的連接槽,則函數返回空值。為了方便,函數uip_ipaddr()可以用于將IP地址打包進兩個單元16位數組里,通過uIP去代表IP地址。

接下來用兩個例子說明。第一個例子展示了怎樣打開一個連接去遠端TCP端口8080。若沒有足夠的TCP連接插槽去允許一個新連接打開,則uip_connect()函數返回NULL并通過uip_abort()中止當前連接。第二個例子展示怎樣打開一個新連接去指定的IP地址。

例1:打開一個連接去遠端TCP端口8080。

void connect_example1_app(void)

{

if(uip_connect(uip_conn->ripaddr,8080) == NULL)

?{

uip_abort();

}

}

例2:打開一個連接去當前連接的遠端的端口8080。

void connect_example2(void)

?{

u16_t? ipaddr[2];

uip_ipaddr(ipaddr,192,168,0,1);

uip_connect(ipaddr,8080);

}

?

3.1.8 數據流控制

uIP通過函數uip_stop()和函數uip_restart()提供對存取TCP數據流的控制途徑。假如一個應用程序下載數據到一個慢速設備,例如磁盤驅動器。當磁盤驅動器的作業隊列滿時,應用程序不會準備從服務器接收更多的數據,直到隊列排出空位。函數uip_stop()可以用于維護流控制和停止遠程主機發送數據。當應用程序準備好接收更多數據時,可用函數uip_restart()告知遠程終端再次發送數據。函數uip_stopped()可以用于檢查當前連接是否停止。

?

?

3.1.9 UIP函數總結

表2 包含了所有uIP提供的函數

表2? uIP 函數總結

系統接口

?

uip_init()

uip_input()

uip_periodic()

初始化uIP

處理輸入包

處理周期計時事件

應用程序接口

?

uip_listen()

uip_connect()

uip_send()

uip_datalen()

uip_close()

uip_abort()

uip_stop()

uip_stopped()

uip_restart()

開始監聽端口

連接到遠程主機

在當前連接發送數據

輸入數據的大小

關閉當前連接

中止當前連接

停止當前連接

查找連接是否停止

重新啟動當前連接

測試函數

?

uip_newdata()

uip_acked()

uip_connected()

uip_closed()

uip_aborted()

uip_timeout()

uip_rexmit

uip_poll()

遠程主機已經發出數據

確定發出的數據

當前連接剛連上

當前連接剛關閉

當前連接剛中止

當前連接剛超時

數據重發

應用程序循環運行

其它

?

uip_mss()

uip_ipaddr()

htons(),ntohs()

獲得當前連接的最大段的大小

將IP地址結構打包

在主機和網絡之間轉換字節次序

?

上面的這些都是引用網上別人博客里面的內容,總結的也很全面。

?

?

?

?

?

?

?

總結

以上是生活随笔為你收集整理的UIP协议栈移植到u-boot详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。