Join our subscribers list to get the latest news, updates and special offers directly in your inbox
Overview
A bootloader is a small program that runs first when a microcontroller comes out of reset. It decides whether to start the main application or stay in an update mode, and it is the part of the firmware that makes field updates over UART, USB, CAN or OTA possible. Because almost every product needs a safe way to update firmware, bootloader questions come up in nearly every embedded firmware interview. This post covers the most common ones, from the basics to the details of jumping to an application on an ARM Cortex-M.
Q1 : What is a bootloader, and why is it needed in an embedded system?Ans : A bootloader is a small piece of code that executes immediately after reset, before the main application. Its jobs are to:
Without a bootloader, the only way to update firmware is with a debugger or programmer (SWD/JTAG), which is not possible once a product is in the field.
Q2 : What is the difference between a bootloader and the startup code?Ans : The startup code (for example startup_stm32xxx.s) belongs to one program. It sets up the stack, copies .data from flash to RAM, zeroes .bss and calls main(). A bootloader is a separate, independently linked program with its own startup code, its own vector table and its own main(). Both the bootloader and the application have startup code; the bootloader simply runs first.
startup_stm32xxx.s
.data
.bss
main()
Q3 : What is the difference between the ROM (system) bootloader and a custom bootloader?Ans : Many MCUs ship with a ROM bootloader programmed by the vendor in system memory (for example the STM32 system memory bootloader, selected with the BOOT0 pin). It supports fixed protocols such as UART, USB DFU or CAN and cannot be changed. A custom bootloader is written by the product team and stored in the first sectors of user flash. It can use any interface, any protocol, encryption, signature checks and A/B slots, which is why most products use one.
Q4 : Explain the boot flow of a typical bootloader.Ans : The flow below is used by most MCU bootloaders:
Q5 : How is flash memory divided between the bootloader and the application?Ans : The bootloader sits at the start of flash because that is where the reset vector is fetched from. The application is linked to start at a higher address, usually aligned to a flash sector. A small region is often reserved for configuration and boot flags, and larger designs add a second slot to hold a downloaded image.
Both programs need their own linker script. For example, the application's linker script would change FLASH ORIGIN from 0x08000000 to 0x0800A000 and reduce LENGTH accordingly.
FLASH ORIGIN
0x08000000
0x0800A000
LENGTH
Q6 : How does a bootloader jump to the application on an ARM Cortex-M?Ans : The first word of the application's vector table is its initial stack pointer and the second word is the address of its Reset_Handler. The bootloader reads both and jumps:
Reset_Handler
#define APP_ADDRESS 0x0800A000UL typedef void (*app_entry_t)(void); void jump_to_application(void) { uint32_t app_sp = *(volatile uint32_t *)(APP_ADDRESS); uint32_t app_reset = *(volatile uint32_t *)(APP_ADDRESS + 4U); __disable_irq(); /* Stop SysTick and clear pending interrupts */ SysTick->CTRL = 0; for (int i = 0; i < 8; i++) { NVIC->ICER[i] = 0xFFFFFFFF; NVIC->ICPR[i] = 0xFFFFFFFF; } /* De-init peripherals and clocks used by the bootloader here */ SCB->VTOR = APP_ADDRESS; /* Point to the application vector table */ __set_MSP(app_sp); /* Load the application stack pointer */ __DSB(); __ISB(); __enable_irq(); ((app_entry_t)app_reset)(); /* Jump to the application Reset_Handler */ }
Q7 : What is VTOR and why must it be updated before jumping?Ans : VTOR (Vector Table Offset Register, SCB->VTOR) tells a Cortex-M3/M4/M7/M33 core where the interrupt vector table is located. After reset it points to the bootloader's table. If it is not moved to the application's table, every interrupt in the application (SysTick, UART, timers) will run the bootloader's handlers and the system will crash or hang. On Cortex-M0, which has no VTOR, the application's vector table is copied to the start of SRAM and the memory is remapped (for example with SYSCFG->CFGR1 on STM32F0).
SCB->VTOR
SYSCFG->CFGR1
Q8 : Why should peripherals and interrupts be de-initialised before jumping to the application?Ans : The application's startup code assumes the MCU is close to its reset state. If the bootloader leaves a UART, DMA channel or timer running with interrupts enabled, an interrupt can fire before the application has set up its handler or its data, which leads to hard faults that are very hard to debug. A clean hand-over means disabling interrupts, stopping SysTick, clearing pending NVIC bits, resetting used peripherals and returning the clock tree to its default (or a documented) state.
Q9 : How does the bootloader know that a firmware update has been requested?Ans : Common methods are:
0xDEADBEEF
.noinit
NVIC_SystemReset()
Q10 : How does a bootloader verify that the application image is valid?Ans : Most bootloaders store an image header with the application's size, version and a CRC32. On boot, the bootloader recalculates the CRC over the image and compares it. A quick sanity check is also common: the initial stack pointer read from the application's vector table must point into SRAM, and the reset vector must point into the application's flash region. Secure products go further and verify a digital signature (ECDSA or RSA) with a public key stored in the bootloader.
Q11 : What happens if power is lost during a firmware update? How do you make updates fail-safe?Ans : With a single application slot, a power cut while erasing or programming leaves a half-written image. A well-designed bootloader handles this by:
Q12 : What is a dual-bank or A/B bootloader?Ans : Flash is split into two application slots. The device runs from slot A while the new image is written to slot B. After verification, the bootloader either swaps the slots or simply boots from B and keeps A as a fallback. Some MCUs (for example STM32 devices with dual-bank flash) support bank swapping in hardware. The cost is that the application can use at most about half of the flash.
Q13 : What is a secure bootloader, and what is a chain of trust?Ans : A secure bootloader only runs firmware that has been signed by the manufacturer. The bootloader itself is protected from modification (write protection, readout protection or an immutable ROM stage), and it holds the public key used to verify the application's signature. Each stage verifies the next one before running it: ROM verifies the bootloader, the bootloader verifies the application. This is the chain of trust. Secure bootloaders usually also include anti-rollback protection, using a version counter so that older, vulnerable firmware cannot be installed.
Q14 : Why can't the bootloader erase the flash sector it is running from?Ans : On most MCUs, the CPU stalls or faults when it fetches instructions from a flash bank that is being erased or programmed. That is why the bootloader and application must be in different sectors, and why updating the bootloader itself needs special care: either run the flash routines from RAM, use a second flash bank, or use a small "updater" application that rewrites the bootloader.
Q15 : How do you debug a bootloader and an application together?Ans : Flash both binaries (or merge them into one HEX file with srec_cat or the IDE). In the debugger, load the symbols of both ELF files (for example add-symbol-file app.elf in GDB) so breakpoints work in both. Common bugs to check are a wrong application start address in the linker script, VTOR not updated, interrupts left enabled during the jump, and an application vector table that is not aligned as the core requires.
srec_cat
add-symbol-file app.elf
Q16 : Which communication interfaces and protocols do bootloaders commonly use?Ans : UART with a simple packet protocol or XMODEM/YMODEM, USB DFU, CAN (common in automotive, often with UDS services), SPI or I2C from a host processor, and Ethernet or Wi-Fi/BLE for OTA updates. Whatever the interface, a good protocol includes packet framing, a CRC per packet, acknowledgements and retries.
A bootloader looks simple, but interviewers use it to check how well you understand the reset sequence, flash memory, linker scripts, the vector table and interrupt handling. If you can explain the boot flow, the flash layout and the steps of a clean jump to the application, you will be able to answer most bootloader questions. To go deeper, read our post on the Boot Sequence of ARM-based MCU and what the start-up code does in an MCU.
EmbeddedWala
EmbeddedWala Jun 14, 2023 0 58.5K
EmbeddedWala Feb 15, 2024 0 43.1K
EmbeddedWala Apr 27, 2023 1 42.9K
EmbeddedWala Apr 26, 2023 0 35.5K
EmbeddedWala Aug 30, 2022 0 34.8K
EmbeddedWala Jun 19, 2022 0 9.1K
This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies Find out more here