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

Bootloader - Where are packets saved for DFU?

Hi,

I would like to know, where the packets are written into the flash for the mesh DFU example.

In nrf_mesh_dfu.c is a function nrf_mesh_dfu_cmd_send:

uint32_t nrf_mesh_dfu_cmd_send(bl_cmd_t* p_cmd)
{
    if (m_cmd_handler == NULL)
    {
        __LOG(LOG_SRC_DFU, LOG_LEVEL_ERROR, "ERROR: No CMD handler!\n");
        return NRF_ERROR_NOT_SUPPORTED;
    }
    if (p_cmd == NULL)
    {
        return NRF_ERROR_NULL;
    }
    /* Suspend flash operations for the duration of the command to avoid
       premature flash-events disturbing the flow */
    mesh_flash_set_suspended(true);
    uint32_t error_code = m_cmd_handler(p_cmd); /* Bootloader */
    mesh_flash_set_suspended(false);
    //__LOG(LOG_SRC_DFU, LOG_LEVEL_INFO, "[NRF_MESH_DFU] nrf_mesh_dfu_cmd_send\n");
    return error_code;
}

It calls a handler, which was allocated at the end of the RAM:

    error_code = dfu_cmd_handler_set(*((bl_if_cmd_handler_t*) (DEVICE_DATA_RAM_END_GET() - sizeof(bl_if_cmd_handler_t)))); /* Puts the command handler at the end of the RAM */
    if (error_code != NRF_SUCCESS)
    {
        m_transfer_state.state = NRF_MESH_DFU_STATE_INITIALIZED;
        return NRF_ERROR_NOT_SUPPORTED;
    }

An this command handler (Bootloader?) gets now commands for BLE transmits or RX packets etc, but I don't see where the commands are actually handled?

Further I don't see where the received packets are stored. There is somehow a listener registered:

AD_LISTENER(m_dfu_ad_listener) = {
    .ad_type = AD_TYPE_DFU,
    .adv_packet_type = ADL_WILDCARD_ADV_TYPE,
    .handler = ad_data_in,
};

And this listener somehow accesses the flash.

What I finally try to do is to store the DFU normally in the flash without flashing it or distributing it in the mesh. After I received the whole update, I want to start distributing

it in the mesh and update it at the end for myself, but I don't know where to access the individual packets out of the flash, since I don't see the storing mechanism behind.

  • HI Sebastian, 

    I apologize for the late reply. DevZone was short staffed during the holidays and we're working through the backlog. 

    Which Mesh SDK version are you using? 

    What I finally try to do is to store the DFU normally in the flash without flashing it or distributing it in the mesh. After I received the whole update, I want to start distributing

    it in the mesh and update it at the end for myself, but I don't know where to access the individual packets out of the flash, since I don't see the storing mechanism behind.

     Just trying to understand what you want to achieve. Am I understanding this correctly that you want to upload the firmware image for the mesh nodes to one node and then trigger the update of the mesh at a later point in time? 

    The command handler you are referring to is located in the bootloader so that is why you do not see the handler it self. The bootloader places a function pointer to the handler function at a specific location in RAM and then switches execution to the application. The application then uses this function pointer to communicate with the bootloader. 

    You can get the metadata of the firmware stored in flash by using the nrf_mesh_dfu_bank_info_get() function which returns a bank_info object.

    Best regards

    Bjørn

Related