[S32K3] Image verificaiton fail in Secure boot

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

[S32K3] Image verificaiton fail in Secure boot

跳至解决方案
1,488 次查看
Changhawn
Contributor III

Hi. 

Now I have developed Secure boot with HSE. In bootloader sequence, application image should be verified. 

S32K344_Basic_SecureBoot Project is refered in S32K3_HSE_DemoExamples.

The verifying function (HSE_VerifyBootImage) is returning failure (HSE_SRV_RSP_VERIFY_FAILED). 

Could you recommand my mistake and comment and fail reason?

My project loader and code is attached like below.

Thank you.

 

log output)

Flash Erase Ok
Flash Program ok(7d2040, len:128)
[SEC BOOT] Image Verify failed.(0x55a5a164)

 

Code)

#define ADKP_LENGTH (uint8_t)16U
 
#define TAG_LENGTH 28
#define APP_HEADER_LENGTH 0x40U
 
/* RAM address for GMAC */
uint8_t temp_addr_of_app_image[32] = {0xFF};
 
const uint8_t* pAppBL = APP_ADDR; //Application Start 0x500000 in ld
uint32_t AppBL_codeLength = (APP_SIZE - 0x2000); //APP_SIZE 0x2d4000 in ld --> 0x2d2000
 
/* ADKP Key/Password required variables */
volatile uint8_t programmed_appdebugkey[ADKP_LENGTH] = {0U}; //Store the reading of the ADKP
volatile uint8_t applicationDebugKeyPassword[16U] =
{
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
  0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x21
};
hseSrvResponse_t HSE_ProgramAdkp(void)
{
    hseSrvResponse_t srvResponse;
 
    /* WARNING: This operation is irreversible */
    /* Program the ADK/P (Application debug key/password) */
    srvResponse = SetAttr(HSE_APP_DEBUG_KEY_ATTR_ID,
        sizeof(hseAttrApplDebugKey_t), (void *)&applicationDebugKeyPassword);
    return srvResponse;
}
 
/* Reads ADKP hash */
hseSrvResponse_t HSE_ReadAdkp( uint8_t *pDebugKey )
{
    hseSrvResponse_t srvResponse;
    srvResponse = GetAttr
            (
                    HSE_APP_DEBUG_KEY_ATTR_ID,
                    sizeof(hseAttrApplDebugKey_t),
                    (void *)pDebugKey
            );
    return srvResponse;
}
 
bool secure_boot_fw_verify(void)
{
  hseSrvResponse_t srvResponse;
  uint32_t temp_addr_of_app_image[32] = {0xFF};
 
  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))
  {
    SYS_TRACE("[SEC BOOT] ADKP is not programmed\r\n");
    srvResponse = HSE_ProgramAdkp();
    if (HSE_SRV_RSP_OK != srvResponse)
    {
      SYS_TRACE("[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)
  {
    SYS_TRACE("[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));
 
  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)
  {
    SYS_TRACE("[SEC BOOT] Image Verify failed.(0x%x)\r\n", srvResponse);
    return false;
  }
  else
  {
    SYS_TRACE("[SEC BOOT] Image Verify ok\r\n");
    return true;
  }
 
}
 
/* bootloader main */
main()
{
....
secure_boot_fw_verify();
....
}
 
 
MEMORY 
{
    int_pflash               : ORIGIN = 0x00400000, LENGTH = 0x00040000       /* 256K*/
    HSE_BINARY              : ORIGIN = 0x00440200, LENGTH = 0x00024000 /* Leave block 0 for HSE FW binary */
    int_flash               : ORIGIN = 0x00500000, LENGTH = 0x002D4000 /* Use only blocks 1,2,3 for install project */
...
 
 
#define IVT_BOOT_CFG_WORD_BOOT_SEQ  (1 << 3)
 
.section ".boot_header","ax"
  .long SBAF_BOOT_MARKER /* IVT marker */
  .long (CM7_0_ENABLE << CM7_0_ENABLE_SHIFT) | (CM7_1_ENABLE << CM7_1_ENABLE_SHIFT) | IVT_BOOT_CFG_WORD_BOOT_SEQ /* Boot configuration word */
0 项奖励
回复
1 解答
1,455 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @Changhawn 

Do you follow this?

lukaszadrapa_0-1734104170173.png

It's a screenshot from Secure boot application note.

You can check how it is implemented in S32K344_SecureBootBlinky project in HSE DemoExamples.

Regards,

Lukas

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,456 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi @Changhawn 

Do you follow this?

lukaszadrapa_0-1734104170173.png

It's a screenshot from Secure boot application note.

You can check how it is implemented in S32K344_SecureBootBlinky project in HSE DemoExamples.

Regards,

Lukas

0 项奖励
回复
1,429 次查看
Changhawn
Contributor III
Hi Lukaszadrapa
Thank you for your support.
0 项奖励
回复