Creating an SBSFU (Secure Boot and Secure Firmware Update) implementation on the STM32H563RI involves several steps. The STM32H563 is part of STM32H5 series which includes built-in security features and supports STM32Trust ecosystem.
Here's a comprehensive guide to implement SBSFU on your STM32H563RI:
Prerequisites
First, ensure you have the necessary tools:
- STM32CubeIDE or IAR/Keil toolchain
- STM32CubeProgrammer
- STM32CubeH5 firmware package (includes SBSFU examples)
- X-CUBE-SBSFU expansion package (though H5 has native secure boot support)
Key Concepts for STM32H5 Security
The STM32H563 uses a different approach than older STM32 series. It features:
- TrustZone technology
- Secure boot based on immutable Root of Trust (RoT)
- OEMiRoT (OEM immutable Root of Trust) or STiRoT (ST immutable Root of Trust)
- Secure storage and cryptographic acceleration
Implementation Steps
Step 1: Configure Security Features
Start by setting up the basic security configuration using STM32CubeMX:
- Enable TrustZone
- Configure SAU (Security Attribution Unit) regions
- Set up secure and non-secure memory regions
- Configure FLASH memory layout for:
- Secure bootloader area
- Secure application area
- Non-secure application area
- Download area for firmware updates
Step 2: Implement Secure Boot
For STM32H5, you have two main options:
Option A: Using STiRoT (ST immutable Root of Trust)
- This is ST's pre-programmed secure boot solution
- Configure through STM32CubeProgrammer's RoT provisioning
- Define secure boot configuration (SB option bytes)
- Set up authentication keys
Option B: Using OEMiRoT (OEM immutable Root of Trust)
- Implement your own secure bootloader
- Must be programmed in the secure area
- Implement cryptographic verification of firmware
Step 3: Set Up Memory Layout
A typical memory layout might look like:
0x08000000 - 0x0801FFFF: Secure Bootloader (OEMiRoT/STiRoT)
0x08020000 - 0x0805FFFF: Secure Application
0x08060000 - 0x080FFFFF: Non-Secure Application
0x08100000 - 0x081FFFFF: Download Slot (for updates)
Step 4: Implement Firmware Update Mechanism
The secure firmware update process typically involves:
- Download Phase: New firmware is downloaded to a dedicated slot
- Verification Phase: Bootloader verifies the authenticity and integrity
- Installation Phase: If valid, firmware is copied to the active slot
- Rollback Protection: Implement version checking to prevent downgrade attacks
Step 5: Key Management
Set up cryptographic keys for:
- Firmware authentication (using ECDSA or RSA)
- Firmware encryption (optional, using AES)
- Secure storage of keys in OTP or secure FLASH regions
Step 6: Code Implementation
Here's a basic structure for the secure bootloader:
// Secure bootloader main function
void SecureBootloader_Main(void)
{
// Initialize hardware and security features
HAL_Init();
SystemClock_Config();
// Check for firmware update in download slot
if (IsFirmwareUpdateAvailable())
{
// Verify firmware signature
if (VerifyFirmwareSignature(DOWNLOAD_SLOT_ADDR))
{
// Check version to prevent rollback
if (CheckFirmwareVersion(DOWNLOAD_SLOT_ADDR))
{
// Install new firmware
InstallFirmware(DOWNLOAD_SLOT_ADDR, APP_SLOT_ADDR);
}
}
}
// Verify active firmware
if (VerifyFirmwareSignature(APP_SLOT_ADDR))
{
// Jump to application
JumpToApplication(APP_SLOT_ADDR);
}
else
{
// Handle error - no valid firmware
ErrorHandler();
}
}
Step 7: Configure Option Bytes
Use STM32CubeProgrammer to set:
- RDP (Read Protection) level
- Secure area boundaries
- Boot configuration
- Write protection for bootloader area
Step 8: Testing and Validation
- Test normal boot sequence
- Test firmware update process
- Verify rollback protection
- Test fault injection resistance
- Validate secure/non-secure boundaries
Important Considerations
- The STM32H563 has specific security features that differ from older STM32 series
- Always refer to the latest STM32H5 reference manual and application notes
- Consider using ST's X-CUBE-SBSFU examples as a starting point
- Implement proper error handling and logging
- Plan for key provisioning in production
Resources
- AN5447: Overview of STM32H5 security features
- UM2237: STM32CubeProgrammer user manual
- STM32H5 HAL documentation
- STM32Trust ecosystem documentation
The exact implementation details will depend on your specific security requirements and use case. I recommend starting with the SBSFU examples provided in the STM32CubeH5 package and adapting them to your needs.