2024-09-07 01:10 PM
Hi,
I'm trying to port the SBSFU onto the F407 controller based on F413 example.
--------------------------------------------------------------------------------------------------
What I've done so far:
I edited the linker files placed in the linker_common folder.
I have edited the linker as follows:
I have edited the mapping_sbsfu.ld as follows:
/* SE Code region */
VECTOR_SIZE = 0x200;
__ICFEDIT_SE_Code_region_ROM_start__ = 0x08000000 + VECTOR_SIZE;
__ICFEDIT_SE_CallGate_region_ROM_start__ = __ICFEDIT_SE_Code_region_ROM_start__; /* No need to do +4 as we have dummy bytes in SE_CoreBin .ld file */
__ICFEDIT_SE_CallGate_region_ROM_end__ = __ICFEDIT_SE_Code_region_ROM_start__ + 0x1FF;
/* SE key region */
__ICFEDIT_SE_Key_region_ROM_start__ = __ICFEDIT_SE_CallGate_region_ROM_end__ + 0x1;
__ICFEDIT_SE_Key_region_ROM_end__ = __ICFEDIT_SE_Key_region_ROM_start__ + 0xFF;
/* SE Startup: call before enabling protection */
__ICFEDIT_SE_Startup_region_ROM_start__ = __ICFEDIT_SE_Key_region_ROM_end__ + 0x1;
__ICFEDIT_SE_Code_nokey_region_ROM_start__ = __ICFEDIT_SE_Startup_region_ROM_start__ + 0x100;
/* Aligned SE End at the end of the 1st 32Kbytes of flash, MPU protection isolation required a fix size */
__ICFEDIT_SE_Code_region_ROM_end__ = 0x08007FFF;
/* SE IF ROM: used to locate Secure Engine interface code */
__ICFEDIT_SE_IF_region_ROM_start__ = __ICFEDIT_SE_Code_region_ROM_end__ + 1;
__ICFEDIT_SE_IF_region_ROM_end__ = __ICFEDIT_SE_IF_region_ROM_start__ + 0xCFF;
/* SBSFU Code region */
__ICFEDIT_SB_region_ROM_start__ = __ICFEDIT_SE_IF_region_ROM_end__ + 0x1;
/* Aligned SBSFU end at the end of the 1st 128Kbytes of FLASH, MPU protection isolation constraints */
__ICFEDIT_SB_region_ROM_end__ = 0x0801FFFF;
SE_Entry_Secure_ROM_Region_Length = __ICFEDIT_SE_CallGate_region_ROM_end__ - __ICFEDIT_SE_CallGate_region_ROM_start__ + 1;
SE_Key_region_ROM_Length = __ICFEDIT_SE_Key_region_ROM_end__ - __ICFEDIT_SE_Key_region_ROM_start__ + 1;
SE_Startup_region_ROM_Length = __ICFEDIT_SE_Code_nokey_region_ROM_start__ - __ICFEDIT_SE_Startup_region_ROM_start__ ;
SE_ROM_region_Length = __ICFEDIT_SE_Code_region_ROM_end__ - __ICFEDIT_SE_Code_nokey_region_ROM_start__ + 1;
SE_IF_region_ROM_Length = __ICFEDIT_SE_IF_region_ROM_end__ - __ICFEDIT_SE_IF_region_ROM_start__ + 1;
SB_ROM_region_Length = __ICFEDIT_SB_region_ROM_end__ - __ICFEDIT_SB_region_ROM_start__ + 1;
/* RAM section */
/* SE RAM1 region protected by firewall */
/* SE stack is placed 1st in RAM, stack overflow does not write on other RAM area */
__ICFEDIT_SE_region_RAM_start__ = 0x20000000;
__ICFEDIT_SE_region_RAM_stack_top__ = 0x20000400;
__ICFEDIT_SE_region_RAM_end__ = 0x20000FFF;
/* SBSFU RAM1 region */
__ICFEDIT_SB_region_RAM_start__ = __ICFEDIT_SE_region_RAM_end__ + 0x1;
__ICFEDIT_SB_region_RAM_end__ = 0x2002FFEF;
/* Shared RAM for Image State Handling */
__ICFEDIT_SB_FWIMG_STATE_region_RAM_start__ = __ICFEDIT_SB_region_RAM_end__ + 1;
__ICFEDIT_SB_FWIMG_STATE_region_RAM_end__ = 0x2002FFFF;
SE_RAM_region_Length = __ICFEDIT_SE_region_RAM_end__ - __ICFEDIT_SE_region_RAM_stack_top__ + 1;
SB_RAM_region_Length = __ICFEDIT_SB_region_RAM_end__ - __ICFEDIT_SB_region_RAM_start__ + 1;
MEMORY
{
SE_Entry_Secure_ROM_Region (rx) : ORIGIN = __ICFEDIT_SE_CallGate_region_ROM_start__, LENGTH = SE_Entry_Secure_ROM_Region_Length
SE_Key_region_ROM (rx) : ORIGIN = __ICFEDIT_SE_Key_region_ROM_start__, LENGTH = SE_Key_region_ROM_Length
SE_Startup_region_ROM (rx) : ORIGIN = __ICFEDIT_SE_Startup_region_ROM_start__, LENGTH = SE_Startup_region_ROM_Length
SE_ROM_region (rx) : ORIGIN = __ICFEDIT_SE_Code_nokey_region_ROM_start__, LENGTH = SE_ROM_region_Length
SE_IF_region_ROM (rx) : ORIGIN = __ICFEDIT_SE_IF_region_ROM_start__, LENGTH = SE_IF_region_ROM_Length
SB_ROM_region (rx) : ORIGIN = __ICFEDIT_SB_region_ROM_start__, LENGTH = SB_ROM_region_Length
SE_RAM_region (xrw) : ORIGIN = __ICFEDIT_SE_region_RAM_stack_top__, LENGTH = SE_RAM_region_Length
SB_RAM_region (xrw) : ORIGIN = __ICFEDIT_SB_region_RAM_start__, LENGTH = SB_RAM_region_Length
}
and the mapping_fwimg.ld as follows:
/* Slots must be aligned on sector size */
/* swap (128 kbytes) */
__ICFEDIT_SWAP_start__ = 0x08020000;
__ICFEDIT_SWAP_end__ = 0x0803FFFF;
/* Active slot #1 (128 kbytes) */
__ICFEDIT_SLOT_Active_1_start__ = 0x08040000;
__ICFEDIT_SLOT_Active_1_end__ = 0x0805FFFF;
__ICFEDIT_SLOT_Active_1_header__ = __ICFEDIT_SLOT_Active_1_start__;
/* Dwl slot #1 (128 kbytes) */
__ICFEDIT_SLOT_Dwl_1_start__ = 0x08060000;
__ICFEDIT_SLOT_Dwl_1_end__ = 0x0807FFFF;
/* Slots not configured */
__ICFEDIT_SLOT_Active_2_header__ = 0x00000000;
__ICFEDIT_SLOT_Active_2_start__ = 0x00000000;
__ICFEDIT_SLOT_Active_2_end__ = 0x00000000;
__ICFEDIT_SLOT_Active_3_header__ = 0x00000000;
__ICFEDIT_SLOT_Active_3_start__ = 0x00000000;
__ICFEDIT_SLOT_Active_3_end__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_2_start__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_2_end__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_3_start__ = 0x00000000;
__ICFEDIT_SLOT_Dwl_3_end__ = 0x00000000;
-------------------------------------------------------------------------------------
In the SE project:
I have not made any changes.
In the SBSFU project:
1. I replaced the f413 startup file with: startup_stm32f407vetx.s
2. I have removed the BSP package, and where errors have occurred, I wrote simple custom initialization, and interaction functions to replace the BSP functions.
In the User App project:
1. I replaced the f413 startup file with: startup_stm32f407vetx.s
2. I have removed the BSP package, and where errors have occurred, I wrote simple custom initialization, and interaction functions to replace the BSP functions. No further changes were made to the specific .ld files of each project because they seem to be all based on the first two provided linker files.
------------------------------------------------------------------------------------------------------------
The results were the following:
I built the projects, I have no errors.
I then programed all three .elf files. Nothing happened.
I see no results on the connected UART port, and the configured LED does not blink.
--------------------------------------------------------------------------------------------------------------
To further debug the problem
I decided to run the SE project through the debugger and move through the code line by line.
I could not get passed the ENTRY function which was the CallGate.
As I understand, the LR must be in the correct range, so I manually gave it the correct range. And then the RAM pointer of the peSE_Status is checked to be in the correct range.
I switched it out to and used the pFlash pointer, pointing to an indefinite correct RAM pointer.
Still no luck.
(BTW, I found that inside the (addr_end) is compared to a fixed incorrect F413 value (0x2004FFFFU), which I again corrected to match the F407 RAM range (0x2002FFFFU).
--------------------------------------------------------------------------------------------------------------
Please guide me as to what I'm doing wrong in the porting process.
I'll be happy to provide more information if needed.
Thank you in advance.