MCUBoot Integration

Introduction

This page describes how MCUBoot is integrated in the SDK for AM13E230X and AM13E232X: what it is, how the SDK port is structured, how the two MCUBoot examples cooperate, and how to bring them up on a board.

For the signing flows, key provisioning and the update protocol, see:

What MCUBoot Does

MCUBoot is a secure bootloader library. At reset it inspects the firmware image slots in flash. Each image carries a header (version, size) and a trailer of TLV (type-length-value) entries that holds the authentication tag. MCUBoot validates every candidate image, selects the newest valid one and hands control to it. An image that is corrupt, unsigned or signed with the wrong key is never executed, so a failed update cannot replace a working image.

The SDK uses a customized MCUBoot with two differences from the upstream defaults:

Feature

SDK configuration

Image authentication

AES-CMAC-128 (MCUBOOT_CMAC_128); the reference examples compile the key into the bootloader

Update strategy

Direct XIP (MCUBOOT_DIRECT_XIP); images run in place, no copy or swap of image data

The key is compiled into the bootloader only to keep the examples self-contained. In a product, the key can be placed in data flash and protected with the GSC, so that it is not stored in the bootloader image itself.

The image trailer holds a single CMAC TLV and no separate hash TLV. The AES-CMAC is computed over the image header and body, so it protects both integrity and authenticity and a plain hash would add nothing.

The firmware is executed directly from flash, so an image can run only at the address it was linked for. The SDK therefore links every application for the primary slot address, and the entry point is always 0x00010100 (the vector table, placed after the image header at offset 0x100 in the slot). The image in the secondary slot is linked the same way, so on its own it is not executable at its physical location.

To activate it, the bootloader does not copy the image into the primary slot. It asks the device to swap which physical flash bank is mapped at address 0x00000000. The secondary slot then appears at the primary slot address, where the image was linked to run, and the boot manager jumps to the same entry point as before. This is a swap of the address mapping of the two banks and moves no image data.

Components

Component

Location

Role

MCUBoot core (bootutil)

source/security/mcuboot/bootutil/

Image validation and slot selection

Device port

source/security/mcuboot/<device>/

Flash map, MCUBoot configuration, slot IDs

Boot manager example

examples/security/mcuboot_boot_manager/

The bootloader application

Firmware update example

examples/security/mcuboot_fw_update/

Application that receives and stages updates

Host tool

examples/security/mcuboot_fw_update/mcuboot_fw_update_host.py

Sends an image over UART

Linker scripts

ti_sdk_config/<device>/default/linker_m33_ti_arm_clang_signed_*.cmd

Slot placement, .header, .trailer

Signing

ti_sdk_sign_executable() in source/device/<device>/cmake/<device>_ti_sdk.cmake

Post-build signing with ti_cst

Device port

Each device port in source/security/mcuboot/<device>/ contains:

File

Purpose

mcuboot_config/mcuboot_config.h

Direct XIP, CMAC algorithm and key, image count, maximum sector count

flash_map_backend/flash_map_backend.{h,c}

Flash area table (bootloader, primary, secondary) and flash access functions

sysflash/sysflash.h

Flash area IDs and the image-to-slot mapping macros

mcuboot.cmake

Adds the port include directories and sources to the mcuboot library

MCUBOOT_WATCHDOG_FEED() in mcuboot_config.h is intentionally defined empty, so it does nothing. Upstream MCUBoot calls it inside long flash erase and copy loops so that a watchdog does not reset the device during an overwrite or swap. Direct XIP never runs those loops, and the boot manager does not enable a watchdog. If you use a watchdog in the boot manager, or move to a strategy that erases or copies flash, define the macro to service your watchdog.

In Direct XIP mode MCUBoot only reads flash, so flash_area_read() is a direct memory copy and flash_area_write() and flash_area_erase() are intentionally empty. Writing the update image is done by the application, not by the bootloader.

The library is enabled per device with set(TI_SDK_INCLUDE_MCUBOOT ON) in source/device/<device>/cmake/<device>_ti_sdk.cmake, and is selected by an example through the mcuboot entry in its libraries list.

Flash Layout

Both devices use the same slot layout (two 256 KB banks, 192 KB image slots):

Region

Address range

Size

Bank

Defined in

Bootloader

0x00000000 – 0x0000FFFF

64 KB

0

FLASH_AREA_BOOTLOADER_*

Primary slot

0x00010000 – 0x0003FFFF

192 KB

0

FLASH_AREA_PRIMARY_SLOT_*

Reserved

0x00040000 – 0x0004FFFF

64 KB

1

linker script

Secondary slot

0x00050000 – 0x0007FFFF

192 KB

1

FLASH_AREA_SECONDARY_SLOT_*

The address and size values in flash_map_backend.h, the memory regions in the signed linker scripts and the --slot-size passed to the signing tool must stay consistent. Changing the layout requires changing all three.

The signed MCUBoot image starts with a 32-byte header at the beginning of the primary slot. The vector table sits at 0x00010100, which is the address the boot manager programs into the vector table offset register.

How the Examples Work Together

Boot manager

mcuboot_boot_manager is the bootloader. It runs from the bootloader region and is the only image the device ROM boots. On a device in HSSE state it must be signed with ROM signing; on HSFS it can be unsigned. See Security Overview.

On reset, App_McubootBootManager_Execute() selects an image and hands control to it:

  1. Check for re-entry. The boot manager must run only once per reset. If the system controller has already received INITDONE (DL_SYSCTL_isINITDONEIssued() returns true), the function asserts and does nothing else.

  2. Select an image. boot_go() validates the primary and secondary slots and reports the winner in boot_rsp. If no valid image is found, LOG_ASSERT stops the boot.

  3. Map the selected bank. If the winner is in the secondary slot, DL_SYSCTL_swapFlashBank() maps that bank at address 0x00000000, so the image appears at the primary slot address. For a primary-slot winner nothing needs to be done.

  4. Set the vector table. DL_GSC_setVTOR_NS points the vector table at the application entry address.

  5. Complete boot. DL_SYSCTL_issueINITDONE() tells the system controller that boot is complete.

Its SysConfig enables the NONMAIN options needed for this flow (cscExists and flashBankSwap), and on the LaunchPad it selects the external-crystal clock profile.

Firmware update application

mcuboot_fw_update is an ordinary application signed with MCUBoot signing. It is linked for the primary slot and runs two activities concurrently so that the effect of an update on real-time behavior is visible:

Activity

Priority

Behavior

Timer ISR (every 50 µs)

0 (highest)

Toggles the heartbeat LED every 500 ms; drives the status LED from the update state

UART ISR (UC4, 115200 8N1)

1

Receives 262-byte packets; the RX callback copies the packet and re-arms reception

The main loop is non-blocking. When the RX callback flags a packet, the main loop passes it to FwUpdate_ProcessPacket() and sends a 5-byte ACK through an interrupt-driven transmit.

fw_update.c implements the update state machine (Idle, Ready, Downloading, Complete, Error). Data is accumulated in RAM and written one flash sector at a time. The destination is fixed in app_cfg.h as APP_FW_UPDATE_BANK_ADDRESS (0x00050000, the secondary slot) and is not sent over the wire. The protocol and LED behavior are described in Enabling Secure Boot.

The transfer checks only transport integrity (CRC16). Authentication is done later by the boot manager.

Security considerations

The update application is deliberately not a trust boundary. It accepts data from an unauthenticated UART link and writes it to the secondary slot. All security decisions are made by the boot manager when it validates the image at the next reset:

  • Authentication. An image is accepted only if its AES-CMAC-128 tag, computed with the key in mcuboot_config.h, is valid. Anything received over UART, whether corrupted, unsigned or signed with another key, is rejected at boot and the current image keeps running. The CRC16 check is not a security mechanism.

  • Version check. The boot manager activates the secondary image only if its version is higher than the running one, which prevents an older (for example vulnerable) signed image from replacing a newer one.

  • No confidentiality. The image is sent in clear text. Do not place secrets in the firmware image.

  • Fault injection hardening (FIH). The SDK builds MCUBoot with MCUBOOT_FIH_PROFILE_MEDIUM, set in source/security/mcuboot/am13e230x/mcuboot_config/mcuboot_config.h. It protects the validation path in the boot manager (bootutil_img_validate() and the functions it calls) against voltage or clock glitches that try to skip a check or flip its result. The medium profile enables:

    • Double variables (FIH_ENABLE_DOUBLE_VARS): critical values, such as the validation result, are stored as (x, x ^ mask). Both halves are checked, so a single bit flip is detected.

    • Global fail (FIH_ENABLE_GLOBAL_FAIL): every failure loop branches to one hardened, non-inlined fih_panic_loop(), so a glitch cannot escape an individual loop.

    • Control flow integrity (FIH_ENABLE_CFI): a global counter is incremented before and decremented after each protected call (FIH_CALL). Skipping a call, such as the CMAC comparison, leaves the counter wrong and is detected.

    Random delays (FIH_ENABLE_DELAY, the HIGH profile) are not enabled, because they need an entropy source. FIH does not protect the update application, nor the ROM verification of the boot manager itself.

  • Key handling. CMAC is a symmetric scheme, so anyone who can read the key can create images that the boot manager accepts. The key in mcuboot_config.h is a development key and is compiled into the bootloader for reference only. For a product, use a unique key, keep it out of source control, and store it in data flash protected through the GSC instead of in the bootloader image.

  • Update channel. The UART link has no authentication, so anyone with access to it can overwrite the secondary slot (a denial of service for updates, not for the running image). Disable or restrict the update path in production, and keep the application’s debug port locked according to the device lifecycle described in Security Overview.

End-to-end sequence

 Reset
   |
 Device ROM ---- verifies boot manager (ROM signature, HSSE only)
   |
 Boot manager -- boot_go(): validate primary + secondary (AES-CMAC-128, version)
   |                 |
   |                 +-- selected image in secondary slot? --> swap flash bank
   |
 Application ---- runs from 0x00010100; receives a new signed image over UART
   |              and writes it to the secondary slot (0x00050000)
   |
 Reset ---------- boot manager runs again, picks the new image if valid and
                  its version is higher; otherwise the current image keeps booting

A completed transfer does not activate the image. Activation happens at the next reset, and only if the new image is authentic and has a higher version than the one currently running.

Signing

The two examples use different signing types, handled by ti_sdk_sign_executable() after linking:

Image

Target type

Header / trailer

Note

Boot manager

SIGNED_ROM

128 B / 44 B

Verified by device ROM

Application

SIGNED_MCUBOOT

32 B / 24 B

Verified by the boot manager

The post-build step extracts a clean binary from the ELF, signs it, and writes the resulting header and trailer back into the .header and .trailer sections of the ELF. For MCUBoot signing it also produces the standalone signed binary (<target>.bin) that is sent to the device during an update.

Signing parameters can be overridden at configure time:

CMake variable

Default

Meaning

TI_SDK_SIGN_KEY_INDEX

1

Key index used for signing

TI_SDK_SIGN_MCUBOOT_IMG_VERSION

1.0

Image version; must be higher than the running image for an update to be activated

TI_SDK_SIGN_SESSION

empty

CST session name; empty uses --dev-session

TI_SDK_SIGN_SESSION_PASSWORD

empty

Password for the session; required when a session is given

TI_SDK_SIGN_KEY_INDEX selects one of the four AES-CMAC keys (1-4) held in the CST session used for signing. It is passed to ti_cst as --key-index and is not mapped to the KEYSTORECTL peripheral. The key index has a different counterpart for each signing type:

  • ROM signing (boot manager): the index refers to the key of the same number that was provisioned into OTP (see Security Overview). Key 1 is the initial root of trust, and keys 2 to 4 are for key revision.

  • MCUBoot signing (application): the index must refer to the same key value as MCUBOOT_CMAC_KEY in mcuboot_config.h, because the boot manager verifies the image with that compiled-in key. If they differ, the image is rejected at boot.

Note

If ti_cst is not installed, the build completes but skips signing, and the resulting image will not boot. Install the CyberShield Toolkit first, see CyberShield Toolkit (CST).

The CMAC key in mcuboot_config.h is a development key. Replace it, and sign with a matching key, before using these examples as the basis of a product, and consider moving it to GSC-protected data flash as described in the Security considerations section above.

Running the Examples

Prerequisites

  • Board connected through the on-board debug probe, with a UART connection to the host for UC4

  • CyberShield Toolkit (ti_cst) installed

  • Python 3 with pyserial for the host tool

  • On an HSSE device, keys provisioned as described in Security Overview

Build

make all TI_SDK_DEVICE=<device>

The two images needed are:

Image

CMake target (LaunchPad)

Boot manager

ex_mcuboot_boot_manager_lp_signed_rom

Application

ex_mcuboot_fw_update_lp_signed_mcuboot

Program and verify

  1. Program the boot manager at 0x00000000.

  2. Program the signed application at 0x00010000.

  3. Reset the board. A blinking heartbeat LED shows that the boot manager validated the application and handed over control.

Perform an update

  1. Rebuild the application with a higher version, for example -DTI_SDK_SIGN_MCUBOOT_IMG_VERSION=2.0, and keep the signed .bin.

  2. Send it to the running application:

    python mcuboot_fw_update_host.py --file <signed_app>.bin --port <serial port> --baudrate 115200
    
  3. Wait for the status LED to turn solid, which means the transfer completed and the CRC check passed.

  4. Reset the board. The boot manager authenticates the secondary image, swaps the banks and boots it.

Troubleshooting

Symptom

Likely cause

No LED activity after reset

Application not signed (ti_cst missing at build time), signed with a key that does not match the one in mcuboot_config.h, or boot manager not signed for ROM on an HSSE device

Status LED fast blink during transfer

A packet failed its CRC or sequence check, or a flash write failed; send a new START packet to retry

Transfer completes but the old image keeps booting

New image version is not higher than the running image, or the image is not authentic

Boot manager assertion at reset

Neither slot holds a valid image; reprogram a validly signed image

List of Supported Devices

Device

Boards

AM13E230X

am13e230x_lp (LaunchPad), am13e230x_som

AM13E232X

am13e232x_lp (LaunchPad)

Other devices are not supported yet. Adding one requires a device port in source/security/mcuboot/<device>/ and set(TI_SDK_INCLUDE_MCUBOOT ON) in the device CMake file.