4.8 Creating a Bootloader Client With Multiple Images and Anti-Rollback Protection
This section demonstrates how to configure a bootloader client to extend support for multiple application images with anti-rollback protection support.
Description: This section details a full multi-image bootloader use case on the PIC18F57Q43 microcontroller, which applies to many variants of the PIC18F family and can also be extrapolated to other 8-bit PIC and AVR chips as well. This example uses the PIC18F57Q43 Curiosity Nano board for demonstration. Refer to the board schematics for configuration information.
This example will be an extension to the basic bootloader client example: Creating a Bootloader Client for PIC® Devices
-
Open the existing project or create a new bootloader client example.
Figure 4-179. Open Multi Image Project -
MCC opens up automatically when a new project is created. If not, click the MCC button in the menu bar to start the MPLAB Code Configurator.
Figure 4-180. Open MCC -
In the 8-Bit MDFU Client User tab, toggle the switch the Enable Multi-Image toggle button on to enable multiple image support.
Figure 4-181. Enable Multiple Image Support -
Update the Number of Images field to the number of extra images, excluding the execution area image. For this application, the client is configured to have three additional images.
Note: The client is always set up to execute code from the partition located at the application start address.Figure 4-182. Update Number of Application Images -
Review the maximum Application Size calculated according the number of images selected.
Figure 4-183. Review Maximum Application Size Tip: Reduce the number of application images if the size displayed is not sufficient for the application. -
Select the image ID for the partition to be used as the staging area.
Figure 4-184. Update Staging Image ID Tip: Staging area is the image partition where the bootloader will download the new image received from the host, perform verification on the image and copy it to the desired location. -
Currently, the additional application images are stored in the device Program Flash Memory.
Figure 4-185. Storage Location of Additional Application Images -
Switch the Enable Backup Image on to enable the Backup Image feature.
Figure 4-186. Enable Backup Image Tip: The Backup Image is a special spare image that can be used for emergency application restoration in case of memory corruption or any other errors that result in the execution space image and the staging area image becoming invalid. -
Select the image ID for the partition to be used for storing the backup image.
Note: Staging area ID and backup image ID cannot cannot have the same value.Figure 4-187. Update Backup Image ID -
Switch the Enable Anti-Rollback toggle button to enable anti-rollback support.
Figure 4-188. Enable Anti-Rollback Tip: Anti-rollback protection for bootloader prevents the application image from being downgraded to older, potentially vulnerable firmware versions, ensuring only newer firmware can be installed. -
Review the Device Flash Memory Partitions table and verify if all the extra application image partitions are correctly configured.
Figure 4-189. Device Flash Memory Partition Table -
- Before generating the code
and programming the device, the linker settings from the 8-Bit MDFU Client
Easy View must be copied into their respective boxes. Right click
the project in the Projects tab and open the project properties. Go
to XC8 Global Option>XC8 Linker>Memory Model>ROM
ranges and paste the copied value.
Figure 4-190. Copy Settings From Linker Settings Tab on UI - For PIC
devices:
Figure 4-191. Compiler - Linker Settings Open Project Properties>XC8 Global Options>XC8 Linker>Memory Model>ROM ranges. In the “ROM ranges” text box, add:0-23FF
- For AVR devices:
- XC8 linker
settings:
For an AVR based bootloader client with application with start address 0x2400 the linker settings are as follows:
Figure 4-192. AVR XC8 Linker Settings: Open Project Properties>XC8 Global Options>XC8 Linker>Additional Options. In the “Extra linker options” text box, add:-Wl,--defsym,__TEXT_REGION_LENGTH__=<Application Start Address in WORDS>
- GCC linker
settingsOpen Project Properties>Avr GCC (Global Options)>avr-ld>General. In the “Additional Options” text box, add:
-Wl,--defsym,__TEXT_REGION_LENGTH__=<Application Start Address in WORDS>
Figure 4-193. GCC Linker Settings
- XC8 linker
settings:
- For PIC
devices:
- Click the Generate
button in the Project Resources tab to generate the updated project
code and compile the project.
Figure 4-194. Generate Code
- Before generating the code
and programming the device, the linker settings from the 8-Bit MDFU Client
Easy View must be copied into their respective boxes. Right click
the project in the Projects tab and open the project properties. Go
to XC8 Global Option>XC8 Linker>Memory Model>ROM
ranges and paste the copied value.
- Click the Clean and Build Main
Project button in the MPLAB X IDE main menu to compile the updated project
with multi-image and anti-rollback enabled.
Figure 4-195. Compile Project -
-
To prepare the chip to bootload, click the Make and Program Device button. After this programming process ends, the LED on the PIC18F57Q43 Curiosity Nano board will remain ON.
Figure 4-196. Program Device
Figure 4-197. Bootloader UART demo Note: The below example is from a UART hardware setup. Bootloader is running and waiting for communication -