1.14 Bootloader Linker and Build Options

Compiler, Linker and Post Build Options for the Bootloader and Application Projects

Since the bootloader often requires specialized build features, extra build options are often required. These settings are automatically enabled in the most recent versions of MPLABx.

Basic Verification Linker Settings

If the user is not enabling any Code Protect or Codeguard settings, then no linker command line changes are required and the user can skip to the Application Post Build Options below

Code Protect / Code Guard settings

When the user selected Code Protect Bootloader, the device is configured to use Codeguard. This feature requires special linker options to place the code in the correct place. The three added features are listed below along with the command line that needs to be added to the project

Bootloader Project Linker Settings
  1. –add-flags-code=boot Forces all code in this project placed in the boot section.

  2. –add-flags-const=boot Forces all constants in this project placed in the boot section.

  3. -D__USE_BFA Allows the boot section to be placed according to the security mode and not default to normal system map.

–add-flags-code=boot,–add-flags-const=boot,-D__USE_BFA  

This linker command should automatically be added to the project for the user. However, they can be added manually by following the below steps.

  1. Go to Project Properties

  2. Go to XC16->xc16-ld

  3. Under additional options add the following: –add-flags-code=boot,–add-flags-const=boot,-D__USE_BFA

Application Project Linker Settings

The application also has an extra linker setting and it should be added automatically and is shown below.

  1. -D__USE_BFA Allows the project to use the best fit settings for the code.

These changes should automatically be added to the project for the user. However, they can be added manually by following the below steps.

  1. Goto Project Properties

  2. Goto XC16->xc16-ld

  3. Under additional options add the following: -D__USE_BFA

ECDSA Verification with Code Protect / Code Guard settings

When the user selected Code Protect Bootloader, the device is configured to use Codeguard. This feature requires special linker options to place the code in the correct place. Below are the linker settings for both the bootloader and applications.

Bootloader Project Linker Settings

–add-flags-code=boot,–add-flags-const=boot,-D__USE_BFA

The steps needed to change this are shown below.
  1. Goto Project Properties

  2. Goto XC16->xc16-ld

  3. Under additional options add the following: –add-flags-code=boot,–add-flags-const=boot,-D__USE_BFA

Application Project Linker Settings
Application Linker Settings  

-D__USE_BFA  

  1. Go to Project Properties

  2. Go to XC16->xc16-ld

  3. Under additional options add the following: -D__USE_BFA

Application Project Post Build Settings

As the final part of the build process, the application code needs to be signed and converted to a hex format to download. This process is the same for all verification methods and is shown below.

Windows Post Build Command

cd mcc_generated_files/boot && postBuild.bat $(MP_CC_DIR) $(ProjectDir) $(ImageDir) $(ImageName) $(IsDebug)

Linux Post Build Command

cd mcc_generated_files/boot && ./postBuild.sh $(MP_CC_DIR) $(ProjectDir) $(ImageDir) $(ImageName) $(IsDebug)
Adding Post Build step to Application Project
  1. Go to Project Properties

  2. Select the 'Building' left navigation node.

  3. Check the box next to 'Execute this line after the build'.

  4. In the text field below add:
    Windows machine
    cd mcc_generated_files/boot && postBuild.bat $(MP_CC_DIR) $(ProjectDir) $(ImageDir) $(ImageName) $(IsDebug)
    
    Linux/Unix/Mac machine
    cd mcc_generated_files/boot && ./postBuild.sh $(MP_CC_DIR) $(ProjectDir) $(ImageDir) $(ImageName) $(IsDebug)