Sie sind auf Seite 1von 602
Free Electrons Embedded Linux training Gregory Clement Thomas Petazzoni Michael Opdenacker Free Electrons . Kernel,

Free Electrons

Embedded Linux training

Gregory Clement Thomas Petazzoni Michael Opdenacker

training Gregory Clement Thomas Petazzoni Michael Opdenacker Free Electrons . Kernel, drivers and embedded Linux

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

Rights to copy © Copyright 2004­2011, Free Electrons feedback@free­electrons.com Electronic version of this document
Rights to copy © Copyright 2004­2011, Free Electrons feedback@free­electrons.com Electronic version of this document

Rights to copy

© Copyright 2004­2011, Free Electrons feedback@free­electrons.com

Electronic version of this document available on http://free­electrons.com/doc/training/embedded­linux

Attribution – ShareAlike 3.0 You are free to copy, distribute, display, and perform the work to make derivative works to make commercial use of the work Under the following conditions

Attribution. You must give the original author credit. Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the copyright holder. Your fair use and other rights are in no way affected by the above. License text: http://creativecommons.org/licenses/by­sa/3.0/legalcode

Corrections, suggestions, contributions and translations are welcome!

Latest update: Mar 15, 2011

and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded
and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded
and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded
and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded
and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded
and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded
and translations are welcome! Latest update: Mar 15, 2011 Free Electrons . Kernel, drivers and embedded

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

Linux kernel

Linux device drivers Board support code Mainstreaming kernel code Kernel debugging

Embedded Linux Training

All materials released with a free license!

Unix and GNU/Linux basics Linux kernel and drivers development Real­time Linux, uClinux Development and profiling tools Lightweight tools for embedded systems Root filesystem creation Audio and multimedia System optimization

Free Electrons

Our services

Custom Development

System integration Embedded Linux demos and prototypes System optimization Application and interface development

Consulting and technical support

Help in decision making System architecture System design and performance review Development tool and application support Investigating issues and fixing tool bugs

System design and performance review Development tool and application support Investigating issues and fixing tool bugs
Hardware used in this training session Calao Systems USB­A9263 AT91SAM9263 ARM CPU 64 MB RAM

Hardware used in this training session

Calao Systems USB­A9263

used in this training session Calao Systems USB­A9263 AT91SAM9263 ARM CPU 64 MB RAM 256 MB
AT91SAM9263 ARM CPU

AT91SAM9263 ARM CPU

64 MB RAM

64 MB RAM

256

MB flash

2 USB 2.0 host

2 USB 2.0 host

1 USB device

100 Mbit Ethernet port

100

Mbit Ethernet port

Powered by USB! Serial and JTAG through this USB port.

Powered by USB! Serial and JTAG through this USB port.

Multiple extension boards.

Multiple extension boards.

Approximately 160 EUR

Approximately 160 EUR

Supported in mainstream Linux since version 2.6.27!

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

During the lectures Participate! Don't hesitate to ask questions. Other people in the audience may

During the lectures

Participate!

Don't hesitate to ask questions. Other people in the audience may have similar questions too.During the lectures Participate! This helps the trainer to detect any explanation that wasn't clear or

This helps the trainer to detect any explanation that wasn't clear or detailed enough.Other people in the audience may have similar questions too. Don't hesitate to share your experience,

Don't hesitate to share your experience, for example to compare Linux with other operating systems used in your company.any explanation that wasn't clear or detailed enough. Your point of view is most valuable, because

Your point of view is most valuable, because it can be similar to your colleagues' and different from the trainer's.Linux with other operating systems used in your company. Your participation can make our session more

Your participation can make our session more interactive and make the topics easier to learn.your colleagues' and different from the trainer's. Free Electrons . Kernel, drivers and embedded Linux

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

During practical labs Practical lab guidelines We cannot support more than 8 workstations at once

During practical labs

Practical lab guidelines

We cannot support more than 8 workstations at once (each with its board and equipment). Having more would make the whole class progress slower, compromising the coverage of the whole training agenda (exception for public sessions: up to 10 people).During practical labs Practical lab guidelines So, if you are more than 8 participants, please form

So, if you are more than 8 participants, please form up to 8 working groups.agenda (exception for public sessions: up to 10 people). Open the electronic copy of your lecture

Open the electronic copy of your lecture materials, and use it throughout the practical labs to find the slides you need again.than 8 participants, please form up to 8 working groups. Don't copy and paste from the

Don't copy and paste from the PDF slides. The slides contain UTF­8 characters that look the same as ASCII ones, but won't be understood by shells or compilers.the practical labs to find the slides you need again. Free Electrons . Kernel, drivers and

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

Command memento sheet This memento sheet gives command examples for the most typical needs (looking

Command memento sheet

Command memento sheet This memento sheet gives command examples for the most typical needs (looking for

This memento sheet gives

command examples for the most typical needs (looking for files,

extracting a tar archive

It saves us 1 day of UNIX / Linux command line training.

Our best tip: in the command line shell, always hit the [Tab] key to complete command names and file paths. This avoids 95% of typing mistakes.

)

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

vi basic commands The vi editor is very useful to make quick changes to files

vi basic commands

vi basic commands The vi editor is very useful to make quick changes to files in

The vi editor is very useful to make quick changes to files in a embedded target.

Though not very user friendly at first, vi is very powerful and its main 15 commands are easy to learn and are sufficient for 99% of everyone's needs!

You can also take the quick tutorial by running vimtutor. This is a worthy investment!

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

Cooperate! As in the Free Software and Open Source community, cooperation during practical labs is

Cooperate!

As in the Free Software and Open Source community, cooperation during practical labs is valuable in this training session:

If you complete your labs before other people, don't hesitate to help other people and investigate the issues they face. The faster we progress as a group, the more time we have to explore extra topics.during practical labs is valuable in this training session: Explain what you understood to other participants

Explain what you understood to other participants when needed. It also helps to consolidate your knowledge.as a group, the more time we have to explore extra topics. Don't hesitate to report

Don't hesitate to report potential bugs to your instructor.when needed. It also helps to consolidate your knowledge. Don't hesitate to look for solutions on

Don't hesitate to look for solutions on the Internet as well.hesitate to report potential bugs to your instructor. Free Electrons . Kernel, drivers and embedded Linux

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

Free Electrons Introduction to embedded Linux Michael Opdenacker Thomas Petazzoni Free Electrons © Copyright 2009,

Free Electrons

Introduction to embedded Linux

Michael Opdenacker Thomas Petazzoni Free Electrons

© Copyright 2009, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/embedded­linux­intro Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

Embedded system? An embedded system is a special­purpose computer system designed to perform one or

Embedded system?

An embedded system is a special­purpose computer system designed to perform one or a few dedicated functions, often with real­time computing constraints. It is usually embedded as part of a complete device including hardware and mechanical parts. In contrast, a general­ purpose computer, such as a personal computer, can do many different tasks depending on programming. Embedded systems control many of the common devices in use today.

2

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

Many different systems A very generic definition Covers very different types of systems Fuzzy border

Many different systems

A very generic definition

Covers very different types of systemsMany different systems A very generic definition Fuzzy border with “standard” systems. Consumer electronics (CE)

Fuzzy border with “standard” systems.generic definition Covers very different types of systems Consumer electronics (CE) products Home routers, DVD

Consumer electronics (CE) products

Home routers, DVD players, TV sets, digital cameras, GPS, camcorders, mobile phones, microwave ovens“standard” systems. Consumer electronics (CE) products Industrial products Machine control, alarms, surveillance

Industrial products

Machine control, alarms, surveillance systems, automotive, rail, aircraft, satellitemobile phones, microwave ovens Industrial products 3 Free Electrons . Kernel, drivers and embedded Linux

3

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

Many different products
Many different products

4

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

Embedded Linux The Free Software and Open Source world offers a broad range of tools

Embedded Linux

The Free Software and Open Source world offers a broad range of tools to develop embedded systems.Embedded Linux Advantages Reuse of existing components for the base system. Allows to focus on the

Advantagesoffers a broad range of tools to develop embedded systems. Reuse of existing components for the

Reuse of existing components for the base system. Allows to focus on the added value of the product.broad range of tools to develop embedded systems. Advantages High quality, proven components (Linux kernel, C

High quality, proven components (Linux kernel, C librariessystem. Allows to focus on the added value of the product. Complete control on the choice

Complete control on the choice of components. Modifications possible without external constraints.High quality, proven components (Linux kernel, C libraries Community support: tutorials, mailing lists Low cost, in

Community support: tutorials, mailing listsModifications possible without external constraints. Low cost, in particular no per­unit royalties. Potentially

Low cost, in particular no per­unit royalties.constraints. Community support: tutorials, mailing lists Potentially less legal issues. Easier access to software and

Potentially less legal issues.lists Low cost, in particular no per­unit royalties. Easier access to software and tools. ) 5

Easier access to software and tools.no per­unit royalties. Potentially less legal issues. ) 5 Free Electrons . Kernel, drivers and embedded

)

5

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

Device examples GPS: TomTom and Garmin Home network routers: Linksys, Netgear PDA: Zaurus, Nokia N8x0

Device examples

GPS: TomTom and GarminDevice examples Home network routers: Linksys, Netgear PDA: Zaurus, Nokia N8x0 TVs, camcorders, DVD players: Sony,

Home network routers: Linksys, NetgearDevice examples GPS: TomTom and Garmin PDA: Zaurus, Nokia N8x0 TVs, camcorders, DVD players: Sony, Philips

PDA: Zaurus, Nokia N8x0TomTom and Garmin Home network routers: Linksys, Netgear TVs, camcorders, DVD players: Sony, Philips Mobile phones:

TVs, camcorders, DVD players: Sony, Philipsnetwork routers: Linksys, Netgear PDA: Zaurus, Nokia N8x0 Mobile phones: Motorola, Android, OpenMoko Industrial

Mobile phones: Motorola, Android, OpenMokoNokia N8x0 TVs, camcorders, DVD players: Sony, Philips Industrial machinery And many other products you don't

Industrial machinerySony, Philips Mobile phones: Motorola, Android, OpenMoko And many other products you don't even imagine 6

And many other products you don't even imaginephones: Motorola, Android, OpenMoko Industrial machinery 6 Free Electrons . Kernel, drivers and embedded Linux

6

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

Quiz It works with Linux, but what is it for? 7 Free Electrons . Kernel,

Quiz

Quiz It works with Linux, but what is it for? 7 Free Electrons . Kernel, drivers

It works with Linux, but what is it for?

7

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

Answer
Answer

To milk cows!

8

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

Tools Global architecture Application Application Library Library Library Standard C library Linux kernel Bootloader

Tools

Global architecture

Application

Tools Global architecture Application Application Library Library Library Standard C library Linux kernel Bootloader
Tools Global architecture Application Application Library Library Library Standard C library Linux kernel Bootloader

Application

Library
Library

Library

Library

Standard C library

Linux kernel

Bootloader

Hardware

9

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

Embedded hardware Hardware for embedded systems is often different from hardware for classical systems. Often

Embedded hardware

Hardware for embedded systems is often different from hardware for classical systems.Embedded hardware Often a different CPU architecture: often ARM, MIPS or PowerPC. x86 is also used.

Often a different CPU architecture:is often different from hardware for classical systems. often ARM, MIPS or PowerPC. x86 is also

often ARM, MIPS or PowerPC. x86 is also used.

Storage on flash storage, NOR or NAND type, often with limited capacity (from a few MB to hundreds of MB)architecture: often ARM, MIPS or PowerPC. x86 is also used. Limited RAM capacity (from a few

Limited RAM capacity (from a few MB to several tens of MB)with limited capacity (from a few MB to hundreds of MB) Many interconnect bus not often

Many interconnect bus not often found on the desktop: I2C, SPI, SSP, CAN, etc.Limited RAM capacity (from a few MB to several tens of MB) Development boards starting from

Development boards starting from a few hundreds of EUR / USDbus not often found on the desktop: I2C, SPI, SSP, CAN, etc. Often used as a

Often used as a basis for the final board design.Development boards starting from a few hundreds of EUR / USD 10 Free Electrons . Kernel,

10

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

Picotux 100 ARM7 55 MHz, Netsilicon NS7520 2 MB of flash 8 MB of RAM

Picotux 100

ARM7 55 MHz, Netsilicon

ARM7 55 MHz, Netsilicon

NS7520

2 MB of flash

2

MB of flash

8 MB of RAM

8

MB of RAM

Ethernet

Ethernet

5 GPIOs

5

GPIOs

Serial

Serial

Serial

Examples

OpenMoko

ARM 920T 400 MHz, Samsung 2442BRAM Ethernet 5 GPIOs Serial Examples OpenMoko 2 MB of NOR flash MB of RAM MB

2 MB of NOR flashSerial Examples OpenMoko ARM 920T 400 MHz, Samsung 2442B MB of RAM MB of NAND flash

MB of RAMOpenMoko ARM 920T 400 MHz, Samsung 2442B 2 MB of NOR flash MB of NAND flash

MB of NAND flashARM 920T 400 MHz, Samsung 2442B 2 MB of NOR flash MB of RAM 640x480 touchscreen

640x480 touchscreen , Bluetooth, GSM, serial, GPS, sound, 2 buttons, Wifi, USB, etc.Samsung 2442B 2 MB of NOR flash MB of RAM MB of NAND flash 128 256

128

256

GSM, serial, GPS, sound, 2 buttons, Wifi, USB, etc. 128 256 11 Free Electrons . Kernel,

11

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

Minimum requirements A CPU supported by gcc and the Linux kernel 32 bit CPU MMU­less

Minimum requirements

A CPU supported by gcc and the Linux kernel

A

CPU supported by gcc and the Linux kernel

32 bit CPUA CPU supported by gcc and the Linux kernel MMU­less CPUs are also supported, through the

MMU­less CPUs are also supported, through the uClinux project.A CPU supported by gcc and the Linux kernel 32 bit CPU A few MB of

A few MB of RAM, from 4 MB.

A

few MB of RAM, from 4 MB.

8

MB are needed to do really do something.

A few MB of storage, from 2 MB.

A

few MB of storage, from 2 MB.

4

MB to really do something.

Linux isn't designed for small microcontrollers that just have a few tens or hundreds of

Linux isn't designed for small microcontrollers that just have a few tens or hundreds of KB of flash and RAM.

Base metal, no OSjust have a few tens or hundreds of KB of flash and RAM. Reduced systems, such

Reduced systems, such as FreeRTOStens or hundreds of KB of flash and RAM. Base metal, no OS 12 Free Electrons

12

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

Software components Cross­compilation toolchain Compiler that runs on the development machine, but generates code for

Software components

Cross­compilation toolchainSoftware components Compiler that runs on the development machine, but generates code for the target Bootloader

Software components Cross­compilation toolchain Compiler that runs on the development machine, but generates code for the

Compiler that runs on the development machine, but generates code for the target

Bootloaderthe development machine, but generates code for the target Started by the hardware, responsible for basic

Started by the hardware, responsible for basic initialization, loading and executing the kernelmachine, but generates code for the target Bootloader Linux Kernel Contains the process and memory management,

Linux Kernelfor basic initialization, loading and executing the kernel Contains the process and memory management, network stack,

loading and executing the kernel Linux Kernel Contains the process and memory management, network stack,

Contains the process and memory management, network stack, device drivers and provides services to userspace applications

C librarydrivers and provides services to userspace applications The interface between the kernel and the userspace

and provides services to userspace applications C library The interface between the kernel and the userspace

The interface between the kernel and the userspace applications

Libraries and applicationsinterface between the kernel and the userspace applications Third­party or in­house 13 Free Electrons . Kernel,

and the userspace applications Libraries and applications Third­party or in­house 13 Free Electrons . Kernel,

Third­party or in­house

13

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

Embedded Linux work Several distinct tasks are needed when deploying embedded Linux in a product

Embedded Linux work

Several distinct tasks are needed when deploying embedded Linux in a product

Board Support Package developmenttasks are needed when deploying embedded Linux in a product A BSP contains a bootloader and

A BSP contains a bootloader and kernel with the suitable device drivers for the targeted hardwareLinux in a product Board Support Package development Purpose of our « Kernel Development » training

Purpose of our « Kernel Development » trainingwith the suitable device drivers for the targeted hardware System integration Integrate all the components, bootloader,

System integrationhardware Purpose of our « Kernel Development » training Integrate all the components, bootloader, kernel,

Integrate all the components, bootloader, kernel, third­party libraries and applications and in­house applications into a working systemof our « Kernel Development » training System integration Purpose of this training Development of applications

Purpose of this trainingand in­house applications into a working system Development of applications Normal Linux applications, but

Development of applicationsapplications into a working system Purpose of this training Normal Linux applications, but using specifically chosen

Normal Linux applications, but using specifically chosen librariessystem Purpose of this training Development of applications 14 Free Electrons . Kernel, drivers and embedded

14

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

Root filesystem In a Linux system, several filesystems are mounted and create a global hierarchy

Root filesystem

In a Linux system, several filesystems are mounted and create a global hierarchy of files and directoriesRoot filesystem A particular filesystem, the root filesystem, is mounted as / On embedded systems, this

A particular filesystem, the root filesystem, is mounted as /and create a global hierarchy of files and directories On embedded systems, this root filesystem contains

On embedded systems, this root filesystem contains all the libraries, applications and data of the systemparticular filesystem, the root filesystem, is mounted as / Therefore, building the root filesystem is one

Therefore, building the root filesystem is one of the main tasks of integrating embedded Linux components into a deviceall the libraries, applications and data of the system The kernel is usually kept separate Flash

The kernel is usually kept separatetasks of integrating embedded Linux components into a device Flash contents Bootloader Kernel Root filesystem 15

Flash contents Bootloader Kernel Root filesystem
Flash contents
Bootloader
Kernel
Root
filesystem

15

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

Development environment Two ways to switch to embedded Linux Use solutions provided and supported by

Development environment

Two ways to switch to embedded Linux

Use solutions provided and supported by vendors like MontaVista, Wind River or TimeSys. These solutions come with their own development tools and environmentDevelopment environment Two ways to switch to embedded Linux Use community solutions In Free Electrons trainings,

Use community solutionscome with their own development tools and environment In Free Electrons trainings, we do not promote

In Free Electrons trainings, we do not promote a particular vendor, and therefore use community solutionsdevelopment tools and environment Use community solutions However, knowing the concepts, switching to vendor solutions

However, knowing the concepts, switching to vendor solutions will be easya particular vendor, and therefore use community solutions Doing embedded Linux development requires Linux on the

Doing embedded Linux development requires Linux on the desktop requires Linux on the desktop

The community solutions usually only exist on Linuxembedded Linux development requires Linux on the desktop Understanding Linux on the desktop allows you to

Understanding Linux on the desktop allows you to better understand Linux on the devicedesktop The community solutions usually only exist on Linux 16 Free Electrons . Kernel, drivers and

16

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

Embedded Linux Training System administration basics Michael Opdenacker Thomas Petazzoni Free Electrons © Copyright

Embedded Linux Training

System

administration

basics

Michael Opdenacker Thomas Petazzoni Free Electrons

© Copyright 2009, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/command­line Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

System administration basics Networking 2 Free Electrons . Kernel, drivers and embedded Linux development, consulting,

System administration basics

Networking

2

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

Network setup (1) ifconfig ­a Prints details about all the network interfaces available on your

Network setup (1)

ifconfig ­a Prints details about all the network interfaces available on your system. Prints details about all the network interfaces available on your system.

ifconfig eth0 Lists details about the eth0 interface Lists details about the eth0 interface

ifconfig eth0 192.168.0.100 Assigns the 192.168.0.100 IP address to eth0 (1 IP address per interface). Assigns the 192.168.0.100 IP address to eth0 (1 IP address per interface).

ifconfig eth0 down Shuts down the eth0 interface (frees its IP address). Shuts down the eth0 interface (frees its IP address).

Shuts down the eth0 interface (frees its IP address). 3 Free Electrons . Kernel, drivers and

3

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

Network setup (2) route add default gw 192.168.0.1 Sets the default route for packets outside

Network setup (2)

route add default gw 192.168.0.1 Sets the default route for packets outside the local network. The gateway (here 192.168.0.1 ) Sets the default route for packets outside the local network. The gateway (here 192.168.0.1) is responsible for sending them to the next gateway, etc., until the final destination.

route ­n Lists the existing routes Lists the existing routes

route del default or route del <IP> Deletes the given route Useful to redefine a new route. or route del <IP> Deletes the given route Useful to redefine a new route.

­n option: immediately displays ip addresses instead of trying to find their domain names

4

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

Network setup (3) Your programs need to know what IP address corresponds to a given

Network setup (3)

Your programs need to know what IP address corresponds to a given host name (such as kernel.org ) kernel.org)

Domain Name Servers (DNS) take care of this.corresponds to a given host name (such as kernel.org ) You just have to specify the

You just have to specify the IP address of 1 or more DNS servers in your /etc/resolv.conf file: /etc/resolv.conf file:

nameserver 217.19.192.132 nameserver 212.27.32.177

The changes take effect immediately!file: nameserver 217.19.192.132 nameserver 212.27.32.177 5 Free Electrons . Kernel, drivers and embedded Linux

5

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

Network testing First, try to ping the IP address of your gateway. This will confirm

Network testing

First, try to ping the IP address of your gateway. This will confirm that your network adapter works fine.Network testing Then, make sure you can ping the name server IP address, which will confirm

Then, make sure you can ping the name server IP address, which will confirm that your gateway is configured properly.This will confirm that your network adapter works fine. Finally, make sure you can ping any

Finally, make sure you can ping any host using its name, which will confirm that the nameserver configuration is correct.which will confirm that your gateway is configured properly. 6 Free Electrons . Kernel, drivers and

6

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

System administration basics Filesystems and devices 7 Free Electrons . Kernel, drivers and embedded Linux

System administration basics

Filesystems and devices

7

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

Creating filesystems Examples mkfs.ext2 /dev/sda1 Formats your USB key ( /dev/sda1 : 1 s t

Creating filesystems

Examples

mkfs.ext2 /dev/sda1 Formats your USB key ( /dev/sda1 : 1 s t partition raw data) in ext2 Formats your USB key (/dev/sda1: 1 st partition raw data) in ext2 format.

mkfs.ext2 ­F disk.img Formats a disk image file in ext2 format Formats a disk image file in ext2 format

mkfs.vfat ­v ­F 32 /dev/sda1 ( ­v : verbose) Formats your USB key back to FAT32 format. (­v: verbose) Formats your USB key back to FAT32 format.

mkfs.vfat ­v ­F 32 disk.img Formats a disk image file in FAT32 format. Formats a disk image file in FAT32 format.

­F: force. Execute even if not a real device file.

Blank disk images can be created as in the below example (64 MB file):

dd if=/dev/zero of=disk.img bs=1M count=64

8

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

Mounting devices (1) To make filesystems on any device (internal or external storage) visible on

Mounting devices (1)

To make filesystems on any device (internal or external storage) visible on your system, you have to mount them. mount them.

The first time, create a mount point in your system:storage) visible on your system, you have to mount them. mkdir /mnt/usbdisk (example) Now, mount it:

mkdir /mnt/usbdisk (example)

Now, mount it:a mount point in your system: mkdir /mnt/usbdisk (example) mount ­t vfat /dev/sda1 /mnt/usbdisk /dev/sda1 :

mount ­t vfat /dev/sda1 /mnt/usbdisk /dev/sda1: physical device ­t: specifies the filesystem (format) type (ext2, ext3, vfat, reiserfs, iso9660

)

raw data (file descriptors and file contents)
raw data
(file descriptors
and file contents)
, iso9660 ) raw data (file descriptors and file contents) mount file structure 9 Free Electrons
, iso9660 ) raw data (file descriptors and file contents) mount file structure 9 Free Electrons

mount

file structure
file

file

structure

structure

9

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

Mounting devices (2) You can also mount a filesystem image stored in a regular file

Mounting devices (2)

You can also mount a filesystem image stored in a regular file (loop devices)

Useful to develop filesystems for another machinea filesystem image stored in a regular file ( loop devices ) Useful to access the

Useful to access the contents of an ISO cdrom image without having to burn it.devices ) Useful to develop filesystems for another machine Useful to have a Linux filesystem inside

Useful to have a Linux filesystem inside a file in a Windows partition.contents of an ISO cdrom image without having to burn it. cp /dev/sda1 usbkey.img mount ­o

cp /dev/sda1 usbkey.img mount ­o loop ­t vfat usbkey.img /mnt/usbdisk

10

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

Listing mounted filesystems Just use the mount command with no argument: /dev/hda6 on / type

Listing mounted filesystems

Just use the mount command with no argument:

/dev/hda6 on / type ext3 (rw,noatime) none on /proc type proc (rw,noatime) none on /sys type sysfs (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) usbfs on /proc/bus/usb type usbfs (rw) /dev/hda4 on /data type ext3 (rw,noatime) none on /dev/shm type tmpfs (rw) /dev/hda1 on /win type vfat (rw,uid=501,gid=501) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

11

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

Unmounting devices umount /mnt/usbdisk Commits all pending writes and unmounts the given device, which can

Unmounting devices

umount /mnt/usbdisk Commits all pending writes and unmounts the given device, which can then be removed in Commits all pending writes and unmounts the given device, which can then be removed in a safe way.

To be able to unmount a device, you have to close all the open files in it:the given device, which can then be removed in a safe way. Close applications opening data

Close applications opening data in the mounted partitiona device, you have to close all the open files in it: Make sure that none

Make sure that none of your shells have a working directory in this mount point.it: Close applications opening data in the mounted partition You can run the lsof <mount point>

You can run the lsof <mount point> command ( l i s t o pen f iles) to view lsof <mount point> command (list open files) to view which processes still have open files in the mounted partition.

12

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

System administration basics Package management 13 Free Electrons . Kernel, drivers and embedded Linux development,

System administration basics

Package management

13

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

Beware of the dark side of root root user privileges are only needed for very

Beware of the dark side of root

Beware of the dark side of root root user privileges are only needed for very specific

root user privileges are only needed for very specific tasks with security risks: mounting, creating device user privileges are only needed for very specific tasks with security risks: mounting, creating device files, loading drivers, starting networking, changing file ownership, package upgrades

Even if you have the root password, your regular account should be sufficient for 99.9 % of your tasks (unless root password, your regular account should be sufficient for 99.9 % of your tasks (unless you are a system administrator).

In a training session, it is acceptable to use root . In real life, you may not even have access to this account, or root. In real life, you may not even have access to this account, or put your systems and data at risk if you do.

14

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

Using the root account In case you really want to use root If you have

Using the root account

In case you really want to use root

If you have the root password:

If you have the root password:

su ­ (switch user)

In modern distributions, the sudo command gives you access to some root privileges with your

In modern distributions, the sudo command gives you access to some root privileges with your own user password. Example: sudo mount /dev/hda4 /home

15

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

Software packages The distribution mechanism for software in GNU/Linux is different from the one in

Software packages

The distribution mechanism for software in GNU/Linux is different from the one in WindowsSoftware packages Linux distributions provides a central and coherent way of installing, updating and removing

Linux distributions provides a central and coherent way of installing, updating and removing applications and libraries :software in GNU/Linux is different from the one in Windows packages Packages contains the application or

packages

Packages contains the application or library files, and associated meta­information, such as the version and the dependenciesupdating and removing applications and libraries : packages .deb on Debian and Ubuntu, .rpm on Mandriva,

meta­information, such as the version and the dependencies .deb on Debian and Ubuntu, .rpm on Mandriva,

.deb on Debian and Ubuntu, .rpm on Mandriva, Fedora, OpenSUSE

Packages are stored in repositories , usually on HTTP or FTP servers repositories, usually on HTTP or FTP servers

One should only use packages from official repositories of its distribution, unless strictly required.are stored in repositories , usually on HTTP or FTP servers 16 Free Electrons . Kernel,

16

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

Managing software packages (1) Instructions for Debian based GNU/Linux systems (Debian, Ubuntu ) Package repositories

Managing software packages (1)

Instructions for Debian based GNU/Linux systems

(Debian, Ubuntu

)

Package repositories are specified in /etc/apt/sources.list /etc/apt/sources.list

To update package repository lists:Package repositories are specified in /etc/apt/sources.list sudo apt­get update To find the name of a package

sudo apt­get update

To find the name of a package to install, the best is to use the search engine on http://packages.debian.org or on http://packages.ubuntu.com . You may also use: http://packages.debian.org or on http://packages.ubuntu.com. You may also use:

apt­cache search <keyword>

17

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

Managing software packages (2) To install a given package: sudo apt­get install <package> To remove

Managing software packages (2)

To install a given package:Managing software packages (2) sudo apt­get install <package> To remove a given package: sudo apt­get remove

sudo apt­get install <package>

To remove a given package:a given package: sudo apt­get install <package> sudo apt­get remove <package> To install all

sudo apt­get remove <package>

To install all available package updates:a given package: sudo apt­get remove <package> sudo apt­get dist­upgrade Get information about a package:

sudo apt­get dist­upgrade

Get information about a package:all available package updates: sudo apt­get dist­upgrade sudo apt­cache show <package> Graphical interfaces

sudo apt­cache show <package>

Graphical interfacesabout a package: sudo apt­cache show <package> Synaptic for GNOME Adept for KDE Further details on

Synaptic for GNOMEsudo apt­cache show <package> Graphical interfaces Adept for KDE Further details on package management:

Adept for KDE<package> Graphical interfaces Synaptic for GNOME Further details on package management:

Further details on package management:

18

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

Shutting down halt Immediately halts the system. reboot Immediately reboots the system. [Ctrl][Alt][Del] Also works

Shutting down

halt Immediately halts the system. Immediately halts the system.

reboot Immediately reboots the system. Immediately reboots the system.

[Ctrl][Alt][Del] Also works on GNU/Linux to reboot. Embedded systems: you must use an implementation of init Also works on GNU/Linux to reboot. Embedded systems: you must use an implementation of init and can specify any key combination in /etc/inittab.

19

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

Practical lab – Training setup Prepare your lab environment Download the lab archive Enforce correct

Practical lab – Training setup

Practical lab – Training setup Prepare your lab environment Download the lab archive Enforce correct permissions

Prepare your lab environment

Download the lab archivePractical lab – Training setup Prepare your lab environment Enforce correct permissions 1 Free Electrons .

Enforce correct permissionssetup Prepare your lab environment Download the lab archive 1 Free Electrons . Kernel, drivers and

1

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

Embedded Linux system development Cross­compiling toolchains Thomas Petazzoni Michael Opdenacker Free Electrons ©

Embedded Linux system development

Cross­compiling

toolchains

Thomas Petazzoni Michael Opdenacker Free Electrons

© Copyright 2004­2010, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/toolchains Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

Definition (1) The usual development tools available on a GNU/Linux workstation is a native toolchain

Definition (1)

The usual development tools available on a GNU/Linux workstation is a native toolchain native toolchain

This toolchain runs on your workstation and generates code for your workstation, usually x86available on a GNU/Linux workstation is a native toolchain For embedded system development, it is usually

For embedded system development, it is usually impossible or not interesting to use a native toolchainand generates code for your workstation, usually x86 The target is too restricted in terms of

The target is too restricted in terms of storage and/or memoryimpossible or not interesting to use a native toolchain The target is very slow compared to

The target is very slow compared to your workstationtarget is too restricted in terms of storage and/or memory You may not want to install

You may not want to install all development tools on your target.memory The target is very slow compared to your workstation Therefore, cross­compiling toolchains are generally used.

Therefore, cross­compiling toolchains are generally used. They run on your workstation but generate code for your cross­compiling toolchains are generally used. They run on your workstation but generate code for your target.

2

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

Definition (2) Source code Cross­compiling Native toolchain toolchain x86 x86 binary ARM binary x86 ARM

Definition (2)

Source code Cross­compiling Native toolchain toolchain x86 x86 binary ARM binary x86 ARM
Source code
Cross­compiling
Native toolchain
toolchain
x86
x86 binary
ARM binary
x86
ARM

Compilation

machine

Execution

machine

3

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

Components Binutils Kernel headers C/C++ libraries GCC compiler GDB debugger (optional) 4 Free Electrons .

Components

Binutils Kernel headers C/C++ libraries GCC compiler GDB debugger (optional)
Binutils
Kernel headers
C/C++ libraries
GCC compiler
GDB debugger
(optional)

4

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

Binutils Binutils is a set of tools to generate and manipulate binaries for a given

Binutils

Binutils is a set of tools to generate and manipulate binaries for a given CPU architecture is a set of tools to generate and manipulate binaries for a given CPU architecture

as, the assembler, that generates binary code from assembler source code , the assembler, that generates binary code from assembler source code

ld, the linker , the linker

ar, ranlib , to generate .a archives, used for libraries , ranlib, to generate .a archives, used for libraries

objdump, readelf , size , nm , strings , to inspect binaries. Very useful analysis , readelf, size, nm, strings, to inspect binaries. Very useful analysis tools !

strip, to strip useless parts of binaries in order to reduce their size , to strip useless parts of binaries in order to reduce their size

GPL licenseto reduce their size http://www.gnu.org/software/binutils/ 5 Free Electrons . Kernel, drivers and embedded Linux

5

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

Kernel headers (1) The C library and compiled programs needs to interact with the kernel

Kernel headers (1)

The C library and compiled programs needs to interact with the kernel

The C library and compiled programs needs to interact with the kernel

Available system calls and their numbersand compiled programs needs to interact with the kernel Constant definitions Data structures, etc. Therefore,

Constant definitionswith the kernel Available system calls and their numbers Data structures, etc. Therefore, compiling the C

Data structures, etc.system calls and their numbers Constant definitions Therefore, compiling the C library requires kernel headers,

Therefore, compiling the C library requires kernel headers, and many applications also require them.

Therefore, compiling the C library requires kernel headers, and many applications also require them.

Available in <linux/ > and <asm/

Available in <linux/

>

and <asm/

Kernel

Kernel headers

C Library

Applications

>

and a few other

Kernel headers C Library Applications > and a few other directories corresponding to the ones visible

directories corresponding to the ones visible in include/ in the kernel sources

6

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

Kernel headers (2) System call numbers, in <asm/unistd.h> #define NR_exit 1 #define NR_fork 2

Kernel headers (2)

System call numbers, in <asm/unistd.h> <asm/unistd.h>

#define

NR_exit

1

#define

NR_fork

2

#define

NR_read

3

Constant definitions, here in <asm­generic/fcntl.h> , included <asm­generic/fcntl.h>, included

from <asm/fcntl.h>, included from <linux/fcntl.h>

#define O_RDWR

00000002

Data structures, here in <asm/stat.h> <asm/stat.h>

struct stat { unsigned long st_dev; unsigned long st_ino; [ ]

};

7

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

Kernel headers (3) The kernel­to­userspace ABI is backward compatible Binaries generated with a toolchain using

Kernel headers (3)

The kernel­to­userspace ABI is backward compatibleKernel headers (3) Binaries generated with a toolchain using kernel headers older than the running kernel

Binaries generated with a toolchain using kernel headers older than the running kernel will work without problem, but won't be able to use the new system calls, data structures, etc.(3) The kernel­to­userspace ABI is backward compatible Binaries generated with a toolchain using kernel headers

Binaries generated with a toolchain using kernel headers newer than the running kernel might work on if they don't use the recent features, otherwise they will breakbe able to use the new system calls, data structures, etc. Using the latest kernel headers

Using the latest kernel headers is not necessary, unless access to the new kernel features is neededdon't use the recent features, otherwise they will break The kernel headers are extracted from the

The kernel headers are extracted from the kernel sources usingunless access to the new kernel features is needed the headers_install kernel Makefile target. 8 Free

the headers_install kernel Makefile target.

8

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

GCC compiler GNU C Compiler, the famous free software compiler Can compile C, C++, Ada,

GCC compiler

GNU C Compiler, the famous free software compilerGCC compiler Can compile C, C++, Ada, Fortran, Java, Objective­ C, Objective­C++, and generate code for

Can compile C, C++, Ada, Fortran, Java, Objective­ C, Objective­C++, and generate code for a large number of CPU architectures, including ARM, AVR, Blackfin, CRIS, FRV, M32, MIPS, MN10300, PowerPC, SH, v850, i386, x86_64, IA64, Xtensa, etc.compiler GNU C Compiler, the famous free software compiler http://gcc.gnu.org/ Available under the GPL license,

Available under the GPL license, libraries under the LGPL.v850, i386, x86_64, IA64, Xtensa, etc. http://gcc.gnu.org/ 9 Free Electrons . Kernel, drivers and embedded Linux

Available under the GPL license, libraries under the LGPL. 9 Free Electrons . Kernel, drivers and

9

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

C library The C library is an essential component of a Linux system Interface between

C library

The C library is an essential component of a Linux system

The C library is an essential component of a Linux system

Interface between the applications and the kernelThe C library is an essential component of a Linux system Provides the well­known standard C

Provides the well­known standard C API to ease application developmentsystem Interface between the applications and the kernel Several C libraries are available: glibc , uClibc

Several C libraries are available:

Several C libraries are available:

glibc, uClibc, eglibc, dietlibc, newlib, etc.

The choice of the C library must be made at the time of the cross­compiling

The choice of the C library must be made at the time of the cross­compiling toolchain generation, as the GCC compiler is compiled against a specific C library.

Kernel

compiler is compiled against a specific C library. Kernel C Library Applications 10 Free Electrons .

C Library

Applications

10

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

glibc http://www.gnu.org/software/libc/ License: LGPL C library from the GNU project Designed for performance, standards

glibc

glibc http://www.gnu.org/software/libc/ License: LGPL C library from the GNU project Designed for performance, standards

License: LGPLglibc http://www.gnu.org/software/libc/ C library from the GNU project Designed for performance, standards compliance

C library from the GNU project GNU project

Designed for performance, standards compliance and portabilityLicense: LGPL C library from the GNU project Found on all GNU / Linux host systems

Found on all GNU / Linux host systems GNU / Linux host systems

Of course, actively maintainedand portability Found on all GNU / Linux host systems Quite big for small embedded systems:

Quite big for small embedded systems: approx 2.5 MB on arm (version 2.9 ­ libc : 1.5 MB, libm : 750 KB) arm (version 2.9 ­ libc: 1.5 MB, libm: 750 KB)

11

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

uClibc http://www.uclibc.org/ from CodePoet Consulting License: LGPL Lightweight C library for small embedded systems

uClibc

http://www.uclibc.org/ from CodePoet Consulting

License: LGPLuClibc http://www.uclibc.org/ from CodePoet Consulting Lightweight C library for small embedded systems High

Lightweight C library for small embedded systemsfrom CodePoet Consulting License: LGPL High configurability: many features can be enabled or

High configurability: many features can be enabled or disabled through a menuconfig interface menuconfig interface

Works only with Linux/uClinux, works on most embedded architecturescan be enabled or disabled through a menuconfig interface No stable ABI, different ABI depending on

No stable ABI, different ABI depending on the library configurationwith Linux/uClinux, works on most embedded architectures Focus on size rather than performance Small compile time

Focus on size rather than performanceABI, different ABI depending on the library configuration Small compile time 12 Free Electrons . Kernel,

Small compile timelibrary configuration Focus on size rather than performance 12 Free Electrons . Kernel, drivers and embedded

12

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

uClibc (2) Most of the applications compile with uClibc. This applies to all applications used

uClibc (2)

Most of the applications compile with uClibc. This applies to all applications used in embedded systems.uClibc (2) Size ( arm ): 4 times smaller than glibc ! uClibc 0.9.30.1 : approx.

Size (arm ): 4 times smaller than glibc ! uClibc 0.9.30.1 : approx. 600 KB ( arm): 4 times smaller than glibc! uClibc 0.9.30.1: approx. 600 KB (libuClibc: 460 KB, libm: 96KB) glibc 2.9: approx 2.5 MB

Used on a large number of production embedded products, including consumer electronic deviceslibuClibc : 460 KB, libm : 96KB) glibc 2.9 : approx 2.5 MB Actively maintained, large

Actively maintained, large developer and user baseembedded products, including consumer electronic devices Now supported by MontaVista , TimeSys and Wind River .

Now supported by MontaVista , TimeSys and Wind River . MontaVista, TimeSys and Wind River.

13

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

uClibc (3) After compilation and installation, the following components are available Standard headers, stdio.h ,

uClibc (3)

After compilation and installation, the following components are available

Standard headers, stdio.h , stdlib.h , unistd.h and others, and Linux kernel headers, integrated with the C stdio.h, stdlib.h, unistd.h and others, and Linux kernel headers, integrated with the C library headers.

The libraries themselves, with mainlyLinux kernel headers, integrated with the C library headers. libuClibc , the C library itself ld­uClibc

libuClibc, the C library itself , the C library itself

ld­uClibc, the dynamic loader, responsible for loading the shared libraries at the beginning of a , the dynamic loader, responsible for loading the shared libraries at the beginning of a program's execution

librt, the library implementing the real­time related functions , the library implementing the real­time related functions

libstdc++, the C++ standard library , the C++ standard library

libpthread, the threads library , the threads library

libm, the mathematic library , the mathematic library

14

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

Honey, I shrunk the programs! C program Compiled with shared libraries Compiled statically   glibc

Honey, I shrunk the programs!

C program

Compiled with shared libraries

Compiled statically

 

glibc

uClibc

glibc

uClibc

Plain “hello world” (stripped)

5.6 K

5.4 K (uClibc 0.9.30.1)

472

K

18 K

(glibc 2.9)

(glibc 2.9)

(uClibc

   

0.9.30.1)

Busybox

245 K (older glibc)

231 K (older uClibc)

843

K

311 K (older uClibc)

(stripped)

(older glibc)

Executable size comparison on ARM

15

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

eglibc « Embedded glibc », under the LGPL Variant of the GNU C Library (GLIBC)

eglibc

« Embedded glibc », under the LGPL

eglibc « Embedded glibc », under the LGPL Variant of the GNU C Library (GLIBC) designed

Variant of the GNU C Library (GLIBC) designed to work well on embedded systemseglibc « Embedded glibc », under the LGPL Strives to be source and binary compatible with

Strives to be source and binary compatible with GLIBCC Library (GLIBC) designed to work well on embedded systems eglibc's goals include reduced footprint, configurable

eglibc's goals include reduced footprint, configurable components, better support for cross­compilation and cross­testing.Strives to be source and binary compatible with GLIBC Can be built without support for NIS,

Can be built without support for NIS, locales, IPv6, and many other features.better support for cross­compilation and cross­testing. Supported by a consortium, with Freescale, MIPS, MontaVista

Supported by a consortium, with Freescale, MIPS, MontaVista and Wind River as members.support for NIS, locales, IPv6, and many other features. The Debian distribution is switching to eglibc

The Debian distribution is switching to eglibc too:with Freescale, MIPS, MontaVista and Wind River as members. http://blog.aurel32.net/?p=47 http://www.eglibc.org 16 Free

16

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

Other smaller C libraries Several other smaller C libraries have been developed, but none of

Other smaller C libraries

Several other smaller C libraries have been developed, but none of them have the goal of allowing the compilation of large existing applicationsOther smaller C libraries They need specially written programs and applications Choices: Dietlibc ,

They need specially written programs and applicationsof allowing the compilation of large existing applications Choices: Dietlibc , http://www.fefe.de/dietlibc/ .

Choices:They need specially written programs and applications Dietlibc , http://www.fefe.de/dietlibc/ . Approximately 70

Dietlibc, http://www.fefe.de/dietlibc/ . Approximately 70 KB. , http://www.fefe.de/dietlibc/. Approximately 70 KB.

Klibc, http://www.kernel.org/pub/linux/libs/klibc/ , designed for use in an initramfs or initrd at boot time. , http://www.kernel.org/pub/linux/libs/klibc/, designed for use in an initramfs or initrd at boot time.

17

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

Building a toolchain Three machines must be distinguished when discussing toolchain creation The build machine,

Building a toolchain

Three machines must be distinguished when discussing toolchain creationBuilding a toolchain The build machine, where the toolchain is built. The host machine, where the

The build machine, where the toolchain is built.must be distinguished when discussing toolchain creation The host machine, where the toolchain will be executed.

The host machine, where the toolchain will be executed.creation The build machine, where the toolchain is built. The target machine, where the binaries created

The target machine, where the binaries created by the toolchain will be executed.The host machine, where the toolchain will be executed. Four build types are possible 18 Free

Four build types are possiblethe binaries created by the toolchain will be executed. 18 Free Electrons . Kernel, drivers and

18

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

build Building a toolchain (2) build host target Cross build used to build a toolchain

build

Building a toolchain (2)

build

host

target

Cross build

used to build a toolchain that runs on your workstation but generates binaries for the target

The most common solution in embedded

host

target

Native build

used to build the normal gcc of a workstation

build

host

target

build

host

target

Cross­native build

used to build a toolchain that runs on your target and generates binaries for the target

Canadian build

used to build on architecture A a toolchain that runs on architecture B and generates binaries for architecture C

19

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

Building a toolchain (3) Many decisions must be made when building a toolchain Choosing the

Building a toolchain (3)

Many decisions must be made when building a toolchainBuilding a toolchain (3) Choosing the C library Choosing the version of the different components Choosing

Choosing the C library(3) Many decisions must be made when building a toolchain Choosing the version of the different

Choosing the version of the different componentsbe made when building a toolchain Choosing the C library Choosing the configuration of the toolchain

Choosing the configuration of the toolchainC library Choosing the version of the different components Which ABI should be used ? Toolchains

Which ABI should be used ? Toolchains for the ARM architecture for example, can generate binaries using the OABI (Old ABI) or the EABI (Embedded ABI), that are incompatiblecomponents Choosing the configuration of the toolchain Should the toolchain support software floating point, or

Should the toolchain support software floating point, or does the hardware support floating point operations ?(Old ABI) or the EABI (Embedded ABI), that are incompatible Should the toolchain support locales, IPv6,

Should the toolchain support locales, IPv6, or other specific features ?or does the hardware support floating point operations ? 20 Free Electrons . Kernel, drivers and

20

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

Building a toolchain (4) Crosstool build reports: http://kegel.com/crosstool/crosstool­0.43/buildlogs 21 Free Electrons

Building a toolchain (4)

http://kegel.com/crosstool/crosstool­0.43/buildlogs 21 Free Electrons . Kernel, drivers and embedded Linux

21

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

Basic steps Extract and install kernel headers Extract, configure, compile and install binutils Extract, configure

Basic steps

Extract and install kernel headersBasic steps Extract, configure, compile and install binutils Extract, configure and compile a first version gcc

Extract, configure, compile and install binutilsBasic steps Extract and install kernel headers Extract, configure and compile a first version gcc that

Extract, configure and compile a first version gcc that generates binaries for the target. It will be used to cross­ compile the C library.headers Extract, configure, compile and install binutils Extract, configure and compile the C library using the

Extract, configure and compile the C library using the previously generated compiler.target. It will be used to cross­ compile the C library. Re­configure and compile the final

Re­configure and compile the final gcc cross­compiler.the C library using the previously generated compiler. 22 Free Electrons . Kernel, drivers and embedded

22

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

Homebuilt toolchains Building a cross­compiling toolchain by yourself is a difficult and painful task! Can

Homebuilt toolchains

Building a cross­compiling toolchain by yourself is a difficult and painful task! Can take days or weeks!

Lots of details to learn. Several components to build.is a difficult and painful task! Can take days or weeks! Lots of decisions to make

Lots of decisions to make (such as C library version and configuration for your platform)Lots of details to learn. Several components to build. Need kernel headers and C library sources

Need kernel headers and C library sourcesas C library version and configuration for your platform) Need to be familiar with current gcc

Need to be familiar with current gcc issues and patches on your platform gcc issues and patches on your platform

Useful to be familiar with building and configuring toolswith current gcc issues and patches on your platform

can show you how fun it can be!

23

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

Get a precompiled toolchain Solution that most people choose, because it is the simplest and

Get a precompiled toolchain

Solution that most people choose, because it is the simplest and most convenient solutionGet a precompiled toolchain First, determine what toolchain you need: CPU, endianism, C library, component versions,

First, determine what toolchain you need: CPU, endianism, C library, component versions, ABI, soft float or hard float, etc.because it is the simplest and most convenient solution Many pre­compiled toolchains are freely available:

Many pre­compiled toolchains are freely available:component versions, ABI, soft float or hard float, etc. CodeSourcery, http://www.codesourcery.com , is a reference

CodeSourcery, http://www.codesourcery.com , is a reference in that area, but they only provide glibc toolchains. http://www.codesourcery.com, is a reference in that area, but they only provide glibc toolchains.

See the next page for Linaro toolchains optimized for ARM.in that area, but they only provide glibc toolchains. See also http://elinux.org/Toolchains 24 Free Electrons .

24

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

Linaro toolchains https://wiki.linaro.org/WorkingGroups/ToolChain Linaro contributes to improving mainstream gcc on ARM,

Linaro toolchains

toolchains https://wiki.linaro.org/WorkingGroups/ToolChain Linaro contributes to improving mainstream gcc on ARM, in

Linaro contributes to improving mainstream gcc on ARM, in particular by hiring CodeSourcery developers.toolchains https://wiki.linaro.org/WorkingGroups/ToolChain For people who can't wait for the next releases of gcc,

For people who can't 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).gcc on ARM, in particular by hiring CodeSourcery developers. As any gcc release, these sources can

As any gcc release, these sources can be used by build tools tooptimizations for ARM (mainly for recent Cortex A CPUs). build their own binary toolchains (Buildroot, OpenEmbedded

build their own binary toolchains (Buildroot, OpenEmbedded This allows to support glibc, uClibc and eglibc.

)

Binary packages are available for Ubuntu users:This allows to support glibc, uClibc and eglibc. ) See

25

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

Installing and using a precompiled toolchain Follow the installation procedure proposed by the vendor Usually,

Installing and using a precompiled toolchain

Follow the installation procedure proposed by the vendorInstalling and using a precompiled toolchain Usually, it is simply a matter of extracting a tarball

Usually, it is simply a matter of extracting a tarball at the proper placeFollow the installation procedure proposed by the vendor Toolchains used not to be relocatable! You must

Toolchains used not to be relocatable! You must install them in the location they were built for.simply a matter of extracting a tarball at the proper place This is no longer true

This is no longer true with gcc 4.x, thanks to sysroot support, but it is still more convenient to install them at the proper place.You must install them in the location they were built for. Then, add the path to

Then, add the path to toolchain binaries in your PATH : PATH:

export PATH=/path/to/toolchain/bin/:$PATH

26

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

Toolchain building utilities Another solution is to use utilities that automate the process of building

Toolchain building utilities

Another solution is to use utilities that automate the process of building the toolchain

Same advantage as the pre­compiled toolchains: you don't need to mess up with all the details of the build processthat automate the process of building the toolchain But also offers more flexibility in terms of

But also offers more flexibility in terms of toolchain configuration, component version selection, etc.need to mess up with all the details of the build process They also usually contain

They also usually contain several patches that fix known issues with the different components on some architecturestoolchain configuration, component version selection, etc. Identical principle: shell scripts or Makefile that

Identical principle: shell scripts or Makefile that automatically fetch, extract, configure, compile and install the different componentsissues with the different components on some architectures 27 Free Electrons . Kernel, drivers and embedded

27

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

Toolchain building utilities (2) Crosstool The precursor, written by Dan Kegel Set of scripts and

Toolchain building utilities (2)

CrosstoolToolchain building utilities (2) The precursor, written by Dan Kegel Set of scripts and patches, glibc­only

The precursor, written by Dan KegelToolchain building utilities (2) Crosstool Set of scripts and patches, glibc­only Not really maintained anymore

Set of scripts and patches, glibc­onlyutilities (2) Crosstool The precursor, written by Dan Kegel Not really maintained anymore http://www.kegel.com/crosstool

Not really maintained anymorewritten by Dan Kegel Set of scripts and patches, glibc­only http://www.kegel.com/crosstool Crosstool­ng Rewrite of

Crosstool­ngNot really maintained anymore http://www.kegel.com/crosstool Rewrite of Crosstool , with a menuconfig ­like

Rewrite of Crosstool , with a menuconfig ­like configuration system Crosstool, with a menuconfig­like configuration system

Feature­full: supports uClibc , glibc , eglibc , hard and soft float, many architectures uClibc, glibc, eglibc, hard and soft float, many architectures

Actively maintained, glibc , eglibc , hard and soft float, many architectures http://ymorin.is­a­geek.org/dokuwiki/projects/crosstool 28

28

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

Toolchain building utilities (3) Many root filesystem building systems also allow the construction of cross­compiling

Toolchain building utilities (3)

Many root filesystem building systems also allow the construction of cross­compiling toolchain

Buildrootalso allow the construction of cross­compiling toolchain Makefile­based, uClibc only, maintained by the community

Makefile­based, uClibc only, maintained by the community uClibc only, maintained by the community

PTXdistmaintained by the community http://buildroot.uclibc.org Makefile­based, uClibc or glibc , maintained mainly by

Makefile­based, uClibc or glibc , maintained mainly by Pengutronix uClibc or glibc, maintained mainly by Pengutronix

OpenEmbeddedhttp://www.pengutronix.de/software/ptxdist/index_en.html The feature­full, but complex building system

The feature­full, but complex building systemOpenEmbedded http://www.openembedded.org/ 29 Free Electrons . Kernel,

29

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

Practical lab – Using Crosstool­NG Time to build your toolchain Configure Crosstool­NG Run it to

Practical lab – Using Crosstool­NG

Practical lab – Using Crosstool­NG Time to build your toolchain Configure Crosstool­NG Run it to build

Time to build your toolchain

Configure Crosstool­NG Crosstool­NG

Run it to build your own cross­ compiling toolchainTime to build your toolchain Configure Crosstool­NG 30 Free Electrons . Kernel, drivers and embedded Linux

30

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

Embedded Linux system development Bootloaders Thomas Petazzoni Michael Opdenacker Free Electrons © Copyright

Embedded Linux system development

Bootloaders

Thomas Petazzoni Michael Opdenacker Free Electrons

© Copyright 2004­2010, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/bootloaders Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

Bootloaders The bootloader is a piece of code responsible for Basic hardware initialization Loading of

Bootloaders

The bootloader is a piece of code responsible forBootloaders Basic hardware initialization Loading of an application binary, usually an operating system kernel, from flash

Basic hardware initializationBootloaders The bootloader is a piece of code responsible for Loading of an application binary, usually

Loading of an application binary, usually an operating system kernel, from flash storage, from the network, or from another type of non­volatile storage.piece of code responsible for Basic hardware initialization Possibly uncompression of the application binary Execution

Possibly uncompression of the application binarythe network, or from another type of non­volatile storage. Execution of the application Besides these basic

Execution of the applicationstorage. Possibly uncompression of the application binary Besides these basic functions, most bootloaders provide a

Besides these basic functions, most bootloaders provide a shell with various commands implementing different operations.of the application binary Execution of the application Loading of data from storage or network, memory

Loading of data from storage or network, memory inspection, hardware diagnostics and testing, etc.with various commands implementing different operations. 2 Free Electrons . Kernel, drivers and embedded Linux

2

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

Bootloaders on x86 (1) The x86 processors are typically bundled on a board with a

Bootloaders on x86 (1)

The x86 processors are typically bundled on a board with a non­ volatile memory containing a program, the BIOS.Bootloaders on x86 (1) This program gets executed by the CPU after reset, and is responsible

This program gets executed by the CPU after reset, and is responsible for basic hardware initialization and loading of a small piece of code from non­volatile storage.with a non­ volatile memory containing a program, the BIOS. This piece of code is usually

loading of a small piece of code from non­volatile storage. This piece of code is usually

This piece of code is usually the first 512 bytes of an hard disk

This piece of code is usually a 1 s t stage bootloader, which will load the full bootloader itself. st stage bootloader, which will load the full bootloader itself.

The bootloader can then offer all its features. It typically understands filesystem formats so that the kernel file can be loaded directly from a normal filesystem.bootloader, which will load the full bootloader itself. 3 Free Electrons . Kernel, drivers and embedded

3

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

Bootloaders on x86 (2) GRUB, Grand Unified Bootloader, the most powerful one. http://www.gnu.org/software/grub/ Can read

Bootloaders on x86 (2)

GRUB, Grand Unified Bootloader, the most powerful one. http://www.gnu.org/software/grub/ http://www.gnu.org/software/grub/

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.the most powerful one. http://www.gnu.org/software/grub/ See our dedicated presentation for details:

See our dedicated presentation for details:commands, can load kernel images over the network, etc. http://free­electrons.com/docs/grub/ LILO, the original

LILO, the original Linux Loader http://freshmeat.net/projects/lilo/ http://freshmeat.net/projects/lilo/

Syslinux, for network and removable media booting http://syslinux.zytor.com http://syslinux.zytor.com

4

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

Bootloaders on embedded architectures (1) On embedded architectures, the low­level booting process is very CPU

Bootloaders on embedded architectures (1)

On embedded architectures, the low­level booting process is very CPU and board dependentBootloaders on embedded architectures (1) Some boards have a NOR flash from which the CPU starts

Some boards have a NOR flash from which the CPU starts executing instructions after reset. In that case, the bootloader must directly be flashed inside the NOR at the proper locationlow­level booting process is very CPU and board dependent Some CPUs have an integrated bootcode in

Some CPUs have an integrated bootcode in ROM that automatically loads a small portion of a DataFlash or NAND flash, usually to a static RAM. In that case, a minimal first stage bootloader is required, that will load the main bootloader (BootROM on AT91SAM CPUs, Steppingstone on S3C24xx CPUs, etc.).directly be flashed inside the NOR at the proper location The bootloader on embedded architectures starts

The bootloader on embedded architectures starts right after CPU reset, so it must initialize all the devices, including the memory controller in order to access the DRAM.on AT91SAM CPUs, Steppingstone on S3C24xx CPUs, etc.). As the boot process is very CPU and

As the boot process is very CPU and board dependent, refer to the vendor documentation.including the memory controller in order to access the DRAM. 5 Free Electrons . Kernel, drivers

5

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

Bootloaders on embedded architectures (2) We will focus on the generic part, the main bootloader,

Bootloaders on embedded architectures (2)

We will focus on the generic part, the main bootloader, offering the most important features.Bootloaders on embedded architectures (2) There are several open­source generic bootloaders. Here are the most popular

There are several open­source generic bootloaders. Here are the most popular ones:the main bootloader, offering the most important features. U­Boot, the universal bootloader by Denx The most

U­Boot, the universal bootloader by Denx The most used on ARM, also used on PPC, MIPS, x86, m68k, NIOS, etc. The de­facto standard nowadays. We will study it in detail. http://www.denx.de/wiki/U­Boot http://www.denx.de/wiki/U­Boot

Barebox, a new architecture­neutral bootloader, written as a successor of U­Boot. Better design, better code, active development, but doesn't yet have as much hardware support as U­Boot. http://www.barebox.org http://www.barebox.org

There are also a lot of other open­source or proprietary bootloaders, often architecture­specificas much hardware support as U­Boot. http://www.barebox.org RedBoot, Yaboot, PMON, etc. 6 Free Electrons . Kernel,

RedBoot, Yaboot, PMON, etc.or proprietary bootloaders, often architecture­specific 6 Free Electrons . Kernel, drivers and embedded Linux

6

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

Embedded Linux system development Accessing a serial console 7 Free Electrons . Kernel, drivers and

Embedded Linux system development

Accessing a serial console

7

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

Minicom (1) Definition: serial communication program Available in all GNU / Linux distributions Capabilities (all

Minicom (1)

Definition: serial communication programMinicom (1) Available in all GNU / Linux distributions Capabilities (all through a serial link): Serial

Available in all GNU / Linux distributions GNU / Linux distributions

Capabilities (all through a serial link):program Available in all GNU / Linux distributions Serial console to a remote Unix system File

Serial console to a remote Unix system File transfer
File transferSerial console to a remote Unix system

Modem control and dial­upSerial console to a remote Unix system File transfer Serial port configuration 8 Free Electrons .

Serial port configurationUnix system File transfer Modem control and dial­up 8 Free Electrons . Kernel, drivers and embedded

8

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

Minicom (2) Start by running minicom ­s to setup Minicom A bit austere at first

Minicom (2)

Minicom (2) Start by running minicom ­s to setup Minicom A bit austere at first glance,

Start by running minicom ­s to setup Minicom minicom ­s to setup Minicom

A bit austere at first glance, but quickly gets friendly (see the labs for details)Minicom (2) Start by running minicom ­s to setup Minicom 9 Free Electrons . Kernel, drivers

9

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

Other terminal emulators GTKTerm : http://www.jls­info.com/julien/linux/ Graphical. Less powerful than Minicom , but

Other terminal emulators

GTKTerm: http://www.jls­info.com/julien/linux/ Graphical. Less powerful than Minicom , but with a simpler and more attractive : http://www.jls­info.com/julien/linux/ Graphical. Less powerful than Minicom, but with a simpler and more attractive interface. Available in recent distros.

CuteCom: http://cutecom.sourceforge.net/ Another graphical and user­friendly terminal emulator. Available in recent distros. : http://cutecom.sourceforge.net/ Another graphical and user­friendly terminal emulator. Available in recent distros.

picocom: http://freshmeat.net/projects/picocom/ Tiny terminal emulator (20K), can be used in embedded systems. http://freshmeat.net/projects/picocom/ Tiny terminal emulator (20K), can be used in embedded systems.

GNU Screen: can also be used on a serial console:terminal emulator (20K), can be used in embedded systems. screen <device> <baudrate> Example: screen

screen <device> <baudrate> Example:

screen /dev/ttyS0 115200

10

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

The U­boot bootloader The U­boot bootloader Michael Opdenacker Thomas Petazzoni Free Electrons © Copyright

The U­boot bootloader

The U­boot bootloader

Michael Opdenacker Thomas Petazzoni Free Electrons

© Copyright 2004­2009, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/u­boot Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

U­Boot U­Boot is a typical free software project Freely available at http://www.denx.de/wiki/U­Boot Documentation

U­Boot

U­Boot is a typical free software project

Freely available at http://www.denx.de/wiki/U­Boot http://www.denx.de/wiki/U­Boot

The latest development source code is available in a Git repository:available at http://www.denx.de/wiki/U­Boot/Documentation

Development and discussions happen around an open mailing­ list http://lists.denx.de/pipermail/u­boot/ http://lists.denx.de/pipermail/u­boot/

Since the end of 2008, it follows a fixed­interval release schedule. Every two months, a new version is released. Versions are named YYYY.MM.open mailing­ list http://lists.denx.de/pipermail/u­boot/ 2 Free Electrons . Kernel, drivers and embedded Linux

2

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

Compiling U­Boot (1) Get the source code from the website, and uncompress it The include/configs/

Compiling U­Boot (1)

Get the source code from the website, and uncompress itCompiling U­Boot (1) The include/configs/ directory contains one configuration file for each supported board It defines

The include/configs/ directory contains one configuration file for each supported board include/configs/ directory contains one configuration file for each supported board

It defines the CPU type, the peripherals and their configuration, the memory mapping, the U­Boot features that should be compiled in, etc.contains one configuration file for each supported board It is a simple .h file that sets

It is a simple .h file that sets pre­processor constants. See the README file for the documentation of these constants. README file for the documentation of these constants.

Assuming that your board is already supported by U­Boot, there should be one file corresponding to your board, for examplethe README file for the documentation of these constants. include/configs/omap2420h4.h . 3 Free Electrons . Kernel,

include/configs/omap2420h4.h.

3

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

Compiling U­Boot (2) U­Boot must be configured before being compiled make BOARDNAME_config Where BOARDNAME is

Compiling U­Boot (2)

U­Boot must be configured before being compiledCompiling U­Boot (2) make BOARDNAME_config Where BOARDNAME is the name of the configuration file in include/configs/

make BOARDNAME_configU­Boot (2) U­Boot must be configured before being compiled Where BOARDNAME is the name of the

Where BOARDNAME is the name of the configuration file in include/configs/ , without the .h BOARDNAME is the name of the configuration file in include/configs/, without the .h

Make sure that the cross­compiler is available in PATH PATH

export PATH=/usr/local/uclibc­0.9.29­2/arm/bin/:$PATH

Compile U­Boot, by specifying the cross­compiler prefix. Example, if your cross­compiler executable is arm­linux­gcc : arm­linux­gcc:

make CROSS_COMPILE=arm­linux­

4

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

Installing U­Boot U­Boot must usually be installed in flash memory to be executed by the

Installing U­Boot

Installing U­Boot U­Boot must usually be installed in flash memory to be executed by the hardware.

U­Boot must usually be installed in flash memory to be executed by the hardware. Depending on the hardware, the installation of U­Boot is done in a different way:

The board provides some kind of specific boot monitor, which allows to flash the second stage bootloader. In this case, refer to the board documentation and toolsthe installation of U­Boot is done in a different way: U­Boot is already installed, and can

U­Boot is already installed, and can be used to flash a new version of U­Boot. However, be careful: if the new version of U­Boot doesn't work, the board is unusableIn this case, refer to the board documentation and tools The board provides a JTAG interface,

The board provides a JTAG interface, which allows to write to the flash memory remotely, without any system running on the board. It also allows to rescue a board if the bootloader doesn't work.version of U­Boot doesn't work, the board is unusable 5 Free Electrons . Kernel, drivers and

5

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

U­boot prompt Connect the target to the host through a serial console Power­up the board.

U­boot prompt

Connect the target to the host through a serial consoleU­boot prompt Power­up the board. On the serial console, you will see something like: U­Boot 1.1.2

Power­up the board. On the serial console, you will see something like:Connect the target to the host through a serial console U­Boot 1.1.2 (Aug 3 2004 ­

U­Boot 1.1.2 (Aug 3 2004 ­ 17:31:20) RAM Configuration:

Bank #0: 00000000

2 MB serial

Out: serial Err: serial u­boot #

The U­Boot shell offers a set of commands. We will study the most important ones, see the documentation for a complete reference or the help command. help command.

8 MB

Flash:

In:

6

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

Flash information NAND flash information U­Boot information Information commands U­Boot> flinfo DataFlash:AT45DB021

Flash

information

NAND flash information U­Boot information

Information commands

U­Boot> flinfo flinfo

DataFlash:AT45DB021

Nb pages:

Page Size:

Size= 270336 bytes Logical address: 0xC0000000

Area 0: C0000000 to C0001FFF (RO) Bootstrap

Area 1: C0002000 to C0003FFF

1024

264

Environment

Area 2: C0004000 to C0041FFF (RO) U­BootBootstrap Area 1: C0002000 to C0003FFF 1024 264 Environment U­Boot> nand info Device 0: NAND 256MiB

U­Boot> nand info Device 0: NAND 256MiB 3,3V 8­bit, sector size 128 KiB nand info Device 0: NAND 256MiB 3,3V 8­bit, sector size 128 KiB

U­Boot> version U­Boot 2009.08 (Nov 15 2009 ­ 14:48:35) version U­Boot 2009.08 (Nov 15 2009 ­ 14:48:35)

Can vary from one board to the other (according to the U­Boot compile configuration)

7

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

Environment variables (1) U­Boot can be configured through environment variables, which affect the behavior of

Environment variables (1)

U­Boot can be configured through environment variables, which affect the behavior of the different commands.Environment variables (1) See the documentation for the complete list of environment variables. The printenv command

See the documentation for the complete list of environment variables.which affect the behavior of the different commands. The printenv command also to display all variables

The printenv command also to display all variables or one : printenv command also to display all variables or one :

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.2

Network configuration

8

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

Environment variables (2) The value of the environment variables can be changed using the setenv

Environment variables (2)

The value of the environment variables can be changed using the setenv command : setenv command :

u­boot # setenv serverip 10.0.0.2

Environment variable changes can be stored to flash using the saveenv command. The location in flash is defined at compile time in the U­Boot configuration saveenv command. The location in flash is defined at compile time in the U­Boot configuration file.

You can even create small scripts stored in environment variables:defined at compile time in the U­Boot configuration file. setenv mmc­boot 'mmc init 0; if fatload

setenv mmc­boot 'mmc init 0; if fatload mmc 0 80000000 boot.ini; then source; else if fatload mmc 0 80000000 uImage; then run mmc­ bootargs; bootm; fi; fi'

You can then execute the script:80000000 uImage; then run mmc­ bootargs; bootm; fi; fi' run mmc­boot 9 Free Electrons . Kernel,

run mmc­boot

9

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

Transferring files to the target U­Boot is mostly used to load and boot a kernel

Transferring files to the target

U­Boot is mostly used to load and boot a kernel image, but it also allows to change the kernel image and the root filesystem stored in flash.Transferring files to the target Files must be exchanged between the target and the development workstation.

Files must be exchanged between the target and the development workstation. This is possible :the kernel image and the root filesystem stored in flash. Through the network if the target

Through the network if the target has an Ethernet connection, and U­Boot contains a driver for the Ethernet chip. If so, the TFTP protocol can be used to exchange filestarget and the development workstation. This is possible : Through the serial line if no Ethernet

Through the serial line if no Ethernet connection is available.chip. If so, the TFTP protocol can be used to exchange files Target U­Boot TFTP client

Target U­Boot TFTP client
Target
U­Boot TFTP
client
Host TFTP server
Host
TFTP
server

Ethernet connection

U­Boot TFTP client Host TFTP server Ethernet connection 10 Free Electrons . Kernel, drivers and embedded

10

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

Configuring and testing tftp On GNU/Linux systems based on Debian: Ubuntu, Knoppix Install the tftpd­hpa

Configuring and testing tftp

On GNU/Linux systems based on Debian: Ubuntu, Knoppix

Install the tftpd­hpa package (tftp server): tftpd­hpa package (tftp server):

apt­get install tftpd­hpa

Copy files to the root directory of the tftp server. Example:package (tftp server): apt­get install tftpd­hpa cp arch/arm/boot/uImage /var/lib/tftpboot To test the

cp arch/arm/boot/uImage /var/lib/tftpboot

To test the server, install a tftp client on your workstation:server. Example: cp arch/arm/boot/uImage /var/lib/tftpboot apt­get install tftp­hpa Use it to download a file ( ­4

apt­get install tftp­hpa

Use it to download a file (­4 to force the use of IPv4) tftp ­4 localhost > get uImage ­4 to force the use of IPv4) tftp ­4 localhost > get uImage

11

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

U­boot mkimage The kernel image that U­Boot loads and boots must be prepared, so that

U­boot mkimage

The kernel image that U­Boot loads and boots must be prepared, so that an U­Boot specific header is added in front of the imageU­boot mkimage This is done with a tool that comes in U­Boot, mkimage Debian / Ubuntu:

This is done with a tool that comes in U­Boot, mkimage mkimage

Debian / Ubuntu: just install the uboot­mkimage package. uboot­mkimage package.

Or, compile it by yourself: simply configure U­Boot for any board of any architecture and compile it. Then install mkimage : mkimage:

cp tools/mkimage /usr/local/bin/

The special target uImage of the kernel Makefile can then be used to generate a kernel image suitable uImage of the kernel Makefile can then be used to generate a kernel image suitable for U­Boot.

12

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

Flashing a kernel image Compile your kernel and generate the U­Boot header running make uImage

Flashing a kernel image

Compile your kernel and generate the U­Boot header running make uImage make uImage

Copy the kernel image to the directory exported by the TFTP serverkernel and generate the U­Boot header running make uImage On the board, in U­Boot, download the

On the board, in U­Boot, download the kernel image to memory :kernel image to the directory exported by the TFTP server u­boot # tftp 8000 uImage Unprotect

u­boot # tftp 8000 uImage

Unprotect NOR flash u­boot # protect off 1:0­4 u­boot # protect off 1:0­4

Erase NOR flash u­boot # erase 1:0­4 u­boot # erase 1:0­4

Copy to NOR flash (0x01000000 : first sector) u­boot # cp.b ${fileaddr} 1000000 ${filesize} 0x01000000: first sector) u­boot # cp.b ${fileaddr} 1000000 ${filesize}

Restore NOR flash sector protection:sector) u­boot # cp.b ${fileaddr} 1000000 ${filesize} u­boot # protect on 1:0­4 See our practical labs

u­boot # protect on 1:0­4

See our practical labs for details handling NAND flash.

13

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

boot commands Specify kernel boot parameters: u­boot # setenv bootargs mem=64M \ console=ttyS0,115200 init=/sbin/init \

boot commands

Specify kernel boot parameters:boot commands u­boot # setenv bootargs mem=64M \ console=ttyS0,115200 init=/sbin/init \ root=/dev/mtdblock0 Continues on

u­boot # setenv bootargs mem=64M \ console=ttyS0,115200 init=/sbin/init \

root=/dev/mtdblock0

\ console=ttyS0,115200 init=/sbin/init \ root=/dev/mtdblock0 Continues on the same line Execute the kernel from a given
\ console=ttyS0,115200 init=/sbin/init \ root=/dev/mtdblock0 Continues on the same line Execute the kernel from a given

Continues on the same line

Execute the kernel from a given physical address (RAM or flash):\ root=/dev/mtdblock0 Continues on the same line bootm 0x01030000 14 Free Electrons . Kernel, drivers and

bootm 0x01030000

14

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

Practical lab – U­Boot Time to start the practical lab ! Communicate with U­Boot on

Practical lab – U­Boot

Practical lab – U­Boot Time to start the practical lab ! Communicate with U­Boot on the

Time to start the practical lab !

Communicate with U­Boot on the serial consolePractical lab – U­Boot Time to start the practical lab ! Learn the basic U­Boot commands

Learn the basic U­Boot commandslab ! Communicate with U­Boot on the serial console Set up TFTP communication with the board

Set up TFTP communication with the boardon the serial console Learn the basic U­Boot commands 1 Free Electrons . Kernel, drivers and

1

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

Free Electrons Linux kernel introduction Michael Opdenacker Thomas Petazzoni Free Electrons © Copyright 2004­2009,

Free Electrons

Linux kernel introduction

Michael Opdenacker Thomas Petazzoni Free Electrons

© Copyright 2004­2009, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/kernel­intro Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

Embedded Linux driver development Kernel overview Linux features 2 Free Electrons . Kernel, drivers and

Embedded Linux driver development

Kernel overview

Linux features

2

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

Linux kernel in the system User app B Library A User app A Userspace C

Linux kernel in the system

User app B Library A User app A Userspace C library Linux Kernel Manage Event
User app B
Library A
User app A
Userspace
C library
Linux Kernel
Manage
Event notification
hardware
Hardware

Event notification, information exposition

Call to services

3

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

History The Linux kernel is one component of a system, which also requires libraries and

History

The Linux kernel is one component of a system, which also requires libraries and applications to provide features to end users.History The Linux kernel was created as a hobby in 1991 by a Finnish student, Linus

The Linux kernel was created as a hobby in 1991 by a Finnish student, Linus Torvalds.libraries and applications to provide features to end users. Linux quickly started to be used as

as a hobby in 1991 by a Finnish student, Linus Torvalds. Linux quickly started to be

Linux quickly started to be used as the kernel for free software operating systems

Linus Torvalds has been able to create a large and dynamic developer and user community around Linux.to be used as the kernel for free software operating systems Nowadays, hundreds of people contribute

Nowadays, hundreds of people contribute to each kernel release, individuals or companies big and small.large and dynamic developer and user community around Linux. 4 Free Electrons . Kernel, drivers and

4

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

Linux license The whole Linux sources are Free Software released under the GNU General Public

Linux license

The whole Linux sources are Free Software released under the GNU General Public License version 2 (GPL v2).Linux license For the Linux kernel, this basically implies that: When you receive or buy a

For the Linux kernel, this basically implies that:under the GNU General Public License version 2 (GPL v2). When you receive or buy a

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.(GPL v2). For the Linux kernel, this basically implies that: When you produce Linux based devices,

When you produce Linux based devices, you must release the sources to the recipient, with the same rights, with no restrictionwith the right to study, modify and redistribute them. 5 Free Electrons . Kernel, drivers and

5

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

Linux kernel key features Portability and hardware support Runs on most architectures. Scalability Can run

Linux kernel key features

Portability and hardware support Runs on most architectures.Linux kernel key features Scalability Can run on super computers as well as on tiny devices

Scalability Can run on super computers as well as on tiny devices (4 MB of RAM is enough).Portability and hardware support Runs on most architectures. Compliance to standards and interoperability. Exhaustive

Compliance to standards and interoperability.as well as on tiny devices (4 MB of RAM is enough). Exhaustive networking support. Security

Exhaustive networking support.is enough). Compliance to standards and interoperability. Security It can't hide its flaws. Its code is

Security It can't hide its flaws. Its code is reviewed by many experts.and interoperability. Exhaustive networking support. Stability and reliability. Modularity Can include only what

Stability and reliability.hide its flaws. Its code is reviewed by many experts. Modularity Can include only what a

Modularity Can include only what a system needs even at run time.code is reviewed by many experts. Stability and reliability. Easy to program You can learn from

Easy to program You can learn from existing code. Many useful resources on the net.Can include only what a system needs even at run time. 6 Free Electrons . Kernel,

6

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

Supported hardware architectures 2.6.31 status See the arch/ directory in the kernel sources Minimum: 32

Supported hardware architectures

2.6.31 status

See the arch/ directory in the kernel sources

See the arch/ directory in the kernel sources

Minimum: 32 bit processors, with or without MMU, and gcc support

Minimum: 32 bit processors, with or without MMU, and gcc support

32 bit architectures ( arch/ subdirectories)

32

bit architectures (arch/ subdirectories)

64 bit architectures:

64

bit architectures:

32/64 bit architectures powerpc , x86 , sh

32/64 bit architectures powerpc, x86, sh

Find details in kernel sources: arch/<arch>/Kconfig , arch/<arch>/README , or

Find details in kernel sources: arch/<arch>/Kconfig, arch/<arch>/README, or Documentation/<arch>/

7

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

System calls The main interface between the kernel and userspace is the set of system

System calls

The main interface between the kernel and userspace is the set of system callsSystem calls About ~300 system calls that provides the main kernel services File and device operations,

About ~300 system calls that provides the main kernel servicesbetween the kernel and userspace is the set of system calls File and device operations, networking

~300 system calls that provides the main kernel services File and device operations, networking operations,

File and device operations, networking operations, inter­process communication, process management, memory mapping, timers, threads, synchronization primitives, etc.

This interface is stable over time: only new system calls can be added by the kernel developersmapping, timers, threads, synchronization primitives, etc. This system call interface is wrapped by the C library,

This system call interface is wrapped by the C library, and userspace applications usually never make a system call directly but rather use the corresponding C library functiononly new system calls can be added by the kernel developers 8 Free Electrons . Kernel,

8

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

Virtual filesystems Linux makes system and kernel information available in user­space through virtual filesystems

Virtual filesystems

Linux makes system and kernel information available in user­space through virtual filesystems (virtual files not existing on any real storage). No need to know kernel programming to access such information!Virtual filesystems Mounting /proc : sudo mount ­t proc none /proc Mounting /sys : sudo mount

Mounting /proc : /proc:

sudo mount ­t proc none /proc

Mounting /sys : /sys:

sudo mount ­t sysfs none /sys

none /proc Mounting /sys : sudo mount ­t sysfs none /sys Filesystem type R a w

Filesystem type

Raw device

or filesystem image In the case of virtual filesystems, any string is fine

Mount point

9

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

/proc details A few examples: /proc/cpuinfo : processor information /proc/meminfo : memory status /proc/version :

/proc details

A few examples:

/proc/cpuinfo: processor information : processor information

/proc/meminfo: memory status : memory status

/proc/version: kernel version and build information : kernel version and build information

/proc/cmdline: kernel command line : kernel command line

/proc/<pid>/environ: calling environment : calling environment

/proc/<pid>/cmdline: process command line : process command line

and many more! See by yourself!

Lots of details about the /proc interface are available in Documentation/filesystems/proc.txt (almost 2000 lines) in the kernel sources.

10

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

Embedded Linux usage Kernel overview Linux versioning scheme and development process 11 Free Electrons .

Embedded Linux usage

Kernel overview

Linux versioning scheme and development process

11

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

Until 2.6 (1) One stable major branch every 2 or 3 years Identified by an

Until 2.6 (1)

One stable major branch every 2 or 3 yearsUntil 2.6 (1) Identified by an even middle number Examples: 1. 0 , 2. 0 ,

Identified by an even middle numberUntil 2.6 (1) One stable major branch every 2 or 3 years Examples: 1. 0 ,

Examples: 1. 0 , 2. 0 , 2. 2 , 2. 4 1.0, 2.0, 2.2, 2.4

One development branch to integrate new functionalities and major changesan even middle number Examples: 1. 0 , 2. 0 , 2. 2 , 2. 4

Identified by an odd middle numberbranch to integrate new functionalities and major changes Examples: 2. 1 , 2. 3 , 2.

Examples: 2. 1 , 2. 3 , 2. 5 2.1, 2.3, 2.5

After some time, a development version becomes the new base version for the stable branchby an odd middle number Examples: 2. 1 , 2. 3 , 2. 5 Minor releases

Minor releases once in while: 2.2. 23 , 2.5. 12 , etc. 2.2.23, 2.5.12, etc.

12

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

Until 2.6 (2) Stable version 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.5.0

Until 2.6 (2)

Stable version
Stable version

2.4.0

2.4.1

2.4.2

2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.6.0 2.6.1
2.4.3
2.4.4
2.4.5
2.4.6
2.4.7
2.4.8
2.5.0
2.5.1
2.5.2
2.5.3
2.5.4
2.6.0
2.6.1
Development Stable
Development
Stable

Note: in reality, many more minor versions exist inside the stable and development branches

13

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

Changes since Linux 2.6 (1) Since 2.6.0 , kernel developers have been able to introduce

Changes since Linux 2.6 (1)

Since 2.6.0 , kernel developers have been able to introduce lots of new features one by 2.6.0, kernel developers have been able to introduce lots of new features one by one on a steady pace, without having to make major changes in existing subsystems.

Opening a new Linux 2.7 (or 2.9 ) development branch will be required only when Linux 2.6 is no 2.7 (or 2.9) development branch will be required only when Linux 2.6 is no longer able to accommodate key features without undergoing traumatic changes.

Thanks to this, more features are released to users at a faster pace.key features without undergoing traumatic changes. 14 Free Electrons . Kernel, drivers and embedded Linux

14

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

Changes since Linux 2.6 (2) Since 2.6.14, the kernel developers agreed on the following development

Changes since Linux 2.6 (2)

Since 2.6.14, the kernel developers agreed on the following development model:

After the release of a 2.6.x version, a two­weeks merge window opens, during which major additions are merged. 2.6.x version, a two­weeks merge window opens, during which major additions are merged.

The merge window is closed by the release of test version 2.6.(x+1)­rc1 2.6.(x+1)­rc1

The bug fixing period opens, for 6 to 10 weeks.is closed by the release of test version 2.6.(x+1)­rc1 At regular intervals during the bug fixing

At regular intervals during the bug fixing period, 2.6.(x+1)­rcY test versions are released. 2.6.(x+1)­rcY test versions are released.

When considered sufficiently stable, kernel 2.6.(x+1) is released, and the process starts again. 2.6.(x+1) is released, and the process starts again.

15

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

Merge and bug fixing windows2 weeks 6 to 10 weeks Merge window Bug fixing period 2.6.21 2.6.22­rc1 2.6.22­rc3 2.6.22­rc5

2 weeks

6 to 10 weeks

Merge window Bug fixing period 2.6.21 2.6.22­rc1 2.6.22­rc3 2.6.22­rc5 2.6.22­rc2 2.6.22­rc4 2.6.22
Merge window
Bug fixing period
2.6.21
2.6.22­rc1
2.6.22­rc3
2.6.22­rc5
2.6.22­rc2
2.6.22­rc4
2.6.22

2.6.21.1

2.6.21.22.6.21.2

2.6.21.3

2.6.21.4

2.6.21.5

2.6.22 2.6.21.1 2.6.21.22.6.21.2 2.6.21.3 2.6.21.4 2.6.21.5 2.6.22.1 Bug fix updates 16 Free Electrons . Kernel, drivers

2.6.22.1

Bug fix updates

16

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

More stability for the 2.6 kernel tree Issue: bug and security fixes only released for

More stability for the 2.6 kernel tree

Issue: bug and security fixes only released for most recent stable kernel versions.More stability for the 2.6 kernel tree Some people need to have a recent kernel, but

Some people need to have a recent kernel, but with long term support for security updates.fixes only released for most recent stable kernel versions. You could get long term support from

You could get long term support from a commercial embedded Linux provider.kernel, but with long term support for security updates. You could reuse sources for the kernel

You could reuse sources for the kernel used in Ubuntu Long Term Support releases (5 years of free security updates).long term support from a commercial embedded Linux provider. You could choose one of the versions

You could choose one of the versions advertised as “long term” in the kernel.org front page. They will be maintained longer (2 or 3 years), unlike other versions.Term Support releases (5 years of free security updates). 17 Free Electrons . Kernel, drivers and

be maintained longer (2 or 3 years), unlike other versions. 17 Free Electrons . Kernel, drivers

17

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

What's new in each Linux release? commit 3c92c2ba33cd7d666c5f83cc32aa590e794e91b0 Author: Andi Kleen

What's new in each Linux release?

commit 3c92c2ba33cd7d666c5f83cc32aa590e794e91b0 Author: Andi Kleen <ak@suse.de>

Date:

Tue Oct 11 01:28:33 2005 +0200

[PATCH] i386: Don't discard upper 32bits of HWCR on K8

Need to use long long, not long when RMWing a MSR. I think it's harmless right now, but still should be better fixed if AMD adds any bits in the upper 32bit of HWCR.

Bug was introduced with the TLB flush filter fix for i386

Signed­off­by: Andi Kleen <ak@suse.de> Signed­off­by: Linus Torvalds <torvalds@osdl.org>

??!

Linus Torvalds <torvalds@osdl.org> ? ? ! The official list of changes for each Linux release is

The official list of changes for each Linux release is just a huge list of individual patches!Linus Torvalds <torvalds@osdl.org> ? ? ! Very difficult to find out the key changes and to

Very difficult to find out the key changes and to get the global picture out of individual changes.Linux release is just a huge list of individual patches! Fortunately, a summary of key changes

Fortunately, a summary of key changes with enough details is available on http://wiki.kernelnewbies.org/LinuxChanges http://wiki.kernelnewbies.org/LinuxChanges

18

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

Embedded Linux kernel usage Embedded Linux kernel usage Michael Opdenacker Thomas Petazzoni Free Electrons ©

Embedded Linux kernel usage

Embedded Linux kernel usage

Michael Opdenacker Thomas Petazzoni Free Electrons

© Copyright 2004­2009, Free Electrons. Creative Commons BY­SA 3.0 license Latest update: Mar 15, 2011, Document sources, updates and translations:

http://free­electrons.com/docs/kernel­usage Corrections, suggestions, contributions and translations are welcome!

suggestions, contributions and translations are welcome! 1 Free Electrons . Kernel, drivers and embedded Linux

1

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

Contents Compiling and booting Linux kernel sources Kernel configuration Compiling the kernel Overall system startup

Contents

Compiling and booting Linux kernel sources Kernel configuration Compiling the kernel Overall system startup Linux device files Cross­compiling the kernel

startup Linux device files Cross­compiling the kernel 2 Free Electrons . Kernel, drivers and embedded Linux
startup Linux device files Cross­compiling the kernel 2 Free Electrons . Kernel, drivers and embedded Linux
startup Linux device files Cross­compiling the kernel 2 Free Electrons . Kernel, drivers and embedded Linux
startup Linux device files Cross­compiling the kernel 2 Free Electrons . Kernel, drivers and embedded Linux
startup Linux device files Cross­compiling the kernel 2 Free Electrons . Kernel, drivers and embedded Linux
startup Linux device files Cross­compiling the kernel 2 Free Electrons . Kernel, drivers and embedded Linux

2

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

Embedded Linux usage Compiling and booting Linux Linux kernel sources 3 Free Electrons . Kernel,

Embedded Linux usage

Compiling and booting Linux

Linux kernel sources

3

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

Location of kernel sources The official version of the Linux kernel, as released by Linus

Location of kernel sources

The official version of the Linux kernel, as released by Linus Torvalds is available at http://www.kernel.org http://www.kernel.org

This version follows the well­defined development model of the kernelby Linus Torvalds is available at http://www.kernel.org However, it may not contain the latest development from

However, it may not contain the latest development from a specific area, due to the organization of the development model and because features in development might not be ready for mainline inclusionfollows the well­defined development model of the kernel Many kernel sub­communities maintain their own kernel, with

Many kernel sub­communities maintain their own kernel, with usually newer but less stable featuresin development might not be ready for mainline inclusion Architecture communities (ARM, MIPS, PowerPC, etc.), device

Architecture communities (ARM, MIPS, PowerPC, etc.), device drivers communities (I2C, SPI, USB, PCI, network, etc.), other communities (real­time, etc.)own kernel, with usually newer but less stable features They generally don't release official versions, only

They generally don't release official versions, only development trees are availablePCI, network, etc.), other communities (real­time, etc.) 4 Free Electrons . Kernel, drivers and embedded Linux

4

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

Linux kernel size (1) Linux 2.6.37 sources: Raw size: 412 MB (37,300 files, approx 14,000,000

Linux kernel size (1)

Linux 2.6.37 sources:Linux kernel size (1) Raw size: 412 MB (37,300 files, approx 14,000,000 lines) gzip compressed tar

Raw size: 412 MB (37,300 files, approx 14,000,000 lines) gzip compressed tar archive: 89 MB bzip2 compressed tar archive: 71 MB (better) lzma compressed tar archive: 61 MB (best)

Minimum Linux 2.6.29 compiled kernel size with CONFIG_EMBEDDED , for a kernel that boots a QEMU PC (IDE hard drive, ext2 filesystem, CONFIG_EMBEDDED, for a kernel that boots a QEMU PC (IDE hard drive, ext2 filesystem, ELF executable support):

532 KB (compressed), 1325 KB (raw)

Why are these sources so big? Because they include thousands of device drivers, many network protocols, support many architectures and filesystemsELF executable support): 532 KB (compressed), 1325 KB (raw) The Linux core (scheduler, memory management )

The Linux core (scheduler, memory managementprotocols, support many architectures and filesystems ) is pretty small! 5 Free Electrons . Kernel, drivers

)

is pretty small!

5

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

Linux kernel size (2) Size of Linux source directories (KB) arch block crypto Documentation drivers

Linux kernel size (2)

Size of Linux source directories (KB)

arch

block

crypto

Documentation

drivers

fs

include

init

ipc

kernel

lib

mm

net

scripts

security

sound

usr

init ipc kernel lib mm net scripts security sound usr 0 50000 100000 150000 Linux 2.6.17
init ipc kernel lib mm net scripts security sound usr 0 50000 100000 150000 Linux 2.6.17

0

50000

100000