Bootloaders In Embedded System - Architecture And Features
In the last blog, we discussed different ways or methods of updating applications in electronic devices and the potential losses for product owners in case of failure. Today, right from low end microcontroller-based devices such as instrument clusters to high end processors such as mobile phones, require firmware upgrades. So, designing a robust and fail-safe upgrade architecture is crucial for the embedded system. Normally DFU (Device firmware upgrade) features will be part of bootloaders in embedded system. There are plenty of bootloaders available in market such as U-boot,? Barebox, BURG, Clover, Coreboot, GNUGRUB, LILO, RedBoot, rEFInd,Smart BootManager, Syslinux, systemd-boot, Tianocore EDK2, U-Boot, UEFI EDK2, xOSL, Yaboot, etc to support DFU. In this blog, we will cover bootloader architecture, stages and ready to use bootloaders available in the market.?
Bootloader architecture?
Booting sequence of an electronic product has following 5 stages?
1. Reset: Device powered on or reset. System initializes internal circuits.?
2. Read Boot Pins: The device reads the boot pins to determine the boot source.?
3. Load Bootloader: Based on the boot source, the MCU/MPU loads the bootloader into RAM. This might involve reading from internal flash, external memory, or another source.?
4. Bootloader Execution: The bootloader initializes hardware, verifies firmware integrity (possibly using OTP-stored keys), and then loads the main application firmware.?
5. Main Application: The main application firmware is executed, which takes over control of the device operations.?
Above sequence has mainly below 3 components?
1. ROM Bootloader?
2. Bootloader with DFU?
3. Application?
Let’s see in detail below?
ROM Bootloaders in embedded system?
A ROM bootloader is a piece of code programmed to read-only memory of an embedded device by chip manufacturers. That code is the very first software that is executed after the chip is powered. One of the main functionalities of this code is to detect the boot source by reading boot pins or OTP (One Time Programmable) memory and proceed with loading the next software.?
Boot Source Configuration – Boot Pins?
Usually, there are specific BOOT pins in the chip dedicated for boot source selection. By having specific combination of high (1) and low (0) levels on these pins at reset or power-on determines the boot source. For example:?
BOOT0 = 0, BOOT1 = 0: Boot from internal flash.?
BOOT0 = 1, BOOT1 = 0: Boot from external flash.?
BOOT0 = 0, BOOT1 = 1: Boot from USB.?
BOOT0 = 1, BOOT1 = 1: Boot from SD Card.?
This configuration allows developers to select different boot options for development, testing, or production without changing the firmware.?
Boot Source Configuration - OTP Flash?
In some processors, OTP (One-Time Programmable) Flash is used to configure the boot medium. These settings or modes are configured in OTP to prevent unauthorized modifications of configured boot medium postproduction. As the code is in read-only memory, it is programmed into the chip once during production by the manufacturer before being shipped to the customer. Developers cannot modify this program.?
The above 2 configurations mostly go together, if OTP is not flashed in system, device will take BOOT pins configuration. Otherwise, the device will boot with configured boot medium in OTP.?
Bootloader with DFU?
This is the second software to get executed after powering on the electronic product after ROM Bootloader. Its main responsibility is to initialize the basic hardware peripherals, diagnostics, loading the application to RAM and launch the application.??
There are 2 types of bootloaders?
1. Single Stage Bootloader?
2. Multistage Bootloader?
Single Stage Bootloader?
A single-stage bootloader is used mainly for a system where sufficient memory is available and there is no need for complex initialization. It’s a straightforward design where the bootloader performs all necessary initializations and directly loads the main application firmware from a non-volatile memory (such as flash memory) and loads into RAM for execution or execute in place (XIP). This type of bootloader is typically small and simpler in design.???
领英推荐
Multistage Bootloader?
This Multistage bootloader is used in a product where memory is constrained, a system with complex initializations such as partition tamper validation, application decryption and custom DFU implementation.?
There are mostly 2 stages in this bootloader?
1. In the first stage, the system initializes basic chip peripherals, external peripherals such as EEPROM, RTC, CAN etc. flash and DRAM that are required for the second stage bootloader. It then loads the second bootloader firmware onto the DRAM and executes it. This is typically small (less than few KB’s) and fits in to the on-chip SRAM.?
2. The second stage bootloader is equipped with many features such as hardware peripheral tests, validating the integrity of application, selecting the right application based on boot configuration etc. The second stage bootloader is scalable, allowing for future expansion and updates without significant architecture changes. It can load applications from other media types as well.?
Bootloader Features?
Modern bootloaders are equipped with features such as secure booting, encryption/decryption, tamper detection, secure storage, file system support, boot logo, DFU, Network boot, CLI, Built in Self-test etc. We will see a few of them below.???
File system support?
Bootloader capable enough to interpret file systems such as FATFS, NTFS, EXT4, JFFS to locate and load firmware or other necessary files during the boot process. This is useful in systems where firmware or configuration data is stored on external storage devices like SD cards, USB devices, or other storage media. This helps in validating the integrity of the file system as well.?
Boot logo?
This feature helps in providing feedback to users on current progress by displaying an image or animation on the screen and product branding. It improves the user experience as the devices seem responsive as soon as they are switched on.?
Device Firmware Update?
This feature is responsible for upgrading the application for bug fixes, adding new features etc. There are multiple modes used as per hardware interfaces available such as USB DFU, Network DFU, Serial DFU. This feature takes care of receiving new application, verifying the application and flashing the same on the device memory.?
Network Boot??
This involves loading and running an operating system or software over a network connection using protocols such as TFTP, etc. As this process typically does not involve updating the firmware permanently stored in the device’s flash memory, loads the software to RAM directly and executes it, this is very helpful for development purposes.?
Command Line Interface??
It is a powerful feature for interacting with and controlling the bootloader environment. This interface allows developers and advanced users to perform a variety of tasks such as configuring boot parameters, debugging, and performing system updates.?
Secure boot?
The secure boot feature ensures that only trusted application is loaded during the boot process. This procedure involves verifying the digital signature of the application and any subsequent code it loads against the manufacturer configured during production. In case of verification failure, the system halts, preventing the execution of potentially malicious code.?
Tamper Detection?
Tamper detection feature support in bootloader will alert the system whether the firmware has been altered. This is achieved by using checksums, hash functions, or more advanced integrity verification techniques by leveraging the hardware engines.?
Popular Bootloaders in embedded system?
Below are few open source & commercial bootloaders available in market?
Conclusion?
Bootloaders are vital for initializing hardware, loading firmware, and ensuring secure transitions to the main application in embedded systems. While single-stage bootloaders are straightforward and suitable for simple systems, multi-stage bootloaders provide enhanced flexibility, security, and scalability for more complex needs. By understanding the different bootloader types, their features, and best practices, developers can design robust, efficient, and secure boot loading processes tailored to their specific requirements. Whether leveraging free or commercial solutions, choosing the right bootloader is crucial for the reliable operation of embedded devices.?
With our 2+ decades of experience in bootloader development and customization services, we deliver a secure solution with a feature set that matches your needs.?
Reference: