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;
}