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
先封包发起一个ArpRequest ,调用 dm9000驱动驱动的send接口 发出
然后循环
1. 调用dm9000驱动的recv接口 收数据,
2. 拆包,解析,是不是ping回包,如果是ping回包,则返回;不是,则继续循环
do_ping
NetLoop
eth_init
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
}
status_led_set (STATUS_LED_RED, STATUS_LED_ON);
for(;;){
eth_rx();
switch (NetState) {
case NETLOOP_CONTINUE:
case NETLOOP_SUCCESS:
eth_halt();
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]);
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);
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
#define CONFIG_DM9000_BASE 0x18000300
#define DM9000_DATA 0x18000304
#define DM9000_IO CONFIG_DM9000_BASE
#define CONFIG_DM9000_USE_16BIT 1