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 shows the Bootloader System Block Diagram:
Figure 1. Bootloader System Block Diagram
The components of the Bootloader System Block Diagram are as follows:
- Communication Channel - File I/O or any other means to read the Application File.
- File Reader - A reader which reads the Application File.
- Flash Programming - To program the Application.
- Vector Redirection - To switch between the Bootloader and Application Vector Table.
- User Interface - Showing status and information to the user, and to switch between the Application and Bootloader mode at system startup.