Create a Custom Embedded Linux Distribu3on for Any Embedded Device Using the Yocto Project Chris Hallinan Mentor Graphics October 16, 2014 Yocto Project Developer Day – Oct 2014 1 Yocto Project Developer Day 2014 Intro to Yocto Project It's not an embedded Linux distribu2on – It creates a custom one for you
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Create a Custom Embedded Linux Distribu3on for Any Embedded Device Using the Yocto Project
Chris Hallinan Mentor Graphics
October 16, 2014
Yocto Project Developer Day – Oct 2014 1
Yocto Project Developer Day 2014 Intro to Yocto Project
It's not an embedded Linux distribu2on – It creates a custom one for you
Agenda!! Introduc3on to the Yocto Project ! Key Concepts
" Build System Overview & Workflow " Exercise 1: Exploring the Host System
! Building and Boo3ng an Image " Exercise 3: Building Your First Linux Image " Exercise 4: BooNng Your Linux Image Using QEMU
! Layers and BSPs " Exercise 5: CreaNng a Custom Layer " Exercise 6-‐7: Adding a graphical boot logo and SSH server " Exercise 8-‐9: BooNng an embedded hardware board
Yocto Project Developer Day – Oct 2014 2
Yocto Project Overview!! Collec3on of tools and methods enabling
" Rapid evaluaNon of embedded Linux on many popular off-‐the-‐shelf boards
" Easy customizaNon of distribuNon characterisNcs
! Supports x86, ARM, MIPS, Power
! Based on technology from OpenEmbedded Project
! Layer architecture allows for easy re-‐use of code
Yocto Project Developer Day – Oct 2014 3
oe-‐core (meta)
meta-‐yocto-‐bsp
meta-‐yocto
other layers
Yocto Project Overview!! Supports use of popular package formats including: " rpm, deb, ipk
! Releases on a 6-‐month cadence
! Latest (stable) kernel, toolchain and packages, documenta3on
! App Development Tools including Eclipse plugin, ADT, hob
Yocto Project Developer Day – Oct 2014 4
Yocto Project Overview!! Governance
" Organized under the Linux FoundaNon
" Split governance model " Technical Leadership Team " Advisory Board made up of parNcipaNng organizaNons
Yocto Project Developer Day – Oct 2014 5
Yocto Project Release Versions!! Major Version Releases
Yocto Project Developer Day – Oct 2014 6
Name Revision Poky Release Date
Bernard 1.0 5.0 Apr 5, 2011
Edison 1.1 6.0 Oct 17, 2011
Denzil 1.2 7.0 Apr 30, 2012
Danny 1.3 8.0 Oct 24, 2012
Dylan 1.4 9.0 Apr 26, 2013
Dora 1.5 10.0 Oct 19, 2013
Daisy 1.6 11.0 Apr 24, 2014
(unnamed) 1.7 12.0 Oct 31, 2014 (planned)
Intro to OpenEmbedded!! Bitbake
" Powerful and flexible build engine
" Determines dependencies and schedules tasks
7
Metadata – a structured collecNon of "recipes" which tell BitBake what to build
Yocto is based on openembedded-core!
8
Metadata describing approximately 900 popular "core" recipes used for building boot images. Includes support for graphics, Qt, networking, kernel recipes, tools, much more.
oe-‐core (meta)
meta-‐yocto-‐bsp
meta-‐yocto
Other layers
OK, so what is Poky?!! Poky is both a reference distribu3on and a build system
! Poky has its own git repo " git clone git://git.yoctoproject.org/poky
! Primary poky layers " oe-‐core (poky/meta)
" meta-‐yocto-‐bsp " meta-‐yocto
! Poky is the basis of YP
Yocto Project Developer Day – Oct 2014 9
What is Metadata?
10
• Metadata exists in four general categories: • Recipes (*.bb)
– Usually describe build instrucNons for a single package • PackageGroups (special *.bb)
– Oeen used to group packages together for a FS image
• Classes (*.bbclass) – Inheritance mechanism for common funcNonality
• Configura3on(*.conf) – Drives the overall behavior of the build process
• Most common form of metadata – The Recipe • Provides the “list of ingredients” and “cooking instruc3ons” to build a package(s)
• Has a common set of tasks… busybox
glibc
sysvinit
inetutils
mtdutils
Metadata
BitBake
Recipe Basics!! A recipe is a set of instruc3ons for building packages, including: " Where to obtain the upstream sources and which patches to apply o SRC_URI!
" Dependencies (on libraries or other recipes) o DEPENDS, RDEPENDS!
" ConfiguraNon/compilaNon opNons o EXTRA_OECONF, EXTRA_OEMAKE!
" Define which files go into what output packages o FILES_*!
Yocto Project Developer Day – Oct 2014 13
Example Recipe – ethtool_3.15.bb"
Yocto Project Developer Day – Oct 2014 14
Example Recipe – ethtool_3.15.bb"
Yocto Project Developer Day – Oct 2014 15
Example Recipe – ethtool_3.15.bb"
Yocto Project Developer Day – Oct 2014 16
Example Recipe – ethtool_3.15.bb"
Yocto Project Developer Day – Oct 2014 17
Recipe Basics – Default Tasks*
18
• If a cache object exists and is valid, use it
• Locate and download source code
• Unpack source into working directory
• Apply any patches
• Perform any necessary pre-‐build configura3on
• Compile the source code
• Installa3on of resul3ng build ar3facts
• Create binary package(s)
do_setscene!
do_fetch!
do_unpack!
do_patch!
do_configure!
do_install!
do_compile!
*Simplified for illustration
do_package!
Note: to see the list of all possible tasks for a recipe, do this: $ bitbake -c listtasks <recipe_name>!
Quick Start Guide in a Slide!! Download Yocto Project sources:
o MACHINE = "wandboard-‐quad" in local.conf o Modify DL_DIR and SSTATE_DIR o ACCEPT_FSL_EULA = "1"
! Bitbake image " core-‐image-‐base
! Copy sdcard image and boot (details in Ex. 4) " Use SD slot on cpu module on bokom of board
Yocto Project Developer Day – Oct 2014 32
WandBoard Build - Detailed!! Sources are already downloaded for you ! Create project directory, edit local.conf and bblayers.conf
$ cd /scratch/working!$ . /scratch/yocto/sources/poky/oe-init-build-env build-wbquad!$ vi conf/local.conf!
o Modify MACHINE = "wandboard-quad"!o Modify DL_DIR = "/scratch/yocto/downloads"!o Modify SSTATE_DIR = "/scratch/yocto/sstate-cache"!o ACCEPT_FSL_EULA = "1" (bokom of file is good locaNon for this)
! Now unplug and replug your SD Card for automount $ cd <path-to-your-binary-images> $ sudo cp -v MLO-beaglebone /media/boot/MLO $ sudo cp -v u-boot.img /media/boot/ $ sudo tar xf core-image-base-beaglebone.tar.bz2 -C /media/rootfs $ sync (flush to device, not neccesary, but illustrative) $ umount /media/rootfs /media/boot
Yocto Project Developer Day – Oct 2014 40
Beaglebone Black Boot - Detailed!
! Copy sdcard image and boot " Use SD slot on cpu module on bokom of board
! For convenience, we will only replace the root file system
! On your laptop Linux, insert your microSD: " $ scp -‐P <port> ilab01@devdayN:/scratch/working/build-‐beaglebone/tmp/deploy/images/beaglebone/core-‐image-‐base-‐beagleboard.tar.bz2 .
! Note: Due to the size of the HDD Image, we offer two op3ons for upda3ng the image on your board. Chose only one of the following: " Copy the enNre image (.hddimg) to the microSD or USB flash drive, creaNng a brand new image
" Update only the roops image (much smaller download from cloud)
Yocto Project Developer Day – Oct 2014 42
Minnowboard Max Boot – Detailed (2)!
! To build a brand new microSD or USB Flash drive image: " Download the .hddimg from your cloud-‐based host: o $ scp -P <port> [email protected]:/scratch/working/build-minnowmx/tmp/deploy/images/intel-corei7-64/core-image-base-intel-corei7-64.hddimg .
" On your laptop Linux, insert your microSD or USB flash drive: $ umount /media/boot!
!$ dd if=core-image-base-intel-corei7-64.hddimg of=/dev/sd(n) <<<replace with proper dev
Yocto Project Developer Day – Oct 2014 43
Minnowboard Max Boot – Detailed (3)!
! To replace only the root file system image, do the following:
! On your laptop Linux, insert your usb flash drive or microSD: $ scp -P <port> [email protected]:/scratch/working/build-minnowmx/tmp/deploy/images/intel-corei7-64/core-image-base-intel-corei7-64.ext3 . !
Obviously, you'll need to verify your SD card device node
WandBoard Boot - Detailed!! For convenience, we will only replace the root file system on a pre-‐populated SD Card
! On your laptop Linux, insert your microSD
! It should auto-‐mount. If it doesn't this won't work $ scp -P <port> [email protected]:/scratch/working/build-wbquad/tmp/deploy/images/wandboard-quad/core-image-base-wandboard-quad.tar.bz2 .
$ sudo rm -rf /media/rootfs/*
$ sudo tar xf core-image-base.tar.bz2 -C /media/rootfs
$ umount /media/rootfs
Yocto Project Developer Day – Oct 2014 47
A Detailed Look at Layers!! Introduc3on to Layers
! Stacking Customiza3ons
! Adding Layers
! Board Support Packages
Yocto Project Developer Day – Oct 2014 48
oe-‐core (poky/meta)
meta-‐yocto-‐bsp
meta-‐yocto
UI layers
Commercial Layers
Developer Layers
Patch Layers
Layers!! The Yocto Project build system is composed of layers " A layer is a logical collecNon of recipes represenNng the core, a BSP, an applicaNon stack, patches, or other funcNonality.
! All layers have a priority and can override policy and config semngs of the layers of lower priority
Yocto Project Developer Day – Oct 2014 49
Layer Hierarchy"
Yocto Project Developer Day – Oct 2014 50
oe-‐core (poky/meta)
meta-‐yocto-‐bsp
meta-‐yocto
UI layers
Commercial Layers
Developer Layers
Patch Layers
Using Layers!! Layers are added to your build by inser3ng them into the global BBLAYERS variable within your …/conf/bblayers.conf file:
Board Support Packages!! BSPs are layers to enable support for specific hardware planorms
! Defines machine configura3on for the board
! Adds machine-‐specific recipes and customiza3ons " Kernel config
" Graphics drivers (e.g, Xorg) " AddiNonal recipes to support hardware features
Yocto Project Developer Day – Oct 2014 52
Exercise 5: Create a Custom Layer!
! When doing development with Yocto, never edit files within the Yocto/Poky source tree " Use a custom layer for modularity and maintainability
! Create custom layers to hold a custom image recipe
! Let's call this layer meta-‐ypdd ! This layer must include:
" Meta-ypdd/conf/layer.conf " Recipes directory (meta-ypdd/recipes-core/) " A meta-‐ypdd/README file (basic documentaNon for the layer, including maintainer info)
Yocto Project Developer Day – Oct 2014 53
Exercise 5: Create a Custom Layer!
! Yocto includes a helper script to create a new layer
! It can also supply an example recipe or bbappends file " $ yocto-layer <new-layer>!
! For this exercise, a layer is already provided " /scratch/sandbox/meta-ypdd!
Yocto Project Developer Day – Oct 2014 54
meta-ypdd/conf/layer.conf!
Yocto Project Developer Day – Oct 2014 55
Must match layer name in three places
Exercise 5: Custom Layer!! Add this new layer to your project's bblayer.conf file " Note that this layer is already provided on your VM $ vi …/conf/bblayers.conf!$ BBLAYERS ?= " \! /scratch/sandbox/meta-ypdd \!! !…!