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;

}

  • And, is it safe to update the BL like this? I can not use DFU to update BL as the devices are installed in the trucks, and the NRF52832 connects to its host via UART, by which a new BL image can be transferred to the NRF, now the only job is how to copy the new BL to its desired address.

    I have tried executing the sd_mbr_command with a parameter of SD_MBR_COMMAND_COPY_BL, however, the APP is deleted as soon as this command is executed.

  • Update:

    I try to do this by using the nrf_fstorage_nvmcinstead of nrf_fstorage_sd to copy the BL before the SD inited, and it seems fine at most time, and some times the system halts during the copying.

  • 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

  • I'll try to reproduce this issue and upload the map files and the flashdump later.

    Yes,  I preferred to use the DFU solution to fixed some bugs in the bootloader for the products that are installed in the customers' vehicle, however, I found it's impossible to do this finally because we didn't enable these functions in previous bootloader. We have to try other methods. 

Related