This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ble_app_uart_c + secure_bootloader doesn't fit in 'UNPLACED_SECTIONS' region?

Hi,

I'm trying to integrate the secure_bootloader DFU code into the ble_app_uart_c example but am stuck on an error regarding not fitting in an 'UNPLACED_SECTIONS' region. Here is the error when I try compiling.

...
Linking ble_app_uart_c_pca10056_s140.elf
    Output/Release/Exe/ble_app_uart_c_pca10056_s140.elf section `.dfu_trans' will not fit in region `UNPLACED_SECTIONS'
    region `UNPLACED_SECTIONS' overflowed by 8200 bytes
...

I'm using nRF5_SDK_17.0.2, and all I've done so far was start with ble_app_uart_c (examples\ble_central\ble_app_uart_c\pca10056\s140\ses), then I added all the folders/files from the secure_bootloader example project (examples\dfu\secure_bootloader\pca10056_s140_ble_debug\ses). I've copy and pasted sections from the sdk_config.h file, though this error showed up before I finished going through the entire config. I haven't touched the main.c file at all.

Is this something particular I need to do in order to add secure bootloader DFU to the BLE app uart c example?

  • Hi,

    When you get this error that indicates that .dfu_trans is not defined in flash_placements.xml, which it must be. I suggest you refer to the example bootloader project, for instance <SDK>\C:\Users\eith\SDK\nRF5_SDK_17.1.0_ddde560\examples\dfu\secure_bootloader\pca10056_s140_ble\ses\flash_placement.xml.

    There you should see this line which is relevant for this error:

        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".dfu_trans" inputsections="*(SORT(.dfu_trans*))" address_symbol="__start_dfu_trans" end_symbol="__stop_dfu_trans" />
    

    Also, may I ask why you are doing this and what you want to achieve? The nRF5 SDK bootloader is normally designed to be stand alone, and not combined with an application. During DFU, the application would typically reset into the bootloader, and then that handles the DFU procedure, and then the application is started again after the operation has completed. And lastly, if for some reason you want to add features to the bootloader (not sure why?), I suspect it would be easier to start off with a bootloader example project and add the NUS code into that.

  • I see, I was not aware of that flash_placements.xml file, thanks for clearing that up. I managed to resolve the compile errors after bringing in a couple of lines from the secure_bootloader example to ble_app_uart_c.

    Maybe I'm misunderstanding the bootloader, but I was under the impression that it was optional and not something which existed in the background for all the example projects. I do not need to modify or add features to the bootloader, I just want to be able to run a modified ble_app_uart_c which has the ability to go into DFU mode and perform an update after a DFU controller connects to it and initiates the process. What do I need to do in order to have the ble_app_uart_c example support DFU?

    I'm going for the typical application of:

    -system on sleep primarily

    -wake up every X hours

    -read some sensors

    -connect to peripheral

    -check for firmware update

    -enter DFU if needed

  • Hi,

    kurtovic said:
    Maybe I'm misunderstanding the bootloader, but I was under the impression that it was optional and not something which existed in the background for all the example projects.

    You are right, the bootloader is optional. If you want to support DFU, you should use it, and if not, don't use it. But remember that its is a different binary altogether, and should not be merged with your application.

    kurtovic said:
    I just want to be able to run a modified ble_app_uart_c which has the ability to go into DFU mode and perform an update after a DFU controller connects to it and initiates the process. What do I need to do in order to have the ble_app_uart_c example support DFU?

    First of all you need a bootloader. Secondly, to enter DFU mode buttonless you need to include a library that adds a DFU service which basically lets a BLE device tell the device to enter DFU mode. This is demonstrated by the Buttonless DFU Template Application.

    I suggest you go though Getting started with Nordic's Secure DFU bootloader, a step by step guide if you have not done so already. You can also find a lot of information in the Bootloader documentation.

  • This is the "secure_bootloader" example application (examples\dfu\secure_bootloader\pca10056_s140_ble_debug\ses)

    #include <stdint.h>
    #include "boards.h"
    #include "nrf_mbr.h"
    #include "nrf_bootloader.h"
    #include "nrf_bootloader_app_start.h"
    #include "nrf_bootloader_dfu_timers.h"
    #include "nrf_dfu.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    #include "app_error.h"
    #include "app_error_weak.h"
    #include "nrf_bootloader_info.h"
    #include "nrf_delay.h"
    
    static void on_error(void)
    {
        NRF_LOG_FINAL_FLUSH();
    
    #if NRF_MODULE_ENABLED(NRF_LOG_BACKEND_RTT)
        // To allow the buffer to be flushed by the host.
        nrf_delay_ms(100);
    #endif
    #ifdef NRF_DFU_DEBUG_VERSION
        NRF_BREAKPOINT_COND;
    #endif
        NVIC_SystemReset();
    }
    
    
    void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
    {
        NRF_LOG_ERROR("%s:%d", p_file_name, line_num);
        on_error();
    }
    
    
    void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
    {
        NRF_LOG_ERROR("Received a fault! id: 0x%08x, pc: 0x%08x, info: 0x%08x", id, pc, info);
        on_error();
    }
    
    
    void app_error_handler_bare(uint32_t error_code)
    {
        NRF_LOG_ERROR("Received an error: 0x%08x!", error_code);
        on_error();
    }
    
    /**
     * @brief Function notifies certain events in DFU process.
     */
    static void dfu_observer(nrf_dfu_evt_type_t evt_type)
    {
        switch (evt_type)
        {
            case NRF_DFU_EVT_DFU_FAILED:
            case NRF_DFU_EVT_DFU_ABORTED:
            case NRF_DFU_EVT_DFU_INITIALIZED:
                bsp_board_init(BSP_INIT_LEDS);
                bsp_board_led_on(BSP_BOARD_LED_0);
                bsp_board_led_on(BSP_BOARD_LED_1);
                bsp_board_led_off(BSP_BOARD_LED_2);
                break;
            case NRF_DFU_EVT_TRANSPORT_ACTIVATED:
                bsp_board_led_off(BSP_BOARD_LED_1);
                bsp_board_led_on(BSP_BOARD_LED_2);
                break;
            case NRF_DFU_EVT_DFU_STARTED:
                break;
            default:
                break;
        }
    }
    
    
    /**@brief Function for application main entry. */
    int main(void)
    {
        uint32_t ret_val;
    
        // Must happen before flash protection is applied, since it edits a protected page.
        nrf_bootloader_mbr_addrs_populate();
    
        // Protect MBR and bootloader code from being overwritten.
        ret_val = nrf_bootloader_flash_protect(0, MBR_SIZE);
        APP_ERROR_CHECK(ret_val);
        ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE);
        APP_ERROR_CHECK(ret_val);
    
        (void) NRF_LOG_INIT(nrf_bootloader_dfu_timer_counter_get);
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("Inside main");
    
        ret_val = nrf_bootloader_init(dfu_observer);
        APP_ERROR_CHECK(ret_val);
    
        NRF_LOG_FLUSH();
    
        NRF_LOG_ERROR("After main, should never be reached.");
        NRF_LOG_FLUSH();
    
        APP_ERROR_CHECK_BOOL(false);
    }

    If I'm not supposed to add any bootloader/DFU related code to my application, how can the development kit possibly support the feature?

    What is the purpose of the secure_bootloader example, if not to demonstrate how to integrate DFU into the other examples?

  • kurtovic said:
    If I'm not supposed to add any bootloader/DFU related code to my application, how can the development kit possibly support the feature?

    Because you should program both the bootloader and your application, which reside at different locations in flash. Please check the tutorial I linked to in my previous post.

    kurtovic said:
    What is the purpose of the secure_bootloader example, if not to demonstrate how to integrate DFU into the other examples?

    That can be considered a more or less complete bootloader. You generally just have to use a different public key, and potentially make some adjustments in the bootloader's sdk_config.h to fit your specific use case.

Related