I need to update a custom bootloader from the main application running on an nRF52840. The bootloader is contained in 0xF0000 to 0xF90D7 in internal flash, and the S140 SoftDevice is present from 0x1000 to 0x253C7. I attempted to run the code below but my program crashes once it attempts to erase a block.
NRF_FSTORAGE_DEF(nrf_fstorage_t bl_flash) = { .evt_handler = fs_event_handler, .start_addr = 0x0000F0000, .end_addr = 0x000100000, }; static void fs_event_handler(nrf_fstorage_evt_t * evt){ if (evt->result != NRF_SUCCESS) NRF_LOG_ERROR("Flash error"); } int main (void) { ret_code_t err_code = nrf_fstorage_init(&bl_flash, &nrf_fstorage_sd, NULL); err_code = nrf_fstorage_erase(&bl_flash, 0xF0000, 1, NULL); }
I also tried nrf_dfu_flash_erase(). In both cases, the init functions work and return an error code of 0, but the app faults when I try to erase or modify the target memory region. Am I going about this the wrong way, or is it not possible to overwrite bootloader code from the main application?