Bootloader Development Guide: Designing a Stable Boot Program for Embedded Systems

Bootloader Development Guide: Designing a Stable Boot Program for Embedded Systems

1. Basic Concepts

In embedded operating systems, BootLoader runs before the operating system kernel and is the first piece of code executed after the system is powered on. It initializes hardware devices, establishes a memory space mapping, and configures the system’s software/hardware environment to an appropriate state to prepare the environment for the operating system kernel. Its main task is to first read the kernel image from the hard disk into RAM and then jump to the kernel’s entry point to run it, thus starting the operating system. In embedded systems, the entire system loading and startup are completed by the BootLoader.

2. Boot Methods

Embedded systems generally manage data or programs using a unified addressing method. After powering on or resetting the system, the microprocessor typically fetches commands from a pre-arranged address set by its manufacturer. For example, microprocessors based on ARM cores usually fetch their first command from 0x00000000. Embedded systems typically have some type of solid-state storage device mapped to this pre-arranged address, where the BootLoader is burned, so after the system is powered on or reset, the microprocessor will first execute the BootLoader.

<1> Boot Media

The BootLoader provides several boot methods: Flash Boot, SD Card Boot, Network Boot, DRAM Boot, etc. Flash is non-volatile memory, and any write operation to Flash can only be performed in empty or erased cells, so an erase operation must be performed before writing.

Flash is divided into NAND Flash and NOR Flash, and their characteristics are compared in the table below.

Flash Type Advantages Disadvantages
NAND Flash Read speed is slightly faster, can be used to store executable programs Write speed is slightly slower, relatively expensive
NOR Flash Simple production process, low cost, write speed is slightly faster Difficult to store running programs, more used for data storage

The comparison of boot methods is as follows.

Boot Method Characteristics
NOR Flash Boot The BootLoader can run on NOR Flash, but for complex systems, it should be imported into memory for execution.
NAND Flash Boot The BootLoader is copied from NAND Flash to SDRAM for execution.
SD Card Boot The BootLoader is copied from the SD card to SDRAM for execution.

<2> Boot Process

The boot process of the BootLoader can be divided into two stages.

  • The first stage mainly includes hardware initialization code dependent on the microprocessor architecture, usually implemented in assembly language. The tasks of this stage include:
    • Hardware initialization (masking all interrupts, disabling the processor’s internal command/data Cache, etc.).
    • Preparing RAM space for the second stage.
    • Setting up the stack.
    • Jumping to the entry point of the second stage C program.
  • The second stage code is generally written in C, which can implement more complex functions and improve the program’s readability and portability. The tasks of this stage include:
    • Initializing the hardware devices used in this stage.
    • Detecting system memory mapping.
    • Reading the kernel image and root filesystem image from Flash into RAM.
    • Setting boot parameters for the kernel.
    • Calling the kernel.

<3> Common Bootloaders

U-Boot
  • Overview
    • U-Boot (Universal Boot Loader) is an open-source bootloader widely used in various embedded systems. It supports multiple hardware platforms such as ARM, MIPS, PowerPC, x86, etc., and various storage media such as NAND Flash, eMMC, SD cards, SPI Flash, etc.
  • Features:
    • Supports multiple file systems (e.g., ext4, FAT, UBIFS, NFS, etc.).
    • Can be booted via serial port, network, USB, etc.
    • Provides a command-line interface for manual command input for debugging.
    • Supports environment variable configuration, allowing dynamic modification of boot parameters at runtime.
    • Supports automated booting (e.g., specifying kernel and root filesystem locations through boot scripts).
  • Use Cases
    • The most commonly used bootloader in embedded systems, suitable for most devices with complex requirements.
Barebox
  • Overview
    • Barebox is an open-source bootloader mainly used for embedded systems, with functionality similar to U-Boot. Its goal is to provide a simple, portable bootloader that supports fast booting.
  • Features
    • Fast booting speed.
    • Supports various hardware platforms, especially with good support on ARM architecture.
    • Supports multiple file systems (e.g., ext4, FAT, NFS, UBIFS, etc.).
    • Provides a concise command-line interface, making configuration and debugging relatively easy.
  • Use Cases
    • Suitable for embedded devices that require fast booting and have limited resources, especially applications on ARM platforms.
RedBoot
  • Overview
    • RedBoot is an early embedded bootloader mainly used for embedded system development. Its main feature is supporting network booting (TFTP) and providing some debugging capabilities.
  • Features:
    • Supports network booting, serial port booting, storage device booting, etc.
    • Provides complete debugging capabilities, suitable for embedded system development.
    • Has high customizability and flexibility.
    • Supports multiple processor architectures (e.g., ARM, PowerPC, etc.).
  • Use Cases
    • Used for development and debugging of embedded systems, supporting network booting and recovery.
Coreboot
  • Overview
    • Coreboot is an open-source bootloader designed for embedded devices, aiming to provide a streamlined and efficient boot program. Unlike traditional bootloaders like U-Boot, Coreboot focuses primarily on system boot speed and code optimization, typically used in embedded devices that require high-performance booting.
  • Features
    • Extremely fast boot speed, capable of completing booting within hundreds of milliseconds.
    • Supports various hardware platforms, including traditional PCs and embedded devices.
    • Supports booting various operating systems, such as Linux, SeaBIOS, etc.
    • Implements richer boot functionality by integrating other open-source projects (like SeaBIOS, Grub, Linux, etc.).
  • Use Cases
    • Embedded devices with high-performance boot requirements, such as routers, servers, industrial control devices, etc.
Bootloader Development Guide: Designing a Stable Boot Program for Embedded Systems

Previous Recommendations

RECOMMEND

Bootloader Development Guide: Designing a Stable Boot Program for Embedded Systems

[1]. Multithreading Programming: Concurrency and Parallelism

[2]. In-Depth Analysis of Linux System Architecture: How Your Code Boots Step by Step

[3]. Avoiding Thread Collisions: In-Depth Analysis of Barrier Mechanisms

[4]. Spinlock vs Mutex: Which is More Suitable for Your Program?

I am Aike, an embedded software engineer.

Follow me for more embedded insights.

Remember to like, share, and turn on notifications,

Your encouragement is my greatest motivation to continue sharing!

See you next time.

Looking forward to your

Share

Like

Notifications

NEWS

WeChat IDaike_eureka

Baijiahao|Playing with Embedded Systems

Leave a Comment