Giter VIP home page Giter VIP logo

crosscompile-raspberrypi-kernel-docker's Introduction

Cross-compiling Raspberry Pi Kernel on a Docker Container

An Ubuntu 16.04-based environment for cross-compiling Raspberry Pi kernel.

Why?

Isolation. I need it so bad because I screwed up my host environment.

Pros & Cons

Pros

  • Faster build time, assuming your machine is far more powerful than a Raspberry Pi.

Cons

  • Installing a newly built kernel isn't that simple, especially if you're targetting a Raspberry Pi Compute Module board.

It's a lot simpler if you build the kernel on the Pi itself, but the whole process can take hours to finish.

Starting the Container

Clone the repository

git clone https://github.com/alwint3r/raspberrypi-kernel-crosscompile

Move to the cloned repository, then build the docker image.

docker build -t rpi-cross-compile:latest .

Don't forget to set up a directory to store the compilation result on your host machine. Mount that directory as one of the volumes of the container using /root/raspberrypi as the mount point. For example, I'm going to use the raspberrypi-linux directory in my home directory.

docker run --name rpi-cross-compile-kernel -it \
 -v $HOME/raspberrypi-linux:/root/raspberrypi \
 rpi-cross-compile:latest \
 /bin/bash

A new container named rpi-cross-compile-kernel will be created and a new bash session will be opened.

Getting the Kernel Source Code

You can get the source code by cloning the whole repository at https://github.com/raspberrypi/linux.

git clone https://github.com/raspberrypi/linux

If you prefer to get the source code at a specific branch only, then run the following command:

git clone --depth=1 --branch rpi-4.18.y https://github.com/raspberrypi/linux

In the example above, the branch that we'll get is rpi-4.18.y which means we will get the source code for kernel version 4.18. If you prefer another version, then just change the branch name to match your preferred kernel version.

Building the Kernel

You can follow the guide on the official documentation.

The steps are pretty much the same as the guide on the official documentation.

Here's what I did

  1. Configuring kernel for target, in this case, I'm targetting a Compute Module 3
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
  1. Run menuconfig to configure the kernel, you can skip this step if you think it's not necessary. It is necessary for me because I need to enable a staging driver.
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
  1. Start building the kernel image, modules, and device trees
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage modules dtbs

Yes, you can use j N flagh with N is the number of jobs that will be run at the same time.

  1. As for installing the modules, I need to copy the entire kernel source code to my Raspberry Pi and then run the installation of the modules there. It is a lot easier than copying the pre-installed modules on your container to the Raspberry Pi. Trust me, you don't want to deal with symlinks.

In the Raspberry Pi terminal, inside the linux kernel directory

sudo make install_modules
  1. If you need to compile a driver source code based on the kernel that you just compiled yourself, see this guide. We need to compile the scripts in the Raspberry Pi instead of in our host machine.

crosscompile-raspberrypi-kernel-docker's People

Contributors

alwint3r avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.