Building the Linux
Kernel
Advanced Embedded Software
Development
with Dan Walkes
Learning objectives:
Introduction to KConfig
Kernel defconfig
Building the kernel
QEMU Example Kernel Build
(assignment 3)
KConfig
● Text format which controls kernel
configuration
● drivers/char/Kconfig example
Mastering Embedded Linux Programming Chapter 4 3
Menuconfig
● Terminal based
graphical tool to
modify kernel
configuration using
KConfig files
● Invoke with “make
menuconfig”
Mastering Embedded Linux Programming Chapter 4 4
KConfig
● Changes are stored
in a .config file at
kernel source root
Mastering Embedded Linux Programming Chapter 4 5
KConfig Options
● Kconfig/menuconfig allows you to specify 3
modes for most drivers
○ off
■ Not built/included
○ on
■ built in to the kernel
○ Module
■ loadable at runtime
6
Kernel Defconfigs
● Files which setup your .config file to use a
set of configurations known to work for a
specific hardware platform.
● Typically provided by hardware
manufacturers (target development board)
● You can use these as the basis for your
kernel .config
Mastering Embedded Linux Programming Chapter 4 7
https://wiki.qemu.org/Documentation/Platforms/ARM
Kernel Defconfigs
● What do we use for QEMU?
○ Assignment 3 uses QEMU virt
○ Can use defconfig with no
arguments to generate
● See more options at
https://github.com/torvalds/linux/tree/master/arch/arm/configs
Mastering Embedded Linux Programming Chapter 4 8
https://wiki.qemu.org/Documentation/Platforms/ARM
Compiling with Kbuild
● Example from drivers/char/Makefile
● obj-y = “built in”
● obj-m = “Module”
● needs mem.o and random.o built into the
kernel (-y)
● ttyprintk may be included into the kernel or
as a module based on
CONFIG_TTY_PRINTK
Mastering Embedded Linux Programming Chapter 4 9
https://github.com/torvalds/linux/blob/v5.3-rc8/drivers/char/Makefile
Build Artifacts
● vmlinux
○ ELF binary - possibly with debugging
symbols
Mastering Embedded Linux Programming Chapter 4 10
Build Artifacts
● Binaries in arch/$ARCH/boot for use with
bootloaders
○ Image - binary version of vmlinux
○ zImage - compressed Image
○ uImage - compressed image with
U-Boot header
Mastering Embedded Linux Programming Chapter 4 11
Assignment 3 QEMU build - clean
● make ARCH=arm64
CROSS_COMPILE=aarch64-none-linux-gnu-
mrproper
○ “deep clean” the kernel build tree -
removing the .config file with any existing
configurations
Mastering Embedded Linux Programming Chapter 4 12
Assignment 3 QEMU build -
defconfig
● make ARCH=arm64
CROSS_COMPILE=aarch64-none-linux-gnu-
defconfig
○ Configure for our “virt” arm dev board we
will simulate in QEMU
Mastering Embedded Linux Programming Chapter 4 13
Assignment 3 QEMU build -
vmlinux
● make -j4 ARCH=arm64
CROSS_COMPILE=aarch64-none-linux-gnu-
all
○ Build a kernel image for booting with
QEMU
Mastering Embedded Linux Programming Chapter 4 14
Assignment 3 QEMU build -
modules and devicetree
● make ARCH=arm64
CROSS_COMPILE=aarch64-none-linux-gnu-
modules
○ Build any kernel modules
● make ARCH=arm64
CROSS_COMPILE=aarch64-none-linux-gnu- dtbs
○ Build the devicetree
Mastering Embedded Linux Programming Chapter 4 15