Preliminary porting tasks

All references to paths in the rest of this chapter are relative to the root of the extracted SDK package. MCU Bootloader is a middleware in SDK package loacted at middleware/ mcu-boot. Before modifying source code, the following tasks should be performed.

Download MCUXpresso SDK

Porting the MCU bootloader to a new target is a manual process that requires updating the device header files. This process is time-consuming and error-prone, so NXP provides Software Development Kit (SDK) for ARM Cortex-M Core devices. SDK package contains device header files and drivers. These SDK packages can be downloaded from mcuxpresso.nxp.com.

Note: Do not proceed with a port if a package does not yet exist for the desired target device.

In the downloaded package, header files including <device>.h, <device>_features.h, fsl_device_registers, system_<device>.h can be found in devices/<device>, and drivers can be found in devices/<device>/drivers. Add these two folders to include directories of the target device’s bootloader project or add these header files and drivers to the target device’s bootloader project.

Parent topic:Preliminary porting tasks

Copy the closest match

Copy the folder of the device that most closely matches the target device in the /middleware/mcu-boot/targets folder of the bootloader source tree. Rename the folder to match the target device part number.

After the files are copied, browse the newly created folder. Rename all files that have reference to the device from which they were copied. Rename the following files:

  • clock_config_<old_device>.c —> clock_config_<new_device>.c

  • hardware_init_<old_device>.c —> hardware_init _<new_device>.c

  • memory_map_<old_device>.c —> memory_map _<new_device>.c

  • peripherals_<old_device>.c —> peripherals _<new_device>.c

Copy the following files from their location in devices/<device>/<tool chain> to the new middleware/mcu-boot/targets/<device>/src/startup folder:

  • <tool chain>/startup_<device>.s

Parent topic:Preliminary porting tasks

Provide device startup file (vector table)

A device-specific startup file is a key piece to the port. The bootloader may not function correctly without the correct vector table. A startup file from the closest match device can be used as a reference, but it is strongly recommended that the file be thoroughly checked before using it to port due to differences in interrupt vector mappings between devices.

Create the startup file and place into the middleware/mcu-boot/targets/<device>/src/startup/<tool chain> folder. Startup files are often assembly (*.s) and are named startup_<device>.s.

Note: For Kinetis devices, the 16-byte Flash Configuration Field should be carefully set in the bootloader image. The Flash Configuration Field is placed at the offset 0x400 in the bootloader image. The field is documented in the SOC reference manual under the subsection called, “Flash Configuration Field” in the “Flash Memory Module” chapter. To change the default 16-byte value for the field in the template startup_<device>.s file of the bootloader project, follow these steps:

  1. Open the startup_<device>.s file in a text editor.

  2. Locate the symbol where Flash Configuration Field is specified. The symbol name is “__FlashConfig” The 16-byte Flash Configuration Field data is enclosed with __FlashConfig and __FlashConfig_End symbols in the startup_<device>.s file

  3. Change the 16-byte setting to the correct value. For example set the flash security byte, enable or disable backdoor access key, specify the 8-byte backdoor key, and so on.

  4. Once the field is updated, save the startup_<device>.s file and close the text editor.

Parent topic:Preliminary porting tasks

Clean up the IAR project

This example uses the IAR tool chain for the new project. Other supported tool chains can be used in a similar manner.

MCU Bootloader projects can be found in <boards>/board/bootloader_examples. Open a bootloader project of the most similar device. This image shows an example of what a workspace looks like and the files that need to be touched.

IAR workspace

Once changes have been made, update the project to reference the target device. This can be found in the project options.

Project options |

|

Parent topic:Preliminary porting tasks

Bootloader peripherals

There are two steps required to enable and configure the desired peripherals on the target device:

  • Choose which peripherals can be used by the bootloader.

  • Configure the hardware at a low level to enable access to those peripherals.

Parent topic:Preliminary porting tasks

Parent topic:MCU bootloader porting