Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Internet Programming on an ARM Guest

DZone's Guide to

Internet Programming on an ARM Guest

Getting network programming working in embedded Linux used to be a pain. Not anymore. See cross-compiling in action when using an ARM QEMU guest.

· IoT Zone
Free Resource

Address your IoT software testing needs – improve quality, security, safety, and compliance across the development lifecycle.

Okay, so there are a couple of ways you can run networking on an ARM QEMU guest. The easiest is via SLIRP, the default user mode networking. It's slow and chatty, but for most IoT work, that's okay. There are alternative, higher performance approaches, but they hijack your local interface to the virtual bridge, removing networking from your host. This is fine, sometimes, but not that frequently. It's a real pain to work with if you're using it day-to-day, but handy for late-stage testing. Anyway, we're not going to use that. We'll use SLIRP instead.

Okay, first, use buildroot to configure an ARM image that includes libcurl. Using our previous buildroot configuration, just go to Target packages -> Libraries -> Networking, and select libcurl:

Image title

Go ahead and select the binary, too. This is handy for connectivity testing.

Now make your new image, and spin it up with QEMU, like we did in my previous article. You'll need to configure it with a new user too. Then test your internet connectivity:

Image title

Curl is especially useful for this when you're running in SLIRP mode because ICMP traffic (i.e. ping) isn't really supported (you can turn it on, but there's really no need, and it's kind of a hassle).

Now, build your ARM program from the previous article, using the IP address of your host. Remember, the QEMU command we use redirects host port 2222 to guest port 22, so you need to take this into account when you SCP the executable over:

$ scp -P 2222 test <username>@localhost:~/
<username>@localhost's password: 
test        100% 7204     7.0KB/s   00:00


Now, when you compiled the test program, you inserted the host IP address, right? Of course you did. Now, spin up Python's SimpleHTTPServer on your host, and run the test program on your guest:

Image title

Here, you can see my session on the guest on the left, where I ran the test program. The output is the directory listing, HTML-ized. On the right, you can see the GET request recorded in the SimpleHTTPServer session. You can also see all my tmux goodness, but you can ignore that.

Anyway, that's all there is to it! You've successfully run your first ARM cross-compiled networking program!

Accelerate the delivery of high-quality software in the connected IoT era through an integrated analysis, testing, security, and analytics platform. Parasoft's comprehensive portfolio of testing toolsautomates time-consuming testing tasks and provides management with intelligent analytics and reporting so they can focus on what matters.

Topics:
qemu ,arm ,cross-compile ,iot ,tutorial

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}