assert flash Memory Metadata not aligned after FOTA

Hi There

I run a NRF52840 with the MESH SDK, and use the Flash manager provided.

After some time i would like to update the Device over FOTA this ends in a Assert on booting with the new firmware at the point flash_manager.c Line 256

NRF_MESH_ASSERT(p_manager->config.p_area[i].metadata.pages_in_area == p_manager->config.page_count);

when erase the full mcu this assert is not showing up due no existing data.

In the best case i can keep the data in the Fields, when not how to erase the Flash bevore or at the FOTA?

Regards Simon

  • I am not a DFU/FOTA expert, so thinking out loud here.

    After a FOTA, the device seems to hit an assert at boot because the mesh flash metadata on the chip seems to not match the flash-manager layout compiled into the new firmware. The flash manager reads the stored page count and compares it to the current config. If they differ, it asserts.

    You can try one to keep the layout fixed across releases. Use the same base addresses and page counts for all flash-manager areas. If nothing moves, the stored metadata still matches and your data stays intact. Or If the layout changed, clear the mesh areas on first boot of the new image. Do this before bringing up the mesh stack: Call mesh_stack_config_clear() to wipe mesh configuration and network state, or For your own managers, call flash_manager_remove() and wait for completion. Then reboot and let the stack rebuild its areas.

    If you need to preserve your own data, keep it in a separate flash-manager area that never moves between releases. That way you can clear mesh state when needed without touching your app data.

  • Hi Susheel

    You named it on the point, as long the flash entries not change the update runs without any problems. After some time in the field there are aditional features developed and with that, more data to store. For the features the harware remains in the field and a software update will be performed.

    I will go the way to first boot erase all the data to be shure there is no assert or corrupt data.

    To know that im first booting, i would like to write on the ucir from the application, reading is working but write fails:

    this i tried following example from the devzone:

          NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
          while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
          *(uint32_t *)0x10001090 = 0xFFFFFFFE;
          NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
          while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}

    what am i missing at this point?  The Memory remains FF FF FF FF

    regards Simon

  • It seems like it has happened before like in this thread and here.

    In this thread, even though the same assert happens, it seems like the user had success when they use smaller values of ACCESS_ELEMENT_COUNT and ACCESS_MODEL_COUNT.

  • Hi Susheel

    thanks for the links, they mostly recomend the --eraseall while programming over jlink.

    ACCESS_ELEMENT_COUNT and ACCESS_MODEL_COUNT only have an influence on the first Flash Manager controlled by the mesh_stack and shift the flash layout when changed what not happend in this case.

    I found many beginners struggling when loading different exampels without --eraseall of the mcu the get stuck in the asserts. 

    I would like to build a software version which can be uploaded over FOTA with a partial blank flash sector or check the nvmc for a flash config id which i can compare with my actual if it match i will proceed, otherwise i had to erase all the flash to ensure the data integrity.

    mesh_stack_config_clear() is alredy implemented and working as expected.

    while taking the mesh_stack_config_clear() as sample, there i discovered that the entry will be first overwritten and then cleared, otherwise i will find the metadata of the depreciated flash entry and assume the flash is valid?

    The assert i could reproduce is when the pagecount is increased so that the memory layout will be shiftedfor the following entries.

    Code line 10 assert at flash_manager.c line 256

    static bool flash_area_is_valid(const flash_manager_t * p_manager)
    {
        for (uint32_t i = 0; i < p_manager->config.page_count; i++)
        {
            if (metadata_is_valid(&p_manager->config.p_area[i].metadata))
            {
                /* Check that the existing metadata aligns with ours */
                NRF_MESH_ASSERT(p_manager->config.p_area[i].metadata.page_index == i);
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "check meta data: %x versus %x \n",p_manager->config.p_area[i].metadata.pages_in_area, p_manager->config.page_count);
                NRF_MESH_ASSERT(p_manager->config.p_area[i].metadata.pages_in_area == p_manager->config.page_count); // assert when structure is different
            }
            else
            {
                return false;
            }
        }
    
        return true;
    }

    <t:      10980>, flash_manager_defrag.c,  630, BOOTLOADERADDR(): 0xFFFFFFFF fm_recovery_area: 0x000FF000
    <t:      10993>, flash_manager.c,  826, FM area: 0x000FE000
    <t:      10996>, flash_manager.c,  256, check meta data: 1 versus 1 
    <t:      11000>, flash_manager.c,  826, FM area: 0x000FC000
    <t:      11003>, flash_manager.c,  256, check meta data: 1 versus 2 
    <t:      11006>, app_error_weak.c,  105, Mesh assert at 0x00035C60 (:0)

    Can you short summarise how to erase properly the user flash  entries/pages (without knowing the old layout).

    Regards

    Simon

  • Hi Simon, 

    These questions is something my colleague can help you with next week as he has more experience in Mesh than me. We need to wait for him until then. thanks for your patience in advance.

Related