The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_NRF51_DONGLE/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/bootloader_dfu/dfu_types.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 148:fd96258d940d 1 /*
Kojto 148:fd96258d940d 2 * Copyright (c) 2013 Nordic Semiconductor ASA
Kojto 148:fd96258d940d 3 * All rights reserved.
Kojto 148:fd96258d940d 4 *
Kojto 148:fd96258d940d 5 * Redistribution and use in source and binary forms, with or without modification,
Kojto 148:fd96258d940d 6 * are permitted provided that the following conditions are met:
Kojto 148:fd96258d940d 7 *
Kojto 148:fd96258d940d 8 * 1. Redistributions of source code must retain the above copyright notice, this list
Kojto 148:fd96258d940d 9 * of conditions and the following disclaimer.
Kojto 148:fd96258d940d 10 *
Kojto 148:fd96258d940d 11 * 2. Redistributions in binary form, except as embedded into a Nordic Semiconductor ASA
Kojto 148:fd96258d940d 12 * integrated circuit in a product or a software update for such product, must reproduce
Kojto 148:fd96258d940d 13 * the above copyright notice, this list of conditions and the following disclaimer in
Kojto 148:fd96258d940d 14 * the documentation and/or other materials provided with the distribution.
Kojto 148:fd96258d940d 15 *
Kojto 148:fd96258d940d 16 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its contributors may be
Kojto 148:fd96258d940d 17 * used to endorse or promote products derived from this software without specific prior
Kojto 148:fd96258d940d 18 * written permission.
Kojto 148:fd96258d940d 19 *
Kojto 148:fd96258d940d 20 * 4. This software, with or without modification, must only be used with a
Kojto 148:fd96258d940d 21 * Nordic Semiconductor ASA integrated circuit.
Kojto 148:fd96258d940d 22 *
Kojto 148:fd96258d940d 23 * 5. Any software provided in binary or object form under this license must not be reverse
Kojto 148:fd96258d940d 24 * engineered, decompiled, modified and/or disassembled.
Kojto 148:fd96258d940d 25 *
Kojto 148:fd96258d940d 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 148:fd96258d940d 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 148:fd96258d940d 28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 148:fd96258d940d 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 148:fd96258d940d 30 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 148:fd96258d940d 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 148:fd96258d940d 32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 148:fd96258d940d 33 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 148:fd96258d940d 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 148:fd96258d940d 35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 148:fd96258d940d 36 *
Kojto 148:fd96258d940d 37 */
Kojto 148:fd96258d940d 38
Kojto 148:fd96258d940d 39
Kojto 148:fd96258d940d 40 /**@file
Kojto 148:fd96258d940d 41 *
Kojto 148:fd96258d940d 42 * @defgroup nrf_dfu_types Types and definitions.
Kojto 148:fd96258d940d 43 * @{
Kojto 148:fd96258d940d 44 *
Kojto 148:fd96258d940d 45 * @ingroup nrf_dfu
Kojto 148:fd96258d940d 46 *
Kojto 148:fd96258d940d 47 * @brief Device Firmware Update module type and definitions.
Kojto 148:fd96258d940d 48 */
Kojto 148:fd96258d940d 49
Kojto 148:fd96258d940d 50 #ifndef DFU_TYPES_H__
Kojto 148:fd96258d940d 51 #define DFU_TYPES_H__
Kojto 148:fd96258d940d 52
Kojto 148:fd96258d940d 53 #include <stdint.h>
Kojto 148:fd96258d940d 54 #include "nrf_sdm.h"
Kojto 148:fd96258d940d 55 #include "nrf_mbr.h"
Kojto 148:fd96258d940d 56 #include "nrf.h"
Kojto 148:fd96258d940d 57 #include "app_util.h"
Kojto 148:fd96258d940d 58
Kojto 148:fd96258d940d 59 #define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */
Kojto 148:fd96258d940d 60
Kojto 148:fd96258d940d 61 #if defined(NRF52)
Kojto 148:fd96258d940d 62 #define NRF_UICR_MBR_PARAMS_PAGE_ADDRESS (NRF_UICR_BASE + 0x18) /**< Register where the mbr params page is stored in the UICR register. (Only in use in nRF52 MBR).*/
Kojto 148:fd96258d940d 63 #endif
Kojto 148:fd96258d940d 64
Kojto 148:fd96258d940d 65 #define CODE_REGION_1_START SD_SIZE_GET(MBR_SIZE) /**< This field should correspond to the size of Code Region 0, (which is identical to Start of Code Region 1), found in UICR.CLEN0 register. This value is used for compile safety, as the linker will fail if application expands into bootloader. Runtime, the bootloader will use the value found in UICR.CLEN0. */
Kojto 148:fd96258d940d 66 #define SOFTDEVICE_REGION_START MBR_SIZE /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
Kojto 148:fd96258d940d 67
Kojto 148:fd96258d940d 68 #ifdef NRF51
Kojto 148:fd96258d940d 69
Kojto 148:fd96258d940d 70 #define CODE_PAGE_SIZE 0x0400 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
Kojto 148:fd96258d940d 71
Kojto 148:fd96258d940d 72 #ifdef SIGNING
Kojto 148:fd96258d940d 73
Kojto 148:fd96258d940d 74 #define BOOTLOADER_REGION_START 0x00039C00 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
Kojto 148:fd96258d940d 75 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003D800 /**< The field specifies the page location of the bootloader settings address. */
Kojto 148:fd96258d940d 76
Kojto 148:fd96258d940d 77 #else
Kojto 148:fd96258d940d 78
Kojto 148:fd96258d940d 79 #define BOOTLOADER_REGION_START 0x0003C000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
Kojto 148:fd96258d940d 80 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00 /**< The field specifies the page location of the bootloader settings address. */
Kojto 148:fd96258d940d 81
Kojto 148:fd96258d940d 82 #endif
Kojto 148:fd96258d940d 83
Kojto 148:fd96258d940d 84
Kojto 148:fd96258d940d 85
Kojto 148:fd96258d940d 86 #elif NRF52
Kojto 148:fd96258d940d 87
Kojto 148:fd96258d940d 88 #define BOOTLOADER_REGION_START 0x0007A000 /**< This field should correspond to start address of the bootloader, found in UICR.RESERVED, 0x10001014, register. This value is used for sanity check, so the bootloader will fail immediately if this value differs from runtime value. The value is used to determine max application size for updating. */
Kojto 148:fd96258d940d 89 #define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */
Kojto 148:fd96258d940d 90 #define BOOTLOADER_MBR_PARAMS_PAGE_ADDRESS 0x0007E000 /**< The field specifies the page location of the mbr params page address. */
Kojto 148:fd96258d940d 91
Kojto 148:fd96258d940d 92 #define CODE_PAGE_SIZE 0x1000 /**< Size of a flash codepage. Used for size of the reserved flash space in the bootloader region. Will be runtime checked against NRF_UICR->CODEPAGESIZE to ensure the region is correct. */
Kojto 148:fd96258d940d 93
Kojto 148:fd96258d940d 94 #else
Kojto 148:fd96258d940d 95
Kojto 148:fd96258d940d 96 #error No target defined
Kojto 148:fd96258d940d 97
Kojto 148:fd96258d940d 98 #endif
Kojto 148:fd96258d940d 99
Kojto 148:fd96258d940d 100 #define DFU_REGION_TOTAL_SIZE (BOOTLOADER_REGION_START - CODE_REGION_1_START) /**< Total size of the region between SD and Bootloader. */
Kojto 148:fd96258d940d 101
Kojto 148:fd96258d940d 102 #ifndef DFU_APP_DATA_RESERVED
Kojto 148:fd96258d940d 103 #define DFU_APP_DATA_RESERVED CODE_PAGE_SIZE * 0 /**< Size of Application Data that must be preserved between application updates. This value must be a multiple of page size. Page size is 0x400 (1024d) bytes, thus this value must be 0x0000, 0x0400, 0x0800, 0x0C00, 0x1000, etc. */
Kojto 148:fd96258d940d 104 #endif
Kojto 148:fd96258d940d 105
Kojto 148:fd96258d940d 106 #define DFU_IMAGE_MAX_SIZE_FULL (DFU_REGION_TOTAL_SIZE - DFU_APP_DATA_RESERVED) /**< Maximum size of an application, excluding save data from the application. */
Kojto 148:fd96258d940d 107
Kojto 148:fd96258d940d 108 #define DFU_IMAGE_MAX_SIZE_BANKED (((DFU_IMAGE_MAX_SIZE_FULL) - \
Kojto 148:fd96258d940d 109 (DFU_IMAGE_MAX_SIZE_FULL % (2 * CODE_PAGE_SIZE)))/2) /**< Maximum size of an application, excluding save data from the application. */
Kojto 148:fd96258d940d 110
Kojto 148:fd96258d940d 111 #define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_SETTINGS_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */
Kojto 148:fd96258d940d 112
Kojto 148:fd96258d940d 113 #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */
Kojto 148:fd96258d940d 114 #define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */
Kojto 148:fd96258d940d 115
Kojto 148:fd96258d940d 116 #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */
Kojto 148:fd96258d940d 117
Kojto 148:fd96258d940d 118 #define INVALID_PACKET 0x00 /**< Invalid packet identifies. */
Kojto 148:fd96258d940d 119 #define INIT_PACKET 0x01 /**< Packet identifies for initialization packet. */
Kojto 148:fd96258d940d 120 #define STOP_INIT_PACKET 0x02 /**< Packet identifies for stop initialization packet. Used when complete init packet has been received so that the init packet can be used for pre validaiton. */
Kojto 148:fd96258d940d 121 #define START_PACKET 0x03 /**< Packet identifies for the Data Start Packet. */
Kojto 148:fd96258d940d 122 #define DATA_PACKET 0x04 /**< Packet identifies for a Data Packet. */
Kojto 148:fd96258d940d 123 #define STOP_DATA_PACKET 0x05 /**< Packet identifies for the Data Stop Packet. */
Kojto 148:fd96258d940d 124
Kojto 148:fd96258d940d 125 #define DFU_UPDATE_SD 0x01 /**< Bit field indicating update of SoftDevice is ongoing. */
Kojto 148:fd96258d940d 126 #define DFU_UPDATE_BL 0x02 /**< Bit field indicating update of bootloader is ongoing. */
Kojto 148:fd96258d940d 127 #define DFU_UPDATE_APP 0x04 /**< Bit field indicating update of application is ongoing. */
Kojto 148:fd96258d940d 128
Kojto 148:fd96258d940d 129 #define DFU_INIT_RX 0x00 /**< Op Code identifies for receiving init packet. */
Kojto 148:fd96258d940d 130 #define DFU_INIT_COMPLETE 0x01 /**< Op Code identifies for transmission complete of init packet. */
Kojto 148:fd96258d940d 131
Kojto 148:fd96258d940d 132 // Safe guard to ensure during compile time that the DFU_APP_DATA_RESERVED is a multiple of page size.
Kojto 148:fd96258d940d 133 STATIC_ASSERT((((DFU_APP_DATA_RESERVED) & (CODE_PAGE_SIZE - 1)) == 0x00));
Kojto 148:fd96258d940d 134
Kojto 148:fd96258d940d 135 /**@brief Structure holding a start packet containing update mode and image sizes.
Kojto 148:fd96258d940d 136 */
Kojto 148:fd96258d940d 137 typedef struct
Kojto 148:fd96258d940d 138 {
Kojto 148:fd96258d940d 139 uint8_t dfu_update_mode; /**< Packet type, used to identify the content of the received packet referenced by data packet. */
Kojto 148:fd96258d940d 140 uint32_t sd_image_size; /**< Size of the SoftDevice image to be transferred. Zero if no SoftDevice image will be transfered. */
Kojto 148:fd96258d940d 141 uint32_t bl_image_size; /**< Size of the Bootloader image to be transferred. Zero if no Bootloader image will be transfered. */
Kojto 148:fd96258d940d 142 uint32_t app_image_size; /**< Size of the application image to be transmitted. Zero if no Bootloader image will be transfered. */
Kojto 148:fd96258d940d 143 } dfu_start_packet_t;
Kojto 148:fd96258d940d 144
Kojto 148:fd96258d940d 145 /**@brief Structure holding a bootloader init/data packet received.
Kojto 148:fd96258d940d 146 */
Kojto 148:fd96258d940d 147 typedef struct
Kojto 148:fd96258d940d 148 {
Kojto 148:fd96258d940d 149 uint32_t packet_length; /**< Packet length of the data packet. Each data is word size, meaning length of 4 is 4 words, not bytes. */
Kojto 148:fd96258d940d 150 uint32_t * p_data_packet; /**< Data Packet received. Each data is a word size entry. */
Kojto 148:fd96258d940d 151 } dfu_data_packet_t;
Kojto 148:fd96258d940d 152
Kojto 148:fd96258d940d 153 /**@brief Structure for holding dfu update packet. Packet type indicate the type of packet.
Kojto 148:fd96258d940d 154 */
Kojto 148:fd96258d940d 155 typedef struct
Kojto 148:fd96258d940d 156 {
Kojto 148:fd96258d940d 157 uint32_t packet_type; /**< Packet type, used to identify the content of the received packet referenced by data packet. */
Kojto 148:fd96258d940d 158 union
Kojto 148:fd96258d940d 159 {
Kojto 148:fd96258d940d 160 dfu_data_packet_t data_packet; /**< Used when packet type is INIT_PACKET or DATA_PACKET. Packet contains data received for init or data. */
Kojto 148:fd96258d940d 161 dfu_start_packet_t * start_packet; /**< Used when packet type is START_DATA_PACKET. Will contain information on software to be updtaed, i.e. SoftDevice, Bootloader and/or Application along with image sizes. */
Kojto 148:fd96258d940d 162 } params;
Kojto 148:fd96258d940d 163 } dfu_update_packet_t;
Kojto 148:fd96258d940d 164
Kojto 148:fd96258d940d 165 /**@brief DFU status error codes.
Kojto 148:fd96258d940d 166 */
Kojto 148:fd96258d940d 167 typedef enum
Kojto 148:fd96258d940d 168 {
Kojto 148:fd96258d940d 169 DFU_UPDATE_APP_COMPLETE, /**< Status update of application complete.*/
Kojto 148:fd96258d940d 170 DFU_UPDATE_SD_COMPLETE, /**< Status update of SoftDevice update complete. Note that this solely indicates that a new SoftDevice has been received and stored in bank 0 and 1. */
Kojto 148:fd96258d940d 171 DFU_UPDATE_SD_SWAPPED, /**< Status update of SoftDevice update complete. Note that this solely indicates that a new SoftDevice has been received and stored in bank 0 and 1. */
Kojto 148:fd96258d940d 172 DFU_UPDATE_BOOT_COMPLETE, /**< Status update complete.*/
Kojto 148:fd96258d940d 173 DFU_BANK_0_ERASED, /**< Status bank 0 erased.*/
Kojto 148:fd96258d940d 174 DFU_TIMEOUT, /**< Status timeout.*/
Kojto 148:fd96258d940d 175 DFU_RESET /**< Status Reset to indicate current update procedure has been aborted and system should reset. */
Kojto 148:fd96258d940d 176 } dfu_update_status_code_t;
Kojto 148:fd96258d940d 177
Kojto 148:fd96258d940d 178 /**@brief Structure holding DFU complete event.
Kojto 148:fd96258d940d 179 */
Kojto 148:fd96258d940d 180 typedef struct
Kojto 148:fd96258d940d 181 {
Kojto 148:fd96258d940d 182 dfu_update_status_code_t status_code; /**< Device Firmware Update status. */
Kojto 148:fd96258d940d 183 uint16_t app_crc; /**< CRC of the recieved application. */
Kojto 148:fd96258d940d 184 uint32_t sd_size; /**< Size of the recieved SoftDevice. */
Kojto 148:fd96258d940d 185 uint32_t bl_size; /**< Size of the recieved BootLoader. */
Kojto 148:fd96258d940d 186 uint32_t app_size; /**< Size of the recieved Application. */
Kojto 148:fd96258d940d 187 uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */
Kojto 148:fd96258d940d 188 } dfu_update_status_t;
Kojto 148:fd96258d940d 189
Kojto 148:fd96258d940d 190 /**@brief Update complete handler type. */
Kojto 148:fd96258d940d 191 typedef void (*dfu_complete_handler_t)(dfu_update_status_t dfu_update_status);
Kojto 148:fd96258d940d 192
Kojto 148:fd96258d940d 193 #endif // DFU_TYPES_H__
Kojto 148:fd96258d940d 194
Kojto 148:fd96258d940d 195 /**@} */