What is a bootloader?
A bootloader is a program which is able to load another program (the application program). Typically, the bootloader program is not changed, and is kept in the microcontroller. That way the bootloader loads different program again and again.
The following figure-1 shows a typical diagram of a serial bootloader:
Figure 1: Serial Bootloader
Note: Depending on the architecture, there can be a mini or micro bootloader that can load the real bootloader. For example, the OpenSDA bootloader on the Freedom boards have this capability.
The Bootloader Code and the Bootloader Vectors are programmed into a new part (for example, with a debugger) or, a standalone flash programmer (for example, with USBDM). Then the bootloader can be used to load or change the Application Code and Application Vectors. With this, the bootloader remains the same, while the application can be updated.
What is Bootloader Sequence?
A typical bootloader has the following sequence:
- At the startup the bootloader either enters in a bootloader mode or in the application running mode. Typically, this is decided with a button or jumper set (or removed). If the bootloader starts in application running mode, it calls the required application and the system starts automatically.
- Otherwise, the bootloader reprograms the application with a new file. The S19 (S-Record) files are often used for this, as they are easy to parse and every tool chain can produce them.
- The bootloader needs to use a communication channel to read that file. That can be RS-232, USB or an SD card file system (e.g. FatFS).
- Using that file, the bootloader programs the flash memory. Special consideration has to be taken into account for the application vector table. When the bootloader runs out of reset, it uses its own (default) vector table, and needs to relocate the vector table if running the application.
Tip: It is possible to use the reset button on the FRDM-KL25Z board as a user. To keep things simple, you may use a dedicated bootloader push button on PTB8.
The following figure-2 shows the Bootloader System Block Diagram:
Figure-2: Bootloader System Block Diagram
The components of the Bootloader System Block Diagram are as follows:
- Communication Channel
- File Reader
- Flash Programming
- Vector Redirection
- User Interface