cancel
Showing results for 
Search instead for 
Did you mean: 

memory map adjust SBSFU on a STM32G474

dominik
Senior

Hi

I'm using the dual image function on a 512kB STM32G474. I like to adjust the bootloader size to 32kb because my user App is too big.

In the AN5056 there is a note how to adjust it, but I'm not sure if this lines in the file low_level_security.h are correct? Can anybody help me please?

#define SFU_PROTECT_MPU_EXEC_SE_RGNV  MPU_REGION_NUMBER7
#define SFU_PROTECT_MPU_EXEC_SE_START FLASH_BASE           /*!< Flash memory area */
#define SFU_PROTECT_MPU_EXEC_SE_SIZE  MPU_REGION_SIZE_16KB //eud MPU_REGION_SIZE_32KB
#if defined (__GNUC__)
#define SFU_PROTECT_MPU_EXEC_SE_SREG  0xE0U                /*!< 32 Kbytes / 8 * 5 ==> 20 Kbytes */
#elif defined(__CC_ARM)
#define SFU_PROTECT_MPU_EXEC_SE_SREG  0x80U                /*!< 32 Kbytes / 8 * 7 ==> 28 Kbytes */
#else
#define SFU_PROTECT_MPU_EXEC_SE_SREG  0xC0U                /*!< 32 Kbytes / 8 * 6 ==> 24 Kbytes */
#endif /* (__GNUC__) */
#define SFU_PROTECT_MPU_EXEC_SE_PERM  MPU_REGION_PRIV_RO
#define SFU_PROTECT_MPU_EXEC_SE_EXECV MPU_INSTRUCTION_ACCESS_ENABLE
#define SFU_PROTECT_MPU_EXEC_SE_TEXV  MPU_TEX_LEVEL0
#define SFU_PROTECT_MPU_EXEC_SE_B     MPU_ACCESS_NOT_BUFFERABLE
#define SFU_PROTECT_MPU_EXEC_SE_C     MPU_ACCESS_CACHEABLE

Is the setting for SFU_PROTECT_MPU_EXEC_SE_SREG the same like before?

thanks

/*###ICF### Set of symbols used in SE and SB_SFU projects ****/
 
/* Slots Regions must be aligned on 4096 bytes (0x1000) */
 
/* swap region (8 Kbytes) */
define exported symbol  __ICFEDIT_region_SWAP_start__  = 0x08042000;
define exported symbol  __ICFEDIT_region_SWAP_end__    = 0x08043FFF;
 
/* slot 0 region (232 Kbytes) */
define exported symbol  __ICFEDIT_region_SLOT_0_start__= 0x08008000;
define exported symbol  __ICFEDIT_region_SLOT_0_end__  = 0x08041FFF;
 
/* slot 1 region (232 KBytes) */
define exported symbol  __ICFEDIT_region_SLOT_1_start__= 0x08044000;
define exported symbol  __ICFEDIT_region_SLOT_1_end__  = 0x0807DFFF;
 
/* firmware images regions definition */
define region SWAP_region   = mem:[from __ICFEDIT_region_SWAP_start__ to __ICFEDIT_region_SWAP_end__];
define region SLOT_0_region = mem:[from __ICFEDIT_region_SLOT_0_start__ to __ICFEDIT_region_SLOT_0_end__];
define region SLOT_1_region = mem:[from __ICFEDIT_region_SLOT_1_start__ to __ICFEDIT_region_SLOT_1_end__];
/* SE Startup: call before enabling protected area */
define exported symbol __ICFEDIT_SE_Startup_region_ROM_start__    = __ICFEDIT_SE_Key_region_ROM_end__ + 1;
define exported symbol __ICFEDIT_SE_Code_nokey_region_ROM_start__ = __ICFEDIT_SE_Startup_region_ROM_start__ + 0x100;
/* Aligned SE End at the end of the 1st 12Kbytes of flash, MPU protection isolation constraints */
define exported symbol __ICFEDIT_SE_Code_region_ROM_end__         = 0x08002FFF;
 
/* SE IF ROM: used to locate Secure Engine interface code out of protected area */
define exported symbol __ICFEDIT_SE_IF_region_ROM_start__         = __ICFEDIT_SE_Code_region_ROM_end__ + 1;
define exported symbol __ICFEDIT_SE_IF_region_ROM_end__           = __ICFEDIT_SE_IF_region_ROM_start__ + 0x5FF;
 
/* SBSFU Code region */
define exported symbol __ICFEDIT_SB_region_ROM_start__            = __ICFEDIT_SE_IF_region_ROM_end__ + 1;
/* Aligned SBSFU end at the end of the 1st 32Kbytes of FLASH, MPU protection isolation constraints */
define exported symbol __ICFEDIT_SB_region_ROM_end__              = 0x08007FFF;

20 REPLIES 20
Jocelyn RICARD
ST Employee

Hi Dominik,

to trigger the update from the application you can rely on the fact the RAM content is not changed upon system reset.

So, you can define a specific memory location that will contain a magic value indicating the SBSFU to switch to update procedure at next reset.

You can look in the STM32WB example where such mechanism is used for activating external loader.

void FW_UPDATE_Run(void)
{
  /* Print Firmware Update welcome message */
  printf("\r\n================ New Fw Download =========================\r\n\n");
 
  /* Standalone loader communication : execution requested */
  (*(uint32_t *)LOADER_COM_REGION_RAM_START) = STANDALONE_LOADER_BYPASS_REQ;
 
  NVIC_SystemReset();
} 

LOADER_COM_REGION_RAM_START is the RAM address and STANDALONE_LOADER_BYPASS_REQ is the magic.

Best regards

Jocelyn