Bootloader Basics
Bootloader Basics
https://learn.adafruit.com/bootloader-basics
Overview 3
• What is a Bootloader?
• So, how do you load a program onto a brand-new microcontroller?
• What if you don't have one of those devices?
• So where do bootloaders come from?
Types of Bootloaders 6
• Basic Bootloaders
• Advanced Bootloaders
• Multi-stage bootstraps
Bootloader Resources 12
Bootloader Usage 12
• CircuitPython and Bootloaders
If you take a bare microcontroller chip fresh from the factory and apply power to it,
the internal system clock will start ticking away. But nothing else will happen.
Without a program to run, the chip will just sit there doing nothing.
Keep in mind that the vast majority of microcontroller chips wind up embedded in
products ranging from toasters to traffic lights. A modern automobile may have 100
or more embedded microcontrollers that only need to be programmed once by the
parts supplier. Cost, performance or other constraints can easily outweigh any
considerations of programming convenience.
There have been a few chips that come with a "ROM" (permanent) bootloader. Such
as the ESP32 or the LPC11xx series with their USB mass storage bootloader, but these
are very few-and-far-between.
Bootloaders tend to be rather small programs. But they do take some space. For
applications that need every last byte of program memory, the convenience of a
bootloader may be an unnecessary luxury.
Embedded systems designers try to keep product costs down by using the smallest
possible processor that can do the job. Investing in a proprietary programming
interface for the manufacturing line is a one-time investment. Sizing up to a bigger
processor adds cost to every unit sold.
Start-up Time
Most bootloaders incur some dead-time on power-up or reset as they look for a
potential upload. If ‘instant on’ is a requirement for your application, a stock
bootloader may not be an option.
Security
If you don’t want everyone with an Arduino IDE to be able to re-program your device,
ditching the bootloader will add another obstacle for a would-be hacker.
(Although any hacker worth her salt will probably have an AVRISP and/or JLink in her
toolbox!)
Types of Bootloaders
There are thousands of different bootloaders. The design and capabilities vary
depending on the processor architectures, hardware resources and intended usage.
Basic Bootloaders
The simplest type of bootloader has just one function: Check for an upload at startup
and load it.
A good example of a basic bootloader is the bootloader programmed into the Arduino
UNO.
On power-up or reset, the bootloader watches the serial receive pin for a few
seconds - waiting to receive the special sequence of bytes that indicates an upload
attempt from the IDE. If that magic byte sequence is received, the bootloader will
respond with an acknowledgement and the IDE will start sending the code. The
bootloader will receive the code from the IDE and burn it into flash memory.
If the bootloader does not see the magic byte sequence, after a few seconds it will
proceed to start running whatever code is already burned into flash.
Advanced Bootloaders
This bootloader can work like an Arduino and accept serial uploads via the USB
connection. Or it can emulate a disk drive that lets you copy Python programs to it.
An on-board RGB LED is used to provide diagnostic feedback in the form of steady or
flashing patterns in different colors to indicate the state of the bootloading process.
Your notebook, desktop computer and even your smartphone most likely have at
least two stages of bootstrapping. This gives you options such as selecting different
operating modes, or even an entirely different operating system.
The BIOS or UEFI is burned into flash memory on the motherboard. At startup it will
look for a bootable drive and load an operating system bootloader from the drive. At
that point it turns control over to the operating system’s bootloader which takes care
of loading your operating system. Once the operating system is up and running, you
can just point and click to load and run any program you want.
In the early days of computing, computers were programmed literally bit-by-bit using
patch cables or an array of toggle switches on the front panel. As you might imagine,
this is quite tedious to do for anything more than a trivial program.
One day, someone had a bright idea: Write a small program that knows how to load
larger programs stored on punched cards or paper-tape. And the computer bootstrap
loader was born.
Although the bootstrap program saved lots of time, it was still rather tedious to have
to toggle in the instructions every time you restarted the machine. Eventually,
another engineer had another bright idea: Build the bootloader into the computer.
You could solder an array of diodes to program the 1’s and 0’s of the bootloader code
at the required memory addresses to create a Read-Only Memory (ROM) for the
bootloader. And the ROM boot was born.
Moving on from the hard-wired diode boot, advanced in technology led to various
forms of electrically programmable non-volatile memories.
These days, bootloaders are programmed into EEPROM or Flash memory. So you
don’t need a soldering iron to modify or repair your bootloader. For more complex
systems, bootloading may be performed in multiple stages with each stage loading a
more complex piece of software.
Your notebook or desktop computer most likely has at least two stages of bootstraps.
The BIOS or UEFI is burned into flash memory on the motherboard. At startup it will
look for a bootable drive and load an operating system bootloader from the drive. At
Bootloader Resources
First time with an unfamiliar bootloader? Not sure what that blinking LED means?
Looking for a way to speed up your restart times? Or just feel like building a better
bootloader?
The following pages contain links to other tutorials regarding the care and feeding of
common bootloaders.
Bootloader Usage
Most bootloaders are fairly simple to use. But the details vary somewhat depending
on the platform and its capabilities. The links on this page describe the unique
features of each one.
Gemma Bootloader
Trinket Bootloader
NRF52 Bootloader
The UF2 bootloader emulates a USB mass storage device. When you connect a board
with a UF2 bootloader to your computer, it looks like you plugged in a thumb-drive.
It's not a real drive, so you can't use it to store all your favorite MP3s. But it will
recognize certain file names as Python programs to load.
The UF2 loader can also operate in BOSSA compatible mode, so it can accept
uploads of Arduino programs from the Arduino IDE.
The links below describe the CircuitPython system and the UF2 Bootloader in depth
and how they work together to load your Python or Arduino programs.
• You are starting with a bare chip, fresh from the factory
• You have ‘bricked’ a processor board and want to repair it
• You have special requirements and want to install a custom bootloader
This page has a number of links to tools and instructions for repairing, customizing
and/or burning bootloaders on various microcontrollers:
Trinket/Gemma Bootloader
USBTiny ISP
This device can be used to flash
bootloaders or other programs onto AVR
Microcontroller boards with ICSP headers.
USBTiny ISP
Segger Forums