Step-by-step play pcduino3--uboot under Ping, add command can accept ping from host

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.