cancel
Showing results for 
Search instead for 
Did you mean: 

Programming My Own Secret Into Memory And Using It In Secure App for H573

cgj004
Associate II

I'm using the STM32H573 Discovery Kit, and I've successfully run the TrustZone Enabled and SFI tutorials.  

 
So for my next step, I wanted to use the SFI process to program the H573 board with the OEMiROT Boot, Secure App, and Non Secure Apps.
In addition, my other goal was to place (program) a secret key/data into a known memory location (provisioned via Option Bytes Key/OBK) and successfully extract/use it in the Secure Application.
 
I've encountered failures on multiple levels trying to do this.
 
I thought I had successfully mastered the SFI process, but I got to a point where I couldn't regress one of my H5 boards, so I have an open ticket for that issue.
This particular post is for feedback on if I'm doing the procedure correctly to program the secret key and the code I'm using to access it and use it.  I think I created the .xml file to program the key into the location I want properly, but I've been running into failure after failure either with compilation or execution of the code.  First, I've attached the OEMiRoT_Config_appl_key - Copy.xml file.
 
 
The next thing I did was define a table for the HDPL3 APIs I wanted to use in stm32hxx_bl2.ld:
 
/* Define the fixed, non-volatile address for the HDPL3 API table */
_HDPL3_API_TABLE_START = 0x0C020000; 
 
....
    .text :
    {
        KEEP(*(.BL2_Error_Code))
    } > FLASH

    /* My changes */
    .hdpl3_api_table (READONLY) :
    {
        . = _HDPL3_API_TABLE_START; /* Explicitly set the start address to 0x0C020000 */
        . = ALIGN(4);
        KEEP(*(.hdpl3_func_table)) /* Collects the table defined in C code */
        . = ALIGN(4);
    } > FLASH

    /*__etext = .;*/
    /* Adjust __etext to follow the new section in FLASH */
    __etext = ADDR(.hdpl3_api_table) + SIZEOF(.hdpl3_api_table);
 
 
In low_level_obkeys.h, I defined the following:
 

/* HDPL 3 Function Table Fixed Address */

#define HDPL3_API_TABLE_ADDR 0x0C020000 //0x0D000000UL

 

extern OBK_Hdpl3Data OBK_Hdpl3_Data;
 

/* === START OF HDPL 3 PROTOTYPE === */

HAL_StatusTypeDef OBK_ReadHdpl3Data(OBK_Hdpl3Data *pOBK_Hdpl3Data);

/* === END OF HDPL 3 PROTOTYPE === */

// Define the function pointer type for your key reader

typedef HAL_StatusTypeDef (*OBK_ReadHdpl3Data_TypeDef)(OBK_Hdpl3Data *pOBK_Hdpl3Data);

// Define the structure that holds the entry points for your HDPL3 services

typedef struct

{

volatile const OBK_ReadHdpl3Data_TypeDef ReadHdpl3Data;

// Add other HDPL3-specific functions here

} HDPL3_pFuncTypeDef;

// Declare the global external pointer to this structure

extern HDPL3_pFuncTypeDef *HDPL3_pFunc;

 

I've also attached the changes I made to low_level_key.c and the Secure Application's main.c.
Basically, in the Secure App, I wanted to be able to access the security functions provided by the OEMiROT Boot through a function pointer to be able to extract and use the secret key that I (hopefully) programmed into memory.  But I either run into build issues with the table or the function pointer ends up being NULL which causes a fault.  I've even tried using a different memory location but I've run into compile issues when I try to do that as well.
 
This seems like something that should be doable even if TrustZone is enabled.  I don't know if I'm making it too hard, or if it's way harder than I'm expecting.. Perhaps I should just try this with TrustZone disabled?   I don't know.. I've been at this for months and haven't gotten over the hump yet.
 
 
(Virus scan in progress ...)
(Virus scan in progress ...)
(Virus scan in progress ...)
0 REPLIES 0