Origin Academy
← Back to course

Embedded Linux & Kernel Developer Phase 0 is free

Join the waitlist

Phase 0 · Module 1 of 5

The four parts of every embedded Linux system

How an embedded Linux system fits together · 11 min read

A router, a car dashboard and a smart meter can all run Linux, and despite looking nothing alike, they're built from the same four parts. Every week of this course is about one of them, so it's worth having the whole map from day one.

On the board

  • The bootloader (usually U-Boot) starts the hardware, loads the kernel and the Device Tree into memory, and jumps to the kernel. On many ARM chips, ROM code and Trusted Firmware run before it.
  • The kernel manages the CPU, memory and devices, and exposes them to programs. The Device Tree tells it what hardware the board has, because most of it can't be discovered automatically.
  • The root filesystem holds everything else: the C library, an init program, configuration, and your applications. It can be as small as a few megabytes with BusyBox.

On your workstation

The fourth part never ships on the device: the cross-compiling toolchain. Your laptop is probably x86-64 and the board is probably ARM, so you need a compiler that runs on one and produces programs for the other.

$ readelf -h /bin/ls | grep Machine
  Machine:                           Advanced Micro Devices X86-64

$ aarch64-linux-gnu-gcc -o hello hello.c      # cross-compile for 64-bit ARM
$ file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, ...

$ ./hello
bash: ./hello: cannot execute binary file: Exec format error

The program built fine, but your laptop's kernel reads its ELF header, sees it's for a different CPU, and refuses to run it. That error is a good sign: it means the toolchain did its job. You run the program on the board, or on your laptop under an emulator.

Your lab: QEMU, and a real board if you have one

Every lab in this course runs on QEMU, which emulates a complete ARM board on your laptop: bootloader, kernel, root filesystem and all. If you own a board such as an STM32MP157 Discovery kit or a BeagleBone, you can follow along on real hardware too, and mentors will help.

$ qemu-aarch64 -L /usr/aarch64-linux-gnu ./hello   # run one ARM program on x86
Hello from ARM64!

Try it

  • Run readelf -h on three programs on your machine. Do they all have the same Machine?
  • Install an ARM64 cross-compiler (on Ubuntu, the gcc-aarch64-linux-gnu package) and reproduce the Exec format error.
  • Draw the four parts for a device you own, such as your Wi-Fi router. Where does each part live: in flash, on an SD card, or only on the developer's laptop?

In the full course you build each part yourself: a toolchain with Crosstool-NG, U-Boot, the kernel and Device Tree, a root filesystem from scratch, then whole systems with Buildroot and Yocto, before writing and debugging your own kernel drivers.

Next in Phase 0

Hardware platforms and the development environment

Continue →