540
Embedded Linux system development Embedded Linux system development Free Electrons Copyright 2004-2015, Free Electrons. Creative Commons BY-SA 3.0 license. Latest update: July 19, 2015. Document updates and sources: http://free- electrons.com/doc/training/embedded- linux Corrections, suggestions, contributions and translations are welcome! Send them to [email protected] Embedded Linux Developers Free Electrons Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 1/540

Embedded Linux Slides

Embed Size (px)

DESCRIPTION

Embedded Linux Slides/FUTURE

Citation preview

  • Embedded Linux system development

    Embedded Linux systemdevelopment

    Free Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Latest update: July 19, 2015.

    Document updates and sources:http://free-electrons.com/doc/training/embedded-linux

    Corrections, suggestions, contributions and translations are welcome!Send them to [email protected]

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 1/540

  • Rights to copy

    Copyright 2004-2015, Free ElectronsLicense: Creative Commons Attribution - Share Alike 3.0http://creativecommons.org/licenses/by-sa/3.0/legalcode

    You are free:

    I to copy, distribute, display, and perform the workI to make derivative worksI to make commercial use of the work

    Under the following conditions:

    I Attribution. You must give the original author credit.I 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.

    I For any reuse or distribution, you must make clear to others the license terms ofthis work.

    I Any of these conditions can be waived if you get permission from the copyrightholder.

    Your fair use and other rights are in no way affected by the above.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 2/540

  • Hyperlinks in the document

    There are many hyperlinks in the document

    I Regular hyperlinks:http://kernel.org/

    I Kernel documentation links:Documentation/kmemcheck.txt

    I Links to kernel source files and directories:drivers/input

    include/linux/fb.h

    I Links to the declarations, definitions and instances of kernelsymbols (functions, types, data, structures):platform_get_irq()

    GFP_KERNEL

    struct file_operations

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 3/540

  • Free Electrons at a glance

    I Engineering company created in 2004(not a training company!)

    I Locations: Orange, Toulouse, Lyon (France)

    I Serving customers all around the worldSee http://free-electrons.com/company/customers/

    I Head count: 9Only Free Software enthusiasts!

    I Focus: Embedded Linux, Linux kernel, Android Free Software/ Open Source for embedded and real-time systems.

    I Activities: development, training, consulting, technicalsupport.

    I Added value: get the best of the user and developmentcommunity and the resources it offers.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 4/540

  • Free Electrons on-line resources

    I All our training materials:http://free-electrons.com/docs/

    I Technical blog:http://free-electrons.com/blog/

    I Quarterly newsletter:http://lists.free-

    electrons.com/mailman/listinfo/newsletter

    I News and discussions (Google +):https://plus.google.com/+FreeElectronsDevelopers

    I News and discussions (LinkedIn):http://linkedin.com/groups/Free-Electrons-4501089

    I Quick news (Twitter):http://twitter.com/free_electrons

    I Linux Cross Reference - browse Linux kernel sources on-line:http://lxr.free-electrons.com

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 5/540

  • Generic course information

    Generic courseinformationFree Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 6/540

  • Hardware used in this training session

    Using Atmel SAMA5D3 Xplained boards in all practical labs

    I SAMA5D36 (Cortex A5) CPU from AtmelI USB powered!I 256 MB DDR2 RAM, 256 MB NAND

    flash

    I 2 Ethernet ports (Gigabit + 100 Mbit)I 2 USB 2.0 host, 1 USB deviceI 1 MMC/SD slotI 3.3 V serial port (like Beaglebone Black)I Misc: Arduino R3-compatible header,

    JTAG, buttons, LEDs

    I Currently sold at 69 EUR by Mouser(V.A.T. not included)

    Board and CPU documentation, design files, software:

    http://www.atmel.com/sama5d3xplained

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 7/540

  • Shopping list: hardware for this course

    I Atmel SAMA5D3 Xplained board - Available fromAtmel and multiple distributors (Mouser, Digikey...)See http://www.atmel.com/tools/ATSAMA5D3-XPLD.aspx

    I USB Serial Cable - Female ends: Olimex:http://j.mp/18Hk8yF

    I Logitech USB H340 audio headsetshttp://www.logitech.com/en-us/product/11608

    I An SD card with at least 128 MB of capacity

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 8/540

  • Participate!

    During the lectures...

    I Dont hesitate to ask questions. Other people in the audiencemay have similar questions too.

    I This helps the trainer to detect any explanation that wasntclear or detailed enough.

    I Dont hesitate to share your experience, for example tocompare Linux / Android with other operating systems usedin your company.

    I Your point of view is most valuable, because it can be similarto your colleagues and different from the trainers.

    I Your participation can make our session more interactive andmake the topics easier to learn.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 9/540

  • Practical lab guidelines

    During practical labs...

    I We cannot support more than 8 workstations at once (eachwith its board and equipment). Having more would make thewhole class progress slower, compromising the coverage of thewhole training agenda (exception for public sessions: up to 10people).

    I So, if you are more than 8 participants, please form up to 8working groups.

    I Open the electronic copy of your lecture materials, and use itthroughout the practical labs to find the slides you need again.

    I Dont copy and paste from the PDF slides.The slides contain UTF-8 characters that look the same asASCII ones, but wont be understood by shells or compilers.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 10/540

  • Cooperate!

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

    I If you complete your labs before other people, dont hesitateto help other people and investigate the issues they face. Thefaster we progress as a group, the more time we have toexplore extra topics.

    I Explain what you understood to other participants whenneeded. It also helps to consolidate your knowledge.

    I Dont hesitate to report potential bugs to your instructor.

    I Dont hesitate to look for solutions on the Internet as well.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 11/540

  • Command memento sheet

    I This memento sheet givescommand examples for the mosttypical needs (looking for files,extracting a tar archive...)

    I It saves us 1 day of UNIX / Linuxcommand line training.

    I Our best tip: in the command lineshell, always hit the Tab key tocomplete command names and filepaths. This avoids 95% of typingmistakes.

    I Get an electronic copy onhttp://free-electrons.com/

    doc/training/embedded-

    linux/command_memento.pdf

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 12/540

  • vi basic commands

    I The vi editor is very useful tomake quick changes to files in anembedded target.

    I Though not very user friendly atfirst, vi is very powerful and itsmain 15 commands are easy tolearn and are sufficient for 99% ofeveryones needs!

    I Get an electronic copy onhttp://free-electrons.com/

    doc/training/embedded-

    linux/vi_memento.pdf

    I You can also take the quick tutorialby running vimtutor. This is aworthy investment!

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 13/540

  • Introduction to Embedded Linux

    Introduction toEmbedded LinuxFree Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 14/540

  • Birth of free software

    I 1983, Richard Stallman, GNU project and the free softwareconcept. Beginning of the development of gcc, gdb, glibc andother important tools

    I 1991, Linus Torvalds, Linux kernel project, a Unix-likeoperating system kernel. Together with GNU software andmany other open-source components: a completely freeoperating system, GNU/Linux

    I 1995, Linux is more and more popular on server systems

    I 2000, Linux is more and more popular on embeddedsystems

    I 2008, Linux is more and more popular on mobile devices

    I 2010, Linux is more and more popular on phones

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 15/540

  • Free software?

    I A program is considered free when its license offers to all itsusers the following four freedoms

    I Freedom to run the software for any purposeI Freedom to study the software and to change itI Freedom to redistribute copiesI Freedom to distribute copies of modified versions

    I These freedoms are granted for both commercial andnon-commercial use

    I They imply the availability of source code, software can bemodified and distributed to customers

    I Good match for embedded systems!

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 16/540

  • What is embedded Linux?

    Embedded Linux is the usage of theLinux kernel and various

    open-source components inembedded systems

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 17/540

  • Introduction to Embedded Linux

    Advantages of Linux and open-sourcefor embedded systems

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 18/540

  • Re-using components

    I The key advantage of Linux and open-source in embeddedsystems is the ability to re-use components

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

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

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

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

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 19/540

  • Low cost

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

    I If your embedded system uses only free software, you canreduce the cost of software licenses to zero. Even thedevelopment tools are free, unless you choose a commercialembedded Linux edition.

    I Allows to have a higher budget for the hardware or toincrease the companys skills and knowledge

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 20/540

  • Full control

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

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

    I Without lock-in or dependency from a third-party vendorI To be true, non open-source components must be avoided

    when the system is designed and developed

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 21/540

  • Quality

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

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

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

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 22/540

  • Eases testing of new features

    I Open-source being freely available, it is easy to get a piece ofsoftware and evaluate it

    I Allows to easily study several options while making a choice

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

    I Allows to easily explore new possibilities and solutions

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 23/540

  • Community support

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

    I This community can provide a high-quality support: you candirectly contact the main developers of the component youare using. The likelyhood of getting an answer doesnt dependwhat company you work for.

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

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 24/540

  • Taking part into the community

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

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

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

    I For the managers: motivation factor for engineers, allowsthe company to be recognized in the open-source communityand therefore get support more easily and be more attractiveto open-source developers

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 25/540

  • Introduction to Embedded Linux

    A few examples of embedded systemsrunning Linux

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 26/540

  • Personal routers

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 27/540

  • Television

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 28/540

  • Point of sale terminal

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 29/540

  • Laser cutting machine

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 30/540

  • Viticulture machine

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 31/540

  • Introduction to Embedded Linux

    Embedded hardware for Linuxsystems

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 32/540

  • Processor and architecture (1)

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

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

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 33/540

  • Processor and architecture (2)

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

    I Linux is not designed for small microcontrollers.

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 34/540

  • RAM and storage

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

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

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

    I Block storage including SD/MMC cards and eMMC issupported

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 35/540

  • Communication

    I The Linux kernel has support for many commoncommunication buses

    I I2CI SPII CANI 1-wireI SDIOI USB

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 36/540

  • Types of hardware platforms

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

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

    I Community development platforms, to make a particularSoC popular and easily available. These are ready-to-use andlow cost, but usually have less peripherals than evaluationplatforms. To some extent, can also be used for real products.

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 37/540

  • Criteria for choosing the hardware

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

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

    I Some SoC vendors and/or board vendors do not contributetheir changes back to the mainline Linux kernel. Ask them todo so, or use another product if you can. A good measurementis to see the delta between their kernel and the official one.

    I Between properly supported hardware in the officialLinux kernel and poorly-supported hardware, there willbe huge differences in development time and cost.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 38/540

  • Introduction to Embedded Linux

    Embedded Linux system architecture

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 39/540

  • Global architecture

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 40/540

  • Software components

    I Cross-compilation toolchainI Compiler that runs on the development machine, but generates

    code for the target

    I BootloaderI Started by the hardware, responsible for basic initialization,

    loading and executing the kernel

    I Linux KernelI Contains the process and memory management, network stack,

    device drivers and provides services to user space applications

    I C libraryI The interface between the kernel and the user space

    applications

    I Libraries and applicationsI Third-party or in-house

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 41/540

  • Embedded Linux work

    Several distinct tasks are needed when deploying embedded Linuxin a product:

    I Board Support Package developmentI A BSP contains a bootloader and kernel with the suitable

    device drivers for the targeted hardwareI Purpose of our Kernel Development training

    I System integrationI Integrate all the components, bootloader, kernel, third-party

    libraries and applications and in-house applications into aworking system

    I Purpose of this training

    I Development of applicationsI Normal Linux applications, but using specifically chosen

    libraries

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 42/540

  • Embedded Linux development environment

    Embedded LinuxdevelopmentenvironmentFree Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 43/540

  • Embedded Linux solutions

    I Two ways to switch to embedded LinuxI Use solutions provided and supported by vendors like

    MontaVista, Wind River or TimeSys. These solutions comewith their own development tools and environment. They usea mix of open-source components and proprietary tools.

    I Use community solutions. They are completely open,supported by the community.

    I In Free Electrons training sessions, we do not promote aparticular vendor, and therefore use community solutions

    I However, knowing the concepts, switching to vendor solutionswill be easy

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 44/540

  • OS for Linux development

    I We strongly recommend to use Linux as the desktop operatingsystem to embedded Linux developers, for multiple reasons.

    I All community tools are developed and designed to run onLinux. Trying to use them on other operating systems(Windows, Mac OS X) will lead to trouble, and their usage onthese systems is generally not supported by communitydevelopers.

    I As Linux also runs on the embedded device, all the knowledgegained from using Linux on the desktop will apply similarly tothe embedded device.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 45/540

  • Desktop Linux distribution

    I Any good and sufficiently recent Linuxdesktop distribution can be used for thedevelopment workstation

    I Ubuntu, Debian, Fedora, openSUSE,Red Hat, etc.

    I We have chosen Ubuntu, as it is a widelyused and easy to use desktop Linuxdistribution

    I The Ubuntu setup on the training laptopshas intentionally been left untouched afterthe normal installation process. Learningembedded Linux is also about learning thetools needed on the developmentworkstation!

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 46/540

  • Linux root and non-root users

    I Linux is a multi-user operating systemI The root user is the administrator, and it can do privileged

    operations such as: mounting filesystems, configuring thenetwork, creating device files, changing the systemconfiguration, installing or removing software

    I All other users are unprivileged, and cannot perform theseadministrator-level operations

    I On an Ubuntu system, it is not possible to log in as root,only as a normal user.

    I The system has been configured so that the user accountcreated first is allowed to run privileged operations through aprogram called sudo.

    I Example: sudo mount /dev/sda2 /mnt/disk

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 47/540

  • Software packages

    I The distribution mechanism for software in GNU/Linux isdifferent from the one in Windows

    I Linux distributions provides a central and coherent way ofinstalling, updating and removing applications and libraries:packages

    I Packages contains the application or library files, andassociated meta-information, such as the version and thedependencies

    I .deb on Debian and Ubuntu, .rpm on Red Hat, Fedora,openSUSE

    I Packages are stored in repositories, usually on HTTP or FTPservers

    I You should only use packages from official repositories foryour distribution, unless strictly required.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 48/540

  • Managing software packages (1)

    Instructions for Debian based GNU/Linux systems(Debian, Ubuntu...)

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

    I To update package repository lists:sudo apt-get update

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 49/540

  • Managing software packages (2)

    I To install a given package:sudo apt-get install

    I To remove a given package:sudo apt-get remove

    I To install all available package updates:sudo apt-get dist-upgrade

    I Get information about a package:apt-cache show

    I Graphical interfacesI Synaptic for GNOMEI KPackageKit for KDE

    Further details on package management:http://www.debian.org/doc/manuals/apt-howto/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 50/540

  • Host vs. target

    I When doing embedded development, there is always a splitbetween

    I The host, the development workstation, which is typically apowerful PC

    I The target, which is the embedded system under development

    I They are connected by various means: almost always a serialline for debugging purposes, frequently an Ethernetconnection, sometimes a JTAG interface for low-leveldebugging

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 51/540

  • Serial line communication program

    I An essential tool for embedded development is a serial linecommunication program, like HyperTerminal in Windows.

    I There are multiple options available in Linux: Minicom,Picocom, Gtkterm, Putty, etc.

    I In this training session, we recommend using the simplest ofthem: picocom

    I Installation with sudo apt-get install picocomI Run with picocom -b BAUD_RATE /dev/SERIAL_DEVICEI Exit with Control-A Control-X

    I SERIAL_DEVICE is typicallyI ttyUSBx for USB to serial convertersI ttySx for real serial ports

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 52/540

  • Command line tips

    I Using the command line is mandatory for many operationsneeded for embedded Linux development

    I It is a very powerful way of interacting with the system, withwhich you can save a lot of time.

    I Some useful tipsI You can use several tabs in the Gnome TerminalI Remember that you can use relative paths (for example:

    ../../linux) in addition to absolute paths (for example:/home/user)

    I In a shell, hit [Control] [r], then a keyword, will searchthrough the command history. Hit [Control] [r] again tosearch backwards in the history

    I You can copy/paste paths directly from the file manager to theterminal by drag-and-drop.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 53/540

  • Practical lab - Training Setup

    Prepare your lab environment

    I Download the lab archive

    I Enforce correct permissions

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 54/540

  • Cross-compiling toolchains

    Cross-compilingtoolchainsFree Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 55/540

  • Cross-compiling toolchains

    Definition and Components

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 56/540

  • Definition (1)

    I The usual development tools available on a GNU/Linuxworkstation is a native toolchain

    I This toolchain runs on your workstation and generates codefor your workstation, usually x86

    I For embedded system development, it is usually impossible ornot interesting to use a native toolchain

    I The target is too restricted in terms of storage and/or memoryI The target is very slow compared to your workstationI You may not want to install all development tools on your

    target.

    I Therefore, cross-compiling toolchains are generally used.They run on your workstation but generate code for yourtarget.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 57/540

  • Definition (2)

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 58/540

  • Machines in build procedures

    I Three machines must be distinguished when discussingtoolchain creation

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

    toolchain are executed.

    I Four common build types are possible for toolchains

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 59/540

  • Different toolchain build procedures

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 60/540

  • Components

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 61/540

  • Binutils

    I Binutils is a set of tools to generate and manipulate binariesfor a given CPU architecture

    I as, the assembler, that generates binary code from assemblersource code

    I ld, the linkerI ar, ranlib, to generate .a archives, used for librariesI objdump, readelf, size, nm, strings, to inspect binaries.

    Very useful analysis tools!I strip, to strip useless parts of binaries in order to reduce their

    size

    I http://www.gnu.org/software/binutils/

    I GPL license

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 62/540

  • Kernel headers (1)

    I The C library and compiledprograms needs to interact withthe kernel

    I Available system calls and theirnumbers

    I Constant definitionsI Data structures, etc.

    I Therefore, compiling the C libraryrequires kernel headers, and manyapplications also require them.

    I Available in and and a few otherdirectories corresponding to theones visible in include/ in thekernel sources

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 63/540

  • Kernel headers (2)

    I System call numbers, in

    #define __NR_exit 1

    #define __NR_fork 2

    #define __NR_read 3

    I Constant definitions, here in ,included from , included from

    #define O_RDWR 00000002

    I Data structures, here in

    struct stat {

    unsigned long st_dev;

    unsigned long st_ino;

    [...]

    };

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 64/540

  • Kernel headers (3)

    I The kernel to user space ABI is backward compatibleI Binaries generated with a toolchain using kernel headers older

    than the running kernel will work without problem, but wontbe able to use the new system calls, data structures, etc.

    I Binaries generated with a toolchain using kernel headers newerthan the running kernel might work on if they dont use therecent features, otherwise they will break

    I Using the latest kernel headers is not necessary, unless accessto the new kernel features is needed

    I The kernel headers are extracted from the kernel sources usingthe headers_install kernel Makefile target.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 65/540

  • GCC

    I GNU Compiler Collection, the famous freesoftware compiler

    I Can compile C, C++, Ada, Fortran, Java,Objective-C, Objective-C++, and generate codefor a large number of CPU architectures,including ARM, AVR, Blackfin, CRIS, FRV,M32, MIPS, MN10300, PowerPC, SH, v850,i386, x86 64, IA64, Xtensa, etc.

    I http://gcc.gnu.org/

    I Available under the GPL license, libraries underthe LGPL.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 66/540

  • C library

    I The C library is an essential component ofa Linux system

    I Interface between the applications andthe kernel

    I Provides the well-known standard C APIto ease application development

    I Several C libraries are available:glibc, uClibc, eglibc, dietlibc, newlib, etc.

    I The choice of the C library must be madeat the time of the cross-compilingtoolchain generation, as the GCC compileris compiled against a specific C library.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 67/540

  • Cross-compiling toolchains

    C Libraries

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 68/540

  • glibc

    I License: LGPL

    I C library from the GNU project

    I Designed for performance, standardscompliance and portability

    I Found on all GNU / Linux host systems

    I Of course, actively maintained

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

    I http://www.gnu.org/software/libc/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 69/540

  • uClibc

    I http://www.uclibc.org/

    I License: LGPLI Lightweight C library for small embedded systems

    I High configurability: many features can be enabled or disabledthrough a menuconfig interface

    I Works only with Linux/uClinux, works on most embeddedarchitectures

    I No guaranteed binary compatibility. May need to recompileapplications when the library configuration changes.

    I Focus on size rather than performanceI Small compile time

    I News: project revived by the uClibc-ng project, makingfrequent releases again, and now supported by Buildroot (seehttp://uclibc-ng.org/).

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 70/540

  • uClibc (2)

    I Most of the applications compile with uClibc. This applies toall applications used in embedded systems.

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

    96KB)I glibc 2.9: approx 2.5 MB

    I Some features not available or limited: priority-inheritancemutexes, NPTL support is very new, fixed Name ServiceSwitch functionality, etc.

    I Used on a large number of production embedded products,including consumer electronic devices

    I Supported by all commercial embedded Linux providers (proofof maturity).

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 71/540

  • eglibc

    I Embedded glibc, LGPL license too

    I Was a variant of glibc, better adapted to theneeds of embedded systems, because of pastdisagreement with glibc maintainers.

    I eglibcs goals included reduced footprint,configurable components, better support forcross-compilation and cross-testing.

    I Could be built without support for NIS, locales,IPv6, and many other features.

    I Fortunately for eglibc, the glibc maintainer haschanged and its features are now included inglibc. Version 2.19 (Feb. 2014) was the lastrelease.

    I http://en.wikipedia.org/wiki/Embedded_GLIBC

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 72/540

  • Honey, I shrunk the programs!

    I Executable size comparison on ARM, tested with eglibc 2.15and uClibc 0.9.33.2

    I Plain hello world program (stripped):helloworld static dynamic

    uClibc 18kB 2.5kBuClibc with Thumb-2 14kB 2.4kBeglibc with Thumb-2 361kB 2.7kB

    I Busybox (stripped):busybox static dynamic

    uClibc 750kB 603kBuClibc with Thumb-2 533kB 439kBeglibc with Thumb-2 934kB 444kB

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 73/540

  • Other smaller C libraries

    I Several other smaller C libraries have been developed, butnone of them have the goal of allowing the compilation oflarge existing applications

    I They need specially written programs and applicationsI Choices:

    I Dietlibc, http://www.fefe.de/dietlibc/. Approximately70 KB.

    I Newlib, http://sourceware.org/newlib/I Klibc, http://www.kernel.org/pub/linux/libs/klibc/,

    designed for use in an initramfs or initrd at boot time.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 74/540

  • Cross-compiling toolchains

    Toolchain Options

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 75/540

  • ABI

    I When building a toolchain, the ABI used to generate binariesneeds to be defined

    I ABI, for Application Binary Interface, defines the callingconventions (how function arguments are passed, how thereturn value is passed, how system calls are made) and theorganization of structures (alignment, etc.)

    I All binaries in a system must be compiled with the same ABI,and the kernel must understand this ABI.

    I On ARM, two main ABIs: OABI and EABII Nowadays everybody uses EABI

    I On MIPS, several ABIs: o32, o64, n32, n64

    I http://en.wikipedia.org/wiki/Application_Binary_Interface

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 76/540

  • Floating point support

    I Some processors have a floating point unit, some others donot.

    I For example, many ARMv4 and ARMv5 CPUs do not have afloating point unit. Since ARMv7, a VFP unit is mandatory.

    I For processors having a floating point unit, the toolchainshould generate hard float code, in order to use the floatingpoint instructions directly

    I For processors without a floating point unit, two solutionsI Generate hard float code and rely on the kernel to emulate the

    floating point instructions. This is very slow.I Generate soft float code, so that instead of generating floating

    point instructions, calls to a user space library are generated

    I Decision taken at toolchain configuration time

    I Also possible to configure which floating point unit should beused

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 77/540

  • CPU optimization flags

    I A set of cross-compiling tools is specific to a CPUarchitecture (ARM, x86, MIPS, PowerPC)

    I However, with the -march=, -mcpu=, -mtune= options, onecan select more precisely the target CPU type

    I For example, -march=armv7 -mcpu=cortex-a8

    I At the toolchain compilation time, values can be chosen.They are used:

    I As the default values for the cross-compiling tools, when noother -march, -mcpu, -mtune options are passed

    I To compile the C library

    I Even if the C library has been compiled for armv5t, it doesntprevent from compiling other programs for armv7

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 78/540

  • Cross-compiling toolchains

    Obtaining a Toolchain

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 79/540

  • Building a toolchain manually

    Building a cross-compiling toolchain by yourself is a difficult andpainful task! Can take days or weeks!

    I Lots of details to learn: many components to build,complicated configuration

    I Lots of decisions to make (such as C library version, ABI,floating point mechanisms, component versions)

    I Need kernel headers and C library sources

    I Need to be familiar with current gcc issues and patches onyour platform

    I Useful to be familiar with building and configuring tools

    I See the Crosstool-NG docs/ directory for details on howtoolchains are built.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 80/540

  • Get a pre-compiled toolchain

    I Solution that many people chooseI Advantage: it is the simplest and most convenient solutionI Drawback: you cant fine tune the toolchain to your needs

    I Determine what toolchain you need: CPU, endianness, Clibrary, component versions, ABI, soft float or hard float, etc.

    I Check whether the available toolchains match yourrequirements.

    I Possible choicesI Sourcery CodeBench toolchainsI Linaro toolchainsI Toolchains packaged by your distribution

    Ubuntu example:sudo apt-get install gcc-arm-linux-gnueabi

    I More references at http://elinux.org/Toolchains

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 81/540

  • Sourcery CodeBench

    I CodeSourcery was a company with extended expertise on freesoftware toolchains. It has been bought by Mentor Graphics.

    I They sell toolchains with support, but also provide a Liteversion, that is free and usable for commercial products

    I They have toolchains available forI MIPSI NIOS-III AMD64I Hexagon

    I They stopped support for ARM, PowerPC, SuperH, x86!

    I Be sure to use the GNU/Linux versions. The EABI versionsare for bare-metal development (no operating system)

    http://mentor.com/embedded-software/sourcery-

    tools/sourcery-codebench/editions/lite-edition/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 82/540

  • Linaro toolchains

    I Linaro contributes to improving mainline gcc on ARM,in particular by hiring CodeSourcery developers.

    I For people who cant wait for the next releases of gcc,Linaro releases modified sources of stable releases ofgcc, with these optimizations for ARM (mainly forrecent Cortex A CPUs).

    I As any gcc release, these sources can be used by buildtools to build their own binary toolchains (Buildroot,OpenEmbedded...). This allows to support glibc,uClibc and eglibc.

    I https://wiki.linaro.org/WorkingGroups/ToolChain

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 83/540

  • Installing and using a pre-compiled toolchain

    I Follow the installation procedure proposed by the vendor

    I Usually, it is simply a matter of extracting a tarball whereveryou want.

    I Then, add the path to toolchain binaries in your PATH:export PATH=/path/to/toolchain/bin/:$PATH

    I Finally, compile your applicationsPREFIX-gcc -o foobar foobar.c

    I PREFIX depends on the toolchain configuration, and allows todistinguish cross-compilation tools from native compilationutilities

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 84/540

  • Toolchain building utilities

    Another solution is to use utilities that automate the process ofbuilding the toolchain

    I Same advantage as the pre-compiled toolchains: you dontneed to mess up with all the details of the build process

    I But also offers more flexibility in terms of toolchainconfiguration, component version selection, etc.

    I They also usually contain several patches that fix knownissues with the different components on some architectures

    I Multiple tools with identical principle: shell scripts or Makefilethat automatically fetch, extract, configure, compile andinstall the different components

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 85/540

  • Toolchain building utilities (2)

    I Crosstool-ngI Rewrite of the older Crosstool, with a menuconfig-like

    configuration systemI Feature-full: supports uClibc, glibc, eglibc, hard and soft float,

    many architecturesI Actively maintainedI http://crosstool-ng.org/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 86/540

  • Toolchain building utilities (3)

    Many root filesystem build systems also allow the construction of across-compiling toolchainI Buildroot

    I Makefile-based. Can build (e)glibc, uClibc and musl basedtoolchains, for a wide range of architectures.

    I http://www.buildroot.net

    I PTXdistI Makefile-based, uClibc or glibc, maintained mainly by

    PengutronixI http://pengutronix.de/software/ptxdist/

    I OpenEmbedded / YoctoI A featureful, but more complicated build systemI http://www.openembedded.org/I https://www.yoctoproject.org/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 87/540

  • Crosstool-NG: installation and usage

    I Installation of Crosstool-NG can be done system-wide, or justlocally in the source directory. For local installation:

    ./configure --enable-local

    make

    make install

    I Some sample configurations for various architectures areavailable in samples, they can be listed using

    ./ct-ng list-samples

    I To load a sample configuration

    ./ct-ng

    I To adjust the configuration

    ./ct-ng menuconfig

    I To build the toolchain

    ./ct-ng build

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 88/540

  • Toolchain contents

    I The cross compilation tool binaries, in bin/I This directory can be added to your PATH to ease usage of the

    toolchain

    I One or several sysroot, each containingI The C library and related libraries, compiled for the targetI The C library headers and kernel headers

    I There is one sysroot for each variant: toolchains can bemultilib if they have several copies of the C library for differentconfigurations (for example: ARMv4T, ARMv5T, etc.)

    I CodeSourcery ARM toolchain are multilib, the sysroots are inarm-none-linux-gnueabi/libc/,arm-none-linux-gnueabi/libc/armv4t/,arm-none-linux-gnueabi/libc/thumb2

    I Crosstool-NG toolchains can be multilib too (stillexperimental), otherwise the sysroot is inarm-unknown-linux-uclibcgnueabi/sysroot

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 89/540

  • Practical lab - Using Crosstool-NG

    Time to build your toolchain

    I Configure Crosstool-NG

    I Run it to build your owncross-compiling toolchain

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 90/540

  • Bootloaders

    BootloadersFree Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 91/540

  • Bootloaders

    Boot Sequence

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 92/540

  • Bootloaders

    I The bootloader is a piece of code responsible forI Basic hardware initializationI Loading of an application binary, usually an operating system

    kernel, from flash storage, from the network, or from anothertype of non-volatile storage.

    I Possibly decompression of the application binaryI Execution of the application

    I Besides these basic functions, most bootloaders provide a shellwith various commands implementing different operations.

    I Loading of data from storage or network, memory inspection,hardware diagnostics and testing, etc.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 93/540

  • Bootloaders on x86 (1)

    I The x86 processors are typically bundled on aboard with a non-volatile memory containing aprogram, the BIOS.

    I This program gets executed by the CPU afterreset, and is responsible for basic hardwareinitialization and loading of a small piece of codefrom non-volatile storage.

    I This piece of code is usually the first 512 bytesof a storage device

    I This piece of code is usually a 1st stagebootloader, which will load the full bootloaderitself.

    I The bootloader can then offer all its features. Ittypically understands filesystem formats so thatthe kernel file can be loaded directly from anormal filesystem.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 94/540

  • Bootloaders on x86 (2)

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

    I Can read many filesystem formats to load the kernel image andthe configuration, provides a powerful shell with variouscommands, can load kernel images over the network, etc.

    I See our dedicated presentation for details:http://free-electrons.com/docs/grub/

    I Syslinux, for network and removable media booting (USB key,CD-ROM)http://www.kernel.org/pub/linux/utils/boot/syslinux/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 95/540

  • Booting on embedded CPUs: case 1

    I When powered, the CPU starts executing codeat a fixed address

    I There is no other booting mechanism providedby the CPU

    I The hardware design must ensure that a NORflash chip is wired so that it is accessible at theaddress at which the CPU starts executinginstructions

    I The first stage bootloader must be programmedat this address in the NOR

    I NOR is mandatory, because it allows randomaccess, which NAND doesnt allow

    I Not very common anymore (unpractical, andrequires NOR flash)

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 96/540

  • Booting on embedded CPUs: case 2

    I The CPU has an integrated boot code in ROMI BootROM on AT91 CPUs, ROM code on OMAP, etc.I Exact details are CPU-dependent

    I This boot code is able to load a first stage bootloader from astorage device into an internal SRAM (DRAM not initializedyet)

    I Storage device can typically be: MMC, NAND, SPI flash,UART (transmitting data over the serial line), etc.

    I The first stage bootloader isI Limited in size due to hardware constraints (SRAM size)I Provided either by the CPU vendor or through community

    projects

    I This first stage bootloader must initialize DRAM and otherhardware devices and load a second stage bootloader intoRAM

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 97/540

  • Booting on ARM Atmel AT91

    I RomBoot: tries to find a valid bootstrap imagefrom various storage sources, and load it intoSRAM (DRAM not initialized yet). Size limitedto 4 KB. No user interaction possible in standardboot mode.

    I AT91Bootstrap: runs from SRAM. Initializes theDRAM, the NAND or SPI controller, and loadsthe secondary bootloader into RAM and starts it.No user interaction possible.

    I U-Boot: runs from RAM. Initializes some otherhardware devices (network, USB, etc.). Loads thekernel image from storage or network to RAMand starts it. Shell with commands provided.

    I Linux Kernel: runs from RAM. Takes over thesystem completely (bootloaders no longer exists).

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 98/540

  • Booting on ARM TI OMAP3

    I ROM Code: tries to find a valid bootstrap imagefrom various storage sources, and load it intoSRAM or RAM (RAM can be initialized by ROMcode through a configuration header). Sizelimited to

  • Booting on Marvell SoC

    I ROM Code: tries to find a valid bootstrap imagefrom various storage sources, and load it intoRAM. The RAM configuration is described in aCPU-specific header, prepended to the bootloaderimage.

    I U-Boot: runs from RAM. Initializes some otherhardware devices (network, USB, etc.). Loads thekernel image from storage or network to RAMand starts it. Shell with commands provided. Filecalled u-boot.kwb.

    I Linux Kernel: runs from RAM. Takes over thesystem completely (bootloaders no longer exists).

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 100/540

  • Generic bootloaders for embedded CPUs

    I We will focus on the generic part, the main bootloader,offering the most important features.

    I There are several open-source generic bootloaders.Here are the most popular ones:

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

    I Barebox, a new architecture-neutral bootloader, written as asuccessor of U-Boot. Better design, better code, activedevelopment, but doesnt yet have as much hardware supportas U-Boot.http://www.barebox.org

    I There are also a lot of other open-source or proprietarybootloaders, often architecture-specific

    I RedBoot, Yaboot, PMON, etc.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 101/540

  • Bootloaders

    The U-boot bootloader

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 102/540

  • U-Boot

    U-Boot is a typical free software project

    I License: GPLv2 (same as Linux)

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

    I Documentation available athttp://www.denx.de/wiki/U-Boot/Documentation

    I The latest development source code is available in a Gitrepository:http://git.denx.de/?p=u-boot.git;a=summary

    I Development and discussions happen around an openmailing-list http://lists.denx.de/pipermail/u-boot/

    I Since the end of 2008, it follows a fixed-interval releaseschedule. Every three months, a new version is released.Versions are named YYYY.MM.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 103/540

  • U-Boot configuration

    I Get the source code from the website, and uncompress itI The include/configs/ directory contains one configuration

    file for each supported boardI It defines the CPU type, the peripherals and their

    configuration, the memory mapping, the U-Boot features thatshould be compiled in, etc.

    I It is a simple .h file that sets C pre-processor constants. Seethe README file for the documentation of these constants. Thisfile can also be adjusted to add or remove features fromU-Boot (commands, etc.).

    I Assuming that your board is already supported by U-Boot,there should be one entry corresponding to your board in theboards.cfg file.

    I Run ./tools/genboardscfg.py to generate it.I Or just look in the configs/ directory.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 104/540

  • U-Boot configuration file excerpt

    /* CPU configuration */

    #define CONFIG_ARMV7 1

    #define CONFIG_OMAP 1

    #define CONFIG_OMAP34XX 1

    #define CONFIG_OMAP3430 1

    #define CONFIG_OMAP3_IGEP0020 1

    [...]

    /* Memory configuration */

    #define CONFIG_NR_DRAM_BANKS 2

    #define PHYS_SDRAM_1 OMAP34XX_SDRC_CS0

    #define PHYS_SDRAM_1_SIZE (32

  • Configuring and compiling U-Boot

    I U-Boot must be configured before being compiledI make BOARDNAME_configI Where BOARDNAME is the name of the board, as visible in the

    boards.cfg file (first column).

    I Make sure that the cross-compiler is available in PATH

    I Compile U-Boot, by specifying the cross-compiler prefix.Example, if your cross-compiler executable is arm-linux-gcc:make CROSS_COMPILE=arm-linux-

    I The main result is a u-boot.bin file, which is the U-Bootimage. Depending on your specific platform, there may beother specialized images: u-boot.img, u-boot.kwb, MLO,etc.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 106/540

  • Installing U-Boot

    I U-Boot must usually be installed in flash memory to beexecuted by the hardware. Depending on the hardware, theinstallation of U-Boot is done in a different way:

    I The CPU provides some kind of specific boot monitor withwhich you can communicate through serial port or USB usinga specific protocol

    I The CPU boots first on removable media (MMC) beforebooting from fixed media (NAND). In this case, boot fromMMC to reflash a new version

    I U-Boot is already installed, and can be used to flash a newversion of U-Boot. However, be careful: if the new version ofU-Boot doesnt work, the board is unusable

    I The board provides a JTAG interface, which allows to write tothe flash memory remotely, without any system running on theboard. It also allows to rescue a board if the bootloaderdoesnt work.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 107/540

  • U-boot prompt

    I Connect the target to the host through a serial consoleI Power-up the board. On the serial console, you will see

    something like:

    U-Boot 2013.04 (May 29 2013 - 10:30:21)

    OMAP36XX/37XX-GP ES1.2, CPU-OPP2, L3-165MHz, Max CPU Clock 1 Ghz

    IGEPv2 + LPDDR/NAND

    I2C: ready

    DRAM: 512 MiB

    NAND: 512 MiB

    MMC: OMAP SD/MMC: 0

    Die ID #255000029ff800000168580212029011

    Net: smc911x-0

    U-Boot #

    I The U-Boot shell offers a set of commands. We will study themost important ones, see the documentation for a completereference or the help command.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 108/540

  • Information commands

    Flash information (NOR and SPI flash)

    U-Boot> flinfo

    DataFlash:AT45DB021

    Nb pages: 1024

    Page Size: 264

    Size= 270336 bytes

    Logical address: 0xC0000000

    Area 0: C0000000 to C0001FFF (RO) Bootstrap

    Area 1: C0002000 to C0003FFF Environment

    Area 2: C0004000 to C0041FFF (RO) U-Boot

    NAND flash information

    U-Boot> nand info

    Device 0: nand0, sector size 128 KiB

    Page size 2048 b

    OOB size 64 b

    Erase size 131072 b

    Version details

    U-Boot> version

    U-Boot 2013.04 (May 29 2013 - 10:30:21)

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 109/540

  • Important commands (1)

    I The exact set of commands depends on the U-Bootconfiguration

    I help and help command

    I boot, runs the default boot command, stored in bootcmd

    I bootm , starts a kernel image loaded at the givenaddress in RAM

    I ext2load, loads a file from an ext2 filesystem to RAMI And also ext2ls to list files, ext2info for information

    I fatload, loads a file from a FAT filesystem to RAMI And also fatls and fatinfo

    I tftp, loads a file from the network to RAM

    I ping, to test the network

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 110/540

  • Important commands (2)

    I loadb, loads, loady, load a file from the serial line to RAM

    I usb, to initialize and control the USB subsystem, mainly usedfor USB storage devices such as USB keys

    I mmc, to initialize and control the MMC subsystem, used forSD and microSD cards

    I nand, to erase, read and write contents to NAND flash

    I erase, protect, cp, to erase, modify protection and write toNOR flash

    I md, displays memory contents. Can be useful to check thecontents loaded in memory, or to look at hardware registers.

    I mm, modifies memory contents. Can be useful to modifydirectly hardware registers, for testing purposes.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 111/540

  • Environment variables commands (1)

    I U-Boot can be configured through environment variables,which affect the behavior of the different commands.

    I Environment variables are loaded from flash to RAM atU-Boot startup, can be modified and saved back to flash forpersistence

    I There is a dedicated location in flash (or in MMC storage) tostore the U-Boot environment, defined in the boardconfiguration file

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 112/540

  • Environment variables commands (2)

    Commands to manipulate environment variables:

    I printenvShows all variables

    I printenv Shows the value of a variable

    I setenv Changes the value of a variable, only in RAM

    I editenv Edits the value of a variable, only in RAM

    I saveenvSaves the current state of the environment to flash

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 113/540

  • Environment variables commands - Example

    u-boot # printenv

    baudrate=19200

    ethaddr=00:40:95:36:35:33

    netmask=255.255.255.0

    ipaddr=10.0.0.11

    serverip=10.0.0.1

    stdin=serial

    stdout=serial

    stderr=serial

    u-boot # printenv serverip

    serverip=10.0.0.1

    u-boot # setenv serverip 10.0.0.100

    u-boot # saveenv

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 114/540

  • Important U-Boot env variables

    I bootcmd, contains the command that U-Boot willautomatically execute at boot time after a configurable delay,if the process is not interrupted

    I bootargs, contains the arguments passed to the Linux kernel,covered later

    I serverip, the IP address of the server that U-Boot willcontact for network related commands

    I ipaddr, the IP address that U-Boot will use

    I netmask, the network mask to contact the server

    I ethaddr, the MAC address, can only be set once

    I bootdelay, the delay in seconds before which U-Boot runsbootcmd

    I autostart, if yes, U-Boot starts automatically an image thathas been loaded into memory

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 115/540

  • Scripts in environment variables

    I Environment variables can contain small scripts, to executeseveral commands and test the results of commands.

    I Useful to automate booting or upgrade processesI Several commands can be chained using the ; operatorI Tests can be done using

    if command ; then ... ; else ... ; fiI Scripts are executed using run I You can reference other variables using ${variable-name}

    I ExampleI setenv mmc-boot if fatload mmc 0 80000000 boot.

    ini; then source; else if fatload mmc 0 80000000

    uImage; then run mmc-bootargs; bootm; fi; fi

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 116/540

  • Transferring files to the target

    I U-Boot is mostly used to load and boot a kernel image, but italso allows to change the kernel image and the root filesystemstored in flash.

    I Files must be exchanged between the target and thedevelopment workstation. This is possible:

    I Through the network if the target has an Ethernet connection,and U-Boot contains a driver for the Ethernet chip. This is thefastest and most efficient solution.

    I Through a USB key, if U-Boot supports the USB controller ofyour platform

    I Through a SD or microSD card, if U-Boot supports the MMCcontroller of your platform

    I Through the serial port

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 117/540

  • TFTP

    I Network transfer from the development workstation to U-Booton the target takes place through TFTP

    I Trivial File Transfer ProtocolI Somewhat similar to FTP, but without authentication and over

    UDP

    I A TFTP server is needed on the development workstationI sudo apt-get install tftpd-hpaI All files in /var/lib/tftpboot are then visible through TFTPI A TFTP client is available in the tftp-hpa package, for

    testing

    I A TFTP client is integrated into U-BootI Configure the ipaddr and serverip environment variablesI Use tftp to load a file

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 118/540

  • U-boot mkimage

    I The kernel image that U-Boot loads and boots must beprepared, so that a U-Boot specific header is added in front ofthe image

    I This header gives details such as the image size, the expectedload address, the compression type, etc.

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

    I Debian / Ubuntu: just install the u-boot-tools package.

    I Or, compile it by yourself: simply configure U-Boot for anyboard of any architecture and compile it. Then installmkimage:cp tools/mkimage /usr/local/bin/

    I The special target uImage of the kernel Makefile can then beused to generate a kernel image suitable for U-Boot.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 119/540

  • Practical lab - U-Boot

    Time to start the practical lab!

    I Communicate with the board usinga serial console

    I Configure, build and install U-Boot

    I Learn U-Boot commands

    I Set up TFTP communication withthe board

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 120/540

  • Linux kernel introduction

    Linux kernelintroductionFree Electrons

    Copyright 2004-2015, Free Electrons.Creative Commons BY-SA 3.0 license.Corrections, suggestions, contributions and translations are welcome!

    Embedded LinuxDevelopers

    Free Electrons

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 121/540

  • Linux kernel introduction

    Linux features

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 122/540

  • History

    I The Linux kernel is one component of a system, which alsorequires libraries and applications to provide features to endusers.

    I The Linux kernel was created as a hobby in 1991 by a Finnishstudent, Linus Torvalds.

    I Linux quickly started to be used as the kernel for free softwareoperating systems

    I Linus Torvalds has been able to create a large and dynamicdeveloper and user community around Linux.

    I Nowadays, more than one thousand people contribute to eachkernel release, individuals or companies big and small.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 123/540

  • Linux kernel key features

    I Portability and hardwaresupport. Runs on mostarchitectures.

    I Scalability. Can run onsuper computers as well ason tiny devices (4 MB ofRAM is enough).

    I Compliance to standardsand interoperability.

    I Exhaustive networkingsupport.

    I Security. It cant hide itsflaws. Its code is reviewedby many experts.

    I Stability and reliability.

    I Modularity. Can includeonly what a system needseven at run time.

    I Easy to program. You canlearn from existing code.Many useful resources onthe net.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 124/540

  • Linux kernel in the system

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 125/540

  • Linux kernel main roles

    I Manage all the hardware resources: CPU, memory, I/O.

    I Provide a set of portable, architecture and hardwareindependent APIs to allow user space applications andlibraries to use the hardware resources.

    I Handle concurrent accesses and usage of hardwareresources from different applications.

    I Example: a single network interface is used by multiple userspace applications through various network connections. Thekernel is responsible to multiplex the hardware resource.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 126/540

  • System calls

    I The main interface between the kernel and user space is theset of system calls

    I About 300 system calls that provide the main kernel servicesI File and device operations, networking operations,

    inter-process communication, process management, memorymapping, timers, threads, synchronization primitives, etc.

    I This interface is stable over time: only new system calls canbe added by the kernel developers

    I This system call interface is wrapped by the C library, anduser space applications usually never make a system calldirectly but rather use the corresponding C library function

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 127/540

  • Pseudo filesystems

    I Linux makes system and kernel information available in userspace through pseudo filesystems, sometimes also calledvirtual filesystems

    I Pseudo filesystems allow applications to see directories andfiles that do not exist on any real storage: they are createdand updated on the fly by the kernel

    I The two most important pseudo filesystems areI proc, usually mounted on /proc:

    Operating system related information (processes, memorymanagement parameters...)

    I sysfs, usually mounted on /sys:Representation of the system as a set of devices and buses.Information about these devices.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 128/540

  • Inside the Linux kernel

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 129/540

  • Linux license

    I The whole Linux sources are Free Software released under theGNU General Public License version 2 (GPL v2).

    I For the Linux kernel, this basically implies that:I When you receive or buy a device with Linux on it, you should

    receive the Linux sources, with the right to study, modify andredistribute them.

    I When you produce Linux based devices, you must release thesources to the recipient, with the same rights, with norestriction.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 130/540

  • Supported hardware architectures

    I See the arch/ directory in the kernel sources

    I Minimum: 32 bit processors, with or without MMU, and gccsupport

    I 32 bit architectures (arch/ subdirectories)Examples: arm, avr32, blackfin, c6x, m68k, microblaze,mips, score, sparc, um

    I 64 bit architectures:Examples: alpha, arm64, ia64, tile

    I 32/64 bit architecturesExamples: powerpc, x86, sh, sparc

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

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 131/540

  • Linux kernel introduction

    Linux versioning scheme anddevelopment process

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 132/540

  • Until 2.6 (1)

    I One stable major branch every 2 or 3 yearsI Identified by an even middle numberI Examples: 1.0.x, 2.0.x, 2.2.x, 2.4.x

    I One development branch to integrate new functionalities andmajor changes

    I Identified by an odd middle numberI Examples: 2.1.x, 2.3.x, 2.5.xI After some time, a development version becomes the new base

    version for the stable branch

    I Minor releases once in while: 2.2.23, 2.5.12, etc.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 133/540

  • Until 2.6 (2)

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 134/540

  • Changes since Linux 2.6

    I Since 2.6.0, kernel developers have been able to introducelots of new features one by one on a steady pace, withouthaving to make disruptive changes to existing subsystems.

    I Since then, there has been no need to create a newdevelopment branch massively breaking compatibility with thestable branch.

    I Thanks to this, more features are released to users at afaster pace.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 135/540

  • 3.x stable branch

    I From 2003 to 2011, the official kernel versions were named2.6.x.

    I Linux 3.0 was released in July 2011I This is only a change to the numbering scheme

    I Official kernel versions are now named 3.x (3.0, 3.1, 3.2,etc.)

    I Stabilized versions are named 3.x.y (3.0.2, 3.4.3, etc.)I It effectively only removes a digit compared to the previous

    numbering scheme

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 136/540

  • New development model

    Using merge and bug fixing windows

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 137/540

  • New development model - Details

    I After the release of a 3.x version (for example), a two-weeksmerge window opens, during which major additions aremerged.

    I The merge window is closed by the release of test version3.(x+1)-rc1

    I The bug fixing period opens, for 6 to 10 weeks.

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

    I When considered sufficiently stable, kernel 3.(x+1) isreleased, and the process starts again.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 138/540

  • More stability for the kernel source tree

    I Issue: bug and security fixes only releasedfor most recent stable kernel versions.

    I Some people need to have a recent kernel,but with long term support for securityupdates.

    I You could get long term support from acommercial embedded Linux provider.

    I You could reuse sources for the kernelused in Ubuntu Long Term Supportreleases (5 years of free security updates).

    I The http://kernel.org front pageshows which versions will be supported forsome time (up to 2 or 3 years), and whichones wont be supported any more(EOL: End Of Life)

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 139/540

  • Whats new in each Linux release?

    I The official list of changes for each Linux release is just ahuge list of individual patches!commit aa6e52a35d388e730f4df0ec2ec48294590cc459Author: Thomas Petazzoni Date: Wed Jul 13 11:29:17 2011 +0200

    at91: at91-ohci: support overcurrent notification

    Several USB power switches (AIC1526 or MIC2026) have a digital outputthat is used to notify that an overcurrent situation is takingplace. This digital outputs are typically connected to GPIO inputs ofthe processor and can be used to be notified of these overcurrentsituations.

    Therefore, we add a new overcurrent_pin[] array in the at91_usbh_datastructure so that boards can tell the AT91 OHCI driver which pins areused for the overcurrent notification, and an overcurrent_supportedboolean to tell the driver whether overcurrent is supported or not.

    The code has been largely borrowed from ohci-da8xx.c andohci-s3c2410.c.

    Signed-off-by: Thomas Petazzoni Signed-off-by: Nicolas Ferre

    I Very difficult to find out the key changes and to get the globalpicture out of individual changes.

    I Fortunately, there are some useful resources availableI http://wiki.kernelnewbies.org/LinuxChangesI http://lwn.netI http://linuxfr.org, for French readers

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 140/540

  • Linux kernel introduction

    Linux kernel sources

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 141/540

  • Location of kernel sources

    I The official versions of the Linux kernel, as released by LinusTorvalds, are available at http://www.kernel.org

    I These versions follow the development model of the kernelI However, they may not contain the latest development from a

    specific area yet. Some features in development might not beready for mainline inclusion yet.

    I Many chip vendors supply their own kernel sourcesI Focusing on hardware support firstI Can have a very important delta with mainline LinuxI Useful only when mainline hasnt caught up yet.

    I Many kernel sub-communities maintain their own kernel, withusually newer but less stable features

    I Architecture communities (ARM, MIPS, PowerPC, etc.),device drivers communities (I2C, SPI, USB, PCI, network,etc.), other communities (real-time, etc.)

    I No official releases, only development trees are available.

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 142/540

  • Getting Linux sources

    I The kernel sources are available fromhttp://kernel.org/pub/linux/kernel as full tarballs(complete kernel sources) and patches (differences betweentwo kernel versions).

    I However, more and more people use the git version controlsystem. Absolutely needed for kernel development!

    I Fetch the entire kernel sources and historygit clone git://git.kernel.org/pub/scm/linux/

    kernel/git/torvalds/linux.gitI Create a branch that starts at a specific stable version

    git checkout -b v3.11I Web interface available at http://git.kernel.org/cgit/

    linux/kernel/git/torvalds/linux.git/tree/.I Read more about Git at http://git-scm.com/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 143/540

  • Linux kernel size (1)

    I Linux 3.10 sources:Raw size: 573 MB (43,000 files, approx 15,800,000 lines)gzip compressed tar archive: 105 MBbzip2 compressed tar archive: 83 MB (better)xz compressed tar archive: 69 MB (best)

    I Minimum Linux 3.17 compiled kernel size, booting on theARM Versatile board (hard drive on PCI, ext2 filesystem, ELFexecutable support, framebuffer console and input devices):876 KB (compressed), 2.3 MB (raw)

    I Why are these sources so big?Because they include thousands of device drivers, manynetwork protocols, support many architectures andfilesystems...

    I The Linux core (scheduler, memory management...) is prettysmall!

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 144/540

  • Linux kernel size (2)

    As of kernel version 3.10.

    I drivers/: 49.4%

    I arch/: 21.9%

    I fs/: 6.0%

    I include/: 4.7%

    I sound/: 4.4%

    I Documentation/: 4.0%

    I net/: 3.9%

    I firmware/: 1.0%

    I kernel/: 1.0%

    I tools/: 0.9%

    I scripts/: 0.5%

    I mm/: 0.5%

    I crypto/: 0.4%

    I security/: 0.4%

    I lib/: 0.4%

    I block/: 0.2%

    I ...

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 145/540

  • Getting Linux sources

    I Full tarballsI Contain the complete kernel sources: long to download and

    uncompress, but must be done at least onceI Example:

    http://www.kernel.org/pub/linux/kernel/v3.x/linux-

    3.10.9.tar.xz

    I Extract command:tar xf linux-3.10.9.tar.xz

    I Incremental patches between versionsI It assumes you already have a base version and you apply the

    correct patches in the right order. Quick to download andapply

    I Examples:http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.10.xz

    (3.9 to 3.10)http://www.kernel.org/pub/linux/kernel/v3.x/patch-3.10.9.xz

    (3.10 to 3.10.9)

    I All previous kernel versions are available inhttp://kernel.org/pub/linux/kernel/

    Free Electrons - Embedded Linux, kernel, drivers and Android - Development, consulting, training and support. http://free-electrons.com 146/540

  • Patch

    I A patch is the difference between two source treesI Computed with the diff tool, or with more elaborate version

    control systems

    I They are very common in the open-source community

    I Excerpt from a patch:

    diff -Nru a/Makefile b/Makefile

    --- a/Makefile 2005-03-04 09:27:15 -08:00

    +++ b/Makefile 2005-03-04 09:27:15 -08:00

    @@ -1,7 +1,7 @@

    VERSION = 2

    PATCHLEVEL = 6

    SUBLEVEL = 11

    -EXTRAVERSION =