I want to implement Secure Boot in S32K1 MCU's using CSEc Peripheral. But not able to get what would be intended demo and flow for it.
What mu understadning is on configuring secure boot, CSEc peripheral will calculate the CMAC onto the application binary using Boot key.
1) In which API, do we refer or how we send the application binary information. In API CSEC_DRV_BootDefine() we only mention size and type of secure boot. But where will we tell, at which address application binary is of which CMAC has to be calculated.
2) What my understanding, CSEc will calculate the CMAC of the application binary and store it in Boot_MAC_Slot. This will be happening by which API? As their are 3 API's for secure boot in CSEc: CSEC_DRV_BootDefine(), CSEC_DRV_BootOK() and CSEC_DRV_BootFailure(). Out of these which one?
3) What would be flow of API's to use the secure boot.?
i have written a piece of code that i will dump at 0x00 address. In that piece of code i have written following API's:
int main(void)
{
uint32_t u32BootSize = 0x00018000U;
status_t statusVal;
/* Write your code here */
/* Initialize and configure clocks
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);
status_t flash_init_for_csec;
/* Initialize pins */
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);
/* Turn off the leds */
PINS_DRV_SetPins(LED_PORT, (1 << LED_ERROR) | (1 << LED_OK));
bool keyLoaded;
uint8_t key[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
/* Initialize CSEc driver */
CSEC_DRV_Init(&csecState);
/* Initialize Flash for CSEc operation */
flash_init_for_csec = initFlashForCsecOperation();
/* Load the MASTER_ECU key with a known value, which will be used as Authorization
* key (a secret key known by the application in order to configure other user keys) */
keyLoaded = setAuthKey();
/* Load the selected key */
//load the BOOT_MAC_KEY
keyLoaded = loadKey(CSEC_BOOT_MAC_KEY, key, 1);
statusVal = CSEC_DRV_BootDefine(u32BootSize, CSEC_BOOT_SERIAL);
statusVal = CSEC_DRV_BootOK();
lets say this piece of code occupies memory till 0x100.
4) Now, i just run this piece of code first time. It will store the Boot MAC value. And then run this again, that will perform secure boot mechanism?
5) And now lets say my main application is at address 0x300. So i will dump the application binary at 0x300. But how and where should i put logic that if CMAC is not verified or equal then perform x set of instruction or code. Like i Dont want the application to get execute if CMAC does not matches.
6) Will this logic be implemented in application fw, just at the starting of its main()? Is yes, then how will i get the value of newly generated CMAC and stored CMAC value to compare? OR i have to check the FCSESTAT register's in application binary?