Since the performance is really bad under Docker, let's configure our mac so we can build the firmware directly on it.
Spoiler alert: Goes from 8 minutes to 8 seconds compilation time 🕺
The Docker build will leave pre-compilation steps files (*.a
, *.d
, *.o
) that we don't need.
Clean everything before moving from the Docker procedure to the native one.
find . -name "*.d" -type f -delete
find . -name "*.o" -type f -delete
find . -name "*.a" -type f -delete
rm -rf build/*
Download the arm-none-eabi-xxx
compilers and likers from the official website (https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm) and extract the files into your home directory.
Ensure you have the correct binary files in your directory:
ls /path/to/your/arm-none.macos64_1.17.0/tools/compiler/bin
# should return a list with...
# arm-none-eabi-cpp
# arm-none-eabi-c++
# arm-none-eabi-g++
# arm-none-eabi-objcopy
# ...
Then, add the ARM binary files path to your system (temporary, for the current shell only):
PATH=$PATH:/path/to/your/arm-none.macos64_1.17.0/tools/compiler/bin
Homebrew must be installed on your machine, obviously.
brew install cmake
brew install ccache
brew install dfu-util
Under macOS, Python 2.7 will be linked to the /usr/bin/python
instead of the 3.x version (if you have both).
Because the /usr/bin/python
is protected, even the sudo rm
won't work, neither the chattr
or chflags
.
Quick fix is to modify the Hackrf's firmware script that uses the Python 3 version in those files:
hackrf/firmware/libopencm3/scripts/irq2nvic_h
firmware/tools/extract_cpld_data.py
firmware/tools/make_spi_image.py
/hackrf/firmware/hackrf-common.cmake
(line220
)
Replace
#!/usr/bin/env python
With
#!/usr/bin/env python3
Hey 👋 Don't commit those files, we'll keep the changes on your laptop only.
Finally, if not already installed on your machine, run
pip3 install pyyaml
cd build
cmake ..
make firmware
This might take the same time as with the Docker procedure, don't panick.
In the build
directory:
make firmware
You should see a real difference here 🚀
Put your HackRF into USB mode, and then, from the build
directory:
hackrf_spiflash -w firmware/portapack-h1_h2-mayhem.bin
Since I tend to build, flash and test each firmware iteration very often (now I can compile it in less than 10 seconds and that there isn't any time left for coffee breaks), the best way to save time is to integrate the Portapack build and flash operations into Visual Studio Code by adding a keyboard shortcut to it.
- Open Run Build Tasks (⌘ + Shift + P)
- Paste the following JSON configuration file (will be saved as
.vscode/tasks.json
)
{
"version": "2.0.0",
"tasks": [
{
"label": "HackRF Portapack Mayhem firmware build & flash",
"type": "shell",
"command": "cd build && make firmware && hackrf_spiflash -w firmware/portapack-h1_h2-mayhem.bin",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- Set it as default task if it's not already the case
- Test it using the build task shortcut! (⌘ + Shift + B)
Now, each time you want to run your freshly written code, you don't need to switch window to the terminal, run the build, then flash the firmware... Just use the build shortcut 🤸♂️
Note: Remember to put your HackRF/Portapack into USB mode before running the command, otherwise the hackrf_spiflash
command will obviously fail...