Introduction️

Having access to a device with a GNU/Linux operating system and MIPS architecture as a router or embedded system will require generating executable binary files using tools such as the complete busybox suite or the tcpdump tool to intercept network packets. These systems often lack these tools or include them with reduced features. To do this, it is necessary to install a cross-compiler and the source code of the application, which depending on the versions used, can result in errors.️

Buildroot is a tool that with a simple interface allows us to select the options and tools to compile through a graphical interface and then generate binary files. Buildroot takes care of all the process.️

Installation️

To install Buildroot, we download its latest version and extract it.️

$ wget https://www.buildroot.org/downloads/buildroot-2024.02.6.tar.gz
$ tar xvzf buildroot-2024.02.6.tar.gz
$ cd buildroot-2024.02.6

Configuration️

To invoke its graphical interface and perform the configuration, we use the tool make. If it is not installed, it will be necessary to install the package build-essential in the case of a GNU/Linux system based on Debian.️

$ make menuconfig

We will see the Buildroot 2024.02.6 Configuration settings. First, we will enter the Target options menu. In Target Architecture, we will select MIPS (big endian) or MIPS (little endian). To know which option to choose, we can use the file command on a binary extracted from the system.️

$ file busybox    
busybox: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, no section header

We observe that it is a 32-bit binary, so it’s MIPS instead of MIPS64. It is MSB, so we select big endian. If it were LSB, we would select little endian. We also notice that it is dynamically linked and its interpreter library is /lib/ld-uClibc.so.0. After selecting MIPS (little endian), we return to the main menu.️

Entering the Toolchain menu. By default, the C library option is set to glibc. We previously observed that the interpreter library was uClibc, so we change it to the uClibc-ng option. We return to the main menu and enter Build options. Since the uClibc-ng library used for compiling the binary is different from the one contained in the binary, we change the binary to be statically linked only in the libraries option to static only.️

Returning to the main menu, we can select the tools to generate in the Target packages menu. Busybox is generated by default. We find Tcpdump in the Networking applications > tcpdump (NEW) menu.️

Compilation️

We can finally generate the configuration file .config by selecting the option Save. We can now start the build process with the command make.️

$ make -j16

After a few minutes, the file system with binaries is generated in the subdirectory output/target/bin.️

$ file output/target/bin/busybox 
output/target/bin/busybox: ELF 32-bit MSB executable, MIPS, MIPS32 version 1 (SYSV), statically linked, stripped

Conclusion️

With the use of Buildroot and after a simple configuration, it is possible to generate binary files for any supported architecture, in case an embedded system’s operating system does not include specific tools.️