diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840/sdk/sdk_config.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840/sdk/sdk_config.h index ded519da30..253f879999 100644 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840/sdk/sdk_config.h +++ b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840/sdk/sdk_config.h @@ -2905,6 +2905,43 @@ #define CRC32_ENABLED 1 #endif +// FSTORAGE_ENABLED - fstorage - Flash storage module +//========================================================== +#ifndef FSTORAGE_ENABLED +#define FSTORAGE_ENABLED 1 +#endif +#if FSTORAGE_ENABLED +// FS_QUEUE_SIZE - Configures the size of the internal queue. +// Increase this if there are many users, or if it is likely that many +// operation will be queued at once without waiting for the previous operations +// to complete. In general, increase the queue size if you frequently receive +// @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 + +// FS_OP_MAX_RETRIES - Number attempts to execute an operation if the SoftDevice fails. +// Increase this value if events return the @ref FS_ERR_OPERATION_TIMEOUT +// 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 + +// FS_MAX_WRITE_SIZE_WORDS - Maximum number of words to be written to flash in a single operation. +// Tweaking this value can increase the chances of the SoftDevice being +// able to fit flash operations in between radio activity. This value is bound by the +// maximum number of words which the SoftDevice can write to flash in a single call to +// @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 +// + // ECC_ENABLED - ecc - Elliptic Curve Cryptography Library diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/ble_dfu/nrf_ble_dfu.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/ble_dfu/nrf_ble_dfu.c deleted file mode 100644 index 535bbc5bd7..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/ble_dfu/nrf_ble_dfu.c +++ /dev/null @@ -1,1037 +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_ble_dfu.h" - -#include -#include "sdk_common.h" -#include "nrf_dfu_req_handler.h" -#include "nrf_dfu_transport.h" -#include "nrf_dfu_mbr.h" -#include "nrf_bootloader_info.h" -#include "ble_conn_params.h" -#include "boards.h" -#include "nrf_log.h" -#include "ble_hci.h" -#include "app_timer.h" -#include "softdevice_handler_appsh.h" -#include "nrf_log.h" -#include "nrf_delay.h" - -#define ADVERTISING_LED_PIN_NO BSP_LED_0 /**< Is on when device is advertising. */ -#define CONNECTED_LED_PIN_NO BSP_LED_1 /**< Is on when device has connected. */ - -#define DEVICE_NAME "DfuTarg" /**< Name of device. Will be included in the advertising data. */ -#define MANUFACTURER_NAME "NordicSemiconductor" /**< Manufacturer. Will be passed to Device Information Service. */ - -#define MIN_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(15, UNIT_1_25_MS)) /**< Minimum acceptable connection interval. */ -#define MAX_CONN_INTERVAL_MS 30 /**< Maximum acceptable connection interval in milliseconds. */ -#define MAX_CONN_INTERVAL (uint16_t)(MSEC_TO_UNITS(MAX_CONN_INTERVAL_MS, UNIT_1_25_MS)) /**< Maximum acceptable connection interval . */ -#define SLAVE_LATENCY 0 /**< Slave latency. */ -#define CONN_SUP_TIMEOUT (4 * 100) /**< Connection supervisory timeout (4 seconds). */ - -#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */ - -#define FIRST_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(100, APP_TIMER_PRESCALER) /**< Time from the Connected event to first time sd_ble_gap_conn_param_update is called (100 milliseconds). */ -#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(500, APP_TIMER_PRESCALER) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (500 milliseconds). */ -#define MAX_CONN_PARAMS_UPDATE_COUNT 3 /**< Number of attempts before giving up the connection parameter negotiation. */ - -#define MAX_ADV_DATA_LENGTH 20 /**< Maximum length of advertising data. */ - -#define APP_ADV_INTERVAL MSEC_TO_UNITS(25, UNIT_0_625_MS) /**< The advertising interval (25 ms.). */ -#define APP_ADV_TIMEOUT_IN_SECONDS BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED /**< The advertising timeout in units of seconds. This is set to @ref BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED so that the advertisement is done as long as there there is a call to @ref dfu_transport_close function.*/ - -#define APP_FEATURE_NOT_SUPPORTED BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2 /**< Reply when unsupported features are requested. */ - -#define MAX_DFU_PKT_LEN (20) /**< Maximum length (in bytes) of the DFU Packet characteristic. */ -#define PKT_CREATE_PARAM_LEN (6) /**< Length (in bytes) of the parameters for Create Object request. */ -#define PKT_SET_PRN_PARAM_LEN (3) /**< Length (in bytes) of the parameters for Set Packet Receipt Notification request. */ -#define PKT_READ_OBJECT_INFO_PARAM_LEN (2) /**< Length (in bytes) of the parameters for Read Object Info request. */ -#define MAX_RESPONSE_LEN (15) /**< Maximum length (in bytes) of the response to a Control Point command. */ - - -#if (NRF_SD_BLE_API_VERSION <= 3) - #define NRF_BLE_MAX_MTU_SIZE GATT_MTU_SIZE_DEFAULT /**< MTU size used in the softdevice enabling and to reply to a BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event. */ -#else - #define NRF_BLE_MAX_MTU_SIZE BLE_GATT_MTU_SIZE_DEFAULT /**< MTU size used in the softdevice enabling and to reply to a BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST event. */ -#endif - - -static ble_dfu_t m_dfu; /**< Structure used to identify the Device Firmware Update service. */ -static uint16_t m_pkt_notif_target; /**< Number of packets of firmware data to be received before transmitting the next Packet Receipt Notification to the DFU Controller. */ -static uint16_t m_pkt_notif_target_cnt; /**< Number of packets of firmware data received after sending last Packet Receipt Notification or since the receipt of a @ref BLE_DFU_PKT_RCPT_NOTIF_ENABLED event from the DFU service, which ever occurs later.*/ -static uint16_t m_conn_handle = BLE_CONN_HANDLE_INVALID; /**< Handle of the current connection. */ - -#define DFU_BLE_FLAG_NONE (0) -#define DFU_BLE_FLAG_SERVICE_INITIALIZED (1 << 0) /**< Flag to check if the DFU service was initialized by the application.*/ -#define DFU_BLE_FLAG_IS_ADVERTISING (1 << 1) /**< Flag to indicate if advertising is ongoing.*/ -#define DFU_BLE_FLAG_TEAR_DOWN_IN_PROGRESS (1 << 2) /**< Flag to indicate whether a tear down is in progress. A tear down could be because the application has initiated it or the peer has disconnected. */ - -static uint32_t m_flags; - -static uint8_t m_notif_buffer[MAX_RESPONSE_LEN]; /**< Buffer used for sending notifications to peer. */ - -//lint -save -e545 -esym(526, dfu_trans) -esym(528, dfu_trans) -DFU_TRANSPORT_REGISTER(nrf_dfu_transport_t const dfu_trans) = -{ - .init_func = ble_dfu_transport_init, - .close_func = ble_dfu_transport_close -}; -//lint -restore - - -/**@brief Function for handling a Connection Parameters error. - * - * @param[in] nrf_error Error code. - */ -static void conn_params_error_handler(uint32_t nrf_error) -{ - APP_ERROR_HANDLER(nrf_error); -} - - -/**@brief Function for initializing the Connection Parameters module. - */ -static uint32_t conn_params_init(void) -{ - ble_conn_params_init_t cp_init = {0}; - - cp_init.first_conn_params_update_delay = FIRST_CONN_PARAMS_UPDATE_DELAY; - cp_init.next_conn_params_update_delay = NEXT_CONN_PARAMS_UPDATE_DELAY; - cp_init.max_conn_params_update_count = MAX_CONN_PARAMS_UPDATE_COUNT; - cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID; - cp_init.disconnect_on_fail = false; - cp_init.error_handler = conn_params_error_handler; - - return ble_conn_params_init(&cp_init); -} - - -/**@brief Function for the Advertising functionality initialization. - * - * @details Encodes the required advertising data and passes it to the stack. - * The advertising data encoded here is specific for DFU. - * Setting advertising data can by done by calling @ref ble_advdata_set. - */ -static uint32_t advertising_init(uint8_t adv_flags) -{ - uint32_t err_code; - uint16_t len_advdata = 9; - uint16_t max_device_name_length = MAX_ADV_DATA_LENGTH - len_advdata; - uint16_t actual_device_name_length = max_device_name_length; - - uint8_t p_encoded_advdata[MAX_ADV_DATA_LENGTH]; - - // Encode flags. - p_encoded_advdata[0] = 0x2; - p_encoded_advdata[1] = BLE_GAP_AD_TYPE_FLAGS; - p_encoded_advdata[2] = adv_flags; - - // Encode 'more available' uuid list. - p_encoded_advdata[3] = 0x3; - p_encoded_advdata[4] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE; - p_encoded_advdata[5] = LSB_16(BLE_DFU_SERVICE_UUID); - p_encoded_advdata[6] = MSB_16(BLE_DFU_SERVICE_UUID); - - // Get GAP device name and length - err_code = sd_ble_gap_device_name_get(&p_encoded_advdata[9], &actual_device_name_length); - if (err_code != NRF_SUCCESS) - { - return err_code; - } - - // Set GAP device in advertising data. - if (actual_device_name_length <= max_device_name_length) - { - p_encoded_advdata[7] = actual_device_name_length + 1; // (actual_length + ADV_AD_TYPE_FIELD_SIZE(1)) - p_encoded_advdata[8] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME; - len_advdata += actual_device_name_length; - } - else - { - // Must use a shorter advertising name than the actual name of the device - p_encoded_advdata[7] = max_device_name_length + 1; // (length + ADV_AD_TYPE_FIELD_SIZE(1)) - p_encoded_advdata[8] = BLE_GAP_AD_TYPE_SHORT_LOCAL_NAME; - len_advdata = MAX_ADV_DATA_LENGTH; - } - return sd_ble_gap_adv_data_set(p_encoded_advdata, len_advdata, NULL, 0); -} - - -/**@brief Function for starting advertising. - */ -static uint32_t advertising_start(void) -{ - uint32_t err_code; - ble_gap_adv_params_t adv_params; - - if ((m_flags & DFU_BLE_FLAG_IS_ADVERTISING) != 0) - { - return NRF_SUCCESS; - } - - // Initialize advertising parameters (used when starting advertising). - memset(&adv_params, 0, sizeof(adv_params)); - - err_code = advertising_init(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - VERIFY_SUCCESS(err_code); - - adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; - adv_params.p_peer_addr = NULL; - adv_params.fp = BLE_GAP_ADV_FP_ANY; - adv_params.interval = APP_ADV_INTERVAL; - adv_params.timeout = APP_ADV_TIMEOUT_IN_SECONDS; - - err_code = sd_ble_gap_adv_start(&adv_params); - VERIFY_SUCCESS(err_code); - - nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO); - nrf_gpio_pin_set(CONNECTED_LED_PIN_NO); - - m_flags |= DFU_BLE_FLAG_IS_ADVERTISING; - return NRF_SUCCESS; -} - - -/**@brief Function for stopping advertising. - */ -static uint32_t advertising_stop(void) -{ - uint32_t err_code; - - if ((m_flags & DFU_BLE_FLAG_IS_ADVERTISING) == 0) - { - return NRF_SUCCESS; - } - - err_code = sd_ble_gap_adv_stop(); - VERIFY_SUCCESS(err_code); - - nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO); - - m_flags |= DFU_BLE_FLAG_IS_ADVERTISING; - return NRF_SUCCESS; -} - - -static bool is_cccd_configured(ble_dfu_t * p_dfu) -{ - uint8_t cccd_val_buf[BLE_CCCD_VALUE_LEN]; - ble_gatts_value_t gatts_value = {0}; - - gatts_value.len = BLE_CCCD_VALUE_LEN; - gatts_value.p_value = cccd_val_buf; - - // Check the CCCD Value of DFU Control Point. - uint32_t err_code = sd_ble_gatts_value_get(m_conn_handle, - p_dfu->dfu_ctrl_pt_handles.cccd_handle, - &gatts_value); - VERIFY_SUCCESS(err_code); - - return ble_srv_is_notification_enabled(cccd_val_buf); -} - - -static uint32_t send_hvx(uint16_t conn_handle, uint16_t value_handle, uint16_t len) -{ - ble_gatts_hvx_params_t hvx_params = {0}; - - hvx_params.handle = value_handle; - hvx_params.type = BLE_GATT_HVX_NOTIFICATION; - hvx_params.p_len = &len; - hvx_params.p_data = m_notif_buffer; - - return sd_ble_gatts_hvx(conn_handle, &hvx_params); -} - - -static uint32_t response_send(ble_dfu_t * p_dfu, - uint8_t op_code, - nrf_dfu_res_code_t resp_val) -{ - uint16_t index = 0; - - NRF_LOG_INFO("Sending Response: [0x%01x, 0x%01x]\r\n", op_code, resp_val); - -#ifndef NRF51 - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } -#endif - - if ((m_conn_handle == BLE_CONN_HANDLE_INVALID) || (m_flags & DFU_BLE_FLAG_SERVICE_INITIALIZED) == 0) - { - return NRF_ERROR_INVALID_STATE; - } - - m_notif_buffer[index++] = BLE_DFU_OP_CODE_RESPONSE; - - // Encode the Request Op code - m_notif_buffer[index++] = op_code; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)resp_val; - - return send_hvx(m_conn_handle, p_dfu->dfu_ctrl_pt_handles.value_handle, index); -} - - -static uint32_t response_crc_cmd_send(ble_dfu_t * p_dfu, - uint32_t offset, - uint32_t crc) -{ - uint16_t index = 0; - - NRF_LOG_INFO("Sending CRC: [0x60, 0x03, 0x01, 0:x%08x, CRC:0x%08x]\r\n", offset, crc); - -#ifndef NRF51 - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } -#endif - - if ((m_conn_handle == BLE_CONN_HANDLE_INVALID) || (m_flags & DFU_BLE_FLAG_SERVICE_INITIALIZED) == 0) - { - return NRF_ERROR_INVALID_STATE; - } - - m_notif_buffer[index++] = BLE_DFU_OP_CODE_RESPONSE; - - // Encode the Request Op code - m_notif_buffer[index++] = BLE_DFU_OP_CODE_CALCULATE_CRC; - - // Encode the Response Value. - m_notif_buffer[index++] = (uint8_t)NRF_DFU_RES_CODE_SUCCESS; - - // Encode the Offset Value. - index += uint32_encode(offset, &m_notif_buffer[index]); - - // Encode the Crc Value. - index += uint32_encode(crc, &m_notif_buffer[index]); - - return send_hvx(m_conn_handle, p_dfu->dfu_ctrl_pt_handles.value_handle, index); -} - - -static uint32_t response_select_object_cmd_send(ble_dfu_t * p_dfu, - uint32_t max_size, - uint32_t offset, - uint32_t crc) -{ - uint16_t index = 0; - - NRF_LOG_INFO("Sending Object Info: [0x60, 0x06, 0x01 max: 0:x%08x 0:x%08x, CRC:0x%08x]\r\n", max_size, offset, crc); -#ifndef NRF51 - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } -#endif - - if ((m_conn_handle == BLE_CONN_HANDLE_INVALID) || (m_flags & DFU_BLE_FLAG_SERVICE_INITIALIZED) == 0) - { - return NRF_ERROR_INVALID_STATE; - } - - m_notif_buffer[index++] = BLE_DFU_OP_CODE_RESPONSE; - - // Encode the Request Op code - m_notif_buffer[index++] = BLE_DFU_OP_CODE_SELECT_OBJECT; - - // Encode the Success Response Value. - m_notif_buffer[index++] = (uint8_t)NRF_DFU_RES_CODE_SUCCESS; - - // Encode the Max Size Value. - index += uint32_encode(max_size, &m_notif_buffer[index]); - - // Encode the Offset Value. - index += uint32_encode(offset, &m_notif_buffer[index]); - - // Encode the Crc Value. - index += uint32_encode(crc, &m_notif_buffer[index]); - - return send_hvx(m_conn_handle, p_dfu->dfu_ctrl_pt_handles.value_handle, index); -} - - -/**@brief Function for handling a Write event on the Control Point characteristic. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_write_evt Pointer to the write event received from BLE stack. - * - * @return NRF_SUCCESS on successful processing of control point write. Otherwise an error code. - */ -static uint32_t on_ctrl_pt_write(ble_dfu_t * p_dfu, ble_gatts_evt_write_t * p_ble_write_evt) -{ - nrf_dfu_res_code_t res_code; - nrf_dfu_req_t dfu_req; - nrf_dfu_res_t dfu_res = {{{0}}}; - - memset(&dfu_req, 0, sizeof(nrf_dfu_req_t)); - - switch (p_ble_write_evt->data[0]) - { - case BLE_DFU_OP_CODE_CREATE_OBJECT: - - if (p_ble_write_evt->len != PKT_CREATE_PARAM_LEN) - { - return response_send(p_dfu, - BLE_DFU_OP_CODE_CREATE_OBJECT, - NRF_DFU_RES_CODE_INVALID_PARAMETER); - } - - NRF_LOG_INFO("Received create object\r\n"); - - // Reset the packet receipt notification on create object - m_pkt_notif_target_cnt = m_pkt_notif_target; - - // Get type parameter - //lint -save -e415 - dfu_req.obj_type = p_ble_write_evt->data[1]; - //lint -restore - - // Get length value - //lint -save -e416 - dfu_req.object_size = uint32_decode(&(p_ble_write_evt->data[2])); - //lint -restore - - // Set req type - dfu_req.req_type = NRF_DFU_OBJECT_OP_CREATE; - - res_code = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); - return response_send(p_dfu, BLE_DFU_OP_CODE_CREATE_OBJECT, res_code); - - case BLE_DFU_OP_CODE_EXECUTE_OBJECT: - NRF_LOG_INFO("Received execute object\r\n"); - - // Set req type - dfu_req.req_type = NRF_DFU_OBJECT_OP_EXECUTE; - - res_code = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); - return response_send(p_dfu, BLE_DFU_OP_CODE_EXECUTE_OBJECT, res_code); - - case BLE_DFU_OP_CODE_SET_RECEIPT_NOTIF: - NRF_LOG_INFO("Set receipt notif\r\n"); - if (p_ble_write_evt->len != PKT_SET_PRN_PARAM_LEN) - { - return (response_send(p_dfu, - BLE_DFU_OP_CODE_SET_RECEIPT_NOTIF, - NRF_DFU_RES_CODE_INVALID_PARAMETER)); - } - - //lint -save -e415 - m_pkt_notif_target = uint16_decode(&(p_ble_write_evt->data[1])); - //lint -restore - m_pkt_notif_target_cnt = m_pkt_notif_target; - - return response_send(p_dfu, BLE_DFU_OP_CODE_SET_RECEIPT_NOTIF, NRF_DFU_RES_CODE_SUCCESS); - - case BLE_DFU_OP_CODE_CALCULATE_CRC: - NRF_LOG_INFO("Received calculate CRC\r\n"); - - dfu_req.req_type = NRF_DFU_OBJECT_OP_CRC; - - res_code = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); - if (res_code == NRF_DFU_RES_CODE_SUCCESS) - { - return response_crc_cmd_send(p_dfu, dfu_res.offset, dfu_res.crc); - } - else - { - return response_send(p_dfu, BLE_DFU_OP_CODE_CALCULATE_CRC, res_code); - } - - case BLE_DFU_OP_CODE_SELECT_OBJECT: - - NRF_LOG_INFO("Received select object\r\n"); - if (p_ble_write_evt->len != PKT_READ_OBJECT_INFO_PARAM_LEN) - { - return response_send(p_dfu, - BLE_DFU_OP_CODE_SELECT_OBJECT, - NRF_DFU_RES_CODE_INVALID_PARAMETER); - } - - // Set object type to read info about - //lint -save -e415 - dfu_req.obj_type = p_ble_write_evt->data[1]; - //lint -restore - - dfu_req.req_type = NRF_DFU_OBJECT_OP_SELECT; - - res_code = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); - if (res_code == NRF_DFU_RES_CODE_SUCCESS) - { - return response_select_object_cmd_send(p_dfu, dfu_res.max_size, dfu_res.offset, dfu_res.crc); - } - else - { - return response_send(p_dfu, BLE_DFU_OP_CODE_SELECT_OBJECT, res_code); - } - - default: - NRF_LOG_INFO("Received unsupported OP code\r\n"); - // Unsupported op code. - return response_send(p_dfu, - p_ble_write_evt->data[0], - NRF_DFU_RES_CODE_INVALID_PARAMETER); - } -} - - -/**@brief Function for handling the @ref BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST event from the - * SoftDevice. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_evt Pointer to the event received from BLE stack. - */ -static bool on_rw_authorize_req(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - uint32_t err_code; - ble_gatts_rw_authorize_reply_params_t auth_reply = {0}; - ble_gatts_evt_rw_authorize_request_t * p_authorize_request; - ble_gatts_evt_write_t * p_ble_write_evt; - - p_authorize_request = &(p_ble_evt->evt.gatts_evt.params.authorize_request); - p_ble_write_evt = &(p_ble_evt->evt.gatts_evt.params.authorize_request.request.write); - - if ((p_authorize_request->type == BLE_GATTS_AUTHORIZE_TYPE_WRITE) && - (p_authorize_request->request.write.handle == p_dfu->dfu_ctrl_pt_handles.value_handle) && - (p_authorize_request->request.write.op != BLE_GATTS_OP_PREP_WRITE_REQ) && - (p_authorize_request->request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) && - (p_authorize_request->request.write.op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL) ) - { - auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE; - auth_reply.params.write.update = 1; - auth_reply.params.write.offset = p_ble_write_evt->offset; - auth_reply.params.write.len = p_ble_write_evt->len; - auth_reply.params.write.p_data = p_ble_write_evt->data; - - if (!is_cccd_configured(p_dfu)) - { - // Send an error response to the peer indicating that the CCCD is improperly configured. - auth_reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR; - - // Ignore response of auth reply - (void)sd_ble_gatts_rw_authorize_reply(m_conn_handle, &auth_reply); - return false; - } - - auth_reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS; - - err_code = sd_ble_gatts_rw_authorize_reply(m_conn_handle, &auth_reply); - return err_code == NRF_SUCCESS ? true: false; - } - else - { - return false; - } -} - - -/**@brief Function for handling the @ref BLE_GATTS_EVT_WRITE event from the SoftDevice. - * - * @param[in] p_dfu DFU Service Structure. - * @param[in] p_ble_evt Pointer to the event received from BLE stack. - */ -static void on_write(ble_dfu_t * p_dfu, ble_evt_t * p_ble_evt) -{ - if (p_ble_evt->evt.gatts_evt.params.write.handle == p_dfu->dfu_pkt_handles.value_handle) - { - nrf_dfu_res_code_t res_code; - nrf_dfu_req_t dfu_req; - nrf_dfu_res_t dfu_res = {{{0}}}; - - memset(&dfu_req, 0, sizeof(nrf_dfu_req_t)); - - // Set req type - dfu_req.req_type = NRF_DFU_OBJECT_OP_WRITE; - - // Set data and length - dfu_req.p_req = p_ble_evt->evt.gatts_evt.params.write.data; - dfu_req.req_len = p_ble_evt->evt.gatts_evt.params.write.len; - - res_code = nrf_dfu_req_handler_on_req(NULL, &dfu_req, &dfu_res); - if(res_code != NRF_DFU_RES_CODE_SUCCESS) - { - NRF_LOG_ERROR("Failure to run packet write\r\n"); - } - - // Check if a packet receipt notification is needed to be sent. - if (m_pkt_notif_target != 0 && --m_pkt_notif_target_cnt == 0) - { - (void)response_crc_cmd_send(p_dfu, dfu_res.offset, dfu_res.crc); - - // Reset the counter for the number of firmware packets. - m_pkt_notif_target_cnt = m_pkt_notif_target; - } - } -} - - -/**@brief Function for the Application's SoftDevice event handler. - * - * @param[in] p_ble_evt SoftDevice event. - */ -static void on_ble_evt(ble_evt_t * p_ble_evt) -{ - uint32_t err_code; - - switch (p_ble_evt->header.evt_id) - { - case BLE_GAP_EVT_CONNECTED: - nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO); - nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO); - - m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle; - m_flags &= ~DFU_BLE_FLAG_IS_ADVERTISING; - break; - - case BLE_GAP_EVT_DISCONNECTED: - // Restart advertising so that the DFU Controller can reconnect if possible. - err_code = advertising_start(); - APP_ERROR_CHECK(err_code); - - m_conn_handle = BLE_CONN_HANDLE_INVALID; - - break; - - case BLE_GAP_EVT_SEC_PARAMS_REQUEST: - { - err_code = sd_ble_gap_sec_params_reply(m_conn_handle, - BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, - NULL, - NULL); - APP_ERROR_CHECK(err_code); - } - break; - - case BLE_GATTS_EVT_TIMEOUT: - if (p_ble_evt->evt.gatts_evt.params.timeout.src == BLE_GATT_TIMEOUT_SRC_PROTOCOL) - { - err_code = sd_ble_gap_disconnect(m_conn_handle, - BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - APP_ERROR_CHECK(err_code); - } - break; - - case BLE_EVT_USER_MEM_REQUEST: - err_code = sd_ble_user_mem_reply(m_conn_handle, NULL); - APP_ERROR_CHECK(err_code); - break; - - case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST: - if (p_ble_evt->evt.gatts_evt.params.authorize_request.type - != BLE_GATTS_AUTHORIZE_TYPE_INVALID) - { - if (on_rw_authorize_req(&m_dfu, p_ble_evt)) - { - err_code = on_ctrl_pt_write(&m_dfu, - &(p_ble_evt->evt.gatts_evt.params.authorize_request.request.write)); -#ifdef NRF_DFU_DEBUG_VERSION - if (err_code != NRF_SUCCESS) - { - NRF_LOG_ERROR("Could not handle on_ctrl_pt_write. err_code: 0x%04x\r\n", err_code); - } -#else - // Swallow result - (void) err_code; -#endif - } - } - break; - - case BLE_GAP_EVT_SEC_INFO_REQUEST: - err_code = sd_ble_gap_sec_info_reply(p_ble_evt->evt.gap_evt.conn_handle, NULL, NULL, NULL); - APP_ERROR_CHECK(err_code); - break; - - case BLE_GATTS_EVT_SYS_ATTR_MISSING: - err_code = sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gap_evt.conn_handle, NULL, 0, 0); - APP_ERROR_CHECK(err_code); - break; - - case BLE_GATTS_EVT_WRITE: - on_write(&m_dfu, p_ble_evt); - break; - -#if (NRF_SD_BLE_API_VERSION >= 3) - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - err_code = sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle, - NRF_BLE_MAX_MTU_SIZE); - APP_ERROR_CHECK(err_code); - break; // BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST -#endif - - default: - // No implementation needed. - break; - } -} - - -/**@brief Function for dispatching a SoftDevice event. - * - * @details This function is called from the SoftDevice event interrupt handler after a - * SoftDevice event has been received. - * - * @param[in] p_ble_evt SoftDevice event. - */ -static void ble_evt_dispatch(ble_evt_t * p_ble_evt) -{ - ble_conn_params_on_ble_evt(p_ble_evt); - on_ble_evt(p_ble_evt); -} - - -/**@brief Function for the LEDs initialization. - * - * @details Initializes all LEDs used by this application. - */ -static void leds_init(void) -{ - nrf_gpio_cfg_output(ADVERTISING_LED_PIN_NO); - nrf_gpio_cfg_output(CONNECTED_LED_PIN_NO); - nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO); - nrf_gpio_pin_set(CONNECTED_LED_PIN_NO); -} - - -static uint32_t gap_address_change(void) -{ - uint32_t err_code; - ble_gap_addr_t addr; - -#if (NRF_SD_BLE_API_VERSION < 3) - err_code = sd_ble_gap_address_get(&addr); -#else - err_code = sd_ble_gap_addr_get(&addr); -#endif - - VERIFY_SUCCESS(err_code); - - // Increase the BLE address by one when advertising openly. - addr.addr[0] += 1; - -#if (NRF_SD_BLE_API_VERSION < 3) - err_code = sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr); -#else - err_code = sd_ble_gap_addr_set(&addr); -#endif - - VERIFY_SUCCESS(err_code); - - return NRF_SUCCESS; -} - - -/**@brief Function for the GAP initialization. - * - * @details This function will setup all the necessary GAP (Generic Access Profile) parameters of - * the device. It also sets the permissions and appearance. - */ -static uint32_t gap_params_init(void) -{ - uint32_t err_code; - ble_gap_conn_params_t gap_conn_params = {0}; - ble_gap_conn_sec_mode_t sec_mode; - - - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode); - - // This seems to not be implemented on Graviton - err_code = gap_address_change(); - VERIFY_SUCCESS(err_code); - - err_code = sd_ble_gap_device_name_set(&sec_mode, - (const uint8_t *)DEVICE_NAME, - strlen(DEVICE_NAME)); - - - VERIFY_SUCCESS(err_code); - - gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL; - gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL; - gap_conn_params.slave_latency = SLAVE_LATENCY; - gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT; - - err_code = sd_ble_gap_ppcp_set(&gap_conn_params); - return err_code; -} - - -static uint32_t ble_stack_init(bool init_softdevice) -{ - uint32_t err_code; - nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC; - - if (init_softdevice) - { - err_code = nrf_dfu_mbr_init_sd(); - VERIFY_SUCCESS(err_code); - } - - NRF_LOG_INFO("vector table: 0x%08x\r\n", BOOTLOADER_START_ADDR); - err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_START_ADDR); - VERIFY_SUCCESS(err_code); - NRF_LOG_INFO("vector table: 0x%08x\r\n", BOOTLOADER_START_ADDR); - - NRF_LOG_INFO("Error code - sd_softdevice_vector_table_base_set: 0x%08x\r\n", err_code); - //err_code = sd_softdevice_vector_table_base_set(BOOTLOADER_START_ADDR); - - NRF_LOG_INFO("Before SOFTDEVICE_HANDLER_APPSH_INIT\r\n"); - SOFTDEVICE_HANDLER_APPSH_INIT(&clock_lf_cfg, true); - NRF_LOG_INFO("After SOFTDEVICE_HANDLER_APPSH_INIT\r\n"); - - ble_enable_params_t ble_enable_params; - // Only one connection as a central is used when performing dfu. - err_code = softdevice_enable_get_default_config(1, 1, &ble_enable_params); - NRF_LOG_INFO("Error code - softdevice_enable_get_default_config: 0x%08x\r\n", err_code); - VERIFY_SUCCESS(err_code); - -#if (NRF_SD_BLE_API_VERSION >= 3) - ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE; -#endif - - NRF_LOG_INFO("Enabling softdevice.\r\n"); - // Enable BLE stack. - err_code = softdevice_enable(&ble_enable_params); - if (err_code != NRF_SUCCESS) - { - NRF_LOG_ERROR("Failed softdevice_enable: 0x%08x\r\n", err_code); - } - else - { - NRF_LOG_INFO("Softdevice enabled\r\n"); - } - - return err_code; -} - - -/**@brief Function for adding DFU Packet characteristic to the BLE Stack. - * - * @param[in] p_dfu DFU Service structure. - * - * @return NRF_SUCCESS on success. Otherwise an error code. - */ -static uint32_t dfu_pkt_char_add(ble_dfu_t * const p_dfu) -{ - ble_gatts_char_md_t char_md = {{0}}; - ble_gatts_attr_t attr_char_value = {0}; - ble_gatts_attr_md_t attr_md = {{0}}; - ble_uuid_t char_uuid; - - char_md.char_props.write_wo_resp = 1; - - char_uuid.type = p_dfu->uuid_type; - char_uuid.uuid = BLE_DFU_PKT_CHAR_UUID; - - BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); - - attr_md.vloc = BLE_GATTS_VLOC_STACK; - attr_md.vlen = 1; - - attr_char_value.p_uuid = &char_uuid; - attr_char_value.p_attr_md = &attr_md; - attr_char_value.max_len = MAX_DFU_PKT_LEN; - attr_char_value.p_value = NULL; - - return sd_ble_gatts_characteristic_add(p_dfu->service_handle, - &char_md, - &attr_char_value, - &p_dfu->dfu_pkt_handles); -} - - -/**@brief Function for adding DFU Control Point characteristic to the BLE Stack. - * - * @param[in] p_dfu DFU Service structure. - * - * @return NRF_SUCCESS on success. Otherwise an error code. - */ -static uint32_t dfu_ctrl_pt_add(ble_dfu_t * const p_dfu) -{ - ble_gatts_char_md_t char_md = {{0}}; - ble_gatts_attr_t attr_char_value = {0}; - ble_gatts_attr_md_t attr_md = {{0}}; - ble_uuid_t char_uuid; - - char_md.char_props.write = 1; - char_md.char_props.notify = 1; - - char_uuid.type = p_dfu->uuid_type; - char_uuid.uuid = BLE_DFU_CTRL_PT_UUID; - - BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&attr_md.read_perm); - BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm); - - attr_md.vloc = BLE_GATTS_VLOC_STACK; - attr_md.wr_auth = 1; - attr_md.vlen = 1; - - attr_char_value.p_uuid = &char_uuid; - attr_char_value.p_attr_md = &attr_md; - attr_char_value.max_len = BLE_L2CAP_MTU_DEF; - attr_char_value.p_value = NULL; - - return sd_ble_gatts_characteristic_add(p_dfu->service_handle, - &char_md, - &attr_char_value, - &p_dfu->dfu_ctrl_pt_handles); -} - - -/**@brief Function for checking if the CCCD of DFU Control point is configured for Notification. - * - * @details This function checks if the CCCD of DFU Control Point characteristic is configured - * for Notification by the DFU Controller. - * - * @param[in] p_dfu DFU Service structure. - * - * @return True if the CCCD of DFU Control Point characteristic is configured for Notification. - * False otherwise. - */ -uint32_t ble_dfu_init(ble_dfu_t * p_dfu) -{ - ble_uuid_t service_uuid; - uint32_t err_code; - -#ifndef NRF51 - if (p_dfu == NULL) - { - return NRF_ERROR_NULL; - } -#endif - - m_conn_handle = BLE_CONN_HANDLE_INVALID; - - BLE_UUID_BLE_ASSIGN(service_uuid, BLE_DFU_SERVICE_UUID); - - err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, - &service_uuid, - &(p_dfu->service_handle)); - VERIFY_SUCCESS(err_code); - - const ble_uuid128_t base_uuid128 = - { - { - 0x50, 0xEA, 0xDA, 0x30, 0x88, 0x83, 0xB8, 0x9F, - 0x60, 0x4F, 0x15, 0xF3, 0x00, 0x00, 0xC9, 0x8E - } - }; - err_code = sd_ble_uuid_vs_add(&base_uuid128, &p_dfu->uuid_type); - VERIFY_SUCCESS(err_code); - - err_code = dfu_pkt_char_add(p_dfu); - VERIFY_SUCCESS(err_code); - - err_code = dfu_ctrl_pt_add(p_dfu); - VERIFY_SUCCESS(err_code); - - m_flags |= DFU_BLE_FLAG_SERVICE_INITIALIZED; - - return NRF_SUCCESS; -} - - -uint32_t ble_dfu_transport_init(void) -{ - uint32_t err_code; - - m_flags &= ~DFU_BLE_FLAG_NONE; - - leds_init(); - - err_code = ble_stack_init(true); - VERIFY_SUCCESS(err_code); - - err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch); - VERIFY_SUCCESS(err_code); - - err_code = gap_params_init(); - VERIFY_SUCCESS(err_code); - - // Initialize the Device Firmware Update Service. - err_code = ble_dfu_init(&m_dfu); - VERIFY_SUCCESS(err_code); - - err_code = conn_params_init(); - VERIFY_SUCCESS(err_code); - - err_code = advertising_start(); - VERIFY_SUCCESS(err_code); - - return NRF_SUCCESS; -} - - -uint32_t ble_dfu_transport_close(void) -{ - uint32_t err_code = NRF_SUCCESS; - - if ((m_flags & DFU_BLE_FLAG_TEAR_DOWN_IN_PROGRESS) != 0) - { - return NRF_SUCCESS; - } - - m_flags |= DFU_BLE_FLAG_TEAR_DOWN_IN_PROGRESS; - - NRF_LOG_INFO("Waiting for buffers to be cleared before disconnect\r\n"); - nrf_delay_ms(MAX_CONN_INTERVAL_MS*4); - NRF_LOG_INFO("Disconnecting\r\n"); - - if (m_conn_handle != BLE_CONN_HANDLE_INVALID) - { - // Disconnect from peer. - err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION); - VERIFY_SUCCESS(err_code); - } - else if ((m_flags & DFU_BLE_FLAG_IS_ADVERTISING) != 0) - { - // If not connected, then the device will be advertising. Hence stop the advertising. - err_code = advertising_stop(); - VERIFY_SUCCESS(err_code); - } - - // Stop the timer, disregard the result. - (void)ble_conn_params_stop(); - return err_code; -} diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/ble_dfu/nrf_ble_dfu.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/ble_dfu/nrf_ble_dfu.h deleted file mode 100644 index 4882acfa2a..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/ble_dfu/nrf_ble_dfu.h +++ /dev/null @@ -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 Bluetooth 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 -#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__ - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu.c deleted file mode 100644 index 43a80a07a0..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu.c +++ /dev/null @@ -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; -} diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu.h deleted file mode 100644 index eb3bc9134b..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu.h +++ /dev/null @@ -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 -#include - -#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__ - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_mbr.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_mbr.c deleted file mode 100644 index 6871b8ac6c..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_mbr.c +++ /dev/null @@ -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; -} diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_mbr.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_mbr.h deleted file mode 100644 index 0d99e14e7d..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_mbr.h +++ /dev/null @@ -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 - -#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__ - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_settings.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_settings.c deleted file mode 100644 index f5661ebdfb..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_settings.c +++ /dev/null @@ -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 -#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; -} - diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_settings.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_settings.h deleted file mode 100644 index da9f1fb1f3..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_settings.h +++ /dev/null @@ -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 -#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__ - -/**@} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_utils.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_utils.c deleted file mode 100644 index 8892391567..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_utils.c +++ /dev/null @@ -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 -#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; -} - diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_utils.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_utils.h deleted file mode 100644 index a1d49dde77..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/dfu/nrf_dfu_utils.h +++ /dev/null @@ -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 -#include -#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__ - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader.c deleted file mode 100644 index 0144d960df..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader.c +++ /dev/null @@ -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; -} diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader.h deleted file mode 100644 index abfb3f7b7f..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader.h +++ /dev/null @@ -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 - -#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__ -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_app_start.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_app_start.c deleted file mode 100644 index e8b390ce5c..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_app_start.c +++ /dev/null @@ -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 -#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); -} - diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_app_start.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_app_start.h deleted file mode 100644 index 891d3c828b..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_app_start.h +++ /dev/null @@ -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 - -/**@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__ - -/** @} */ diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_info.c b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_info.c deleted file mode 100644 index 628e4e9f4e..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_info.c +++ /dev/null @@ -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 diff --git a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_info.h b/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_info.h deleted file mode 100644 index dd861fb12e..0000000000 --- a/targets/TARGET_NORDIC/TARGET_NRF5_SDK13/sdk/libraries/bootloader/nrf_bootloader_info.h +++ /dev/null @@ -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__ -/** @} */