Skip to content

darshankharbikar/Embedded-Linux-using-yocto

Repository files navigation

Yocto Project Overview

What is Yocto?


  • The Yocto Project is an open-source framework used to create custom Linux distributions for embedded systems.
  • It provides a collection of tools, templates, metadata, and processes for building Embedded Linux systems.
  • Yocto allows developers to create a Linux operating system tailored specifically to their hardware and application requirements instead of using a general-purpose distribution such as Ubuntu.
  • Yocto is not a Linux distribution itself; it is a build system and ecosystem for generating Linux distributions.

Why Yocto is Used


Build Optimized Embedded Linux Systems

  • Create minimal and lightweight Linux images.
  • Include only the components required by the target device.
  • Reduce storage, memory, and boot time requirements.

Complete System Control

Yocto provides control over:

  1. Bootloader
  2. Linux Kernel
  3. Device Tree
  4. Libraries
  5. Applications
  6. Root Filesystem
  7. Software Packages

Multi-Architecture Support

Supports multiple processor architectures:

  • ARM
  • ARM64 (AArch64)
  • x86
  • x86_64
  • RISC-V
  • MIPS
  • PowerPC

Industry Adoption

Widely used in:

  • Automotive Systems
  • Telecommunications Equipment
  • Industrial Automation
  • Medical Devices
  • Consumer Electronics
  • IoT Gateways
  • Networking Products

Key Components of Yocto

1. BitBake

BitBake is the build engine of the Yocto Project.

Responsibilities:

  • Parses recipes and metadata
  • Resolves dependencies
  • Executes build tasks
  • Creates packages
  • Generates root filesystems and images

Think of BitBake as:

make + package manager + dependency resolver + build orchestrator

Example:

bitbake core-image-minimal

2. Recipes (.bb Files)

Recipes describe how a software package should be built.

A recipe contains:

  • Source location
  • Dependencies
  • Configure instructions
  • Compilation instructions
  • Installation instructions

Example:

busybox.bb

Typical recipe contents:

SRC_URI
LICENSE
DEPENDS

do_configure()
do_compile()
do_install()

3. Layers

Layers are logical collections of:

  • Recipes
  • Configuration files
  • Metadata

Layers improve:

  • Modularity
  • Reusability
  • Maintainability

Common layers:

meta
meta-poky
meta-openembedded
meta-raspberrypi
meta-custom

4. BSP (Board Support Package)

A BSP layer provides hardware-specific support.

Contains:

  • Kernel configuration
  • Device Trees
  • Bootloader settings
  • Drivers
  • Firmware

Example:

meta-raspberrypi

Supported boards may include:

  • Raspberry Pi
  • BeagleBone
  • NXP i.MX
  • STM32MP1
  • Xilinx Zynq

5. Poky

Poky is the reference distribution of the Yocto Project.

It includes:

  • BitBake
  • OpenEmbedded-Core Metadata
  • Build Tools
  • Documentation
  • Example Configurations

Poky serves as the starting point for most Yocto-based projects.


6. Images

Images are the final output generated by Yocto.

Examples:

core-image-minimal
core-image-base
core-image-full-cmdline

Generated formats:

.wic
.img
.ext4
.tar.gz

7. SDK (Software Development Kit)

Yocto can generate an SDK containing:

  • Cross Compiler
  • Libraries
  • Header Files
  • Debugging Tools

Used for application development outside the Yocto build environment.


Yocto Build Process

Step 1: Install Host Dependencies

Install required packages on the build machine.

Examples:

g++
make
chrpath
cpio
diffstat
zstd
lz4
git
python3

Step 2: Download Poky

git clone git://git.yoctoproject.org/poky

Poky contains:

bitbake
meta
meta-poky
meta-yocto-bsp
scripts

Step 3: Initialize Build Environment

source oe-init-build-env

Creates:

build/
 ├── conf/
 │    ├── local.conf
 │    └── bblayers.conf

Step 4: Select Target Hardware

Configure the target machine.

Example:

MACHINE = "raspberrypi4-64"

This determines:

  • Kernel
  • Device Tree
  • Bootloader
  • BSP Components

Step 5: Configure Layers

Edit:

conf/bblayers.conf

Example:

BBLAYERS += "meta-raspberrypi"

Step 6: Configure Build Settings

Edit:

conf/local.conf

Common settings:

MACHINE
DL_DIR
SSTATE_DIR
IMAGE_INSTALL
EXTRA_IMAGE_FEATURES

Step 7: Build the Image

bitbake core-image-minimal

BitBake performs:

Fetch Sources
      ↓
Unpack Sources
      ↓
Apply Patches
      ↓
Configure
      ↓
Compile
      ↓
Install
      ↓
Package
      ↓
Generate RootFS
      ↓
Create Image

Step 8: Locate Generated Image

Generated files are stored in:

tmp/deploy/images/<machine>/

Examples:

core-image-minimal.wic
core-image-minimal.ext4
Image
zImage
uImage

Step 9: Flash Image to Target

Example:

sudo dd if=image.wic of=/dev/sdX bs=4M status=progress

Alternative tools:

  • Raspberry Pi Imager
  • Balena Etcher

Step 10: Boot the Device

Typical Embedded Linux boot sequence:

ROM Code
   ↓
Bootloader (U-Boot)
   ↓
Linux Kernel
   ↓
Device Tree
   ↓
Root Filesystem
   ↓
Init/Systemd
   ↓
Applications

Directory Structure

poky/
├── bitbake/
├── meta/
├── meta-poky/
├── meta-yocto-bsp/
├── build/
│   ├── conf/
│   └── tmp/

Important directories:

Directory Purpose
build/ Build output and configuration
conf/ Build configuration files
meta*/ Metadata layers
tmp/ Build artifacts
downloads/ Downloaded source code
sstate-cache/ Shared state cache
deploy/ Final images and packages

Customization Workflow

Create a Custom Layer

bitbake-layers create-layer meta-custom

Add the layer:

bitbake-layers add-layer meta-custom

Add a Custom Application

Create:

recipes-apps/myapp/myapp.bb

BitBake will:

Fetch
Compile
Install
Package

Modify Existing Recipes

Use:

.bbappend

Example:

busybox_%.bbappend

Avoid modifying upstream recipes directly.


Create a Custom Distribution

Configure:

meta-custom/conf/distro/

Customize:

DISTRO_FEATURES
INIT_MANAGER
PREFERRED_VERSION
PACKAGE_CLASSES

Advantages

  • Highly customizable
  • Reproducible builds
  • Supports multiple architectures
  • Excellent package management
  • Scalable for large products
  • Strong community support
  • Long-Term Support (LTS) releases available

Challenges

  • Steep learning curve
  • Long build times
  • Complex dependency management
  • Debugging build failures can be difficult
  • Requires strong Linux fundamentals

Common Use Cases

  • Embedded Linux Devices
  • Automotive Infotainment Systems
  • Industrial Controllers
  • Medical Equipment
  • Smart Home Devices
  • Routers and Networking Equipment
  • IoT Gateways
  • Robotics Platforms

Learning Path

Embedded Linux Fundamentals
            ↓
Yocto Fundamentals
            ↓
Poky Architecture
            ↓
BitBake
            ↓
Layers
            ↓
Recipes
            ↓
Configuration Files
            ↓
Image Creation
            ↓
BSP Development
            ↓
Kernel & Device Tree Customization
            ↓
Custom Layers
            ↓
Application Integration
            ↓
Custom Linux Distribution

This progression mirrors the workflow followed by Embedded Linux BSP, Linux Kernel, and Device Driver engineers when developing production-grade embedded systems.

About

Learning yocto from scratch

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages