cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, I am porting SBSFU to STM32L496 and want to use USB Virtual port to replace UART2, Now SNSFU failed at calling __IS_SFU_RESERVED(); What could be the problem? Thanks

klang.1
Associate II

if (SE_Startup() == SE_SUCCESS)

 {

......

SE_Startup() --> __IS_SFU_RESERVED();

__get_LR() = 0x80055d7

SB_REGION_ROM_START) = 0x8005d00

 SB_REGION_ROM_END = 0x801 ffff

1 ACCEPTED SOLUTION

Accepted Solutions
eziya76
Associate II

Hello, Today I encountered the same issue as you had

IS_SFU_RESERVED() return failed as link register value is out of secure boot code range.

But I found that it happens when I change the optimization option as none.

so I checked the code and found that current code need to be changed for no optimization option.

Below is original code get_LR is inline function.

It will be replace with the codes inside when optimization is active.

But without optimization option, it works as normal function and it returns link register of the current function. so it will return unexpected SE_ERROR.

#define __IS_SFU_RESERVED() \
  do{ \
    if ((get_LR())< SB_REGION_ROM_START){\
      return SE_ERROR;}\
    if ((get_LR())> SB_REGION_ROM_END){\
      return SE_ERROR;}\
  }while(0)

​so I removed the get_LR function and test with none optimization option.

It worked without errors.

#define __IS_SFU_RESERVED() \
  do{ \
	register uint32_t result;\
	__asm volatile("MOV %0, LR\n" : "=r"(result));\
    if (result < SB_REGION_ROM_START){\
      return SE_ERROR;}\
    if (result > SB_REGION_ROM_END){\
      return SE_ERROR;}\
  }while(0)

View solution in original post

4 REPLIES 4
Bubbles
ST Employee

Hi @klang.1​ ,

you wrote porting, but what is your staring point? There is already a L496 variant of SBSFU 2.6.

What you need to do is to check the linker files and memory ranges. The SBSFU is checking the process security by tightly controlling the addresses, using firewalls, PCROP and other techniques.

The AN5056 should be helpful.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thank you Jhoud,

I made the modification based on the example of L496 Discovery Board, instead of using UART2, I want to use USB Virtual Com port. I did it first by adding USB Device components to the project, but unfortunately USB connection was not reliable. I guess it could be related to Clock setting.

As there is no IOC file in the example project, I can not use GUI to do Clock configuration.

Then I created a new project with USB Device (COM port) , tested USB com works fine, then added all SBSFU components to this project, modified the linker files and memory ranges respectively.

But now it failed at  __IS_SFU_RESERVED()

Best Regards,

Kevin

eziya76
Associate II

Hello, Today I encountered the same issue as you had

IS_SFU_RESERVED() return failed as link register value is out of secure boot code range.

But I found that it happens when I change the optimization option as none.

so I checked the code and found that current code need to be changed for no optimization option.

Below is original code get_LR is inline function.

It will be replace with the codes inside when optimization is active.

But without optimization option, it works as normal function and it returns link register of the current function. so it will return unexpected SE_ERROR.

#define __IS_SFU_RESERVED() \
  do{ \
    if ((get_LR())< SB_REGION_ROM_START){\
      return SE_ERROR;}\
    if ((get_LR())> SB_REGION_ROM_END){\
      return SE_ERROR;}\
  }while(0)

​so I removed the get_LR function and test with none optimization option.

It worked without errors.

#define __IS_SFU_RESERVED() \
  do{ \
	register uint32_t result;\
	__asm volatile("MOV %0, LR\n" : "=r"(result));\
    if (result < SB_REGION_ROM_START){\
      return SE_ERROR;}\
    if (result > SB_REGION_ROM_END){\
      return SE_ERROR;}\
  }while(0)

MSand.5
Associate II

Confirming that __IS_SFU_RESERVED() depends on get_LR() being inline, but using GCC with optimization fully disabled, the inline doesn't work. @eziya76 's code above fixes the issue.