cancel
Showing results for 
Search instead for 
Did you mean: 

F401 Enabling ROP?

mwp
Senior
Posted on May 14, 2018 at 20:27

Hi all,

I'm trying to get ROP enabled by my bootloader.

This function is run first up by main().

I'm finding that it get stuck in a loop, as ROP never seems to become enabled (always reads back as being set at level 0).

Any ideas what im doing wrong here?

Thanks.

void BL_ROPL1()

{

FLASH_OBProgramInitTypeDef OBInit;

//check ROP status

HAL_FLASHEx_OBGetConfig(&OBInit);

if (OBInit.RDPLevel == OB_RDP_LEVEL_0)

{

  //no read out protection is active, enable it

  OBInit.OptionType = OPTIONBYTE_RDP;

  OBInit.RDPLevel = OB_RDP_LEVEL_1;

  HAL_FLASH_Unlock();

  HAL_FLASH_OB_Unlock();

  HAL_FLASHEx_OBProgram(&OBInit);

  HAL_FLASH_OB_Lock();

  HAL_FLASH_OB_Launch();

  NVIC_SystemReset(); //shouldnt get to here

}

}

#rop #security #stm32 #stm32f401 #protection
3 REPLIES 3
Posted on May 14, 2018 at 20:39

You should perhaps unlock the Flash/OB first, and pay attention to status returned.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mwp
Senior
Posted on May 15, 2018 at 19:27

Okay, here is the full thing.

All i ever see is a flickering green LED (flickering due to the boot loop).

Never a red LED indicating an issue.

void

BL_Flash_Protect()

{

#ifndef BL_DONT_PROTECT

    FLASH_OBProgramInitTypeDef OBInit;

    

//get ROP status

    

if

(HAL_FLASH_Unlock() != HAL_OK)

        

goto

ferror;

    

if

(HAL_FLASH_OB_Unlock() != HAL_OK)

        

goto

ferror;

    HAL_FLASHEx_OBGetConfig(&OBInit);

    

if

(OBInit.RDPLevel == OB_RDP_LEVEL_0)

    {

        

//no read out protection is active

        

//disable flash read out to external devices

        LL_GPIO_SetOutputPin(LED3_GRN_PIN);

        OBInit.OptionType = OPTIONBYTE_RDP;

        OBInit.RDPLevel = OB_RDP_LEVEL_1;

        

if

(HAL_FLASHEx_OBProgram(&OBInit) != HAL_OK)

            

goto

ferror;

        HAL_FLASH_OB_Lock();

        HAL_FLASH_Lock();

        HAL_FLASH_OB_Launch();

//restarts

        NVIC_SystemReset();

//shouldnt get to here

    }

    HAL_FLASH_OB_Lock();

    HAL_FLASH_Lock();

    

return

;

    ferror:

while

(1)

    {

        LL_GPIO_SetOutputPin(LED3_RED_PIN);

        __BKPT(0);

    }

#endif

}
mwp
Senior
Posted on May 15, 2018 at 21:06

Solved!

I misunderstood the function of HAL_FLASH_OB_Launch().

The correct working order is:

HAL_FLASHEx_OBGetConfig(&OBInit);

OBInit.OptionType = OPTIONBYTE_RDP;

OBInit.RDPLevel = OB_RDP_LEVEL_1;

HAL_FLASH_OB_Unlock();

HAL_FLASH_Unlock();

HAL_FLASHEx_OBProgram(&OBInit);

HAL_FLASH_OB_Launch();

HAL_FLASH_OB_Lock();

HAL_FLASH_Lock();

NVIC_SystemReset();