Embedded Linux Slides
Embedded Linux Slides
Embedded Linux Slides
Free Electrons
Embedded Linux
Developers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
1/540
Rights to copy
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
2/540
Regular hyperlinks:
http://kernel.org/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
3/540
Head count: 9
Only Free Software enthusiasts!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
4/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
5/540
Generic course
information
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
6/540
flash
I 2 Ethernet ports (Gigabit + 100 Mbit)
I 2 USB 2.0 host, 1 USB device
I 1 MMC/SD slot
I 3.3 V serial port (like Beaglebone Black)
I Misc: Arduino R3-compatible header,
7/540
http://j.mp/18Hk8yF
I Logitech USB H340 audio headsets
http://www.logitech.com/en-us/product/11608
I An SD card with at least 128 MB of capacity
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
8/540
Participate!
During the lectures...
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
9/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
10/540
Cooperate!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
11/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
12/540
vi basic commands
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
13/540
Introduction to
Embedded Linux
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
14/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
15/540
Free software?
Freedom
Freedom
Freedom
Freedom
to
to
to
to
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
16/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
17/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
18/540
Re-using components
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
19/540
Low cost
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
20/540
Full control
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
21/540
Quality
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
22/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
23/540
Community support
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
24/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
25/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
26/540
Personal routers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
27/540
Television
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
28/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
29/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
30/540
Viticulture machine
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
31/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
32/540
I
I
I
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
33/540
Besides the toolchain, the bootloader and the kernel, all other
components are generally architecture-independent
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
34/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
35/540
Communication
I2C
SPI
CAN
1-wire
SDIO
USB
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
36/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
37/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
38/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
39/540
Global architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
40/540
Software components
I
Cross-compilation toolchain
I
Bootloader
I
C library
I
Linux Kernel
I
Third-party or in-house
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
41/540
System integration
I
Development of applications
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
42/540
Embedded Linux
development
environment
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
43/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
44/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
45/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
46/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
47/540
Software packages
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
48/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
49/540
I
I
50/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
51/540
I
I
I
SERIAL_DEVICE is typically
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
52/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
53/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
54/540
Cross-compiling toolchains
Cross-compiling
toolchains
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
55/540
Cross-compiling toolchains
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
56/540
Definition (1)
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
57/540
Definition (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
58/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
59/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
60/540
Components
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
61/540
Binutils
I
I
I
http://www.gnu.org/software/binutils/
GPL license
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
62/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
63/540
1
2
3
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
64/540
The kernel headers are extracted from the kernel sources using
the headers_install kernel Makefile target.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
65/540
GCC
http://gcc.gnu.org/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
66/540
C library
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
67/540
Cross-compiling toolchains
C Libraries
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
68/540
glibc
License: LGPL
http://www.gnu.org/software/libc/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
69/540
uClibc
I
http://www.uclibc.org/
License: LGPL
Lightweight C library for small embedded systems
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
70/540
uClibc (2)
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
71/540
eglibc
I
http:
//en.wikipedia.org/wiki/Embedded_GLIBC
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
72/540
Busybox (stripped):
busybox
uClibc
uClibc with Thumb-2
eglibc with Thumb-2
static
750kB
533kB
934kB
dynamic
603kB
439kB
444kB
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
73/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
74/540
Cross-compiling toolchains
Toolchain Options
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
75/540
ABI
I
http://en.wikipedia.org/wiki/Application_Binary_
Interface
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
76/540
Generate hard float code and rely on the kernel to emulate the
floating point instructions. This is very slow.
Generate soft float code, so that instead of generating floating
point instructions, calls to a user space library are generated
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
77/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
78/540
Cross-compiling toolchains
Obtaining a Toolchain
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
79/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
80/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
81/540
Sourcery CodeBench
I
I
I
I
I
MIPS
NIOS-II
AMD64
Hexagon
http://mentor.com/embedded-software/sourcerytools/sourcery-codebench/editions/lite-edition/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
82/540
Linaro toolchains
For people who cant wait for the next releases of gcc,
Linaro releases modified sources of stable releases of
gcc, with these optimizations for ARM (mainly for
recent Cortex A CPUs).
https://wiki.linaro.org/WorkingGroups/ToolChain
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
83/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
84/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
85/540
Crosstool-ng
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
86/540
PTXdist
I
OpenEmbedded / Yocto
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
87/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
88/540
Toolchain contents
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
89/540
Configure Crosstool-NG
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
90/540
Bootloaders
Free Electrons
Bootloaders
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
91/540
Bootloaders
Boot Sequence
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
92/540
Bootloaders
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
93/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
94/540
Can read many filesystem formats to load the kernel image and
the configuration, provides a powerful shell with various
commands, can load kernel images over the network, etc.
See our dedicated presentation for details:
http://free-electrons.com/docs/grub/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
95/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
96/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
97/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
98/540
99/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
100/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
101/540
Bootloaders
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
102/540
U-Boot
U-Boot is a typical free software project
I
Documentation available at
http://www.denx.de/wiki/U-Boot/Documentation
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
103/540
U-Boot configuration
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
104/540
/* CPU configuration */
#define CONFIG_ARMV7 1
#define CONFIG_OMAP 1
#define CONFIG_OMAP34XX 1
#define CONFIG_OMAP3430 1
#define CONFIG_OMAP3_IGEP0020 1
[...]
/* Memory configuration */
#define CONFIG_NR_DRAM_BANKS 2
#define PHYS_SDRAM_1 OMAP34XX_SDRC_CS0
#define PHYS_SDRAM_1_SIZE (32 << 20)
#define PHYS_SDRAM_2 OMAP34XX_SDRC_CS1
[...]
/* USB configuration */
#define CONFIG_MUSB_UDC 1
#define CONFIG_USB_OMAP3 1
#define CONFIG_TWL4030_USB 1
[...]
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
105/540
make BOARDNAME_config
Where BOARDNAME is the name of the board, as visible in the
boards.cfg file (first column).
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
106/540
Installing U-Boot
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
107/540
U-boot prompt
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
108/540
Information commands
Flash information (NOR and SPI flash)
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
NAND flash information
U-Boot> nand info
Device 0: nand0, sector size 128 KiB
Page size
2048 b
OOB size
64 b
Erase size
131072 b
Version details
U-Boot> version
U-Boot 2013.04 (May 29 2013 - 10:30:21)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
109/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
110/540
loadb, loads, loady, load a file from the serial line to RAM
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
111/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
112/540
printenv
Shows all variables
printenv <variable-name>
Shows the value of a variable
editenv <variable-name>
Edits the value of a variable, only in RAM
saveenv
Saves the current state of the environment to flash
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
113/540
u-boot # printenv
baudrate=19200
ethaddr=00:40:95:36:35:33
netmask=255.255.255.0
ipaddr=10.0.0.11
serverip=10.0.0.1
stdin=serial
stdout=serial
stderr=serial
u-boot # printenv serverip
serverip=10.0.0.1
u-boot # setenv serverip 10.0.0.100
u-boot # saveenv
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
114/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
115/540
I
I
Example
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
116/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
117/540
TFTP
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
118/540
U-boot mkimage
I
This header gives details such as the image size, the expected
load address, the compression type, etc.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
119/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
120/540
Linux kernel
introduction
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
121/540
Linux features
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
122/540
History
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
123/540
Compliance to standards
and interoperability.
Exhaustive networking
support.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
124/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
125/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
126/540
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
I
This interface is stable over time: only new system calls can
be added by the kernel developers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
127/540
Pseudo filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
128/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
129/540
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:
I
When you receive or buy a device with Linux on it, you should
receive the Linux sources, with the right to study, modify and
redistribute them.
When you produce Linux based devices, you must release the
sources to the recipient, with the same rights, with no
restriction.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
130/540
64 bit architectures:
Examples: alpha, arm64, ia64, tile
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
131/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
132/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
133/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
134/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
135/540
I
I
Official kernel versions are now named 3.x (3.0, 3.1, 3.2,
etc.)
Stabilized versions are named 3.x.y (3.0.2, 3.4.3, etc.)
It effectively only removes a digit compared to the previous
numbering scheme
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
136/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
137/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
138/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
139/540
Very difficult to find out the key changes and to get the global
picture out of individual changes.
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
140/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
141/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
142/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
143/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
144/540
drivers/: 49.4%
arch/: 21.9%
fs/: 6.0%
include/: 4.7%
sound/: 4.4%
Documentation/: 4.0%
net/: 3.9%
firmware/: 1.0%
kernel/: 1.0%
tools/: 0.9%
scripts/: 0.5%
mm/: 0.5%
crypto/: 0.4%
security/: 0.4%
lib/: 0.4%
block/: 0.2%
...
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
145/540
Full tarballs
I
Extract command:
tar xf linux-3.10.9.tar.xz
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)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
146/540
Patch
I
I
I
147/540
Contents of a patch
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
148/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
149/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
150/540
Apply patches
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
151/540
Kernel configuration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
152/540
I
I
Example
I
I
cd linux-3.6.x/
make <target>
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
153/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
154/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
155/540
Kernel or module?
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
156/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
157/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
158/540
make xconfig
make xconfig
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
159/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
160/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
161/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
162/540
163/540
make gconfig
make gconfig
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
164/540
make menuconfig
make menuconfig
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
165/540
make nconfig
make nconfig
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
166/540
make oldconfig
make oldconfig
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
167/540
A frequent problem:
I
If you dont remember all the changes you made, you can get
back to your previous configuration:
$ cp .config.old .config
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
168/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
169/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
170/540
Kernel compilation
I
make
I
I
Generates
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
171/540
Kernel installation
I
make install
I
Installs
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
172/540
Module installation
make modules_install
I
kernel/
Module .ko (Kernel Object) files, 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
173/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
174/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
175/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
176/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
177/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
178/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
179/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
180/540
Device Tree
I
The bootloader must load both the kernel image and the
Device Tree Blob in memory before starting the kernel.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
181/540
Run make
Copy the final kernel image to the target storage
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
182/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
183/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
184/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
185/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
186/540
Advantages of modules
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
187/540
Module dependencies
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
188/540
Kernel log
When a new module is loaded, related information is available in
the kernel log.
I
Note that you can write to the kernel log from user space too:
echo "<n>Debug info" > /dev/kmsg
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
189/540
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.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
190/540
Example:
$ sudo insmod ./intr_monitor.ko
insmod: error inserting './intr_monitor.ko': -1 Device or resource busy
$ dmesg
[17549774.552000] Failed to register handler for irq channel 2
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
191/540
lsmod
Displays the list of loaded modules
Compare its output with the contents of /proc/modules!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
192/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
193/540
Through insmod:
sudo insmod ./snd-intel8x0m.ko index=-2
Through modprobe:
Set parameters in /etc/modprobe.conf or in any file in
/etc/modprobe.d/:
options snd-intel8x0m index=-2
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
194/540
Check /sys/module/<name>/parameters.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
195/540
Useful reading
Linux Kernel in a Nutshell, Dec 2006
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
196/540
Linux Root
Filesystem
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
197/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
198/540
Filesystems
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
199/540
Filesystems (2)
It is empty
$ ls /mnt/usbkey
$
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
200/540
mount / umount
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
201/540
Root filesystem
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
202/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
203/540
Partitions of an SD card
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
204/540
Can have a big root filesystem even if you dont have support
for internal or external storage yet.
The root filesystem can be huge. You can even build native
compiler tools and build all the tools you need on the target
itself (better to cross-compile though).
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
205/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
206/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
207/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
208/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
209/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
210/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
211/540
Contents
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
212/540
http://www.linuxfoundation.org/collaborate/
workgroups/lsb/fhs
Most Linux systems conform to this specification
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
213/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
214/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
215/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
216/540
Device Files
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
217/540
Devices
Character device
Block device
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
218/540
Types of devices
Block devices
I
Character devices
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
219/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
220/540
/dev/zero
/dev/sda1
/dev/sda2
/dev/tty1
/dev/ttyS0
/dev/zero
Example C code that uses the usual file API to write data to a
serial port
int fd;
fd = open("/dev/ttyS0", O_RDWR);
write(fd, "Hello", 5);
close(fd);
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
221/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
222/540
Pseudo Filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
223/540
man proc
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
224/540
proc contents
I
/proc/<pid>
cat /proc/3840/cmdline
It contains details about the files opened by the process, the
CPU and memory usage, etc.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
225/540
sysfs filesystem
I
$ ls /sys/
block bus class dev devices firmware
fs kernel module power
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
226/540
Minimal filesystem
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
227/540
Basic applications
I
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
228/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
229/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
230/540
Busybox
Free Electrons
Busybox
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
231/540
Why Busybox?
I
I
I
An init program
A shell
Various basic utilities for file manipulation and system
configuration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
232/540
http://www.busybox.net/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
233/540
BusyBox commands!
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
234/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
235/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
236/540
Configuring BusyBox
I
I
make defconfig
Good to begin with BusyBox.
Configures BusyBox with all options for regular users.
make allnoconfig
Unselects all options. Good to configure only what you need.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
237/540
the commands
to compile,
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
238/540
Compiling BusyBox
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
239/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
240/540
Block filesystems
Free Electrons
Block filesystems
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
241/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
242/540
0
1
2
0
1
2
3866624
73712
3792896
976762584
1060258
975699742
mmcblk0
mmcblk0p1
mmcblk0p2
sda
sda1
sda2
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
243/540
Traditional filesystems
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
244/540
Journaled filesystems
Designed to stay in a
correct state even
after system crashes
or a sudden poweroff
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
245/540
Thanks to the
journal, the filesystem
is never left in a
corrupted state
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
246/540
Its easy to switch filesystems. The best is to try each and find
out which yields the best performance on your own system.
247/540
mkfs.ext2
mkfs.ext3
mkfs.ext4
mkfs.ext2
/dev/hda3
/dev/sda2
/dev/sda3
disk.img
Use the genext2fs tool, from the package of the same name
genext2fs -d rootfs/ rootfs.img
Your image is then ready to be transferred to your block device
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
248/540
Once a filesystem image has been created, one can access and
modifies its contents from the development workstation, using
the loop mechanism
Example:
genext2fs -d rootfs/ rootfs.img
mkdir /tmp/tst
mount -t ext2 -o loop rootfs.img /tmp/tst
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
249/540
F2FS
http://en.wikipedia.org/wiki/F2FS
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
250/540
Squashfs
Squashfs: http://squashfs.sourceforge.net
I
251/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
252/540
tmpfs
Not a block filesystem of course!
Perfect to store temporary data in RAM: system log files,
connection data, temporary files...
I
tmpfs configuration:
File systems -> Pseudo filesystems
Lives in the Linux file cache. Doesnt waste RAM: unlike
ramdisks, no need to copy files to the file cache, grows and
shrinks to accommodate stored files. Saves RAM: can swap
out pages to disk when needed.
253/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
254/540
Hence, no way to access a low level flash interface and use the
Linux filesystems doing wear leveling.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
255/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
256/540
Flash filesystems
Free Electrons
Flash filesystems
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
257/540
Block devices:
I
I
I
Flash devices:
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
258/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
259/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
260/540
Reliability
I
I
I
Lifetime
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
261/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
262/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
263/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
264/540
MTD partitioning
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
265/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
266/540
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
267/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
268/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
269/540
NAND device: Manufacturer ID: 0x2c, Chip ID: 0xbc (Micron NAND 512MiB 1,8V 16-bit)
Creating 5 MTD partitions on "omap2-nand.0":
0x000000000000-0x000000080000 : "X-Loader"
0x000000080000-0x000000200000 : "U-Boot"
0x000000200000-0x000000280000 : "Environment"
0x000000280000-0x000000580000 : "Kernel"
0x000000580000-0x000020000000 : "File System"
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
270/540
Example:
mtdids=nand0=omap2-nand.0
mtdparts=mtdparts=omap2-nand.0:512k(XLoader)ro,1536k(UBoot)ro,512k(Environment),4m(Kernel),-(RootFS)
Weve just defined 5 partitions in the omap2-nand.0 device:
I
I
I
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
271/540
The userspace only see MTD partitions, not the flash device
under those partitions
The mtdchar driver creates a character device for each MTD
device/partition of the system
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
272/540
273/540
274/540
U-Boot and linux are using the same syntax to describe the
MTD partitions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
275/540
I
I
I
See http://www.linux-mtd.infradead.org/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
276/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
277/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
278/540
Flash file-systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
279/540
http://www.linuxmtd.infradead.org/doc/jffs2.html
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
280/540
No compression
http://www.yaffs.net/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
281/540
UBI/UBIFS
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
282/540
UBI (1)
Unsorted Block Images
I
http://www.linux-mtd.infradead.org/doc/ubi.html
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
283/540
UBI (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
284/540
UBI: internals
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
285/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
286/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
287/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
288/540
UBIFS
http://www.linux-mtd.infradead.org/doc/ubifs.html
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
289/540
I
I
I
Example:
ubinize -o ubi.img -p 16KiB -m 512 -s 256 cfg.ini
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
290/540
Example:
[kernel-volume]
mode=ubi
image=zImage
vol_id=1
vol_type=static
vol_name=kernel
vol_alignment=1
I
[rootfs-volume]
mode=ubi
image=rootfs.squashfs
vol_id=2
vol_type=static
vol_name=rootfs
vol_alignment=1
[data-volume]
mode=ubi
image=data.ubifs
vol_id=3
vol_size=30MiB
vol_type=dynamic
vol_name=data
vol_flags=autoresize
vol_alignment=1
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
291/540
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
292/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
293/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
294/540
Once created
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
295/540
Example:
mount -t ubifs ubi0:data /data
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
296/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
297/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
298/540
Example:
rootfstype=ubifs ubi.mtd=1 root=ubi0:rootfs
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
299/540
http://elinux.org/Flash_Filesystem_Benchmarks
I jffs2
I
I
yaffs2
I
Worst performance
Requires CONFIG_SUMMARY to have acceptable boot time
Good performance, but not in mainline Linux
ubifs
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
300/540
I
I
the emulation layer does not properly deal with wear leveling
and data retention issues occurring on the flash media
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
301/540
Linux: mtdblock
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
302/540
Linux: ubiblock
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
303/540
Useful reading
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
304/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
305/540
Embedded Linux
system
development
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
306/540
Contents
I
I
Networking
System utilities
Language interpreters
Audio, video and multimedia
Graphical toolkits
Databases
Web browsers
System building
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
307/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
308/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
309/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
310/540
Choosing components
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
311/540
Licenses (1)
I
All software that are under a free software license give four
freedoms to all users
I
I
I
I
Freedom
Freedom
Freedom
Freedom
to
to
to
to
use
study
copy
modify and distribute modified copies
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
312/540
Licenses (2)
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
313/540
GPL
I
I
Is a copyleft license
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
314/540
GPL: redistribution
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
315/540
LGPL
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
316/540
Licensing: examples
I
You must release the modified versions under the same license
You must release the modified versions under the same license,
and be ready to distribute the source code to your customers
You can keep your application proprietary, but you must link
dynamically with the LGPL libraries
You can keep your modifications proprietary, but you must still
credit the authors
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
317/540
Non-copyleft licenses
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
318/540
BSD license
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
319/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
320/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
321/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
322/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
323/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
324/540
http://matt.ucc.asn.au/dropbear/dropbear.html
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
325/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
326/540
Web servers
I
lighttpd: http://lighttpd.net
Low footprint server good at managing high
loads.
May be useful in embedded systems too
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
327/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
328/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
329/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
330/540
System utilities
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
331/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
332/540
Language interpreters
Application development
Web services development
Scripting
Languages supported
I
I
I
I
I
I
Lua
Python
Perl
Ruby
TCL
PHP
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
333/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
334/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
335/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
336/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
337/540
DirectFB
I
http://www.directfb.org
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
338/540
DirectFB: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
339/540
DirectFB: usage
Multimedia applications
I
Industrial control
Device control with limited number of widgets
Visualization applications
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
340/540
DirectFB: screenshot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
341/540
X.org - KDrive
I
X11 license
http://www.x.org
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
342/540
Kdrive: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
343/540
Kdrive: usage
Gtk
Qt
Enlightment Foundation Libraries
Others: Fltk, WxEmbedded, etc
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
344/540
Wayland
http://wayland.freedesktop.org/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
345/540
Wayland: architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
346/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
347/540
Gtk
License: LGPL
http://www.gtk.org
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
348/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
349/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
350/540
351/540
Qt (1)
Framebuffer
X11
DirectFB back-end integrated in version 4.4, which allows to
take advantage of the acceleration provided by DirectFB
drivers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
352/540
Qt (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
353/540
Qts usage
354/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
355/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
356/540
http://www.sqlite.org
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
357/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
358/540
WebKit
http://webkit.org/
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
359/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
360/540
Industrial applications
Kernel
BusyBox
C library
Applications relying directly on the C library, sometimes using
the real-time capabilities of the Linux kernel
Sometimes a Web server for remote control, or another server
implementing a custom protocol
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
361/540
I
I
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
362/540
Base system
I
I
I
I
I
I
Busybox
Build system, in this case was OpenEmbedded
Components: u-boot, Linux, busybox
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
363/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
364/540
JPEG display
I
I
I
MP3 support
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
365/540
3D interface
I
I
Application itself
I
I
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
366/540
System building
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
367/540
Goal
I
Several solutions
I
I
I
Manually
System building tools
Distributions or ready-made filesystems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
368/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
369/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
370/540
System foundations
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
371/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
372/540
Build systems
A basic Makefile
I
CMake, http://www.cmake.org/
I
Scons, http://www.scons.org/
Waf, http://code.google.com/p/waf/
Other manual build systems
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
373/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
374/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
375/540
automake / autoconf
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
376/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
377/540
At least some of the environment variables AR, AS, LD, NM, CC,
GCC, CPP, CXX, STRIP, OBJCOPY must be defined to point to
the proper cross-compilation tools. The host tuple is also by
default used as prefix.
configure script arguments:
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
378/540
export PATH=/usr/local/arm-linux/bin:$PATH
export CC=arm-linux-gcc
export STRIP=arm-linux-strip
./configure --host=arm-linux --prefix=/usr
make
make DESTDIR=$HOME/work/rootfs install
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
379/540
Installation (1)
I
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
380/540
Installation (2)
Contents of usr/lib after installation of libpng and zlib
I libpng libtool description files
./lib/libpng12.la
./lib/libpng.la -> libpng12.la
I libpng static version
./lib/libpng12.a
./lib/libpng.a -> libpng12.a
I libpng dynamic version
./lib/libpng.so.3.32.0
./lib/libpng12.so.0.32.0
./lib/libpng12.so.0 -> libpng12.so.0.32.0
./lib/libpng12.so -> libpng12.so.0.32.0
./lib/libpng.so -> libpng12.so
./lib/libpng.so.3 -> libpng.so.3.32.0
I libpng pkg-config description files
./lib/pkgconfig/libpng12.pc
./lib/pkgconfig/libpng.pc -> libpng12.pc
I zlib dynamic version
./lib/libz.so.1.2.3
./lib/libz.so -> libz.so.1.2.3
./lib/libz.so.1 -> libz.so.1.2.3
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
381/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
382/540
pkg-config
I
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
383/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
384/540
Manually cross-compiling
applications and libraries
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
385/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
386/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
387/540
Buildroot (1)
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
388/540
Buildroot (2)
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
389/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
390/540
config BR2_PACKAGE_GQVIEW
bool "gqview"
depends on BR2_PACKAGE_LIBGTK2
help
GQview is an image viewer for Unix operating systems
http://prdownloads.sourceforge.net/gqview
I
source "package/gqview/Config.in"
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
391/540
GQVIEW_VERSION = 2.1.5
GQVIEW_SOURCE = gqview-$(GQVIEW_VERSION).tar.gz
GQVIEW_SITE = http://prdownloads.sourceforge.net/gqview
GQVIEW_DEPENDENCIES = host-pkgconf libgtk2
GQVIEW_CONF_ENV = LIBS="-lm"
$(eval $(autotools-package))
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
392/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
393/540
Distributions - Debian
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
394/540
Distributions - Others
Fedora
I
http://fedoraproject.org/wiki/
Architectures/ARM
Ubuntu
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
395/540
Embedded distributions
Android: http://www.android.com/
Googles distribution for phones and tablet PCs.
Except the Linux kernel, very different user space
than other Linux distributions. Very successful, lots
of applications available (many proprietary).
Angstr
om:
http://www.angstrom-distribution.org/
Targets PDAs and webpads (Siemens Simpad...)
Binaries available for arm little endian.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
396/540
Application frameworks
Not real distributions you can download. Instead, they
implement middleware running on top of the Linux kernel
and allowing to develop applications.
I
Mer: http://merproject.org/
Fork from the Meego project.
Targeting mobile devices.
Supports x86, ARM and MIPS.
See http://en.wikipedia.org/wiki/Mer_
(software_distribution)
Tizen: https://www.tizen.org/
Targeting smartphones, tablets, netbooks, smart TVs
and In Vehicle Infotainment devices.
Supported by big phone manufacturers and operators
HTML5 base application framework.
Likely to compete against Android!
See http://en.wikipedia.org/wiki/Tizen
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
397/540
http://qemu.org
Fast processor emulator
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
398/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
399/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
400/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
401/540
Technical advantages
I
Graphical developments
tools
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
402/540
Best if you dont have your own support resources and have a
sufficient budget
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
403/540
Embedded Linux
application
development
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
404/540
Contents
Application development
I
I
Source management
I
I
Debuggers
Memory checkers
System analysis
Development environments
I
Developing on Windows
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
405/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
406/540
Application development
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
407/540
Programming language
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
408/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
409/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
410/540
CROSS_COMPILE?=arm-linuxCC=$(CROSS_COMPILE)gcc
OBJS=foo.o bar.o
all: foobar
foobar: $(OBJS)
$(CC) -o $@ $^
clean:
$(RM) -f foobar $(OBJS)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
411/540
Case of an application that uses the Glib and the GPS libraries
CROSS_COMPILE?=arm-linuxLIBS=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
412/540
Integrated Development
Environments (IDE)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
413/540
KDevelop
http://kdevelop.org
I
License: GPL
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
414/540
KDevelop screenshot
Ruby debugger
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
415/540
Eclipse (1)
http://www.eclipse.org/
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
416/540
Eclipse (2)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
417/540
Vim
Emacs
418/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
419/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
420/540
I
I
Subversion
I
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
421/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
422/540
Git
I
I
I
Mercurial
I
I
I
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
423/540
Debuggers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
424/540
GDB
The GNU Project Debugger
http://www.gnu.org/software/gdb/
I
425/540
break foobar
puts a breakpoint at the entry of function foobar()
break foobar.c:42
puts a breakpoint in foobar.c, line 42
print var or print task->files[0].fd
prints the variable var, or a more complicated reference. GDB
can also nicely display structures with all their members
continue
continue the execution
next
continue to the next line, stepping over function calls
step
continue to the next line, entering into subfunctions
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
426/540
GDB/Insight
http://sourceware.org/insight/
From the GDB maintainers.
KDbg
http://www.kdbg.org/
Another front-end, for the K Display Environment.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
427/540
Remote debugging
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
428/540
Remote debugging
I
gdb has direct access to the binary and libraries compiled with
debugging symbols.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
429/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
430/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
431/540
On the host
I
After the crash, transfer the core file from the target to the
host, and run
ARCH-linux-gdb -c core-file application-binary
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
432/540
Memory checkers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
433/540
DUMA
Detect Unintended Memory Access
http://duma.sourceforge.net/
I
GDB will then display the source-code line that causes the
bug.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
434/540
Valgrind (1)
http://valgrind.org/
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
435/540
Valgrind (2)
Example usage
valgrind --leak-check=yes ls -la
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
436/540
System analysis
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
437/540
strace
System call tracer
http://sourceforge.net/projects/strace/
I
Usage:
strace <command> (starting a new process)
strace -p <pid> (tracing an existing process)
438/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
439/540
ltrace
A tool to trace library calls used by a program and all the signals it
receives
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
440/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
441/540
ltrace summary
Example summary at the end of the ltrace output (-c option)
Process 17019 detached
% time
seconds usecs/call
calls
errors syscall
------ ----------- ----------- --------- --------- ---------------100.00
0.000050
50
1
set_thread_area
0.00
0.000000
0
48
read
0.00
0.000000
0
44
write
0.00
0.000000
0
80
63 open
0.00
0.000000
0
19
close
0.00
0.000000
0
1
execve
0.00
0.000000
0
2
2 access
0.00
0.000000
0
3
brk
0.00
0.000000
0
1
munmap
0.00
0.000000
0
1
uname
0.00
0.000000
0
1
mprotect
0.00
0.000000
0
19
mmap2
0.00
0.000000
0
50
46 stat64
0.00
0.000000
0
18
fstat64
------ ----------- ----------- --------- --------- ---------------100.00
0.000050 288 111 total
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
442/540
OProfile
http://oprofile.sourceforge.net
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
443/540
Callgrind / KCachegrind
KCachegrind: http://kcachegrind.sourceforge.net/
An amazing visualizer for Cachegrind / Callgrind data.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
444/540
KCachegrind screenshot
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
445/540
Application development
I
Remote debugging
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
446/540
Developing on Windows
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
447/540
Developing on Windows!?
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
448/540
Cygwin
http://cygwin.com/
Linux (POSIX)-like environment for Windows
I
2 components:
Linux API emulation layer: cygwin1.dll
A collection of tools originally found in
GNU/Linux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
449/540
Cygwin limitations
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
450/540
VirtualBox
See http://en.wikipedia.org/wiki/VirtualBox
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
451/540
Real-time in
embedded Linux
systems
Free Electrons
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
452/540
Introduction
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
453/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
454/540
I
I
The main goal was to get the best throughput from the
available hardware, by making the best possible usage of
resources (CPU, memory, I/O)
Time determinism was not taken into account
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
455/540
Approach 2
I
Add a layer below the Linux kernel that will handle all the
real-time requirements, so that the behaviour of Linux doesnt
affect real-time tasks.
Approach taken by RTLinux, RTAI and Xenomai
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
456/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
457/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
458/540
Understanding latency
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
459/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
460/540
Interrupt latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
461/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
462/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
463/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
464/540
Scheduler latency
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
465/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
466/540
This means that the time before which the scheduler will be
called to schedule another task is unbounded.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
467/540
Scheduler duration
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
468/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
469/540
Priority inversion
A process with a low priority might hold a lock needed by a higher
priority process, effectively reducing the priority of this process.
Things can be even worse if a middle priority process uses the CPU.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
470/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
471/540
https://rt.wiki.kernel.org
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
472/540
O(1) scheduler
Kernel preemption
Better POSIX real-time
API support
Since 2.6.18
I
Priority inheritance
support for mutexes
Since 2.6.21
I
Since 2.6.30
I
High-resolution timers
Threaded interrupts
Since 2.6.33
I
Spinlock annotations
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
473/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
474/540
CONFIG_PREEMPT_NONE
Kernel code (interrupts, exceptions, system calls) never preempted.
Default behavior in standard kernels.
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
475/540
CONFIG_PREEMPT_VOLUNTARY
Kernel code can preempt itself
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
476/540
CONFIG_PREEMPT
Most kernel code can be involuntarily preempted at any time.
When a process becomes runnable, no more need to wait for kernel
code (typically a system call) to return before running the
scheduler.
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
477/540
Priority inheritance
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
478/540
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
479/540
Threaded interrupts
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
480/540
See http://lwn.net/Articles/604695/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
481/540
PREEMPT RT specifics
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
482/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
483/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
484/540
Threaded interrupts
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
485/540
Setting up PREEMPT RT
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
486/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
487/540
CONFIG_PREEMPT_RT
High-resolution timers
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
488/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
489/540
Compile a program
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
490/540
Process, thread?
I
I
I
I
They run in the same address space as the initial thread of the
process
They start executing a function passed as argument to
pthread_create()
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
491/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
492/540
Creating threads
I
The new thread will run in the same address space, but will
be scheduled independently
pthread_exit(void *value_ptr);
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
493/540
I
I
The highest priority process gets all the CPU time, until it
blocks.
In SCHED_RR, round-robin scheduling between the processes of
the same priority. All must block before lower priority
processes get CPU time.
Priorities ranging from 0 (lowest) to 99 (highest)
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
494/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
495/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
496/540
Memory locking
mlockall(MCL_CURRENT | MCL_FUTURE);
I
Stack pages
Dynamically-allocated memory
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
497/540
Mutexes
I
Initialization/destruction
pthread_mutex_init(pthread_mutex_t *mutex,
const pthread_mutexattr_t *mutexattr);
pthread_mutex_destroy(pthread_mutex_t *mutex);
I
Lock/unlock
pthread_mutex_lock(pthread_mutex_t *mutex);
pthread_mutex_unlock(pthread_mutex_t *mutex);
I
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
498/540
Timers
Timer creation
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
499/540
Timers (2)
Delete a timer
timer_delete(timer_t timerid)
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
500/540
Signals
I
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
501/540
Inter-process communication
Semaphores
I
I
Message queues
I
I
Shared memory
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
502/540
Debugging latencies in
PREEMPT RT
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
503/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
504/540
Using ftrace
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
505/540
Disable tracing:
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
506/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
507/540
Useful reading
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
508/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
509/540
RTLinux
RTAI
Xenomai
A common principle
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
510/540
RTLinux
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
511/540
RTAI
http://www.rtai.org/ - Real-Time Application Interface for
Linux
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
512/540
Xenomai project
http://www.xenomai.org/
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
513/540
Xenomai architecture
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
514/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
515/540
Xenomai features
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
516/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
517/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
518/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
519/540
Setting up Xenomai
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
520/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
521/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
522/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
523/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
524/540
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
525/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
526/540
http://xenomai.org/documentation/branches/v2.4.x/
pdf/Native-API-Tour-rev-C.pdf
Usable both in user space and kernel space. Development of
tasks in user space is the preferred way.
More coherent and more flexible API than the POSIX API.
Easier to learn and understand. Certainly the way to go for
new applications.
To compile applications:
527/540
rt_task_create(), rt_task_start(),
rt_task_suspend(), rt_task_resume(),
rt_task_delete(), rt_task_join(), etc.
rt_queue_create(), rt_queue_delete(),
rt_queue_alloc(), rt_queue_free(), rt_queue_send(),
rt_queue_receive(), etc.
Mutex services
I
rt_mutex_create(), rt_mutex_delete(),
rt_mutex_acquire(), rt_mutex_release(), etc.
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
528/540
Alarm services
I
rt_alarm_create(), rt_alarm_delete(),
rt_alarm_start(), rt_alarm_stop(), rt_alarm_wait(),
etc.
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()
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
529/540
I
I
Using rt pipes
In the native Xenomai application, use the Pipe API
I
rt_pipe_create(), rt_pipe_delete(),
rt_pipe_receive(), rt_pipe_send(), rt_pipe_alloc(),
rt_pipe_free()
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
530/540
See results at
http://xenomai.org/~gch/core-3.14-latencies/
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
531/540
Books
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
532/540
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
533/540
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
534/540
References
Free Electrons
References
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
535/540
Books
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
536/540
Web sites
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
537/540
International conferences
Useful conferences featuring embedded Linux and kernel topics
I
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
538/540
Last slides
Free Electrons
Last slides
Embedded Linux
Developers
Free Electrons
Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com
539/540
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
540/540