Monday 1 September 2014

Part Two: HackRF One - Howto use a Raspberry Pi to upgrade the Firmware on a HackRF One

Update: September 2014. There is now a temporary way to perform a HackRF One firmware upgrade in Windows: using a special modified firmware https://homes.cs.washington.edu/~supersat/hackrf-tools-cpld-update-hack.zip 1. Install ARM firmware, 2. power cycle hackrf, 3. flash CPLD firmware, 4. power cycle hackrf.


Since currently there is no way to upgrade the firmware on a HackRF One from Microsoft Windows, I though these commands may be useful for others, who have a Raspberry Pi and want to update their firmware. These instructions are generic enough that they should work with most other Debian based Linux distributions as well (you may need to type "sudo apt-get install pkg-config" in addition to the commands below).

The RPi is good enough to upgrade the firmware on the HackRF One with no issues, but it would not be easy to use the HackRF One for anything else. It does not have enough CPU power for DSP (no NEON instruction set), it does not have enough USB bandwidth for more than about 6MSPS, and writing IQ data to anywhere but a RAM disk will fail with USB timeouts. It is really not a great platform to use a H1 on. Although with some custom niche software that used the GPU for FFT's it may be possible to just about do something useful, but it would take a lot of work.

Below are the commands I used to upgrade the ARM firmware and CPLD firmware from version git-44df9d1 to 2014.08.1. The RELEASENOTES for this binary firmware, downloaded from sourceforge said that the latest hackrf-tools and libhackrf must be used to install, and that is what I did below:

As usual, I have censored any identifying information about my personal hardware.

pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 1d50:6089 OpenMoko, Inc.
pi@raspberrypi ~ $ mkdir src
pi@raspberrypi ~ $ cd src
pi@raspberrypi ~/src $ git clone https://github.com/mossmann/hackrf.git
Cloning into 'hackrf'...
remote: Counting objects: 9045, done.
remote: Total 9045 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9045/9045), 24.04 MiB | 1.04 MiB/s, done.
Resolving deltas: 100% (6329/6329), done.
pi@raspberrypi ~/src $ cd hackrf/host
pi@raspberrypi ~/src/hackrf/host $ mkdir build
pi@raspberrypi ~/src/hackrf/host $ cd build/
pi@raspberrypi ~/src/hackrf/host/build $ sudo apt-get install cmake
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  cmake-data emacsen-common libxmlrpc-core-c3
The following NEW packages will be installed:
  cmake cmake-data emacsen-common libxmlrpc-core-c3
0 upgraded, 4 newly installed, 0 to remove and 85 not upgraded.
Need to get 5,766 kB of archives.
After this operation, 13.6 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libxmlrpc-core-c3 armhf 1.16.33-3.2 [146 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main emacsen-common all 2.0.5 [20.9 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main cmake-data all 2.8.9-1 [1,359 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main cmake armhf 2.8.9-1 [4,240 kB]
Fetched 5,766 kB in 4s (1,328 kB/s)
Selecting previously unselected package libxmlrpc-core-c3.
(Reading database ... 69052 files and directories currently installed.)
Unpacking libxmlrpc-core-c3 (from .../libxmlrpc-core-c3_1.16.33-3.2_armhf.deb) ...
Selecting previously unselected package emacsen-common.
Unpacking emacsen-common (from .../emacsen-common_2.0.5_all.deb) ...
Selecting previously unselected package cmake-data.
Unpacking cmake-data (from .../cmake-data_2.8.9-1_all.deb) ...
Selecting previously unselected package cmake.
Unpacking cmake (from .../cmake_2.8.9-1_armhf.deb) ...
Processing triggers for man-db ...
Setting up libxmlrpc-core-c3 (1.16.33-3.2) ...
Setting up emacsen-common (2.0.5) ...
Setting up cmake-data (2.8.9-1) ...
Install cmake-data for emacs
Setting up cmake (2.8.9-1) ...
pi@raspberrypi ~/src/hackrf/host/build $ sudo apt-get install libusb-1.0-0-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  libusb-1.0-0-dev
0 upgraded, 1 newly installed, 0 to remove and 85 not upgraded.
Need to get 184 kB of archives.
After this operation, 962 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libusb-1.0-0-dev armhf 2:1.0.11-1 [184 kB]
Fetched 184 kB in 5s (32.3 kB/s)
Selecting previously unselected package libusb-1.0-0-dev.
(Reading database ... 69752 files and directories currently installed.)
Unpacking libusb-1.0-0-dev (from .../libusb-1.0-0-dev_2%3a1.0.11-1_armhf.deb) ...
Setting up libusb-1.0-0-dev (2:1.0.11-1) ...
pi@raspberrypi ~/src/hackrf/host/build $ cmake .. -DINSTALL_UDEV_RULES=ON
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26")
-- checking for module 'libusb-1.0'
--   found libusb-1.0, version 1.0.11
-- Found LIBUSB: /usr/lib/arm-linux-gnueabihf/libusb-1.0.so
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/src/hackrf/host/build
pi@raspberrypi ~/src/hackrf/host/build $ make
Scanning dependencies of target hackrf
[ 11%] Building C object libhackrf/src/CMakeFiles/hackrf.dir/hackrf.c.o
/home/pi/src/hackrf/host/libhackrf/src/hackrf.c: In function ‘hackrf_set_freq_explicit’:
/home/pi/src/hackrf/host/libhackrf/src/hackrf.c:783:2: warning: this decimal constant is unsigned only in ISO C90 [enabled by default]
/home/pi/src/hackrf/host/libhackrf/src/hackrf.c:783:2: warning: this decimal constant is unsigned only in ISO C90 [enabled by default]
Linking C shared library libhackrf.so
[ 11%] Built target hackrf
Scanning dependencies of target hackrf-static
[ 22%] Building C object libhackrf/src/CMakeFiles/hackrf-static.dir/hackrf.c.o
/home/pi/src/hackrf/host/libhackrf/src/hackrf.c: In function ‘hackrf_set_freq_explicit’:
/home/pi/src/hackrf/host/libhackrf/src/hackrf.c:783:2: warning: this decimal constant is unsigned only in ISO C90 [enabled by default]
/home/pi/src/hackrf/host/libhackrf/src/hackrf.c:783:2: warning: this decimal constant is unsigned only in ISO C90 [enabled by default]
Linking C static library libhackrf.a
[ 22%] Built target hackrf-static
Scanning dependencies of target hackrf_cpldjtag
[ 33%] Building C object hackrf-tools/src/CMakeFiles/hackrf_cpldjtag.dir/hackrf_cpldjtag.c.o
Linking C executable hackrf_cpldjtag
[ 33%] Built target hackrf_cpldjtag
Scanning dependencies of target hackrf_info
[ 44%] Building C object hackrf-tools/src/CMakeFiles/hackrf_info.dir/hackrf_info.c.o
Linking C executable hackrf_info
[ 44%] Built target hackrf_info
Scanning dependencies of target hackrf_max2837
[ 55%] Building C object hackrf-tools/src/CMakeFiles/hackrf_max2837.dir/hackrf_max2837.c.o
Linking C executable hackrf_max2837
[ 55%] Built target hackrf_max2837
Scanning dependencies of target hackrf_rffc5071
[ 66%] Building C object hackrf-tools/src/CMakeFiles/hackrf_rffc5071.dir/hackrf_rffc5071.c.o
Linking C executable hackrf_rffc5071
[ 66%] Built target hackrf_rffc5071
Scanning dependencies of target hackrf_si5351c
[ 77%] Building C object hackrf-tools/src/CMakeFiles/hackrf_si5351c.dir/hackrf_si5351c.c.o
Linking C executable hackrf_si5351c
[ 77%] Built target hackrf_si5351c
Scanning dependencies of target hackrf_spiflash
[ 88%] Building C object hackrf-tools/src/CMakeFiles/hackrf_spiflash.dir/hackrf_spiflash.c.o
Linking C executable hackrf_spiflash
[ 88%] Built target hackrf_spiflash
Scanning dependencies of target hackrf_transfer
[100%] Building C object hackrf-tools/src/CMakeFiles/hackrf_transfer.dir/hackrf_transfer.c.o
Linking C executable hackrf_transfer
[100%] Built target hackrf_transfer
pi@raspberrypi ~/src/hackrf/host/build $ sudo make install
[ 11%] Built target hackrf
[ 22%] Built target hackrf-static
[ 33%] Built target hackrf_cpldjtag
[ 44%] Built target hackrf_info
[ 55%] Built target hackrf_max2837
[ 66%] Built target hackrf_rffc5071
[ 77%] Built target hackrf_si5351c
[ 88%] Built target hackrf_spiflash
[100%] Built target hackrf_transfer
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib/pkgconfig/libhackrf.pc
-- Installing: /etc/udev/rules.d/53-hackrf.rules
-- Installing: /usr/local/lib/libhackrf.so.0.3.0
-- Installing: /usr/local/lib/libhackrf.so.0
-- Installing: /usr/local/lib/libhackrf.so
-- Installing: /usr/local/lib/libhackrf.a
-- Installing: /usr/local/include/libhackrf/hackrf.h
-- Installing: /usr/local/bin/hackrf_max2837
-- Removed runtime path from "/usr/local/bin/hackrf_max2837"
-- Installing: /usr/local/bin/hackrf_si5351c
-- Removed runtime path from "/usr/local/bin/hackrf_si5351c"
-- Installing: /usr/local/bin/hackrf_transfer
-- Removed runtime path from "/usr/local/bin/hackrf_transfer"
-- Installing: /usr/local/bin/hackrf_rffc5071
-- Removed runtime path from "/usr/local/bin/hackrf_rffc5071"
-- Installing: /usr/local/bin/hackrf_spiflash
-- Removed runtime path from "/usr/local/bin/hackrf_spiflash"
-- Installing: /usr/local/bin/hackrf_cpldjtag
-- Removed runtime path from "/usr/local/bin/hackrf_cpldjtag"
-- Installing: /usr/local/bin/hackrf_info
-- Removed runtime path from "/usr/local/bin/hackrf_info"
pi@raspberrypi ~/src/hackrf/host/build $ sudo ldconfig
pi@raspberrypi ~/src/hackrf/host/build $ sudo udevadm control --reload-rules
pi@raspberrypi ~/src/hackrf/host/build $ hackrf_info
hackrf_open() failed: HACKRF_ERROR_NOT_FOUND (-5)
(I pressed the blue reset button on the hackrf)
pi@raspberrypi ~/src/hackrf/host/build $ hackrf_info
Found HackRF board.
Board ID Number: 2 (HackRF One)
Firmware Version: git-44df9d1
Part ID Number: 0xa000cb3c 0x00724f45
Serial Number: 0x00000000 0x00000000
0x         0x        

pi@raspberrypi ~/src/hackrf/host/build $ cd
pi@raspberrypi ~ $ mkdir firmware
pi@raspberrypi ~ $ cd firmware
pi@raspberrypi ~/firmware $ wget http://sourceforge.net/projects/hackrf/files/hackrf-2014.08.1.tar.xz/download
--2014-09-01 22:05:58--  http://sourceforge.net/projects/hackrf/files/hackrf-2014.08.1.tar.xz/download
Resolving sourceforge.net (sourceforge.net)... 216.34.181.60
Connecting to sourceforge.net (sourceforge.net)|216.34.181.60|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://downloads.sourceforge.net/project/hackrf/hackrf-2014.08.1.tar.xz?r=&ts=1409605559&use_mirror=cznic [following]
--2014-09-01 22:05:59--  http://downloads.sourceforge.net/project/hackrf/hackrf-2014.08.1.tar.xz?r=&ts=1409605559&use_mirror=cznic
Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://cznic.dl.sourceforge.net/project/hackrf/hackrf-2014.08.1.tar.xz [following]
--2014-09-01 22:05:59--  http://cznic.dl.sourceforge.net/project/hackrf/hackrf-2014.08.1.tar.xz
Resolving cznic.dl.sourceforge.net (cznic.dl.sourceforge.net)... 217.31.202.30, 2001:1488:ffff::30
Connecting to cznic.dl.sourceforge.net (cznic.dl.sourceforge.net)|217.31.202.30|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 14376904 (14M) [application/octet-stream]
Saving to: `download'

100%[=====================================================================================================================================================================>] 14,376,904  2.64M/s   in 7.0s

2014-09-01 22:06:07 (1.96 MB/s) - `download' saved [14376904/14376904]

pi@raspberrypi ~/firmware $ mv download hackrf-2014.08.1.tar.xz
pi@raspberrypi ~/firmware $ unxz hackrf-2014.08.1.tar.xz
pi@raspberrypi ~/firmware $ tar xf hackrf-2014.08.1.tar
pi@raspberrypi ~/firmware $ cd hackrf-2014.08.1/firmware-bin

(The next command will flash the firmware on the HackRF One, it would be good idea to make sure that it does not loose power)
pi@raspberrypi ~/firmware/hackrf-2014.08.1/firmware-bin $ hackrf_spiflash -w hackrf_one_usb_rom_to_ram.bin
File size 20292 bytes.
Erasing SPI flash.
Writing 256 bytes at 0x000000.
Writing 256 bytes at 0x000100.
Writing 256 bytes at 0x000200.
Writing 256 bytes at 0x000300.
Writing 256 bytes at 0x000400.
Writing 256 bytes at 0x000500.
Writing 256 bytes at 0x000600.
Writing 256 bytes at 0x000700.
Writing 256 bytes at 0x000800.
Writing 256 bytes at 0x000900.
Writing 256 bytes at 0x000a00.
Writing 256 bytes at 0x000b00.
Writing 256 bytes at 0x000c00.
Writing 256 bytes at 0x000d00.
Writing 256 bytes at 0x000e00.
Writing 256 bytes at 0x000f00.
Writing 256 bytes at 0x001000.
Writing 256 bytes at 0x001100.
Writing 256 bytes at 0x001200.
Writing 256 bytes at 0x001300.
Writing 256 bytes at 0x001400.
Writing 256 bytes at 0x001500.
Writing 256 bytes at 0x001600.
Writing 256 bytes at 0x001700.
Writing 256 bytes at 0x001800.
Writing 256 bytes at 0x001900.
Writing 256 bytes at 0x001a00.
Writing 256 bytes at 0x001b00.
Writing 256 bytes at 0x001c00.
Writing 256 bytes at 0x001d00.
Writing 256 bytes at 0x001e00.
Writing 256 bytes at 0x001f00.
Writing 256 bytes at 0x002000.
Writing 256 bytes at 0x002100.
Writing 256 bytes at 0x002200.
Writing 256 bytes at 0x002300.
Writing 256 bytes at 0x002400.
Writing 256 bytes at 0x002500.
Writing 256 bytes at 0x002600.
Writing 256 bytes at 0x002700.
Writing 256 bytes at 0x002800.
Writing 256 bytes at 0x002900.
Writing 256 bytes at 0x002a00.
Writing 256 bytes at 0x002b00.
Writing 256 bytes at 0x002c00.
Writing 256 bytes at 0x002d00.
Writing 256 bytes at 0x002e00.
Writing 256 bytes at 0x002f00.
Writing 256 bytes at 0x003000.
Writing 256 bytes at 0x003100.
Writing 256 bytes at 0x003200.
Writing 256 bytes at 0x003300.
Writing 256 bytes at 0x003400.
Writing 256 bytes at 0x003500.
Writing 256 bytes at 0x003600.
Writing 256 bytes at 0x003700.
Writing 256 bytes at 0x003800.
Writing 256 bytes at 0x003900.
Writing 256 bytes at 0x003a00.
Writing 256 bytes at 0x003b00.
Writing 256 bytes at 0x003c00.
Writing 256 bytes at 0x003d00.
Writing 256 bytes at 0x003e00.
Writing 256 bytes at 0x003f00.
Writing 256 bytes at 0x004000.
Writing 256 bytes at 0x004100.
Writing 256 bytes at 0x004200.
Writing 256 bytes at 0x004300.
Writing 256 bytes at 0x004400.
Writing 256 bytes at 0x004500.
Writing 256 bytes at 0x004600.
Writing 256 bytes at 0x004700.
Writing 256 bytes at 0x004800.
Writing 256 bytes at 0x004900.
Writing 256 bytes at 0x004a00.
Writing 256 bytes at 0x004b00.
Writing 256 bytes at 0x004c00.
Writing 256 bytes at 0x004d00.
Writing 256 bytes at 0x004e00.
Writing 68 bytes at 0x004f00.

(The next command flashs the CPLD in the HackRF One, it would be a good idea to make sure that it does not loose power) 
pi@raspberrypi ~/firmware/hackrf-2014.08.1/firmware-bin $ hackrf_cpldjtag -x hackrf_cpld_default.xsvf
File size 37629 bytes.
LED1/2/3 blinking means CPLD program success.
LED3/RED steady means error.

Wait message 'Write finished' or in case of LED3/RED steady, Power OFF/Disconnect the HackRF.
Write finished.
Please Power OFF/Disconnect the HackRF.
pi@raspberrypi ~/firmware/hackrf-2014.08.1/firmware-bin $
(LED1/2/3 are the three LED's starting at the antenna)
pi@raspberrypi ~/firmware/hackrf-2014.08.1/firmware-bin $ hackrf_info
Found HackRF board.
Board ID Number: 2 (HackRF One)
Firmware Version: 2014.08.1
Part ID Number: 0xa000cb3c 0x00724f45
Serial Number: 0x00000000 0x00000000 0x         0x       
pi@raspberrypi ~/firmware/hackrf-2014.08.1/firmware-bin $