DEV Community

Miguel Jimenez Lopez
Miguel Jimenez Lopez

Posted on

Compiling Raspberry Pi firmware with Docker

Firmware compilation is a very common process in the embedded systems. Under this context, there are some tools such as Buildroot and Yocto that can ease this task. However, there are situations that require some specific versions of some libraries and packages that can provoke some conflicts with the rest of applications in the development station. To avoid this, some virtualization mechanisms as Docker can be used to isolate the compilation process inside a single container. In this post, we explain a method to compile the Raspberry Pi firmware using Buildroot and Docker. The first step is to install Docker in the workstation. This can be slightly different depending on the operating system but for Debian-like distributions can be performed as follows:

user@workstation $> apt-get install docker docker.io docker-compose
user@workstation $> groupadd docker
user@workstation $> usermod -aG docker user

Once Docker has been installed, the next step is to create a specific container for the compilation process (together with a shared folder between the host and the container):

user@workstation $> cd ~
user@workstation $> mkdir docker-shared
user@workstation $> docker run -it --name compilation_rpi -v ~/docker-shared:/mnt ubuntu:18.04

When the previous commands finish, a new session inside the container should be initialized:

root@9f9b62ea1496:/#

Before compiling Buildroot, some libraries and packages must be installed inside the container:

root@9f9b62ea1496:/# apt-get update
root@9f9b62ea1496:/# apt-get install -y git vim make gcc autoconf \
  texinfo file g++ unzip bison flex m4 build-essential gettext \  
  libncursesw5 libncursesw5-dev fakeroot wget rename cpio \
  python rsync bc device-tree-compiler u-boot-tools \
  libssl-dev libtool

The next step consists on downloading Buildroot:

root@9f9b62ea1496:/# cd /mnt
root@9f9b62ea1496:/# mkdir rpi-compilation
root@9f9b62ea1496:/# cd rpi-compilation
root@9f9b62ea1496:/# wget https://buildroot.org/downloads/buildroot-2020.02.7.tar.gz
root@9f9b62ea1496:/# tar xvf buildroot-2020.02.7.tar.gz 

Finally, move to the Buildroot folder, configure it for the Raspberry and compile it using make command:

root@9f9b62ea1496:/# cd /mnt/rpi-compilation/buildroot-2020.02.7
root@9f9b62ea1496:/# make raspberrypi3_64_defconfig
root@9f9b62ea1496:/# export FORCE_UNSAFE_CONFIGURE=1
root@9f9b62ea1496:/# make

Thanks for reading!! =)

Notes

  • The firmware images can be found in /mnt/rpi-compilation/buildroot-2020.02.7/output/images or in ~/docker-shared/rpi-compilation/buildroot-2020.02.7/output/images
  • FORCE_UNSAFE_CONFIGURE=1 is required to avoid errors trying to compile Buildroot as root
  • To exit from docker container, just run exit command.
  • To initialize the docker container again, run the following commands:
    user@workstation $> docker start compilation_rpi
    user@workstation $> docker exec -it compilation_rpi bash
    

Top comments (0)