Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Embedded Linux Quick Start Guide

2.638 visualizaciones

Publicado el

Are you thinking of using Linux on your next embedded project but not sure where to begin? This tutorial shows you how it is done. Beginning with a blank development board, you will learn how to bring up Linux and and get to a login prompt - all in half a day! The tutorial covers the four elements of embedded Linux on which every project depends: toolchain, bootloader, kernel and root filesystem. The theory is backed up with a hands-on session using a common development board: a BeagelBone Black.

Publicado en: Software
  • Sé el primero en comentar

Embedded Linux Quick Start Guide

  1. 1. Embedded Linux Quick Start Guide using Buildroot and BeagleBone Black 2net Ltd v1.4, May 2016 Embedded Linux Quick Start Guide 1 Copyright © 2011-2016, 2net Ltd
  2. 2. License These slides are available under a Creative Commons Attribution-ShareAlike 3.0 license. You can read the full text of the license here You are free to • copy, distribute, display, and perform the work • make derivative works • 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 (i.e. include this page exactly as it is) • For any reuse or distribution, you must make clear to others the license terms of this work Embedded Linux Quick Start Guide 2 Copyright © 2011-2016, 2net Ltd
  3. 3. About Chris Simmonds • Consultant and trainer • Author of Mastering Embedded Linux Programming • Working with embedded Linux since 1999 • Android since 2009 • Speaker at many conferences and workshops "Looking after the Inner Penguin" blog at Embedded Linux Quick Start Guide 3 Copyright © 2011-2016, 2net Ltd
  4. 4. Overview • This is a quick introduction to embedded Linux • It includes hands-on exercises that will take you from zero to command prompt in half a day • The target board is a BeagleBone Black • It uses Buildroot to generate the Linux distro Embedded Linux Quick Start Guide 4 Copyright © 2011-2016, 2net Ltd
  5. 5. Topics • Getting started with embedded Linux • The four elements • Booting and running the BeagleBone Black • Hands-on with the BeagleBone Black Embedded Linux Quick Start Guide 5 Copyright © 2011-2016, 2net Ltd
  6. 6. What is embedded Linux? • Embedded Linux = Linux running on embedded hardware • "Linux" in the broad sense: a Linux kernel plus other open source packages needed to make a working system • Hard to define: applications range from the small (light bulbs) to the large (aircraft AV systems) and beyond (large network switches) • ... from the trivial (light bulbs) to the critical (industrial plant; self-driving cars) • Linux is commonly used in mission critical applications, but not (yet) safely critical Embedded Linux Quick Start Guide 6 Copyright © 2011-2016, 2net Ltd
  7. 7. Driving factors • Moore’s law: complex hardware requires complex software • Free: you have the freedom to get and modify the code, making it easy to adapt and extend • Functional: supports a (very) wide range of hardware • Up to date: the kernel has a three month release cycle • Free: there is no charge for using the source code Embedded Linux Quick Start Guide 7 Copyright © 2011-2016, 2net Ltd
  8. 8. Open source ecosystem The main players are: • Open source community • A loose alliance of developers, working on 1000’s of individual projects, some funded by companies with a commercial interest • SoC vendors • Customise upstream code (e.g. Linux kernel, toolchain) to ensure it works well on their platforms • SBC and SoM vendors: further customisation • Commercial embedded Linux vendors: offer support and services Embedded Linux Quick Start Guide 8 Copyright © 2011-2016, 2net Ltd
  9. 9. Pain points • Lack of support for your particular hardware (always check with the manufacturer before you design a component in) • Lack of knowledge (that’s why I am here) • Underestimating the task Embedded Linux Quick Start Guide 9 Copyright © 2011-2016, 2net Ltd
  10. 10. The four elements Embedded Linux Quick Start Guide 10 Copyright © 2011-2016, 2net Ltd
  11. 11. Overview Every embedded Linux project has these elements: • Toolchain: to compile the other elements • Bootloader: to initialise the board and load the kernel • Kernel: to manage system resources • Root filesystem: to run applications Embedded Linux Quick Start Guide 11 Copyright © 2011-2016, 2net Ltd
  12. 12. Element 1: Toolchain • Toolchain = GNU GCC + C library + GNU GDB • LLVM/Clang is also an option, but not quite mainstream yet • Native toolchain • Install and develop on the target • Cross toolchain • Build on development system, deploy on target • Keeps target and development environments separate • Cross toolchains are the most common Embedded Linux Quick Start Guide 12 Copyright © 2011-2016, 2net Ltd
  13. 13. Choosing a C library • The C library is the interface between user space and kernel • Three options Library Notes GNU glibc Big, good support for POSIX and extensions uClibc Small: a good choice for memory-constrained systems musl libc Small: an alternative to uClibc. BSD license Embedded Linux Quick Start Guide 13 Copyright © 2011-2016, 2net Ltd
  14. 14. Getting a toolchain • You can: • Build from upstream source, e.g. using CrosstoolNG • Download from a trusted third party, e.g. Linaro for ARM devices • Use the one provided by your SoC/board vendor (check quality first) • Use an embedded build system to generate one • We will be using an embedded build system (Buildroot) Embedded Linux Quick Start Guide 14 Copyright © 2011-2016, 2net Ltd
  15. 15. Element 2: Bootloader • Tasks • Initialise board • Load kernel • Maintenance tasks, e.g. flash system images • Open source bootloaders • Das U-Boot • Barebox • GRUB 2 (for X86 and X86_64) Embedded Linux Quick Start Guide 15 Copyright © 2011-2016, 2net Ltd
  16. 16. Das U-Boot • Open source, GPL license • Small run-time binary (50 - 800 KiB) • Supports many CPU architectures, incl. ARM, MIPS, PowerPC, SH • ... and many boards (> 1000) • Reasonably easy to port to a new board Embedded Linux Quick Start Guide 16 Copyright © 2011-2016, 2net Ltd
  17. 17. U-Boot command-line Load a kernel image into memory from... • NAND flash Uboot# nand read 80100000 1000000 200000 • eMMC or SD card UBoot# mmc rescan 1 UBoot# fatload mmc 1:1 80100000 zimage • TFTP server UBoot# setenv ipaddr UBoot# setenv serverip UBoot# tftp 80100000 zImage • Boot a kernel image (already loaded into memory) UBoot# bootz 80100000 Embedded Linux Quick Start Guide 17 Copyright © 2011-2016, 2net Ltd
  18. 18. U-Boot environment • Contains parameters, e.g. ipaddr and serverip from previous slide • Parameters can be created or modified at run-time using setenv • Default set is hard-coded in U-Boot • At boot, additional parameters may be read from: • Dedicated area of flash memory • A file named boot.scr • A file named uEnv.txt Embedded Linux Quick Start Guide 18 Copyright © 2011-2016, 2net Ltd
  19. 19. Element 3: Kernel • Tasks • Manage system resources: CPU, memory, I/O • Interface with hardware via device drivers • Provide a (mostly) hardware-independent API • Rapid development cycle: new version every 12 weeks Embedded Linux Quick Start Guide 19 Copyright © 2011-2016, 2net Ltd
  20. 20. Kernel versions Up to May 2011 From July 2011 From April 2015 3.0.1 4.0.1 Release number: changes every 12 weeks or so Bug fix number: changes every time a bug is fixed Embedded Linux Quick Start Guide 20 Copyright © 2011-2016, 2net Ltd
  21. 21. Mainline, stable and longterm • Mainline: Linus Torvald’s development tree • Stable: bug fixes to the previous mainline release • Longterm: selected versions that are supported for >= 2 years • 4.4 • 4.1 • 3.18 • 3.14 • 3.12 • 3.10 • 3.4 Embedded Linux Quick Start Guide 21 Copyright © 2011-2016, 2net Ltd
  22. 22. Vendor kernels • Mainline Linux has good support for x86/x86_64 • SoC vendors take mainline Linux and customise to support their chips • Vendor kernels lag behind mainline • Vendors don’t take every mainline release: typically only one per year • Most vendors are not very good at pushing their changes into mainline • Most of the time you will be not be working with mainline Linux Embedded Linux Quick Start Guide 22 Copyright © 2011-2016, 2net Ltd
  23. 23. Digression: device trees • The kernel needs to know details about hardware • To decide which drivers to initialise • To configure device parameters such as register addresses and IRQ • Sources of information: • Firmware ACPI tables (x86 and ARM server) • Bus enumeration, e.g. PCI • Hard coded structures • Device tree (ARM, PPC, MIPS, some x86) Embedded Linux Quick Start Guide 23 Copyright © 2011-2016, 2net Ltd
  24. 24. Device Tree • Open Firmware specification, IEEE-1275-1994 • Description of hardware (contains no code) • Tree of nodes, containing attributes, for example: /dts-v1/; /{ model = "TI AM335x BeagleBone"; compatible = "ti,am33xx"; #address-cells = <1>; #size-cells = <1>; memory@0x80000000 { device_type = "memory"; reg = <0x80000000 0x20000000>; /* 512 MB */ }; [...] Embedded Linux Quick Start Guide 24 Copyright © 2011-2016, 2net Ltd
  25. 25. Compiling the device tree • .dts source files are in arch/<ARCH>/boot/dts • compiled to .dtb, using dtc • dtb file is loaded into memory by the bootloader • The U-boot bootz command takes three arguments bootz <kernel> <ramdisk> <dt binary> • If there is no ramdisk (which is common) bootz <kernel> - <dt binary> Embedded Linux Quick Start Guide 25 Copyright © 2011-2016, 2net Ltd
  26. 26. Element 4: Root filesystem • The kernel contains no applications: these are in the root filesystem • The last stage of kernel boot is to launch the first program: /sbin/init • init runs a number of scripts that start up the rest of the system Embedded Linux Quick Start Guide 26 Copyright © 2011-2016, 2net Ltd
  27. 27. Root filesystem layout • Linux file layout is defined in Filesystem Hierarchy Standard (FHS) Directory Notes /bin Programs /dev Device nodes /etc Configuration /lib Dynamically-loaded libraries /sbin Binaries for superuser /tmp Temporary files /usr Additional binaries and libraries /var Non-volatile data Embedded Linux Quick Start Guide 27 Copyright © 2011-2016, 2net Ltd
  28. 28. Embedded build systems • Building the four elements by hand is time consuming • Embedded build systems make it easy Tool Notes buildroot Small, menu-driven OpenWrt A variant of Buildroot for network devices OpenEmbedded General purpose Tizen Good for mobile and automotive Yocto Project General purpose, wide industry support, complex Embedded Linux Quick Start Guide 28 Copyright © 2011-2016, 2net Ltd
  29. 29. Buildroot • Simple and fast: ideal for small embedded projects • Has configurations for c. 100 dev boards • Has c. 1000 packages • incl. network tools, databases, Qt5 graphics Embedded Linux Quick Start Guide 29 Copyright © 2011-2016, 2net Ltd
  30. 30. Buildroot Embedded Linux Quick Start Guide 30 Copyright © 2011-2016, 2net Ltd
  31. 31. Directories • Upstream source -> dl/ • Build artifacts -> output/ • output/ contains Directory Notes build Working directory for compiling source host Tools that run on the host, incl. toolchain images bootloader, kernel and root filesystem for the target staging Link to the sysroot of the toolchain target Staging area for target root filesystem Embedded Linux Quick Start Guide 31 Copyright © 2011-2016, 2net Ltd
  32. 32. The BeagleBone Black Embedded Linux Quick Start Guide 32 Copyright © 2011-2016, 2net Ltd
  33. 33. The BeagleBone Black • Open source hardware design from • Low cost ($55) • Extensible via stackable daughter boards, called capes Embedded Linux Quick Start Guide 33 Copyright © 2011-2016, 2net Ltd
  34. 34. Features • TI AM335x 1GHz Cortex-A8 SoC • Imagination Tech. PowerVR SGX530 GPU • 512 MiB DDR3 RAM • 2 or 4 GiB 8-bit eMMC on-board flash storage • MicroSD card slot for external storage • Mini USB OTG port, also provides power • Full size USB 2.0 host • 10/100 Ethernet • Mini HDMI connector Embedded Linux Quick Start Guide 34 Copyright © 2011-2016, 2net Ltd
  35. 35. Memory map 0x0000_0000 1 GiB memory-mapped peripherals 512 MiB DDR3 RAM 0x8000_0000 0xA000_0000 0xFFFF_FFFF 0x4000_0000 Embedded Linux Quick Start Guide 35 Copyright © 2011-2016, 2net Ltd
  36. 36. Storage • MMC0: External microSD (4-bit) • MMC1: 2/4 GiB internal eMMC (8-bit) Embedded Linux Quick Start Guide 36 Copyright © 2011-2016, 2net Ltd
  37. 37. Switches Power Reset Boot Embedded Linux Quick Start Guide 37 Copyright © 2011-2016, 2net Ltd
  38. 38. Boot sequence • Default: • boot from internal eMMC • If boot switch is pressed while power is applied: • Try to boot from microSD card • If no SD card present, try to load an image via USB port, followed by serial port Embedded Linux Quick Start Guide 38 Copyright © 2011-2016, 2net Ltd
  39. 39. Boot files When booting from MMC (eMMC or SD): • The first partition is mounted • Must be FAT32 (vfat) format • Must have boot flag set • Load and execute 1st stage boot in MLO • Load and execute 2nd stage boot in u-boot.img • U-Boot loads • Linux kernel: zImage • Device tree binary: am335x-boneblack.dtb • U-Boot starts Linux Embedded Linux Quick Start Guide 39 Copyright © 2011-2016, 2net Ltd
  40. 40. LEDs usr 0 usr 1 usr 2 usr 3 Embedded Linux Quick Start Guide 40 Copyright © 2011-2016, 2net Ltd
  41. 41. Conclusion Embedded Linux Quick Start Guide 41 Copyright © 2011-2016, 2net Ltd
  42. 42. The story so far • We have investigated the four elements of embedded Linux: • Toolchain • Bootloder • Kernel • Root filesystem • We used Buildroot to create these elements • We tried it out using a BeagleBone Black target Embedded Linux Quick Start Guide 42 Copyright © 2011-2016, 2net Ltd
  43. 43. Delving deeper • This is an excerpt from my Fast track to embedded Linux class • If you would like to discover more about the power of embedded Linux, visit and enquire about training classes for your company • 2net training is available world-wide • Also, my book, Mastering Embedded Linux Programming, covers the topics discused here in much greater detail Embedded Linux Quick Start Guide 43 Copyright © 2011-2016, 2net Ltd
  44. 44. Lab Time to do the lab! The instructions are in the workbook embedded-linux-quick-start-workbook.pdf Embedded Linux Quick Start Guide 44 Copyright © 2011-2016, 2net Ltd