This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can firmware be overwritten by fds?

Hi guys

I'm just want to know, is this situation can occur if my application size will grow so high that it could be overwritten by the flash data storage module?

The start and end addresses are calculated in fds.c:

static void flash_bounds_set(void)
{
uint32_t flash_size = (FDS_PHY_PAGES * FDS_PHY_PAGE_SIZE * sizeof(uint32_t));
m_fs.end_addr = flash_end_addr();
m_fs.start_addr = m_fs.end_addr - flash_size;
}


static ret_code_t flash_subsystem_init(void)
{
flash_bounds_set();

#if (FDS_BACKEND == NRF_FSTORAGE_SD)
return nrf_fstorage_init(&m_fs, &nrf_fstorage_sd, NULL);
#elif (FDS_BACKEND == NRF_FSTORAGE_NVMC)
return nrf_fstorage_init(&m_fs, &nrf_fstorage_nvmc, NULL);
#else
#error Invalid FDS_BACKEND.
#endif
}

SDK 17.1.0. Softdevice s132 nrf52832

Parents
  • Hi,

    FDS automatically ensures that the FDS pages occupy the flash immediately below the bootloader (if used). That is essentially what happens in flash_bounds_set() and flash_end_addr(). FDS does not check where your application ends. It is your responsibility to have control over the memory layout and ensure that the various regions does not overlap. I suggest you refer to the Memory layout figure in the bootloader documentation if to help visualize how this looks.

    If you want an error when building a too large application, you should adjust the flash size in your linker configuration to only include the size you have reserved for the application. Then you would get a build error if the application grows into the FDS pages.

Reply
  • Hi,

    FDS automatically ensures that the FDS pages occupy the flash immediately below the bootloader (if used). That is essentially what happens in flash_bounds_set() and flash_end_addr(). FDS does not check where your application ends. It is your responsibility to have control over the memory layout and ensure that the various regions does not overlap. I suggest you refer to the Memory layout figure in the bootloader documentation if to help visualize how this looks.

    If you want an error when building a too large application, you should adjust the flash size in your linker configuration to only include the size you have reserved for the application. Then you would get a build error if the application grows into the FDS pages.

Children
  • Thank you for explanation.

    I added the following LOG message to know exact addresses where FDS memory allocated:

    #include "nrf_log.h"
    static void flash_bounds_set(void)
    {
        uint32_t flash_size  = (FDS_PHY_PAGES * FDS_PHY_PAGE_SIZE * sizeof(uint32_t));
        m_fs.end_addr   = flash_end_addr();
        m_fs.start_addr = m_fs.end_addr - flash_size;
        NRF_LOG_INFO("FDS  start: %x  end: %x",m_fs.start_addr,m_fs.end_addr);
    }

    By default in Keil examples these addresses overlaps with IROM1 memory area in Keil's project options.

    Besides, FDS addresses are differerent when I run my application with secure_bootloader_ble (I use mergehex, nrfutil and nrfjprog for manually program firmware with bootloader, softdevice, application, bootloader settings).

  • Hi,

    Yes, when you use a bootloader, FDS will use the pages immediately below the bootloader. If you don't use a bootloader, the FDS pages are located at the end of the flash. Note that when you use FDS and a bootloader you also need to ensure that you configure NRF_DFU_APP_DATA_AREA_SIZE in the bootloader's sdk_config.h correctly, so that the FDS pages are not overwritten during a DFU procedure.

Related