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

How does the bootloader load the application in SDK 15?

I'm working with an custom application and a bootloader with code drawn from the examples in SDK 15.2.0. The main method of my bootloader is below:

/**@brief Function for application main entry. */
int main(void)
{
    uint32_t ret_val;

    // Protect MBR and bootloader code from being overwritten.
    ret_val = nrf_bootloader_flash_protect(0, MBR_SIZE, false);
    APP_ERROR_CHECK(ret_val);
    ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false);
    APP_ERROR_CHECK(ret_val);

    (void) NRF_LOG_INIT(nrf_bootloader_dfu_timer_counter_get);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("Inside main");

    ret_val = nrf_bootloader_init(dfu_observer);
    APP_ERROR_CHECK(ret_val);

    // Either there was no DFU functionality enabled in this project or the DFU module detected
    // no ongoing DFU operation and found a valid main application.
    // Boot the main application.
    nrf_bootloader_app_start();

    // Should never be reached.
    NRF_LOG_INFO("After main");
}

I can run and debug the application successfully when it and the softdevice are the only things programmed to the board. The bootloader runs fine, but hits an issue trying to jump to the application (specifically in the jump_to_addr() call inside of app_start(), which is called at the top level by nrf_bootloader_init()). I'm not quite sure what's going on here, but the error did bring up an inconsistency in the code that's confusing me. In the past, calling nrf_bootloader_app_start() from the main method was the way to jump into a valid application if one exists on the board. Now, however, nrf_bootloader_init() seems to be accomplishing this task, but the call to nrf_bootloader_app_start() remains in the sample code.

So my question is this: how does the application get launched from the bootloader, from nrf_bootloader_init() or from nrf_bootloader_app_start()? If nrf_bootloader_init() is responsible for starting the application, should the call to nrf_bootloader_app_start() be removed?

Related