LINUX
LINUX
LINUX
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 1/517
Rights to copy
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 2/517
Hyperlinks in the document
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 3/517
Company at a glance
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 4/517
Bootlin on-line resources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 5/517
Generic course information
Generic course
information
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 6/517
Hardware used in this training session
Using Microchip (formerly Atmel) SAMA5D3 Xplained boards in
all practical labs
▶ SAMA5D36 (Cortex A5) CPU from
Microchip
▶ 256 MB DDR2 RAM, 256 MB NAND
flash
▶ 2 Ethernet ports (Gigabit + 100 Mbit)
▶ 2 USB 2.0 host, 1 USB device
▶ 1 MMC/SD slot
▶ 3.3 V serial port (like Beaglebone Black)
▶ Misc: Arduino R3-compatible header,
JTAG, buttons, LEDs
▶ Currently sold at 102 EUR by Mouser
(V.A.T. not included)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 8/517
Participate!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 9/517
Practical lab guidelines
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 10/517
Advise: write down your commands!
During practical labs, write down all your commands in a text file.
▶ You can save a lot of time re-using
commands in later labs.
▶ This helps to replay your work if Lab commands
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 11/517
Cooperate!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 12/517
Command memento sheet
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 14/517
Introduction to Embedded Linux
Introduction to
Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 15/517
Birth of free software
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 16/517
Free software?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 17/517
What is embedded Linux?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 18/517
Introduction to Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 19/517
Re-using components
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 20/517
Low cost
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 21/517
Full control
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 22/517
Quality
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 23/517
Eases testing of new features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 24/517
Community support
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 25/517
Taking part into the community
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 26/517
Introduction to Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 27/517
Wireless routers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 28/517
Video systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 29/517
Bike computers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 32/517
Introduction to Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 33/517
Processor and architecture (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 34/517
Processor and architecture (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 35/517
RAM and storage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 36/517
Communication
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 37/517
Types of hardware platforms
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 38/517
Criteria for choosing the hardware
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 39/517
Introduction to Embedded Linux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 40/517
Global architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 41/517
Software components
▶ Cross-compilation toolchain
▶ Compiler that runs on the development machine, but generates
code for the target
▶ Bootloader
▶ Started by the hardware, responsible for basic initialization,
loading and executing the kernel
▶ Linux Kernel
▶ Contains the process and memory management, network stack,
device drivers and provides services to user space applications
▶ C library
▶ The interface between the kernel and the user space
applications
▶ Libraries and applications
▶ Third-party or in-house
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 42/517
Embedded Linux work
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 43/517
Embedded Linux development environment
Embedded Linux
development
environment
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 44/517
Embedded Linux solutions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 45/517
OS for Linux development
:-)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 46/517
Desktop Linux distribution
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 47/517
Linux root and non-root users
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 48/517
Software packages
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 49/517
Managing software packages (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 50/517
Managing software packages (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 52/517
Serial line communication program
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 53/517
Command line tips
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 54/517
Practical lab - Training Setup
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 55/517
Cross-compiling toolchains
Cross-compiling
toolchains
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 56/517
Cross-compiling toolchains
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 57/517
Definition (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 58/517
Definition (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 59/517
Machines in build procedures
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 60/517
Different toolchain build procedures
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 61/517
Components
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 62/517
Binutils
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 63/517
Kernel headers (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 64/517
Kernel headers (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 65/517
Kernel headers (3)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 66/517
C/C++ compiler
tio
nc lls
n
ca
BusyBox
C API to ease application Linux
memory
manager
calls
et al.
Virtual system
development
IPC
file
manager
system Linux
process
scheduler
system
calls
fu
nc
ca tion
lls
C Libraries
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 69/517
glibc
▶ License: LGPL
▶ C library from the GNU project
▶ Designed for performance, standards
compliance and portability
▶ Found on all GNU / Linux host systems
▶ Of course, actively maintained
▶ By default, quite big for small embedded
systems. On armv7hf, version 2.23: libc:
1.5 MB, libm: 492 KB, source:
https://toolchains.bootlin.com
▶ But some features not needed in
embedded systems can be configured out
(merged from the old eglibc project).
▶ http://www.gnu.org/software/libc/ Image: https://bit.ly/2EzHl6m
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 70/517
uClibc-ng
▶ http://uclibc-ng.org/
▶ A continuation of the old uClibc project, license: LGPL
▶ Lightweight C library for small embedded systems
▶ High configurability: many features can be enabled or disabled
through a menuconfig interface.
▶ Supports most embedded architectures, including MMU-less
ones (ARM Cortex-M, Blackfin, etc.). The only library
supporting ARM noMMU.
▶ No guaranteed binary compatibility. May need to recompile
applications when the library configuration changes.
▶ Some glibc features may not be implemented yet (real-time,
floating-point operations...)
▶ Focus on size rather than performance
▶ Size on armv7hf, version 1.0.24: libc: 652 KB, , source:
https://toolchains.bootlin.com
▶ Actively supported, but Yocto Project stopped supporting it.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 71/517
musl C library
http://www.musl-libc.org/
▶ A lightweight, fast and simple library for embedded
systems
▶ Created while uClibc’s development was stalled
▶ In particular, great at making small static
executables
▶ Permissive license (MIT)
▶ Supported by build systems such as Buildroot and
Yocto Project.
▶ Used by the Alpine Linux distribution
(https://www.alpinelinux.org/), fitting in about
130 MB of storage.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 72/517
glibc vs uclibc-ng vs musl - small static executables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 73/517
Other smaller C libraries
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 74/517
Cross-compiling toolchains
Toolchain Options
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 75/517
ABI
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 76/517
Floating point support
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 77/517
CPU optimization flags
Obtaining a Toolchain
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 79/517
Building a toolchain manually
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 80/517
Get a pre-compiled toolchain
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 81/517
Toolchain building utilities
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 82/517
Toolchain building utilities (2)
▶ Crosstool-ng
▶ Rewrite of the older Crosstool, with a menuconfig-like
configuration system
▶ Feature-full: supports uClibc, glibc, musl, hard and soft float,
many architectures
▶ Actively maintained
▶ https://crosstool-ng.github.io/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 83/517
Toolchain building utilities (3)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 84/517
Crosstool-NG: installation and usage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 86/517
Practical lab - Using Crosstool-NG
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 87/517
Bootloaders
Bootloaders
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 88/517
Bootloaders
Boot Sequence
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 89/517
Bootloaders
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 90/517
Bootloaders on BIOS-based x86 (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 92/517
Booting on embedded CPUs: case 1
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 93/517
Booting on embedded CPUs: case 2
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 94/517
Booting on ARM Microchip AT91
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 95/517
Booting on ARM TI OMAP3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 96/517
Booting on Marvell SoC
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 97/517
Generic bootloaders for embedded CPUs
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 99/517
U-Boot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 100/517
U-Boot configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 101/517
U-Boot configuration file
CHIP_defconfig
CONFIG_ARM=y
CONFIG_ARCH_SUNXI=y
CONFIG_MACH_SUN5I=y
CONFIG_DRAM_TIMINGS_DDR3_800E_1066G_1333J=y
# CONFIG_MMC is not set
CONFIG_USB0_VBUS_PIN="PB10"
CONFIG_VIDEO_COMPOSITE=y
CONFIG_DEFAULT_DEVICE_TREE="sun5i-r8-chip"
CONFIG_SPL=y
CONFIG_SYS_EXTRA_OPTIONS="CONS_INDEX=2"
# CONFIG_CMD_IMLS is not set
CONFIG_CMD_DFU=y
CONFIG_CMD_USB_MASS_STORAGE=y
CONFIG_AXP_ALDO3_VOLT=3300
CONFIG_AXP_ALDO4_VOLT=3300
CONFIG_USB_MUSB_GADGET=y
CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_DOWNLOAD=y
CONFIG_G_DNL_MANUFACTURER="Allwinner Technology"
CONFIG_G_DNL_VENDOR_NUM=0x1f3a
CONFIG_G_DNL_PRODUCT_NUM=0x1010
CONFIG_USB_EHCI_HCD=y
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 102/517
Configuring and compiling U-Boot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 103/517
Installing U-Boot
U-Boot must usually be installed in flash memory to be executed
by the hardware. Depending on the hardware, the installation of
U-Boot is done in a different way:
▶ The CPU provides some kind of specific boot monitor with
which you can communicate through serial port or USB using
a specific protocol
▶ The CPU boots first on removable media (MMC) before
booting from fixed media (NAND). In this case, boot from
MMC to reflash a new version
▶ U-Boot is already installed, and can be used to flash a new
version of U-Boot. However, be careful: if the new version of
U-Boot doesn’t work, the board is unusable
▶ The board provides a JTAG interface, which allows to write to
the flash memory remotely, without any system running on
the board. It also allows to rescue a board if the bootloader
doesn’t work.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 104/517
U-boot prompt
▶ Connect the target to the host through a serial console.
▶ Power-up the board. On the serial console, you will see
something like:
U-Boot 2016.05 (May 17 2016 - 12:41:15 -0400)
CPU: SAMA5D36
Crystal frequency: 12 MHz
CPU clock : 528 MHz
Master clock : 132 MHz
DRAM: 256 MiB
NAND: 256 MiB
MMC: mci: 0
In: serial
Out: serial
Err: serial
Net: gmac0
Version details
U-Boot> version
U-Boot 2016.05 (May 17 2016 - 12:41:15 -0400)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 106/517
Important commands (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 107/517
Important commands (2)
▶ loadb, loads, loady, load a file from the serial line to RAM
▶ usb, to initialize and control the USB subsystem, mainly used
for USB storage devices such as USB keys
▶ mmc, to initialize and control the MMC subsystem, used for
SD and microSD cards
▶ nand, to erase, read and write contents to NAND flash
▶ erase, protect, cp, to erase, modify protection and write to
NOR flash
▶ md, displays memory contents. Can be useful to check the
contents loaded in memory, or to look at hardware registers.
▶ mm, modifies memory contents. Can be useful to modify
directly hardware registers, for testing purposes.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 108/517
Environment variables: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 109/517
Environment variables commands (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 110/517
Environment variables commands - Example
u-boot # printenv
baudrate=19200
ethaddr=00:40:95:36:35:33
netmask=255.255.255.0
ipaddr=10.0.0.11
serverip=10.0.0.1
stdin=serial
stdout=serial
stderr=serial
u-boot # printenv serverip
serverip=10.0.0.1
u-boot # setenv serverip 10.0.0.100
u-boot # saveenv
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 111/517
Important U-Boot env variables
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 113/517
Transferring files to the target
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 114/517
TFTP
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 115/517
Practical lab - U-Boot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 116/517
Linux kernel introduction
Linux kernel
introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 117/517
Linux kernel introduction
Linux features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 118/517
History
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 119/517
Linux kernel key features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 120/517
Linux kernel in the system
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 121/517
Linux kernel main roles
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 122/517
System calls
▶ The main interface between the kernel and user space is the
set of system calls
▶ About 400 system calls that provide the main kernel services
▶ File and device operations, networking operations,
inter-process communication, process management, memory
mapping, timers, threads, synchronization primitives, etc.
▶ This interface is stable over time: only new system calls can
be added by the kernel developers
▶ This system call interface is wrapped by the C library, and
user space applications usually never make a system call
directly but rather use the corresponding C library function
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 123/517
Pseudo filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 124/517
Inside the Linux kernel
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 125/517
Linux license
▶ The whole Linux sources are Free Software released under the
GNU General Public License version 2 (GPL v2).
▶ For the Linux kernel, this basically implies that:
▶ When you receive or buy a device with Linux on it, you should
receive the Linux sources, with the right to study, modify and
redistribute them.
▶ When you produce Linux based devices, you must release the
sources to the recipient, with the same rights, with no
restriction.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 126/517
Supported hardware architectures
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 127/517
Linux kernel introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 128/517
Until 2.6 (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 129/517
Until 2.6 (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 130/517
Changes since Linux 2.6
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 131/517
Versions since 2.6.0
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 132/517
New development model
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 133/517
Need for long term support
▶ Issue: bug and security fixes only released for most recent
stable kernel versions. Only LTS (Long Term Support)
releases are supported for up to 6 years.
▶ Example at Google: starting from Android O, all new Android
devices will have to run such an LTS kernel.
▶ You could also get long term support from a commercial
embedded Linux provider.
▶ The Civil Infrastructure Platform project is an industry /
Linux Foundation effort to support selected LTS versions
(starting with 4.4) much longer (> 10 years). See
http://bit.ly/2hy1QYC.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 134/517
What’s new in each Linux release? (1)
The official list of changes for each Linux release is just a huge list
of individual patches!
commit aa6e52a35d388e730f4df0ec2ec48294590cc459
Author: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Date: Wed Jul 13 11:29:17 2011 +0200
Very difficult to find out the key changes and to get the global
picture out of individual changes.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 135/517
What’s new in each Linux release? (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 136/517
Linux kernel introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 137/517
Location of kernel sources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 138/517
Getting Linux sources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 139/517
Linux kernel size (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 140/517
Linux kernel size (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 141/517
Getting Linux sources
▶ Full tarballs
▶ Contain the complete kernel sources: long to download and
uncompress, but must be done at least once
▶ Example:
http://www.kernel.org/pub/linux/kernel/v3.x/linux-
3.10.9.tar.xz
▶ Extract command:
tar xf linux-3.10.9.tar.xz
▶ Incremental patches between versions
▶ It assumes you already have a base version and you apply the
correct patches in the right order. Quick to download and
apply
▶ Examples:
http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.10.xz
(3.9 to 3.10)
http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.10.9.xz
(3.10 to 3.10.9)
▶ All previous kernel versions are available in
http://kernel.org/pub/linux/kernel/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 142/517
Patch
▶ A patch is the difference between two source trees
▶ Computed with the diff tool, or with more elaborate version
control systems
▶ They are very common in the open-source community
▶ Excerpt from a patch:
# *DOCUMENTATION*
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 143/517
Contents of a patch
# *DOCUMENTATION*
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 144/517
Using the patch command
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 145/517
Applying a Linux patch
▶ Two types of Linux patches:
▶ Either to be applied to the previous stable version
(from 3.<x-1> to 3.x)
▶ Or implementing fixes to the current stable version
(from 3.x to 3.x.y)
▶ Can be downloaded in gzip or xz (much smaller) compressed
files.
▶ Always produced for n=1
(that’s what everybody does... do it too!)
▶ Need to run the patch command inside the toplevel kernel
source directory
▶ Linux patch command line example:
cd linux-3.9
xzcat ../patch-3.10.xz | patch -p1
xzcat ../patch-3.10.9.xz | patch -p1
cd ..; mv linux-3.9 linux-3.10.9
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 146/517
Practical lab - Kernel sources
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 147/517
Linux kernel introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 148/517
Linux kernel introduction
Kernel configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 149/517
Kernel configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 150/517
Specifying the target architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 151/517
Kernel configuration and build system
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 152/517
Kernel configuration details
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 153/517
Initial configuration
Difficult to find which kernel configuration will work with your
hardware and root filesystem. Start with one that works!
▶ Desktop or server case:
▶ Advisable to start with the configuration of your running
kernel, usually available in /boot:
cp /boot/config-`uname -r` .config
▶ Embedded platform case:
▶ Default configuration files are available, usually for each CPU
family.
▶ They are stored in arch/<arch>/configs/, and are just
minimal .config files (only settings different from default
ones).
▶ Run make help to find if one is available for your platform
▶ To load a default configuration file, just run
make cpu_defconfig
▶ This will overwrite your existing .config file!
Now, you can make configuration changes (make menuconfig...).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 154/517
Create your own default configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 155/517
Kernel or module?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 156/517
Kernel option types
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 157/517
Kernel option dependencies
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 158/517
make xconfig
make xconfig
▶ The most common graphical interface to configure the kernel.
▶ Make sure you read
help -> introduction: useful options!
▶ File browser: easier to load configuration files
▶ Search interface to look for parameters
▶ Required Debian / Ubuntu packages: qt5-default g++
pkg-config
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 159/517
make xconfig screenshot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 160/517
make xconfig search interface
Looks for a keyword in the parameter name. Allows to select or
unselect found parameters.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 161/517
Kernel configuration options
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 162/517
Corresponding .config file excerpt
Options are grouped by sections and are prefixed with CONFIG_.
#
# CD-ROM/DVD Filesystems
#
CONFIG_ISO9660_FS=m
CONFIG_JOLIET=y
CONFIG_ZISOFS=y
CONFIG_UDF_FS=y
CONFIG_UDF_NLS=y
#
# DOS/FAT/NT Filesystems
#
# CONFIG_MSDOS_FS is not set
# CONFIG_VFAT_FS is not set
CONFIG_NTFS_FS=m
# CONFIG_NTFS_DEBUG is not set
CONFIG_NTFS_RW=y
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 163/517
make gconfig
make gconfig
▶ GTK based graphical
configuration interface.
Functionality similar to that
of make xconfig.
▶ Just lacking a search
functionality.
▶ Required Debian packages:
libglade2-dev
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 164/517
make menuconfig
make menuconfig
▶ Useful when no graphics are
available. Pretty convenient
too!
▶ Same interface found in
other tools: BusyBox,
Buildroot...
▶ Required Debian packages:
libncurses-dev
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 165/517
make nconfig
make nconfig
▶ A newer, similar text
interface
▶ More user friendly (for
example, easier to access
help information).
▶ Required Debian packages:
libncurses-dev
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 166/517
make oldconfig
make oldconfig
▶ Needed very often!
▶ Useful to upgrade a .config file from an earlier kernel release
▶ Issues warnings for configuration parameters that no longer
exist in the new kernel.
▶ Asks for values for new parameters (while xconfig and
menuconfig silently set default values for new parameters).
If you edit a .config file by hand, it’s strongly recommended to
run make oldconfig afterwards!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 167/517
Undoing configuration changes
A frequent problem:
▶ After changing several kernel configuration settings, your
kernel no longer works.
▶ If you don’t remember all the changes you made, you can get
back to your previous configuration:
$ cp .config.old .config
▶ All the configuration interfaces of the kernel (xconfig,
menuconfig, oldconfig...) keep this .config.old backup
copy.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 168/517
Linux kernel introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 169/517
Choose a compiler
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 170/517
Specifying ARCH and CROSS_COMPILE
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 171/517
Kernel compilation
▶ make
▶ In the main kernel source directory!
▶ Remember to run multiple jobs in parallel if you have multiple
CPU cores. Example: make -j 4
▶ No need to run as root!
▶ Generates
▶ vmlinux, the raw uncompressed kernel image, in the ELF
format, useful for debugging purposes, but cannot be booted
▶ arch/<arch>/boot/*Image, the final, usually compressed,
kernel image that can be booted
▶ bzImage for x86, zImage for ARM, vmlinux.bin.gz for ARC,
etc.
▶ arch/<arch>/boot/dts/*.dtb, compiled Device Tree files (on
some architectures)
▶ All kernel modules, spread over the kernel source tree, as .ko
(Kernel Object) files.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 172/517
Kernel installation: native case
▶ make install
▶ Does the installation for the host system by default, so needs
to be run as root.
▶ Installs
▶ /boot/vmlinuz-<version>
Compressed kernel image. Same as the one in
arch/<arch>/boot
▶ /boot/System.map-<version>
Stores kernel symbol addresses for debugging purposes
(obsolete: such information is usually stored in the kernel
itself)
▶ /boot/config-<version>
Kernel configuration for this version
▶ In GNU/Linux distributions, typically re-runs the bootloader
configuration utility to make the new kernel available at the
next boot.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 173/517
Kernel installation: embedded case
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 174/517
Module installation: native case
▶ make modules_install
▶ Does the installation for the host system by default, so needs
to be run as root
▶ Installs all modules in /lib/modules/<version>/
▶ kernel/
Module .ko (Kernel Object) files, in the same directory
structure as in the sources.
▶ modules.alias, modules.aliases.bin
Aliases for module loading utilities. Used to find drivers for
devices. Example line:
alias usb:v066Bp20F9d*dc*dsc*dp*ic*isc*ip*in* asix
▶ modules.dep, modules.dep.bin
Module dependencies
▶ modules.symbols, modules.symbols.bin
Tells which module a given symbol belongs to.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 175/517
Module installation: embedded case
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 176/517
Kernel cleanup targets
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 177/517
Kernel building overview
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 178/517
Linux kernel introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 179/517
Device Tree (DT)
▶ Many embedded architectures have a lot of non-discoverable
hardware.
▶ Depending on the architecture, such hardware is either
described using C code directly within the kernel, or using a
special hardware description language in a Device Tree.
▶ The DT was created for PowerPC, and later was adopted by
other architectures (ARM, ARC...). Now Linux has DT
support in most architectures, at least for specific systems (for
example for the OLPC on x86).
▶ A Device Tree Source, written by kernel developers, is
compiled into a binary Device Tree Blob, and needs to be
passed to the kernel at boot time.
▶ There is one different Device Tree for each board/platform
supported by the kernel, available in
arch/arm/boot/dts/<board>.dtb.
▶ The bootloader must load both the kernel image and the
Device Tree Blob in memory before starting the kernel.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 180/517
Customize your board device tree!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 181/517
Booting with U-Boot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 182/517
Kernel command line
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 183/517
Practical lab - Kernel cross-compiling
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 184/517
Linux kernel introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 185/517
Advantages of modules
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 186/517
Module dependencies
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 187/517
Kernel log
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 188/517
Module utilities (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 189/517
Understanding module loading issues
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 190/517
Module utilities (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 191/517
Module utilities (3)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 192/517
Passing parameters to modules
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 194/517
Useful reading
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 195/517
Linux Root Filesystem
Linux Root
Filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 196/517
Linux Root Filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 197/517
Filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 198/517
Filesystems (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 199/517
mount / umount
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 200/517
Root filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 201/517
Location of the root filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 202/517
Mounting rootfs from storage devices
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 203/517
Mounting rootfs over the network (1)
Once networking works, your root filesystem could be a directory
on your GNU/Linux development host, exported by NFS (Network
File System). This is very convenient for system development:
▶ Makes it very easy to update files on the root filesystem,
without rebooting. Much faster than through the serial port.
▶ Can have a big root filesystem even if you don’t have support
for internal or external storage yet.
▶ The root filesystem can be huge. You can even build native
compiler tools and build all the tools you need on the target
itself (better to cross-compile though).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 204/517
Mounting rootfs over the network (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 205/517
Mounting rootfs over the network (3)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 206/517
Mounting rootfs over the network (4)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 207/517
rootfs in memory: initramfs (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 209/517
rootfs in memory: initramfs (3)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 210/517
Linux Root Filesystem
Contents
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 211/517
Root filesystem organization
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 212/517
Important directories (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 213/517
Important directories (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 214/517
Separation of programs and libraries
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 215/517
Linux Root Filesystem
Device Files
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 216/517
Devices
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 217/517
Types of devices
▶ Block devices
▶ A device composed of fixed-sized blocks, that can be read and
written to store data
▶ Used for hard disks, USB keys, SD cards, etc.
▶ Character devices
▶ Originally, an infinite stream of bytes, with no beginning, no
end, no size. The pure example: a serial port.
▶ Used for serial ports, terminals, but also sound cards, video
acquisition devices, frame buffers
▶ Most of the devices that are not block devices are represented
as character devices by the Linux kernel
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 218/517
Devices: everything is a file
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 219/517
Device files examples
Example C code that uses the usual file API to write data to a
serial port
int fd;
fd = open("/dev/ttyS0", O_RDWR);
write(fd, "Hello", 5);
close(fd);
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 220/517
Creating device files
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 221/517
Linux Root Filesystem
Pseudo Filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 222/517
proc virtual filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 223/517
proc contents
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 224/517
sysfs filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 225/517
Linux Root Filesystem
Minimal filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 226/517
Basic applications
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 227/517
Overall booting process
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 228/517
Overall booting process with initramfs
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 229/517
Busybox
Busybox
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 230/517
Why Busybox?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 231/517
General purpose toolbox: BusyBox
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 232/517
BusyBox commands!
[, [[, acpid, addgroup, adduser, adjtimex, ar, arp, arping, ash, awk, basename, beep, blkid, brctl,
bunzip2, bzcat, bzip2, cal, cat, catv, chat, chattr, chgrp, chmod, chown, chpasswd, chpst, chroot,
chrt, chvt, cksum, clear, cmp, comm, cp, cpio, crond, crontab, cryptpw, cut, date, dc, dd,
deallocvt, delgroup, deluser, depmod, devmem, df, dhcprelay, diff, dirname, dmesg, dnsd,
dnsdomainname, dos2unix, dpkg, du, dumpkmap, dumpleases, echo, ed, egrep, eject, env, envdir,
envuidgid, expand, expr, fakeidentd, false, fbset, fbsplash, fdflush, fdformat, fdisk, fgrep, find,
findfs, flash_lock, flash_unlock, fold, free, freeramdisk, fsck, fsck.minix, fsync, ftpd, ftpget,
ftpput, fuser, getopt, getty, grep, gunzip, gzip, hd, hdparm, head, hexdump, hostid, hostname,
httpd, hush, hwclock, id, ifconfig, ifdown, ifenslave, ifplugd, ifup, inetd, init, inotifyd, insmod,
install, ionice, ip, ipaddr, ipcalc, ipcrm, ipcs, iplink, iproute, iprule, iptunnel, kbd_mode, kill,
killall, killall5, klogd, last, length, less, linux32, linux64, linuxrc, ln, loadfont, loadkmap,
logger, login, logname, logread, losetup, lpd, lpq, lpr, ls, lsattr, lsmod, lzmacat, lzop, lzopcat,
makemime, man, md5sum, mdev, mesg, microcom, mkdir, mkdosfs, mkfifo, mkfs.minix, mkfs.vfat, mknod,
mkpasswd, mkswap, mktemp, modprobe, more, mount, mountpoint, mt, mv, nameif, nc, netstat, nice,
nmeter, nohup, nslookup, od, openvt, passwd, patch, pgrep, pidof, ping, ping6, pipe_progress, pivot_
root, pkill, popmaildir, printenv, printf, ps, pscan, pwd, raidautorun, rdate, rdev, readlink,
readprofile, realpath, reformime, renice, reset, resize, rm, rmdir, rmmod, route, rpm, rpm2cpio,
rtcwake, run-parts, runlevel, runsv, runsvdir, rx, script, scriptreplay, sed, sendmail, seq,
setarch, setconsole, setfont, setkeycodes, setlogcons, setsid, setuidgid, sh, sha1sum, sha256sum,
sha512sum, showkey, slattach, sleep, softlimit, sort, split, start-stop-
daemon, stat, strings, stty, su, sulogin, sum, sv, svlogd, swapoff, swapon, switch_root, sync,
sysctl, syslogd, tac, tail, tar, taskset, tcpsvd, tee, telnet, telnetd, test, tftp, tftpd, time,
timeout, top, touch, tr, traceroute, true, tty, ttysize, udhcpc, udhcpd, udpsvd, umount, uname,
uncompress, unexpand, uniq, unix2dos, unlzma, unlzop, unzip, uptime, usleep, uudecode, uuencode,
vconfig, vi, vlock, volname, watch, watchdog, wc, wget, which, who, whoami, xargs, yes, zcat, zcip
Source: https://busybox.net/downloads/BusyBox.html
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 233/517
Applet highlight: Busybox init
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 234/517
Applet highlight - BusyBox vi
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 235/517
Configuring BusyBox
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 236/517
BusyBox make xconfig
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 237/517
Compiling BusyBox
▶ Set the cross-compiler prefix in the configuration interface:
BusyBox Settings -> Build Options -
> Cross Compiler prefix
Example: arm-linux-
▶ Set the installation directory in the configuration interface:
BusyBox Settings -> Installation Options -
> BusyBox installation prefix
▶ Add the cross-compiler path to the PATH environment
variable:
export PATH=/home/<user>/x-tools/arm-unknown-linux-
uclibcgnueabi/bin:$PATH
▶ Compile BusyBox:
make
▶ Install it (this creates a Unix directory structure symbolic links
to the busybox executable):
make install
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 238/517
Practical lab - A tiny embedded system
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 239/517
Block filesystems
Block filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 240/517
Block filesystems
Block devices
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 241/517
Block vs. flash
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 242/517
Block device list
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 243/517
Partitioning
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 244/517
Transfering data to a block device
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 245/517
Block filesystems
Available filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 246/517
Standard Linux filesystem format: ext2, ext3, ext4
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 247/517
Journaled filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 248/517
Filesystem recovery after crashes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 249/517
Other Linux/Unix filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 250/517
F2FS: filesystem for flash-based storage
http://en.wikipedia.org/wiki/F2FS
▶ Filesystem that takes into account the characteristics of
flash-based storage: eMMC, SD cards, SSD, etc.
▶ Developed and contributed by Samsung
▶ Available in the mainline Linux kernel
▶ For optimal results, need a number of details about the
storage internal behavior which may not easy to get
▶ Benchmarks: best performer on flash devices most of the time:
See http://lwn.net/Articles/520003/
▶ Technical details: http://lwn.net/Articles/518988/
▶ Not as widely used as ext3,4, even on flash-based storage.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 251/517
Squashfs: read-only filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 252/517
Compatibility filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 253/517
tmpfs: filesystem in RAM
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 254/517
Block filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 255/517
Creating ext2/ext3/ext4 filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 256/517
Mounting filesystem images
▶ Once a filesystem image has been created, one can access and
modifies its contents from the development workstation, using
the loop mechanism
▶ Example:
genext2fs -d rootfs/ rootfs.img
mkdir /tmp/tst
mount -t ext2 -o loop rootfs.img /tmp/tst
▶ In the /tmp/tst directory, one can access and modify the
contents of the rootfs.img file.
▶ This is possible thanks to loop, which is a kernel driver that
emulates a block device with the contents of a file.
▶ Do not forget to run umount before using the filesystem image!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 257/517
Creating squashfs filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 258/517
Mixing read-only and read-write filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 259/517
Issues with flash-based block storage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 260/517
Practical lab - Block filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 261/517
Flash storage and filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 262/517
Block devices vs flash devices: reminder
▶ Block devices:
▶ Allow for random data access using fixed size blocks
▶ Do not require special care when writing on the media
▶ Block size is relatively small (minimum 512 bytes, can be
increased for performance reasons)
▶ Considered as reliable (if the storage media is not, some
hardware or software parts are supposed to make it reliable)
▶ Flash devices:
▶ Allow for random data access too
▶ Require special care before writing on the media (erasing the
region you are about to write on)
▶ Erase, write and read operation might not use the same block
size
▶ Reliability depends on the flash technology
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 263/517
NAND flash chips: how they work ?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 264/517
NAND flash storage: organization
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 265/517
NAND flash storage: constraints
▶ Reliability
▶ Far less reliable than NOR flash
▶ Reliability depends on the NAND flash technology (SLC, MLC)
▶ Require additional mechanisms to recover from bit flips: ECC
(Error Correcting Code)
▶ ECC information stored in the OOB (Out-of-band area)
▶ Lifetime
▶ Short lifetime compared to other storage media
▶ Lifetime depends on the NAND flash technology (SLC, MLC):
between 1000000 and 1000 erase cycles per block
▶ Wear leveling mechanisms are required
▶ Bad block detection/handling required too
▶ Despite the number of constraints brought by NAND they are
widely used in embedded systems for several reasons:
▶ Cheaper than other flash technologies
▶ Provide high capacity storage
▶ Provide good performance (both in read and write access)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 266/517
NAND flash: ECC
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 267/517
The MTD subsystem (1)
▶ MTD stands for Memory Technology Devices
▶ Generic subsystem in Linux dealing with all types of storage
media that are not fitting in the block subsystem
▶ Supported media types: RAM, ROM, NOR flash, NAND
flash, Dataflash
▶ Independent of the communication interface (drivers available
for parallel, SPI, direct memory mapping, ...)
▶ Abstract storage media characteristics and provide a simple
API to access MTD devices
▶ MTD device characteristics exposed to users:
▶ erasesize: minimum erase size unit
▶ writesize: minimum write size unit
▶ oobsize: extra size to store metadata or ECC data
▶ size: device size
▶ flags: information about device type and capabilities
▶ Various kind of MTD ”users” in the kernel: file-systems, block
device emulation layers, user space interfaces...
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 268/517
The MTD subsystem (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 269/517
MTD partitioning
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 270/517
Linux: definition of MTD partitions
The Device Tree is the standard place to define default MTD partitions
for platforms with Device Tree support.
Example from arch/arm/boot/dts/omap3-overo-base.dtsi:
nand@0,0 {
linux,mtd-name= "micron,mt29c4g96maz";
[...]
ti,nand-ecc-opt = "bch8"
[...]
partition@0 {
label = "SPL";
reg = <0 0x80000>; /* 512KiB */
};
partition@80000 {
label = "U-Boot";
reg = <0x80000 0x1C0000>; /* 1792KiB */
};
partition@1c0000 {
label = "Environment";
reg = <0x240000 0x40000>; /* 256KiB */
};
[...]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 271/517
U-Boot: defining MTD partitions (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 272/517
U-Boot: defining MTD partitions (2)
▶ Example:
setenv mtdids nand0=omap2-nand.0
setenv mtdparts mtdparts=omap2-nand.0:512k(X-Loader)ro,1536k(U-Boot)ro,512k(Env),4m(Kernel),-(RootFS)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 273/517
U-Boot: defining MTD partitions (3)
Details about the two environment variables needed by U-Boot:
▶ mtdids attaches an mtdid to a flash device.
setenv mtdids <devid>=<mtdid>[,<devid>=<mtdid>]
▶ devid: U-Boot device identifier (from nand info or flinfo)
▶ mtdid: Linux mtd identifier. Displayed when booting the
Linux kernel:
NAND device: Manufacturer ID: 0x2c, Chip ID: 0xbc (Micron NAND 512MiB 1,8V 16-bit)
Creating 5 MTD partitions on "omap2-nand.0":
0x000000000000-0x000000080000 : "X-Loader"
0x000000080000-0x000000200000 : "U-Boot"
0x000000200000-0x000000280000 : "Environment"
0x000000280000-0x000000580000 : "Kernel"
0x000000580000-0x000020000000 : "File System"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 275/517
U-Boot: manipulating NAND devices
U-Boot provides a set of commands to manipulate NAND devices,
grouped under the nand command
▶ nand info
Show available NAND devices and characteristics
▶ nand device [dev]
Select or display the active NAND device
▶ nand read[.option] <addr> <offset|partname> <size>
Read data from NAND
▶ nand write[.option] <addr> <offset|partname> <size>
Write data on NAND
▶ Use nand write.trimffs to avoid writing empty pages (those
filled with 0xff)
▶ nand erase <offset> <size>
Erase a NAND region
▶ nand erase.part <partname>
Erase a NAND partition
▶ More commands for debugging purposes
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 276/517
U-Boot: manipulating NOR devices (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 277/517
U-Boot: manipulating NOR devices (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 278/517
Linux: MTD devices interface with user space
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 279/517
Linux: user space flash management tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 280/517
Flash wear leveling (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 281/517
Flash wear leveling (2)
Flash users should also take the limited lifetime of flash devices
into account by taking additional precautions
▶ Do not use your flash storage as swap area (rare in embedded
systems anyway)
▶ Mount your filesystems as read-only, or use read-only
filesystems (SquashFS), whenever possible.
▶ Keep volatile files in RAM (tmpfs)
▶ Don’t use the sync mount option (commits writes
immediately). Use the fsync() system call for per-file
synchronization.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 282/517
Flash file-systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 283/517
Legacy flash filesystems: JFFS2
Standard file
API
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 284/517
Legacy flash filesystems: YAFFS2
Standard file
API
▶ Mainly supports NAND flash
▶ No compression
YAFFS2
▶ Wear leveling, power failure resistant
filesystem
▶ Fast boot time
▶ Not part of the official Linux kernel: code
only available separately MTD
(Dual GPL / Proprietary license for non driver
Linux operating systems)
▶ https://yaffs.net/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 285/517
UBI/UBIFS
Standard file
API
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 286/517
UBI (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 287/517
UBI (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 288/517
UBI: internals
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 289/517
UBI: good practice
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 290/517
UBI layout: bad example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 291/517
UBI layout: good example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 292/517
UBIFS
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 293/517
Linux: UBI host tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 294/517
ubinize configuration file
▶ Can contain several sections
▶ Each section is describing a UBI volume
▶ static volumes are meant to store read-only blobs of data,
and get the minimum corresponding size. CRC checks are
done on them.
▶ A read-only UBIFS filesystem can go in a static volume, but
in this case dynamic volumes are best for performance (CRC
checking also done at UBIFS level).
[data-volume]
[rootfs-volume]
[kernel-volume] mode=ubi
mode=ubi
mode=ubi image=data.ubifs
image=rootfs.ubifs
image=zImage vol_id=3
vol_id=2
vol_id=1 vol_size=30MiB
vol_size=2MiB
vol_type=static vol_type=dynamic
vol_type=dynamic
vol_name=kernel vol_name=data
vol_name=rootfs
vol_flags=autoresize
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 295/517
U-Boot: UBI tools
Grouped under the ubi command
▶ ubi part <part-name>
Attach an MTD partition to the UBI layer
▶ ubi info [layout]
Display UBI device information
(or volume information if the layout string is passed)
▶ ubi check <vol-name>
Check if a volume exists
▶ ubi readvol <dest-addr> <vol-name> [<size>]
Read volume contents
▶ U-Boot also provides tools to update the UBI device contents
▶ Using them is highly discouraged (the U-Boot UBI
implementation is not entirely stable, and using commands
that do not touch the UBI metadata is safer)
▶ ubi createvol <vol-name> [<size>] [<type>]
▶ ubi removevol <vol-name>
▶ ubi writevol <src-addr> <vol-name> <size>
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 296/517
Linux: UBI target tools (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 297/517
Linux: UBI target tools (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 298/517
Linux tools: BusyBox UBI limitations
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 299/517
Linux: UBIFS host tools
UBIFS filesystems images can be created using mkfs.ubifs
▶ mkfs.ubifs -m 4096 -e 258048 -c 1000 -
r rootfs/ ubifs.img
▶ -m 4096, minimal I/O size
(see /sys/class/mtd/mtdx/writesize).
▶ -e 258048, logical erase block size (smaller than PEB size,
can be found in the kernel log after running ubiattach)
▶ -c 1000, maximum size of the UBI volume the image will be
flashed into, in number of logical erase blocks. Do not make
this number unnecessary big, otherwise the UBIFS data
structures will be bigger than needed and performance will be
degraded. Details:
http://linux-mtd.infradead.org/faq/ubifs.html#L_max_leb_cnt
▶ Once created
▶ Can be written to a UBI volume from the target using
ubiupdatevol from Linux on the target
▶ Or, can be included in a UBI image (using ubinize on the
host)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 300/517
Linux: UBIFS target tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 301/517
Linux: UBI image creation workflow
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 302/517
Linux: Using a UBIFS filesystem as root filesystem
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 303/517
Summary: how to boot on a UBIFS filesystem
In U-Boot:
▶ Define partitions:
setenv mtdids ...
setenv mtdparts ...
▶ Define the base Linux kernel bootargs, specifying booting on
UBIFS, the UBI volume used as root filesystem, and the MTD
partition attached to UBI. Example:
setenv bootargs_base console=ttyS0 rootfstype=ubifs
root=ubi0:rootfs ubi.mtd=2 ...
▶ Define the boot command sequence, loading the U-Boot
partition definitions, loading kernel and DTB images from UBI
partitions, and adding mtdparts to the kernel command line.
Example:
setenv bootcmd 'mtdparts; ubi part UBI; ubi readvol
0x81000000 kernel; ubi readvol 0x82000000 dtb;
setenv bootargs ${bootargs_base} ${mtdparts}; bootz
0x81000000 - 0x82000000'
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 304/517
Linux: Block emulation layers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 305/517
Linux: mtdblock
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 306/517
Linux: ubiblock
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 307/517
Useful reading
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 308/517
Practical lab - Flash Filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 309/517
Embedded Linux system development
Embedded Linux
system
development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 310/517
Contents
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 311/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 312/517
Third party libraries and applications
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 313/517
Find existing components
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 314/517
Choosing components
Not all free software components are necessarily good to re-use.
One must pay attention to:
▶ Vitality of the developer and user communities. This vitality
ensures long-term maintenance of the component, and
relatively good support. It can be measured by looking at the
mailing-list traffic and the version control system activity.
▶ Quality of the component. Typically, if a component is
already available through embedded build systems, and has a
dynamic user community, it probably means that the quality is
relatively good.
▶ License. The license of the component must match your
licensing constraints. For example, GPL libraries cannot be
used in proprietary applications.
▶ Technical requirements. Of course, the component must
match your technical requirements. But don’t forget that you
can improve the existing components if a feature is missing!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 315/517
Licenses (1)
▶ All software that are under a free software license give four
freedoms to all users
▶ Freedom to use
▶ Freedom to study
▶ Freedom to copy
▶ Freedom to modify and distribute modified copies
▶ See http://www.gnu.org/philosophy/free-sw.html for a
definition of Free Software
▶ Open Source software, as per the definition of the Open
Source Initiative, are technically similar to Free Software in
terms of freedoms
▶ See http://www.opensource.org/docs/osd for the definition
of Open Source Software
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 316/517
Licenses (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 317/517
GPL
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 318/517
GPL: redistribution
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 319/517
LGPL
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 321/517
Non-copyleft licenses
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 322/517
BSD license
[...]
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 323/517
Is this free software?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 324/517
Respect free software licenses
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 326/517
Keeping changes separate (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 327/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 328/517
ssh server and client: Dropbear
http://matt.ucc.asn.au/dropbear/dropbear.html
▶ Very small memory footprint ssh server for embedded systems
▶ Satisfies most needs. Both client and server!
▶ Size: 110 KB, statically compiled with uClibc on x86.
(OpenSSH client and server: approx 1200 KB, dynamically
compiled with glibc on x86)
▶ Useful to:
▶ Get a remote console on the target device
▶ Copy files to and from the target device (scp or
rsync -e ssh).
▶ An alternative to OpenSSH, used on desktop and server
systems.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 329/517
Benefits of a web server interface
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 330/517
Web servers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 331/517
Network utilities (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 332/517
Network utilities (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 333/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 334/517
System utilities
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 335/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 336/517
Language interpreters
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 337/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 338/517
Audio, video and multimedia
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 339/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 340/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 341/517
X.org - KDrive
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 342/517
Kdrive: architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 343/517
Kdrive: usage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 344/517
Wayland
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 345/517
Wayland: architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 346/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 347/517
Gtk
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 348/517
Gtk stack components
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 349/517
Gtk example
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 350/517
Qt (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 351/517
Qt (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 352/517
Qt’s usage
Source: https://www.qt.io/qt-for-device-creation/
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 353/517
Other less frequent solutions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 354/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 355/517
Lightweight database - SQLite
http://www.sqlite.org
▶ SQLite is a small C library that implements a self-contained,
embeddable, lightweight, zero-configuration SQL database
engine
▶ The database engine of choice for embedded Linux systems
▶ Can be used as a normal library
▶ Can be directly embedded into a application, even a
proprietary one since SQLite is released in the public domain
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 356/517
Embedded Linux system development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 357/517
WebKit
http://webkit.org/
▶ Web browser engine. Application framework that
can be used to develop web browsers.
▶ License: portions in LGPL and others in BSD.
Proprietary applications allowed.
▶ Used by many web browsers: Safari, iPhone and
Android default browsers ... Google Chrome now
uses a fork of its WebCore component). Used by
e-mail clients too to render HTML:
http://trac.webkit.org/wiki/
Applications%20using%20WebKit
▶ Multiple graphical back-ends: Qt4, GTK, EFL...
▶ You could use it to create your custom browser.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 358/517
Embedded Linux system development
System building
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 359/517
System building: goal and solutions
▶ Goal
▶ Integrate all the software
components, both third-party
and in-house, into a working root
filesystem
▶ It involves the download,
extraction, configuration,
compilation and installation of all
components, and possibly fixing
issues and adapting configuration
files
▶ Several solutions
▶ Manually
▶ System building tools Penguin picture: http://bit.ly/1PwDklz
▶ Distributions or ready-made
filesystems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 360/517
System building: manually
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 361/517
System building: manually (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 362/517
System foundations
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 363/517
Target and build spaces
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 364/517
Build systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 365/517
Autotools and friends
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 366/517
automake / autoconf / autoheader
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 367/517
automake / autoconf
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 368/517
Configuring and compiling: native case
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 369/517
Configuring and compiling: cross case (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 370/517
Configuring and compiling: cross case (2)
export PATH=/usr/local/arm-linux/bin:$PATH
export CC=arm-linux-gcc
export STRIP=arm-linux-strip
./configure --host=arm-linux --prefix=/usr
make
make DESTDIR=$HOME/work/rootfs install
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 371/517
Installation (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 372/517
Installation (2)
Contents of usr/lib after installation of libpng and zlib
▶ libpng libtool description files
./lib/libpng12.la
./lib/libpng.la -> libpng12.la
▶ libpng static version
./lib/libpng12.a
./lib/libpng.a -> libpng12.a
▶ libpng dynamic version
./lib/libpng.so.3.32.0
./lib/libpng12.so.0.32.0
./lib/libpng12.so.0 -> libpng12.so.0.32.0
./lib/libpng12.so -> libpng12.so.0.32.0
./lib/libpng.so -> libpng12.so
./lib/libpng.so.3 -> libpng.so.3.32.0
▶ libpng pkg-config description files
./lib/pkgconfig/libpng12.pc
./lib/pkgconfig/libpng.pc -> libpng12.pc
▶ zlib dynamic version
./lib/libz.so.1.2.3
./lib/libz.so -> libz.so.1.2.3
./lib/libz.so.1 -> libz.so.1.2.3
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 373/517
Installation in the build and target spaces
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 374/517
pkg-config
▶ pkg-config is a tool that allows to query a small database to
get information on how to compile programs that depend on
libraries
▶ The database is made of .pc files, installed by default in
<prefix>/lib/pkgconfig/.
▶ pkg-config is used by the configure script to get the library
configurations
▶ It can also be used manually to compile an application:
arm-linux-gcc -o test test.c $(pkg-config --libs --
cflags thelib)
▶ By default, pkg-config looks in /usr/lib/pkgconfig for the
*.pc files, and assumes that the paths in these files are
correct.
▶ PKG_CONFIG_PATH allows to set another location for the *.pc
files and PKG_CONFIG_SYSROOT_DIR to prepend a prefix to the
paths mentioned in the .pc files.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 375/517
Let’s find the libraries
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 376/517
Further details about autotools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 377/517
Practical lab - Third party libraries and applications
▶ Manually cross-compiling
applications and libraries
▶ Learning about common techniques
and issues.
▶ Compile and run an audio player
application!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 378/517
System building tools: principle
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 379/517
Available system building tools
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 380/517
Buildroot (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 381/517
Buildroot (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 382/517
Buildroot: adding a new package (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 383/517
Buildroot: adding a new package (2)
config BR2_PACKAGE_GQVIEW
bool "gqview"
depends on BR2_PACKAGE_LIBGTK2
help
GQview is an image viewer for Unix operating systems
http://prdownloads.sourceforge.net/gqview
▶ It must be sourced from package/Config.in:
source "package/gqview/Config.in"
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 384/517
Buildroot: adding new package (3)
▶ Create the gqview.mk file to describe the build steps
GQVIEW_VERSION = 2.1.5
GQVIEW_SOURCE = gqview-$(GQVIEW_VERSION).tar.gz
GQVIEW_SITE = http://prdownloads.sourceforge.net/gqview
GQVIEW_DEPENDENCIES = host-pkgconf libgtk2
GQVIEW_CONF_ENV = LIBS="-lm"
GQVIEW_LICENSE = GPL-2.0
GQVIEW_LICENSE_FILES = COPYING
$(eval $(autotools-package))
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 386/517
Distributions - Debian
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 387/517
Distributions - Others
Fedora
▶ http://fedoraproject.org/wiki/
Architectures/ARM Image credits:
https://bit.ly/2EzmJLF
▶ Supported on various recent ARM boards
(such as Beaglebone Black and Raspberry
Pi)
▶ Supports QEMU emulated ARM boards
too (Versatile Express board)
▶ Shipping the same version as for desktops!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 388/517
Embedded distributions
Even if you don’t use them for final products, they can be useful to
make demos quickly
▶ Android: http://www.android.com/
Google’s distribution for phones, tablets, TVs, cars...
Except the Linux kernel, very different user space
than other Linux distributions. Very successful, lots
of applications available (many proprietary).
▶ Alpine Linux: https://www.alpinelinux.org/
Security oriented distribution based on Musl and
BusyBox, fitting in about 130 MB of storage,
supporting x86 and arm, both 32 and 64 bit.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 389/517
Application frameworks
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 390/517
Practical lab - Buildroot
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 391/517
Embedded Linux application development
Embedded Linux
application
development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 392/517
Contents
▶ Application development
▶ Developing applications on embedded Linux
▶ Building your applications
▶ Source management
▶ Integrated development environments (IDEs)
▶ Version control systems
▶ Debugging and analysis tools
▶ Debuggers
▶ Memory checkers
▶ System analysis
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 393/517
Embedded Linux application development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 394/517
Application development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 395/517
Programming language
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 396/517
C library or higher-level libraries?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 397/517
Building your applications
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 398/517
Simple Makefile (1)
CROSS_COMPILE?=arm-linux-
CC=$(CROSS_COMPILE)gcc
OBJS=foo.o bar.o
all: foobar
foobar: $(OBJS)
Tab$(CC) -o $@ $^
clean:
Tab$(RM) -f foobar $(OBJS)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 399/517
Simple Makefile (2)
▶ Case of an application that uses the Glib and the GPS libraries
CROSS_COMPILE?=arm-linux-
LIBS=libgps glib-2.0
OBJS=foo.o bar.o
CC=$(CROSS_COMPILE)gcc
CFLAGS=$(shell pkg-config --cflags $(LIBS))
LDFLAGS=$(shell pkg-config --libs $(LIBS))
all: foobar
foobar: $(OBJS)
$(CC) -o $@ $^ $(LDFLAGS)
Tab
clean:
Tab$(RM) -f foobar $(OBJS)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 400/517
Embedded Linux application development
Integrated Development
Environments (IDE)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 401/517
KDevelop
http://kdevelop.org
▶ A full featured IDE!
▶ License: GPL
▶ Supports many languages: Ada, C, C++,
Database, Java, Perl, PHP, Python, Ruby, Shell
▶ Supports many kinds of projects: KDE, but also
GTK, Gnome, kernel drivers...
▶ Many features: editor, syntax highlighting, code
completion, compiler interface, debugger
interface, file manager, class browser...
Nice overview:
http://en.wikipedia.org/wiki/Kdevelop
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 402/517
KDevelop screenshot
Ruby debugger
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 403/517
Eclipse (1)
http://www.eclipse.org/
▶ An extensible, plug-in based software
development kit, typically used for creating IDEs.
▶ Supported by the Eclipse foundation, a
non-profit consortium of major software industry
vendors (IBM, Intel, Borland, Nokia, Wind
River, Zend, Computer Associates...).
▶ Free Software license (Eclipse Public License).
Incompatible with the GPL.
▶ Supported platforms: GNU/Linux, Unix,
Windows
Extremely popular: created a lot of attraction.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 404/517
Eclipse (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 405/517
Other popular solutions
Vim
▶ Many embedded Linux developers
simply use Vim or Emacs. They
can integrate with debuggers,
source code browsers such as
cscope, offer syntax highlighting
and more.
▶ Geany is an easy-to-use graphical
code editor.
Emacs
▶ CodeBlocks is also quite popular,
since it’s also available on the
Windows platform.
All these editors are available in most
Linux distributions, simply install them
and try them out!
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 406/517
Embedded Linux application development
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 407/517
Version control systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 408/517
Traditional version control systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 409/517
Distributed source control systems (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 410/517
Distributed source control systems (2)
▶ Git
▶ Initially designed and developed by Linus Torvalds for Linux
kernel development
▶ Extremely popular in the community, and used by more and
more projects (kernel, U-Boot, Barebox, uClibc, GNOME,
X.org, etc.)
▶ Outstanding performance, in particular in big projects
▶ http://en.wikipedia.org/wiki/Git_(software)
▶ Mercurial
▶ Another system, created with the same goals as Git.
▶ Used by some big projects too
▶ http://en.wikipedia.org/wiki/Mercurial
http://en.wikipedia.org/wiki/Version_control_systems#
Distributed_revision_control
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 411/517
Embedded Linux application development
Debuggers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 412/517
GDB
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 413/517
GDB crash course
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 414/517
GDB graphical front-ends
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 415/517
Embedded Linux application development
Remote debugging
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 416/517
Remote debugging
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 417/517
Remote debugging: architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 418/517
Remote debugging: usage
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 419/517
Post mortem analysis
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 420/517
Embedded Linux application development
Memory checkers
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 421/517
DUMA
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 422/517
Valgrind (1)
http://valgrind.org/
▶ GNU GPL Software suite for debugging and
profiling programs.
▶ Supported platforms: Linux on x86, x86_64,
ppc32, ppc64 and arm (armv7 only: Cortex A8,
A9 and A5)
▶ Can detect many memory management and
threading bugs.
▶ Profiler: provides information helpful to speed
up your program and reduce its memory usage.
▶ The most popular tool for this usage. Even used
by projects with hundreds of programmers.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 423/517
Valgrind (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 424/517
Embedded Linux application development
System analysis
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 425/517
strace
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 427/517
ltrace
A tool to trace library calls used by a program and all the signals it
receives
▶ Very useful complement to strace, which shows only system
calls.
▶ Of course, works even if you don’t have the sources
▶ Allows to filter library calls with regular expressions, or just by
a list of function names.
▶ Manual page: http://linux.die.net/man/1/ltrace
See http://en.wikipedia.org/wiki/Ltrace for details
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 428/517
ltrace example output
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 429/517
ltrace summary
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 430/517
OProfile
http://oprofile.sourceforge.net
▶ A system-wide profiling tool
▶ Can collect statistics like the top users of the CPU.
▶ Works without having the sources.
▶ Requires a kernel patch to access all features, but is already
available in a standard kernel.
▶ Requires more investigation to see how it works.
▶ Ubuntu/Debian packages: oprofile, oprofile-gui
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 431/517
Practical lab - App. development and debugging
Application development
▶ Compile your own application with
the ncurses library
Remote debugging
▶ Set up remote debugging tools on
the target: strace, ltrace
and gdbserver.
▶ Debug a simple application running
on the target using remote
debugging
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 432/517
Real-time in embedded Linux systems
Real-time in
embedded Linux
systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 433/517
Real-time in embedded Linux systems
Introduction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 434/517
Embedded Linux and real time
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 435/517
Embedded Linux and real time
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 436/517
Linux and real-time approaches (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 437/517
Linux and real-time approaches (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 438/517
Real-time in embedded Linux systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 439/517
Understanding latency
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 440/517
Linux kernel latency components
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 441/517
Interrupt latency
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 442/517
Sources of interrupt latency
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 443/517
Interrupt handler duration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 444/517
Interrupt handler implementation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 445/517
Scheduler latency
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 446/517
Understanding preemption (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 447/517
Understanding preemption (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 448/517
Scheduler duration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 449/517
Sources of scheduler duration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 450/517
Other non-deterministic mechanisms
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 452/517
Interrupt handler priority
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 453/517
The PREEMPT_RT project
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 454/517
Improvements to the mainline kernel
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 455/517
Preemption options
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 456/517
1st option: no forced preemption
CONFIG_PREEMPT_NONE
Kernel code (interrupts, exceptions, system calls) never preempted.
Default behavior in standard kernels.
▶ Best for systems making intense computations, on which
overall throughput is key.
▶ Best to reduce task switching to maximize CPU and cache
usage (by reducing context switching).
▶ Still benefits from some Linux real-time improvements: O(1)
scheduler, increased multiprocessor safety (work on RT
preemption was useful to identify hard to find SMP bugs).
▶ Can also benefit from a lower timer frequency (100 Hz instead
of 250 or 1000).
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 457/517
2nd option: voluntary kernel preemption
CONFIG_PREEMPT_VOLUNTARY
Kernel code can preempt itself
▶ Typically for desktop systems, for quicker application reaction
to user input.
▶ Adds explicit rescheduling points throughout kernel code.
▶ Minor impact on throughput.
▶ Still used in: Ubuntu Desktop 17.04
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 458/517
3rd option: preemptible kernel
CONFIG_PREEMPT
Most kernel code can be involuntarily preempted at any time.
When a process becomes runnable, no more need to wait for kernel
code (typically a system call) to return before running the
scheduler.
▶ Exception: kernel critical sections (holding spinlocks). In a
case you hold a spinlock on a uni-processor system, kernel
preemption could run another process, which would loop
forever if it tried to acquire the same spinlock.
▶ Typically for desktop or embedded systems with latency
requirements in the milliseconds range.
▶ Still a relatively minor impact on throughput.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 459/517
Priority inheritance
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 461/517
Threaded interrupts
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 462/517
Ongoing work on the PREEMPT_RT patchset
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 463/517
Real-time in embedded Linux systems
PREEMPT_RT specifics
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 464/517
CONFIG_PREEMPT_RT (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 465/517
CONFIG_PREEMPT_RT (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 466/517
Real-time in embedded Linux systems
Setting up PREEMPT_RT
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 467/517
PREEMPT_RT setup (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 468/517
PREEMPT_RT setup (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 469/517
Real-time in embedded Linux systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 470/517
Development and compilation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 471/517
Process, thread?
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 472/517
Process, thread: kernel point of view
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 473/517
Creating threads
pthread_exit(void *value_ptr);
▶ Waiting for the termination of a thread
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 474/517
Scheduling classes (1)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 475/517
Scheduling classes (2)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 476/517
Scheduling classes (3)
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
parm.sched_priority = 42;
pthread_attr_setschedparam(&attr, &parm);
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 477/517
Memory locking
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 478/517
Mutexes
pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *mutexattr);
pthread_mutex_destroy(pthread_mutex_t *mutex);
▶ Lock/unlock
pthread_mutex_lock(pthread_mutex_t *mutex);
pthread_mutex_unlock(pthread_mutex_t *mutex);
pthread_mutexattr_t attr;
pthread_mutexattr_init (&attr);
pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 479/517
Timers
▶ Timer creation
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 480/517
Timers (2)
▶ Delete a timer
timer_delete(timer_t timerid)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 481/517
Signals
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 482/517
Inter-process communication
▶ Semaphores
▶ Usable between different processes using named semaphores
▶ sem_open(), sem_close(), sem_unlink(), sem_init(),
sem_destroy(), sem_wait(), sem_post(), etc.
▶ Message queues
▶ Allows processes to exchange data in the form of messages.
▶ mq_open(), mq_close(), mq_unlink(), mq_send(),
mq_receive(), etc.
▶ Shared memory
▶ Allows processes to communicate by sharing a segment of
memory
▶ shm_open(), ftruncate(), mmap(), munmap(), close(),
shm_unlink()
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 483/517
Real-time in embedded Linux systems
Debugging latencies in
PREEMPT_RT
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 484/517
ftrace - Kernel function tracer
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 485/517
Using ftrace
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 486/517
Scheduling latency tracer
cat /sys/kernel/tracing/tracing_max_latency
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 487/517
Exemple of worst-case latencies
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 488/517
Useful reading
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 489/517
Real-time in embedded Linux systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 490/517
Linux real-time extensions
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 491/517
RTLinux
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 492/517
RTAI
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 493/517
Xenomai project
http://www.xenomai.org/
▶ Started in 2001 as a project aiming at emulating
traditional RTOS.
▶ Initial goals: facilitate the porting of programs to
GNU / Linux.
▶ Initially related to the RTAI project (as the RTAI
/ fusion branch), now independent.
▶ Skins mimicking the APIs of traditional RTOS
such as VxWorks, pSOS+, and VRTXsa as well
as the POSIX API, and a “native” API.
▶ Aims at working both as a co-kernel and on top
of PREEMPT_RT in future upstream Linux
versions.
▶ Will never be merged in the mainline kernel.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 494/517
Xenomai architecture
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 495/517
The Adeos interrupt pipeline abstraction
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 496/517
Xenomai features
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 497/517
Xenomai user space real-time support
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 498/517
Life of a Xenomai application
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 499/517
Real Time Driver Model (RTDM)
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 500/517
Real-time in embedded Linux systems
Setting up Xenomai
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 501/517
How to build Xenomai
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 502/517
Linux options for Xenomai configuration
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 503/517
Xenomai user space support
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 504/517
Real-time in embedded Linux systems
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 505/517
The POSIX skin
▶ The POSIX skin allows to recompile without changes a
traditional POSIX application so that instead of using Linux
real-time services, it uses Xenomai services
▶ http://www.xenomai.org/index.php/Porting_POSIX_
applications_to_Xenomai
▶ Clocks and timers, condition variables, message queues,
mutexes, semaphores, shared memory, signals, thread
management
▶ Good for existing code or programmers familiar with the
POSIX API
▶ Of course, if the application uses any Linux service that isn’t
available in Xenomai, it will switch back to secondary mode
▶ To link an application against the POSIX skin
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 507/517
The native API
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 508/517
Xenomai worst-case latencies results
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 509/517
Organizations
▶ http://www.osadl.org
Open Source Automation Development Lab (OSADL)
Targets machine and plant control systems. Most member
companies are German (Thomas Gleixner is on board).
Supports the use of PREEMPT_RT and Xenomai and
contributes to these projects. Shares useful documentation
and resources.
They also organize a yearly Real Time Linux Workshop.
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 510/517
Practical lab - Real-time - Scheduling latency
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 511/517
References
References
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 512/517
Books
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 514/517
International conferences
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 515/517
Last slides
Last slides
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 516/517
Last slide
Thank you!
And may the Source be with you
- Kernel, drivers and embedded Linux - Development, consulting, training and support - https://bootlin.com 517/517