Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to change the mbr jump address location

Hi,

I am using nrf5280 development kit and 17.1.0 sdk.

i am working on  ble_app_uart example code.

Its working fine no issue. Since the start address of the application is 0x27000 and i want to change it on to some other location as per my requirement which id 0xE8000.

But when i changed the starting address then its not working. Looks like control not reaches to that location.

or 

mbr not able to jump that location which i changed. 

can someone help me here. what exactly i am missing here.?

Regards

R_S

  • Hi,

    I trace it and found the point where i am getting hard fault.

    ret_code = sd_softdevice_enable(&clock_lf_cfg, app_error_fault_handler);

    The result is same even after using nrf_dfu_mbr_vector_table_set() and not nrf_dfu_mbr_irq_forward_address_set() in the bootloader code.

    And the value of registers are mentioned below:

    And yes the only chage in my application is in .icf file that is flash start address change.

    Previously it was 

    And Currently i changed it to this 

    in previous case the application address was 27000 so in that case i directly flashed it without bootloader code.

    And in the current scenario as address is 0xED000, so i flashed it with Bootloader code. But not sure what goes wrong in this case? Because i had used open bootloader and secure bootloader together where code control first goes to open bootloader and then from there it jump to the secure bootloader and then it was no issue. But dont know what wrong with this ble_app_uart code.

     

    Regards

    R_S

  • I see... Can you share your bootloader code, where you branch to the application, including configuring the MBR etc? Please include enough context, so include values of constants that may be set elsewhere etc.

  • HI,

    pca10056_usb.zip

    I have attached the bootloader code here.

    In main.c line no 218. i am calling "nrf_bootloader_app_start();" API to jump to the application part.

    And inside nrf_bootloader_app_start() function i am given the start address as the application start address(0xED000).

    And also calling the function nrf_dfu_mbr_init_sd() & nrf_dfu_mbr_vector_table_set() as you mentioned.

    /**
     * Copyright (c) 2016 - 2019, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    #include <stdint.h>
    #include "nrf.h"
    #include "nrf_bootloader_app_start.h"
    #include "nrf_bootloader_info.h"
    #include "nrf_log.h"
    #include "nrf_dfu_mbr.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_bootloader_info.h"
    
    // Do the final stages of app_start. Protect flash and run app. See nrf_bootloader_app_start_final.c
    void nrf_bootloader_app_start_final(uint32_t start_addr);
    
    uint32_t nrf_dfu_mbr_vector_table_set(uint32_t address)
    {
        uint32_t ret_val;
    
        NRF_LOG_DEBUG("running vector table set");
        sd_mbr_command_t command =
        {
            .command = SD_MBR_COMMAND_VECTOR_TABLE_BASE_SET,
            .params.base_set.address = address,
        };
    
        ret_val = sd_mbr_command(&command);
        NRF_LOG_DEBUG("After running vector table set");
    
        return ret_val;
    }
    
    void nrf_bootloader_app_start(void)
    {
        uint32_t start_addr = 0xED000; // Always boot from end of MBR. If a SoftDevice is present, it will boot the app.
        NRF_LOG_DEBUG("Running nrf_bootloader_app_start with address: 0x%08x", start_addr);
        uint32_t err_code;
    
        err_code = nrf_dfu_mbr_init_sd();
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("Failed running nrf_dfu_mbr_init_sd");
            return;
        }
        // Disable and clear interrupts
        // Notice that this disables only 'external' interrupts (positive IRQn).
        NRF_LOG_DEBUG("Disabling interrupts. NVIC->ICER[0]: 0x%x", NVIC->ICER[0]);
    
        NVIC->ICER[0]=0xFFFFFFFF;
        NVIC->ICPR[0]=0xFFFFFFFF;
    #if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2
        NVIC->ICER[1]=0xFFFFFFFF;
        NVIC->ICPR[1]=0xFFFFFFFF;
    #endif
    
      err_code = nrf_dfu_mbr_vector_table_set( start_addr );
      if ( err_code != NRF_SUCCESS )
      {
        NRF_LOG_ERROR( "Failed running nrf_dfu_mbr_irq_forward_address_set()" );
      }
        err_code = nrf_dfu_mbr_irq_forward_address_set( start_addr );
        if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("Failed running nrf_dfu_mbr_irq_forward_address_set()");
        }
    
        NRF_LOG_FLUSH();
        nrf_bootloader_app_start_final(start_addr);
    }
    

    i also attached nrf_bootloader_app_start.c file in which i have added these chnages.

    apart from that i dont have any change in the bootloader code. An the code i am using is open bootloader code.

    Regards

    R_S

  • Hi,

    I did not get a chance to look at this today, but I will test your code on my end tomorrow and get back to you.

  • Hi Einar,

    The issue got resolved.

    I found that under DFU we are also calling ble_stack_init() function. But there is additional data added in that function.

    So same thing i am calling in ble code under ble_stack_init() function. And after that its working fine.

    actually we need to use these two function calls on both the places once in bootloader before jumping to application and second is inside the application. 

    Regards

    R_S

Related