Skip to main content

#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.

Qemu

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: http://www.aeronetworks.ca/2014/01/fedora-20-on-virtualbox.html

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:
https://fedoraproject.org/wiki/Architectures/ARM/HowToQemu

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:
http://qemu.weilnetz.de/qemu-doc.html
http://fedoraproject.org/wiki/How_to_debug_Virtualization_problems 
http://www.aurel32.net/info/debian_arm_qemu.php

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: http://wiki.libvirt.org/page/QEMUSwitchToLibvirt

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:
http://cdot.senecac.on.ca/arm/arm1.xml \
http://cdot.senecac.on.ca/arm/arm1.img.gz

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:
<vcpu>1</vcpu>
  <os>
    <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.

SELinux

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:
http://archlinuxarm.org/platforms/armv7/ti/beaglebone-black

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!

H.

Comments

Popular posts from this blog

Parasitic Quadrifilar Helical Antenna

This article was reprinted in OSCAR News, March 2018:  http://www.amsat-uk.org If you want to receive Satellite Weather Pictures , then you need a decent antenna, otherwise you will receive more noise than picture. For polar orbit satellites, one needs an antenna with a mushroom shaped radiation pattern .  It needs to have strong gain towards the horizon where the satellites are distant, less gain upwards where they are close and as little as possible downwards, which would be wasted and a source of noise.  Most satellites are spin stabilized and therefore the antenna also needs circular polarization, otherwise the received signal will flutter as the antennas rotate through nulls. The helical antenna, first proposed by Kraus in 1948, is the natural solution to circular polarized satellite communications.  It is a simple twisted wire - there seems to be nothing to it.  Various papers have been published on helix antennas, so the operation is pretty well ...

To C or not to C, That is the Question

As most would know, the Kernighan and Ritchie C Programming Language is an improved version of B, which is a simplified version of BCPL, which is derived from ALGOL, which is the Ur computer language that started the whole madness, when Adam needed an operating system for his Abacus, to count Eve's apples in the garden of Eden in Iraq.  The result is that C is my favourite, most hated computer language , which I use for everything. At university, I learned FORTRAN with punch cards on a Sperry-Univac, in order to run SPICE, to simulate an operational amplifier.  Computers rapidly lost their glamour after that era! Nobody taught me C.  I bought the book and figured it out myself. Over time, I wrote a couple of assemblers, a linker-locator, various low level debuggers and schedulers and I even fixed a bug in a C compiler - not because I wanted to, but because I had to, to get the job done!   Much of my software work was down in the weeds with DSP and radio modems...

Unlock CRA PDF Forms

Unlock Canada Revenue Agency PDF Forms It appears that there is a relatively new PDF feature to prevent casual copying and saving of a file and that some programs save PDF files with these foolish features active by default.  Many forms from the Canada Revenue Agency are locked in this way, which makes it difficult to do one's taxes, since one can fill the form, but cannot save it.  One can only print the form.  It should be possible to print to a file or export it to a new PDF file, but it is far better to reset the annoying anti-taxpayer flags, since the 'printed' form cannot be edited easily any more and I always manage to make a mistake or three that need to be corrected after review. If there is a Linux (virtual) machine handy, install qpdf and use it to reset the silly flags: $ su - password # dnf update # dnf install qpdf # exit $ qpdf --decrypt lockedfile.pdf unlockedfile.pdf One doesn't need a password to unlock these flags, so the fix is instant. La voila! He...