This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Writing to bootloader flash region from the application?

  • The initialized struct "nrf_fstorage_t" for use in nrf_fstorage_init( ) temporarily includes the application and bootloader (just for this test) 
    • start address is 0x2'600
    • end address is 0xF'DFFF.
  • Bootloader test page address (last page of Bootloader partition) 0xF'D000 - 0xF'DFFF
  • Bootloader layer partition 0xF'8000 - 0xF'DFFF
  • Application layer partition 0x2'600 - 0xF'7FFF

The bootloader sets the write protection, but I need to test the write protection (WRP) from the application layer, by writing to the last page in the bootloader with WRP turned off, then writing to it with WRP turned on.

I'm using nrf_fstorage_write( ) API (and nrf_fstorage_read( ) and nrf_fstorage_erase( ) as well), it encounters a hard fault when attempting to erase or write to the last page of the bootloader (Bootloader test page ) from the application layer with WRP turned OFF. What would cause this? 

Is there a better API set for erasing, writing, reading flash memory across partitions like this? Perhaps a better way to test the WRP from the application layer?

Parents Reply Children
  • Hi, 

    WRP - Write protection

    The bootloader applies the write protection using the following and experiences no issues (right now it's commented out):

    nrf_bootloader_flash_protect( START_ADDR, BOOTLOADER_SIZE, false )

    Where START_ADDR = 0x2'6000 and BOOTLOADER_SIZE = (0xF'DFFF - START_ADDR + 1)

    Then in the application layer, any attempt to write to the last page of the bootloader partition (which is not used, all 0xFF's) at the test address ( BOOTLOADER_SIZE - PAGE_SIZE ) nothing is erased or written.

    My hypothesis is based on other ARM MCU's, but may or may not be correct, but it is essentially this:

    1. When nrf_bootloader_flash_protect is commented out, erase/write should pass and write to the test address

    2. When nrf_bootloader_flash_protect is active, it should exhibit a fault.  

    So, the issue is writing to the flash from the app layer to the bootloader region and in test case #1, nrf_fstorage_write( ) and nrf_fstorage_erase( ) erases nothing and writes nothing to the test address.

  • Yes your hypothesis is correct. When flash protect is commented out, the write/erase should pass. 


    It's the reason why I asked to try testing the same when you don't use the bootloader.
    Just to verify that the code you used to write to the desired address is correct and works without the bootloader. Then we know that the bootloader does something to the flash area (which it should not).

Related