SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
How to create
your own Linux
distribution
Dimitris Platis
dimitris@platis.solutions
About me Dimitrios Platis
● Grew up in Rodos, Greece
● Software Engineer @ Zenseact,
Gothenburg
● Course responsible @ DIT112,
Gothenburg University
● Interests:
○ Embedded systems
○ Software Architecture
○ API Design
○ Open source software & hardware
○ Robots, Portable gadgets, IoT
○ 3D printing
○ Autonomous Driving
● Website: https://platis.solutions
How about you?
Topics
● Why create your own Linux distribution?
● What is Yocto?
● How to configure hardware & software?
● How to include your own component in an image?
● How to launch your component on boot?
● How to connect to WiFi on boot?
● How to cross compile for your distro?
● How to configure the Linux kernel?
Demo platform
● dimitriOS RPi Zero Wifi
● WiFi connection on boot
● /usr/bin/employee_getter
Why
dimitriOS?
platisd/meta-dimitriOS
● Got tired of following the golden image
approach
● As projects get complex, maintaining a
modified image becomes unsustainable
● Reproducibility is really low
● Maintaining variants would be a nightmare
● Updating to a new operating system version
would require major rework
● Need a standardized, version controllable
method to configure and create embedded
operating systems
About Yocto ● "Umbrella open source project that builds and
maintains validated open source tools and
components associated with embedded Linux"
● A collection of tools and processes enabling the
creation of configurable Linux distributions
● Used a lot for embedded systems
○ IoT
○ Automotive
○ Wearables
○ Industry
● Open source
● Little to no assumptions on hardware architecture,
programming languages, init system etc
● Good documentation (but too much for beginners)
Basic
glossary
Recipe: Specifies
how a particular
package is built.
They include all the
dependencies,
source code
locations,
configuration,
compilation, build,
install and remove
instructions. They
are stored in layers.
(employee-getter_git.bb)
Layer: A collection
of related recipes.
Layers allow you to
customize your
build, and isolate
information for
multiple
architecture builds.
Layers are
hierarchical in their
ability to override
previous
specifications.
(meta-dimitriOS)
Bitbake: a scheduler
and execution
engine which
parses recipes. It
then creates a
dependency tree to
order the
compilation,
schedules the
compilation of the
included code, and
finally, executes the
building of the
specified, custom
Linux image.
Basic glossary .conf files: Files which hold
global definitions of
variables, user defined
variables and hardware
configuration information.
They tell the build system
what to build and put into
the image to support a
particular platform.
(local.conf, dimitrios.conf)
OpenEmbedded-Core:
oe-core is meta-data
comprised of foundation
recipes, classes and
associated files that are
meant to be common
among many different
OpenEmbedded-derived
systems, including the
Yocto Project.
(meta-openembedded)
BSP: The Board Support
Package. A layer
containing
hardware-specific drivers
and utilities, necessary for
the Operating System to
function.
(meta-raspberrypi)
Basic glossary Packages: The output of
the build system used to
create your final image.
(.rpm, .deb etc)
Distribution: A
hardware-agnostic
(abstract) representation
of an operating system.
(dimitriOS.conf)
Image: A binary form of a
Linux distribution
(operating system)
intended to be flashed onto
a device.
(.bin, .sdcard etc)
Read more
Poky
Poky: A reference embedded
distribution and a reference test
configuration created to provide a
base level functional distro which
can be used to illustrate how to
customize a distribution
(Over)Simplified
layered system view
Vendor BSP
(RPi drivers etc)
Linux kernel
Your Distro
(dimitriOS common functionality)
Your product variant
(workshop-image)
employee_getter
Down the
rabbit hole
$ repo init -u https://github.com/platisd/dimitriOS-manifest.git -m dimitriOS-rpi.xml
$ repo sync
➢ dimitriOS-rpi.xml
➢ dimitriOS-base.xml
$ export TEMPLATECONF=~/dimitriOS/layers/meta-dimitriOS/rpi-conf/
➢ rpi-conf/bblayers.conf(.sample)
➢ rpi-conf/local.conf(.sample)
➢ conf/distro/dimitriOS.conf
$ . layers/poky/oe-init-build-env build
$ export MACHINE=raspberrypi4
$ bitbake workshop-image
➢ workshop-image/workshop-image.bb
➢ employee-getter/employee-getter_git.bb
➢ wifi-autoconnect/wifi-autoconnect_git.bb
Fetching the
sources
(dimitrios-rpi.xml)
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<include name="dimitriOS-base.xml" />
<remote fetch="git://git.yoctoproject.org" name="yocto"/>
<project name="meta-raspberrypi"
remote="yocto"
revision="dunfell"
path="layers/meta-raspberrypi"/>
</manifest>
Fetching the
sources
(dimitrios-base.xml)
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote fetch="git://git.yoctoproject.org" name="yocto"/>
<remote fetch="git://git.openembedded.org" name="oe"/>
<remote fetch="git://github.com/platisd" name="origin"/>
<default sync-j="4"/>
<project name="poky"
remote="yocto"
revision="dunfell"
path="layers/poky"/>
<project name="meta-openembedded"
remote="oe"
revision="dunfell"
path="layers/meta-openembedded"/>
<project name="meta-dimitriOS"
remote="origin"
revision="master"
path="layers/meta-dimitriOS"/>
</manifest>
Hardware
configuration
(rpi-conf/bblayers.conf)
BBLAYERS ?= " 
${TOPDIR}/../layers/poky/meta 
${TOPDIR}/../layers/poky/meta-poky 
${TOPDIR}/../layers/meta-raspberrypi 
${TOPDIR}/../layers/meta-dimitriOS 

${TOPDIR}/../layers/meta-openembedded/meta-oe 
${TOPDIR}/../layers/meta-openembedded/meta-networking 
${TOPDIR}/../layers/meta-openembedded/meta-python 
${TOPDIR}/../layers/meta-openembedded/meta-gnome 
"
Hardware
configuration
(rpi-conf/local.conf)
IMAGE_FSTYPES = "rpi-sdimg"
IMAGE_OVERHEAD_FACTOR = "1.5"
IMAGE_INSTALL_append = " linux-firmware-rpidistro-bcm43430"
IMAGE_INSTALL_append = " kernel-module-brcmfmac"
DISABLE_SPLASH = "1"
BOOT_DELAY = "0"
BOOT_DELAY_MS = "0"
MACHINE ?= "raspberrypi0-wifi"
DISTRO = "dimitriOS"
Software
configuration
(distro/dimitriOS.conf)
require conf/distro/poky.conf
DISTRO = "dimitriOS"
DISTRO_NAME = "dimitriOS"
SYSTEMD_BOOT_TIMEOUT := "0"
PACKAGE_CLASSES ?= " package_rpm"
DISTRO_FEATURES_append = " wifi systemd"
DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
VIRTUAL-RUNTIME_initscripts = ""
PREFERRED_PROVIDER_udev ?= "systemd"
PREFERRED_PROVIDER_udev-utils ?= "systemd"
hostname_pn-base-files = "dimitrios"
CORE_IMAGE_EXTRA_INSTALL += "openssh"
CORE_IMAGE_EXTRA_INSTALL += "usbutils"
Image
configuration
(workshop-image.bb)
require recipes-core/images/core-image-minimal.bb
IMAGE_BASENAME = "workshop"
IMAGE_INSTALL_append = " employee-getter"
IMAGE_INSTALL_append = " wifi-autoconnect"
EXTRA_USERS_PARAMS = "
useradd -P workshop grcpp; 
"
inherit extrausers
Component
recipe
(employee-getter_git.bb)
DEPENDS = "
curl 
nlohmann-json 
"
RDEPENDS_${PN} = "
libcurl 
"
SRC_URI = "
git://github/platisd/example-dimitriOS-cmake-project 
file://employee-getter.service 
"
SRCREV = "${AUTOREV}"
do_install_append() {
install -d ${D}/${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/employee-getter.service
${D}/${systemd_system_unitdir}
}
REQUIRED_DISTRO_FEATURES= "systemd"
SYSTEMD_SERVICE_${PN} = "employee-getter.service"
inherit cmake features_check systemd
Start on boot
(employee-getter.service)
[Unit]
Description=EmployeeGetter
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/employee_getter
[Install]
WantedBy=multi-user.target
WiFi on boot
(wifi-autoconnect.bb)
See also:
● dimitrios-wifi-wlan0.service
RDEPENDS_${PN} = "
wpa-supplicant 
"
SRC_URI = "
file://98-wireless-interface-naming.link 
file://dimitrios-wifi-wlan0.service 
"
do_install() {
install -d ${D}/${systemd_system_unitdir}
install -m 0644
${WORKDIR}/dimitrios-wifi-wlan0.service
${D}/${systemd_system_unitdir}
install -d ${D}${sysconfdir}/systemd/network/
install -m 0644
${WORKDIR}/98-wireless-interface-naming.link
${D}${sysconfdir}/systemd/network/
}
REQUIRED_DISTRO_FEATURES= "systemd"
SYSTEMD_SERVICE_${PN} = "
dimitrios-wifi-wlan0.service 
"
inherit systemd features_check
WiFi on boot
(wpa-supplicant_%.bbappend)
See also:
● wpa_supplicant.conf
● systemd-conf_%.bbappend
● wifi.network
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
SRC_URI += " 
file://wpa_supplicant.conf 
"
WIFI_SSID ??= "ssid"
WIFI_PASSWORD ??= "password"
do_install_append() {
install -d ${D}/${sysconfdir}/wpa_supplicant
install -m 0644 ${WORKDIR}/wpa_supplicant.conf
${D}/${sysconfdir}/wpa_supplicant
sed -i 's/default_ssid/'"${WIFI_SSID}"'/g'
${D}/${sysconfdir}/wpa_supplicant/wpa_supplicant.conf
sed -i 's/default_password/'"${WIFI_PASSWORD}"'/g'
${D}/${sysconfdir}/wpa_supplicant/wpa_supplicant.conf
}
FILES_${PN} += "
${sysconfdir} 
"
Environment
variables
(BB_ENV_EXTRAWHITE)
The build does not have access to your host's environment
variables unless they are stated in BB_ENV_EXTRAWHITE!
1. Export variables
● export WIFI_SSID=your-ssid
● export WIFI_PASSWORD=your-password
2. Register them through BB_ENV_EXTRAWHITE
● export BB_ENV_EXTRAWHITE="WIFI_SSID WIFI_PASSWORD"
Cross-compile
for your
embedded OS
To cross compile an executable that will run on your
embedded OS, you need:
1. Compiler toolchain for the target system
2. All dependencies compiled for the target system
This is very cumbersome to set up manually!
To cross-compiling employee_getter, what about:
⁇ Compiler for Raspberry Pi
⁇ Compile-time dependencies:
○ #include <curl/curl.h>
○ #include <nlohmann/json.hpp>
Cross-compile
for your
embedded OS
Yocto can produce an SDK for you!
Cross compiling for your image now becomes trivial:
1. Build SDK
● bitbake workshop-image -c populate_sdk
2. Install SDK
● ./dimitriOS-glibc-x86_64-workshop-arm1176jzfshf-vfp-raspberrypi0-wifi-toolchain-3.1.4.sh
3. Source SDK
● . ~/opt/dimitriOS/3.1.4/environment-setup-arm1176jzfshf-vfp-poky-linux-gnueabi
4. Configure and build (e.g. with CMake and make)
● mkdir build
● cd build
● cmake ..
● make
5. Verify employee_getter is cross-compiled:
● file employee_getter
> employee_getter: ELF 32-bit LSB shared object, ARM
Configure
Linux kernel
with
fragments
If you need to load or remove kernel modules, you can use
the menuconfig tool to produce fragments (.cfg) and
include them to your image.
● Run menuconfig for RPi
○ bitbake linux-raspberrypi -c menuconfig
● diff the new configuration and place the delta into a
.cfg file
○ CONFIG_ATH9K_AHB=y
● Append to the kernel recipe
○ linux-raspberrypi_%.bbappend
For more on how to get started, look at the
QuickAndDirtyKernelConfig guide.
Building the
image
● Takes a long time at first!
● You are building the entire OS from source
● Bitbake will try to utilize all your CPU cores
● Tip: Let it run over night
$ bitbake workshop-image
Flashable image found inside build folder at:
tmp/deploy/images/raspberrypi0-wifi/workshop-raspberrypi0-wifi.rpi-sdimg
Root filesystem found inside build folder at:
tmp/work/raspberrypi0_wifi-poky-linux-gnueabi/workshop-image/1.0-r0/rootfs
Too much?
I thought so too!
Let's keep in
touch!
https://www.linkedin.com/in/
platisd/
dimitris@platis.solutions
@PlatisSolutions

Mais conteúdo relacionado

Mais procurados

yocto_scale_handout-with-notes
yocto_scale_handout-with-notesyocto_scale_handout-with-notes
yocto_scale_handout-with-notes
Steve Arnold
 
Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7
Etsuji Nakai
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.
 

Mais procurados (19)

App container rkt
App container rktApp container rkt
App container rkt
 
Yocto Project Dev Day Prague 2017 - Advanced class - Kernel modules with eSDK
Yocto Project Dev Day Prague 2017 - Advanced class - Kernel modules with eSDKYocto Project Dev Day Prague 2017 - Advanced class - Kernel modules with eSDK
Yocto Project Dev Day Prague 2017 - Advanced class - Kernel modules with eSDK
 
E D - Environmental Dependencies in Python
E D - Environmental Dependencies in PythonE D - Environmental Dependencies in Python
E D - Environmental Dependencies in Python
 
Introduction to Project atomic (CentOS Dojo Bangalore)
Introduction to Project atomic (CentOS Dojo Bangalore)Introduction to Project atomic (CentOS Dojo Bangalore)
Introduction to Project atomic (CentOS Dojo Bangalore)
 
yocto_scale_handout-with-notes
yocto_scale_handout-with-notesyocto_scale_handout-with-notes
yocto_scale_handout-with-notes
 
Red Hat Enterprise Linux OpenStack Platform 7 - VM Instance HA Architecture
Red Hat Enterprise Linux OpenStack Platform 7 - VM Instance HA ArchitectureRed Hat Enterprise Linux OpenStack Platform 7 - VM Instance HA Architecture
Red Hat Enterprise Linux OpenStack Platform 7 - VM Instance HA Architecture
 
Docker 활용법: dumpdocker
Docker 활용법: dumpdockerDocker 활용법: dumpdocker
Docker 활용법: dumpdocker
 
Openshift meetup Paris - 21/03/2018
Openshift meetup Paris - 21/03/2018Openshift meetup Paris - 21/03/2018
Openshift meetup Paris - 21/03/2018
 
Marco Cavallini @ LinuxLab 2018 : Workshop Yocto Project, an automatic genera...
Marco Cavallini @ LinuxLab 2018 : Workshop Yocto Project, an automatic genera...Marco Cavallini @ LinuxLab 2018 : Workshop Yocto Project, an automatic genera...
Marco Cavallini @ LinuxLab 2018 : Workshop Yocto Project, an automatic genera...
 
Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7Linux Container Technology inside Docker with RHEL7
Linux Container Technology inside Docker with RHEL7
 
Tech Talk - Vagrant
Tech Talk - VagrantTech Talk - Vagrant
Tech Talk - Vagrant
 
Rootless Kubernetes
Rootless KubernetesRootless Kubernetes
Rootless Kubernetes
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demo
 
Autobuilder2 Yocto Project Summit Lyon 2019
Autobuilder2 Yocto Project Summit Lyon 2019Autobuilder2 Yocto Project Summit Lyon 2019
Autobuilder2 Yocto Project Summit Lyon 2019
 
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
Django로 만든 웹 애플리케이션 도커라이징하기 + 도커 컴포즈로 개발 환경 구축하기
 
Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013Working with the AOSP - Linaro Connect Asia 2013
Working with the AOSP - Linaro Connect Asia 2013
 
Ansible Workshop for Pythonistas
Ansible Workshop for PythonistasAnsible Workshop for Pythonistas
Ansible Workshop for Pythonistas
 
TOMOYO Linux on Android
TOMOYO Linux on AndroidTOMOYO Linux on Android
TOMOYO Linux on Android
 
td
tdtd
td
 

Semelhante a How to create your own Linux distribution (embedded-gothenburg)

System Imager.20051215
System Imager.20051215System Imager.20051215
System Imager.20051215
guest95b42b
 
UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70
UGIF
 
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Nicolas Desachy
 
the NML project
the NML projectthe NML project
the NML project
Lei Yang
 

Semelhante a How to create your own Linux distribution (embedded-gothenburg) (20)

Building Embedded Linux UDOONEO
Building Embedded Linux UDOONEOBuilding Embedded Linux UDOONEO
Building Embedded Linux UDOONEO
 
A million ways to provision embedded linux devices
A million ways to provision embedded linux devicesA million ways to provision embedded linux devices
A million ways to provision embedded linux devices
 
Building and Customizing CoreOS
Building and Customizing CoreOSBuilding and Customizing CoreOS
Building and Customizing CoreOS
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Project ACRN Yocto Project meta-acrn layer introduction
Project ACRN Yocto Project meta-acrn layer introductionProject ACRN Yocto Project meta-acrn layer introduction
Project ACRN Yocto Project meta-acrn layer introduction
 
Slim Server Theory
Slim Server TheorySlim Server Theory
Slim Server Theory
 
RunX ELCE 2020
RunX ELCE 2020RunX ELCE 2020
RunX ELCE 2020
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
System Imager.20051215
System Imager.20051215System Imager.20051215
System Imager.20051215
 
UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70UGIF 12 2010 - features11.70
UGIF 12 2010 - features11.70
 
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
Informix User Group France - 30/11/2010 - Fonctionalités IDS 11.7
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 
Howto Pxeboot
Howto PxebootHowto Pxeboot
Howto Pxeboot
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
the NML project
the NML projectthe NML project
the NML project
 
CEHv10 M0 Introduction.pptx
CEHv10 M0 Introduction.pptxCEHv10 M0 Introduction.pptx
CEHv10 M0 Introduction.pptx
 
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
Badge Hacking with Nerves Workshop - ElixirConf 2016 - Justin Schneck and Fra...
 
Build and Run Android N Source Ccode on NXP SABRESD platform
Build and Run Android N Source Ccode on NXP SABRESD platformBuild and Run Android N Source Ccode on NXP SABRESD platform
Build and Run Android N Source Ccode on NXP SABRESD platform
 
Universal Userland
Universal UserlandUniversal Userland
Universal Userland
 
Christchurch Embedded .NET User Group - Introduction to Microsoft Embedded pl...
Christchurch Embedded .NET User Group - Introduction to Microsoft Embedded pl...Christchurch Embedded .NET User Group - Introduction to Microsoft Embedded pl...
Christchurch Embedded .NET User Group - Introduction to Microsoft Embedded pl...
 

Mais de Dimitrios Platis

Introduction to CMake
Introduction to CMakeIntroduction to CMake
Introduction to CMake
Dimitrios Platis
 

Mais de Dimitrios Platis (10)

[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)
 
OpenAI API crash course
OpenAI API crash courseOpenAI API crash course
OpenAI API crash course
 
Builder pattern in C++.pdf
Builder pattern in C++.pdfBuilder pattern in C++.pdf
Builder pattern in C++.pdf
 
Interprocess communication with C++.pdf
Interprocess communication with C++.pdfInterprocess communication with C++.pdf
Interprocess communication with C++.pdf
 
Lambda expressions in C++
Lambda expressions in C++Lambda expressions in C++
Lambda expressions in C++
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
 
Introduction to CMake
Introduction to CMakeIntroduction to CMake
Introduction to CMake
 
Afry software safety ISO26262 (Embedded @ Gothenburg Meetup)
Afry software safety ISO26262 (Embedded @ Gothenburg Meetup)Afry software safety ISO26262 (Embedded @ Gothenburg Meetup)
Afry software safety ISO26262 (Embedded @ Gothenburg Meetup)
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++
 
Refactoring for testability c++
Refactoring for testability c++Refactoring for testability c++
Refactoring for testability c++
 

Último

Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Marc Lester
 

Último (20)

The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...
Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...
Sinoville Clinic ](+27832195400*)[🏥Abortion Pill Prices Sinoville ● Women's A...
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024OpenChain @ LF Japan Executive Briefing - May 2024
OpenChain @ LF Japan Executive Briefing - May 2024
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?Prompt Engineering - an Art, a Science, or your next Job Title?
Prompt Engineering - an Art, a Science, or your next Job Title?
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 

How to create your own Linux distribution (embedded-gothenburg)

  • 1. How to create your own Linux distribution Dimitris Platis dimitris@platis.solutions
  • 2. About me Dimitrios Platis ● Grew up in Rodos, Greece ● Software Engineer @ Zenseact, Gothenburg ● Course responsible @ DIT112, Gothenburg University ● Interests: ○ Embedded systems ○ Software Architecture ○ API Design ○ Open source software & hardware ○ Robots, Portable gadgets, IoT ○ 3D printing ○ Autonomous Driving ● Website: https://platis.solutions
  • 4. Topics ● Why create your own Linux distribution? ● What is Yocto? ● How to configure hardware & software? ● How to include your own component in an image? ● How to launch your component on boot? ● How to connect to WiFi on boot? ● How to cross compile for your distro? ● How to configure the Linux kernel?
  • 5. Demo platform ● dimitriOS RPi Zero Wifi ● WiFi connection on boot ● /usr/bin/employee_getter
  • 6. Why dimitriOS? platisd/meta-dimitriOS ● Got tired of following the golden image approach ● As projects get complex, maintaining a modified image becomes unsustainable ● Reproducibility is really low ● Maintaining variants would be a nightmare ● Updating to a new operating system version would require major rework ● Need a standardized, version controllable method to configure and create embedded operating systems
  • 7. About Yocto ● "Umbrella open source project that builds and maintains validated open source tools and components associated with embedded Linux" ● A collection of tools and processes enabling the creation of configurable Linux distributions ● Used a lot for embedded systems ○ IoT ○ Automotive ○ Wearables ○ Industry ● Open source ● Little to no assumptions on hardware architecture, programming languages, init system etc ● Good documentation (but too much for beginners)
  • 8. Basic glossary Recipe: Specifies how a particular package is built. They include all the dependencies, source code locations, configuration, compilation, build, install and remove instructions. They are stored in layers. (employee-getter_git.bb) Layer: A collection of related recipes. Layers allow you to customize your build, and isolate information for multiple architecture builds. Layers are hierarchical in their ability to override previous specifications. (meta-dimitriOS) Bitbake: a scheduler and execution engine which parses recipes. It then creates a dependency tree to order the compilation, schedules the compilation of the included code, and finally, executes the building of the specified, custom Linux image.
  • 9. Basic glossary .conf files: Files which hold global definitions of variables, user defined variables and hardware configuration information. They tell the build system what to build and put into the image to support a particular platform. (local.conf, dimitrios.conf) OpenEmbedded-Core: oe-core is meta-data comprised of foundation recipes, classes and associated files that are meant to be common among many different OpenEmbedded-derived systems, including the Yocto Project. (meta-openembedded) BSP: The Board Support Package. A layer containing hardware-specific drivers and utilities, necessary for the Operating System to function. (meta-raspberrypi)
  • 10. Basic glossary Packages: The output of the build system used to create your final image. (.rpm, .deb etc) Distribution: A hardware-agnostic (abstract) representation of an operating system. (dimitriOS.conf) Image: A binary form of a Linux distribution (operating system) intended to be flashed onto a device. (.bin, .sdcard etc) Read more
  • 11. Poky Poky: A reference embedded distribution and a reference test configuration created to provide a base level functional distro which can be used to illustrate how to customize a distribution
  • 12. (Over)Simplified layered system view Vendor BSP (RPi drivers etc) Linux kernel Your Distro (dimitriOS common functionality) Your product variant (workshop-image) employee_getter
  • 13. Down the rabbit hole $ repo init -u https://github.com/platisd/dimitriOS-manifest.git -m dimitriOS-rpi.xml $ repo sync ➢ dimitriOS-rpi.xml ➢ dimitriOS-base.xml $ export TEMPLATECONF=~/dimitriOS/layers/meta-dimitriOS/rpi-conf/ ➢ rpi-conf/bblayers.conf(.sample) ➢ rpi-conf/local.conf(.sample) ➢ conf/distro/dimitriOS.conf $ . layers/poky/oe-init-build-env build $ export MACHINE=raspberrypi4 $ bitbake workshop-image ➢ workshop-image/workshop-image.bb ➢ employee-getter/employee-getter_git.bb ➢ wifi-autoconnect/wifi-autoconnect_git.bb
  • 14. Fetching the sources (dimitrios-rpi.xml) <?xml version="1.0" encoding="UTF-8"?> <manifest> <include name="dimitriOS-base.xml" /> <remote fetch="git://git.yoctoproject.org" name="yocto"/> <project name="meta-raspberrypi" remote="yocto" revision="dunfell" path="layers/meta-raspberrypi"/> </manifest>
  • 15. Fetching the sources (dimitrios-base.xml) <?xml version="1.0" encoding="UTF-8"?> <manifest> <remote fetch="git://git.yoctoproject.org" name="yocto"/> <remote fetch="git://git.openembedded.org" name="oe"/> <remote fetch="git://github.com/platisd" name="origin"/> <default sync-j="4"/> <project name="poky" remote="yocto" revision="dunfell" path="layers/poky"/> <project name="meta-openembedded" remote="oe" revision="dunfell" path="layers/meta-openembedded"/> <project name="meta-dimitriOS" remote="origin" revision="master" path="layers/meta-dimitriOS"/> </manifest>
  • 16. Hardware configuration (rpi-conf/bblayers.conf) BBLAYERS ?= " ${TOPDIR}/../layers/poky/meta ${TOPDIR}/../layers/poky/meta-poky ${TOPDIR}/../layers/meta-raspberrypi ${TOPDIR}/../layers/meta-dimitriOS ${TOPDIR}/../layers/meta-openembedded/meta-oe ${TOPDIR}/../layers/meta-openembedded/meta-networking ${TOPDIR}/../layers/meta-openembedded/meta-python ${TOPDIR}/../layers/meta-openembedded/meta-gnome "
  • 17. Hardware configuration (rpi-conf/local.conf) IMAGE_FSTYPES = "rpi-sdimg" IMAGE_OVERHEAD_FACTOR = "1.5" IMAGE_INSTALL_append = " linux-firmware-rpidistro-bcm43430" IMAGE_INSTALL_append = " kernel-module-brcmfmac" DISABLE_SPLASH = "1" BOOT_DELAY = "0" BOOT_DELAY_MS = "0" MACHINE ?= "raspberrypi0-wifi" DISTRO = "dimitriOS"
  • 18. Software configuration (distro/dimitriOS.conf) require conf/distro/poky.conf DISTRO = "dimitriOS" DISTRO_NAME = "dimitriOS" SYSTEMD_BOOT_TIMEOUT := "0" PACKAGE_CLASSES ?= " package_rpm" DISTRO_FEATURES_append = " wifi systemd" DISTRO_FEATURES_BACKFILL_CONSIDERED += "sysvinit" VIRTUAL-RUNTIME_init_manager = "systemd" VIRTUAL-RUNTIME_initscripts = "" PREFERRED_PROVIDER_udev ?= "systemd" PREFERRED_PROVIDER_udev-utils ?= "systemd" hostname_pn-base-files = "dimitrios" CORE_IMAGE_EXTRA_INSTALL += "openssh" CORE_IMAGE_EXTRA_INSTALL += "usbutils"
  • 19. Image configuration (workshop-image.bb) require recipes-core/images/core-image-minimal.bb IMAGE_BASENAME = "workshop" IMAGE_INSTALL_append = " employee-getter" IMAGE_INSTALL_append = " wifi-autoconnect" EXTRA_USERS_PARAMS = " useradd -P workshop grcpp; " inherit extrausers
  • 20. Component recipe (employee-getter_git.bb) DEPENDS = " curl nlohmann-json " RDEPENDS_${PN} = " libcurl " SRC_URI = " git://github/platisd/example-dimitriOS-cmake-project file://employee-getter.service " SRCREV = "${AUTOREV}" do_install_append() { install -d ${D}/${systemd_system_unitdir} install -m 0644 ${WORKDIR}/employee-getter.service ${D}/${systemd_system_unitdir} } REQUIRED_DISTRO_FEATURES= "systemd" SYSTEMD_SERVICE_${PN} = "employee-getter.service" inherit cmake features_check systemd
  • 22. WiFi on boot (wifi-autoconnect.bb) See also: ● dimitrios-wifi-wlan0.service RDEPENDS_${PN} = " wpa-supplicant " SRC_URI = " file://98-wireless-interface-naming.link file://dimitrios-wifi-wlan0.service " do_install() { install -d ${D}/${systemd_system_unitdir} install -m 0644 ${WORKDIR}/dimitrios-wifi-wlan0.service ${D}/${systemd_system_unitdir} install -d ${D}${sysconfdir}/systemd/network/ install -m 0644 ${WORKDIR}/98-wireless-interface-naming.link ${D}${sysconfdir}/systemd/network/ } REQUIRED_DISTRO_FEATURES= "systemd" SYSTEMD_SERVICE_${PN} = " dimitrios-wifi-wlan0.service " inherit systemd features_check
  • 23. WiFi on boot (wpa-supplicant_%.bbappend) See also: ● wpa_supplicant.conf ● systemd-conf_%.bbappend ● wifi.network FILESEXTRAPATHS_prepend := "${THISDIR}/files:" SRC_URI += " file://wpa_supplicant.conf " WIFI_SSID ??= "ssid" WIFI_PASSWORD ??= "password" do_install_append() { install -d ${D}/${sysconfdir}/wpa_supplicant install -m 0644 ${WORKDIR}/wpa_supplicant.conf ${D}/${sysconfdir}/wpa_supplicant sed -i 's/default_ssid/'"${WIFI_SSID}"'/g' ${D}/${sysconfdir}/wpa_supplicant/wpa_supplicant.conf sed -i 's/default_password/'"${WIFI_PASSWORD}"'/g' ${D}/${sysconfdir}/wpa_supplicant/wpa_supplicant.conf } FILES_${PN} += " ${sysconfdir} "
  • 24. Environment variables (BB_ENV_EXTRAWHITE) The build does not have access to your host's environment variables unless they are stated in BB_ENV_EXTRAWHITE! 1. Export variables ● export WIFI_SSID=your-ssid ● export WIFI_PASSWORD=your-password 2. Register them through BB_ENV_EXTRAWHITE ● export BB_ENV_EXTRAWHITE="WIFI_SSID WIFI_PASSWORD"
  • 25. Cross-compile for your embedded OS To cross compile an executable that will run on your embedded OS, you need: 1. Compiler toolchain for the target system 2. All dependencies compiled for the target system This is very cumbersome to set up manually! To cross-compiling employee_getter, what about: ⁇ Compiler for Raspberry Pi ⁇ Compile-time dependencies: ○ #include <curl/curl.h> ○ #include <nlohmann/json.hpp>
  • 26. Cross-compile for your embedded OS Yocto can produce an SDK for you! Cross compiling for your image now becomes trivial: 1. Build SDK ● bitbake workshop-image -c populate_sdk 2. Install SDK ● ./dimitriOS-glibc-x86_64-workshop-arm1176jzfshf-vfp-raspberrypi0-wifi-toolchain-3.1.4.sh 3. Source SDK ● . ~/opt/dimitriOS/3.1.4/environment-setup-arm1176jzfshf-vfp-poky-linux-gnueabi 4. Configure and build (e.g. with CMake and make) ● mkdir build ● cd build ● cmake .. ● make 5. Verify employee_getter is cross-compiled: ● file employee_getter > employee_getter: ELF 32-bit LSB shared object, ARM
  • 27. Configure Linux kernel with fragments If you need to load or remove kernel modules, you can use the menuconfig tool to produce fragments (.cfg) and include them to your image. ● Run menuconfig for RPi ○ bitbake linux-raspberrypi -c menuconfig ● diff the new configuration and place the delta into a .cfg file ○ CONFIG_ATH9K_AHB=y ● Append to the kernel recipe ○ linux-raspberrypi_%.bbappend For more on how to get started, look at the QuickAndDirtyKernelConfig guide.
  • 28. Building the image ● Takes a long time at first! ● You are building the entire OS from source ● Bitbake will try to utilize all your CPU cores ● Tip: Let it run over night $ bitbake workshop-image Flashable image found inside build folder at: tmp/deploy/images/raspberrypi0-wifi/workshop-raspberrypi0-wifi.rpi-sdimg Root filesystem found inside build folder at: tmp/work/raspberrypi0_wifi-poky-linux-gnueabi/workshop-image/1.0-r0/rootfs