Professional Documents
Culture Documents
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 1/520
Rights to copy
Your fair use and other rights are in no way aected by the above.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 2/520
Hyperlinks in the document
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 3/520
Free Electrons at a glance
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 4/520
Free Electrons on-line resources
information
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 6/520
Hardware used in this training session
Using Atmel SAMA5D3 Xplained boards in all practical labs
SAMA5D36 (Cortex A5) CPU from Atmel
USB powered!
256 MB DDR2 RAM, 256 MB NAND
ash
2 Ethernet ports (Gigabit + 100 Mbit)
2 USB 2.0 host, 1 USB device
1 MMC/SD slot
3.3 V serial port (like Beaglebone Black)
Misc: Arduino R3-compatible header,
JTAG, buttons, LEDs
Currently sold at 69 EUR by Mouser
(V.A.T. not included)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 8/520
Participate!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 9/520
Practical lab guidelines
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 10/520
Advise: write down your commands!
During practical labs, write down all your commands in a text le.
You can save a lot of time re-using
commands in later labs.
This helps to replay your work if Lab commands
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 11/520
Cooperate!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 12/520
Command memento sheet
Embedded Linux
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 15/520
Birth of free software
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 16/520
Free software?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 17/520
What is embedded Linux?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 18/520
Introduction to Embedded Linux
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 19/520
Re-using components
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 20/520
Low cost
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 21/520
Full control
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 22/520
Quality
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 23/520
Eases testing of new features
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 24/520
Community support
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 25/520
Taking part into the community
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 26/520
Introduction to Embedded Linux
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 27/520
Personal routers
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 28/520
Television
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 29/520
Point of sale terminal
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 30/520
Laser cutting machine
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 31/520
Viticulture machine
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 32/520
Introduction to Embedded Linux
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 33/520
Processor and architecture (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 34/520
Processor and architecture (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 35/520
RAM and storage
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 36/520
Communication
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 37/520
Types of hardware platforms
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 38/520
Criteria for choosing the hardware
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 39/520
Introduction to Embedded Linux
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 40/520
Global architecture
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 41/520
Software components
Cross-compilation toolchain
Compiler that runs on the development machine, but generates
code for the target
Bootloader
Started by the hardware, responsible for basic initialization,
loading and executing the kernel
Linux Kernel
Contains the process and memory management, network stack,
device drivers and provides services to user space applications
C library
The interface between the kernel and the user space
applications
Libraries and applications
Third-party or in-house
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 42/520
Embedded Linux work
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 43/520
Embedded Linux development environment
Embedded Linux
development Embedded Linux
Experts
environment
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 44/520
Embedded Linux solutions
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 45/520
OS for Linux development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 46/520
Desktop Linux distribution
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 47/520
Linux root and non-root users
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 48/520
Software packages
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 49/520
Managing software packages (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 50/520
Managing software packages (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 51/520
Host vs. target
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 52/520
Serial line communication program
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 53/520
Command line tips
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 54/520
Practical lab - Training Setup
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 55/520
Cross-compiling toolchains
toolchains
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 56/520
Cross-compiling toolchains
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 57/520
Denition (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 58/520
Denition (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 59/520
Machines in build procedures
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 60/520
Dierent toolchain build procedures
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 61/520
Components
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 62/520
Binutils
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 63/520
Kernel headers (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 64/520
Kernel headers (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 65/520
Kernel headers (3)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 66/520
GCC
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 67/520
C library
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 68/520
Cross-compiling toolchains
C Libraries
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 69/520
glibc
License: LGPL
C library from the GNU project
Designed for performance, standards
compliance and portability
Found on all GNU / Linux host systems
Of course, actively maintained
By default, quite big for small embedded
systems: approx 2.5 MB on ARM (version
2.9 - libc: 1.5 MB, libm: 750 KB)
But some features not needed in
embedded systems can be congured out
(merged from the old eglibc project).
http://www.gnu.org/software/libc/
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 70/520
uClibc-ng (1)
http://uclibc-ng.org/
A continuation of the old uClibc project
License: LGPL
Lightweight C library for small embedded systems
High congurability: many features can be enabled or disabled
through a menucong interface
Supports most embedded architectures
No guaranteed binary compatibility. May need to recompile
applications when the library conguration changes.
Focus on size rather than performance
Small compile time
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 71/520
uClibc-ng (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 72/520
Honey, I shrunk the programs!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 73/520
musl C library
http://www.musl-libc.org/
A lightweight, fast and simple library for embedded systems
Created while uClibc's development was stalled
In particular, great at making small static executables
Permissive license (MIT)
Compare features with other C libraries:
http://www.etalabs.net/compare_libcs.html
Supported by build systems such as Buildroot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 74/520
Other smaller C libraries
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 75/520
Cross-compiling toolchains
Toolchain Options
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 76/520
ABI
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 77/520
Floating point support
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 79/520
Cross-compiling toolchains
Obtaining a Toolchain
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 80/520
Building a toolchain manually
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 81/520
Get a pre-compiled toolchain
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 82/520
Toolchain building utilities
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 83/520
Toolchain building utilities (2)
Crosstool-ng
Rewrite of the older Crosstool, with a menucong-like
conguration system
Feature-full: supports uClibc, glibc, musl, hard and soft oat,
many architectures
Actively maintained
http://crosstool-ng.org/
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 84/520
Toolchain building utilities (3)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 85/520
Crosstool-NG: installation and usage
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 87/520
Practical lab - Using Crosstool-NG
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 88/520
Bootloaders
Embedded Linux
Experts
Bootloaders
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 89/520
Bootloaders
Boot Sequence
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 90/520
Bootloaders
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 91/520
Bootloaders on x86 (1)
The x86 processors are typically bundled on a
board with a non-volatile memory containing a
program, the BIOS.
This program gets executed by the CPU after
reset, and is responsible for basic hardware
initialization and loading of a small piece of code
from non-volatile storage.
This piece of code is usually the rst 512 bytes
of a storage device
This piece of code is usually a 1st stage
bootloader, which will load the full bootloader
itself.
The bootloader can then oer all its features. It
typically understands lesystem formats so that
the kernel le can be loaded directly from a
normal lesystem.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 92/520
Bootloaders on x86 (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 93/520
Booting on embedded CPUs: case 1
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 94/520
Booting on embedded CPUs: case 2
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 95/520
Booting on ARM Atmel AT91
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 96/520
Booting on ARM TI OMAP3
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 97/520
Booting on Marvell SoC
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 98/520
Generic bootloaders for embedded CPUs
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 100/520
U-Boot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 101/520
U-Boot conguration
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 102/520
U-Boot conguration le 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 103/520
Conguring and compiling U-Boot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 104/520
Installing U-Boot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 105/520
U-boot prompt
Connect the target to the host through a serial console
Power-up the board. On the serial console, you will see
something like:
U-Boot 2013.04 (May 29 2013 - 10:30:21)
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 107/520
Important commands (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 108/520
Important commands (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 109/520
Environment variables commands (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 110/520
Environment variables commands (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 111/520
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 112/520
Important U-Boot env variables
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 114/520
Transferring les to the target
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 115/520
TFTP
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 116/520
Practical lab - U-Boot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 117/520
Linux kernel introduction
introduction
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 118/520
Linux kernel introduction
Linux features
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 119/520
History
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 120/520
Linux kernel key features
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 121/520
Linux kernel in the system
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 122/520
Linux kernel main roles
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 123/520
System calls
The main interface between the kernel and user space is the
set of system calls
About 300 system calls that provide the main kernel services
File and device operations, networking operations,
inter-process communication, process management, memory
mapping, timers, threads, synchronization primitives, etc.
This interface is stable over time: only new system calls can
be added by the kernel developers
This system call interface is wrapped by the C library, and
user space applications usually never make a system call
directly but rather use the corresponding C library function
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 124/520
Pseudo lesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 125/520
Inside the Linux kernel
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 126/520
Linux license
The whole Linux sources are Free Software released under the
GNU General Public License version 2 (GPL v2).
For the Linux kernel, this basically implies that:
When you receive or buy a device with Linux on it, you should
receive the Linux sources, with the right to study, modify and
redistribute them.
When you produce Linux based devices, you must release the
sources to the recipient, with the same rights, with no
restriction.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 127/520
Supported hardware architectures
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 128/520
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 129/520
Until 2.6 (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 130/520
Until 2.6 (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 131/520
Changes since Linux 2.6
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 132/520
3.x stable branch
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 133/520
New development model
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 134/520
New development model - Details
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 135/520
More stability for the kernel source tree
Very dicult to nd out the key changes and to get the global
picture out of individual changes.
Fortunately, there are some useful resources available
http://wiki.kernelnewbies.org/LinuxChanges
http://lwn.net
http://linuxfr.org, for French readers
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 137/520
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 138/520
Location of kernel sources
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 139/520
Getting Linux sources
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 140/520
Linux kernel size (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 142/520
Getting Linux sources
Full tarballs
Contain the complete kernel sources: long to download and
uncompress, but must be done at least once
Example:
http://www.kernel.org/pub/linux/kernel/v3.x/linux-
3.10.9.tar.xz
Extract command:
tar xf linux-3.10.9.tar.xz
Incremental patches between versions
It assumes you already have a base version and you apply the
correct patches in the right order. Quick to download and
apply
Examples:
http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.10.xz
(3.9 to 3.10)
http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.10.9.xz
(3.10 to 3.10.9)
All previous kernel versions are available in
http://kernel.org/pub/linux/kernel/
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 143/520
Patch
A patch is the dierence between two source trees
Computed with the diff tool, or with more elaborate version
control systems
They are very common in the open-source community
Excerpt from a patch:
# *DOCUMENTATION*
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 144/520
Contents of a patch
# *DOCUMENTATION*
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 145/520
Using the patch command
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 146/520
Applying a Linux patch
Two types of Linux patches:
Either to be applied to the previous stable version
(from 3.<x-1> to 3.x)
Or implementing xes to the current stable version
(from 3.x to 3.x.y)
Can be downloaded in gzip, bzip2 or xz (much smaller)
compressed les.
Always produced for n=1
(that's what everybody does... do it too!)
Need to run the patch command inside the kernel source
directory
Linux patch command line example:
cd linux-3.9
xzcat ../patch-3.10.xz | patch -p1
xzcat ../patch-3.10.9.xz | patch -p1
cd ..; mv linux-3.9 linux-3.10.9
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 147/520
Practical lab - Kernel sources
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 148/520
Linux kernel introduction
Kernel conguration
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 149/520
Kernel conguration and build system
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 150/520
Kernel conguration (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 151/520
Kernel conguration (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 152/520
Kernel or module?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 153/520
Kernel option types
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 154/520
Kernel option dependencies
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 155/520
make xcong
make xconfig
The most common graphical interface to congure the kernel.
Make sure you read
help -> introduction: useful options!
File browser: easier to load conguration les
Search interface to look for parameters
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 156/520
make xcong screenshot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 157/520
make xcong 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 158/520
Kernel conguration options
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 159/520
Corresponding .cong le excerpt
Options are grouped by sections and are prexed 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 160/520
make gcong
make gconfig
GTK based graphical
conguration interface.
Functionality similar to that
of make xconfig.
Just lacking a search
functionality.
Required Debian packages:
libglade2-dev
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 161/520
make menucong
make menuconfig
Useful when no graphics are
available. Pretty convenient
too!
Same interface found in
other tools: BusyBox,
Buildroot...
Required Debian packages:
libncurses-dev
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 162/520
make ncong
make nconfig
A newer, similar text
interface
More user friendly (for
example, easier to access
help information).
Required Debian packages:
libncurses-dev
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 163/520
make oldcong
make oldconfig
Needed very often!
Useful to upgrade a .config le from an earlier kernel release
Issues warnings for conguration parameters that no longer
exist in the new kernel.
Asks for values for new parameters (while xconfig and
menuconfig silently set default values for new parameters).
If you edit a .config le 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 164/520
Undoing conguration changes
A frequent problem:
After changing several kernel conguration settings, your
kernel no longer works.
If you don't remember all the changes you made, you can get
back to your previous conguration:
$ cp .config.old .config
All the conguration 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 165/520
Conguration per architecture
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 166/520
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 167/520
Kernel compilation
make
in the main kernel source directory
Remember to run multiple jobs in parallel if you have multiple
CPU cores. Example: make -j 4
No need to run as root!
Generates
vmlinux, the raw uncompressed kernel image, in the ELF
format, useful for debugging purposes, but cannot be booted
arch/<arch>/boot/*Image, the nal, usually compressed,
kernel image that can be booted
bzImage for x86, zImage for ARM, vmImage.gz for Blackn,
etc.
arch/<arch>/boot/dts/*.dtb, compiled Device Tree les (on
some architectures)
All kernel modules, spread over the kernel source tree, as .ko
les.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 168/520
Kernel installation
make install
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 les on the development
workstation.
Installs
/boot/vmlinuz-<version>
Compressed kernel image. Same as the one in
arch/<arch>/boot
/boot/System.map-<version>
Stores kernel symbol addresses
/boot/config-<version>
Kernel conguration for this version
Typically re-runs the bootloader conguration 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 169/520
Module installation
make modules_install
Does the installation for the host system by default, so needs
to be run as root
Installs all modules in /lib/modules/<version>/
kernel/
Module .ko (Kernel Object) les, in the same directory
structure as in the sources.
modules.alias
Module aliases for module loading utilities. Example line:
alias sound-service-?-0 snd_mixer_oss
modules.dep
Module dependencies
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 170/520
Kernel cleanup targets
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 171/520
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 172/520
Cross-compiling the kernel
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 173/520
Specifying cross-compilation (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 174/520
Specifying cross-compilation (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 175/520
Predened conguration les
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 176/520
Conguring the kernel
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 177/520
Device Tree
Run make
Copy the nal kernel image to the target storage
can be zImage, vmlinux, bzImage in arch/<arch>/boot
copying the Device Tree Blob might be necessary as well, they
are available in arch/<arch>/boot/dts
make install is rarely used in embedded development, as the
kernel image is a single le, easy to handle
It is however possible to customize the make install behaviour
in arch/<arch>/boot/install.sh
make modules_install is used even in embedded
development, as it installs many modules and description les
make INSTALL_MOD_PATH=<dir>/ modules_install
The INSTALL_MOD_PATH variable is needed to install the
modules in the target root lesystem instead of your host root
lesystem.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 179/520
Booting with U-Boot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 180/520
Kernel command line
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 181/520
Practical lab - Kernel cross-compiling
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 182/520
Linux kernel introduction
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 183/520
Advantages of modules
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 184/520
Module dependencies
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 185/520
Kernel log
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 186/520
Module utilities (1)
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.
sudo insmod <module_path>.ko
Tries to load the given module. The full path to the module
object le must be given.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 187/520
Understanding module loading issues
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 188/520
Module utilities (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 189/520
Module utilities (3)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 190/520
Passing parameters to modules
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 191/520
Check module parameter values
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 192/520
Useful reading
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 193/520
Linux Root Filesystem
Filesystem
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 194/520
Linux Root Filesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 195/520
Filesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 196/520
Filesystems (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 197/520
mount / umount
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 198/520
Root lesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 199/520
Location of the root lesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 200/520
Mounting rootfs from storage devices
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 201/520
Mounting rootfs over the network (1)
Once networking works, your root lesystem could be a directory
on your GNU/Linux development host, exported by NFS (Network
File System). This is very convenient for system development:
Makes it very easy to update les on the root lesystem,
without rebooting. Much faster than through the serial port.
Can have a big root lesystem even if you don't have support
for internal or external storage yet.
The root lesystem 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 202/520
Mounting rootfs over the network (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 203/520
Mounting rootfs over the network (3)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 204/520
Mounting rootfs over the network (4)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 205/520
rootfs in memory: initramfs (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 207/520
rootfs in memory: initramfs (3)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 208/520
Linux Root Filesystem
Contents
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 209/520
Root lesystem organization
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 210/520
Important directories (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 211/520
Important directories (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 212/520
Separation of programs and libraries
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 213/520
Linux Root Filesystem
Device Files
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 214/520
Devices
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 215/520
Types of devices
Block devices
A device composed of xed-sized blocks, that can be read and
written to store data
Used for hard disks, USB keys, SD cards, etc.
Character devices
Originally, an innite stream of bytes, with no beginning, no
end, no size. The pure example: a serial port.
Used for serial ports, terminals, but also sound cards, video
acquisition devices, frame buers
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 216/520
Devices: everything is a le
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 217/520
Device les examples
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 218/520
Creating device les
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 219/520
Linux Root Filesystem
Pseudo Filesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 220/520
proc virtual lesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 221/520
proc contents
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 222/520
sysfs lesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 223/520
Linux Root Filesystem
Minimal lesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 224/520
Basic applications
and /bin/sh.
In the case of an initramfs, it will only look for /init. Another
process is stopped.
The init application is responsible for starting all other user
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 225/520
Overall booting process
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 226/520
Overall booting process with initramfs
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 227/520
Busybox
Embedded Linux
Experts
Busybox
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 228/520
Why Busybox?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 229/520
General purpose toolbox: BusyBox
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 230/520
BusyBox commands!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 231/520
Applet highlight: Busybox init
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 232/520
Applet highlight - BusyBox vi
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 233/520
Conguring BusyBox
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 234/520
BusyBox make xcong
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 235/520
Compiling BusyBox
Set the cross-compiler prex in the conguration interface:
BusyBox Settings -> Build Options -
> Cross Compiler prefix
Example: arm-linux-
Set the installation directory in the conguration interface:
BusyBox Settings -> Installation Options -
> BusyBox installation prefix
Add the cross-compiler path to the PATH environment
variable:
export PATH=/usr/xtools/arm-unknown-linux-
uclibcgnueabi/bin:$PATH
Compile BusyBox:
make
Install it (this creates a Unix directory structure symbolic links
to the busybox executable):
make install
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 236/520
Practical lab - A tiny embedded system
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 237/520
Block lesystems
Embedded Linux
Experts
Block lesystems
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 238/520
Block vs. ash
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 239/520
Block device list
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 240/520
Traditional block lesystems
Traditional lesystems
Can be left in a non-coherent state after a system crash or
sudden powero, which requires a full lesystem check after
reboot.
ext2: traditional Linux lesystem
(repair it with fsck.ext2)
vfat: traditional Windows lesystem
(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 241/520
Journaled lesystems
Designed to stay in a
correct state even
after system crashes
or a sudden powero
All writes are rst
described in the
journal before being
committed to les
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 242/520
Filesystem recovery after crashes
Thanks to the
journal, the lesystem
is never left in a
corrupted state
Recently saved data
could still be lost
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 243/520
Journaled block lesystems
Journaled lesystems
ext3: ext2 with journal extension
ext4: newest version in the family with many improvements.
Btrfs (``Butter FS'')
The next generation. Great performance. Now used in major
GNU/Linux distros.
The Linux kernel supports many other lesystems: reiserFS,
JFS, XFS, etc. Each of them have their own characteristics,
but are more oriented towards server or scientic workloads.
It's easy to switch lesystems. The best is to try each and nd
out which yields the best performance on your own system.
We recommend ext2 for very small partitions (< 5 MB), because
other lesystems 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 244/520
Creating ext2/ext3/ext4 volumes
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 245/520
Mounting lesystem images
Once a lesystem image has been created, one can access and
modies its contents from the development workstation, using
the loop mechanism
Example:
genext2fs -d rootfs/ rootfs.img
mkdir /tmp/tst
mount -t ext2 -o loop rootfs.img /tmp/tst
In the /tmp/tst directory, one can access and modify the
contents of the rootfs.img le.
This is possible thanks to loop, which is a kernel driver that
emulates a block device with the contents of a le.
Do not forget to run umount before using the lesystem image!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 246/520
F2FS
http://en.wikipedia.org/wiki/F2FS
Filesystem optimized for block devices based on NAND ash
Available in the mainline Linux kernel
Benchmarks: best performer on ash devices most of the time:
See http://lwn.net/Articles/520003/
Technical details: http://lwn.net/Articles/518988/
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 247/520
Squashfs
Squashfs: http://squashfs.sourceforge.net
Read-only, compressed lesystem for block devices. Fine for
parts of a lesystem which can be read-only (kernel,
binaries...)
Great compression rate and read access performance
Used in most live CDs and live USB distributions
Supports LZO compression for better performance on
embedded systems with slow CPUs (at the expense of a
slightly degraded compression rate)
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 248/520
Squashfs - How to use
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 249/520
tmpfs
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 250/520
Mixing read-only and read-write lesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 251/520
Issues with ash-based block storage
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 252/520
Practical lab - Block lesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 253/520
Flash lesystems
Embedded Linux
Experts
Flash lesystems
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 254/520
Block devices vs ash devices: reminder
Block devices:
Allow for random data access using xed size blocks
Do not require special care when writing on the media
Block size is relatively small (minimum 512 bytes, can be
increased for performance reasons)
Considered as reliable (if the storage media is not, some
hardware or software parts are supposed to make it reliable)
Flash devices:
Allow for random data access too
Require special care before writing on the media (erasing the
region you are about to write on)
Erase, write and read operation might not use the same block
size
Reliability depends on the ash technology
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 255/520
NAND ash chips: how they work ?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 256/520
NAND ash storage: organization
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 257/520
NAND ash storage: constraints
Reliability
Far less reliable than NOR ash
Reliability depends on the NAND ash technology (SLC, MLC)
Require additional mechanisms to recover from bit ips: ECC
(Error Correcting Code)
ECC information stored in the OOB (Out-of-band area)
Lifetime
Short lifetime compared to other storage media
Lifetime depends on the NAND ash technology (SLC, MLC):
between 1000000 and 1000 erase cycles per block
Wear leveling mechanisms are required
Bad block detection/handling required too
Despite the number of constraints brought by NAND they are
widely used in embedded systems for several reasons:
Cheaper than other ash technologies
Provide high capacity storage
Provide good performance (both in read and write access)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 258/520
NAND ash: ECC
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 259/520
The MTD subsystem (1)
MTD stands for Memory Technology Devices
Generic subsystem dealing with all types of storage media that
are not tting in the block subsystem
Supported media types: RAM, ROM, NOR ash, NAND
ash, Dataash
Independent of the communication interface (drivers available
for parallel, SPI, direct memory mapping, ...)
Abstract storage media characteristics and provide a simple
API to access MTD devices
MTD device characteristics exposed to users:
erasesize: minimum erase size unit
writesize: minimum write size unit
oobsize: extra size to store metadata or ECC data
size: device size
flags: information about device type and capabilities
Various kind of MTD users: le-systems, block device
emulation layers, user space interfaces...
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 260/520
The MTD subsystem (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 261/520
MTD partitioning
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 262/520
Linux: denition of MTD partitions
The Device Tree is the standard place to dene MTD partitions for
platforms with Device Tree support.
Example from arch/arm/boot/dts/omap3-igep.dtsi:
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 263/520
U-Boot: dening MTD partitions (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 264/520
U-Boot: dening MTD partitions (2)
Example:
setenv mtdids nand0=omap2-nand.0
setenv mtdparts mtdparts=omap2-nand.0:512k(X-Loader)ro,1536k(U-Boot)ro,512k(Env),4m(Kernel),-(RootFS)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 265/520
U-Boot: dening MTD partitions (3)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 267/520
U-Boot: manipulating NAND devices
U-Boot provides a set of commands to manipulate NAND devices,
grouped under the nand command
nand info
Show available NAND devices and characteristics
nand device [dev]
Select or display the active NAND device
nand read[.option] <addr> <offset|partname> <size>
Read data from NAND
nand write[.option] <addr> <offset|partname> <size>
Write data on NAND
Use nand write.trimffs to avoid writing empty pages (those
lled with 0xff)
nand erase <offset> <size>
Erase a NAND region
nand erase.part <partname>
Erase a NAND partition
More commands for debugging purposes
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 268/520
U-Boot: manipulating NOR devices (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 269/520
U-Boot: manipulating NOR devices (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 270/520
Linux: MTD devices interface with user space
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 271/520
Linux: user space ash management tools
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 272/520
Flash wear leveling (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 273/520
Flash wear leveling (2)
Flash users should also take the limited lifetime of ash devices
into account by taking additional precautions
Do not use your ash storage as swap area (rare in embedded
systems anyway)
Mount your lesystems as read-only, or use read-only
lesystems (SquashFS), whenever possible.
Keep volatile les in RAM (tmpfs)
Don't use the sync mount option (commits writes
immediately). Use the fsync() system call for per-le
synchronization.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 274/520
Flash le-systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 275/520
Legacy ash lesystems: JFFS2
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 276/520
Legacy ash lesystems: YAFFS2
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 277/520
UBI/UBIFS
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 278/520
UBI (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 279/520
UBI (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 280/520
UBI: internals
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 281/520
UBI: good practice
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 282/520
UBI layout: bad example
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 283/520
UBI layout: good example
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 284/520
UBIFS
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 285/520
Linux: UBI host tools (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 286/520
Linux: UBI host tools (2)
[data-volume]
[kernel-volume] [rootfs-volume] mode=ubi
mode=ubi mode=ubi image=data.ubifs
image=zImage image=rootfs.squashfs vol_id=3
vol_id=1 vol_id=2 vol_size=30MiB
vol_type=static vol_type=static vol_type=dynamic
vol_name=kernel vol_name=rootfs vol_name=data
vol_flags=autoresize
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 287/520
U-Boot: UBI tools
Grouped under the ubi command
ubi part <part-name>
Attach an MTD partition to the UBI layer
ubi info [layout]
Display UBI device information
(or volume information if the layout string is passed
ubi check <vol-name>
Check if a volume exists
ubi readvol <dest-addr> <vol-name> [<size>]
Read volume contents
U-Boot also provides tools to update the UBI device contents
Using them is highly discouraged (the U-Boot UBI
implementation is not entirely stable, and using commands
that do not touch the UBI metadata is safer)
ubi createvol <vol-name> [<size>] [<type>]
ubi removevol <vol-name>
ubi writevol <src-addr> <vol-name> <size>
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 288/520
Linux: UBI target tools (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 289/520
Linux: UBI target tools (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 290/520
Linux tools: BusyBox UBI limitations
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 291/520
Linux: UBIFS host tools
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 292/520
Linux: UBIFS target tools
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 293/520
Linux: UBI image creation workow
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 294/520
Linux: ashing UBI/UBIFS howtos
See http://free-electrons.com/blog/creating-
flashing-ubi-ubifs-images/ for details about creating UBI
and UBIFS images.
See http://www.linux-
mtd.infradead.org/doc/ubi.html#L_flasher_algo for
what is required when ashing UBI images.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 295/520
Linux: Using a UBIFS lesystem as root lesystem
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 296/520
Summary: how to boot on a UBIFS lesystem
In U-Boot:
Dene partitions:
setenv mtdids ...
setenv mtdparts ...
Dene the base Linux kernel bootargs, specifying booting on
UBIFS, the UBI volume used as root lesystem, and the MTD
partition attached to UBI. Example:
setenv base_bootargs console=ttyS0 rootfstype=ubifs
root=ubi0:rootfs ubi.mtd=2 ...
Dene the boot command sequence, loading the U-Boot
partition denitions, loading kernel and DTB images from UBI
partitions, and adding mtdparts to the kernel command line.
Example:
setenv bootcmd 'mtdparts; ubi part UBI; ubi readvol
0x81000000 kernel; ubi readvol 0x82000000 dtb;
setenv bootargs ${bootargs_base} ${mtdparts}; bootz
0x81000000 - 0x82000000'
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 297/520
Linux: Block emulation layers
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 298/520
Linux: mtdblock
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 299/520
Linux: ubiblock
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 300/520
Useful reading
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 301/520
Practical lab - Flash Filesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 302/520
Embedded Linux system development
Embedded Linux
system Embedded Linux
Experts
development
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 303/520
Contents
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 304/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 305/520
Third party libraries and applications
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 306/520
Find existing components
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 307/520
Choosing components
Not all free software components are necessarily good to re-use.
One must pay attention to:
Vitality of the developer and user communities. This vitality
ensures long-term maintenance of the component, and
relatively good support. It can be measured by looking at the
mailing-list trac and the version control system activity.
Quality of the component. Typically, if a component is
already available through embedded build systems, and has a
dynamic user community, it probably means that the quality is
relatively good.
License. The license of the component must match your
licensing constraints. For example, GPL libraries cannot be
used in proprietary applications.
Technical requirements. Of course, the component must
match your technical requirements. But don't forget that you
can improve the existing components if a feature is missing!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 308/520
Licenses (1)
All software that are under a free software license give four
freedoms to all users
Freedom to use
Freedom to study
Freedom to copy
Freedom to modify and distribute modied copies
See http://www.gnu.org/philosophy/free-sw.html for a
denition of Free Software
Open Source software, as per the denition of the Open
Source Initiative, are technically similar to Free Software in
terms of freedoms
See http://www.opensource.org/docs/osd for the denition
of Open Source Software
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 309/520
Licenses (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 310/520
GPL
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 311/520
GPL: redistribution
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 312/520
LGPL
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 314/520
Non-copyleft licenses
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 315/520
BSD license
.
Copyright (c) <year>, <copyright holder>
All rights reserved.
.
[...]
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 316/520
Is this free software?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 317/520
Respect free software licenses
Free Software is not public domain software, the distributors
have obligations due to the licenses
Before using a free software component, make sure the license
matches your project constraints
Make sure to keep a complete list of the free software
packages you use, the original versions you used, and to keep
your modications and adaptations well-separated from the
original version.
Buildroot and Yocto Project can generate this list for you!
Conform to the license requirements before shipping the
product to the customers.
Free Software licenses have been enforced successfully in
courts. Organizations which can help:
Software Freedom Law Center,
http://www.softwarefreedom.org/
Software Freedom Conservancy, http://sfconservancy.org/
Ask your legal department!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 318/520
Keeping changes separate (1)
When integrating existing open-source components in your
project, it is sometimes needed to make modications to them
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 320/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 321/520
ssh server and client: Dropbear
http://matt.ucc.asn.au/dropbear/dropbear.html
Very small memory footprint ssh server for embedded systems
Satises most needs. Both client and server!
Size: 110 KB, statically compiled with uClibc on i386.
(OpenSSH client and server: approx 1200 KB, dynamically
compiled with glibc on i386)
Useful to:
Get a remote console on the target device
Copy les to and from the target device (scp or rsync -e ssh).
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 322/520
Benets of a web server interface
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 323/520
Web servers
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 324/520
Network utilities (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 325/520
Network utilities (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 326/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 327/520
System utilities
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 328/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 329/520
Language interpreters
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 330/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 331/520
Audio, video and multimedia
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 332/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 333/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 334/520
DirectFB
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 336/520
DirectFB: usage
Multimedia applications
For example the Disko framework, for set-top box related
applications
``Simple'' graphical applications
Industrial control
Device control with limited number of widgets
Visualization applications
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 337/520
DirectFB: screenshot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 338/520
X.org - KDrive
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 339/520
Kdrive: architecture
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 340/520
Kdrive: usage
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 341/520
Wayland
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 342/520
Wayland: architecture
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 343/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 344/520
Gtk
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 345/520
Gtk stack components
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 346/520
Gtk examples (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 347/520
Gtk examples (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 348/520
Qt (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 349/520
Qt (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 350/520
Qt's usage
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 351/520
Other less frequent solutions
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 352/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 353/520
Lightweight database - SQLite
http://www.sqlite.org
SQLite is a small C library that implements a self-contained,
embeddable, lightweight, zero-conguration SQL database
engine
The database engine of choice for embedded Linux systems
Can be used as a normal library
Can be directly embedded into a application, even a
proprietary one since SQLite is released in the public domain
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 354/520
Embedded Linux system development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 355/520
WebKit
http://webkit.org/
Web browser engine. Application framework that
can be used to develop web browsers.
License: portions in LGPL and others in BSD.
Proprietary applications allowed.
Used by many web browsers: Safari, iPhone and
Android default browsers ... Google Chrome now
uses a fork of its WebCore component). Used by
e-mail clients too to render HTML:
http://trac.webkit.org/wiki/
Applications%20using%20WebKit
Multiple graphical back-ends: Qt4, GTK, EFL...
You could use it to create your custom browser.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 356/520
Embedded Linux system development
System building
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 357/520
System building: goal and solutions
Goal
Integrate all the software components, both third-party and
in-house, into a working root lesystem
It involves the download, extraction, conguration, compilation
and installation of all components, and possibly xing issues
and adapting conguration les
Several solutions
Manually
System building tools
Distributions or ready-made lesystems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 358/520
System building: manually
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 359/520
System building: manually (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 360/520
System foundations
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 361/520
Target and build spaces
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 362/520
Build systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 363/520
Autotools and friends
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 364/520
automake / autoconf / autoheader
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 365/520
automake / autoconf
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 366/520
Conguring and compiling: native case
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 367/520
Conguring and compiling: cross case (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 368/520
Conguring and compiling: cross case (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 369/520
Installation (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 370/520
Installation (2)
Contents of usr/lib after installation of libpng and zlib
libpng libtool description les
./lib/libpng12.la
./lib/libpng.la -> libpng12.la
libpng static version
./lib/libpng12.a
./lib/libpng.a -> libpng12.a
libpng dynamic version
./lib/libpng.so.3.32.0
./lib/libpng12.so.0.32.0
./lib/libpng12.so.0 -> libpng12.so.0.32.0
./lib/libpng12.so -> libpng12.so.0.32.0
./lib/libpng.so -> libpng12.so
./lib/libpng.so.3 -> libpng.so.3.32.0
libpng pkg-cong description les
./lib/pkgconfig/libpng12.pc
./lib/pkgconfig/libpng.pc -> libpng12.pc
zlib dynamic version
./lib/libz.so.1.2.3
./lib/libz.so -> libz.so.1.2.3
./lib/libz.so.1 -> libz.so.1.2.3
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 371/520
Installation in the build and target spaces
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 372/520
pkg-cong
pkg-config is a tool that allows to query a small database to
get information on how to compile programs that depend on
libraries
The database is made of .pc les, installed by default in
<prefix>/lib/pkgconfig/.
pkg-config is used by the configure script to get the library
congurations
It can also be used manually to compile an application:
arm-linux-gcc -o test test.c $(pkg-config --libs --
cflags thelib)
By default, pkg-config looks in /usr/lib/pkgconfig for the
*.pc les, and assumes that the paths in these les are
correct.
PKG_CONFIG_PATH allows to set another location for the *.pc
les and PKG_CONFIG_SYSROOT_DIR to prepend a prex to the
paths mentioned in the .pc les.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 373/520
Let's nd the libraries
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 374/520
Practical lab - Manual cross-compiling
Manually cross-compiling
applications and libraries
Learning about common techniques
and issues.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 375/520
System building tools: principle
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 376/520
Available system building tools
Large choice of tools
Buildroot, developed by the community
http://www.buildroot.net
PTXdist, developed by Pengutronix
http://pengutronix.de/software/ptxdist/
OpenWRT, originally a fork of Buildroot for wireless routers, now a
more generic project
http://www.openwrt.org
LTIB. Good support for Freescale boards, but small community
http://ltib.org/
OpenEmbedded, more exible but also far more complicated
http://www.openembedded.org, its industrialized version Yocto
Project and vendor-specic derivatives such as Arago.
See our dedicated course and training materials:
http://free-electrons.com/training/yocto/.
Vendor specic tools (silicon vendor or embedded Linux vendor)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 377/520
Buildroot (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 378/520
Buildroot (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 379/520
Buildroot: adding a new package (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 380/520
Buildroot: adding a new package (2)
. http://prdownloads.sourceforge.net/gqview
It must be sourced from package/Config.in:
.
source
. "package/gqview/Config.in"
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 381/520
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 382/520
OpenEmbedded / Yocto Project
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 383/520
Distributions - Debian
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 384/520
Distributions - Others
Fedora
http://fedoraproject.org/wiki/
Architectures/ARM
Supported on various recent ARM boards
(such as Beaglebone Black). Pidora
supports Raspberry Pi too.
Supports QEMU emulated ARM boards
too (Versatile Express board)
Shipping the same version as for desktops!
Ubuntu
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 385/520
Embedded distributions
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 386/520
Application frameworks
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 387/520
Practical lab - Buildroot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 388/520
Embedded Linux application development
Embedded Linux
application Embedded Linux
Experts
development
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 389/520
Contents
Application development
Developing applications on embedded Linux
Building your applications
Source management
Integrated development environments (IDEs)
Version control systems
Debugging and analysis tools
Debuggers
Memory checkers
System analysis
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 390/520
Embedded Linux application development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 391/520
Application development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 392/520
Programming language
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 393/520
C library or higher-level libraries?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 394/520
Building your applications
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 395/520
Simple Makele (1)
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 396/520
Simple Makele (2)
Case of an application that uses the Glib and the GPS libraries
.
CROSS_COMPILE?=arm-linux-
LIBS=libgps glib-2.0
OBJS=foo.o bar.o
CC=$(CROSS_COMPILE)gcc
CFLAGS=$(shell pkg-config --cflags $(LIBS))
LDFLAGS=$(shell pkg-config --libs $(LIBS))
all: foobar
foobar: $(OBJS)
$(CC) -o $@ $^ $(LDFLAGS)
clean:
. $(RM) -f foobar $(OBJS)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 397/520
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 398/520
KDevelop
http://kdevelop.org
A full featured IDE!
License: GPL
Supports many languages: Ada, C, C++,
Database, Java, Perl, PHP, Python, Ruby, Shell
Supports many kinds of projects: KDE, but also
GTK, Gnome, kernel drivers, embedded (Opie)...
Many features: editor, syntax highlighting, code
completion, compiler interface, debugger
interface, le 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 399/520
KDevelop screenshot
Ruby debugger
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 400/520
Eclipse (1)
http://www.eclipse.org/
An extensible, plug-in based software
development kit, typically used for creating IDEs.
Supported by the Eclipse foundation, a
non-prot consortium of major software industry
vendors (IBM, Intel, Borland, Nokia, Wind
River, Zend, Computer Associates...).
Free Software license (Eclipse Public License).
Incompatible with the GPL.
Supported platforms: GNU/Linux, Unix,
Windows
Extremely popular: created a lot of attraction.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 401/520
Eclipse (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 402/520
Other popular solutions
Vim
Many embedded Linux developers
simply use Vim or Emacs. They
can integrate with debuggers,
source code browsers such as
cscope, oer syntax highlighting
and more.
Geany is an easy-to-use graphical
code editor.
Emacs
CodeBlocks is also quite popular,
since it's also available on the
Windows platform.
All these editors are available in most
Linux distributions, simply install them
and try them out!
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 403/520
Embedded Linux application development
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 404/520
Version control systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 405/520
Traditional version control systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 406/520
Distributed source control systems (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 407/520
Distributed source control systems (2)
Git
Initially designed and developed by Linus Torvalds for Linux
kernel development
Extremely popular in the community, and used by more and
more projects (kernel, U-Boot, Barebox, uClibc, GNOME,
X.org, etc.)
Outstanding performance, in particular in big projects
http://en.wikipedia.org/wiki/Git_(software)
Mercurial
Another system, created with the same goals as Git.
Used by some big projects too
http://en.wikipedia.org/wiki/Mercurial
http://en.wikipedia.org/wiki/Version_control_systems#
Distributed_revision_control
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 408/520
Embedded Linux application development
Debuggers
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 409/520
GDB
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 410/520
GDB crash course
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 411/520
GDB graphical front-ends
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 412/520
Embedded Linux application development
Remote debugging
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 413/520
Remote debugging
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 414/520
Remote debugging: architecture
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 415/520
Remote debugging: usage
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 416/520
Post mortem analysis
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 417/520
Embedded Linux application development
Memory checkers
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 418/520
DUMA
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 419/520
Valgrind (1)
http://valgrind.org/
GNU GPL Software suite for debugging and
proling programs.
Supported platforms: Linux on x86, x86_64,
ppc32, ppc64 and arm (armv7 only: Cortex A8,
A9 and A5)
Can detect many memory management and
threading bugs.
Proler: provides information helpful to speed
up your program and reduce its memory usage.
The most popular tool for this usage. Even used
by projects with hundreds of programmers.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 420/520
Valgrind (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 421/520
Embedded Linux application development
System analysis
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 422/520
strace
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 424/520
ltrace
A tool to trace library calls used by a program and all the signals it
receives
Very useful complement to strace, which shows only system
calls.
Of course, works even if you don't have the sources
Allows to lter library calls with regular expressions, or just by
a list of function names.
Manual page: http://linux.die.net/man/1/ltrace
See http://en.wikipedia.org/wiki/Ltrace for details
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 425/520
ltrace example output
.
ltrace nedit index.html
sscanf(0x8274af1, 0x8132618, 0x8248640, 0xbfaadfe8, 0) = 1
sprintf("const 0", "const %d", 0) = 7
strcmp("startScan", "const 0") = 1
strcmp("ScanDistance", "const 0") = -1
strcmp("const 200", "const 0") = 1
strcmp("$list_dialog_button", "const 0") = -1
strcmp("$shell_cmd_status", "const 0") = -1
strcmp("$read_status", "const 0") = -1
strcmp("$search_end", "const 0") = -1
strcmp("$string_dialog_button", "const 0") = -1
strcmp("$rangeset_list", "const 0") = -1
strcmp("$calltip_ID",
. "const 0") = -1
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 426/520
ltrace summary
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 427/520
OProle
http://oprofile.sourceforge.net
A system-wide proling tool
Can collect statistics like the top users of the CPU.
Works without having the sources.
Requires a kernel patch to access all features, but is already
available in a standard kernel.
Requires more investigation to see how it works.
Ubuntu/Debian packages: oprofile, oprofile-gui
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 428/520
Callgrind / KCachegrind
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 429/520
KCachegrind screenshot
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 430/520
Practical lab - App. development and debugging
Application development
Compile your own application with
the ncurses library
Remote debugging
Set up remote debugging tools on
the target: strace, ltrace
and gdbserver.
Debug a simple application running
on the target using remote
debugging
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 431/520
Real-time in embedded Linux systems
Real-time in
embedded Linux Embedded Linux
Experts
systems
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 432/520
Real-time in embedded Linux systems
Introduction
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 433/520
Embedded Linux and real time
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 434/520
Embedded Linux and real time
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 435/520
Linux and real-time approaches (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 436/520
Linux and real-time approaches (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 437/520
Real-time in embedded Linux systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 438/520
Understanding latency
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 439/520
Linux kernel latency components
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 440/520
Interrupt latency
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 441/520
Sources of interrupt latency
One of the concurrency prevention mechanism used in the
kernel is the spinlock
It has several variants, but one of the variant commonly used
to prevent concurrent accesses between a process context and
an interrupt context works by disabling interrupts
Critical sections protected by spinlocks, or other section in
which interrupts are explicitly disabled will delay the beginning
of the execution of the interrupt handler
The duration of these critical sections is unbounded
Other possible source: shared interrupts (not a real problem:
mustn't be used for time-critical interrupt-sources anyway).
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 442/520
Interrupt handler duration
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 443/520
Interrupt handler implementation
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 444/520
Scheduler latency
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 445/520
Understanding preemption (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 446/520
Understanding preemption (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 447/520
Scheduler duration
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 448/520
Other non-deterministic mechanisms
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 449/520
Priority inversion
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 450/520
Interrupt handler priority
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 451/520
The PREEMPT_RT project
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 452/520
Improvements in the mainline kernel
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 453/520
New preemption options in Linux 2.6
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 454/520
1st option: no forced preemption
CONFIG_PREEMPT_NONE
Kernel code (interrupts, exceptions, system calls) never preempted.
Default behavior in standard kernels.
Best for systems making intense computations, on which
overall throughput is key.
Best to reduce task switching to maximize CPU and cache
usage (by reducing context switching).
Still benets from some Linux 2.6 improvements: O(1)
scheduler, increased multiprocessor safety (work on RT
preemption was useful to identify hard to nd SMP bugs).
Can also benet 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 455/520
2nd option: voluntary kernel preemption
CONFIG_PREEMPT_VOLUNTARY
Kernel code can preempt itself
Typically for desktop systems, for quicker application reaction
to user input.
Adds explicit rescheduling points throughout kernel code.
Minor impact on throughput.
Used in: Ubuntu Desktop 15.04, Ubuntu Server 14.04
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 456/520
3rd option: preemptible kernel
CONFIG_PREEMPT
Most kernel code can be involuntarily preempted at any time.
When a process becomes runnable, no more need to wait for kernel
code (typically a system call) to return before running the
scheduler.
Exception: kernel critical sections (holding spinlocks). In a
case you hold a spinlock on a uni-processor system, kernel
preemption could run another process, which would loop
forever if it tried to acquire the same spinlock.
Typically for desktop or embedded systems with latency
requirements in the milliseconds range.
Still a relatively minor impact on throughput.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 457/520
Priority inheritance
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 459/520
Threaded interrupts
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 460/520
The future of the PREEMPT_RT patchset
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 461/520
Real-time in embedded Linux systems
PREEMPT_RT specics
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 462/520
CONFIG_PREEMPT_RT (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 463/520
CONFIG_PREEMPT_RT (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 464/520
Threaded interrupts
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 465/520
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 466/520
PREEMPT_RT setup (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 467/520
PREEMPT_RT setup (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 468/520
Real-time in embedded Linux systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 469/520
Development and compilation
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 470/520
Process, thread?
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 471/520
Process, thread: kernel point of view
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 472/520
Creating threads
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 473/520
Scheduling classes (1)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 474/520
Scheduling classes (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 475/520
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 476/520
Memory locking
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 477/520
Mutexes
Lock/unlock
.
pthread_mutex_lock(pthread_mutex_t *mutex);
.pthread_mutex_unlock(pthread_mutex_t *mutex);
Priority inheritance must be activated explicitly
.
pthread_mutexattr_t attr;
pthread_mutexattr_init (&attr);
pthread_mutexattr_setprotocol(&attr,
. PTHREAD_PRIO_INHERIT);
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 478/520
Timers
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 479/520
Timers (2)
Delete a timer
.
t. imer_delete(timer_t timerid)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 480/520
Signals
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 481/520
Inter-process communication
Semaphores
Usable between dierent processes using named semaphores
sem_open(), sem_close(), sem_unlink(), sem_init(),
sem_destroy(), sem_wait(), sem_post(), etc.
Message queues
Allows processes to exchange data in the form of messages.
mq_open(), mq_close(), mq_unlink(), mq_send(),
mq_receive(), etc.
Shared memory
Allows processes to communicate by sharing a segment of
memory
shm_open(), ftruncate(), mmap(), munmap(), close(),
shm_unlink()
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 482/520
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 483/520
ftrace - Kernel function tracer
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 484/520
Using ftrace
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 485/520
Scheduling latency tracer
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 486/520
Exemple of worst-case latencies
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 487/520
Useful reading
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 488/520
Real-time in embedded Linux systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 489/520
Linux real-time extensions
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 490/520
RTLinux
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 491/520
RTAI
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 492/520
Xenomai project
http://www.xenomai.org/
Started in 2001 as a project aiming at emulating
traditional RTOS.
Initial goals: facilitate the porting of programs to
GNU / Linux.
Initially related to the RTAI project (as the RTAI
/ fusion branch), now independent.
Skins mimicking the APIs of traditional RTOS
such as VxWorks, pSOS+, and VRTXsa as well
as the POSIX API, and a native API.
Aims at working both as a co-kernel and on top
of PREEMPT_RT in future upstream Linux
versions.
Will never be merged in the mainline kernel.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 493/520
Xenomai architecture
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 494/520
The Adeos interrupt pipeline abstraction
From the Adeos point of view, guest OSes are prioritized
domains.
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 495/520
Xenomai features
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 496/520
Xenomai user space real-time support
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 497/520
Life of a Xenomai application
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 498/520
Real Time Driver Model (RTDM)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 499/520
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 500/520
How to build Xenomai
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 501/520
Linux options for Xenomai conguration
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 502/520
Xenomai user space support
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 503/520
Real-time in embedded Linux systems
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 504/520
The POSIX skin
The POSIX skin allows to recompile without changes a
traditional POSIX application so that instead of using Linux
real-time services, it uses Xenomai services
http://www.xenomai.org/index.php/Porting_POSIX_
applications_to_Xenomai
Clocks and timers, condition variables, message queues,
mutexes, semaphores, shared memory, signals, thread
management
Good for existing code or programmers familiar with the
POSIX API
Of course, if the application uses any Linux service that isn't
available in Xenomai, it will switch back to secondary mode
To link an application against the POSIX skin
.
CFL=`pkg-config --cflags libxenomai_posix`
LDF=`pkg-config --libs libxenomai_posix`
.ARCH-gcc $CFL -o rttest rttest.c $LDF
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 505/520
Communication with a normal task
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 507/520
The native API (2)
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 508/520
The native API (3)
Alarm services
rt_alarm_create(), rt_alarm_delete(),
rt_alarm_start(), rt_alarm_stop(), rt_alarm_wait(), etc.
Memory heap services
Allows to share memory between processes and/or to
pre-allocate a pool of memory
rt_heap_create(), rt_heap_delete(), rt_heap_alloc(),
rt_heap_bind()
Condition variable services
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 509/520
Xenomai and normal task communication
Using rt_pipes
In the native Xenomai application, use the Pipe API
rt_pipe_create(), rt_pipe_delete(), rt_pipe_receive(),
rt_pipe_send(), rt_pipe_alloc(), rt_pipe_free()
In the normal Linux application
Open the corresponding /dev/rtpX le, the minor is specied
at rt_pipe_create() time
Then, just read() and write() to the opened le
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 510/520
Xenomai worst-case latencies results
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 511/520
Books
http://oreilly.com/catalog/9780596529680/
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 512/520
Organizations
http://www.osadl.org
Open Source Automation Development Lab (OSADL)
Targets machine and plant control systems. Most member
companies are German (Thomas Gleixner is on board).
Supports the use of PREEMPT_RT and Xenomai and
contributes to these projects. Shares useful documentation
and resources.
They also organize a yearly Real Time Linux Workshop.
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 513/520
Practical lab - Real-time - Scheduling latency
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 514/520
References
Embedded Linux
Experts
References
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 515/520
Books
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 516/520
Web sites
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 517/520
International conferences
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 518/520
Last slides
Embedded Linux
Experts
Last slides
free electrons
free electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 519/520
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 520/520