UNIT 04 · BUILDING AND RUNNING FIRMWARE

The Build Toolchain

From text files to the bytes in flash.

6 lessons24 guided experiments56 min full read

A firmware image is not written; it is built. Dozens of source files pass through a preprocessor, a compiler and an assembler into object files full of placeholders, and a linker, steered by a script that describes the chip’s memory, stitches them into one image with every address decided. When a build fails with an undefined reference, when RAM overflows by 312 bytes, when a function is mysteriously missing from the binary or a release cannot be rebuilt bit for bit, the explanation is in this pipeline, and the tools to read it (nm, objdump, size, the map file) come with every toolchain.

Start with lesson 1 →

The unit in six ideas

  1. 1A cross toolchain runs on your PC and targets the chip; the triple arm-none-eabi names architecture, OS (none) and ABI.
  2. 2The linker resolves every undefined symbol to exactly one definition, then relocates: patches every placeholder with its formula.
  3. 3An ELF object holds sections, a symbol table (16-byte entries with binding and type) and relocations; objdump -h, nm and objdump -r show them.
  4. 4MEMORY names the chip’s regions; SECTIONS maps input sections to output sections and regions. Both come from the datasheet, not the compiler.
  5. 5size’s Berkeley columns: text (code and constants), data (initialised), bss (zeroed). Flash = text + data; RAM = data + bss, plus stack and heap.
  6. 6Configurations differ in optimisation, debug information and assertions; -g does not change code, NDEBUG removes asserts and their side effects.

Lessons

  1. LESSON 01 · 4 EXPERIMENTS · 10 MIN

    From Source Code to Machine Code

    What did each one do, and why can the number 466 only be computed at the very end?

  2. LESSON 02 · 4 EXPERIMENTS · 9 MIN

    Compiling, Assembling, and Linking

    What rules is the linker applying, and what exactly does it do to the bytes the assembler produced?

  3. LESSON 03 · 4 EXPERIMENTS · 9 MIN

    Object Files, Symbols, and Libraries

    What is inside a .o, and how does the linker choose what to take from a .a?

  4. LESSON 04 · 4 EXPERIMENTS · 10 MIN

    Linker Scripts and Memory Sections

    What does that file say, and how does it turn a pile of sections into an image with every address decided?

  5. LESSON 05 · 4 EXPERIMENTS · 9 MIN

    Reading a Map File and Disassembly

    How do you read each?

  6. LESSON 06 · 4 EXPERIMENTS · 9 MIN

    Build Configurations and Reproducible Builds

    What makes a build fast, correct and repeatable?