Yocto: Training in English


Published on

Published in: Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Yocto: Training in English

  1. 1. Yocto: Your Next Development Platform for Embedded Linux Otavio Salvador Chief Technical Officer Mario Goulart Developer
  2. 2. About O.S. SystemsAbout O.S. Systems ● Brazilian Company, founded in 2002 ● Uses Yocto/OpenEmbedded since 2008 ● Actively contributes to the development of Yocto and many other open source projects ● Customers and partners in Brazil and around the world
  3. 3. O.S. Systems' work areasO.S. Systems' work areas ● Operating systems customization ● Expertise in development based on the Linux kernel ● Consultancy services in several areas ● Development/customization of BSPs ● Migration of build systems to Yocto ● ...
  4. 4. Using the training virtual machineUsing the training virtual machine ● Before booting the VM up – The VM is configured to use 3 cores and 3GB of RAM. If your system doesn't have at least 4 cores and 6GB of RAM, you'll may want to change the VM settings before booting it up. ● After booting the VM – User: yocto – Password: yocto – Click the “Warm up” icon
  5. 5. YoctoYocto ● Linux-based cross-compilation framework ● Open source (but can be used to build proprietarry code) ● Used by many players in the embedded industry, for several architectures (ARM, PPC, MIPS etc)
  6. 6. What Yocto doesWhat Yocto does ● Source code download ● Patch application ● Cross compilation ● Package management
  7. 7. What Yocto generatesWhat Yocto generates ● Binary packages ● Linux-based system images ● Toolchains ● SDKs (Software Development Kits)
  8. 8. HistoryHistory
  9. 9. Advantages in using YoctoAdvantages in using Yocto ● Detailed control over the final product – Possibility of compile-time software configuration ● Easy migration to different hardware platforms – Exemple: migrating a whole x86 image to ARM is trivial ● Huge amount of available software – Thousands of packages available ● Extensible – Adding packages is easy ● Large community of developers – Active development, with participation of members of big players of the embedded industry ● Highly performant – Possibility of parallelization of build tasks
  10. 10. ComponentsComponents ● BitBake: tasks scheduler and executor ● Metadata: – Configuration (.conf): global definition of variables – Classes (.bbclass): inheritance and encapsulation of build logic, packaging etc. – Recipes (.bb): instructions about how to build software and images ● Poky: build system Poky = BitBake + Metadata
  11. 11. PackagesPackages ● Set of files generated by the build system, packaged into some popular archiving format ● Exemples of package types: – .ipk – .deb – .rpm – .tar{.gz,.bz2}
  12. 12. RecipesRecipes ● Set of instructions about how to build software, including (but not limited to): – source code location specification – patches to apply – dependencies – build-time configuration options – how to split files into packages ● May inherit behavior from classes (.bbclass) and/or include files containing common definitions (.inc) ● Support recipe code in shell script, Python and in a custom configuration language
  13. 13. TasksTasks ● Tasks to be executed by the build system ● Specified in classes and/or recipes ● Scheduled by BitBake ● Examples of standard tasks: do_fetch, do_unpack, do_configure, do_compile, do_package
  14. 14. LayersLayers ● Set of recipes, classes, configuration files that can be added to the build system to extend it ● A BSP (Board Support Package) can be implemented as a layer ● Examples of layers: meta-fsl-arm, meta-fsl-demos, meta-fsl-arm-extras, meta-java, meta-browser
  15. 15. Recipe exampleRecipe example DESCRIPTION = "BSD replacement for libreadline" HOMEPAGE = "http://www.thrysoee.dk/editline/" SECTION = "libs" LICENSE = "BSD" LIC_FILES_CHKSUM = "file://COPYING;md5=1e4228d0c5a9093b01aeaaeae6641533" DEPENDS = "ncurses" inherit autotools SRC_URI = "http://www.thrysoee.dk/editline/${PN}-${PV}-3.0.tar.gz" S = "${WORKDIR}/${PN}-${PV}-3.0" SRC_URI[md5sum] = "e50f6a7afb4de00c81650f7b1a0f5aea" SRC_URI[sha256sum] = "51f0f4b4a97b7ebab26e7b5c2564c47628cdb3042fd8ba8d0605c719d2541918"
  16. 16. BitBakeBitBake ● Command line tool made in Python ● Processes recipes ● Runs and manages tasks ● bitbake -h
  17. 17. Frequent uses of BitBakeFrequent uses of BitBake ● bitbake <recipe> – Processes all tasks for the given recipe. <recipe> is the name of any recipe available in any of the available layers (e.g., samba) ● bitbake -c cleansstate <recipe> – Cleans up all the tasks state with regard to the given <recipe>. This option is frequently used during the development of new recipes ● bitbake -e – Displays the internal state of variables used by BitBake
  18. 18. Generating an imageGenerating an image $ cd ~/src/fsl-community-bsp $ MACHINE=wandboard-dual source setup-environment build $ bitbake core-image-minimal In this case, core-image-minimal is a recipe that produces an image, not only packages (packages are also generated, but for being dependencies.)
  19. 19. Exploring Yocto's root directoryExploring Yocto's root directory ● ~/src/fsl-community-bsp: – build: directory created by the build system to store files generated during the build process – sources: layers' metadata – downloads: source files to be used by the build system
  20. 20. Exploring Yocto's build directoryExploring Yocto's build directory (build)(build) ● ~/src/fsl-community-bsp/build: – cache: directory where cache data used by BitBake is stored – conf: directory where the main configuration files (local.conf and bblayers.conf) are stored – sstate-cache: directory where previously generated packages are stored, so that they can be reused without rebuilding – tmp: temporary directory for the build system. This directory is used to store files that are produced by the build system: toolchains, binary files for the target platform, images etc.
  21. 21. Exploring Yocto's configurationExploring Yocto's configuration directory (build/conf)directory (build/conf) ● ~/src/fsl-community-bsp/build/conf – Main files: local.conf and bblayers.conf ● Some variables: – MACHINE: target machine specification – DISTRO: distribution to build – BBLAYERS: path layers directories – BB_NUMBER_THREADS: number of BitBake threads to run in parallel – PARALLEL_MAKE: number of make threads to run in parallel (-j) ●
  22. 22. Explorando Yocto's temporary directoryExplorando Yocto's temporary directory (build/tmp)(build/tmp) ● ~/src/fsl-community-bsp/build/tmp ● Some directories in it: – deploy: build products: images, packages, SDKs – sysroots: shared libraries and headers that can be reused along the process of building recipes. Files in this directory are organized by architecture. – work: work directory used to actually build recipes
  23. 23. Exploring Yocto's work directoryExploring Yocto's work directory (build/tmp/work)(build/tmp/work) ● ~/src/fsl-community-bsp/build/tmp/work ● One of the main directories to be exaplored when debugging ● In this directory: – source code for the software to be compiled is extracted – the tasks' configuration and execution logs are stored – the content of generated packages is stored – etc.
  24. 24. Structure of the build/tmp/workStructure of the build/tmp/work directorydirectory <arch>/<recipe name>/<software version>/ ● Some directories under this tree: – temp: tasks' configuration and execution logs – packages: content of packages, extracted – packages-split: content of packages, extracted and split – <sources>: extracted source code of the software to be built
  25. 25. BuildhistoryBuildhistory ● Log system that keeps track of what was generated during the build (packages and images) ● Useful to show differences between, for example, two image versions ● Git-based
  26. 26. Activating buildhistoryActivating buildhistory ● Edit the file ~/src/fsl-community-bsp/build/conf/local.conf and add: INHERIT += "buildhistory" BUILDHISTORY_COMMIT = "1" ● You'll need to rerun BitBake to populate the buildhistory directory
  27. 27. Adding layersAdding layers ● To add a layer, you basically need to add its path to the BBLAYERS variable, which is in the $BUILDDIR/conf/bblayers.conf file
  28. 28. Anatomy of a layerAnatomy of a layer ● Layers usually follow a structure like: – <layer dir>/classes – <layer dir>/conf – <layer dir>/recipes-<category1> – <layer dir>/recipes-<category...> where <layer dir> is usually the layer name (e.g., meta-fsl-arm)
  29. 29. Anatomy of a layer (conf)Anatomy of a layer (conf) ● <layer dir>/conf must provide at least the layer configuration file: layer.conf, which can be used to configure layer-related variables. ● Configuration examples: – Where recipes can be found in the layer – Layer priority
  30. 30. Anatomy of a layer (layer.conf)Anatomy of a layer (layer.conf) # We have a conf and classes directory, add to BBPATH BBPATH .= ":${LAYERDIR}" # We have a packages directory, add to BBFILES BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend" BBFILE_COLLECTIONS += "fsl-arm" BBFILE_PATTERN_fsl-arm := "^${LAYERDIR}/" BBFILE_PRIORITY_fsl-arm = "5" FSL_EULA_FILE = "${LAYERDIR}/EULA" FSL_MIRROR ?= "http://www.freescale.com/lgfiles/NMG/MAD/YOCTO/" MIRRORS += " ${FSL_MIRROR} http://download.ossystems.com.br/bsp/freescale/source/ n " # Let us add layer-specific bbappends which are only applied when that # layer is included in our configuration BBFILES += "${@' '.join('${LAYERDIR}/%s/recipes*/*/*.bbappend' % layer for layer in BBFILE_COLLECTIONS.split())}"
  31. 31. Anatomy of a layer (conf/machine)Anatomy of a layer (conf/machine) ● The <layer dir>/conf/machine contains machine description files, usually used to configure variables related to the target machine (e.f., imx23evk.conf) ● This directory is optional, but it usually is present in layers that implement BSPs ● The file names in this directory (without extension) are used as value to the MACHINE variable in $BUILDDIR/conf/local.conf
  32. 32. Anatomy of a layerAnatomy of a layer (conf/machines/imx23evk.conf)(conf/machines/imx23evk.conf) #@TYPE: Machine #@NAME: Freescale i.MX23 Evaluation Kit #@SOC: i.MX23 #@DESCRIPTION: Machine configuration for Freescale i.MX23 Evaluation Kit include conf/machine/include/mxs-base.inc SOC_FAMILY = "mxs:mx23" IMXBOOTLETS_MACHINE = "stmp378x_dev" UBOOT_MACHINE = "mx23evk_config" KERNEL_IMAGETYPE = "uImage" KERNEL_DEVICETREE = "${S}/arch/arm/boot/dts/imx23-evk.dts" SDCARD_ROOTFS ?= "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3" IMAGE_FSTYPES ?= "tar.bz2 ext3 uboot.mxsboot-sdcard sdcard" MACHINE_FEATURES = "apm usbgadget usbhost vfat alsa touchscreen"
  33. 33. Anatomy of a layerAnatomy of a layer (recipes-<category>)(recipes-<category>) ● Directories which store recipes available in layers, organized by actegory ● Exemples: – recipes-qt: recipes related to the Qt library – recipes-kernel: recipes related to kernels
  34. 34. Applying patchesApplying patches Assuming a recipe named “foo” and a patch “fix.patch”: ● Patches are referenced by the SRC_URI variable in .bb files (recipes) ● SRC_URI += “file://fix.patch”
  35. 35. Storing patchesStoring patches ● Patches are stored into special directories in the recipe directory. Examples: – foo/files/fix.patch : the patch can be referenced by any recipe in the “foo” directory – foo/foo/fix.patch : the patch can only be referenced by the “foo” recipe (any version) – foo/foo-1.0/fix.patch : the patch can only be referenced by recipe “foo”, version 1.0
  36. 36. Hands on: creating a layerHands on: creating a layer Goal: ● Create a meta-training layer containing a hello-freescale recipe and add it to the fsl-community-bsp BSP
  37. 37. Hands on: creating a layerHands on: creating a layer ● yocto-layer create meta-training -o ~/src/fsl-community-bsp/sources/meta-training 4
  38. 38. Hands on: creating a layerHands on: creating a layer (adding the layer to the build directory)(adding the layer to the build directory) echo 'BBLAYERS += " ${BSPDIR}/sources/meta-training "' >> ~/src/fsl-community-bsp/build/conf/bblayers.conf
  39. 39. Hands on: creating a layerHands on: creating a layer (creating a recipe)(creating a recipe) ● Change to the layer's sources directory – cd ~/src/fsl-community-bsp/sources/meta-training ● Create the recipe directory – mkdir -p recipes-training/hello-freescale ● Create the directory to store the code of the application (unusual) – mkdir recipes-training/hello-freescale/hello-freescale ● Write the application code – echo 'int main () { puts("Hello FreeScale"); }' > recipes-training/hello-freescale/hello-freescale/hello-freescale.c
  40. 40. Hands on: creating a layerHands on: creating a layer (recipe file)(recipe file) File ~/src/fsl-community-bsp/sources/meta-training/recipes-training/hello-freescale/hello-freescale_1.0.bb DESCRIPTION = "A Hello World application" SECTION = "console/utils" LICENSE = "CLOSED" SRC_URI = "file://hello-freescale.c" S = "${WORKDIR}" do_compile () { ${CC} -o hello-freescale hello-freescale.c } do_install () { install -d ${D}/${bindir} install -m 755 hello-freescale ${D}/${bindir}/hello-freescale }
  41. 41. Hands on: creating a layerHands on: creating a layer (generating a package)(generating a package) ● Generate the package for the recipe – cd ~/src/fsl-community-bsp/build – bitbake hello-freescale
  42. 42. Hands on: creating a layerHands on: creating a layer (checking the package)(checking the package) ● Check the generated package – rpm -qlp tmp/deploy/rpm/armv7a_vfp_neon/hello-freescale-1.0-r0.armv7a_vfp_neon.rpm – mkdir test – cd test – rpm2cpio ../tmp/deploy/rpm/armv7a_vfp_neon/hello-freescale-1.0-r0.armv7a_vfp_neon.rp m | cpio -i --make-directories – file usr/bin/hello-freescale usr/bin/hello-freescale: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, BuildID[sha1]=0xdf0a4bcbe5872d18a571d51e6ee10895198c84c6, stripped
  43. 43. Hands on: creating a layerHands on: creating a layer (applying a patch)(applying a patch) ● Generate the patch – cd ~/src/fsl-community-bsp/sources/meta-training/recipes-training/hello-freesc ale – cp hello-freescale/hello-freescale.c hello-freescale/hello-freescale.c.orig – sed -i 's/Hello FreeScale/Hello, FreeScale./' hello-freescale/hello-freescale.c – diff -u hello-freescale/hello-freescale.c.orig hello-freescale/hello-freescale.c > hello-freescale/fix.patch – mv hello-freescale/hello-freescale.c.orig hello-freescale/hello-freescale.c ● Add fix.patch to SRC_URI in the recipe file – SRC_URI = "file://hello-freescale.c file://fix.patch" ● Use BitBake to regenerate the package
  44. 44. Hands on: creating a layerHands on: creating a layer (check patch application)(check patch application) less ~/src/fsl-community-bsp/build/tmp/work/armv7a-vfp-neon-poky-lin ux-gnueabi/hello-freescale/1.0-r0/temp/log.do_patch ... NOTE: Applying patch 'fix.patch' (../sources/meta-training/recipes-training/hello-freescale/hello-freescale/fix.patc h) ...
  45. 45. Hands on: creating a layerHands on: creating a layer (creating an image)(creating an image) ● To create an image you just need to make a recipe ● New images usually inherit characteristics from base images available in Yocto (e.g., core-image)
  46. 46. Hands on: creating a layerHands on: creating a layer (image recipe)(image recipe) ● ~/src/fsl-community-bsp/sources/meta-training/recipes- training/images/training-image.bb DESCRIPTION = "Image for Yocto training" LICENSE = "MIT" inherit core-image CORE_IMAGE_EXTRA_INSTALL += "hello-freescale" ● bitbake training-image
  47. 47. Hands on: creating a layerHands on: creating a layer (exploring buildhistory)(exploring buildhistory) ● Directory where historic compilation data gets stored – ~/src/fsl-community-bsp/build/buildhistory ● Organized by packages, images and SDKs
  48. 48. Hands on: creating a layerHands on: creating a layer (checking the image)(checking the image) ● Check if the hello-freescale package has been added to the image (buildhistory) – cd ~/src/fsl-community-bsp/build/buildhistory/images/wandboar d_dual/eglibc/training-image – grep hello-freescale installed-packages.txt ● Check if the binary file has been added to the image – grep hello-freescale files-in-image.txt
  49. 49. Hands on: creating a layerHands on: creating a layer (copying the image to a memory card)(copying the image to a memory card) ● Image files go into – ~/src/fsl-community-bsp/build/tmp/deploy/images ● Write the image to a memory card – Insert the memory card into the memory slot – On VirtualBox, share the the device the memory card is connected to with the virtual machine (Devices menu) – Run “dmesg” on the virtual machine system and check which device the memory card got bound to – cd ~/src/fsl-community-bsp/build/tmp/deploy/images – sudo dd if=training-image-wandboard-dual.sdcard of=/dev/<memory card device> bs=1M
  50. 50. Hands on: creating a layerHands on: creating a layer (serial console)(serial console) ● Conect the target board to your computer using a serial console cable – Use an USB<->DB9 cable to connect your computer to the target board – On VirtualBox, share the USB device your cable is connected to with the virtual machine (Devices menu) – sudo screen /dev/ttyUSB<n> 115200 ● <n> is a number (0 if no other device is connected)
  51. 51. Hands on: Eclipse SDKHands on: Eclipse SDK Goals: ● Configure the Eclipse IDE to use an SDK generated by Yocto ● Create a “helloworld” project/application to test the SDK
  52. 52. Hands on: Eclipse SDKHands on: Eclipse SDK (environment setup)(environment setup) ● Install the Yocto plugin for Eclipse: – http://www.yoctoproject.org/docs/1.4/dev-manual/dev-manual.html#adt-eclipse ● Generate the toolchain – bitbake meta-toolchain ● After generating the toolchain, you need to install it: $ cd tmp/deploy/sdk $ sudo ./poky-<arch>-toolchain-<version>.sh ● The SDK will be installed into: /opt/poky/<version>/
  53. 53. Hands on: Eclipse SDKHands on: Eclipse SDK (environment setup)(environment setup) ● Set up the Yocto plugin for Eclipse to use the SDK: – On Eclipse, click Window → Preferences – On the left listing, click “Yocto Project ADT” – On the “Cross Compiler Options” dialog: ● Select “Standalone pre-built toolchain” ● On “Toolchain Root Location”, fill in the SDK root directory (e.g:, /opt/poky/<version>/) ● On “Sysroot Location”, fill in the sysroot directory (/opt/poky/<version>/sysroots/<target_sysroot>) ● On “Target Architecture”, select the board architecture – On the “Target Options” dialog, select “External HW”
  54. 54. Hands on: Eclipse SDKHands on: Eclipse SDK (creating the helloworld project)(creating the helloworld project) ● On Eclipse, click File → New → Project... ● Select “C Project”, then click “Next” ● Type a name for the new project: “helloworld” ● Click the “Yocto Project ADT Project” folder ● Select “Hello World ANSI C Autotools Project”, then click “Next” – There are two other templates that could also be used: “Empty Project” and “Hello World GTK C Autotools”; all of them are pre-configured with Autotools ● If you want, you can add more information to the project, such as “Author”, “Copyright notice”, “Hello world greeting”, the “Source” directory and “License”. Click “Finish” ● At this point, the “helloworld” project has been created
  55. 55. Hands on: Eclipse SDKHands on: Eclipse SDK (building the helloworld project)(building the helloworld project) ● To build the helloworld project: – On Eclipse, click Project → Reconfigure Project. This only needs to be done when some project configuration changes – Click Project → Build Project ● At this point, the binary file for the program has been generated
  56. 56. Hands on: Eclipse SDKHands on: Eclipse SDK (image generation)(image generation) ● Add to the $BUILDDIR/conf/local.conf file: IMAGE_FEATURES += "eclipse-debug" ● Generate the image – bitbake training-image
  57. 57. Hands on: Eclipse SDKHands on: Eclipse SDK (deploying the helloworld project)(deploying the helloworld project) ● Board setup: – Configure a local network between the development machine and the target board – Boot the target board up – Check the target board IP address $ /sbin/ifconfig ● If it doesn't have an IP address, assign it a new one. Example: $ sudo ifconfig eth0 – Check if the “TCF Agent” is running $ ps | grep tcf ● If it is not running, start the service up: $ sudo /etc/init.d/tcf-agent start
  58. 58. Hands on: Eclipse SDKHands on: Eclipse SDK (deploying the helloworld project)(deploying the helloworld project) ● Development machine setup: – On Eclipse, click Run → Debug configurations – On the left area, unfold “C/C++ Remote Application” – Look for the project to brig the settings to the right area – On the “Connection” field, select the target board configuration. Those connections are bound to IP addresses, that is, if the target board's IP address doesn't change, you can use the same connection. If you want to create a new one: ● Click “New” to create a new connection to the target board ● Select “TCF” (Target Communication Framework), then click “Next” ● Fill in the target board's IP address, the connection name and, optionally, the connection description. Click “Finish” to create the new connection – Assign the application an absolute path (path on the target board's filesystem), then click “Apply”
  59. 59. Hands on: Eclipse SDKHands on: Eclipse SDK (deploying the helloworld project)(deploying the helloworld project) ● Development machine setup (continued): – At the same window, click “Debug” to run the application on the target board – The first time it is executed, a login dialog is displayed. Log in with credentials for the target board then click “OK” – Eclipse will ask you if you want to change the interface layout. Accept or deny that according to your preferences (when in doubt, accept it) ● At this point, the application is running in debug mode (on GDB) and stuck on a breakpoint. To resume its execution, hit “F8” on the keyboard
  60. 60. Thank you