Building your own embedded
system with Yocto
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Preface
● if you have any questions, don't hesitate to ask, comment, ...
● ⚠ 10 GB of free disk space ⚠
● ⚠ internet connection ⚠
● please pass the USB flash drives around and copy the contents to your
laptop
2
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
🙋‍♂ About me
● Marius Meisenzahl
● loves to tinker with hardware and software 🤓
● Linux enthusiast 🐧
● co-founder of
○ located in Bochum
○ we build software from embedded to web
3
/meisenzahl /msnzhl
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
🐧 Linux origin story
● first steps with Knoppix, Mandriva (formerly Mandrake)
● distro hopped: openSUSE, Debian, Ubuntu, Arch Linux, ...
○ interest in how things work
■ Gentoo
■ Linux From Scratch → Great for a rainy weekend
● Ubuntu Hardy Heron (8.04)
● several years Arch Linux
● for a long time elementary OS (Ubuntu based distribution)
● building own systems
○ Kernel + BusyBox
○ Buildroot
○ Yocto
4
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Quick Poll
● Who of you has ever built an embedded system before?
● Who of you has ever compiled a Linux kernel?
● Who of you has ever used a cross-compiler?
5
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Goals
➔ Building your own embedded system with Yocto
◆ How do embedded Linux systems work?
◆ What is Yocto?
◆ How does Yocto work?
6
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Agenda
1. Basic knowledge
○ Embedded systems
○ Yocto Project
2. Inner workings
○ Initial setup
○ Leaving the comfort zone
3. Getting used to it
○ DIY
○ Outlook
7
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
1. Basic knowledge
8
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Embedded systems
9
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
What is an embedded system?
● An embedded system is a computer system that has a dedicated function
within a larger mechanical or electrical system
● A distribution is an operating system based on a Linux kernel
10
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Architecture of embedded systems
11
Applications
Libraries
System Call Interface
IO
Management
Process
Management
Memory
Management
Device Driver Layer
Bootloader
Firmware
Userland
Kernel
Hardware
ConfigurationsApplications
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Hardware
12
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Firmware
● basic initialization of the hardware
● loads the bootloader
13
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Bootloader
● further initialization of the hardware
● loads kernel and userland into main memory
● additional features
○ read and write memory
○ define boot parameters
○ choose boot source (internal/external memory, network, …)
○ scripting (A/B booting, …)
○ image verification
○ ...
● common bootloader
○ Das U-Boot
14
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Kernel
15
System Call Interface
IO
Management
Process
Management
Memory
Management
Device Driver Layer
Kernel
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Kernel
16
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Kernel
● current LTS 5.4.25
○ allnoconfig 652 KB
○ allyesconfig 123 MB
17
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Kernel
18
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Userland
19
Applications
LibrariesConfigurations
Userland
● logic of the system apart from the kernel
● located on root file system
● contains
○ libraries
○ applications
○ configurations
○ …
Applications
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Userland
● kernel starts process with id 1
○ so called init process
● it can be a simple shell script
○ which starts other processes
● or a full blown process manager like systemd
○ starts so called services as background processes
20
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Userland
21
init
pid=1
httpd
pid=1038
login
pid=154
bash
pid=294
httpd
pid=1364
httpd
pid=1284
ls
pid=336
cowsay
pid=300
php
pid=1783
php
pid=1694
htop
pid=385
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Filesystem Hierarchy Standard (simplified)
22
/bin, /sbin system applications
/boot boot related files like kernels, ...
/dev, /proc, /sys devices, processes, ...
/etc configuration files
/home user related files
/lib libraries
/tmp temporary files
/usr user applications, libraries, ...
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Yocto Project
23
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
24
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
It’s not an embedded Linux distribution.
25
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
It’s not an embedded Linux distribution.
It creates a custom one for you.
26
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Yocto
● open source project of the Linux Foundation
● licensed under MIT and GPLv2
● helps developers create custom Linux-based systems regardless of the
hardware architecture
27
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Poky
● Poky is the reference distribution
● you can use it as a base
● tweak it to your needs
28
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Cooking
29
👨‍🍳
🍛
🍚🥕🧂🍠
📗📘📙
📄
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Engineering with Yocto
30
👨‍🍳 👨‍💻
🍛 embedded system
🍚🥕🧂🍠 libraries, applications, ...
📗📘📙 📁 layers
📄 📄 recipe
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Layers
📁 meta-embo
📁 meta-poky
📁 meta-selftest
📁 meta-skeleton
📁 meta-yocto-bsp
31
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Layer
meta-embo
├── conf
│ ├── distro
│ │ ├── embo.conf
│ │ └── embo-tiny.conf
│ └── layer.conf
└── recipes-core
├── hello-cmake
│ └── hello-cmake.bb
└── images
└── embo-image.bb
32
BBPATH .= ":${LAYERDIR}"
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb 
${LAYERDIR}/recipes-*/*/*.bbappend"
BBFILE_COLLECTIONS += "embo"
BBFILE_PATTERN_embo = "^${LAYERDIR}/"
BBFILE_PRIORITY_embo = "6"
LAYERSERIES_COMPAT_embo = "warrior"
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Recipe
meta-embo
├── conf
│ ├── distro
│ │ ├── embo.conf
│ │ └── embo-tiny.conf
│ └── layer.conf
└── recipes-core
├── hello-cmake
│ └── hello-cmake.bb
└── images
└── embo-image.bb
33
DESCRIPTION = "hello cmake"
SECTION = "examples"
LICENSE = "CLOSED"
DEPENDS = ""
SRC_URI = " file:./hello-cmake/"
S = "${WORKDIR}/hello-cmake"
inherit pkgconfig cmake
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Image
meta-embo
├── conf
│ ├── distro
│ │ ├── embo.conf
│ │ └── embo-tiny.conf
│ └── layer.conf
└── recipes-core
├── hello-cmake
│ └── hello-cmake.bb
└── images
└── embo-image.bb
34
require recipes-core/images/core-image-minimal.bb
IMAGE_INSTALL_append = "
hello-cmake 
hello-make 
hello-meson 
"
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
BitBake
● build tool
● reads .bb and .bbappend files
● resolves dependencies between recipes
● creates build order
● generates Python code to build packages
35
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
BitBake tasks
● fetch
● unpack
● patch
● configure
● compile
● populate
● install
● package
● package_write
36
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
2. Inner workings
37
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Initial setup
38
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
QEMU
● generic machine emulator and virtualizer
● licensed under GPLv2 and BSD
● we use qemu-system-i386 to test our embedded system
○ due to lack of embedded hardware
39
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
👷 Build Host
● linux distribution
○ Windows Subsystem for Linux (WSL) is not supported
○ but you can use Docker or a virtual machine (VirtualBox)
● Ubuntu 16.04, 18.04, 19.04
● Fedora 28, 29, 30
● CentOS 7.x
● Debian GNU/Linux 8.x, 9.x, 10.x
● OpenSUSE Leap 15.1
40
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
👷 Build Host
● initialize your build environment
○ Docker (recommended)
○ local (Linux only)
○ VirtualBox
41
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
🤞 Test if build environment works
● make embo-image
● make run-embo-image
42
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Important files and folders
● Makefile
○ BRANCH
○ DISTRO
○ MACHINE
● poky/build/conf/bblayers.conf
● poky/build/conf/local.conf
○ DL_DIR = downloads
○ SSTATE_DIR = sstate-cache
● poky/build/tmp/deploy/images
● poky/build/tmp/deploy/licenses
● poky/build/tmp/deploy/rpm
43
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Playtime
● login as user root
● ps
○ /init pid=1
● /init
○ /sbin/init
■ /bin/busybox.nosuid
● /bin/busybox.nosuid
● /bin/busybox.nosuid init
● hello-make
● hello-cmake
● hello-meson
44
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-make
● minimal example built with make
45
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-cmake
● minimal example built with cmake
46
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-meson
● minimal example built with meson
47
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Leaving the comfort zone
48
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
bitbake
● cd poky
● source oe-init-build-env
● export DISTRO=embo-tiny
● export MACHINE=qemux86
● bitbake embo-image
● bitbake hello-make -c build
● bitbake hello-make -c cleanall
● bitbake hello-make -c build
● bitbake -s
49
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Dependencies
🔗 https://layers.openembedded.org/layerindex/branch/warrior/recipes/
● git clone -b warrior git:./git.openembedded.org/meta-openembedded
● add to poky/build/conf/bblayers.conf
○ meta-openembedded/meta-oe
● bitbake nlohmann-json
50
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-json
● create a new example recipe which uses nlohmann-json
DESCRIPTION = "hello json"
SECTION = "examples"
LICENSE = "CLOSED"
DEPENDS = "nlohmann-json"
SRC_URI = " file:./hello-json/"
S = "${WORKDIR}/hello-json"
inherit pkgconfig cmake
51
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-json
● create a main.cpp which uses nlohmann-json
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann.:json;
int main() {
json j;
j["hello"] = "json";
std.:cout .< j.dump() .< std.:endl;
return 0;
}
52
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-json
● create a CMakeLists.txt to build example
cmake_minimum_required(VERSION 3.10)
project(hello-json)
find_package(nlohmann_json REQUIRED)
add_executable(hello-json main.cpp)
target_link_libraries(hello-json nlohmann_json.:nlohmann_json)
install(TARGETS hello-json DESTINATION bin)
53
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
embo-image
● add your new package to our image
require recipes-core/images/core-image-minimal.bb
IMAGE_INSTALL_append = "
hello-cmake 
hello-make 
hello-meson 
hello-json 
"
54
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
embo-image
● bitbake embo-image
● make run-embo-image
● hello-json
○ {"hello":"json"}
55
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Dependency graph
● bitbake -g hello-make
● less recipe-depends.dot
● ⚠ dot -Tpng recipe-depends.dot -o recipe-depends.png ⚠
● less task-depends.dot
56
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Dependency graph
● bitbake -g embo-image
● less recipe-depends.dot
● less task-depends.dot
57
👨‍💻
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
3. Getting used to it
58
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Add files to rootfs
base-files_%.bbappend
FILESEXTRAPATHS_prepend .= "${THISDIR}/files:"
SRC_URI += "file:./embo"
do_install_append() {
install -m 0644 ${WORKDIR}/embo ${D}/embo
}
59
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Add users
recipe
inherit useradd
USER .= "user"
PASSWORD .= "9PfNy0O1z0O5g"
USERADD_PACKAGES = "${PN}"
USERADD_PARAM_${PN} = ".-system .-create-home 
.-groups tty 
.-password ${PASSWORD} 
.-user-group ${USER}"
60
⚠ DISTRO = embo ⚠
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-boost
DESCRIPTION = "hello boost"
SECTION = "examples"
LICENSE = "CLOSED"
DEPENDS = "boost"
RDEPENDS_${PN} = "boost-thread"
SRC_URI = " file:./hello-boost/"
S = "${WORKDIR}/hello-boost"
inherit pkgconfig cmake
61
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-boost
#include <boost/thread.hpp>
#include <boost/chrono.hpp>
#include <iostream>
void wait(int seconds) {
boost.:this_thread.:sleep_for(boost.:chrono.:seconds{seconds});
}
void thread() {
for (int i = 0; i < 5; .+i) {
wait(1);
std.:cout .< i .< std.:endl;
62
}
}
int main() {
boost.:thread t{thread};
t.join();
return 0;
}
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
hello-boost
cmake_minimum_required(VERSION 3.10)
project(hello-boost)
find_package(Boost COMPONENTS thread REQUIRED)
add_executable(hello-boost main.cpp)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(hello-cmake ${Boost_LIBRARIES})
install(TARGETS hello-boost DESTINATION bin)
63
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
DIY
● try to build something yourself
● ask for help
64
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
Outlook
● bundle sources of packages used to build image
○ update your systems with a package manager
■ EXTRA_IMAGE_FEATURES += "package-management"
○ sign your packages
■ INHERIT += "sign_rpm"
● create a SDK to simplify development
○ bitbake <image> -c populate_sdk
● bundle list of licenses of packages used to build image
● license management
○ prohibit certain licenses
■ INCOMPATIBLE_LICENSE = "GPL-3.0 LGPL-3.0 AGPL-3.0"
● ...
65
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
What else can you do with Yocto?
● build custom Docker images
IMAGE_FSTYPES += " .tar.gz"
FROM scratch
ADD rootfs.tar.gz /
CMD ["/bin/sh"]
66
13.03.2020Building your own embedded system with Yocto • Marius Meisenzahl
References
● https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.h
tml
● https://git.yoctoproject.org/
● https://www.yoctoproject.org/docs/what-i-wish-id-known/
67

Building your own embedded system with Yocto

  • 1.
    Building your ownembedded system with Yocto
  • 2.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Preface ● if you have any questions, don't hesitate to ask, comment, ... ● ⚠ 10 GB of free disk space ⚠ ● ⚠ internet connection ⚠ ● please pass the USB flash drives around and copy the contents to your laptop 2
  • 3.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 🙋‍♂ About me ● Marius Meisenzahl ● loves to tinker with hardware and software 🤓 ● Linux enthusiast 🐧 ● co-founder of ○ located in Bochum ○ we build software from embedded to web 3 /meisenzahl /msnzhl
  • 4.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 🐧 Linux origin story ● first steps with Knoppix, Mandriva (formerly Mandrake) ● distro hopped: openSUSE, Debian, Ubuntu, Arch Linux, ... ○ interest in how things work ■ Gentoo ■ Linux From Scratch → Great for a rainy weekend ● Ubuntu Hardy Heron (8.04) ● several years Arch Linux ● for a long time elementary OS (Ubuntu based distribution) ● building own systems ○ Kernel + BusyBox ○ Buildroot ○ Yocto 4
  • 5.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Quick Poll ● Who of you has ever built an embedded system before? ● Who of you has ever compiled a Linux kernel? ● Who of you has ever used a cross-compiler? 5
  • 6.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Goals ➔ Building your own embedded system with Yocto ◆ How do embedded Linux systems work? ◆ What is Yocto? ◆ How does Yocto work? 6
  • 7.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Agenda 1. Basic knowledge ○ Embedded systems ○ Yocto Project 2. Inner workings ○ Initial setup ○ Leaving the comfort zone 3. Getting used to it ○ DIY ○ Outlook 7
  • 8.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 1. Basic knowledge 8
  • 9.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Embedded systems 9
  • 10.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl What is an embedded system? ● An embedded system is a computer system that has a dedicated function within a larger mechanical or electrical system ● A distribution is an operating system based on a Linux kernel 10
  • 11.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Architecture of embedded systems 11 Applications Libraries System Call Interface IO Management Process Management Memory Management Device Driver Layer Bootloader Firmware Userland Kernel Hardware ConfigurationsApplications
  • 12.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Hardware 12
  • 13.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Firmware ● basic initialization of the hardware ● loads the bootloader 13
  • 14.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Bootloader ● further initialization of the hardware ● loads kernel and userland into main memory ● additional features ○ read and write memory ○ define boot parameters ○ choose boot source (internal/external memory, network, …) ○ scripting (A/B booting, …) ○ image verification ○ ... ● common bootloader ○ Das U-Boot 14
  • 15.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Kernel 15 System Call Interface IO Management Process Management Memory Management Device Driver Layer Kernel
  • 16.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Kernel 16
  • 17.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Kernel ● current LTS 5.4.25 ○ allnoconfig 652 KB ○ allyesconfig 123 MB 17
  • 18.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Kernel 18
  • 19.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Userland 19 Applications LibrariesConfigurations Userland ● logic of the system apart from the kernel ● located on root file system ● contains ○ libraries ○ applications ○ configurations ○ … Applications
  • 20.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Userland ● kernel starts process with id 1 ○ so called init process ● it can be a simple shell script ○ which starts other processes ● or a full blown process manager like systemd ○ starts so called services as background processes 20
  • 21.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Userland 21 init pid=1 httpd pid=1038 login pid=154 bash pid=294 httpd pid=1364 httpd pid=1284 ls pid=336 cowsay pid=300 php pid=1783 php pid=1694 htop pid=385
  • 22.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Filesystem Hierarchy Standard (simplified) 22 /bin, /sbin system applications /boot boot related files like kernels, ... /dev, /proc, /sys devices, processes, ... /etc configuration files /home user related files /lib libraries /tmp temporary files /usr user applications, libraries, ...
  • 23.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Yocto Project 23
  • 24.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 24
  • 25.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl It’s not an embedded Linux distribution. 25
  • 26.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl It’s not an embedded Linux distribution. It creates a custom one for you. 26
  • 27.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Yocto ● open source project of the Linux Foundation ● licensed under MIT and GPLv2 ● helps developers create custom Linux-based systems regardless of the hardware architecture 27
  • 28.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Poky ● Poky is the reference distribution ● you can use it as a base ● tweak it to your needs 28
  • 29.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Cooking 29 👨‍🍳 🍛 🍚🥕🧂🍠 📗📘📙 📄
  • 30.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Engineering with Yocto 30 👨‍🍳 👨‍💻 🍛 embedded system 🍚🥕🧂🍠 libraries, applications, ... 📗📘📙 📁 layers 📄 📄 recipe
  • 31.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Layers 📁 meta-embo 📁 meta-poky 📁 meta-selftest 📁 meta-skeleton 📁 meta-yocto-bsp 31
  • 32.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Layer meta-embo ├── conf │ ├── distro │ │ ├── embo.conf │ │ └── embo-tiny.conf │ └── layer.conf └── recipes-core ├── hello-cmake │ └── hello-cmake.bb └── images └── embo-image.bb 32 BBPATH .= ":${LAYERDIR}" BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend" BBFILE_COLLECTIONS += "embo" BBFILE_PATTERN_embo = "^${LAYERDIR}/" BBFILE_PRIORITY_embo = "6" LAYERSERIES_COMPAT_embo = "warrior"
  • 33.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Recipe meta-embo ├── conf │ ├── distro │ │ ├── embo.conf │ │ └── embo-tiny.conf │ └── layer.conf └── recipes-core ├── hello-cmake │ └── hello-cmake.bb └── images └── embo-image.bb 33 DESCRIPTION = "hello cmake" SECTION = "examples" LICENSE = "CLOSED" DEPENDS = "" SRC_URI = " file:./hello-cmake/" S = "${WORKDIR}/hello-cmake" inherit pkgconfig cmake
  • 34.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Image meta-embo ├── conf │ ├── distro │ │ ├── embo.conf │ │ └── embo-tiny.conf │ └── layer.conf └── recipes-core ├── hello-cmake │ └── hello-cmake.bb └── images └── embo-image.bb 34 require recipes-core/images/core-image-minimal.bb IMAGE_INSTALL_append = " hello-cmake hello-make hello-meson "
  • 35.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl BitBake ● build tool ● reads .bb and .bbappend files ● resolves dependencies between recipes ● creates build order ● generates Python code to build packages 35
  • 36.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl BitBake tasks ● fetch ● unpack ● patch ● configure ● compile ● populate ● install ● package ● package_write 36
  • 37.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 2. Inner workings 37
  • 38.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Initial setup 38
  • 39.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl QEMU ● generic machine emulator and virtualizer ● licensed under GPLv2 and BSD ● we use qemu-system-i386 to test our embedded system ○ due to lack of embedded hardware 39
  • 40.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 👷 Build Host ● linux distribution ○ Windows Subsystem for Linux (WSL) is not supported ○ but you can use Docker or a virtual machine (VirtualBox) ● Ubuntu 16.04, 18.04, 19.04 ● Fedora 28, 29, 30 ● CentOS 7.x ● Debian GNU/Linux 8.x, 9.x, 10.x ● OpenSUSE Leap 15.1 40
  • 41.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 👷 Build Host ● initialize your build environment ○ Docker (recommended) ○ local (Linux only) ○ VirtualBox 41
  • 42.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 🤞 Test if build environment works ● make embo-image ● make run-embo-image 42
  • 43.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Important files and folders ● Makefile ○ BRANCH ○ DISTRO ○ MACHINE ● poky/build/conf/bblayers.conf ● poky/build/conf/local.conf ○ DL_DIR = downloads ○ SSTATE_DIR = sstate-cache ● poky/build/tmp/deploy/images ● poky/build/tmp/deploy/licenses ● poky/build/tmp/deploy/rpm 43 👨‍💻
  • 44.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Playtime ● login as user root ● ps ○ /init pid=1 ● /init ○ /sbin/init ■ /bin/busybox.nosuid ● /bin/busybox.nosuid ● /bin/busybox.nosuid init ● hello-make ● hello-cmake ● hello-meson 44 👨‍💻
  • 45.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-make ● minimal example built with make 45 👨‍💻
  • 46.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-cmake ● minimal example built with cmake 46 👨‍💻
  • 47.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-meson ● minimal example built with meson 47 👨‍💻
  • 48.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Leaving the comfort zone 48
  • 49.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl bitbake ● cd poky ● source oe-init-build-env ● export DISTRO=embo-tiny ● export MACHINE=qemux86 ● bitbake embo-image ● bitbake hello-make -c build ● bitbake hello-make -c cleanall ● bitbake hello-make -c build ● bitbake -s 49 👨‍💻
  • 50.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Dependencies 🔗 https://layers.openembedded.org/layerindex/branch/warrior/recipes/ ● git clone -b warrior git:./git.openembedded.org/meta-openembedded ● add to poky/build/conf/bblayers.conf ○ meta-openembedded/meta-oe ● bitbake nlohmann-json 50 👨‍💻
  • 51.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-json ● create a new example recipe which uses nlohmann-json DESCRIPTION = "hello json" SECTION = "examples" LICENSE = "CLOSED" DEPENDS = "nlohmann-json" SRC_URI = " file:./hello-json/" S = "${WORKDIR}/hello-json" inherit pkgconfig cmake 51 👨‍💻
  • 52.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-json ● create a main.cpp which uses nlohmann-json #include <iostream> #include <nlohmann/json.hpp> using json = nlohmann.:json; int main() { json j; j["hello"] = "json"; std.:cout .< j.dump() .< std.:endl; return 0; } 52 👨‍💻
  • 53.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-json ● create a CMakeLists.txt to build example cmake_minimum_required(VERSION 3.10) project(hello-json) find_package(nlohmann_json REQUIRED) add_executable(hello-json main.cpp) target_link_libraries(hello-json nlohmann_json.:nlohmann_json) install(TARGETS hello-json DESTINATION bin) 53 👨‍💻
  • 54.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl embo-image ● add your new package to our image require recipes-core/images/core-image-minimal.bb IMAGE_INSTALL_append = " hello-cmake hello-make hello-meson hello-json " 54 👨‍💻
  • 55.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl embo-image ● bitbake embo-image ● make run-embo-image ● hello-json ○ {"hello":"json"} 55 👨‍💻
  • 56.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Dependency graph ● bitbake -g hello-make ● less recipe-depends.dot ● ⚠ dot -Tpng recipe-depends.dot -o recipe-depends.png ⚠ ● less task-depends.dot 56 👨‍💻
  • 57.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Dependency graph ● bitbake -g embo-image ● less recipe-depends.dot ● less task-depends.dot 57 👨‍💻
  • 58.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl 3. Getting used to it 58
  • 59.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Add files to rootfs base-files_%.bbappend FILESEXTRAPATHS_prepend .= "${THISDIR}/files:" SRC_URI += "file:./embo" do_install_append() { install -m 0644 ${WORKDIR}/embo ${D}/embo } 59
  • 60.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Add users recipe inherit useradd USER .= "user" PASSWORD .= "9PfNy0O1z0O5g" USERADD_PACKAGES = "${PN}" USERADD_PARAM_${PN} = ".-system .-create-home .-groups tty .-password ${PASSWORD} .-user-group ${USER}" 60 ⚠ DISTRO = embo ⚠
  • 61.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-boost DESCRIPTION = "hello boost" SECTION = "examples" LICENSE = "CLOSED" DEPENDS = "boost" RDEPENDS_${PN} = "boost-thread" SRC_URI = " file:./hello-boost/" S = "${WORKDIR}/hello-boost" inherit pkgconfig cmake 61
  • 62.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-boost #include <boost/thread.hpp> #include <boost/chrono.hpp> #include <iostream> void wait(int seconds) { boost.:this_thread.:sleep_for(boost.:chrono.:seconds{seconds}); } void thread() { for (int i = 0; i < 5; .+i) { wait(1); std.:cout .< i .< std.:endl; 62 } } int main() { boost.:thread t{thread}; t.join(); return 0; }
  • 63.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl hello-boost cmake_minimum_required(VERSION 3.10) project(hello-boost) find_package(Boost COMPONENTS thread REQUIRED) add_executable(hello-boost main.cpp) include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(hello-cmake ${Boost_LIBRARIES}) install(TARGETS hello-boost DESTINATION bin) 63
  • 64.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl DIY ● try to build something yourself ● ask for help 64
  • 65.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl Outlook ● bundle sources of packages used to build image ○ update your systems with a package manager ■ EXTRA_IMAGE_FEATURES += "package-management" ○ sign your packages ■ INHERIT += "sign_rpm" ● create a SDK to simplify development ○ bitbake <image> -c populate_sdk ● bundle list of licenses of packages used to build image ● license management ○ prohibit certain licenses ■ INCOMPATIBLE_LICENSE = "GPL-3.0 LGPL-3.0 AGPL-3.0" ● ... 65
  • 66.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl What else can you do with Yocto? ● build custom Docker images IMAGE_FSTYPES += " .tar.gz" FROM scratch ADD rootfs.tar.gz / CMD ["/bin/sh"] 66
  • 67.
    13.03.2020Building your ownembedded system with Yocto • Marius Meisenzahl References ● https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.h tml ● https://git.yoctoproject.org/ ● https://www.yoctoproject.org/docs/what-i-wish-id-known/ 67