mirror of https://github.com/ARMmbed/mbed-os.git
make nRF52840 target compilable for ARM compiler - enable fstorage in sdk config - remove files of modules: bootloader, DFU bootloader and UICR setings
parent
2b9de59387
commit
b7dc228f5f
|
@ -2905,6 +2905,43 @@
|
|||
#define CRC32_ENABLED 1
|
||||
#endif
|
||||
|
||||
// <e> FSTORAGE_ENABLED - fstorage - Flash storage module
|
||||
//==========================================================
|
||||
#ifndef FSTORAGE_ENABLED
|
||||
#define FSTORAGE_ENABLED 1
|
||||
#endif
|
||||
#if FSTORAGE_ENABLED
|
||||
// <o> FS_QUEUE_SIZE - Configures the size of the internal queue.
|
||||
// <i> Increase this if there are many users, or if it is likely that many
|
||||
// <i> operation will be queued at once without waiting for the previous operations
|
||||
// <i> to complete. In general, increase the queue size if you frequently receive
|
||||
// <i> @ref FS_ERR_QUEUE_FULL errors when calling @ref fs_store or @ref fs_erase.
|
||||
|
||||
#ifndef FS_QUEUE_SIZE
|
||||
#define FS_QUEUE_SIZE 4
|
||||
#endif
|
||||
|
||||
// <o> FS_OP_MAX_RETRIES - Number attempts to execute an operation if the SoftDevice fails.
|
||||
// <i> Increase this value if events return the @ref FS_ERR_OPERATION_TIMEOUT
|
||||
// <i> error often. The SoftDevice may fail to schedule flash access due to high BLE activity.
|
||||
|
||||
#ifndef FS_OP_MAX_RETRIES
|
||||
#define FS_OP_MAX_RETRIES 3
|
||||
#endif
|
||||
|
||||
// <o> FS_MAX_WRITE_SIZE_WORDS - Maximum number of words to be written to flash in a single operation.
|
||||
// <i> Tweaking this value can increase the chances of the SoftDevice being
|
||||
// <i> able to fit flash operations in between radio activity. This value is bound by the
|
||||
// <i> maximum number of words which the SoftDevice can write to flash in a single call to
|
||||
// <i> @ref sd_flash_write, which is 256 words for nRF51 ICs and 1024 words for nRF52 ICs.
|
||||
|
||||
#ifndef FS_MAX_WRITE_SIZE_WORDS
|
||||
#define FS_MAX_WRITE_SIZE_WORDS 1024
|
||||
#endif
|
||||
|
||||
#endif //FSTORAGE_ENABLED
|
||||
// </e>
|
||||
|
||||
// <q> ECC_ENABLED - ecc - Elliptic Curve Cryptography Library
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_ble_dfu DFU BLE Service
|
||||
* @{
|
||||
* @ingroup sdk_nrf_bootloader
|
||||
* @brief Device Firmware Update (DFU) transport layer for <em>Bluetooth</em> low energy.
|
||||
*
|
||||
* @details The Device Firmware Update (DFU) Service is a GATT-based service that can be used for
|
||||
* performing firmware updates over BLE. Note that this implementation uses
|
||||
* vendor-specific UUIDs for the service and characteristics and is intended to demonstrate
|
||||
* firmware updates over BLE. See @ref lib_dfu_transport_ble "DFU Transport: BLE" for more information on the service and the profile.
|
||||
*/
|
||||
|
||||
#ifndef NRF_BLE_DFU_H__
|
||||
#define NRF_BLE_DFU_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ble_gatts.h"
|
||||
#include "ble.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// This is a 16-bit UUID.
|
||||
#define BLE_DFU_SERVICE_UUID 0xFE59 //!< The UUID of the DFU Service.
|
||||
|
||||
// These UUIDs are used with the Nordic base address to create a 128-bit UUID (0x8EC9XXXXF3154F609FB8838830DAEA50).
|
||||
#define BLE_DFU_CTRL_PT_UUID 0x0001 //!< The UUID of the DFU Control Point.
|
||||
#define BLE_DFU_PKT_CHAR_UUID 0x0002 //!< The UUID of the DFU Packet Characteristic.
|
||||
|
||||
|
||||
/**@brief BLE DFU opcodes.
|
||||
*
|
||||
* @details These types of opcodes are used in control point access.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
BLE_DFU_OP_CODE_CREATE_OBJECT = 0x01, /**< Value of the opcode field for a 'Create object' request. */
|
||||
BLE_DFU_OP_CODE_SET_RECEIPT_NOTIF = 0x02, /**< Value of the opcode field for a 'Set Packet Receipt Notification' request. */
|
||||
BLE_DFU_OP_CODE_CALCULATE_CRC = 0x03, /**< Value of the opcode field for a 'Calculating checksum' request. */
|
||||
BLE_DFU_OP_CODE_EXECUTE_OBJECT = 0x04, /**< Value of the opcode field for an 'Initialize DFU parameters' request. */
|
||||
BLE_DFU_OP_CODE_SELECT_OBJECT = 0x06, /**< Value of the opcode field for a 'Select object' request. */
|
||||
BLE_DFU_OP_CODE_RESPONSE = 0x60 /**< Value of the opcode field for a response.*/
|
||||
} ble_dfu_op_code_t;
|
||||
|
||||
|
||||
/**@brief DFU Service.
|
||||
*
|
||||
* @details This structure contains status information related to the service.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t service_handle; /**< Handle of the DFU Service (as provided by the SoftDevice). */
|
||||
uint8_t uuid_type; /**< UUID type assigned to the DFU Service by the SoftDevice. */
|
||||
ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet Characteristic. */
|
||||
ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point Characteristic. */
|
||||
} ble_dfu_t;
|
||||
|
||||
|
||||
/**@brief Function for initializing the DFU Service.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the DFU Service and its characteristics were successfully added to the
|
||||
* SoftDevice. Otherwise, an error code is returned.
|
||||
*/
|
||||
uint32_t ble_dfu_transport_init(void);
|
||||
|
||||
|
||||
/**@brief Function for closing down the DFU Service and disconnecting from the host.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the DFU Service was correctly closed down.
|
||||
*/
|
||||
uint32_t ble_dfu_transport_close(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_BLE_DFU_H__
|
||||
|
||||
/** @} */
|
|
@ -1,177 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "nrf_dfu.h"
|
||||
#include "nrf_dfu_transport.h"
|
||||
#include "nrf_dfu_utils.h"
|
||||
#include "nrf_bootloader_app_start.h"
|
||||
#include "nrf_dfu_settings.h"
|
||||
#include "nrf_gpio.h"
|
||||
#include "app_scheduler.h"
|
||||
#include "app_timer_appsh.h"
|
||||
#include "nrf_log.h"
|
||||
#include "boards.h"
|
||||
#include "nrf_bootloader_info.h"
|
||||
#include "nrf_dfu_req_handler.h"
|
||||
|
||||
#define SCHED_MAX_EVENT_DATA_SIZE MAX(APP_TIMER_SCHED_EVT_SIZE, 0) /**< Maximum size of scheduler events. */
|
||||
|
||||
#define SCHED_QUEUE_SIZE 20 /**< Maximum number of events in the scheduler queue. */
|
||||
|
||||
#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
|
||||
#define APP_TIMER_OP_QUEUE_SIZE 4 /**< Size of timer operation queues. */
|
||||
|
||||
// Weak function implementation
|
||||
|
||||
/** @brief Weak implemenation of nrf_dfu_check_enter.
|
||||
*
|
||||
* @note This function must be overridden to enable entering DFU mode at will.
|
||||
* Default behaviour is to enter DFU when BOOTLOADER_BUTTON is pressed.
|
||||
*/
|
||||
__WEAK bool nrf_dfu_enter_check(void)
|
||||
{
|
||||
if (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (s_dfu_settings.enter_buttonless_dfu == 1)
|
||||
{
|
||||
s_dfu_settings.enter_buttonless_dfu = 0;
|
||||
APP_ERROR_CHECK(nrf_dfu_settings_write(NULL));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Internal Functions
|
||||
|
||||
/**@brief Function for initializing the timer handler module (app_timer).
|
||||
*/
|
||||
static void timers_init(void)
|
||||
{
|
||||
// Initialize timer module, making it use the scheduler.
|
||||
APP_TIMER_APPSH_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, true);
|
||||
}
|
||||
|
||||
|
||||
/** @brief Function for event scheduler initialization.
|
||||
*/
|
||||
static void scheduler_init(void)
|
||||
{
|
||||
APP_SCHED_INIT(SCHED_MAX_EVENT_DATA_SIZE, SCHED_QUEUE_SIZE);
|
||||
}
|
||||
|
||||
|
||||
static void wait_for_event()
|
||||
{
|
||||
// Transport is waiting for event?
|
||||
while(true)
|
||||
{
|
||||
// Can't be emptied like this because of lack of static variables
|
||||
(void)sd_app_evt_wait();
|
||||
app_sched_execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void nrf_dfu_wait()
|
||||
{
|
||||
app_sched_execute();
|
||||
(void)sd_app_evt_wait();
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_init()
|
||||
{
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
uint32_t enter_bootloader_mode = 0;
|
||||
|
||||
NRF_LOG_INFO("In real nrf_dfu_init\r\n");
|
||||
|
||||
nrf_dfu_settings_init();
|
||||
|
||||
// Continue ongoing DFU operations
|
||||
// Note that this part does not rely on SoftDevice interaction
|
||||
ret_val = nrf_dfu_continue(&enter_bootloader_mode);
|
||||
if(ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_INFO("Could not continue DFU operation: 0x%08x\r\n", ret_val);
|
||||
enter_bootloader_mode = 1;
|
||||
}
|
||||
|
||||
// Check if there is a reason to enter DFU mode
|
||||
// besides the effect of the continuation
|
||||
if (nrf_dfu_enter_check())
|
||||
{
|
||||
NRF_LOG_INFO("Application sent bootloader request\n");
|
||||
enter_bootloader_mode = 1;
|
||||
}
|
||||
|
||||
if(enter_bootloader_mode != 0 || !nrf_dfu_app_is_valid())
|
||||
{
|
||||
timers_init();
|
||||
scheduler_init();
|
||||
|
||||
// Initializing transports
|
||||
ret_val = nrf_dfu_transports_init();
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Could not initalize DFU transport: 0x%08x\r\n", ret_val);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
(void)nrf_dfu_req_handler_init();
|
||||
|
||||
// This function will never return
|
||||
NRF_LOG_INFO("Waiting for events\r\n");
|
||||
wait_for_event();
|
||||
NRF_LOG_INFO("After waiting for events\r\n");
|
||||
}
|
||||
|
||||
if (nrf_dfu_app_is_valid())
|
||||
{
|
||||
NRF_LOG_INFO("Jumping to: 0x%08x\r\n", MAIN_APPLICATION_START_ADDR);
|
||||
nrf_bootloader_app_start(MAIN_APPLICATION_START_ADDR);
|
||||
}
|
||||
|
||||
// Should not be reached!
|
||||
NRF_LOG_INFO("After real nrf_dfu_init\r\n");
|
||||
return NRF_SUCCESS;
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_nrf_dfu DFU bootloader
|
||||
* @{
|
||||
* @ingroup sdk_nrf_bootloader
|
||||
* @brief Bootloader with Device Firmware Update (DFU) functionality.
|
||||
*
|
||||
* The DFU bootloader module, in combination with the @ref sdk_bootloader module,
|
||||
* can be used to implement a bootloader that supports Device Firmware Updates.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NRF_DFU_H__
|
||||
#define NRF_DFU_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define BOOTLOADER_BUTTON (BSP_BUTTON_3) /**< Button for entering DFU mode. */
|
||||
|
||||
/** @brief Function for initializing a DFU operation.
|
||||
*
|
||||
* This function initializes a DFU operation and any transports that are registered
|
||||
* in the system.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the DFU operation was successfully initialized.
|
||||
*/
|
||||
uint32_t nrf_dfu_init(void);
|
||||
|
||||
|
||||
/** @brief Function for checking if DFU mode should be entered.
|
||||
*
|
||||
* This function checks whether DFU mode is required.
|
||||
*
|
||||
* @retval true If DFU mode must be entered.
|
||||
* @retval false If there is no need to enter DFU mode.
|
||||
*/
|
||||
bool nrf_dfu_enter_check(void);
|
||||
|
||||
|
||||
/** @brief Function for checking if DFU should be reset (failsafe).
|
||||
*
|
||||
* This function will check if DFU should be reset (failsafe).
|
||||
*
|
||||
* If this returns true, DFU mode will be entered and DFU will be reset.
|
||||
*
|
||||
* @retval true If DFU must be reset (failsafe).
|
||||
* @retval false If there is no need to reset DFU.
|
||||
*/
|
||||
bool nrf_dfu_check_failsafe_reset(void);
|
||||
|
||||
|
||||
/** @brief Function for blocking until an event (i.e. incoming BLE packet) arrives.
|
||||
*/
|
||||
void nrf_dfu_wait(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DFU_H__
|
||||
|
||||
/** @} */
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "nrf_dfu_mbr.h"
|
||||
#include "nrf_mbr.h"
|
||||
#include "nrf_dfu_types.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
uint32_t nrf_dfu_mbr_copy_bl(uint32_t * p_src, uint32_t len)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
uint32_t const len_words = len / sizeof(uint32_t);
|
||||
|
||||
sd_mbr_command_t command =
|
||||
{
|
||||
.command = SD_MBR_COMMAND_COPY_BL,
|
||||
.params.copy_bl.bl_src = p_src,
|
||||
.params.copy_bl.bl_len = len_words
|
||||
};
|
||||
|
||||
ret_val = sd_mbr_command(&command);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_mbr_copy_sd(uint32_t * p_dst, uint32_t * p_src, uint32_t len)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
uint32_t const len_words = len / sizeof(uint32_t);
|
||||
|
||||
if((len_words & (CODE_PAGE_SIZE / sizeof(uint32_t) - 1)) != 0)
|
||||
return NRF_ERROR_INVALID_LENGTH;
|
||||
|
||||
sd_mbr_command_t command =
|
||||
{
|
||||
.command = SD_MBR_COMMAND_COPY_SD,
|
||||
.params.copy_sd.src = p_src,
|
||||
.params.copy_sd.dst = p_dst,
|
||||
.params.copy_sd.len = len_words
|
||||
};
|
||||
|
||||
ret_val = sd_mbr_command(&command);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_mbr_init_sd(void)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
|
||||
sd_mbr_command_t command =
|
||||
{
|
||||
.command = SD_MBR_COMMAND_INIT_SD
|
||||
};
|
||||
|
||||
ret_val = sd_mbr_command(&command);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_mbr_compare(uint32_t * p_ptr1, uint32_t * p_ptr2, uint32_t len)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
uint32_t const len_words = len / sizeof(uint32_t);
|
||||
|
||||
sd_mbr_command_t command =
|
||||
{
|
||||
.command = SD_MBR_COMMAND_COMPARE,
|
||||
.params.compare.ptr1 = p_ptr1,
|
||||
.params.compare.ptr2 = p_ptr2,
|
||||
.params.compare.len = len_words
|
||||
};
|
||||
|
||||
ret_val = sd_mbr_command(&command);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_mbr_vector_table_set(uint32_t address)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
|
||||
NRF_LOG_INFO("running vector table set\r\n");
|
||||
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_INFO("After running vector table set\r\n");
|
||||
|
||||
return ret_val;
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_nrf_dfu_mbr MBR functions
|
||||
* @{
|
||||
* @ingroup sdk_nrf_dfu
|
||||
*/
|
||||
|
||||
#ifndef NRF_DFU_MBR_H__
|
||||
#define NRF_DFU_MBR_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Function for copying the bootloader using an MBR command.
|
||||
*
|
||||
* @param[in] p_src Source address of the bootloader data to copy.
|
||||
* @param[in] len Length of the data to copy in bytes.
|
||||
*
|
||||
* @return This function will return only if the command request could not be run.
|
||||
* See @ref sd_mbr_command_copy_bl_t for possible return values.
|
||||
*/
|
||||
uint32_t nrf_dfu_mbr_copy_bl(uint32_t * p_src, uint32_t len);
|
||||
|
||||
|
||||
/** @brief Function for copying the SoftDevice using an MBR command.
|
||||
*
|
||||
* @param[in] p_dst Target of the SoftDevice copy.
|
||||
* @param[in] p_src Source address of the SoftDevice image to copy.
|
||||
* @param[in] len Length of the data to copy in bytes.
|
||||
*
|
||||
* @retval NRF_SUCCESS indicates that the contents of the memory blocks where copied correctly.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH Invalid len
|
||||
* @retval NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
|
||||
* @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
* @retval NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
|
||||
*/
|
||||
uint32_t nrf_dfu_mbr_copy_sd(uint32_t * p_dst, uint32_t * p_src, uint32_t len);
|
||||
|
||||
|
||||
/** @brief Function for initializing the SoftDevice using an MBR command.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the SoftDevice was copied successfully.
|
||||
* Any other return value indicates that the SoftDevice
|
||||
* could not be copied.
|
||||
*/
|
||||
uint32_t nrf_dfu_mbr_init_sd(void);
|
||||
|
||||
|
||||
/** @brief Function for comparing source and target using an MBR command.
|
||||
*
|
||||
* @param[in] p_ptr1 First pointer to data to compare.
|
||||
* @param[in] p_ptr2 Second pointer to data to compare.
|
||||
* @param[in] len Length of the data to compare in bytes.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the content of both memory blocks is equal.
|
||||
* @retval NRF_ERROR_NULL If the content of the memory blocks differs.
|
||||
*/
|
||||
uint32_t nrf_dfu_mbr_compare(uint32_t * p_ptr1, uint32_t * p_ptr2, uint32_t len);
|
||||
|
||||
|
||||
/** @brief Function for setting the address of the vector table using an MBR command.
|
||||
*
|
||||
* @param[in] address Address of the new vector table.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the address of the new vector table was set. Any other
|
||||
* return value indicates that the address could not be set.
|
||||
*/
|
||||
uint32_t nrf_dfu_mbr_vector_table_set(uint32_t address);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DFU_MBR_H__
|
||||
|
||||
/** @} */
|
|
@ -1,260 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "nrf_dfu_settings.h"
|
||||
#include "nrf_dfu_flash.h"
|
||||
#include "nrf_log.h"
|
||||
#include "crc32.h"
|
||||
#include <string.h>
|
||||
#include "app_scheduler.h"
|
||||
#include "nrf_delay.h"
|
||||
|
||||
/** @brief This variable reserves a codepage for bootloader specific settings,
|
||||
* to ensure the compiler doesn't locate any code or variables at his location.
|
||||
*/
|
||||
#if defined (__CC_ARM )
|
||||
|
||||
uint8_t m_dfu_settings_buffer[CODE_PAGE_SIZE] __attribute__((at(BOOTLOADER_SETTINGS_ADDRESS)))
|
||||
__attribute__((used));
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
|
||||
uint8_t m_dfu_settings_buffer[CODE_PAGE_SIZE] __attribute__ ((section(".bootloaderSettings")))
|
||||
__attribute__((used));
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
__no_init __root uint8_t m_dfu_settings_buffer[CODE_PAGE_SIZE] @ BOOTLOADER_SETTINGS_ADDRESS;
|
||||
|
||||
#else
|
||||
|
||||
#error Not a valid compiler/linker for m_dfu_settings placement.
|
||||
|
||||
#endif // Compiler specific
|
||||
|
||||
#ifndef BL_SETTINGS_ACCESS_ONLY
|
||||
#if defined( NRF52_SERIES )
|
||||
|
||||
/**@brief This variable reserves a codepage for mbr parameters, to ensure the compiler doesn't
|
||||
* locate any code or variables at his location.
|
||||
*/
|
||||
#if defined ( __CC_ARM )
|
||||
|
||||
uint8_t m_mbr_params_page[CODE_PAGE_SIZE] __attribute__((at(NRF_MBR_PARAMS_PAGE_ADDRESS))) __attribute__((used));
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
|
||||
uint8_t m_mbr_params_page[CODE_PAGE_SIZE] __attribute__ ((section(".mbrParamsPage")));
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
__no_init uint8_t m_mbr_params_page[CODE_PAGE_SIZE] @ NRF_MBR_PARAMS_PAGE_ADDRESS;
|
||||
|
||||
#else
|
||||
|
||||
#error Not a valid compiler/linker for m_mbr_params_page placement.
|
||||
|
||||
#endif // Compiler specific
|
||||
|
||||
|
||||
/**@brief This variable makes the linker script write the mbr parameters page address to the
|
||||
* UICR register. This value will be written in the HEX file and thus written to the
|
||||
* UICR when the bootloader is flashed into the chip.
|
||||
*/
|
||||
#if defined ( __CC_ARM )
|
||||
uint32_t m_uicr_mbr_params_page_address __attribute__((at(NRF_UICR_MBR_PARAMS_PAGE_ADDRESS)))
|
||||
= NRF_MBR_PARAMS_PAGE_ADDRESS;
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
volatile uint32_t m_uicr_mbr_params_page_address __attribute__ ((section(".uicrMbrParamsPageAddress")))
|
||||
= NRF_MBR_PARAMS_PAGE_ADDRESS;
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
__root const uint32_t m_uicr_mbr_params_page_address @ NRF_UICR_MBR_PARAMS_PAGE_ADDRESS
|
||||
= NRF_MBR_PARAMS_PAGE_ADDRESS;
|
||||
|
||||
#else
|
||||
|
||||
#error Not a valid compiler/linker for m_mbr_params_page placement.
|
||||
|
||||
#endif // Compiler specific
|
||||
|
||||
#endif // #if defined( NRF52_SERIES )
|
||||
|
||||
#endif // #ifndef BL_SETTINGS_ACCESS_ONLY
|
||||
|
||||
nrf_dfu_settings_t s_dfu_settings;
|
||||
|
||||
//lint -save -esym(551, flash_operation_pending)
|
||||
static bool flash_operation_pending; // barrier for reading flash
|
||||
//lint -restore
|
||||
|
||||
static dfu_flash_callback_t m_callback;
|
||||
|
||||
|
||||
static void dfu_settings_write_callback(fs_evt_t const * const evt, fs_ret_t result)
|
||||
{
|
||||
if (result == FS_SUCCESS)
|
||||
{
|
||||
flash_operation_pending = false;
|
||||
}
|
||||
if (m_callback != NULL)
|
||||
{
|
||||
m_callback(evt, result);
|
||||
}
|
||||
}
|
||||
|
||||
static void delay_operation(void)
|
||||
{
|
||||
nrf_delay_ms(100);
|
||||
app_sched_execute();
|
||||
}
|
||||
|
||||
static void wait_for_pending(void)
|
||||
{
|
||||
while (flash_operation_pending == true)
|
||||
{
|
||||
NRF_LOG_INFO("Waiting for other flash operation to finish.\r\n");
|
||||
delay_operation();
|
||||
}
|
||||
}
|
||||
|
||||
static void wait_for_queue(void)
|
||||
{
|
||||
while (fs_queue_is_full())
|
||||
{
|
||||
NRF_LOG_INFO("Waiting for available space on flash queue.\r\n");
|
||||
delay_operation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_settings_calculate_crc(void)
|
||||
{
|
||||
// the crc is calculated from the s_dfu_settings struct, except the crc itself and the init command
|
||||
return crc32_compute((uint8_t*)&s_dfu_settings + 4, sizeof(nrf_dfu_settings_t) - 4 - sizeof(s_dfu_settings.init_command), NULL);
|
||||
}
|
||||
|
||||
|
||||
void nrf_dfu_settings_init(void)
|
||||
{
|
||||
NRF_LOG_INFO("running nrf_dfu_settings_init\r\n");
|
||||
|
||||
uint32_t crc;
|
||||
|
||||
flash_operation_pending = false;
|
||||
|
||||
// Copy the DFU settings out of flash and into a buffer in RAM.
|
||||
memcpy((void*)&s_dfu_settings, &m_dfu_settings_buffer[0], sizeof(nrf_dfu_settings_t));
|
||||
|
||||
if(s_dfu_settings.crc != 0xFFFFFFFF)
|
||||
{
|
||||
// CRC is set. Content must be valid
|
||||
crc = nrf_dfu_settings_calculate_crc();
|
||||
if(crc == s_dfu_settings.crc)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Reached if nothing is configured or if CRC was wrong
|
||||
NRF_LOG_INFO("!!!!!!!!!!!!!!! Resetting bootloader settings !!!!!!!!!!!\r\n");
|
||||
memset(&s_dfu_settings, 0x00, sizeof(nrf_dfu_settings_t));
|
||||
s_dfu_settings.settings_version = NRF_DFU_SETTINGS_VERSION;
|
||||
APP_ERROR_CHECK(nrf_dfu_settings_write(NULL));
|
||||
}
|
||||
|
||||
|
||||
ret_code_t nrf_dfu_settings_write(dfu_flash_callback_t callback)
|
||||
{
|
||||
ret_code_t err_code = FS_SUCCESS;
|
||||
NRF_LOG_INFO("Erasing old settings at: 0x%08x\r\n", (uint32_t)&m_dfu_settings_buffer[0]);
|
||||
|
||||
// Wait for any ongoing operation (because of multiple calls to nrf_dfu_settings_write)
|
||||
wait_for_pending();
|
||||
|
||||
flash_operation_pending = true;
|
||||
m_callback = callback;
|
||||
|
||||
do
|
||||
{
|
||||
wait_for_queue();
|
||||
|
||||
// Not setting the callback function because ERASE is required before STORE
|
||||
// Only report completion on successful STORE.
|
||||
err_code = nrf_dfu_flash_erase((uint32_t*)&m_dfu_settings_buffer[0], 1, NULL);
|
||||
|
||||
} while (err_code == FS_ERR_QUEUE_FULL);
|
||||
|
||||
|
||||
if (err_code != FS_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Erasing from flash memory failed.\r\n");
|
||||
flash_operation_pending = false;
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
s_dfu_settings.crc = nrf_dfu_settings_calculate_crc();
|
||||
|
||||
NRF_LOG_INFO("Writing 0x%08x words\r\n", sizeof(nrf_dfu_settings_t)/4);
|
||||
|
||||
static nrf_dfu_settings_t temp_dfu_settings;
|
||||
memcpy(&temp_dfu_settings, &s_dfu_settings, sizeof(nrf_dfu_settings_t));
|
||||
|
||||
do
|
||||
{
|
||||
wait_for_queue();
|
||||
|
||||
err_code = nrf_dfu_flash_store((uint32_t*)&m_dfu_settings_buffer[0],
|
||||
(uint32_t*)&temp_dfu_settings,
|
||||
sizeof(nrf_dfu_settings_t)/4,
|
||||
dfu_settings_write_callback);
|
||||
|
||||
} while (err_code == FS_ERR_QUEUE_FULL);
|
||||
|
||||
if (err_code != FS_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Storing to flash memory failed.\r\n");
|
||||
flash_operation_pending = false;
|
||||
return NRF_ERROR_INTERNAL;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Writing settings...\r\n");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup nrf_dfu_settings DFU settings
|
||||
* @{
|
||||
* @ingroup sdk_nrf_dfu
|
||||
*/
|
||||
|
||||
#ifndef NRF_DFU_SETTINGS_H__
|
||||
#define NRF_DFU_SETTINGS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "app_util_platform.h"
|
||||
#include "nrf_dfu_types.h"
|
||||
#include "nrf_dfu_flash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**@brief Global DFU settings.
|
||||
*
|
||||
* @note Using this variable is not thread-safe.
|
||||
*
|
||||
*/
|
||||
extern nrf_dfu_settings_t s_dfu_settings;
|
||||
|
||||
|
||||
/** @brief Function for writing DFU settings to flash.
|
||||
*
|
||||
* @param[in] callback Pointer to a function that is called after completing the write operation.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the write process was successfully initiated.
|
||||
* @retval NRF_ERROR_INTERNAL If a flash error occurred.
|
||||
*/
|
||||
ret_code_t nrf_dfu_settings_write(dfu_flash_callback_t callback);
|
||||
|
||||
|
||||
/** @brief Function for initializing the DFU settings module.
|
||||
*/
|
||||
void nrf_dfu_settings_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DFU_SETTINGS_H__
|
||||
|
||||
/**@} */
|
|
@ -1,572 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "nrf_dfu_utils.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "nrf_dfu_settings.h"
|
||||
#include "nrf_dfu_mbr.h"
|
||||
#include "nrf_bootloader_app_start.h"
|
||||
#include "nrf_bootloader_info.h"
|
||||
#include "crc32.h"
|
||||
#include "nrf_log.h"
|
||||
|
||||
|
||||
static uint32_t align_to_page(uint32_t val, uint32_t page_size)
|
||||
{
|
||||
return ((val + page_size - 1 ) &~ (page_size - 1));
|
||||
}
|
||||
|
||||
|
||||
static void nrf_dfu_invalidate_bank(nrf_dfu_bank_t * p_bank)
|
||||
{
|
||||
// Set the bank-code to invalid, and reset size/CRC
|
||||
memset(p_bank, 0, sizeof(nrf_dfu_bank_t));
|
||||
|
||||
// Reset write pointer after completed operation
|
||||
s_dfu_settings.write_offset = 0;
|
||||
|
||||
// Reset SD size
|
||||
s_dfu_settings.sd_size = 0;
|
||||
|
||||
// Promote dual bank layout
|
||||
s_dfu_settings.bank_layout = NRF_DFU_BANK_LAYOUT_DUAL;
|
||||
|
||||
// Signify that bank 0 is empty
|
||||
s_dfu_settings.bank_current = NRF_DFU_CURRENT_BANK_0;
|
||||
}
|
||||
|
||||
|
||||
/** @brief Function to continue App update
|
||||
*
|
||||
* @details This function will be called after reset if there is a valid application in Bank1
|
||||
* required to be copied down to bank0.
|
||||
*
|
||||
* @param[in] src_addr Source address of the application to copy from Bank1 to Bank0.
|
||||
*
|
||||
* @retval NRF_SUCCESS Continuation was successful.
|
||||
* @retval NRF_ERROR_NULL Invalid data during compare.
|
||||
* @retval FS_ERR_UNALIGNED_ADDR A call to fstorage was not aligned to a page boundary or the address was not word aliged.
|
||||
* @retval FS_ERR_INVALID_ADDR The destination of a call to fstorage does not point to
|
||||
* the start of a flash page or the operation would
|
||||
* go beyond the flash memory boundary.
|
||||
* @retval FS_ERR_NOT_INITIALIZED The fstorage module is not initialized.
|
||||
* @retval FS_ERR_INVALID_CFG The initialization of the fstorage module is invalid.
|
||||
* @retval FS_ERR_NULL_ARG A call to fstorage had an invalid NULL argument.
|
||||
* @retval FS_ERR_INVALID_ARG A call to fstorage had invalid arguments.
|
||||
* @retval FS_ERR_QUEUE_FULL If the internal operation queue of the fstorage module is full.
|
||||
* @retval FS_ERR_FAILURE_SINCE_LAST If an error occurred in another transaction and fstorage cannot continue before
|
||||
* the event has been dealt with.
|
||||
*/
|
||||
static uint32_t nrf_dfu_app_continue(uint32_t src_addr)
|
||||
{
|
||||
// This function only in use when new app is present in bank 1
|
||||
uint32_t const image_size = s_dfu_settings.bank_1.image_size;
|
||||
uint32_t const split_size = CODE_PAGE_SIZE; // Arbitrary number that must be page aligned
|
||||
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
uint32_t target_addr = MAIN_APPLICATION_START_ADDR + s_dfu_settings.write_offset;
|
||||
uint32_t length_left = (image_size - s_dfu_settings.write_offset);
|
||||
uint32_t cur_len;
|
||||
uint32_t crc;
|
||||
|
||||
NRF_LOG_INFO("Enter nrf_dfu_app_continue\r\n");
|
||||
|
||||
// Copy the application down safely
|
||||
do
|
||||
{
|
||||
cur_len = (length_left > split_size) ? split_size : length_left;
|
||||
|
||||
// Erase the target page
|
||||
ret_val = nrf_dfu_flash_erase((uint32_t*) target_addr, split_size / CODE_PAGE_SIZE, NULL);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
// Flash one page
|
||||
ret_val = nrf_dfu_flash_store((uint32_t*)target_addr, (uint32_t*)src_addr, cur_len, NULL);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
ret_val = nrf_dfu_mbr_compare((uint32_t*)target_addr, (uint32_t*)src_addr, cur_len);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
// We will not retry the copy
|
||||
NRF_LOG_ERROR("Invalid data during compare: target: 0x%08x, src: 0x%08x\r\n", target_addr, src_addr);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
// Erase the head (to handle growing bank 0)
|
||||
ret_val = nrf_dfu_flash_erase((uint32_t*) src_addr, split_size / CODE_PAGE_SIZE, NULL);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("App update: Failure erasing page at addr: 0x%08x\r\n", src_addr);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
s_dfu_settings.write_offset += cur_len;
|
||||
ret_val = nrf_dfu_settings_write(NULL);
|
||||
|
||||
target_addr += cur_len;
|
||||
src_addr += cur_len;
|
||||
|
||||
length_left -= cur_len;
|
||||
}
|
||||
while(length_left > 0);
|
||||
|
||||
// Check the crc of the copied data. Enable if so.
|
||||
crc = crc32_compute((uint8_t*)MAIN_APPLICATION_START_ADDR, image_size, NULL);
|
||||
|
||||
if (crc == s_dfu_settings.bank_1.image_crc)
|
||||
{
|
||||
NRF_LOG_INFO("Setting app as valid\r\n");
|
||||
s_dfu_settings.bank_0.bank_code = NRF_DFU_BANK_VALID_APP;
|
||||
s_dfu_settings.bank_0.image_crc = crc;
|
||||
s_dfu_settings.bank_0.image_size = image_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_LOG_ERROR("CRC computation failed for copied app: src crc: 0x%08x, res crc: 0x08x\r\n", s_dfu_settings.bank_1.image_crc, crc);
|
||||
}
|
||||
|
||||
nrf_dfu_invalidate_bank(&s_dfu_settings.bank_1);
|
||||
ret_val = nrf_dfu_settings_write(NULL);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/** @brief Function to execute the continuation of a SoftDevice update.
|
||||
*
|
||||
* @param[in] src_addr Source address of the SoftDevice to copy from.
|
||||
* @param[in] p_bank Pointer to the bank where the SoftDevice resides.
|
||||
*
|
||||
* @retval NRF_SUCCESS Continuation was successful.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH Invalid len
|
||||
* @retval NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
|
||||
* @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
* @retval NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
|
||||
* @retval NRF_ERROR_NULL If the content of the memory blocks differs after copying.
|
||||
*/
|
||||
static uint32_t nrf_dfu_sd_continue_impl(uint32_t src_addr,
|
||||
nrf_dfu_bank_t * p_bank)
|
||||
{
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
uint32_t target_addr = SOFTDEVICE_REGION_START + s_dfu_settings.write_offset;
|
||||
uint32_t length_left = align_to_page(s_dfu_settings.sd_size - s_dfu_settings.write_offset, CODE_PAGE_SIZE);
|
||||
uint32_t split_size = align_to_page(length_left / 4, CODE_PAGE_SIZE);
|
||||
|
||||
NRF_LOG_INFO("Enter nrf_bootloader_dfu_sd_continue\r\n");
|
||||
|
||||
// This can be a continuation due to a power failure
|
||||
src_addr += s_dfu_settings.write_offset;
|
||||
|
||||
if (s_dfu_settings.sd_size != 0 && s_dfu_settings.write_offset == s_dfu_settings.sd_size)
|
||||
{
|
||||
NRF_LOG_INFO("SD already copied\r\n");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Updating SD. Old SD ver: 0x%04x\r\n", SD_FWID_GET(MBR_SIZE));
|
||||
|
||||
do
|
||||
{
|
||||
NRF_LOG_INFO("Copying [0x%08x-0x%08x] to [0x%08x-0x%08x]: Len: 0x%08x\r\n", src_addr, src_addr + split_size, target_addr, target_addr + split_size, split_size);
|
||||
|
||||
// Copy a chunk of the SD. Size in words
|
||||
ret_val = nrf_dfu_mbr_copy_sd((uint32_t*)target_addr, (uint32_t*)src_addr, split_size);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Failed to copy SD: target: 0x%08x, src: 0x%08x, len: 0x%08x\r\n", target_addr, src_addr, split_size);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Finished copying [0x%08x-0x%08x] to [0x%08x-0x%08x]: Len: 0x%08x\r\n", src_addr, src_addr + split_size, target_addr, target_addr + split_size, split_size);
|
||||
|
||||
// Validate copy. Size in words
|
||||
ret_val = nrf_dfu_mbr_compare((uint32_t*)target_addr, (uint32_t*)src_addr, split_size);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Failed to Compare SD: target: 0x%08x, src: 0x%08x, len: 0x%08x\r\n", target_addr, src_addr, split_size);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Validated 0x%08x-0x%08x to 0x%08x-0x%08x: Size: 0x%08x\r\n", src_addr, src_addr + split_size, target_addr, target_addr + split_size, split_size);
|
||||
|
||||
target_addr += split_size;
|
||||
src_addr += split_size;
|
||||
|
||||
if (split_size > length_left)
|
||||
{
|
||||
length_left = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
length_left -= split_size;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Finished with the SD update.\r\n");
|
||||
|
||||
// Save the updated point of writes in case of power loss
|
||||
s_dfu_settings.write_offset = s_dfu_settings.sd_size - length_left;
|
||||
ret_val = nrf_dfu_settings_write(NULL);
|
||||
}
|
||||
while (length_left > 0);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
/** @brief Function to continue SoftDevice update
|
||||
*
|
||||
* @details This function will be called after reset if there is a valid SoftDevice in Bank0 or Bank1
|
||||
* required to be relocated and activated through MBR commands.
|
||||
*
|
||||
* @param[in] src_addr Source address of the SoftDevice to copy from.
|
||||
* @param[in] p_bank Pointer to the bank where the SoftDevice resides.
|
||||
*
|
||||
* @retval NRF_SUCCESS Continuation was successful.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH Invalid len
|
||||
* @retval NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
|
||||
* @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
* @retval NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
|
||||
* @retval NRF_ERROR_NULL If the content of the memory blocks differs after copying.
|
||||
*/
|
||||
static uint32_t nrf_dfu_sd_continue(uint32_t src_addr,
|
||||
nrf_dfu_bank_t * p_bank)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
|
||||
ret_val = nrf_dfu_sd_continue_impl(src_addr, p_bank);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("SD update continuation failed\r\n");
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
nrf_dfu_invalidate_bank(p_bank);
|
||||
ret_val = nrf_dfu_settings_write(NULL);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
/** @brief Function to continue Bootloader update
|
||||
*
|
||||
* @details This function will be called after reset if there is a valid Bootloader in Bank0 or Bank1
|
||||
* required to be relocated and activated through MBR commands.
|
||||
*
|
||||
* @param[in] src_addr Source address of the BL to copy from.
|
||||
* @param[in] p_bank Pointer to the bank where the SoftDevice resides.
|
||||
*
|
||||
* @return This fucntion will not return if the bootloader is copied succesfully.
|
||||
* After the copy is verified the device will reset and start the new bootloader.
|
||||
*
|
||||
* @retval NRF_SUCCESS Continuation was successful.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH Invalid length of flash operation.
|
||||
* @retval NRF_ERROR_NO_MEM if no parameter page is provided (see sds for more info).
|
||||
* @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
* @retval NRF_ERROR_INTERNAL internal error that should not happen.
|
||||
* @retval NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
|
||||
*/
|
||||
static uint32_t nrf_dfu_bl_continue(uint32_t src_addr, nrf_dfu_bank_t * p_bank)
|
||||
{
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
uint32_t const len = (p_bank->image_size - s_dfu_settings.sd_size);
|
||||
|
||||
// if the update is a combination of BL + SD, offset with SD size to get BL start address
|
||||
src_addr += s_dfu_settings.sd_size;
|
||||
|
||||
NRF_LOG_INFO("Verifying BL: Addr: 0x%08x, Src: 0x%08x, Len: 0x%08x\r\n", MAIN_APPLICATION_START_ADDR, src_addr, len);
|
||||
|
||||
|
||||
// If the bootloader is the same as the banked version, the copy is finished
|
||||
ret_val = nrf_dfu_mbr_compare((uint32_t*)BOOTLOADER_START_ADDR, (uint32_t*)src_addr, len);
|
||||
if (ret_val == NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_INFO("Bootloader was verified\r\n");
|
||||
|
||||
// Invalidate bank, marking completion
|
||||
nrf_dfu_invalidate_bank(p_bank);
|
||||
ret_val = nrf_dfu_settings_write(NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
NRF_LOG_INFO("Bootloader not verified, copying: Src: 0x%08x, Len: 0x%08x\r\n", src_addr, len);
|
||||
// Bootloader is different than the banked version. Continue copy
|
||||
// Note that if the SD and BL was combined, then the split point between them is in s_dfu_settings.sd_size
|
||||
ret_val = nrf_dfu_mbr_copy_bl((uint32_t*)src_addr, len);
|
||||
if(ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Request to copy BL failed\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
/** @brief Function to continue combined Bootloader and SoftDevice update
|
||||
*
|
||||
* @details This function will be called after reset if there is a valid Bootloader and SoftDevice in Bank0 or Bank1
|
||||
* required to be relocated and activated through MBR commands.
|
||||
*
|
||||
* @param[in] src_addr Source address of the combined Bootloader and SoftDevice to copy from.
|
||||
* @param[in] p_bank Pointer to the bank where the SoftDevice resides.
|
||||
*
|
||||
* @retval NRF_SUCCESS Continuation was successful.
|
||||
* @retval NRF_ERROR_INVALID_LENGTH Invalid len
|
||||
* @retval NRF_ERROR_NO_MEM if UICR.NRFFW[1] is not set (i.e. is 0xFFFFFFFF).
|
||||
* @retval NRF_ERROR_INVALID_PARAM if an invalid command is given.
|
||||
* @retval NRF_ERROR_INTERNAL indicates that the contents of the memory blocks where not verified correctly after copying.
|
||||
* @retval NRF_ERROR_NULL If the content of the memory blocks differs after copying.
|
||||
* @retval NRF_ERROR_FORBIDDEN if NRF_UICR->BOOTADDR is not set.
|
||||
*/
|
||||
static uint32_t nrf_dfu_sd_bl_continue(uint32_t src_addr, nrf_dfu_bank_t * p_bank)
|
||||
{
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
|
||||
NRF_LOG_INFO("Enter nrf_dfu_sd_bl_continue\r\n");
|
||||
|
||||
ret_val = nrf_dfu_sd_continue_impl(src_addr, p_bank);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("SD+BL: SD copy failed\r\n");
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
ret_val = nrf_dfu_bl_continue(src_addr, p_bank);
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("SD+BL: BL copy failed\r\n");
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t nrf_dfu_continue_bank(nrf_dfu_bank_t * p_bank, uint32_t src_addr, uint32_t * p_enter_dfu_mode)
|
||||
{
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
|
||||
switch (p_bank->bank_code)
|
||||
{
|
||||
case NRF_DFU_BANK_VALID_APP:
|
||||
NRF_LOG_INFO("Valid App\r\n");
|
||||
if(s_dfu_settings.bank_current == NRF_DFU_CURRENT_BANK_1)
|
||||
{
|
||||
// Only continue copying if valid app in bank1
|
||||
ret_val = nrf_dfu_app_continue(src_addr);
|
||||
}
|
||||
break;
|
||||
|
||||
case NRF_DFU_BANK_VALID_SD:
|
||||
NRF_LOG_INFO("Valid SD\r\n");
|
||||
// There is a valid SD that needs to be copied (or continued)
|
||||
ret_val = nrf_dfu_sd_continue(src_addr, p_bank);
|
||||
(*p_enter_dfu_mode) = 1;
|
||||
break;
|
||||
|
||||
case NRF_DFU_BANK_VALID_BL:
|
||||
NRF_LOG_INFO("Valid BL\r\n");
|
||||
// There is a valid BL that must be copied (or continued)
|
||||
ret_val = nrf_dfu_bl_continue(src_addr, p_bank);
|
||||
break;
|
||||
|
||||
case NRF_DFU_BANK_VALID_SD_BL:
|
||||
NRF_LOG_INFO("Single: Valid SD + BL\r\n");
|
||||
// There is a valid SD + BL that must be copied (or continued)
|
||||
ret_val = nrf_dfu_sd_bl_continue(src_addr, p_bank);
|
||||
// Set the bank-code to invalid, and reset size/CRC
|
||||
(*p_enter_dfu_mode) = 1;
|
||||
break;
|
||||
|
||||
case NRF_DFU_BANK_INVALID:
|
||||
default:
|
||||
NRF_LOG_ERROR("Single: Invalid bank\r\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_continue(uint32_t * p_enter_dfu_mode)
|
||||
{
|
||||
uint32_t ret_val;
|
||||
nrf_dfu_bank_t * p_bank;
|
||||
uint32_t src_addr = CODE_REGION_1_START;
|
||||
|
||||
NRF_LOG_INFO("Enter nrf_dfu_continue\r\n");
|
||||
|
||||
if (s_dfu_settings.bank_layout == NRF_DFU_BANK_LAYOUT_SINGLE )
|
||||
{
|
||||
p_bank = &s_dfu_settings.bank_0;
|
||||
}
|
||||
else if(s_dfu_settings.bank_current == NRF_DFU_CURRENT_BANK_0)
|
||||
{
|
||||
p_bank = &s_dfu_settings.bank_0;
|
||||
}
|
||||
else
|
||||
{
|
||||
p_bank = &s_dfu_settings.bank_1;
|
||||
src_addr += align_to_page(s_dfu_settings.bank_0.image_size, CODE_PAGE_SIZE);
|
||||
}
|
||||
|
||||
ret_val = nrf_dfu_continue_bank(p_bank, src_addr, p_enter_dfu_mode);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
bool nrf_dfu_app_is_valid(void)
|
||||
{
|
||||
NRF_LOG_INFO("Enter nrf_dfu_app_is_valid\r\n");
|
||||
if (s_dfu_settings.bank_0.bank_code != NRF_DFU_BANK_VALID_APP)
|
||||
{
|
||||
// Bank 0 has no valid app. Nothing to boot
|
||||
NRF_LOG_INFO("Return false in valid app check\r\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
// If CRC == 0, this means CRC check is skipped.
|
||||
if (s_dfu_settings.bank_0.image_crc != 0)
|
||||
{
|
||||
uint32_t crc = crc32_compute((uint8_t*) CODE_REGION_1_START,
|
||||
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_INFO("Return false in CRC\r\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Return true. App was valid\r\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_dfu_find_cache(uint32_t size_req, bool dual_bank_only, uint32_t * p_address)
|
||||
{
|
||||
// TODO: Prevalidate p_address and p_bank
|
||||
|
||||
uint32_t free_size = DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED;
|
||||
nrf_dfu_bank_t * p_bank;
|
||||
|
||||
NRF_LOG_INFO("Enter nrf_dfu_find_cache\r\n");
|
||||
|
||||
// Simple check if size requirement can me met
|
||||
if(free_size < size_req)
|
||||
{
|
||||
NRF_LOG_INFO("No way to fit the new firmware on device\r\n");
|
||||
return NRF_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("Bank content\r\n");
|
||||
NRF_LOG_INFO("Bank type: %d\r\n", s_dfu_settings.bank_layout);
|
||||
NRF_LOG_INFO("Bank 0 code: 0x%02x: Size: %d\r\n", s_dfu_settings.bank_0.bank_code, s_dfu_settings.bank_0.image_size);
|
||||
NRF_LOG_INFO("Bank 1 code: 0x%02x: Size: %d\r\n", s_dfu_settings.bank_1.bank_code, s_dfu_settings.bank_1.image_size);
|
||||
|
||||
// Setting bank_0 as candidate
|
||||
p_bank = &s_dfu_settings.bank_0;
|
||||
|
||||
// Setting candidate address
|
||||
(*p_address) = MAIN_APPLICATION_START_ADDR;
|
||||
|
||||
// Calculate free size
|
||||
if (s_dfu_settings.bank_0.bank_code == NRF_DFU_BANK_VALID_APP)
|
||||
{
|
||||
// Valid app present.
|
||||
|
||||
NRF_LOG_INFO("free_size before bank select: %d\r\n", free_size);
|
||||
|
||||
free_size -= align_to_page(p_bank->image_size, CODE_PAGE_SIZE);
|
||||
|
||||
NRF_LOG_INFO("free_size: %d, size_req: %d\r\n", free_size, size_req);
|
||||
|
||||
// Check if we can fit the new in the free space or if removal of old app is required.
|
||||
if(size_req > free_size)
|
||||
{
|
||||
// Not enough room in free space (bank_1)
|
||||
if ((dual_bank_only))
|
||||
{
|
||||
NRF_LOG_ERROR("Failure: dual bank restriction\r\n");
|
||||
return NRF_ERROR_NO_MEM;
|
||||
}
|
||||
|
||||
// Can only support single bank update, clearing old app.
|
||||
s_dfu_settings.bank_layout = NRF_DFU_BANK_LAYOUT_SINGLE;
|
||||
s_dfu_settings.bank_current = NRF_DFU_CURRENT_BANK_0;
|
||||
p_bank = &s_dfu_settings.bank_0;
|
||||
NRF_LOG_INFO("Enforcing single bank\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Room in bank_1 for update
|
||||
// Ensure we are using dual bank layout
|
||||
s_dfu_settings.bank_layout = NRF_DFU_BANK_LAYOUT_DUAL;
|
||||
s_dfu_settings.bank_current = NRF_DFU_CURRENT_BANK_1;
|
||||
p_bank = &s_dfu_settings.bank_1;
|
||||
// Set to first free page boundry after previous app
|
||||
(*p_address) += align_to_page(s_dfu_settings.bank_0.image_size, CODE_PAGE_SIZE);
|
||||
NRF_LOG_INFO("Using second bank\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No valid app present. Promoting dual bank.
|
||||
s_dfu_settings.bank_layout = NRF_DFU_BANK_LAYOUT_DUAL;
|
||||
s_dfu_settings.bank_current = NRF_DFU_CURRENT_BANK_0;
|
||||
|
||||
p_bank = &s_dfu_settings.bank_0;
|
||||
NRF_LOG_INFO("No previous, using bank 0\r\n");
|
||||
}
|
||||
|
||||
// Set the bank-code to invalid, and reset size/CRC
|
||||
memset(p_bank, 0, sizeof(nrf_dfu_bank_t));
|
||||
|
||||
// Store the Firmware size in the bank for continuations
|
||||
p_bank->image_size = size_req;
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_nrf_dfu_utils DFU utilities
|
||||
* @{
|
||||
* @ingroup sdk_nrf_dfu
|
||||
*/
|
||||
|
||||
#ifndef NRF_DFU_UTILS_H__
|
||||
#define NRF_DFU_UTILS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "nrf_dfu_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief Function for continuing an ongoing DFU operation.
|
||||
*
|
||||
* @details This function initiates or continues the DFU copy-back
|
||||
* routines. These routines are fail-safe operations to activate
|
||||
* either a new SoftDevice, Bootloader, combination of SoftDevice and
|
||||
* Bootloader, or a new application.
|
||||
*
|
||||
* @details This function relies on accessing MBR commands through supervisor calls.
|
||||
* It does not rely on the SoftDevice for flash operations.
|
||||
*
|
||||
* @note When updating the bootloader or both bootloader and SoftDevice in combination,
|
||||
* this function does not return, but rather initiate a reboot to activate
|
||||
* the new bootloader.
|
||||
*
|
||||
* @param[in,out] p_enter_dfu_mode True if the continuation failed or the update requires DFU mode.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the DFU operation was continued successfully.
|
||||
* Any other error code indicates that the DFU operation could
|
||||
* not be continued.
|
||||
*/
|
||||
uint32_t nrf_dfu_continue(uint32_t * p_enter_dfu_mode);
|
||||
|
||||
|
||||
/** @brief Function for checking if the main application is valid.
|
||||
*
|
||||
* @details This function checks if there is a valid application
|
||||
* located at Bank 0.
|
||||
*
|
||||
* @retval true If a valid application has been detected.
|
||||
* @retval false If there is no valid application.
|
||||
*/
|
||||
bool nrf_dfu_app_is_valid(void);
|
||||
|
||||
|
||||
/** @brief Function for finding a cache write location for the DFU process.
|
||||
*
|
||||
* @details This function checks the size requirements and selects a location for
|
||||
* placing the cache of the DFU images.
|
||||
* The function tries to find enough space in Bank 1. If there is not enough space,
|
||||
* the present application is erased.
|
||||
*
|
||||
* @param[in] size_req Requirements for the size of the new image.
|
||||
* @param[in] dual_bank_only True to enforce dual-bank updates. In this case, if there
|
||||
* is not enough space for caching the DFU image, the existing
|
||||
* application is retained and the function returns an error.
|
||||
* @param[out] p_address Updated to the cache address if a cache location is found.
|
||||
*
|
||||
* @retval NRF_SUCCESS If a cache location was found for the DFU process.
|
||||
* @retval NRF_ERROR_NO_MEM If there is no space available on the device to continue the DFU process.
|
||||
*/
|
||||
uint32_t nrf_dfu_find_cache(uint32_t size_req, bool dual_bank_only, uint32_t * p_address);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_DFU_UTILS_H__
|
||||
|
||||
/** @} */
|
|
@ -1,99 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "nrf_bootloader.h"
|
||||
|
||||
#include "compiler_abstraction.h"
|
||||
#include "nrf.h"
|
||||
#include "nrf_bootloader_app_start.h"
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_dfu.h"
|
||||
#include "nrf_error.h"
|
||||
|
||||
|
||||
/** @brief Weak implemenation of nrf_dfu_init
|
||||
*
|
||||
* @note This function will be overridden if nrf_dfu.c is
|
||||
* compiled and linked with the project
|
||||
*/
|
||||
#if (__LINT__ != 1)
|
||||
__WEAK uint32_t nrf_dfu_init(void)
|
||||
{
|
||||
NRF_LOG_INFO("in weak nrf_dfu_init\r\n");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief Weak implementation of nrf_dfu_init
|
||||
*
|
||||
* @note This function must be overridden in application if
|
||||
* user-specific initialization is needed.
|
||||
*/
|
||||
__WEAK uint32_t nrf_dfu_init_user(void)
|
||||
{
|
||||
NRF_LOG_INFO("in weak nrf_dfu_init_user\r\n");
|
||||
return NRF_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
uint32_t nrf_bootloader_init(void)
|
||||
{
|
||||
NRF_LOG_INFO("In nrf_bootloader_init\r\n");
|
||||
|
||||
uint32_t ret_val = NRF_SUCCESS;
|
||||
|
||||
#if 0
|
||||
// Call user-defined init function if implemented
|
||||
ret_val = nrf_dfu_init_user();
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
return ret_val;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Call DFU init function if implemented
|
||||
ret_val = nrf_dfu_init();
|
||||
if (ret_val != NRF_SUCCESS)
|
||||
{
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
NRF_LOG_INFO("After nrf_bootloader_init\r\n");
|
||||
return ret_val;
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_nrf_bootloader Bootloader modules
|
||||
* @ingroup app_common
|
||||
* @brief Modules for creating a bootloader.
|
||||
*
|
||||
* @defgroup sdk_bootloader Bootloader
|
||||
* @{
|
||||
* @ingroup sdk_nrf_bootloader
|
||||
* @brief Basic bootloader.
|
||||
*
|
||||
* The bootloader module can be used to implement a basic bootloader that
|
||||
* can be extended with, for example, Device Firmware Update (DFU) support
|
||||
* or custom functionality.
|
||||
*/
|
||||
|
||||
#ifndef NRF_BOOTLOADER_H__
|
||||
#define NRF_BOOTLOADER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief Function for initializing the bootloader.
|
||||
*
|
||||
* @details This function is the entry point of all bootloader operations.
|
||||
* If DFU functionality is compiled in, the DFU process is initialized
|
||||
* when running this function.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the bootloader was successfully initialized.
|
||||
* Any other return code indicates that the operation failed.
|
||||
*/
|
||||
uint32_t nrf_bootloader_init(void);
|
||||
|
||||
|
||||
/** @brief Function for customizing the bootloader initialization.
|
||||
*
|
||||
* @details This function is called during the initialization of the bootloader.
|
||||
* It is implemented as weak function that can be overridden in the main file of the application.
|
||||
*
|
||||
* @retval NRF_SUCCESS If the user initialization was run successfully.
|
||||
*/
|
||||
uint32_t nrf_bootloader_user_init(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NRF_BOOTLOADER_H__
|
||||
/** @} */
|
|
@ -1,209 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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_bootloader_app_start.h"
|
||||
#include "compiler_abstraction.h"
|
||||
#include "nrf_log.h"
|
||||
#include "nrf_dfu_mbr.h"
|
||||
#include "nrf_sdm.h"
|
||||
|
||||
#if defined ( __CC_ARM )
|
||||
__ASM static void nrf_bootloader_app_start_impl(uint32_t start_addr)
|
||||
{
|
||||
LDR R5, [R0] ; Get App initial MSP for bootloader.
|
||||
MSR MSP, R5 ; Set the main stack pointer to the applications MSP.
|
||||
LDR R0, [R0, #0x04] ; Load Reset handler into R0. This will be first argument to branch instruction (BX).
|
||||
|
||||
MOVS R4, #0xFF ; Load ones to R4.
|
||||
SXTB R4, R4 ; Sign extend R4 to obtain 0xFFFFFFFF instead of 0xFF.
|
||||
MRS R5, IPSR ; Load IPSR to R5 to check for handler or thread mode.
|
||||
CMP R5, #0x00 ; Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
|
||||
BNE isr_abort ; If not zero we need to exit current ISR and jump to reset handler of bootloader.
|
||||
|
||||
MOV LR, R4 ; Clear the link register and set to ones to ensure no return, R4 = 0xFFFFFFFF.
|
||||
BX R0 ; Branch to reset handler of bootloader.
|
||||
|
||||
isr_abort
|
||||
; R4 contains ones from line above. Will be popped as R12 when exiting ISR (Cleaning up the registers).
|
||||
MOV R5, R4 ; Fill with ones before jumping to reset handling. We be popped as LR when exiting ISR. Ensures no return to application.
|
||||
MOV R6, R0 ; Move address of reset handler to R6. Will be popped as PC when exiting ISR. Ensures the reset handler will be executed when exist ISR.
|
||||
MOVS r7, #0x21 ; Move MSB reset value of xPSR to R7. Will be popped as xPSR when exiting ISR. xPSR is 0x21000000 thus MSB is 0x21.
|
||||
REV r7, r7 ; Reverse byte order to put 0x21 as MSB.
|
||||
PUSH {r4-r7} ; Push everything to new stack to allow interrupt handler to fetch it on exiting the ISR.
|
||||
|
||||
MOVS R4, #0x00 ; Fill with zeros before jumping to reset handling. We be popped as R0 when exiting ISR (Cleaning up of the registers).
|
||||
MOVS R5, #0x00 ; Fill with zeros before jumping to reset handling. We be popped as R1 when exiting ISR (Cleaning up of the registers).
|
||||
MOVS R6, #0x00 ; Fill with zeros before jumping to reset handling. We be popped as R2 when exiting ISR (Cleaning up of the registers).
|
||||
MOVS R7, #0x00 ; Fill with zeros before jumping to reset handling. We be popped as R3 when exiting ISR (Cleaning up of the registers).
|
||||
PUSH {r4-r7} ; Push zeros (R4-R7) to stack to prepare for exiting the interrupt routine.
|
||||
|
||||
MOVS R0, #0xF9 ; Move the execution return command into register, 0xFFFFFFF9.
|
||||
SXTB R0, R0 ; Sign extend R0 to obtain 0xFFFFFFF9 instead of 0xF9.
|
||||
BX R0 ; No return - Handler mode will be exited. Stack will be popped and execution will continue in reset handler initializing other application.
|
||||
ALIGN
|
||||
}
|
||||
|
||||
#elif defined ( __GNUC__ )
|
||||
|
||||
static void __attribute__ ((noinline)) nrf_bootloader_app_start_impl(uint32_t start_addr)
|
||||
{
|
||||
__ASM volatile(
|
||||
"ldr r0, [%0]\t\n" // Get App initial MSP for bootloader.
|
||||
"msr msp, r0\t\n" // Set the main stack pointer to the applications MSP.
|
||||
"ldr r0, [%0, #0x04]\t\n" // Load Reset handler into R0.
|
||||
|
||||
"movs r4, #0xFF\t\n" // Move ones to R4.
|
||||
"sxtb r4, r4\t\n" // Sign extend R4 to obtain 0xFFFFFFFF instead of 0xFF.
|
||||
|
||||
"mrs r5, IPSR\t\n" // Load IPSR to R5 to check for handler or thread mode.
|
||||
"cmp r5, #0x00\t\n" // Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
|
||||
"bne isr_abort\t\n" // If not zero we need to exit current ISR and jump to reset handler of bootloader.
|
||||
|
||||
"mov lr, r4\t\n" // Clear the link register and set to ones to ensure no return.
|
||||
"bx r0\t\n" // Branch to reset handler of bootloader.
|
||||
|
||||
"isr_abort: \t\n"
|
||||
|
||||
"mov r5, r4\t\n" // Fill with ones before jumping to reset handling. Will be popped as LR when exiting ISR. Ensures no return to application.
|
||||
"mov r6, r0\t\n" // Move address of reset handler to R6. Will be popped as PC when exiting ISR. Ensures the reset handler will be executed when exist ISR.
|
||||
"movs r7, #0x21\t\n" // Move MSB reset value of xPSR to R7. Will be popped as xPSR when exiting ISR. xPSR is 0x21000000 thus MSB is 0x21.
|
||||
"rev r7, r7\t\n" // Reverse byte order to put 0x21 as MSB.
|
||||
"push {r4-r7}\t\n" // Push everything to new stack to allow interrupt handler to fetch it on exiting the ISR.
|
||||
|
||||
"movs r4, #0x00\t\n" // Fill with zeros before jumping to reset handling. We be popped as R0 when exiting ISR (Cleaning up of the registers).
|
||||
"movs r5, #0x00\t\n" // Fill with zeros before jumping to reset handling. We be popped as R1 when exiting ISR (Cleaning up of the registers).
|
||||
"movs r6, #0x00\t\n" // Fill with zeros before jumping to reset handling. We be popped as R2 when exiting ISR (Cleaning up of the registers).
|
||||
"movs r7, #0x00\t\n" // Fill with zeros before jumping to reset handling. We be popped as R3 when exiting ISR (Cleaning up of the registers).
|
||||
"push {r4-r7}\t\n" // Push zeros (R4-R7) to stack to prepare for exiting the interrupt routine.
|
||||
|
||||
"movs r0, #0xF9\t\n" // Move the execution return command into register, 0xFFFFFFF9.
|
||||
"sxtb r0, r0\t\n" // Sign extend R0 to obtain 0xFFFFFFF9 instead of 0xF9.
|
||||
"bx r0\t\n" // No return - Handler mode will be exited. Stack will be popped and execution will continue in reset handler initializing other application.
|
||||
".align\t\n"
|
||||
:: "r" (start_addr) // Argument list for the gcc assembly. start_addr is %0.
|
||||
: "r0", "r4", "r5", "r6", "r7" // List of register maintained manually.
|
||||
);
|
||||
}
|
||||
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
static inline void nrf_bootloader_app_start_impl(uint32_t start_addr)
|
||||
{
|
||||
__ASM("ldr r5, [%0]\n" // Get App initial MSP for bootloader.
|
||||
"msr msp, r5\n" // Set the main stack pointer to the applications MSP.
|
||||
"ldr r0, [%0, #0x04]\n" // Load Reset handler into R0.
|
||||
|
||||
"movs r4, #0x00\n" // Load zero into R4.
|
||||
"mvns r4, r4\n" // Invert R4 to ensure it contain ones.
|
||||
|
||||
"mrs r5, IPSR\n" // Load IPSR to R5 to check for handler or thread mode
|
||||
"cmp r5, #0x00\n" // Compare, if 0 then we are in thread mode and can continue to reset handler of bootloader.
|
||||
"bne.n isr_abort\n" // If not zero we need to exit current ISR and jump to reset handler of bootloader.
|
||||
|
||||
"mov lr, r4\n" // Clear the link register and set to ones to ensure no return.
|
||||
"bx r0\n" // Branch to reset handler of bootloader.
|
||||
|
||||
"isr_abort: \n"
|
||||
// R4 contains ones from line above. We be popped as R12 when exiting ISR (Cleaning up the registers).
|
||||
"mov r5, r4\n" // Fill with ones before jumping to reset handling. Will be popped as LR when exiting ISR. Ensures no return to application.
|
||||
"mov r6, r0\n" // Move address of reset handler to R6. Will be popped as PC when exiting ISR. Ensures the reset handler will be executed when exist ISR.
|
||||
"movs r7, #0x21\n" // Move MSB reset value of xPSR to R7. Will be popped as xPSR when exiting ISR. xPSR is 0x21000000 thus MSB is 0x21.
|
||||
"rev r7, r7\n" // Reverse byte order to put 0x21 as MSB.
|
||||
"push {r4-r7}\n" // Push everything to new stack to allow interrupt handler to fetch it on exiting the ISR.
|
||||
|
||||
"movs r4, #0x00\n" // Fill with zeros before jumping to reset handling. We be popped as R0 when exiting ISR (Cleaning up of the registers).
|
||||
"movs r5, #0x00\n" // Fill with zeros before jumping to reset handling. We be popped as R1 when exiting ISR (Cleaning up of the registers).
|
||||
"movs r6, #0x00\n" // Fill with zeros before jumping to reset handling. We be popped as R2 when exiting ISR (Cleaning up of the registers).
|
||||
"movs r7, #0x00\n" // Fill with zeros before jumping to reset handling. We be popped as R3 when exiting ISR (Cleaning up of the registers).
|
||||
"push {r4-r7}\n" // Push zeros (R4-R7) to stack to prepare for exiting the interrupt routine.
|
||||
|
||||
"movs r0, #0x06\n" // Load 0x06 into R6 to prepare for exec return command.
|
||||
"mvns r0, r0\n" // Invert 0x06 to obtain EXEC_RETURN, 0xFFFFFFF9.
|
||||
"bx r0\n" // No return - Handler mode will be exited. Stack will be popped and execution will continue in reset handler initializing other application.
|
||||
:: "r" (start_addr) // Argument list for the IAR assembly. start_addr is %0.
|
||||
: "r0", "r4", "r5", "r6", "r7"); // List of register maintained manually.
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error Compiler not supported.
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void nrf_bootloader_app_start(uint32_t start_addr)
|
||||
{
|
||||
NRF_LOG_INFO("Running nrf_bootloader_app_start with address: 0x%08x\r\n", start_addr);
|
||||
|
||||
#ifdef BLE_STACK_SUPPORT_REQD
|
||||
uint32_t err_code;
|
||||
|
||||
//NRF_LOG_INFO("Initializing SD in mbr\r\n");
|
||||
err_code = nrf_dfu_mbr_init_sd();
|
||||
if(err_code != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Failed running nrf_dfu_mbr_init_sd\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Disable interrupts
|
||||
NRF_LOG_INFO("Disabling interrupts\r\n");
|
||||
|
||||
NVIC->ICER[0]=0xFFFFFFFF;
|
||||
#if defined(__NRF_NVIC_ISER_COUNT) && __NRF_NVIC_ISER_COUNT == 2
|
||||
NVIC->ICER[1]=0xFFFFFFFF;
|
||||
#endif
|
||||
|
||||
#ifdef BLE_STACK_SUPPORT_REQD
|
||||
// Set the sd softdevice vector table base address
|
||||
NRF_LOG_INFO("Setting SD vector table base: 0x%08x\r\n", start_addr);
|
||||
err_code = sd_softdevice_vector_table_base_set(start_addr);
|
||||
if(err_code != NRF_SUCCESS)
|
||||
{
|
||||
NRF_LOG_ERROR("Failed running sd_softdevice_vector_table_base_set\r\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Run application
|
||||
nrf_bootloader_app_start_impl(start_addr);
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_bootloader_app Application start
|
||||
* @{
|
||||
* @ingroup sdk_bootloader
|
||||
*/
|
||||
|
||||
#ifndef NRF_BOOTLOADER_APP_START_H__
|
||||
#define NRF_BOOTLOADER_APP_START_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**@brief Function for starting another application (and aborting the current one).
|
||||
*
|
||||
* @details This function uses the provided address to swap the stack pointer and then load
|
||||
* the address of the reset handler to be executed. It checks the current system mode
|
||||
* (thread/handler). If in thread mode, it resets into the other application.
|
||||
* If in handler mode, isr_abort is executed to ensure that handler mode is left correctly.
|
||||
* It then jumps into the reset handler of the other application.
|
||||
*
|
||||
* @note This function will never return, but issues a reset into the provided application.
|
||||
*
|
||||
* @param[in] start_addr Start address of the other application. This address must point to the
|
||||
initial stack pointer of the application.
|
||||
*
|
||||
*/
|
||||
void nrf_bootloader_app_start(uint32_t start_addr);
|
||||
|
||||
#endif // NRF_BOOTLOADER_APP_START_H__
|
||||
|
||||
/** @} */
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "nrf_bootloader_info.h"
|
||||
|
||||
|
||||
/** @brief This variable ensures that the linker script will write the bootloader start address
|
||||
* to the UICR register. This value will be written in the HEX file and thus written to
|
||||
* UICR when the bootloader is flashed into the chip.
|
||||
*/
|
||||
#if defined (__CC_ARM )
|
||||
#pragma push
|
||||
#pragma diag_suppress 1296
|
||||
uint32_t m_uicr_bootloader_start_address __attribute__((at(NRF_UICR_BOOTLOADER_START_ADDRESS)))
|
||||
= BOOTLOADER_START_ADDR;
|
||||
#pragma pop
|
||||
#elif defined ( __GNUC__ )
|
||||
volatile uint32_t m_uicr_bootloader_start_address __attribute__ ((section(".uicrBootStartAddress")))
|
||||
= BOOTLOADER_START_ADDR;
|
||||
#elif defined ( __ICCARM__ )
|
||||
__root const uint32_t m_uicr_bootloader_start_address @ NRF_UICR_BOOTLOADER_START_ADDRESS
|
||||
= BOOTLOADER_START_ADDR;
|
||||
#endif
|
|
@ -1,135 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 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 or object form under this license must not be reverse
|
||||
* engineered, decompiled, modified and/or disassembled.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**@file
|
||||
*
|
||||
* @defgroup sdk_bootloader_info Information
|
||||
* @{
|
||||
* @ingroup sdk_bootloader
|
||||
*/
|
||||
|
||||
#ifndef NRF_BOOTLOADER_INFO_H__
|
||||
#define NRF_BOOTLOADER_INFO_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nrf.h"
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
#include "nrf_sdm.h"
|
||||
#endif
|
||||
|
||||
/** @brief External definitions of symbols for the start of the application image.
|
||||
*/
|
||||
#if (__LINT__ == 1)
|
||||
// No implementation
|
||||
#elif defined ( __CC_ARM )
|
||||
extern uint32_t* Image$$ER_IROM1$$Base __attribute__((used));
|
||||
#elif defined ( __GNUC__ )
|
||||
extern uint32_t * __isr_vector;
|
||||
#elif defined ( __ICCARM__ )
|
||||
extern void * __vector_table;
|
||||
#else
|
||||
#error Not a valid compiler/linker for application image symbols.
|
||||
#endif
|
||||
|
||||
|
||||
/** @brief Macro for getting the start address of the application image.
|
||||
*
|
||||
* This macro is valid only when absolute placement is used for the application
|
||||
* image. The macro is not a compile time symbol. It cannot be used as a
|
||||
* constant expression, for example, inside a static assert or linker script
|
||||
* at-placement.
|
||||
*/
|
||||
#if (__LINT__ == 1)
|
||||
#define BOOTLOADER_START_ADDR (0x3AC00)
|
||||
#elif BOOTLOADER_START_ADDR
|
||||
// Bootloader start address is defined at project level
|
||||
#elif defined (__CC_ARM)
|
||||
#define BOOTLOADER_START_ADDR (uint32_t)&Image$$ER_IROM1$$Base
|
||||
#elif defined (__GNUC__)
|
||||
#define BOOTLOADER_START_ADDR (uint32_t)&__isr_vector
|
||||
#elif defined (__ICCARM__)
|
||||
#define BOOTLOADER_START_ADDR (uint32_t)&__vector_table
|
||||
#else
|
||||
#error Not a valid compiler/linker for BOOTLOADER_START_ADDR.
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Bootloader start address in UICR.
|
||||
*
|
||||
* Register location in UICR where the bootloader start address is stored.
|
||||
*
|
||||
* @note If the value at the given location is 0xFFFFFFFF, the bootloader address is not set.
|
||||
*/
|
||||
#define NRF_UICR_BOOTLOADER_START_ADDRESS (NRF_UICR_BASE + 0x14)
|
||||
|
||||
|
||||
#ifndef MAIN_APPLICATION_START_ADDR
|
||||
|
||||
|
||||
#ifdef SOFTDEVICE_PRESENT
|
||||
|
||||
/** @brief Main application start address (if the project uses a SoftDevice).
|
||||
*
|
||||
* @note The start address is equal to the end address of the SoftDevice.
|
||||
*/
|
||||
#define MAIN_APPLICATION_START_ADDR (SD_SIZE_GET(MBR_SIZE))
|
||||
|
||||
#else
|
||||
|
||||
/** @brief Main application start address if the project does not use a SoftDevice.
|
||||
*
|
||||
* @note The MBR is required for the @ref sdk_bootloader to function.
|
||||
*/
|
||||
#define MAIN_APPLICATION_START_ADDR (MBR_SIZE)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef MAIN_APPLICATION_START_ADDR
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // #ifndef NRF_BOOTLOADER_INFO_H__
|
||||
/** @} */
|
Loading…
Reference in New Issue