Dev/Embedded/FromScratch/LinuxKernel

From Embeded Linux (and more) Wiki by Nathael
Revision as of 15:57, 9 December 2024 by Drizzt (talk | contribs) (Created page with "== Introduction == For the Linux kernel, you usually have two (sometimes three) choices : * Get the official "vanilla" kernel from kernel.org * Get the custom kernel provided by the board manufacturer * Get a custom kernel from a community project when there's one available. I try to use official kernels as much as possible, but sometimes you are stuck to a custom kernel (most of the time outdated).<br /> If you have some time available, then you can try to port the patc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

For the Linux kernel, you usually have two (sometimes three) choices :

  • Get the official "vanilla" kernel from kernel.org
  • Get the custom kernel provided by the board manufacturer
  • Get a custom kernel from a community project when there's one available.

I try to use official kernels as much as possible, but sometimes you are stuck to a custom kernel (most of the time outdated).
If you have some time available, then you can try to port the patches from the custom kernel to the official one and have them included in the upstream official kernel, which will always be greatly appreciated, though the hardest part of this is not the technical part (effective porting of the patches) but getting them accepted upstream.

Grab the sources

When getting the source from kernel.org you can use either git, or download an archive from kernel.org (which will lack git history but be smaller, both for download and for disk space)

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

Configure

It's usually a god idea to build the Linux kernel in a separate Build directory in order to keep the sources clean and allow you to run multiple builds using a single source tree, saving disk space and making it easier to spot what got compiled.

Let's suppose you have your sources in the "linux" directory then to setup the Build environment you should run the following commands (set the arch variable to the right value for your hardware) :

mkdir -p Build/linux
cd linux
arch=
make ARCH=${arch} -j8 O=../Build/linux/ allnoconfig

Note that "allnoconfig" can be replaced by "alldefconfig".

You now have a kernel "Build" directory, and should run all further commands from this build directory in order to keep the sources clean.

the .config file

the device tree

Compile

From the Build directory created in the configure step :

make ARCH=arm -j8 CROSS_COMPILE=arm-linux-gnueabihf-
make ARCH=arm -j8  ROSS_COMPILE=arm-linux-gnueabihf- dtbs
make ARCH=arm -j8 CROSS_COMPILE=arm-linux-gnueabihf- modules_install INSTALL_MOD_PATH=../results/

Use

Linux Kernel

Compilation result is in arch/arm/boot/Image

Device tree

Use the sun8i-h2-plus-orangepi-zero.dtb device-tree (found in arch/arm/boot/dts/) or sun8i-h2-plus-orangepi-zero-ed3l.dtb from my shared ressources.

Modules

If the compilation has been performed using the above command lines you should have a directory "Build/Mods/lib/modules/***" (*** = name of the kernel you just compiled)
You must copy the whole directory (not only the content) on the SD card, in the partition holding the root filesystem (rootfs), in the /lib/modules/ directory without changing the name.