If you look at the secure bootloader example the nrf_bootloader_init(...) never return to main scope unless an error occurs.
Everything is handled inside this function even jump to application by calling nrf_bootloader_app_start().
I suggest that the call to nrf_bootloader_app_start() is replaced by return NRF_SUCCESS, allowing the developer to implement some user specific code like using the gprepret-registers to signal information back to application
ret_code_t nrf_bootloader_init(nrf_dfu_observer_t observer)
{
...
m_flash_write_done = false;
nrf_dfu_settings_backup(flash_write_callback);
ASSERT(m_flash_write_done);
return NRF_SUCCESS;
//nrf_bootloader_app_start();
//NRF_LOG_ERROR("Unreachable");
}
// Should not be reached.
return NRF_ERROR_INTERNAL;
}
/**@brief Function for application main entry. */
int main(void)
{
...
ret_val = nrf_bootloader_init(dfu_observer);
APP_ERROR_CHECK(ret_val);
//user specifice code like
nrf_power_gpregret_set( ... );
nrf_power_gpregret2_set( ... );
// 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");
}