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

debug the app with the secure bootloader.

Hi, I've tried to implement in my project the OTA DFU based on the dfu buttonless example using the secure bootloader.

I used this guide to realize it: https://devzone.nordicsemi.com/b/blog/posts/getting-started-with-nordics-secure-dfu-bootloader

Everything works fine but if I modify the application and try to load and consequently to debug it (with keil) the bootloader does not reconize it somehow as a valid version and to test it i'm forced to upload if via the OTA DFU.

This obviously is a problem for the debugging of the code.

Analysing the bootloader I noticed that in the function nrf_dfu_app_is_valid() there is a function that check the CRC of the code. Being different the code I update with the OTA DFU and the one (even strictly different) i want to debut the bootloader goed in DfuTarg.

Modifying the function if the following way:

bool nrf_dfu_app_is_valid(bool do_crc)
{
    NRF_LOG_DEBUG("Enter nrf_dfu_app_is_valid");
    if (s_dfu_settings.bank_0.bank_code != NRF_DFU_BANK_VALID_APP)
    {
       // Bank 0 has no valid app. Nothing to boot
       NRF_LOG_DEBUG("Return false in valid app check");
       return false;
    }

    // If CRC == 0, the CRC check is skipped.
    if (do_crc && (s_dfu_settings.bank_0.image_crc != 0))
    {
        uint32_t crc = crc32_compute((uint8_t*) nrf_dfu_app_start_address(),
                                     s_dfu_settings.bank_0.image_size,
                                     NULL);

        if (crc != s_dfu_settings.bank_0.image_crc)
        {
            // CRC does not match with what is stored.
            NRF_LOG_DEBUG("Return false in CRC");
            
            //return  false;
            
            // I return true instead of false
            return true;
        }
    }

    NRF_LOG_DEBUG("Return true. App was valid");
    return true;
}

in this way I'm able to debug properly the app but I don't feel is a nice thing to do, I'd like to know if there is a better way to debug the app with the dfu or if i'm oding something wrong.

thanks

Fabiano

  • Hi Fabiano, 

     

    You are correct. The bootloader check the CRC of the application image on every booting up to verify the integrity of the application. If you modify the application and flash it with Keil, the CRC wouldn't be updated and won't match with your new application. For development you can just skip the CRC check as you already done. But consider to put it back when you release. 

Related