Professional Documents
Culture Documents
Embedded Linux Slides PDF
Embedded Linux Slides PDF
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 1/524
Rights to copy
Your fair use and other rights are in no way affected by the above.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 2/524
Hyperlinks in the document
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 3/524
Free Electrons at a glance
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 4/524
Free Electrons on-line resources
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 8/523
Participate!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 9/523
Practical lab guidelines
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 10/523
Cooperate!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 11/523
Command memento sheet
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 14/523
Birth of free software
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 15/523
Free software?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 16/523
What is embedded Linux?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 17/523
Introduction to Embedded Linux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 18/523
Re-using components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 19/523
Low cost
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 20/523
Full control
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 21/523
Quality
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 22/523
Eases testing of new features
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 23/523
Community support
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 24/523
Taking part into the community
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 25/523
Introduction to Embedded Linux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 26/523
Personal routers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 27/523
Television
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 28/523
Point of sale terminal
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 29/523
Laser cutting machine
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 30/523
Viticulture machine
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 31/523
Introduction to Embedded Linux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 32/523
Processor and architecture (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 33/523
Processor and architecture (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 34/523
RAM and storage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 35/523
Communication
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 36/523
Types of hardware platforms
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 37/523
Criteria for choosing the hardware
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 38/523
Introduction to Embedded Linux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 39/523
Global architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 40/523
Software components
I Cross-compilation toolchain
I Compiler that runs on the development machine, but generates
code for the target
I Bootloader
I Started by the hardware, responsible for basic initialization,
loading and executing the kernel
I Linux Kernel
I Contains the process and memory management, network stack,
device drivers and provides services to user space applications
I C library
I The interface between the kernel and the user space
applications
I Libraries and applications
I Third-party or in-house
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 41/523
Embedded Linux work
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 42/523
Embedded Linux development environment
Embedded Linux
development Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 43/523
Embedded Linux solutions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 44/523
OS for Linux development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 45/523
Desktop Linux distribution
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 46/523
Linux root and non-root users
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 47/523
Software packages
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 48/523
Managing software packages (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 49/523
Managing software packages (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 50/523
Host vs. target
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 51/523
Serial line communication program
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 52/523
Command line tips
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 53/523
Practical lab - Training Setup
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 54/523
Cross-compiling toolchains
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 55/523
Cross-compiling toolchains
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 56/523
Definition (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 57/523
Definition (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 58/523
Machines in build procedures
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 59/523
Different toolchain build procedures
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 60/523
Components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 61/523
Binutils
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 62/523
Kernel headers (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 63/523
Kernel headers (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 64/523
Kernel headers (3)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 65/523
GCC
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 66/523
C library
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 67/523
Cross-compiling toolchains
C Libraries
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 68/523
glibc
I License: LGPL
I C library from the GNU project
I Designed for performance, standards
compliance and portability
I Found on all GNU / Linux host systems
I Of course, actively maintained
I Quite big for small embedded systems:
approx 2.5 MB on ARM (version 2.9 -
libc: 1.5 MB, libm: 750 KB)
I http://www.gnu.org/software/libc/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 69/523
uClibc
I License: LGPL
I Lightweight C library for small embedded systems
I High configurability: many features can be enabled or disabled
through a menuconfig interface
I Works only with Linux/uClinux, works on most embedded
architectures
I No guaranteed binary compatibility. May need to recompile
applications when the library configuration changes.
I Focus on size rather than performance
I Small compile time
I http://www.uclibc.org/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 70/523
uClibc (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 73/523
Other smaller C libraries
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 74/523
Cross-compiling toolchains
Toolchain Options
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 75/523
ABI
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 76/523
Floating point support
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 77/523
CPU optimization flags
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 78/523
Cross-compiling toolchains
Obtaining a Toolchain
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 79/523
Building a toolchain manually
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 80/523
Get a pre-compiled toolchain
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 81/523
Sourcery CodeBench
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 82/523
Linaro toolchains
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 83/523
Installing and using a pre-compiled toolchain
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 84/523
Toolchain building utilities
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 85/523
Toolchain building utilities (2)
I Crosstool-ng
I Rewrite of the older Crosstool, with a menuconfig-like
configuration system
I Feature-full: supports uClibc, glibc, eglibc, hard and soft float,
many architectures
I Actively maintained
I http://crosstool-ng.org/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 86/523
Toolchain building utilities (3)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 87/523
Crosstool-NG: installation and usage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 89/523
Practical lab - Using Crosstool-NG
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 90/523
Bootloaders
Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 91/523
Bootloaders
Boot Sequence
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 92/523
Bootloaders
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 93/523
Bootloaders on x86 (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 95/523
Booting on embedded CPUs: case 1
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 96/523
Booting on embedded CPUs: case 2
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 97/523
Booting on ARM Atmel AT91
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 98/523
Booting on ARM TI OMAP3
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 99/523
Booting on Marvell SoC
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 100/523
Generic bootloaders for embedded CPUs
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 102/523
U-Boot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 103/523
U-Boot configuration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 104/523
U-Boot configuration file excerpt
/* CPU configuration */
#define CONFIG_ARMV7 1
#define CONFIG_OMAP 1
/* Available commands and features */
#define CONFIG_OMAP34XX 1
#define CONFIG_CMD_CACHE
#define CONFIG_OMAP3430 1
#define CONFIG_CMD_EXT2
#define CONFIG_OMAP3_IGEP0020 1
#define CONFIG_CMD_FAT
[...]
#define CONFIG_CMD_I2C
/* Memory configuration */
#define CONFIG_CMD_MMC
#define CONFIG_NR_DRAM_BANKS 2
#define CONFIG_CMD_NAND
#define PHYS_SDRAM_1 OMAP34XX_SDRC_CS0
#define CONFIG_CMD_NET
#define PHYS_SDRAM_1_SIZE (32 << 20)
#define CONFIG_CMD_DHCP
#define PHYS_SDRAM_2 OMAP34XX_SDRC_CS1
#define CONFIG_CMD_PING
[...]
#define CONFIG_CMD_NFS
/* USB configuration */
#define CONFIG_CMD_MTDPARTS
#define CONFIG_MUSB_UDC 1
[...]
#define CONFIG_USB_OMAP3 1
#define CONFIG_TWL4030_USB 1
[...]
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 105/523
Configuring and compiling U-Boot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 106/523
Installing U-Boot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 107/523
U-boot prompt
Die ID #255000029ff800000168580212029011
Net: smc911x-0
U-Boot #
U-Boot> flinfo
DataFlash:AT45DB021
Nb pages: 1024
Page Size: 264
Size= 270336 bytes
Logical address: 0xC0000000
Area 0: C0000000 to C0001FFF (RO) Bootstrap
Area 1: C0002000 to C0003FFF Environment
Area 2: C0004000 to C0041FFF (RO) U-Boot
Version details
U-Boot> version
U-Boot 2013.04 (May 29 2013 - 10:30:21)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 109/523
Important commands (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 110/523
Important commands (2)
I loadb, loads, loady, load a file from the serial line to RAM
I usb, to initialize and control the USB subsystem, mainly used
for USB storage devices such as USB keys
I mmc, to initialize and control the MMC subsystem, used for
SD and microSD cards
I nand, to erase, read and write contents to NAND flash
I erase, protect, cp, to erase, modify protection and write to
NOR flash
I md, displays memory contents. Can be useful to check the
contents loaded in memory, or to look at hardware registers.
I mm, modifies memory contents. Can be useful to modify
directly hardware registers, for testing purposes.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 111/523
Environment variables commands (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 112/523
Environment variables commands (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 113/523
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
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 114/523
Important U-Boot env variables
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 116/523
Transferring files to the target
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 117/523
TFTP
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 118/523
U-boot mkimage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 119/523
Practical lab - U-Boot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 120/523
Linux kernel introduction
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 121/523
Linux kernel introduction
Linux features
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 122/523
History
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 123/523
Linux kernel key features
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 124/523
Linux kernel in the system
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 125/523
Linux kernel main roles
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 126/523
System calls
I The main interface between the kernel and user space is the
set of system calls
I About 300 system calls that provide the main kernel services
I File and device operations, networking operations,
inter-process communication, process management, memory
mapping, timers, threads, synchronization primitives, etc.
I This interface is stable over time: only new system calls can
be added by the kernel developers
I 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
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 127/523
Pseudo filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 128/523
Inside the Linux kernel
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 129/523
Linux license
I The whole Linux sources are Free Software released under the
GNU General Public License version 2 (GPL v2).
I For the Linux kernel, this basically implies that:
I 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.
I When you produce Linux based devices, you must release the
sources to the recipient, with the same rights, with no
restriction.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 130/523
Supported hardware architectures
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 131/523
Linux kernel introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 132/523
Until 2.6 (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 133/523
Until 2.6 (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 134/523
Changes since Linux 2.6
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 135/523
3.x stable branch
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 136/523
New development model
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 137/523
New development model - Details
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 138/523
More stability for the kernel source tree
I Very difficult to find out the key changes and to get the global
picture out of individual changes.
I Fortunately, there are some useful resources available
I http://wiki.kernelnewbies.org/LinuxChanges
I http://lwn.net
I http://linuxfr.org, for French readers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 140/523
Linux kernel introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 141/523
Location of kernel sources
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 142/523
Getting Linux sources
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 143/523
Linux kernel size (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 145/523
Getting Linux sources
I Full tarballs
I Contain the complete kernel sources: long to download and
uncompress, but must be done at least once
I Example:
http://www.kernel.org/pub/linux/kernel/v3.x/linux-
3.10.9.tar.xz
I Extract command:
tar xf linux-3.10.9.tar.xz
I Incremental patches between versions
I It assumes you already have a base version and you apply the
correct patches in the right order. Quick to download and
apply
I 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)
I All previous kernel versions are available in
http://kernel.org/pub/linux/kernel/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 146/523
Patch
I A patch is the difference between two source trees
I Computed with the diff tool, or with more elaborate version
control systems
I They are very common in the open-source community
I Excerpt from a patch:
# *DOCUMENTATION*
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 147/523
Contents of a patch
# *DOCUMENTATION*
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 148/523
Using the patch command
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 149/523
Applying a Linux patch
I Two types of Linux patches:
I Either to be applied to the previous stable version
(from 3.<x-1> to 3.x)
I Or implementing fixes to the current stable version
(from 3.x to 3.x.y)
I Can be downloaded in gzip, bzip2 or xz (much smaller)
compressed files.
I Always produced for n=1
(that’s what everybody does... do it too!)
I Need to run the patch command inside the kernel source
directory
I 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
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 150/523
Practical lab - Kernel sources
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 151/523
Linux kernel introduction
Kernel configuration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 152/523
Kernel configuration and build system
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 153/523
Kernel configuration (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 154/523
Kernel configuration (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 155/523
Kernel or module?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 156/523
Kernel option types
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 157/523
Kernel option dependencies
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 158/523
make xconfig
make xconfig
I The most common graphical interface to configure the kernel.
I Make sure you read
help -> introduction: useful options!
I File browser: easier to load configuration files
I Search interface to look for parameters
I Required Debian / Ubuntu packages: libqt4-dev g++
(libqt3-mt-dev for older kernel releases)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 159/523
make xconfig screenshot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 160/523
make xconfig search interface
Looks for a keyword in the parameter name. Allows to select or
unselect found parameters.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 161/523
Kernel configuration options
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 162/523
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
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 163/523
make gconfig
make gconfig
I GTK based graphical
configuration interface.
Functionality similar to that
of make xconfig.
I Just lacking a search
functionality.
I Required Debian packages:
libglade2-dev
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 164/523
make menuconfig
make menuconfig
I Useful when no graphics are
available. Pretty convenient
too!
I Same interface found in
other tools: BusyBox,
Buildroot...
I Required Debian packages:
libncurses-dev
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 165/523
make nconfig
make nconfig
I A newer, similar text
interface
I More user friendly (for
example, easier to access
help information).
I Required Debian packages:
libncurses-dev
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 166/523
make oldconfig
make oldconfig
I Needed very often!
I Useful to upgrade a .config file from an earlier kernel release
I Issues warnings for configuration parameters that no longer
exist in the new kernel.
I 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!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 167/523
Undoing configuration changes
A frequent problem:
I After changing several kernel configuration settings, your
kernel no longer works.
I If you don’t remember all the changes you made, you can get
back to your previous configuration:
$ cp .config.old .config
I All the configuration interfaces of the kernel (xconfig,
menuconfig, oldconfig...) keep this .config.old backup
copy.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 168/523
Configuration per architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 169/523
Linux kernel introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 170/523
Kernel compilation
I make
I in the main kernel source directory
I Remember to run multiple jobs in parallel if you have multiple
CPU cores. Example: make -j 4
I No need to run as root!
I Generates
I vmlinux, the raw uncompressed kernel image, in the ELF
format, useful for debugging purposes, but cannot be booted
I arch/<arch>/boot/*Image, the final, usually compressed,
kernel image that can be booted
I bzImage for x86, zImage for ARM, vmImage.gz for Blackfin,
etc.
I arch/<arch>/boot/dts/*.dtb, compiled Device Tree files
(on some architectures)
I All kernel modules, spread over the kernel source tree, as .ko
files.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 171/523
Kernel installation
I make install
I Does the installation for the host system by default, so needs
to be run as root. Generally not used when compiling for an
embedded system, as it installs files on the development
workstation.
I Installs
I /boot/vmlinuz-<version>
Compressed kernel image. Same as the one in
arch/<arch>/boot
I /boot/System.map-<version>
Stores kernel symbol addresses
I /boot/config-<version>
Kernel configuration for this version
I Typically re-runs the bootloader configuration utility to take
the new kernel into account.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 172/523
Module installation
I make modules_install
I Does the installation for the host system by default, so needs
to be run as root
I Installs all modules in /lib/modules/<version>/
I kernel/
Module .ko (Kernel Object) files, in the same directory
structure as in the sources.
I modules.alias
Module aliases for module loading utilities. Example line:
alias sound-service-?-0 snd_mixer_oss
I modules.dep
Module dependencies
I modules.symbols
Tells which module a given symbol belongs to.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 173/523
Kernel cleanup targets
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 174/523
Linux kernel introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 175/523
Cross-compiling the kernel
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 176/523
Specifying cross-compilation (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 177/523
Specifying cross-compilation (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 178/523
Predefined configuration files
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 179/523
Configuring the kernel
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 180/523
Device Tree
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 181/523
Building and installing the kernel
I Run make
I Copy the final kernel image to the target storage
I can be uImage, zImage, vmlinux, bzImage in
arch/<arch>/boot
I copying the Device Tree Blob might be necessary as well, they
are available in arch/<arch>/boot/dts
I make install is rarely used in embedded development, as
the kernel image is a single file, easy to handle
I It is however possible to customize the make install behaviour
in arch/<arch>/boot/install.sh
I make modules_install is used even in embedded
development, as it installs many modules and description files
I make INSTALL_MOD_PATH=<dir>/ modules_install
I The INSTALL_MOD_PATH variable is needed to install the
modules in the target root filesystem instead of your host root
filesystem.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 182/523
Booting with U-Boot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 183/523
Kernel command line
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 184/523
Practical lab - Kernel cross-compiling
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 185/523
Linux kernel introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 186/523
Advantages of modules
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 187/523
Module dependencies
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 188/523
Kernel log
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 189/523
Module utilities (1)
I modinfo <module_name>
modinfo <module_path>.ko
Gets information about a module: parameters, license,
description and dependencies.
Very useful before deciding to load a module or not.
I sudo insmod <module_path>.ko
Tries to load the given module. The full path to the module
object file must be given.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 190/523
Understanding module loading issues
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 191/523
Module utilities (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 192/523
Module utilities (3)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 193/523
Passing parameters to modules
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 194/523
Check module parameter values
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 195/523
Useful reading
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 196/523
Linux Root Filesystem
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 197/523
Linux Root Filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 198/523
Filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 199/523
Filesystems (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 200/523
mount / umount
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 201/523
Root filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 202/523
Location of the root filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 203/523
Mounting rootfs from storage devices
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 204/523
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:
I Makes it very easy to update files on the root filesystem,
without rebooting. Much faster than through the serial port.
I Can have a big root filesystem even if you don’t have support
for internal or external storage yet.
I 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).
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 205/523
Mounting rootfs over the network (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 206/523
Mounting rootfs over the network (3)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 207/523
Mounting rootfs over the network (4)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 208/523
rootfs in memory: initramfs (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 210/523
rootfs in memory: initramfs (3)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 211/523
Linux Root Filesystem
Contents
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 212/523
Root filesystem organization
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 213/523
Important directories (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 214/523
Important directories (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 215/523
Separation of programs and libraries
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 216/523
Linux Root Filesystem
Device Files
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 217/523
Devices
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 218/523
Types of devices
I Block devices
I A device composed of fixed-sized blocks, that can be read and
written to store data
I Used for hard disks, USB keys, SD cards, etc.
I Character devices
I Originally, an infinite stream of bytes, with no beginning, no
end, no size. The pure example: a serial port.
I Used for serial ports, terminals, but also sound cards, video
acquisition devices, frame buffers
I Most of the devices that are not block devices are represented
as character devices by the Linux kernel
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 219/523
Devices: everything is a file
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 220/523
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);
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 221/523
Creating device files
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 222/523
Linux Root Filesystem
Pseudo Filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 223/523
proc virtual filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 225/523
sysfs filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 226/523
Linux Root Filesystem
Minimal filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 227/523
Basic applications
I In order to work, a Linux system needs at least a few
applications
I An init application, which is the first user space application
started by the kernel after mounting the root filesystem
I The kernel tries to run /sbin/init, /bin/init, /etc/init
and /bin/sh.
I In the case of an initramfs, it will only look for /init.
Another path can be supplied by the rdinit kernel argument.
I If none of them are found, the kernel panics and the boot
process is stopped.
I The init application is responsible for starting all other user
space applications and services
I Usually a shell, to allow a user to interact with the system
I Basic Unix applications, to copy files, move files, list files
(commands like mv, cp, mkdir, cat, etc.)
I These basic components have to be integrated into the root
filesystem to make it usable
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 228/523
Overall booting process
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 229/523
Overall booting process with initramfs
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 230/523
Busybox
Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 231/523
Why Busybox?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 232/523
General purpose toolbox: BusyBox
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 233/523
BusyBox commands!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 234/523
Applet highlight: Busybox init
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 235/523
Applet highlight - BusyBox vi
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 236/523
Configuring BusyBox
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 237/523
BusyBox make xconfig
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 238/523
Compiling BusyBox
I Set the cross-compiler prefix in the configuration interface:
BusyBox Settings -> Build Options -
> Cross Compiler prefix
Example: arm-linux-
I Set the installation directory in the configuration interface:
BusyBox Settings -> Installation Options -
> BusyBox installation prefix
I Add the cross-compiler path to the PATH environment
variable:
export PATH=/usr/xtools/arm-unknown-linux-
uclibcgnueabi/bin:$PATH
I Compile BusyBox:
make
I Install it (this creates a Unix directory structure symbolic links
to the busybox executable):
make install
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 239/523
Practical lab - A tiny embedded system
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 240/523
Block filesystems
Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 241/523
Block vs. flash
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 242/523
Block device list
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 243/523
Traditional block filesystems
Traditional filesystems
I Can be left in a non-coherent state after a system crash or
sudden poweroff, which requires a full filesystem check after
reboot.
I ext2: traditional Linux filesystem
(repair it with fsck.ext2)
I vfat: traditional Windows filesystem
(repair it with fsck.vfat on GNU/Linux or Scandisk on
Windows)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 244/523
Journaled filesystems
I Designed to stay in a
correct state even
after system crashes
or a sudden poweroff
I All writes are first
described in the
journal before being
committed to files
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 245/523
Filesystem recovery after crashes
I Thanks to the
journal, the filesystem
is never left in a
corrupted state
I Recently saved data
could still be lost
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 246/523
Journaled block filesystems
Journaled filesystems
I ext3: ext2 with journal extension
ext4: newest version in the family with many improvements.
I Btrfs (“Butter FS”)
The next generation. Great performance. Now used in major
GNU/Linux distros.
I The Linux kernel supports many other filesystems: reiserFS,
JFS, XFS, etc. Each of them have their own characteristics,
but are more oriented towards server or scientific workloads.
I It’s easy to switch filesystems. The best is to try each and find
out which yields the best performance on your own system.
We recommend ext2 for very small partitions (< 5 MB), because
other filesystems need too much space for metadata (ext3 and
ext4 need about 1 MB for a 4 MB partition).
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 247/523
Creating ext2/ext3/ext4 volumes
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 248/523
Mounting filesystem images
I Once a filesystem image has been created, one can access and
modifies its contents from the development workstation, using
the loop mechanism
I Example:
genext2fs -d rootfs/ rootfs.img
mkdir /tmp/tst
mount -t ext2 -o loop rootfs.img /tmp/tst
I In the /tmp/tst directory, one can access and modify the
contents of the rootfs.img file.
I This is possible thanks to loop, which is a kernel driver that
emulates a block device with the contents of a file.
I Do not forget to run umount before using the filesystem
image!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 249/523
F2FS
http://en.wikipedia.org/wiki/F2FS
I Filesystem optimized for block devices based on NAND flash
I Available in the mainline Linux kernel
I Benchmarks: best performer on flash devices most of the time:
See http://lwn.net/Articles/520003/
I Technical details: http://lwn.net/Articles/518988/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 250/523
Squashfs
Squashfs: http://squashfs.sourceforge.net
I Read-only, compressed filesystem for block devices. Fine for
parts of a filesystem which can be read-only (kernel,
binaries...)
I Great compression rate and read access performance
I Used in most live CDs and live USB distributions
I Supports LZO compression for better performance on
embedded systems with slow CPUs (at the expense of a
slightly degraded compression rate)
I Now supports the XZ algorithm, for a much better
compression rate, at the expense of higher CPU usage and
time.
Benchmarks: (roughly 3 times smaller than ext3, and 2-4 times
faster)
http://elinux.org/Squash_Fs_Comparisons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 251/523
Squashfs - How to use
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 252/523
tmpfs
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 253/523
Mixing read-only and read-write filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 254/523
Practical lab - Block filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 255/523
Flash filesystems
Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 256/523
The MTD subsystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 257/523
MTD devices
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 258/523
MTD partitioning
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 259/523
Definition of MTD partitions (1)
The Device Tree is the standard place to device MTD partitions for
boards with Device Tree support.
Example from arch/arm/boot/dts/omap3-igep0020.dts:
nand@0,0 {
linux,mtd-name= "micron,mt29c4g96maz";
[...]
partition@0 {
label = "SPL";
reg = <0 0x100000>;
};
partition@0x80000 {
label = "U-Boot";
reg = <0x100000 0x180000>;
};
[...]
partition@0x780000 {
label = "Filesystem";
reg = <0x680000 0x1f980000>;
};
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 260/523
Definition of MTD partitions (2)
For boards or platforms that do not use the Device Tree, MTD
partitions can be defined in the kernel. Legacy example from
arch/arm/mach-omap2/board-igep0020.c (removed in 3.13):
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 262/523
Modifying MTD partitions (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 263/523
Modifying MTD partitions (3)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 264/523
mtd-utils
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 265/523
jffs2
I Today’s standard filesystem for MTD flash
I Nice features: on the fly compression
(saves storage space and reduces I/O),
power down reliable, wear-leveling and
ECC.
I Drawbacks: doesn’t scale well
I Mount time depending on filesystem
size: the kernel has to scan the whole
filesystem at mount time, to read which
block belongs to each file.
I Need to use the
CONFIG_JFFS2_SUMMARY kernel option
to store such information in flash. This
dramatically reduces mount time (from
16 s to 0.8 s for a 128 MB partition).
I http://www.linux-
mtd.infradead.org/doc/jffs2.html
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 266/523
jffs2 - How to use
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 267/523
How to create a jffs2 image
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 268/523
Mounting a jffs2 image on your host
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 269/523
Initializing jffs2 partitions from U-boot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 270/523
Booting from a jffs2 root partition
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 271/523
yaffs2
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 272/523
yaffs2 - How to use
I Erase a partition:
flash_eraseall /dev/mtd2
I The filesystem is automatically formatted at the first mount:
mount -t yaffs2 /dev/mtdblock2 /mnt/flash
I Images can be created with the mkyaffs tool, from
yaffs-utils
http://code.google.com/p/yaffs2utils/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 273/523
UBI (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 274/523
UBI (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 275/523
UBIFS
http://www.linux-
mtd.infradead.org/doc/ubifs.html
I The next generation of the jffs2
filesystem, from the same linux-mtd
developers.
I Works on top of UBI volumes
I Has a noticeable metadata overhead on
very small partitions (4M, 8M)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 276/523
UBI layout example
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 277/523
UBI - Preparation
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 278/523
UBI - Volume management
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 279/523
UBIFS - How to use
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 280/523
Ubinize (1)
After creating images of UBIFS filesystems, images of a full UBI
space, containing several volumes, can be created using ubinize:
I Can be written to a raw MTD partition in U-boot.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 281/523
Ubinize (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 282/523
UBIFS - How to prepare a root fs
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 283/523
Flash filesystem benchmarks
http://elinux.org/Flash_Filesystem_Benchmarks
I jffs2
I Worst performance
I Requires CONFIG_SUMMARY to have acceptable boot time
I yaffs2
I Good performance, but not in mainline Linux
I ubifs
I Best solution and performance for medium and big partitions
I Too much metadata overhead small partitions (only case when
yaffs2 and jffs2 are still useful)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 284/523
Issues with flash-based block storage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 285/523
Reducing the number of writes
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 286/523
Useful reading
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 287/523
Practical lab - Flash Filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 288/523
Embedded Linux system development
Embedded Linux
system Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 289/523
Contents
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 290/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 291/523
Third party libraries and applications
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 292/523
Find existing components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 293/523
Choosing components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 294/523
Licenses (1)
I All software that are under a free software license give four
freedoms to all users
I Freedom to use
I Freedom to study
I Freedom to copy
I Freedom to modify and distribute modified copies
I See http://www.gnu.org/philosophy/free-sw.html for
a definition of Free Software
I Open Source software, as per the definition of the Open
Source Initiative, are technically similar to Free Software in
terms of freedoms
I See http://www.opensource.org/docs/osd for the
definition of Open Source Software
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 295/523
Licenses (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 296/523
GPL
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 297/523
GPL: redistribution
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 298/523
LGPL
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 300/523
Non-copyleft licenses
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 301/523
BSD license
[...]
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 302/523
Is this free software?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 303/523
Respect free software licenses
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 306/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 307/523
ssh server and client: Dropbear
http://matt.ucc.asn.au/dropbear/dropbear.html
I Very small memory footprint ssh server for embedded systems
I Satisfies most needs. Both client and server!
I Size: 110 KB, statically compiled with uClibc on i386.
(OpenSSH client and server: approx 1200 KB, dynamically
compiled with glibc on i386)
I Useful to:
I Get a remote console on the target device
I Copy files to and from the target device (scp or rsync -e ssh).
I An alternative to OpenSSH, used on desktop and server
systems.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 308/523
Benefits of a web server interface
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 309/523
Web servers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 310/523
Network utilities (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 311/523
Network utilities (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 312/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 313/523
System utilities
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 314/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 315/523
Language interpreters
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 316/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 317/523
Audio, video and multimedia
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 318/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 319/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 320/523
DirectFB
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 321/523
DirectFB: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 322/523
DirectFB: usage
I Multimedia applications
I For example the Disko framework, for set-top box related
applications
I “Simple” graphical applications
I Industrial control
I Device control with limited number of widgets
I Visualization applications
I As a lower layer for higher-level graphical libraries
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 323/523
DirectFB: screenshot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 324/523
X.org - KDrive
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 325/523
Kdrive: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 326/523
Kdrive: usage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 327/523
Wayland
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 328/523
Wayland: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 329/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 330/523
Gtk
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 331/523
Gtk stack components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 332/523
Gtk examples (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 333/523
Gtk examples (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 334/523
Qt (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 335/523
Qt (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 336/523
Qt’s usage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 337/523
Other less frequent solutions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 338/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 339/523
Lightweight database - SQLite
http://www.sqlite.org
I SQLite is a small C library that implements a self-contained,
embeddable, lightweight, zero-configuration SQL database
engine
I The database engine of choice for embedded Linux systems
I Can be used as a normal library
I Can be directly embedded into a application, even a
proprietary one since SQLite is released in the public domain
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 340/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 341/523
WebKit
http://webkit.org/
I Web browser engine. Application framework that
can be used to develop web browsers.
I License: portions in LGPL and others in BSD.
Proprietary applications allowed.
I 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
I Multiple graphical back-ends: Qt4, GTK, EFL...
I You could use it to create your custom browser.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 342/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 343/523
Industrial applications
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 344/523
Digital Photo Frame: requirements
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 345/523
Digital Photo Frame: components (1)
I Base system
I Components present in virtually all embedded Linux systems
I The U-Boot bootloader
I Linux Kernel
I Drivers for SD/MMC, framebuffer, sound, input devices
I Busybox
I Build system, in this case was OpenEmbedded
I Components: u-boot, Linux, busybox
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 346/523
Digital Photo Frame: components (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 347/523
Digital Photo Frame: components (3)
I JPEG display
I libjpeg to decode the pictures
I jpegtran to resize and rotate them
I FIM (Fbi Improved) for dithering
I MP3 support
I libmad for playing
I libid3 for ID3 tags reading
I libm3u to support playlists
I Used vendor-provided components to leverage the DSP to play
MP3
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 348/523
Digital Photo Frame: components (4)
I 3D interface
I Vincent, an open-source implementation of OpenGL ES
I Clutter, higher-level API to develop 3D applications
I Application itself
I Manages media events
I Uses the JPEG libraries to decode and render pictures
I Receives Linux input events from buttons and draws
OpenGL-based UI developed with Clutter
I Manage a user-defined configuration
I Play the music with the MP3-related libraries
I Display photo slideshow
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 349/523
Embedded Linux system development
System building
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 350/523
System building: goal and solutions
I Goal
I Integrate all the software components, both third-party and
in-house, into a working root filesystem
I It involves the download, extraction, configuration, compilation
and installation of all components, and possibly fixing issues
and adapting configuration files
I Several solutions
I Manually
I System building tools
I Distributions or ready-made filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 351/523
System building: manually
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 352/523
System building: manually (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 353/523
System foundations
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 354/523
Target and build spaces
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 355/523
Build systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 356/523
Autotools and friends
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 357/523
automake / autoconf / autoheader
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 358/523
automake / autoconf
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 359/523
Configuring and compiling: native case
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 360/523
Configuring and compiling: cross case (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 361/523
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
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 362/523
Installation (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 363/523
Installation (2)
Contents of usr/lib after installation of libpng and zlib
I libpng libtool description files
./lib/libpng12.la
./lib/libpng.la -> libpng12.la
I libpng static version
./lib/libpng12.a
./lib/libpng.a -> libpng12.a
I 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
I libpng pkg-config description files
./lib/pkgconfig/libpng12.pc
./lib/pkgconfig/libpng.pc -> libpng12.pc
I 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
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 364/523
Installation in the build and target spaces
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 365/523
pkg-config
I pkg-config is a tool that allows to query a small database to
get information on how to compile programs that depend on
libraries
I The database is made of .pc files, installed by default in
<prefix>/lib/pkgconfig/.
I pkg-config is used by the configure script to get the
library configurations
I It can also be used manually to compile an application:
arm-linux-gcc -o test test.c $(pkg-config --
libs --cflags thelib)
I By default, pkg-config looks in /usr/lib/pkgconfig for
the *.pc files, and assumes that the paths in these files are
correct.
I 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.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 366/523
Let’s find the libraries
I Manually cross-compiling
applications and libraries
I Learning about common techniques
and issues.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 368/523
System building tools: principle
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 369/523
Available system building tools
Large choice of tools
I Buildroot, developed by the community
http://www.buildroot.net
I PTXdist, developed by Pengutronix
http://pengutronix.de/software/ptxdist/
I OpenWRT, originally a fork of Buildroot for wireless routers, now a
more generic project
http://www.openwrt.org
I LTIB. Good support for Freescale boards, but small community
http://ltib.org/
I OpenEmbedded, more flexible but also far more complicated
http://www.openembedded.org, its industrialized version Yocto
Project and vendor-specific derivatives such as Arago.
See our dedicated course and training materials:
http://free-electrons.com/training/yocto/.
I Vendor specific tools (silicon vendor or embedded Linux vendor)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 370/523
Buildroot (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 371/523
Buildroot (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 372/523
Buildroot: adding a new package (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 373/523
Buildroot: adding a new package (2)
http://prdownloads.sourceforge.net/gqview
source "package/gqview/Config.in"
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 374/523
Buildroot: adding new package (3)
$(eval $(autotools-package))
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 375/523
OpenEmbedded / Yocto Project
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 376/523
Distributions - Debian
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 377/523
Distributions - Others
Fedora
I http://fedoraproject.org/wiki/
Architectures/ARM
I Supported on various recent ARM boards
(such as Beaglebone Black). Pidora
supports Raspberry Pi too.
I Supports QEMU emulated ARM boards
too (Versatile Express board)
I Shipping the same version as for desktops!
Ubuntu
I Had some releases for ARM mobile
multimedia devices, but stopped at
version 12.04. Now focusing on ARM
servers only.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 378/523
Embedded distributions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 379/523
Application frameworks
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 380/523
System emulator: QEMU
http://qemu.org
Fast processor emulator
I Useful to develop root filesystems and applications when the
hardware is not available yet (binary compatible development
boards are also possible).
I Emulates the processor and various peripherals (“System
emulation): x86, ppc, arm, sparc, mips, m68k...
I Many different ARM boards supported:
qemu-system-arm -M ?
I QEMU also allows to just run binaries for other architectures
(“User emulation”). Used inside some building tools.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 381/523
Practical lab - Buildroot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 382/523
Embedded Linux system development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 383/523
Commercial embedded Linux solutions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 384/523
Commercial solution strengths
I Technical advantages
I Well tested and supported I Graphical developments
kernel and tool versions tools
I Often supporting patches
not supported by the I Development tools available
mainline kernel yet on multiple platforms: GNU
(example: real-time / Linux, Solaris, Windows...
patches) I Support services
I Complete development tool I Useful if you don’t have
sets: kernels, toolchains, your own support
utilities, binaries for resources
impressive lists of target
I Long term support
commitment, even for
platforms
versions considered as
I Integrated utilities for obsolete by the
automatic kernel image, community, but not by
initramfs and filesystem your users!
generation.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 385/523
Commercial or community solutions?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 386/523
Embedded Linux application development
Embedded Linux
application Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 387/523
Contents
I Application development
I Developing applications on embedded Linux
I Building your applications
I Source management
I Integrated development environments (IDEs)
I Version control systems
I Debugging and analysis tools
I Debuggers
I Memory checkers
I System analysis
I Development environments
I Developing on Windows
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 388/523
Embedded Linux application development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 389/523
Application development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 390/523
Programming language
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 391/523
C library or higher-level libraries?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 392/523
Building your applications
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 393/523
Simple Makefile (1)
CROSS_COMPILE?=arm-linux-
CC=$(CROSS_COMPILE)gcc
OBJS=foo.o bar.o
all: foobar
foobar: $(OBJS)
$(CC) -o $@ $^
clean:
$(RM) -f foobar $(OBJS)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 394/523
Simple Makefile (2)
I 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)
clean:
$(RM) -f foobar $(OBJS)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 395/523
Embedded Linux application development
Integrated Development
Environments (IDE)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 396/523
KDevelop
http://kdevelop.org
I A full featured IDE!
I License: GPL
I Supports many languages: Ada, C, C++,
Database, Java, Perl, PHP, Python, Ruby, Shell
I Supports many kinds of projects: KDE, but also
GTK, Gnome, kernel drivers, embedded (Opie)...
I Many features: editor, syntax highlighting, code
completion, compiler interface, debugger
interface, file manager, class browser...
Nice overview:
http://en.wikipedia.org/wiki/Kdevelop
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 397/523
KDevelop screenshot
Ruby debugger
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 398/523
Eclipse (1)
http://www.eclipse.org/
I An extensible, plug-in based software
development kit, typically used for creating IDEs.
I Supported by the Eclipse foundation, a
non-profit consortium of major software industry
vendors (IBM, Intel, Borland, Nokia, Wind
River, Zend, Computer Associates...).
I Free Software license (Eclipse Public License).
Incompatible with the GPL.
I Supported platforms: GNU/Linux, Unix,
Windows
Extremely popular: created a lot of attraction.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 399/523
Eclipse (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 400/523
Other popular solutions
Vim
I 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.
I Geany is an easy-to-use graphical
code editor.
Emacs
I 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!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 401/523
Embedded Linux application development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 402/523
Version control systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 403/523
Traditional version control systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 404/523
Distributed source control systems (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 405/523
Distributed source control systems (2)
I Git
I Initially designed and developed by Linus Torvalds for Linux
kernel development
I Extremely popular in the community, and used by more and
more projects (kernel, U-Boot, Barebox, uClibc, GNOME,
X.org, etc.)
I Outstanding performance, in particular in big projects
I http://en.wikipedia.org/wiki/Git_(software)
I Mercurial
I Another system, created with the same goals as Git.
I Used by some big projects too
I http://en.wikipedia.org/wiki/Mercurial
http://en.wikipedia.org/wiki/Version_control_systems#
Distributed_revision_control
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 406/523
Embedded Linux application development
Debuggers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 407/523
GDB
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 408/523
GDB crash course
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 409/523
GDB graphical front-ends
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 410/523
Embedded Linux application development
Remote debugging
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 411/523
Remote debugging
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 412/523
Remote debugging: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 413/523
Remote debugging: usage
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 414/523
Post mortem analysis
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 415/523
Embedded Linux application development
Memory checkers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 416/523
DUMA
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 417/523
Valgrind (1)
http://valgrind.org/
I GNU GPL Software suite for debugging and
profiling programs.
I Supported platforms: Linux on x86, x86 64,
ppc32, ppc64 and arm (armv7 only: Cortex A8,
A9 and A5)
I Can detect many memory management and
threading bugs.
I Profiler: provides information helpful to speed
up your program and reduce its memory usage.
I The most popular tool for this usage. Even used
by projects with hundreds of programmers.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 418/523
Valgrind (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 419/523
Embedded Linux application development
System analysis
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 420/523
strace
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 422/523
ltrace
A tool to trace library calls used by a program and all the signals it
receives
I Very useful complement to strace, which shows only system
calls.
I Of course, works even if you don’t have the sources
I Allows to filter library calls with regular expressions, or just by
a list of function names.
I Manual page: http://linux.die.net/man/1/ltrace
See http://en.wikipedia.org/wiki/Ltrace for details
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 423/523
ltrace example output
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 424/523
ltrace summary
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 425/523
OProfile
http://oprofile.sourceforge.net
I A system-wide profiling tool
I Can collect statistics like the top users of the CPU.
I Works without having the sources.
I Requires a kernel patch to access all features, but is already
available in a standard kernel.
I Requires more investigation to see how it works.
I Ubuntu/Debian packages: oprofile, oprofile-gui
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 426/523
Callgrind / KCachegrind
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 427/523
KCachegrind screenshot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 428/523
Practical lab - App. development and debugging
Application development
I Compile your own application with
the ncurses library
Remote debugging
I Set up remote debugging tools on
the target: strace, ltrace
and gdbserver.
I Debug a simple application running
on the target using remote
debugging
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 429/523
Embedded Linux application development
Developing on Windows
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 430/523
Developing on Windows!?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 431/523
Cygwin
http://cygwin.com/
Linux (POSIX)-like environment for Windows
I 2 components:
Linux API emulation layer: cygwin1.dll
A collection of tools originally found in
GNU/Linux
I Allows to compile and run many GNU/Linux
programs on Windows: shells, compiler, http
servers, X Window, GTK...
I Very easy to install. Can choose which tools to
download and install.
I For embedded Linux system developers: makes it
possible to use GNU toolchains (compiled for
Windows) required to build Linux binaries
(kernel, libraries or applications).
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 432/523
Cygwin limitations
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 433/523
VirtualBox
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 434/523
Real-time in embedded Linux systems
Real-time in
embedded Linux Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 435/523
Real-time in embedded Linux systems
Introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 436/523
Embedded Linux and real time
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 437/523
Embedded Linux and real time
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 438/523
Linux and real-time approaches (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 439/523
Linux and real-time approaches (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 440/523
Real-time in embedded Linux systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 441/523
Understanding latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 442/523
Linux kernel latency components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 443/523
Interrupt latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 444/523
Sources of interrupt latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 445/523
Interrupt handler duration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 446/523
Interrupt handler implementation
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 447/523
Scheduler latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 448/523
Understanding preemption (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 449/523
Understanding preemption (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 450/523
Scheduler duration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 451/523
Other non-deterministic mechanisms
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 452/523
Priority inversion
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 453/523
Interrupt handler priority
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 454/523
The PREEMPT RT project
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 455/523
Improvements in the mainline kernel
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 456/523
New preemption options in Linux 2.6
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 457/523
1st option: no forced preemption
CONFIG_PREEMPT_NONE
Kernel code (interrupts, exceptions, system calls) never preempted.
Default behavior in standard kernels.
I Best for systems making intense computations, on which
overall throughput is key.
I Best to reduce task switching to maximize CPU and cache
usage (by reducing context switching).
I Still benefits from some Linux 2.6 improvements: O(1)
scheduler, increased multiprocessor safety (work on RT
preemption was useful to identify hard to find SMP bugs).
I Can also benefit from a lower timer frequency (100 Hz instead
of 250 or 1000).
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 458/523
2nd option: voluntary kernel preemption
CONFIG_PREEMPT_VOLUNTARY
Kernel code can preempt itself
I Typically for desktop systems, for quicker application reaction
to user input.
I Adds explicit rescheduling points throughout kernel code.
I Minor impact on throughput.
I Used in: Ubuntu Desktop 13.04, Ubuntu Server 12.04
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 459/523
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.
I 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.
I Typically for desktop or embedded systems with latency
requirements in the milliseconds range.
I Still a relatively minor impact on throughput.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 460/523
Priority inheritance
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 461/523
High resolution timers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 462/523
Threaded interrupts
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 463/523
The future of the PREEMPT RT patchset
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 464/523
Real-time in embedded Linux systems
PREEMPT RT specifics
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 465/523
CONFIG PREEMPT RT (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 466/523
CONFIG PREEMPT RT (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 467/523
Threaded interrupts
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 468/523
Real-time in embedded Linux systems
Setting up PREEMPT RT
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 469/523
PREEMPT RT setup (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 470/523
PREEMPT RT setup (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 471/523
Real-time in embedded Linux systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 472/523
Development and compilation
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 473/523
Process, thread?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 474/523
Process, thread: kernel point of view
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 475/523
Creating threads
I The new thread will run in the same address space, but will
be scheduled independently
I Exiting from a thread
pthread_exit(void *value_ptr);
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 476/523
Scheduling classes (1)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 477/523
Scheduling classes (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 478/523
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);
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 479/523
Memory locking
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 480/523
Mutexes
pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *mutexattr);
pthread_mutex_destroy(pthread_mutex_t *mutex);
I Lock/unlock
pthread_mutex_lock(pthread_mutex_t *mutex);
pthread_mutex_unlock(pthread_mutex_t *mutex);
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 481/523
Timers
I Timer creation
timer_create(clockid_t clockid, struct sigevent *evp,
timer_t *timerid);
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 482/523
Timers (2)
I Delete a timer
timer_delete(timer_t timerid)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 483/523
Signals
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 484/523
Inter-process communication
I Semaphores
I Usable between different processes using named semaphores
I sem_open(), sem_close(), sem_unlink(), sem_init(),
sem_destroy(), sem_wait(), sem_post(), etc.
I Message queues
I Allows processes to exchange data in the form of messages.
I mq_open(), mq_close(), mq_unlink(), mq_send(),
mq_receive(), etc.
I Shared memory
I Allows processes to communicate by sharing a segment of
memory
I shm_open(), ftruncate(), mmap(), munmap(), close(),
shm_unlink()
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 485/523
Real-time in embedded Linux systems
Debugging latencies in
PREEMPT RT
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 486/523
ftrace - Kernel function tracer
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 487/523
Using ftrace
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 488/523
Scheduling latency tracer
CONFIG_SCHED_TRACER (Kernel Hacking section)
I Maximum recorded time between waking up a top priority task and
its scheduling on a CPU, expressed in us.
I Check that wakeup is listed in
/sys/kernel/debug/tracing/available_tracers
I To select, reset and enable this tracer:
echo wakeup > /sys/kernel/debug/tracing/current_tracer
echo 0 > /sys/kernel/debug/tracing/tracing_max_latency
echo 1 > /sys/kernel/debug/tracing/tracing_enabled
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 490/523
Useful reading
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 491/523
Real-time in embedded Linux systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 492/523
Linux real-time extensions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 493/523
RTLinux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 494/523
RTAI
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 495/523
Xenomai project
http://www.xenomai.org/
I Started in 2001 as a project aiming at emulating
traditional RTOS.
I Initial goals: facilitate the porting of programs to
GNU / Linux.
I Initially related to the RTAI project (as the RTAI
/ fusion branch), now independent.
I Skins mimicking the APIs of traditional RTOS
such as VxWorks, pSOS+, and VRTXsa as well
as the POSIX API, and a “native” API.
I Aims at working both as a co-kernel and on top
of PREEMPT RT in future upstream Linux
versions.
I Will never be merged in the mainline kernel.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 496/523
Xenomai architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 497/523
The Adeos interrupt pipeline abstraction
I From the Adeos point of view, guest OSes are prioritized
domains.
I For each event (interrupts, exceptions, syscalls, etc...), the
various domains may handle the event or pass it down the
pipeline.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 498/523
Xenomai features
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 499/523
Xenomai user space real-time support
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 500/523
Life of a Xenomai application
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 501/523
Real Time Driver Model (RTDM)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 502/523
Real-time in embedded Linux systems
Setting up Xenomai
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 503/523
How to build Xenomai
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 504/523
Linux options for Xenomai configuration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 505/523
Xenomai user space support
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 506/523
Real-time in embedded Linux systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 507/523
The POSIX skin
I 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
I http://www.xenomai.org/index.php/Porting_POSIX_
applications_to_Xenomai
I Clocks and timers, condition variables, message queues,
mutexes, semaphores, shared memory, signals, thread
management
I Good for existing code or programmers familiar with the
POSIX API
I Of course, if the application uses any Linux service that isn’t
available in Xenomai, it will switch back to secondary mode
I To link an application against the POSIX skin
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 510/523
The native API (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 511/523
The native API (3)
I Alarm services
I rt_alarm_create(), rt_alarm_delete(),
rt_alarm_start(), rt_alarm_stop(), rt_alarm_wait(),
etc.
I Memory heap services
I Allows to share memory between processes and/or to
pre-allocate a pool of memory
I rt_heap_create(), rt_heap_delete(), rt_heap_alloc(),
rt_heap_bind()
I Condition variable services
I rt_cond_create(), rt_cond_delete(),
rt_cond_signal(), rt_cond_broadcast(),
rt_cond_wait(), etc.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 512/523
Xenomai and normal task communication
I Using rt pipes
I In the native Xenomai application, use the Pipe API
I rt_pipe_create(), rt_pipe_delete(),
rt_pipe_receive(), rt_pipe_send(), rt_pipe_alloc(),
rt_pipe_free()
I In the normal Linux application
I Open the corresponding /dev/rtpX file, the minor is specified
at rt_pipe_create() time
I Then, just read() and write() to the opened file
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 513/523
Xenomai worst-case latencies results
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 514/523
Books
http://oreilly.com/catalog/9780596529680/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 515/523
Organizations
I 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.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 516/523
Practical lab - Real-time - Scheduling latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 517/523
References
Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 518/523
Books
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 519/523
Web sites
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 520/523
International conferences
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 521/523
Last slides
Free Electrons
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 522/523
Last slide
Thank you!
And may the Source be with you
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 523/523