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

How to set bootloader run first in my application?

Iprogram the bootloader.hex to 0x78000 with jlink.Then in my application program,I set the NRF_UICR->NRFFW[0] register as belew:

static void write_uicr_customer_register(uint32_t * data, uint32_t offset)
{
    uint32_t* cust_data = (uint32_t*)(NRF_UICR_BASE + offset);

    if(*cust_data != 0xFFFFFFFF)
    {
        NRF_NVMC->CONFIG = 2; //erase enable

        while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

        NRF_NVMC->ERASEUICR = 1; //perform erase of UICR only

        while(NRF_NVMC->READY == NVMC_READY_READY_Busy || NRF_NVMC->ERASEUICR == 1);//busy

        while(*cust_data != 0xFFFFFFFF);
    }

    NRF_NVMC->CONFIG = 1; //write enabled

    while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

    *cust_data = *data;

    while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

    NRF_NVMC->CONFIG = 0; //read only

    while(NRF_NVMC->READY == NVMC_READY_READY_Busy);//busy

    NVIC_SystemReset();
}

int main(void)
{
    uint32_t data = 0x00078000;
    system_module_init();

    // uicr_page_erase();
    LOG_INFO("smartrouter started!\r\n");
    LOG_INFO("main: %X\r\n", main);
    LOG_INFO("ADDR IS %X\r\n", &NRF_UICR->NRFFW[0]);
    LOG_INFO("BEFORE ADDR IS %X\r\n", NRF_UICR->NRFFW[0]);
    LOG_INFO("AFTER ADDR IS %X\r\n", NRF_UICR->NRFFW[0]);

    write_uicr_customer_register(&data, 0x14);

    for (;;)
    {
        // Wait for BLE events.
        // power_manage();
    }
}

I can readback that register is seated,but when restart, it do not goto the boot loader.Please give me a hand,Thank you very much!