Setting up docker, for compiling embedded Firmware

What we will cover

  • Why?
  • Install docker
  • Create container for our buildchain

Why?

  • Docker container for full toolchain, faster to use and maintain then to “install” full toolchain.
  • More then one developer, everyone has the same toolset
  • Reproducable offer different system
  • Can be used for automated builds
  • Different toolset versions, system can be used.

Installing docker

Basically i just followed the guide. At the moment of writing you had to be in the insider Preview to get WSL2 (windows subsystem for linux).
But to summarize the blog entry of Matt Hernandez.

If installing docker was a success you can execute from a terminal window directly a docker container.

docker run hello-world

Getting used to docker on windows

For the first tests and “playing” with docker, we will install the official gcc container.

docker search --filter "is-official=true" gcc 
docker pull gcc

To ensure it works and check that the container was pulled and work we will open up a terminal and create a new file “main.c” which is a very simple helloworld c program.

#include <stdio.h>

int main()
{
 printf("Hello Docker!");
}

And now we can “compile” and test our program.
For this you need to map the folder containing your main.c to one folder of the docker system. In my case it’s f:\test . What i found out if you execute docker from the windows context, you will not have the “wsl” file system available and you need to map directly a windows folder.

docker run --rm -v f:\test\:/usr/test -w /usr/test gcc gcc -o hello main.c
docker run --rm -v f:\test\:/usr/test -w /usr/test gcc ./hello

This will “run” the container “gcc” with mapping the folder f:\test\ to /usr/test. It will set the workpath to /usrc/test.
Also using –rm will cleanup the container automatically after executing.
The first command will compile our “hello” executable from the main.c. If it was succesfull the second one will run it and you will see “Hello Docker”

Now you could e.g. execute a makefile or cmake inside the container and a whole build to the “linux target” system would be completed.

Making our own image and get the Project started

To prepare our project, we will generate a Dockerfile, which describes what is available on the container, to allow an easy execution of our compile Process. My file will be based on the gcc image, as it contains allreade the build essential files and few other. We will download the 2020q2 release of the arm-none-eabi. The image will run “cmake” if it is executed without any arguments.

FROM gcc:10.1.0
LABEL Description="Image for building and debugging arm-embedded projects"
WORKDIR /work

ADD . /work

# Install any needed packages specified in requirements.txt
RUN apt-get update &amp;&amp; \
  apt-get upgrade -y &amp;&amp; \
  apt-get install -y \
  # Development files
  build-essential \
  cmake \
  ninja-build \
  git \
  bzip2 \
  wget &amp;&amp; \
  apt-get clean
#Tools dir
WORKDIR /home/dev
#Download arm-none-eabi-gcc pipe it to tar for running
RUN wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2 | tar -xj

ENV PATH "/home/dev/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH"
WORKDIR /usr/target

Now we can build this file, create our image and tag it.
The tag should be “yourdockeriousername/somethingwhichmakessense”

docker build -t="tobiwan88/gcc-arm-make:1.0" ./

And if it works we can execute our image

docker run –rm tobiwan88/gcc-arm-make:1.0

And now we can make a testbuild to check if in general our docker container is able to build files. I will re use my previous github project, but all you need is a project with a CMake File and a toolchain file for the installed toolchain (here it arm-none-eabi gcc).

docker run --rm -v f:\embedded\embedded_spectogram\Firmware:/usr/projects -w /usr/projects/remotebuild tobiwan88/gcc-arm-make:1.0 cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="../arm-none-eabi-gcc.cmake" -DCMAKE_BUILD_TYPE=Debug ../
 docker run --rm -v f:\embedded\embedded_spectogram\Firmware:/usr/projects -w /usr/projects/remotebuild tobiwan88/gcc-arm-make:1.0 cmake --build
A test build runs!

Next steps – improvments

The next steps is creating an yaml file, which will allow a full “autonomous” build. This would allow integration into CI like Jenkins and also adding automated unit tests and running the hex file in a simulator. Also left is an integration into visual studio.

Additional Resources and Inspiration

0 thoughts on “Setting up docker, for compiling embedded Firmware

Leave a Reply

Your email address will not be published. Required fields are marked *