introduction to embedded linux - bootlin – formerly free...

103
Embedded Linux Embedded Linux Introduction Thomas Petazzoni Free Electrons thomas.petazzoni@free- electrons.com Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1

Upload: trinhkhuong

Post on 16-May-2018

238 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Embedded Linux

Embedded LinuxIntroduction

Thomas PetazzoniFree [email protected]

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 1

Page 2: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Thomas Petazzoni

I Thomas PetazzoniI Embedded Linux engineer and trainer at Free Electrons since

January 2008I Linux user and developer since 2000I Given more than 120 days of embedded Linux training around

the worldI Linux kernel development, embedded Linux system integration,

boot time and power consumption optimization, consulting, forvarious customers on ARM, MIPS, Blackfin and x86 basedsystems

I Major contributor to Buildroot, an open-source, simple andfast embedded Linux build system

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 2

Page 3: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Free Electrons

I Free Electrons, specialized in Embedded Linux, since 2005

I Strong emphasis on community relationI Training

I Embedded Linux system developmentI Linux kernel and device driver developmentI Upcoming public sessions in Avignon, Lyon and Toulouse, or

sessions at customer locationI All training materials freely available under a Creative

Commons license.

I Development and consultingI Board Support Package development or improvementI Kernel and driver developmentI Embedded Linux system integrationI Power-management, boot-time, performance audits and

improvementI Embedded Linux application development

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 3

Page 4: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Free Electrons customers

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 4

Page 5: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Free Electrons trainings

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 5

Page 6: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Agenda

I Introduction: open-source and free software principles,advantages in the embedded space, hardware needed forembedded Linux

I Open Source for embedded systems: tools, bootloaders,kernel, system foundations, graphics and multimedia,networking, real-time, etc.

I Development process of an embedded Linux system

I Commercial support, community support

I Android

I Conclusion

I Q&A

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 6

Page 7: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

About free software

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 7

Page 8: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Birth of free software

I 1983, Richard Stallman: GNU project and concept of “freesoftware”. Start of development of gcc, gdb, glibc, etc.developed.

I 1991, Linus Torvalds launches the Linux project, a Unix-likeoperating system kernel. Together with GNU software andother free software components, it creates a complete andusable operating system: GNU/Linux

I ≈ 1995, Linux is more and more widely used on serversystems.

I ≈ 2000, Linux is more and more widely used in embeddedsystems

I ≈ 2005, Linux is more and more widely used in desktopsystems

Free software is no longer a “new” thing, it has been wellestablished for many years

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 8

Page 9: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Free software

A program is considered free when its license offers to all its usersthe following freedoms:

I Freedom to run the software, for any purpose

I Freedom to study how the software works, and change it

I Freedom to redistribute copies

I Freedom to distribute copies of modified versions

These freedoms are granted for both commercial andnon-commercial use, without distinction.Those freedoms imply that the source code is available, itcan modified to match the needs of a given product, and theresult can be distributed to customers ⇒ good match forembedded systems!

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 9

Page 10: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Advantages of open-source inembedded systems

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 10

Page 11: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Re-using components

I The key advantage when using Linux and open-sourcecomponents in embedded systems is the ability to re-useexisting components.

I The open-source ecosystem already provides manycomponents for standard features, from hardware support tonetwork protocols, going through multimedia, graphic,cryptographic libraries, etc.

I As soon as a hardware device, or a protocol, or a feature iswide-spread enough, high chance of having open-sourcecomponents that support it.

I Allows to quickly design and develop complicated products,based on existing components.

I No-one should re-develop yet another operating system kernel,TCP/IP stack, USB stack or another graphical toolkit library.

I Allows to focus on the added value of your product.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 11

Page 12: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Low cost

I Free software can be duplicated on as many devices as youwant, free of charge.

I If your embedded system uses only free software, you canreduce the cost of software to zero. Even the developmenttools are free, unless you choose a commercial embeddedLinux edition.

I Allows to have an higher budget for the hardware or toincrease the company’s skills and knowledge

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 12

Page 13: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Full control

I With open-source, you have the source code for allcomponents in your system

I Allows unlimited modifications, changes, tuning, debugging,optimization, for an unlimited period of time

I Without locking or dependency from a third-party vendor

I To be true, non open-source components must be avoidedwhen the system is designed and developed

I Allows to have full control over the software part of yoursystem

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 13

Page 14: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Quality

I Many open-source components are widely used, on millions ofsystems

I Higher quality than what an in-house development canproduce, or even proprietary vendors

I Of course, not all open-source components are of goodquality, but most of the widely-used ones are.

I Allows to design your system with high-qualitycomponents at the foundations

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 14

Page 15: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Test of possible components

I Open-source being freely available, it is easy to get one andevaluate it

I Allows to easily study several options while making a choice

I Much easier than purchasing and demonstration proceduresneeded with most proprietary products

I Allows to easily explore new possibilities and solutions

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 15

Page 16: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Community support

I Open-source software components are developed bycommunities of developers and users

I This community can provide a high-quality support: you candirectly contact the main developers of the component youare using

I Often better than traditional support, but one needs tounderstand how the community works to properly use thecommunity support possibilities

I Allows to speed up the resolution of problems whendeveloping your system

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 16

Page 17: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Taking part into the community

I Possibility of taking part into the development community ofsome of the components used in the embedded systems: bugreporting, test of new versions or features, patches that fixbugs or add new features, etc.

I Most of the time the open-source components are not thecore value of the product: it’s the interest of everybody tocontribute back.

I For the engineers: a very motivating way of being recognizedoutside the company, communication with others in the samefield, opening of new possibilities, etc.

I For the managers: motivation factor for engineers, allows thecompany to be recognized in the open-source community andtherefore get support more easily and be more attractive toopen-source developers

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 17

Page 18: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Drawbacks

I Large choice: community support or commercial support?Which company for the support? Which software solution?

I At the same time a strength and a drawback of free softwareand open source

I New skills needed compared to bare metal development ordevelopment with traditional embedded operating systems.

I Need for trainingI Need for recruiting new profiles

I Licensing fearI Generally over-exaggerated

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 18

Page 19: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Hardware for embedded Linux

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 19

Page 20: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Processor architecture

I The Linux kernel and most other architecture-dependentcomponent support a wide range of 32 and 64 bitsarchitectures

I x86 and x86 64, as found on PC platforms, but also embeddedsystems (multimedia, industrial)

I ARM, with hundreds of different SoC (multimedia, industrial)I PowerPC (mainly real-time, industrial applications)I MIPS (mainly networking applications)I SuperH (mainly set top box and multimedia applications)I Blackfin (DSP architecture)I Microblaze (soft-core for Xilinx FPGA)I Coldfire, SCore, Tile, Xtensa, Cris, FRV, AVR32, M32R

I Both MMU and no-MMU architectures are supported,even though no-MMU architectures have a few limitations.

I Linux is not designed for small microcontrollers.

I Besides the toolchain, the bootloader and the kernel, all othercomponents are generally architecture-independent

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 20

Page 21: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

RAM and storage

I RAM: a very basic Linux system can work within 8 MB ofRAM, but a more realistic system will usually require at least32 MB of RAM. Depends on the type and size of applications.

I Storage: a very basic Linux system can work within 4 MB ofstorage, but usually more is needed.

I flash storage is supported, both NAND and NOR flash, withspecific filesystems

I Block storage including SD/MMC cards and eMMC issupported

I Not necessarily interesting to be too restrictive on the amountof RAM/storage: having flexibility at this level allows tore-use as many existing components as possible.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 21

Page 22: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Communication

I The Linux kernel has support for many commoncommunication busses

I I2CI SPII CANI 1-wireI SDIOI USB

I And also extensive networking supportI Ethernet, Wifi, Bluetooth, CAN, etc.I IPv4, IPv6, TCP, UDP, SCTP, DCCP, etc.I Firewalling, advanced routing, multicast

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 22

Page 23: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

ARM and System-on-Chip

I ARM is one of the most popular architectures used inembedded Linux systems

I ARM designs CPU cores (instruction sets, caches, MMU,etc.) and sells the design to licensees

I The licensees are founders (Texas Instruments, Freescale, STEricsson, Atmel, etc.), they integrate an ARM core with manyperipherals, into a chip called a SoC, for System-on-chip

I Each founder provides different models of SoC, with differentcombination of peripherals, power, power consumption, etc.

I The concept of SoC allows to reduce the number ofperipherals needed on the board, and therefore the cost ofdesigning and building the board.

I Linux supports SoCs from most vendors, but not all, andnot with the same level of functionality.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 23

Page 24: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

ARM and System-on-Chip

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 24

Page 25: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Atmel AT91SAM9263

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 25

Page 26: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Texas Instruments OMAP3430

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 26

Page 27: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Type of hardware platforms

I Evaluation platforms from the SoC vendor. Usuallyexpensive, but many peripherals are built-in. Generallyunsuitable for real products.

I Component on Module, a small board with onlyCPU/RAM/flash and a few other core components, withconnectors to access all other peripherals. Can be used tobuild end products for small to medium quantities.

I Community development platforms, a new trend to make aparticular SoC popular and easily available. Those areready-to-use and low cost, but usually have less peripheralsthan evaluation platforms. To some extent, can also be usedfor real products.

I Custom platform. Schematics for evaluation boards ordevelopment platforms are more and more commonly freelyavailable, making it easier to develop custom platforms.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 27

Page 28: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Gumstix

I TI OMAP3530 (600 MHz, ARMCortex-A8, PowerVR SGX, DSP)

I Component on Module

I 256 MB RAM

I 256 MB NAND

I Bluetooth, Wifi

I uSD

I $229

I Development boards available at $49-229, with many peripherals: LCD,Ethernet, UART, SPI, I2C, etc.

I http://www.gumstix.com

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 28

Page 29: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Armadeus

I Freescale i.MX 27, 400 MHz

I Component on Module

I 128 MB RAM

I 256 MB NAND

I FPGA Xilinx Spartan 3A

I 116 e

I Development boards available at130-230 e, with peripherals(Ethernet, serial, etc.) and accessto UART, SPI, I2C, PWM, GPIO,USB, SD, LCD, Keypad, etc.

I http://www.armadeus.com

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 29

Page 30: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Calao TNY A9G20

I Atmel AT91 9G20, 400MHz

I Component on Module

I 64 MB RAM

I 256 MB NAND

I 152 e

I Many expansion boardsavailable

I http://www.

calao-systems.com

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 30

Page 31: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

BeagleBoard

I TI OMAP DM3730 (1GHz, cortex A8, PowerVRGPU, DSP)

I Community developmentplatform

I 512 MB RAM

I eMMC, microSD, Ethernet

I HDMI, S-Video, Camera,audio

I Expansion: USB, I2C, SPI,LCD, UART, GPIO, etc.

I $ 149

I http://beagleboard.org

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 31

Page 32: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Snowball

I ST Ericsson AP9500 (dualcortex A9, MALI GPU)

I Community developmentplatform

I 1 GB RAM

I 4-8 GB eMMC, microSD

I HDMI, S-Video, audio

I Wifi, Bluetooth, Ethernet

I Accelerometer, Magnetometer,Gyrometer, GPS

I Expansion: USB, I2C, SPI,LCD, UART, GPIO, etc.

I 169 e to 244 e

I http://igloocommunity.orgFree Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 32

Page 33: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Freescale Quick Start

I Freescale I.MX53 (1 GHzCortex A8)

I Community developmentplatform

I 1 GB RAM

I 4-8 GB eMMC, microSD

I LVDS, LCD, VGA, HDMI,audio

I Accelerometer, SD/MMC,microSD, SATA, Ethernet,USB

I Expansion: I2C, SPI, SSI, LCD,Camera

I 149 e

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 33

Page 34: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Criteria for choosing the hardware

I Make sure the hardware you plan to use is already supportedby the Linux kernel, and has an open-source bootloader,especially the SoC you’re targeting.

I Having support in the official versions of the projects (kernel,bootloader) is a lot better: quality is better, and newversions are available.

I Some SoC vendors and/or board vendors do not contributetheir changes back to the Linux kernel. Ask them to do so, oruse another product if you can. A good measurement is to seethe delta between their kernel and the official one.

I Between properly supported hardware in the official Linuxkernel and poorly-supported hardware, there will be hugedifferences in development time and cost.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 34

Page 35: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Embedded systems using Linux

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 35

Page 36: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Consumer device: Internet box

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 36

Page 37: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Consumer device: Network Attached Storage

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 37

Page 38: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Consumer device: Television

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 38

Page 39: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Professional device: point of sale terminal

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 39

Page 40: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Industrial system: laser cutter

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 40

Page 41: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Industrial system: wind turbine

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 41

Page 42: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Industrial system: cow milking

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 42

Page 43: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Industrial system: snow removal equipment

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 43

Page 44: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Industrial system: sea pollution detection system

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 44

Page 45: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Industrial system: viticulture machine

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 45

Page 46: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Open-source components forembedded systems

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 46

Page 47: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Four major components

Every embedded Linux system needs four major components towork:

I Toolchain, which doesn’t run on the target platform, butallows to generate code for the target from a developmentmachine.

I Bootloader, which is responsible for the initial boot processof the system, and for loading the kernel into memory

I Linux Kernel, with all the device drivers

I Root filesystem, which contains all the applications andlibraries

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 47

Page 48: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Four major components

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 48

Page 49: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Toolchain

The toolchain is usually a cross-compilation toolchain: it runs on adevelopment machine and generates code for the embeddedplatform. It has the following components:

I binutils, the binary manipulation utility including anassembler and a linker

I gcc, the C/C++ (and more) compiler, which is the standardin the open-source world

I a C library, which offers the POSIX interface to userspaceapplications. Several C libraries are available: glibc, eglibc anduClibc, with different size/features.

I gdb, the debugger, which allows remote debugging

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 49

Page 50: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Getting a cross-compilation toolchain

I Pre-compiled toolchains are the easiest solution. Thetoolchains from CodeSourcery are very popular.http://www.codesourcery.com/

I Crosstool-NG is a tool that automates the process ofgenerating the toolchain. Allows more flexibility thanpre-compiled toolchains.http://www.crosstool-ng.org

I Embedded Linux build systems are also usually capable ofgenerating their own cross-compilation toolchain.

Make sure to get a toolchain that matches your hardware and yourneeds.The toolchains provided by the hardware vendors are often old andrusty.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 50

Page 51: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Bootloader: principle

I The role of the bootloader is to initialize some basic hardwareperipherals, load the Linux kernel image and run it.

I The boot process of most recent embedded processors is thefollowing:

1. The processor executes code in ROM, to load a first-stagebootloader from NAND, SPI flash, serial port or SD card

2. The first stage bootloader initializes the memory controllerand a few other peripherals, and loads a second stagebootloader. No interaction is possible with this first stagebootloader, and it is typically provided by the CPU vendor.

3. The second stage bootloader offers more features: usually ashell, with commands. It allows to manipulate the storagedevices, the network, configure the boot process, etc. Thisbootloader is typically generic and open-source.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 51

Page 52: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Bootloader: principle

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 52

Page 53: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Open-source bootloaders

I U-Boot is the de-facto standard in open-source bootloaders.Available on ARM, PowerPC, MIPS, m68k, Microblaze, x86,NIOS, SuperH, Sparc. Huge hardware support available, largenumber of features (networking, USB, SD, etc.)http://www.denx.de/wiki/U-Boot

I Barebox, a newer open-source bootloader, with a cleanerdesign than U-Boot, but less hardware support for themoment.http://www.barebox.org

I GRUB, the standard for x86 PC.http://www.gnu.org/software/grub/

Make sure your hardware comes with one of these well-knownopen-source bootloaders.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 53

Page 54: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Linux kernel

I The Linux kernel is a core piece of the system. It provides themajor following features:

I Process managementI Memory managementI Inter-process communication, timersI Device drivers for the hardware: input, sound, network,

storage, graphics, data acquisition, timers, GPIO, etc.I FilesystemsI NetworkingI Power management

I The Linux kernel has thousands of options to selectivelyenable or disable features depending on the system needs.

I Under the GPLv2 license.

I http://www.kernel.org

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 54

Page 55: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Kernel vs. userspace

I The Linux kernel runs in privileged mode. It can access andcontrol the hardware. Its role is to multiplex the availableresources, and provide coherent and consistent interfaces touserspace.

I Userspace is the set of applications and libraries that run onthe system. They work in unprivileged mode. They must gothrough the kernel to access the system resources, includingthe hardware. The kernel provides isolation betweenapplications.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 55

Page 56: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Kernel vs. userspace

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 56

Page 57: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

The kernel for your platform

The Linux kernel is highly-portable across architectures. Therefore,the code is split into several levels:

I Code generic to all architectures: ARM, x86, PowerPC, etc.

I Code specific to an architecture

I Code specific to a System-on-Chip: Atmel AT91, TIOMAP3, Freescale i.MX, etc.

I Code specific to a board, which consists of a particular SoCwith additional peripherals on the board

If your SoC is well supported, the only part of the code that needsto be modified is the part specific to the board. Except if you needadditional device drivers.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 57

Page 58: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Kernel compilation

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 58

Page 59: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Kernel programming

I The programming environment inside the Linux kernel is verydifferent from the one in userspace: different API, differentconstraints, different mechanisms

I No standard C library, a specific API is availableI No memory protection

I Programming in the kernel is typically needed toI adapt the kernel to a particular boardI write device drivers

I There are many resources on kernel programming:I Linux Device Drivers, book from O’ReillyI Essential Linux Device Drivers, book from Prentice HallI Kernel programming training materials from Free Electrons

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 59

Page 60: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Root filesystem

I In a Linux system, applications, libraries, configuration anddata are stored into files in a filesystem

I A global single hierarchy of directories and files is used torepresent all the files in the system, regardless of their storagemedium or location.

I A particular filesystem, called the root filesystem is mountedat the root of this hierarchy.

I This root filesystem typically contains all files needed for thesystem to work properly.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 60

Page 61: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Filesystems

The Linux kernel supports a wide-range of filesystem types:

I ext2, ext3, ext4 are the default filesystem types for Linux.They are usable on block devices.

I jffs2, ubifs are the filesystems usable on flash devices(NAND, NOR, SPI flashes). Note that SD/MMC cards orUSB keys are not flash devices, but block devices.

I squashfs is a read-only highly-compressed filesystem,appropriate for all system files that never change.

I vfat, nfts, the Windows-world filesystems, are also supportedfor compatibility

I nfs, cifs are the two most important network filesystemssupported

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 61

Page 62: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Minimum contents of a root filesystem

I An init application, which is the first application started bythe kernel when the system boots. init is in charge of startingshells, system services and applications.

I A shell and associated tools, in order to interact with thesystem. The shell will typically operate over a serial port.

I The C library, which implements the POSIX interface, usedby all applications.

I A set of device files. Those are special files that allowapplications to perform operations on the devices managed bythe kernel.

I A typical Unix hierarchy, with the bin, dev, lib, sbin,usr/bin, usr/lib, usr/sbin, proc, sys

I The proc and sysfs virtual filesystems mounted

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 62

Page 63: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Busybox

I In a normal Linux system, all core components are spread intodifferent projects and not implemented with embeddedconstraints in mind

I Busybox provides a highly-configurable compilation of all thebasic commands needed in a Linux system: cp, mv, sh, wget,grep, init, modprobe, udhcpc, httpd

I All those commands are compiled into a single binary, and thecommands are symbolic links to this binary. Veryspace-efficient on systems where static compilation is used.

I Under the GPLv2 license

I http://www.busybox.net

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 63

Page 64: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Application development in a basic system

I With just Busybox and the C library, we have a fully workingembedded Linux system

I The C library implements the well-known POSIX interface,which provides an API for process control, signals, file anddirectory operations, timers, pipes, the C standard library(string functions, etc.), memory management, semaphores,shared memory, thread management, etc.

I This is an already very comfortable environment to developapplications in C or C++ that can interact with the hardwaredevices, do some computations, react on hardware devices.

I Thanks to Busybox, you can even easily provide a Web serverto monitor the system.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 64

Page 65: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Interaction with the hardware

There are different ways of interacting with the hardware:

I The kernel has a device driver for the device, in which case itcan be accessed either through a device file in /dev with thestandard file API, through a text file in the sysfs filesystem orthrough the networking API.

I Userspace applications running as root can use the /dev/mem

special device to access directly the physical memory, or betteruse the UIO framework of the kernel.

I For the SPI and I2C busses, there are special /dev/spidevXand /dev/i2cdevX to send/receive messages on the bus,without having a kernel device driver. For USB, the libusb

library allows userspace USB device drivers.

The choice of one solution over another depends on the type ofdevice, and the need of interaction with existing kernel subsystems.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 65

Page 66: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Graphics

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 66

Page 67: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Drawing

I X.org, http://www.x.orgI A client/server approach. The server manages the hardware

(graphics and input), and provides a protocol to clients. Theclients are all applications that want to draw things and receiveinput events.

I The solution used on all desktop Linux systems. The X Serverimplements the well-known X11 protocol.

I Client libraries are available, but applications can hardly bewritten against them: too low-level. Toolkits are used on topof it.

I DirectFB, http://www.directfb.orgI A library over the kernel framebuffer driver, which allows to

handle input events.I More lightweight than the X Server, but without the X11

protocol compatibility, and with a bit less features.I The API can directly be used to develop applications, but

toolkits can also be used on top of it.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 67

Page 68: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Toolkits

Toolkits provide high-level API to build graphical interfaces withwindows, buttons, text inputs, drop-down lists, check boxes,canvas, etc.

I Qt, http://qt.nokia.comI A complete development framework in C++, with event

management, networking, timers, threads, XML... and graphicsI Used as the foundation for the KDE desktop environment on

Linux systems, but also very popular on embedded systems.I Works on X.org, on the framebuffer or on top of DirectFB

I Gtk, http://www.gtk.orgI Also a complete development framework, in C.I Used as the foundation for the GNOME desktop environment

on Linux systems. Probably less popular on embedded systems.I Works on X.org and on DirectFB

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 68

Page 69: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Sound

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 69

Page 70: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Sound stack

I ALSA is the kernel subsystem for sound deviceshttp://www.alsa-project.org

I alsa-lib is the userspace library that allows applications to useALSA drivers. It is a fairly low-level library.

I PulseAudio is a sound server. It manages multiple audiostreams, can adjust their volume independently, redirect themdynamically, etc.http://www.pulseaudio.org

I GStreamer is a multimedia framework. With a collection ofinput, output, decoding and encoding plugins, one can buildcustom pipelines, to encode, decode and display video oraudio streamshttp://www.gstreamer.org

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 70

Page 71: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Video stack

I X.org or the framebuffer are typically used as video-outputdevices

I The Video4Linux kernel subsystem supports video-inputdevices and some video-output devices that do overlay.

I The GStreamer multimedia framework video decoding andencoding

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 71

Page 72: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Networking

Linux is well-known system its networking capabilities:

I Support for Ethernet, CAN, Wifi, Bluetooth devices in thekernel, and associated userspace configuration applications

I Web servers: httpd in Busybox, lighttpd, boa, etc.

I SSH servers: Dropbear, OpenSSH

I Cryptography/VPN: OpenSSL, OpenVPN

I GPRS/Modem: pppd

I Firewall: Netfilter in the kernel, iptables command inuserspace

I And also: mail server, SNMP, NTP, etc.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 72

Page 73: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

The service infrastructure

I Standardization of services around an inter-processcommunication bus: D-Bus. Allows programs to offer servicesto other programs, and to signal them events in the system.

I Used to split the low-level mechanisms from the graphicalinterfaces.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 73

Page 74: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Real-time

Three solutions for real-time in Linux:

I Use the standard kernel. It has been improved over the yearsfor real-time applications (kernel preemption, high-resolutiontimers, priority inheritance, support for the POSIX real-timeAPI, etc.)

I Use the PREEMPT RT patches. Those are patches againstthe Linux kernel that further improves its behaviour forreal-time (more complete preemption, interrupt handlers inthreads, etc.)http://rt.wiki.kernel.org

I Use one of the co-kernel solutions: Xenomai or RTAI.Real-time tasks are scheduled by a dedicated real-time core,and Linux runs as a low-priority task.http://www.xenomai.org

http://www.rtai.org

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 74

Page 75: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Example: exercise bike

System that shows the performance and progression of the bikeuser, with a graphical interface and connection to the hardware.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 75

Page 76: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Embedded Linux developmentprocess

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 76

Page 77: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Three major steps

I Board Support Package development

I System integration

I Application development

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 77

Page 78: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Board Support Package

I The BSP is the base of the system, that heavily depends onthe hardware: toolchain, bootloader and Linux kernel

I Important questionsI Are the bootloader and Linux kernel versions sufficiently

recent? With too old versions you miss features, and moreimportantly, you loose all community support.

I Is support available in the mainline official versions of thebootloader and the kernel? This is the best solution, as itguarantees that you will benefit from updated versions.

I If provided by the hardware vendor, how big is the delta withthe official version? When the delta is too large, it is hard toupgrade to newer versions → you will be blocked.

I Are there binary drivers? They will prevent you to upgrade thekernel.

I These components are critical. Don’t rely on old versions with hugemodifications from the hardware vendor.

I Make sure you keep separate: the official version from which thedevelopment was started, the hardware vendor modifications, and yourown modifications.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 78

Page 79: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

System integration

I Integrate all the open-source components needed for yoursystem and your custom libraries and applications.

I This involves configuring and cross-compiling a lot ofcomponents, with sometimes complex dependencies and/ornon-trivial compilation mechanism, especially in across-compilation context.

I Don’t do this by hand, and don’t re-invent the wheel bywriting your own build system.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 79

Page 80: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

System integration: solutions

I Some binary distributions, such as Debian, are available forembedded architectures (ARM, PowerPC, MIPS, etc.).

I Advantages: everything is already compiled, easy toadd/remove components, nice package management system.

I Drawbacks: not a lot of control on the componentconfiguration, code not necessarily optimized for your hardwareplatform, fairly big system that often needs to be strippeddown, no mechanism to reproduce the build.

I Embedded Linux build systems, that build from source allthe elements of a Linux system and generates the rootfilesystem image (and more)

I Advantages: huge control over the system and componentsconfiguration, automated mechanism to reproduce the build,lightweight system.

I Drawbacks: need to learn a new tool, long compilation times.

Do not use the demonstration root filesystem of the hardwarevendor as a starting point: you have no way to reproduce the buildand you don’t control its components.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 80

Page 81: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Embedded Linux build system: principle

Some common open-source build systems:I Buildroot, http://www.buildroot.orgI OpenEmbedded, http://www.openembedded.orgI Yocto, http://www.yoctoproject.orgI and others: PTXdist, OpenBricks, OpenWRT, etc.I Note: the hardware vendor specific build systems are usually

of bad quality. Replace it with an independent,community-driven build system.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 81

Page 82: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Embedded Linux build system: example of Buildroot

I A configuration interface similar to the kernel one allows todefine all aspects of the system: CPU architecture, softwarecomponents needed, filesystem type for the root filesystemimage, kernel version and configuration, bootloader versionand configuration, etc.

I Once the configuration is done, Buildroot takes care of allthe steps: downloading, extracting, patching, configuring,compiling and installing all components, in the right order.

I More than 600 software components already available

I Simple to use, regular stable releases, active community

I Very easy to add new software components, eitheropen-source or in-house

I Drawbacks: full rebuilds often needed, no packagemanagement system on the target.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 82

Page 83: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Choosing open-source components

There are several criteria to look at when choosing an open-sourcecomponent:

I Component quality. Is there sufficient documentation? Isthe component widely used (presence in embedded Linuxbuild systems is a good indicator)

I Community vitality. Is the component still being developedactively? Is the community responsive to bug reports andquestions? When was the last stable release? Is there regularactivity in the revision control system?

I License. Does the license of the component matches therequirement of your product?

I Technical requirements. Does it offer the features youneed? Is it appropriate in terms of storage, CPU and memoryconsumption?

→ Components already available in embedded Linux build systemsare often a good starting point.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 83

Page 84: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Application development

I Application development in embedded Linux systems is justthe same as developing applications in a normal Linux system:same development tools, same libraries.

I The standard language in Linux is C. All the system, andmany libraries are written in this language.

I C++ is also widely used.

I Many interpreted languages are available: Lua, Python, Perl,PHP. Do not neglect their usefulness for non-performancesensitive parts, since they typically allow faster development.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 84

Page 85: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Application and system debugging

I Cross-debugging with gdb and gdbserverI gdbserver runs on the target, and controls the execution of

the application to debugI gdb and potentially one of its graphical interfaces, runs on the

development machine, and talks to gdbserver throughEthernet or serial port.

I System call tracing with strace and library call tracing withltrace

I System-wide tracing with LTTng, http://lttng.org

I System-wide profiling with OProfile,http://oprofile.sourceforge.net

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 85

Page 86: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Licenses

I The free software licenses grants to everyone the set of fourfundamental freedoms, but they also have somerequirements.

I They fall into two main categories:I Copyleft licenses, that require modified versions to be

distributed under the same license.I Non-copyleft licenses, that do not require modified versions

to be distributed under the same license: they can be keptproprietary.

I The Free Software Foundation and the Open Source Initiativehave a list of licenses together with their opinion on them:http://www.gnu.org/licenses/license-list.html

http://opensource.org/licenses/index.html

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 86

Page 87: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

GPL

I General Public LicenseI The major copyleft license, covers ≈ 50% of the free

software projectsI For example: Busybox, Linux Kernel, U-Boot, etc.I Requires derivative works to be released under the same

license, including applications relying on a library licensedunder the GPL.

I The license requires you to ship the complete source code ofthe GPL components together with your product, includingyour modifications to these components, and attribution mustbe kept.

I No need to distribute the source code before the product isdistributed.

I License already enforced multiple times in court.I Even though the kernel is GPL, all userspace does not need to

be under the GPLFree Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 87

Page 88: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

GPL and kernel modules

I As the Linux kernel is under GPL, modifications to it must bereleased under the GPL

I Some kernel code can be written as modules, which can bedynamically loaded/unloaded at runtime.

I There is a debate whether kernel modules are derivativeworks of the kernel or not.

I No final answer on the question, opinions vary.

I Generally, the community opinion, including many kerneldevelopers, is that proprietary kernel modules are bad.

I “We, the undersigned Linux kernel developers, consider anyclosed-source Linux kernel module or driver to be harmful andundesirable.”,

I Easier to make your kernel code GPL, and leave theadded-value parts in userspace

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 88

Page 89: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

LGPL

I Lesser General Public License

I A weaker copyleft license, used for many libraries

I For example: Gtk, Qt, alsa-lib and most libraries

I Requires derivative works to be released under the samelicense, but non-free applications can be linked against aLGPL library, as long as the library can be replaced (dynamiclinking is used in general)

I The license also requires you to ship the complete source codeof the LGPL components, including your modifications.

I Beware that a few libraries are under the GPL: readline library,MySQL library, etc.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 89

Page 90: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Non-copyleft licenses

Many non-copyleft licenses are widely used. They do not requirederivative works to be distributed under the same license, butthe original project must still be credited.

I BSD license

I Apache license

I MIT license

I Artistic license

I X11 license

You are not required to distribute the source code for thesecomponents and you can integrate code from these componentsinto your proprietary applications.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 90

Page 91: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Licensing good practices

I Keep an accurate and complete list of all componentsyou use in your product, together with their respective license

I Make sure that the license of a component matches yourrequirements before basing all your product development on it.

I Keep your changes separate from the original version ofthe components. This allows for easier upgrades, but also torespect the licenses that want the changes from the originalversion to be clearly identified.Possible methods: stack of patches with Quilt, or branches ina revision control system.

I Do not copy/paste GPL/LGPL code into the parts of yoursystem that must remain proprietary.

I Comply with the licenses as soon as your product startsshipping.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 91

Page 92: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Licensing analysis

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 92

Page 93: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Working on embedded Linux

I Use Linux on the development stationI All community tools are developed by Linux developers, using

Linux as their desktop operating system. Trying to useWindows or Mac OS to do embedded Linux development willlead to difficulties

I Linux on the embedded system is the same as the Linux on thedesktop: many good embedded Linux engineers are justlong-time Linux users

I Have a good e-mail clientI Needed to interact with the communityI Your e-mail client must support threading, text-only e-mails

(no HTML) and proper wrappingI Don’t use Outlook or Lotus Notes, but instead Thunderbird,

Evolution, KMail, Claws-Mail, etc.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 93

Page 94: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Working on embedded Linux

I Have a good and unfiltered network connectivityI Need to have access to many resources: Git and SVN

repositories, IRC channels for discussion with the community,mailing-lists

I Having a standard SMTP server is also useful to send patches

I Control your system components, build procedure anduse revision control systems

I Don’t rely on prebuilt kernels or root filesystems, make sureyou have all the source code and the documentation or scriptsto rebuild all your system from scratch.

I Use revision control systems to keep track of the changes youmake to the different components you use in your system.

I A significant part of working with embedded Linux isintegration: it has to be done in a clean way.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 94

Page 95: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Support: full commercial solutions

I Vendors such as Montavista, Wind River or Timesys

I Provides integrated Board Support Package, system buildingtools, application development tools for embedded Linux,together with support.

I Advantages: single known representative to deal with,supposedly well-tested solutions and comprehensive support

I Drawbacks: dependency on vendor specific tools, vendorspecific kernel and component versions, lock-in, high cost,support not necessarily that good

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 95

Page 96: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Support: community

I The developers of the different components and theopen-source community as a whole generally provides goodand timely support.

I Through mailing-lists, IRC.

I Need to understand how the community works, or better bepart of it, to benefit from good support.

I Advantages: small cost, generally very quick and efficientfeedback, allows your engineers to gain knowledge

I Drawbacks: support only for recent versions of thecomponents, no clear representative, need to have someknowledge of how the community works, doesn’t work forclosed code

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 96

Page 97: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Support: commercial support to community solutions

I Companies that do not have any specific product, and providesupport for existing open-source components

I Companies such as Free Electrons, DENX, and hundreds ofother small to medium sized companies.

I Advantages: single known representative, usage of well-knownopen source components so that you remain independent fromthe support provider, support that cares about your specificproblem even if old components are used

I Drawbacks:?

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 97

Page 98: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Android

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 98

Page 99: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Android

I Android is the famous Linux-based embedded operatingsystem developed by Google, mainly targeted at phones, butusable for other applications as well

I Not a traditional Linux system: Google has only re-used theLinux kernel and a few userspace components, but the largemajority of the system is Android-specific→ need of specific skills and knowledge to work on Android

I The kernel needs fairly major modifications to beAndroid-compatible (power management, inter-processcommunication, etc.)

I Most components developed by Google are licensed under theApache license, the kernel is the only component under theGPL.

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 99

Page 100: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Android architecture

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 100

Page 101: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Conclusion

I Linux and the open source world offers a wide range ofcomponents and tools for embedded system development

I Those components have many advantages: focus on addedvalue, low cost, complete control, etc.

I Support is available, both from the community or commercialcompanies

I So what about Linux in your next embedded product?

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 101

Page 102: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Conclusion

I Linux and the open source world offers a wide range ofcomponents and tools for embedded system development

I Those components have many advantages: focus on addedvalue, low cost, complete control, etc.

I Support is available, both from the community or commercialcompanies

I So what about Linux in your next embedded product?

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 101

Page 103: Introduction to embedded Linux - Bootlin – Formerly Free …thomas/presentation-linux-embarqu… ·  · 2011-07-29embedded Linux I Open Source for embedded systems: tools, bootloaders,

Questions?

Thomas [email protected]

I Developpement noyau Linux et pilotes de peripheriques, 3 au 7 octobre, Avignon (anglais)

I Developpement systeme Linux embarque, 10 au 14 octobre, Lyon (francais)

I Developpement systeme Linux embarque, 21 au 25 novembre, Avignon (anglais)

I Developpement noyau Linux et pilotes de peripheriques, 5 au 9 decembre, Toulouse (francais)

I Developpement systeme Linux embarque, 6 au 10 fevrier 2012, Toulouse (francais)

I Toutes les informations sur http://free-electrons.com/fr/formation/sessions/

Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com 102