Uboot is a very good open source project. Not only can learn bootloader, embedded, various bus protocols. You can also learn about the network protocol stack. In embedded development, Uboot TFTP and NFS are often used to speed up development. Before TFTP can be used, we have to make sure that host and PcDuino3 can ping. You can ping the host under Uboot, but host cannot ping Uboot, because Uboot is not the operating system, we need to make a command to cycle through the ping command from host.
Before you add a command to Uboot to accept a ping from host, let's take a look at the ping process:
Hardware environment: The IP of host hosts is 192.168.1.11,mac address is 5c:26:0a:5c:91:50.
The IP of PCDUINO3 is 192.168.1.188,mac address is 12:34:56:78:11:22.
When we send ping 192.168.1.188 from Uboot to host, this process can be captured with Wireshark:
First, the broadcast sends an ARP request, and then the host responds to the request so that the uboot end gets the host's MAC address;
The next step is to send the echo request for the ICMP protocol and receive the Echo reply, which means the ping is out.
In fact, from the host to PCDUINO3 send ping process is the same, we just need to add a few lines of simple code on it,
Add a recvping command for Uboot:
static int recv_ping (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
printf ("recv ping command Excute \ n ");
if (Netloop (recvping) < 0) {
printf ("Ping failed;");
return 1;
}
printf ("Host is alive\n");
return 0;
}
U_boot_cmd (
recvping, 2, 1, recv_ping,
"recv ICMP echo_request from Network host",
" Wait the ping from other host "
);
Next, add the processing branch that handles recvping in Netloop:
Case recvping:
recvping_start ();
Break
Where the Recvping_start function is as follows:
void Recvping_start (void)
{
printf ("Using%s device\n", Eth_get_name ());
Netsettimeout (100000UL, ping_timeout);
}
In this way, we again ping from the host, using the Wireshark capture package:
Because host sends ICMP packets four times, there are multiple echo request.
In such a look, the network protocol stack is also quite simple and clear, through this process, only for the understanding of the network protocol stack, and not only the UNIX network programming Socket,listen,bind and so on.