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

debug bootloader for thread examples

Hi,

I wonder if there exists a debug bootloader for thread examples. There is a bootloader in the secure DFU example, but it is not for debugging. "examples/thread/dfu/bootloader" . I appreciate if you can point me to the right direction.

Best regards,

Ozan

  • I am not sure what that needs to be changed in the flash placement file. I don't think you need to change anything in this file, to be honest. What you should do is to change your nrf_bootloader_init() to something like this:

    ret_code_t nrf_bootloader_init(nrf_dfu_observer_t observer)
    {
        NRF_LOG_DEBUG("In nrf_bootloader_init");
    
        ret_code_t                            ret_val;
        nrf_bootloader_fw_activation_result_t activation_result;
        uint32_t                              initial_timeout;
        bool                                  dfu_enter = false;
    
        m_user_observer = observer;
    
        if (NRF_BL_DFU_ENTER_METHOD_BUTTON)
        {
            dfu_enter_button_init();
        }
    
        ret_val = nrf_dfu_settings_init(false);
        if (ret_val != NRF_SUCCESS)
        {
            return NRF_ERROR_INTERNAL;
        }
    
        // Check if an update needs to be activated and activate it.
        activation_result = nrf_bootloader_fw_activate();
    
        switch (activation_result)
        {
            case ACTIVATION_NONE:
                initial_timeout = NRF_BOOTLOADER_MS_TO_TICKS(NRF_BL_DFU_INACTIVITY_TIMEOUT_MS);
                dfu_enter       = dfu_enter_check();
                break;
    
            case ACTIVATION_SUCCESS_EXPECT_ADDITIONAL_UPDATE:
                initial_timeout = NRF_BOOTLOADER_MS_TO_TICKS(NRF_BL_DFU_CONTINUATION_TIMEOUT_MS);
                dfu_enter       = true;
                break;
    
            case ACTIVATION_SUCCESS:
                bootloader_reset();
                NRF_LOG_ERROR("Should never come here: After bootloader_reset()");
                return NRF_ERROR_INTERNAL; // Should not reach this.
    
            case ACTIVATION_ERROR:
            default:
                return NRF_ERROR_INTERNAL;
        }
    
        //if (dfu_enter)
        if (false)               //This will always start application, regardless of the state of dfu_enter.
        {
            nrf_bootloader_wdt_init();
    
            scheduler_init();
    
            // Clear all DFU stop flags.
            dfu_enter_flags_clear();
    
            // Call user-defined init function if implemented
            ret_val = nrf_dfu_init_user();
            if (ret_val != NRF_SUCCESS)
            {
                return NRF_ERROR_INTERNAL;
            }
    
            nrf_bootloader_dfu_inactivity_timer_restart(initial_timeout, inactivity_timeout);
    
            ret_val = nrf_dfu_init(dfu_observer);
            if (ret_val != NRF_SUCCESS)
            {
                return NRF_ERROR_INTERNAL;
            }
    
            NRF_LOG_DEBUG("Enter main loop");
            loop_forever(); // This function will never return.
            NRF_LOG_ERROR("Should never come here: After looping forever.");
        }
        else
        {
            // Erase additional data like peer data or advertisement name
            ret_val = nrf_dfu_settings_additional_erase();
            if (ret_val != NRF_SUCCESS)
            {
                return NRF_ERROR_INTERNAL;
            }
    
            m_flash_write_done = false;
            nrf_dfu_settings_backup(flash_write_callback);
            ASSERT(m_flash_write_done);
    
            nrf_bootloader_app_start();
            NRF_LOG_ERROR("Should never come here: After nrf_bootloader_app_start()");
        }
    
        // Should not be reached.
        return NRF_ERROR_INTERNAL;
    }

    You can see that I changed the "if (dfu_enter)" to "if (false)".

    Note that with this very simple approach, it will never enter bootloader mode, but always start the application.

    If you want to filter on your own premises, e.g. work as a normal bootloader, but not check the CRC, you need to study the bootloader project found in examples\thread\dfu\bootloader.

    Inside the nrf_bootloader_init() there is a state machine:

    nrf_bootloader_fw_activate checks whether it has received any new application that it needs to move around. If not, it will return ACTIVATION_NONE. In this case, it will check dfu_enter_check(). If you want to disable the CRC here, just comment out the first check inside. nrf_dfu_app_is_valid(). If you skip this check, you should be able to debug your application, because the bootloader skips the CRC check. However, the rest of the bootloader and DFU procedure requires the keys as normal.

    Best regards,

    Edvin

  • Thank you, Edvin! I will try your suggestions.

    Best wishes,

    Vedat

Related