Saturday, April 26, 2014

#4: Qemu Tool Chain for the Beaglebone Black

So far my adventures with the Beaglebone Black left something to be desired, so I decided to make my own ARM tool chain and try to get Fedora 20 to run properly on it.

The easiest way to prepare code for the BBB is with Qemu.  This way, one can make a native ARM system for test and debug on a fast computer and then one can simply copy the resultant programs over to the slow little BBB.

Well, that is the idea anyway.


On a Mac, installing Qemu is an adventure in and of itself, so I eventually called it quits and rather installed it on a Fedora 20 virtual machine on the Mac - a virtual machine inside a virtual machine.  It makes my head hurt just to think about the computing contortions required underneath it all, but if it works, it works - except when it doesn't wanna...

Therefore, start here:

Instaling Qemu on Fedora is super simple, since it is very well supported:
# yum install qemu -y

which will install the whole catastrophe with all the different processors that Qemu can emulate.

This one liner is quite a contrast with trying to make Qemu work on a Mac.

Fedora 20 ARM on Qemu

There is a good guide on the Fedora web site on this:

So, let's plod through that and see what happens.  That guide describes various ways to do it, with and without libvirt, with or without a cross compiler and so on.  It is worth scanning through the whole thing once before you start.

As is usual with Linux, something is bound to screw up spectacularly somewhere along the line.

Debugging Qemu

Some more information:

Using Qemu with libvirt

If one can get this method to work, the advantage is easy access to NAT and DHCP utilities, so connecting to the virtual machine and managing it, is more convenient.

Details here:

We need a few more goodies:
# yum groupinstall virtualization

If you installed all of Qemu above, then this will do nothing:
# yum install qemu-system-arm
Start her up:
# service libvirtd start

ARM Root File System
# cd /var/lib/libvirt/images

Get it: \

That takes a while - So far, so good!

Now unzippit:
# gunzip arm1.img.gz 
# restorecon * 
# virsh define arm1.xml
error: Failed to define domain from arm1.xml
error: unsupported configuration: Unknown architecture arm

Bah, humbug...

Something is amiss here in file arm1.xml:
    <type arch='arm' machine='versatileab'>hvm</type>

The problem is that "arm" is not correct.  It should be "armv7l".  So let's edit the arm1.xml file and try again:
# virsh define arm1.xml
Domain arm1 defined from arm1.xml

Cool, now we are progressing again.


We need to loosen the access control a little bit to allow Qemu to run:
# setsebool -P virt_use_execmem 1

That takes a few seconds.

Virtual Machine Manager

Try System Tools>Virtual Machine Manager on the LXDE menu.  It should ask for the root password and then start a simple GUI with one VM called arm1.

The initial root password for the ARM VM image is fedoraarm.

As soon as I try to run the VM however, I get a monitor error and none of the available monitor types work:
Error starting domain: internal error: process exited while connecting to monitor: Error: Cirrus VGA not available

Bah, Humbug #2...

The command virsh start arm1 gives the same error, while virt-viewer arm1 brings up a dialogue with the message "waiting for guest domain to start", which really doesn't help a lot now does it?

Looking at the XML file again, there is a VNC option left to try, but for that I need a VNC viewer - sigh...
# yum install tigervnc -y
So, let's try to run the VM with a VNC server:
# virsh vncdisplay arm1
error: Domain is not running

Bah humbug #3, that error message is extremely unhelpful.

To known the exact error, look in the guest log:
# less /var/log/libvirt/qemu/arm1.logError: Cirrus VGA not available
2014-04-26 12:16:04.790+0000: shutting down

So it is really just the same old problem.

After some more experimentation with the Virtual Machine Manager, I found that a combination of NIC=RTL8139Display=VNC and Video=Xen runs, but that combination is not exactly the BBB hardware.

Hmmm, maybe I spoke too soon, because the whole F20 virtual machine locked up and I had to restart it...

On a second try,  I could connect to it with TigerVNC localhost:5900 and log in as root with password fedoraarm.  So it can work, I just don't know for how long or why it died before.

Here is the proof!

So now what can I do with it?

Hmm, when I try to pause Qemu, VNC exits and the F20 virtual machine becomes unusable.  It still runs, but most things don't work and it needs to be reset.  

Cross Compiler

Normally, one would use a cross compiler to develop for an  embedded system, since compiling something on a dinky little ARM processor will chug along till the sun goes nova and few people have that much time on their hands.

A good Linux cross compiler system is available here:

In general, two versions are available using either glibc or uclibc.
However, I would like to compile natively inside Qemu just for fun.  Yes, it will be slow, but a modern umpteen Gigahertz computer should be plenty fast enough - I hope.
Anyhoo, this is supposed to be fun, for various values of pain...

Native Compiler

As with most things, this has been done before,  but not necessarily on Qemu.

Very good ARM support is available with Arch Linux:

I'll probably have to abandon Fedora and work with Arch - sigh...

A whole lot more information can be had here:
This guide, while it is out of date, really explains a lot of things regarding making your own tool chain and is worth reading attentively:

To be continued!


No comments:

Post a Comment

On topic comments are welcome. Junk will be deleted.