AdvancedTopic 73 of 104Electronics & Embedded
Bootloaders and startup code
Initialise stack, memory and clocks before main runs.
In depth
At reset the CPU loads the stack pointer and jumps to the reset handler, which initialises .data and .bss, sets clocks, calls constructors and then main(). A bootloader can load new firmware via UART/USB before launching the application. Vector table relocation is required.
Key points
- Linker script
- Vector table
- Dual-bank updates
ExampleArduino bootloader flashes sketches over serial.
What is Bootloaders and startup code?
Initialise stack, memory and clocks before main runs.
Why is it important to understand bootloaders and startup code?
Startup code prepares the processor before main runs, so a wrong startup sequence causes failures that are hard to trace.
What does the reset handler do?
It sets the stack pointer, copies initialised data from flash to RAM, zeroes the uninitialised data and calls the system initialisation before main.
Why does a bootloader matter?
It can update firmware and start the application safely, which is useful for field upgrades and recovery.
How is Bootloaders and startup code used in practice?
Typical applications include setting up the stack pointer and clearing RAM before the first line of C runs, configuring the system clock and PLL before running fast code and copying initial values from flash into RAM for global variables.
What should I learn before Bootloaders and startup code?
Study "Memory-mapped I/O" first (topic 72 of 104 in Electronics & Embedded). It covers the groundwork this topic builds on.
What are the key points of Bootloaders and startup code?
Linker script. Vector table. Dual-bank updates.
Can you give an example of Bootloaders and startup code?
Arduino bootloader flashes sketches over serial.
What comes after Bootloaders and startup code?
The next topic is "Power management", which builds directly on this one.
How difficult is Bootloaders and startup code?
It is classed as Advanced in Electronics & Embedded (topic 73 of 104). It is an advanced topic. It assumes you are comfortable with the intermediate topics in Electronics & Embedded.