1.2.5 PIC32CX-BZ3 Standalone Bootloader Component Help

PIC32CX-BZ3 bootloader is a standalone harmony component, Using it, one can generate bootloader which is a program that typically is loaded in to the boot flash memory and gets executed every time the device powers up or resets. Due to the size of the internal flash, PIC32CX-BZ3 bootloader supports external flash. The external flash that is supported in this component is SST26 (available on WBZ351 curiosity board)

Bootloader can be used to upgrade firmware on a target device without the need for an external programmer or debugger. It does not fully operate on the device, but can perform various functions prior to starting the main application

Functionality of Bootloader
  • Loads firmware images to embedded flash/external flash over the serial connection using a tool or python script, known as Device Firmware Upgrade (DFU)
  • Provides application protection for firmware (Secured device)
  • Upgrades application firmware to newer revision
  • Controls which application can run based on Sequence number and other metadata information embedded in the OTA image.

Memory Information and Layout of PIC32CXBZ3 device (WBZ351 Curiosity Board)

Table 1-13. 
Memory AreaPurpose
Boot Flash Size is 0x0080_0000 to 0x0080_3FFF (16KB)The memory where bootloader code runs
Embeded Flash Slot 0 base address - 0x01000000The memory where the application firmware runs and the memory where the bootloader copies the new application firmware
Embedded Flash Slot 1 base address - 0x01040000The memory where the received image(Either through DFU or any other way) gets stored. and the memory where bootloader looks for the new image to copy into the Slot 0
External Flash Slot 0 (SST26)Start Address (relative):0x00000; Size 512KB
External Flash Slot 1(SST26)Start Address (relative): 0x80000; Size 512KB

Boot Flash

In PIC32CXBZ3, 16KB boot flash memory is separated from the main execution memory. This boot flash is used for bootloader code

Metadata Header

Format of image meta-data header is described in the Secure Boot ROM Help page - PIC32CX-BZ3 Secure Boot ROM Help

Working of Bootloader

when the application receives new image from a server or via a tool, it will/should store in the Slot 1 location with meta data header & firmware or in the external flash and it should trigger software reset so that bootloader code runs

Bootloader checks for valid image in the external flash and the internal flash by reading the meta data header and firmware and authenticating the same with the selected authentication method. If valid image is found and successfully authenticated, then
  • Erases Slot 0
  • Copies the new image (DFU or OTA) image to Slot 0
  • Verifies the Copy
After that it checks for valid image in Slot 0 by validating it, it jumps to the application if valid image is found

Bootloader usage with DFU

Bootloader programmed to the MCU (in DFU mode) receives an application image from the host over serial interface and writes it to the external flash or internal flash slot 1 . After loading new image on external flash or internal flash slot 1, if reset is triggered, then bootloader erases the slot 0, copies the image to slot 0, verifies the copy. Then bootloader jumps to application which is the new application image

Bootloader stores information about the image in Meta Data Header. This is basically size of 0x200 bytes and gets stored at the start of slot. Bootloader reads this meta data header and does the authentication procedure based on the information in meta data header

Flow Diagram of Bootloader

The detailed flow diagram of bootloader with the optional DFU block can be found below