OK6410A 开发板 (三) 2 u-boot-1.1.6 ethernet 解析

  • u-boot-1.1.6 现状
1. 检查当前局域网可用ip
$ nmap -sP 10.10.11.*
2. 设置 u-boot ip 相关变量
setenv gatewayip 10.10.11.254
setenv ipaddr 10.10.11.120
setenv serverip 10.10.11.57
setenv netmask 255.255.255.0
3. ping 局域网主机
SMDK6410 # ping 10.10.11.57
Found DM9000 ID:90000a46 at address 18000300 !
DM9000 work in 16 bus width
bd->bi_entaddr: 00:40:5c:26:0a:5b
[eth_init]MAC:0:40:5c:26:a:5b:
host 10.10.11.57 is alive
  • ping 流程(简述)
先封包发起一个ArpRequest ,调用 dm9000驱动驱动的send接口 发出
然后循环
	1. 调用dm9000驱动的recv接口 收数据,
	2. 拆包,解析,是不是ping回包,如果是ping回包,则返回;不是,则继续循环
  • ping 流程(硬件无关)
do_ping
	NetLoop
		eth_init // dm9000驱动提供的函数

		switch (protocol) {
    
    
			case PING:
	        NetCopyIP(&NetOurIP, &bd->bi_ip_addr);                                   
	        NetOurGatewayIP = getenv_IPaddr ("gatewayip");                           
	        NetOurSubnetMask= getenv_IPaddr ("netmask");                             
	        NetOurVLAN = getenv_VLAN("vlan");                                        
	        NetOurNativeVLAN = getenv_VLAN("nvlan"); 
        }

        switch (net_check_prereq (protocol)) {
    
    
	        case PING:
	        PingStart();
	        	NetSetHandler (PingHandler);
	        		packetHandler = PingHandler;
	        	PingSend
	        		ArpRequest
	        			eth_send 	// dm9000驱动提供的函数
        }
        status_led_set (STATUS_LED_RED, STATUS_LED_ON);

        for(;;){
    
    
        
	        eth_rx(); 	// dm9000驱动提供的函数
	        
	        switch (NetState) {
    
    
	        case NETLOOP_CONTINUE: // 403次
	        //nothing
	        case NETLOOP_SUCCESS: // 到达这种状态,是因为 PingHandler 被执行了 , 具体看 RECV 流程
	        eth_halt()// dm9000驱动提供的函数
	        return NetBootFileXferSize;


        }
    if (return value of NetLoop) >=0
    	printf("host %s is alive\n", argv[1]);
   	else
   		printf("ping failed; host %s is not alive\n", argv[1]);
  • ping 流程(硬件dm9000相关)
eth_rx
	volatile uchar *NetRxPackets[PKTBUFSRX];
	unsigned char *addr = (unsigned char *)NetRxPackets[0];

	MoveData(addr, rxlen, 0);
	NetReceive (NetRxPackets[0], rxlen);
		Ethernet_t *et = (Ethernet_t *)inpkt;
		x = ntohs(et->et_protlen);

		switch (x) {
    
    
			case PROT_IP:
				if (ip->ip_p == IPPROTO_ICMP) {
    
    
					switch (icmph->type) {
    
    
						case ICMP_ECHO_REPLY:
							(*packetHandler)((uchar *)ip, 0, 0, 0); // PingHandler
								NetState = NETLOOP_SUCCESS;
					}
				}
		}

dm9000 驱动

dm9000驱动
	提供了 4个 出口函数 给 ping 流程
	提供了 0个 出口变量 给 ping 流程
eth_init
eth_send
eth_halt
eth_rx


include/configs/smdk6410.h

#define CONFIG_DRIVER_DM9000    1   /* we have a SMC9115 on-board */             
#define CONFIG_DM9000_BASE 0x18000300 /*XMOCSN1*/                                   
#define DM9000_DATA 0x18000304 /*ADDR2*/                                            
#define DM9000_IO CONFIG_DM9000_BASE                                                
#define CONFIG_DM9000_USE_16BIT 1

猜你喜欢

转载自blog.csdn.net/u011011827/article/details/114653153