Introduction
In this article, we will learn how to compile radare2 for armhf
using Buildroot’s toolchain (note that this can be adapted to any other cross-toolchain you have, either you got it from your package manager, or with Crosstool-NG).
I assume you are familiar with Buildroot and already know how to use it to build a Linux system.
Steps
First, clone the radare2
repo:
1
$ git clone https://github.com/radareorg/radare2
Then, build a toolchain using Buildroot:
1
2
3
4
5
# assuming Buildroot is ready in its dedicated folder
$ cd ~/buildroot
$ make qemu_arm_vexpress_defconfig
$ make menuconfig
$ make toolchain
This will give you a full cross-toolchain in buildroot/output/host/
.
The sysroot will be in buildroot/output/host/arm-buildroot-linux-gnueabi*/sysroot
.
Next, create an overlay, i.e. a folder that will receive additional files that Buildroot will copy to its rootfs at the end of the build so that they are available to the target system.
1
$ mkdir ~/buildroot/overlay
Now, configure radare2 to use Buildroot’s cross-compiler, and to output it to our overlay:
1
2
3
4
5
6
7
$ cd ~/radare2
$ CC=$HOME/buildroot/output/host/bin/arm-buildroot-linux-gnueabihf-gcc \
CFLAGS=-I$HOME/output/host/include LDFLAGS=-L$HOME/buildroot/output/host/lib \
./configure --prefix=$HOME/buildroot/overlay/usr/local/r2 \
--target=armhf-buildroot-linux --host=armhf-buildroot-linux
$ make -j 8
$ make install
Since we installed r2 to /usr/local/r2
, its binaries and libs won’t be found be default, so we need to edit LD_LIBRARY_PATH
and PATH
of our new system.
First, we can alter the PATH
by setting the BR2_SYSTEM_DEFAULT_PATH
to include our r2 folder.
As for LD_LIBRARY_PATH
, we can set it by creating /etc/profile
:
1
2
3
$ cd ~/buildroot/overlay
$ mkdir etc
$ cat "export LD_LIBRARY_PATH=/usr/local/r2/lib:$LD_LIBRARY_PATH" >> overlay/etc/profile
You can now build your rootfs with Buildroot, and do not forget to add the overlay to your build by settings BR2_ROOTFS_OVERLAY
to $HOME/buildroot/overlay
.
Then build:
1
2
3
4
$ cd ~/buildroot
$ make menuconfig
# set BR2_ROOTFS_OVERLAY and BR2_SYSTEM_DEFAULT_PATH, save and exit
$ make
Conclusion
Now your system has radare2 installed!
1
2
3
4
5
Welcome to Buildroot
buildroot login:
$ r2
Usage: r2 [-ACdfjLMnNqStuvwzX] [-P patch] [-p prj] [-a arch] [-b bits] [-c cmd]
[-s addr] [-B baddr] [-m maddr] [-i script] [-e k=v] file|pid|-|--|=