In S32K314 platform, we are developping secure boot(Basic Secure Boot) of Application image in Bootloader.
We did below 1,2,3
1. Bootloader is 0x00400000, and ivt (boot_header) is located at 0x00400000.
IVT_BOOT_CFG_WORD_BOOT_SEQ (1 << 3) in the boot configuration word of ivt was not set separately.
2. Application is 0x00500000, and app_boot_header for secure boot is located at 0x00500000 with the value below.
Application has no IVT. Image signing and verification is failed By IVT header. So remove it.
const hseAppHeader_t __attribute__((section("._app_boot_header"))) app_header =
{
.hdrTag = 0xD5 ,
.reserved1 = {0xFF, 0xFF},
.hdrVersion = 0x60 ,
.pAppDestAddres = 0x00,
.pAppStartEntry = (uint32_t)(&__text_start),
.codeLength = (uint32_t)(0x2d0000),
.coreId = 0x00u ,
.reserved2 = {0},
};
3. In bootloader, Image signing & verification for secure boot of application is successful as follows.
bool secure_boot_fw(void)
{
hseSrvResponse_t srvResponse;
memset((void *)&programmed_appdebugkey,0U,ADKP_LENGTH);
srvResponse = HSE_ReadAdkp((uint8_t *)&programmed_appdebugkey);
/*
* First time when ADKP is not programmed,
* read adkp will always result in not allowed
* If ADKP is not programmed then do so
*/
if( (HSE_SRV_RSP_NOT_ALLOWED == srvResponse))
{
printf("[SEC BOOT] ADKP is not programmed\r\n");
srvResponse = HSE_ProgramAdkp();
if (HSE_SRV_RSP_OK != srvResponse)
{
printf("[SEC BOOT] Program ADKP is failed.(0x%x)\r\n", srvResponse);
return false;
}
}
/* Generate Tag of size 32 over the provided APPBL */
srvResponse = HSE_SignBootImage(pAppBL, TAG_LENGTH, temp_addr_of_app_image);
if (HSE_SRV_RSP_OK != srvResponse)
{
printf("[SEC BOOT] Sign Image failed.(0x%x)\r\n", srvResponse);
return false;
}
GVP_FlashErase(pAppBL + APP_HEADER_LENGTH + AppBL_codeLength, sizeof(temp_addr_of_app_image));
TestDelay(5000);
GVP_FlashProgram(pAppBL + APP_HEADER_LENGTH + AppBL_codeLength , temp_addr_of_app_image, sizeof(temp_addr_of_app_image));
/* Verify that the generated TAG is valid for the APPBL */
srvResponse = HSE_VerifyBootImage(pAppBL);
if (HSE_SRV_RSP_OK != srvResponse)
{
printf("[SEC BOOT] Image Verify failed.(0x%x)\r\n", srvResponse);
return false;
}
else
{
printf("[SEC BOOT] Image Verify ok\r\n");
return true;
}
}
question)
After I've done image verification in the bootloader, I want to jump to the application. I don't know how to do it.
Option 1)
Set IVT_BOOT_CFG_WORD_BOOT_SEQ (1 << 3) in the boot configuration word of the bootloader ivt and reset it. Is it right?
--> C40 API does not work up to bootloader (0x400000) 256k. See Option 1 below.
Option 2) Force jump to the application code start address without the application IVT.
--> See option 2. Fault occurs and jump does not occur.
Option 1. after image verification, set the boot configuration word IVT_BOOT_CFG_WORD_BOOT_SEQ (1 << 3) IVT of bootloader
#define BLOCK0_IVT_ADDRESS 0x00400000U
bool set_secure_boot(void)
{
ivt_t IVT;
memcpy((void *)&IVT, (void *)BLOCK0_IVT_ADDRESS, 0x100U);
GVP_FlashErase(BLOCK0_IVT_ADDRESS, 0x100U);
TestDelay(5000);
IVT.bootCfgWord |= IVT_BOOT_CFG_WORD_BOOT_SEQ;
GVP_FlashProgram(BLOCK0_IVT_ADDRESS , (uint8_t *)&IVT, 0x100U );
}
c40 api(C40_Ip_MainInterfaceSectorEraseStatus) fault is happened.
Option 2.
bool secure_boot_jump(void)
{
hseAppHeader_t *pAppHeader = (hseAppHeader_t *)APP_ADDR;
/* verify the header */
if (pAppHeader->hdrTag != 0xD5U || pAppHeader->hdrVersion != 0x60U)
{
printf("[SEC BOOT] APP Header is failed\r\n");
return false;
}
// check the pAppStartEntry (Not NULL, check if valid)
if (pAppHeader->pAppStartEntry == 0U || pAppHeader->pAppStartEntry == 0xFFFFFFFFU)
{
printf("[SEC BOOT] APP Header is failed with startEntry\r\n");
return false;
}
typedef void (*AppEntryPoint)(void);
AppEntryPoint AppEntry = (AppEntryPoint)pAppHeader->pAppStartEntry; //(0x00500080)
/* Without Timer HAL init, application jump has some problem */
TIMER_HAL_Deinit();
/* Interrupt disable */
__asm volatile ("cpsid i" : : : "memory");
IntCtrl_Ip_DisableIrq(PIT0_IRQn);
/* S32_SCB->VTOR = (uint32_t)(pAppHeader->pAppStartEntry); */
AppEntry();
}