6.1.2 Configure User Application to Use Bootloader

To integrate Bootloader with a user application, follow these steps in the user application project. These steps are applicable to any user application that requires Bootloader functionality:

  • Add the Bootloader Services component to the user application project and generate the necessary code.
  • Include the bootloader as a “Loadable File/Project” to create a unified image.
  • Program the unified image onto the device.

Add Bootloader Services Component and Generate Code

  1. Launch MPLAB® X IDE.
  2. Go to File>Open Project.
    1. Navigate to user application project folder (ending with .X), select it, and click Open.
  3. Click the MCC icon to launch the MPLAB® Code Configurator.
    1. The MCC window will open, displaying the Project Graph tab.
  4. After launching MCC, in the Device Resource window, perform the following steps:
    1. Expand Harmony>Wireless>Driver.
    2. Click the green (+) symbol next to the “Bootloader Services” component. This action adds the “Bootloader Services” to the Project Graph.
    3. Click Yes to accept and auto-activate any required dependencies. The MCC automatically adds and connects any additional components needed for the Bootloader to function.
    4. The “Bootloader Services” component generates the supporting linker file and MPLABX script needed for adding a metadata header into the application image.
    5. The Project Properties tab include the “SignFirmware” settings.
    6. For DFU via UART, firmware signature and verification are optional. For OTAU, the user must enable firmware signature and verification by checking Use Firmware Signature Verification API in Bootloader.
  5. The following project graph figure is just an example. The user may have different graph depending on their application.
    Figure 6-17. User Application Adding Bootloader Services
  6. Click Generate to generate the user application code.
    1. The newly generated code includes some code related to the bootloader service. Additionally, the project’s linker script file is automatically modified to incorporate bootloader functionality.
    Figure 6-18. Generate User Application Code
  7. After code generation, the “SignFirmware” settings appear in Project Properties.
    Note: If not visible, restart MPLAB X IDE.
  8. The following are the recommended authentication methods to the user:
    • From the “Auth Method:” drop-down list, the user can choose ECDSA256-SHA256 or SHA256.
      • ECDSA256-SHA256 – Firmware signature validation and data integrity check.
      • SHA256 – Firmware data integrity check only.
    • If the user chooses None as the authentication method, then no firmware security/integrity check (not recommended).
      Important: If an issue occurs during image saving into slot1, the new image might be incomplete, and the firmware could become non-functional at the next restart. Therefore, choosing None option is not secure for firmware upgrades.
    Figure 6-19. SignFirmware Authentication Method: ECDSA256-SHA256
    Figure 6-20. SignFirmware Authentication Method: SHA256
    Note: The “Sequence Number:” must not be 0x00000000 or 0xffffffff, as these are invalid values.

Add Bootloader as Lodable File/Project to Create Unified Image

Once the new code is generated and configured, add the Bootloader as a loadable project or loadable hex file in the updated project. This allows MPLAB X IDE to merge both the user application and the bootloader, creating a unified firmware by generating a unified image file.

To add Bootloader as loadable file, perform the following steps:
  1. In the project tree, right-click Loadables>Add Loadable File.
    Figure 6-21. User Application Add Loadable File
  2. Browse and select the bootloader file.
    1. In this scenario, select Bootloader.X.production.hex file.
      Figure 6-22. Add Loadable File
  3. To add bootloader as loadable project, perform the following steps:
    1. Expand application project’s tree. Right-click Loadables>Add Loadable Project.
      Figure 6-23. User Application Add Loadable Project
  4. Browse and select the bootloader project.
    1. In this scenario, select Bootloader.X file.
      Figure 6-24. Add Loadable Project
  5. After adding, click Clean and Build Main Project on the MPLAB X IDE tool bar to rebuild and create a unified image.
    1. Click the Clean and Build Main Project icon.
    2. The build process merges the user application and bootloader.
    Figure 6-25. Build to Create Unified Image
  6. After building, the generated files are available under firmware\ble_sensor.X\dist\default\production path.
    • signed.unified.hex – This is a combined image that includes both the user application and the bootloader. By programming this unified image, the user application gains bootloader capabilities.
    • signed.bin – This is the target binary image file that the bootloader uses for DFU.
  7. If there are any modifications to the user application firmware, the user can build and generate the binary file. Then, use the bootloader to upgrade the device to the new image.
    Note: Ensure that the binary file is correctly generated before proceeding.

Program Unified Image

As mentioned above, the user needs to program the device with a unified image to enable the user application to have bootloader capability. To do this, on the MPLAB® X IDE Tools bar, click the Make and Program Device Main Project icon to program the device. The unified image will be programmed into the device.
Figure 6-26. Program Unified Image
Now, the device with the user application will have bootloader functionality. The user can run DFU by using the bootloader. For more details, see Device Firmware Upgrade Over Serial from Related Links.