BeagleBone Black, GNU Radio, and HackRF One

on 18 June, 2014

18 June, 2014

The BeagleBone Black is a small, single board computer that runs Linux.

More powerful that a Raspberry Pi, it is a good candidate for running a Software Defined Radio for long running tasks without having to tie up a laptop for so long. This is a guide to setting up a BeagleBone Black with Ångström Linux to compile GNU Radio and HackRF drivers so you can use a HackRF with a BeagleBone Black.

Having recently gotten my hands on both a BeagleBone Black (BBB) and a HackRF One prototype I started thinking how useful it would be to run the HackRF from the BBB rather than having a whole laptop sat there while doing long running tasks with GNU Radio. The BBB can run Ångström or Debian Linux, and although Debian has GNU Radio in its repositories, Ångström is designed specifically for embedded systems and so may have some performance benefits, although I haven’t tested this assumption; plus, I like to build the latest version of GNU Radio from git sources.

Getting all the dependencies and bits of configuration right was a little tricky, so I wrote this guide to show the steps I took to get everything built and working so you can drive a HackRF from a BeagleBone Black.

Firstly, decide whether to use the on-board eMMC storage or a micro SD card. If using the eMMC be prepared to uninstall a few things to make enough space, or use an SD card as I ended up doing. This guide is based on the Ångström SD card image from 2013-06-20, but hopefully it will largely apply to later versions as well. Remember that after writing the SD card it’s a good idea to expand the root partition to use the whole of the SD card, I booted a GParted live CD on my laptop to do this.

To begin upgrade all the existing packages so your BBB is fully patched and up to date:

opkg update
opkg upgrade

This may take a while, and uses /tmp a lot so keep an eye on it with df. If you get close to running out of space in /tmp you can dynamically resize it during the upgrade with:

mount -o remount,size=500M tmpfs /tmp

But remember this will take a toll on the available RAM.

Before we get to GNU Radio, a bit of general configuration to the OS of the BBB. Set the correct date and time while online with:

ntpdate -b -s -u pool.ntp.org

To have it update at each reboot:

opkg install ntp

Update /etc/ntp.conf (you can get appropriate servers for your country from www.pool.ntp.org):

# This is the most basic ntp configuration file
# The driftfile must remain in a place specific to this
# machine - it records the machine specific clock error
driftfile /etc/ntp.drift
# This obtains a random server which will be close
# (in IP terms) to the machine. Add other servers
# as required, or change this.
server 0.uk.pool.ntp.org
server 1.uk.pool.ntp.org
server 2.uk.pool.ntp.org
server 3.uk.pool.ntp.org
# Using local hardware clock as fallback
# Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself
#server 127.127.1.0
#fudge 127.127.1.0 stratum 14
# Defining a default security setting
restrict default

Then find your timezone in /usr/share/zoneinfo (eg. Europe/London), and update the link:

rm /etc/localtime

Now enable the ntp service:

systemctl enable ntpdate.service
systemctl enable ntpd.service

Now, for the BeagleBone Black specifically, update the /lib/systemd/system/ntpdate.service:

[Unit]
Description=Network Time Service (one-shot ntpdate mode)
Before=ntpd.service

[Service]
Type=oneshot
ExecStart=/usr/bin/ntpd -q -g -x
ExecStart=/sbin/hwclock --systohc
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Thanks to derekmolloy.ie for this info on NTP on the BBB!

At this point I removed some packages I wasn’t going to use and which expose network services by default on the BBB. Using opkg remove I uninstalled bonescript, nodejs, cloud9, and gateone.

Then install a few additional packages:

opkg install sudo
opkg install cmake
opkg install libusb-1.0-0
opkg install libusb-1.0-dev

As root is the only user by default on the BBB, create another user and give it sudo access by running:

visudo

And uncommenting the line reading:

%wheel ALL=(ALL) ALL

I then like to edit /etc/skel/.bashrc and uncomment options to add colour to ls output, and copy that into root’s home too along with /etc/skel/.profile.

Then add a user:

useradd -k /etc/skel -m -d /home/sdr sdr

And set a password:

passwd sdr

Then add create the wheel group and add the new user to it to enable it’s sudo access:

addgroup wheel
usermod -a -G wheel sdr

Finally, lock the root account so only sudo provides root access:

passwd -l root

We will need fftw as a dependency, but the version of fftw in the Ångström repositories is not built with float support, providing the fftw3f library. So download it’s source (I used the fftw-3.3.4 tarball), configure it for float support, build and install it:

./configure --enable-float
make
sudo make install
sudo su -
ldconfig

Now install the HackRF drivers. Note that if you use git clone with an https:// address from github it fails for some reason, but if you replace it with git:// it works:

git clone git://github.com/mossmann/hackrf.git
cd hackrf/host
mkdir build
cd build
cmake ../ -DINSTALL_UDEV_RULES=ON
sudo make install

For the library to get picked up correctly (this is also needed for GNU Radio libraries), edit /etc/ld.so.conf to include:

/usr/local/lib

Then run ldconfig as root.

To properly enable the udev rules and allow the sdr non-root user HackRF access:

chmod a+x /etc/udev/rules.d/52-hackrf.rules
usermod -a -G plugdev sdr

Now grab the following dependencies for GNU Radio. This will enable a good set of GNU Radio features as you will see when you configure it later, and should be just about everything needed to work with the HackRF. You will need other dependencies if you want the additional support enabled.

opkg install python-distutils
opkg install python-cheetah
opkg install boost
opkg install boost-dev
opkg install orc
opkg install orc-dev
opkg install liborc-0.4-0
opkg install gsl
opkg install gsl-dev
opkg install wxpython
opkg install python-lxml
opkg install python-pygtk
opkg install python-modules

I struggled to get QT installed in such a way that GNU Radio was happy so I gave up on it. The WX based GUI is more heavily used anyway and is enough to get gnuradio-companion itself working.

Now download and configure the GNU Radio build:

git clone http://git.gnuradio.org/git/gnuradio.git
cd gnuradio
mkdir build
cd build
cmake ../

After the cmake command you should see a list of features enabled and disabled, so if you want any of the disabled features take action now.

The build process for GNU Radio will take a good long time on the BBB. It could be cross compiled but I found it easier to ensure all the dependencies were present and working by building on the device. It also uses a lot of memory at certain points so you will need a swap. You can add a swap partition if you like, but I just made a swap file on the SD card for the duration of the build. If your SD card is on the small side, plug in a USB stick and use it as a swap partition. To make a swap file:

fallocate -l 2048M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

Build, and waaaiiit:

make

When it is finished install:

sudo make install

To correctly set $PYTHONPATH, create the file /etc/profile.d/gnuradio-pythonpath.sh containing:

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Now install gr-osmosdr to get nice multi-purpose source and sink blocks for the HackRF in GNU Radio:

git clone git://git.osmocom.org/gr-osmosdr
cd gr-osmosdr
mkdir buikd
cd build
cmake ../
make
sudo make install
sudo su -
ldconfig

You should now be able to plug in your HackRF and use it with GNU Radio on your BeagleBone Black!

Note as well that if you don’t have a monitor around but need gnuradio-companion, you can use x11vnc as installed by default. It only seems to work as root with the default configuration and operates in a not-very-secure manner, so only do this on a private internal network.