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

FAILS to erase the bootloader in app

HI,

I want to upgrade the BL in APP directly. I encouter a wierd problem. When APP erase a specific page of the BL(the address is 0x74000), the system halts. If ignoring this page, the progress can be done without any problem. The flash space for BL is from 0x6E000 to 0x7DFFF. 

And if the APP runs without BL, the operation can be also done.

I have tried to delete the nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false) in the bootloader, but it seems no help.

I have tried it in two boards, this issue is found.

And the code is now like this

#define BL_CODE_START 0x6E000

#define BL_CODE_END 0x7E000

bool cpy_bootloader()
{
uint32_t write_addr = BL_CODE_START;
uint32_t retry = 0;

uint8_t test = 0xA1;

while(write_addr < BL_CODE_END)
{
uint8_t write_buffer[12];
memset(write_buffer, test++, sizeof(write_buffer));

NRF_LOG_DEBUG("erase bl %x, retry = %d", write_addr, retry);


//if(write_addr != 0x74000)
{
nrf_fstorage_erase(&fstorage, write_addr, 1, NULL);
while(nrf_fstorage_is_busy(&fstorage)) {nrf_delay_us(100);wdt_feed();}

NRF_LOG_DEBUG("cpy bl %x -> %x", read_addr, write_addr);
nrf_fstorage_write(&fstorage, write_addr, (void*)write_buffer, sizeof(write_buffer), NULL);
while(nrf_fstorage_is_busy(&fstorage)) {nrf_delay_us(100);wdt_feed();}
}


//if(!memcmp((void*)write_addr, (void*)write_buffer, sizeof(write_buffer)))
{
write_addr += FLASH_PAGE_SIZE;
read_addr += FLASH_PAGE_SIZE;
retry = 0;
}
}

return retry == 0;

}

Parents
  • Hi,

    Do you get any errors when calling the erase function, or do you get some assert/Hardfault?

    Can you upload a map-file of the application and bootloader? A flashdump of the device would also be helpful.

    It does not sound like a safe way to update the bootloader. If the device is reset during the erase cycle, you will not be able to boot back to the application if you have erased the current bootloader. We do have background DFU solutions where the application/bootloader is received by the application (Thread/BLE Mesh/IoT IPv6 LowPAN), you should be able to use this for your purpose as well, only with UART transport, to avoid making a new completely custom solution.

    Best regards,
    Jørgen

Reply
  • Hi,

    Do you get any errors when calling the erase function, or do you get some assert/Hardfault?

    Can you upload a map-file of the application and bootloader? A flashdump of the device would also be helpful.

    It does not sound like a safe way to update the bootloader. If the device is reset during the erase cycle, you will not be able to boot back to the application if you have erased the current bootloader. We do have background DFU solutions where the application/bootloader is received by the application (Thread/BLE Mesh/IoT IPv6 LowPAN), you should be able to use this for your purpose as well, only with UART transport, to avoid making a new completely custom solution.

    Best regards,
    Jørgen

Children
Related