1.3.1 PIC32CX-BZ6 Secure Boot ROM Help

The Boot ROM allows to ensure the integrity of the device at boot.

An immutable boot sequence (Secure Boot Code) is implemented into a ROM called the Secure Boot ROM. The Secure Boot ROM manages Test mode entry, firmware and data authentication, firmware loading, and necessary system configurations.

For secure boot support on the PIC32CX-BZ6, a 64KB ROM is dedicated to the secure boot firmware. Keys and credentials required for code authentication are stored as a part of eFuses. On every reset, secure boot firmware authenticates the rest of the program image in the Flash.

Features
  • Immutable boot support with ROM
  • Firmware code authentication (Only at Boot time)
  • Support for immutable keys
  • Microchip or customer programmable secure boot key
  • Support for secure execution environment
  • Supports Anti-roll back
  • Support for firmware readable life cycle counter
  • Defined system boot state

Boot ROM Flow

Figure 1-2. Boot ROM Flow

Once the device comes out of reset, Boot ROM firmware checks if Test mode is triggered, if not it continues with chip initialization. After the completion of chip initialization, the bootstrap code checks for a valid firmware image and executes. If the device does not find any valid image, it jumps to Secure Safe mode. For validating the firmware image, the bootstrap code uses the security library depending on the firmware images authentication scheme specified for that firmware.

Firmware programming is handled by Device Firmware Update (DFU) using Device Service Unit (DSU). DSU supports the Debug mode, also it implements a CoreSight Debug ROM that provides device identification as well as identification of other debug components within the system. See Device Service Unit (DSU) from Related Links.

The following options are valid images for a PIC32CX-BZ6 device:
  • An image with valid structure (defined in Table 1-14) and without using any authentication scheme.
  • An image with a valid structure (defined inTable 1-14 ) with an authentication scheme supported by the device. For supporting the authentication scheme using public key cryptography, EFUSE must have a valid SECURE_BOOT_KEY.
  • If the device is secured (with SECURE_BOOT_KEY! = 0), the valid image must always use the ECDSA p384 + SHA 384 or ECDSA p256 + SHA 256 for authentication.

Firmware Image Format

Firmware image comes with a metadata header, metadata payload, and metadata footer that gives the ROM firmware information about location of the firmware image, security decryption/ authentication information, sequence number and more. Application (Firmware Image) can only be executed from Embedded Flash or Boot Flash.

The following table provides details about the contents of each firmware image.

Table 1-14. Firmware Image Description
OffsetNameDescription
Metadata Header
0x00:0x17FillerSet to all zero
0x18:0x1BMANU_IDENTIFIER“MCHP” ASCII String Identifier
0x1C:0x3BFillerSet to all zero
0x3C:0x3FSEQ_NUM

Metadata sequence number of the image in Little Endian

(LE). Monotonically decreasing image index. Values of 0 indicates that the image is invalid;

value of 0xFFFFFFFF indicates that the image is unauthenticated.

0x40MD_REV

Support Metadata Header Version

Note: This field must be set to 0x03 for this version of metadata header.

0x41CONT_IDX0x01 – Plain firmware image
0x42MD_AUTH_MTHD

Metadata authentication method.

0x00 – None

0x02 – ECDSA p256 + SHA256

0x03 – ECDSA p256 + SHA2-384

0x43MD_AUTH_KEY

Key index for authenticating metadata.

0x00 – Secure boot Key

0x44PL_DEC_MTHD

Payload decryption method.

0x00 – Plain

0x45PL_DEC_KEYNot applicable.
0x46:0x47PL_LENMetadata payload length. The payload length for this version must be 0x74.
Metadata Payload = Firmware Image Header
0x48:0x4BFW_IMG_REVFirmware image revision (little endian).
0x4C:0x4FFW_IMG_SRC_ADDR

Firmware Image source address.

The source address of the firmware image in persistent storage. This field is not authenticated and the OTA or Bootloader can rewrite it based on the image storage location selected.

0x50:0x53FW_IMG_DST_ADDR

Firmware image destination address.

The destination address will be used as the jump address during the application transition. As the ROM firmware must copy this header structure into executable memory, the destination address must not be less than 0x200.

0x54:0x57FW_IMG_LEN

Firmware image length.

The firmware image length must be a multiple of 4096 (Count) bytes.

0x58FW_IMG_AUTH_MTHD

Firmware image authentication method.

0x00 – None

0x02 – ECDSA p256 + SHA-256

0x03 – ECDSA p384 + SHA2-384

0x59FW_IMG_AUTH_KEY

Firmware image authentication key index.

0x00 – Secure boot key

0x5AFW_IMG_DEC_MTHD

Firmware image decryption method.

0x00 – Plain

0x5BFW_IMG_DEC_KEYNot applicable.
0x5C:0xBBFW_IMG_SIG

The following are the options of firmware image signature: The concatenated R and S term of the ECDSA signature (P-256) of the SHA-256 hash of the firmware image specified by FW_IMG_SRC_ADDR and FW_IMG_LEN.

(or)

The concatenated R and S term of the ECDSA signature (P-384) of the SHA-384 hash of the firmware image specified by FW_IMG_SRC_ADDR and FW_IMG_LEN.

Metadata Footer
0xBC:0x11BMD_SIG

The following are the options of metadata payload signature: The concatenated R and S term of the ECDSA signature (P-256) of the SHA-256 hash of the firmware image specified by FW_IMG_SRC_ADDR and FW_IMG_LEN.

(or)

The concatenated R and S term of the ECDSA signature (P-384) of the SHA-384 hash of the firmware image specified by FW_IMG_SRC_ADDR and FW_IMG_LEN.

Table 1-15. Firmware Images Lookup Table 2MB Flash Variant
AddressSize (bytes)
Image 0 metadata0x0080_0000512
Image 00x0080_0200Max: 60928
Image 1 metadata0x0080_8000512
Image 10x0080_8200Max: 28160
Image 2 metadata0x0100_0000512
Image 20x0100_0200Max: 2096640
Image 3 metadata0x0110_0000512
Image 30x0110_0200Max: 1048064
Table 1-16. Firmware Images Lookup Table 1MB Flash Variant
AddressSize (bytes)
Image 0 metadata0x0080_0000512
Image 00x0080_0200Max: 60928
Image 1 metadata0x0080_8000512
Image 10x0080_8200Max: 28160
Image 2 metadata0x0100_0000512
Image 20x0100_0200Max: 1048064
Image 3 metadata0x0108_0000512
Image 30x0108_0200Max: 523776
  • Image 0: External Flash Bootloader - Primary Image
  • Image 1: External Flash Bootloader - Secondary Image
  • Image 2: Embedded Flash image 0
  • Image 3: Embedded Flash image 1 in the second panel (possible only if image < 256KB; including headers)

Based on the above tables, the ROM firmware will check for a valid image in 4 memory locations. Table 1-16.

DSU Mode Entry

Immediately after resetting, the ROM firmware reads the condition of Code Protect, and Device Secured State bits to determine the Device Security state. Security state the ROM firmware needs to perform specific actions.

Serial Debugging and Programming

  • The device is not code-protected and unsecured, supports debugging and programming features.
  • The device is code-protected and unsecured, supports debugging, erase and programming features.
  • The device is not code-protected and secured, does not support the debugging feature, and supports the programming feature.
  • The device is not code-protected and secured, does not support the debugging feature, erase and supports the programming feature.

Chip Initialization

All the necessary hardware modules that the BOOT ROM program uses will be initialized – System clock, Interrupts, and more.

Firmware Authentication and Loading

The firmware image validation block is the primary block that ensures the integrity/authenticity of the images that are run on a secured device.

Firmware Image Validation – Secured Mode

The following are the main blocks in the process of image validation:

  1. READ_CFG - Read device configuration (device id, secure elements). Secure elements and device id information can be accessed from EFUSE memory.
  2. LOOKUP_METADATA - Search for valid firmware image metadata with the lowest sequence number.
  3. AUTHENTICATE_IMAGE - Authenticate the image based on the security configuration of the device (EFUSE) and as indicated by its metadata. The firmware image header dictates the authentication scheme. Secure Boot is done on successful authentication of the firmware.
  4. RUN_APPLICATION - If the valid image is in embedded flash and is available in its destination address space, jump to the DST_ADDR as indicated by its metadata.
  5. SECURE_SAFE_MODE - Secure Safe mode is a while 1() loop in the firmware, where the device is waiting for a valid application image to execute.

Firmware Image Validation – Unsecured Mode

In the Unsecured mode, the device is not checked for authentication scheme that needs SECURE_BOOT_KEY.

If the device is unsecured (and SECURE_BOOT_KEY is invalid and the Device Secured state is not set), the bootstrap code looks for valid images (valid sequence number, header and more.). Root of trust cannot be possible in this scenario.