Nordic stack and drivers for the mbed BLE API
Dependents: BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate writable_gatt ... more
TARGET_MCU_NRF51822/sdk/source/libraries/bootloader_dfu/dfu_types.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 32 | |
Vincent Coubard |
638:c90ae1400bf2 | 33 | /**@file |
Vincent Coubard |
638:c90ae1400bf2 | 34 | * |
Vincent Coubard |
638:c90ae1400bf2 | 35 | * @defgroup nrf_dfu_types Types and definitions. |
Vincent Coubard |
638:c90ae1400bf2 | 36 | * @{ |
Vincent Coubard |
638:c90ae1400bf2 | 37 | * |
Vincent Coubard |
638:c90ae1400bf2 | 38 | * @ingroup nrf_dfu |
Vincent Coubard |
638:c90ae1400bf2 | 39 | * |
Vincent Coubard |
638:c90ae1400bf2 | 40 | * @brief Device Firmware Update module type and definitions. |
Vincent Coubard |
638:c90ae1400bf2 | 41 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 42 | |
Vincent Coubard |
638:c90ae1400bf2 | 43 | #ifndef DFU_TYPES_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 44 | #define DFU_TYPES_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 45 | |
Vincent Coubard |
638:c90ae1400bf2 | 46 | #include <stdint.h> |
Vincent Coubard |
638:c90ae1400bf2 | 47 | #include "nrf_sdm.h" |
Vincent Coubard |
638:c90ae1400bf2 | 48 | #include "nrf.h" |
Vincent Coubard |
638:c90ae1400bf2 | 49 | #include "app_util.h" |
Vincent Coubard |
638:c90ae1400bf2 | 50 | |
Vincent Coubard |
638:c90ae1400bf2 | 51 | #define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */ |
Vincent Coubard |
638:c90ae1400bf2 | 52 | |
Vincent Coubard |
638:c90ae1400bf2 | 53 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 54 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 55 | |
Vincent Coubard |
638:c90ae1400bf2 | 56 | #ifdef NRF51 |
Vincent Coubard |
638:c90ae1400bf2 | 57 | #ifdef SIGNING |
Vincent Coubard |
638:c90ae1400bf2 | 58 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 59 | #define BOOTLOADER_SETTINGS_ADDRESS 0x0003D800 /**< The field specifies the page location of the bootloader settings address. */ |
Vincent Coubard |
638:c90ae1400bf2 | 60 | #else |
Vincent Coubard |
638:c90ae1400bf2 | 61 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 62 | #define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00 /**< The field specifies the page location of the bootloader settings address. */ |
Vincent Coubard |
638:c90ae1400bf2 | 63 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 64 | |
Vincent Coubard |
638:c90ae1400bf2 | 65 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 66 | #elif NRF52 |
Vincent Coubard |
638:c90ae1400bf2 | 67 | #define BOOTLOADER_REGION_START 0x0007B000 /**< 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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 68 | #define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */ |
Vincent Coubard |
638:c90ae1400bf2 | 69 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 70 | #else |
Vincent Coubard |
638:c90ae1400bf2 | 71 | #error No target defined |
Vincent Coubard |
638:c90ae1400bf2 | 72 | #endif |
Vincent Coubard |
638:c90ae1400bf2 | 73 | |
Vincent Coubard |
638:c90ae1400bf2 | 74 | #define DFU_REGION_TOTAL_SIZE (BOOTLOADER_REGION_START - CODE_REGION_1_START) /**< Total size of the region between SD and Bootloader. */ |
Vincent Coubard |
638:c90ae1400bf2 | 75 | |
Vincent Coubard |
638:c90ae1400bf2 | 76 | #define DFU_APP_DATA_RESERVED 0x0000 /**< 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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 77 | #define DFU_BANK_PADDING (DFU_APP_DATA_RESERVED % (2 * CODE_PAGE_SIZE)) /**< Padding to ensure that image size banked is always page sized. */ |
Vincent Coubard |
638:c90ae1400bf2 | 78 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 79 | #define DFU_IMAGE_MAX_SIZE_BANKED ((DFU_REGION_TOTAL_SIZE - \ |
Vincent Coubard |
638:c90ae1400bf2 | 80 | DFU_APP_DATA_RESERVED - \ |
Vincent Coubard |
638:c90ae1400bf2 | 81 | DFU_BANK_PADDING) / 2) /**< Maximum size of an application, excluding save data from the application. */ |
Vincent Coubard |
638:c90ae1400bf2 | 82 | |
Vincent Coubard |
638:c90ae1400bf2 | 83 | #define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_SETTINGS_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */ |
Vincent Coubard |
638:c90ae1400bf2 | 84 | |
Vincent Coubard |
638:c90ae1400bf2 | 85 | #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */ |
Vincent Coubard |
638:c90ae1400bf2 | 86 | #define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */ |
Vincent Coubard |
638:c90ae1400bf2 | 87 | |
Vincent Coubard |
638:c90ae1400bf2 | 88 | #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ |
Vincent Coubard |
638:c90ae1400bf2 | 89 | |
Vincent Coubard |
638:c90ae1400bf2 | 90 | #define INVALID_PACKET 0x00 /**< Invalid packet identifies. */ |
Vincent Coubard |
638:c90ae1400bf2 | 91 | #define INIT_PACKET 0x01 /**< Packet identifies for initialization packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 92 | #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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 93 | #define START_PACKET 0x03 /**< Packet identifies for the Data Start Packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 94 | #define DATA_PACKET 0x04 /**< Packet identifies for a Data Packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 95 | #define STOP_DATA_PACKET 0x05 /**< Packet identifies for the Data Stop Packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 96 | |
Vincent Coubard |
638:c90ae1400bf2 | 97 | #define DFU_UPDATE_SD 0x01 /**< Bit field indicating update of SoftDevice is ongoing. */ |
Vincent Coubard |
638:c90ae1400bf2 | 98 | #define DFU_UPDATE_BL 0x02 /**< Bit field indicating update of bootloader is ongoing. */ |
Vincent Coubard |
638:c90ae1400bf2 | 99 | #define DFU_UPDATE_APP 0x04 /**< Bit field indicating update of application is ongoing. */ |
Vincent Coubard |
638:c90ae1400bf2 | 100 | |
Vincent Coubard |
638:c90ae1400bf2 | 101 | #define DFU_INIT_RX 0x00 /**< Op Code identifies for receiving init packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 102 | #define DFU_INIT_COMPLETE 0x01 /**< Op Code identifies for transmission complete of init packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 103 | |
Vincent Coubard |
638:c90ae1400bf2 | 104 | // Safe guard to ensure during compile time that the DFU_APP_DATA_RESERVED is a multiple of page size. |
Vincent Coubard |
638:c90ae1400bf2 | 105 | STATIC_ASSERT((((DFU_APP_DATA_RESERVED) & (CODE_PAGE_SIZE - 1)) == 0x00)); |
Vincent Coubard |
638:c90ae1400bf2 | 106 | |
Vincent Coubard |
638:c90ae1400bf2 | 107 | /**@brief Structure holding a start packet containing update mode and image sizes. |
Vincent Coubard |
638:c90ae1400bf2 | 108 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 109 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 110 | { |
Vincent Coubard |
638:c90ae1400bf2 | 111 | uint8_t dfu_update_mode; /**< Packet type, used to identify the content of the received packet referenced by data packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 112 | uint32_t sd_image_size; /**< Size of the SoftDevice image to be transferred. Zero if no SoftDevice image will be transfered. */ |
Vincent Coubard |
638:c90ae1400bf2 | 113 | uint32_t bl_image_size; /**< Size of the Bootloader image to be transferred. Zero if no Bootloader image will be transfered. */ |
Vincent Coubard |
638:c90ae1400bf2 | 114 | uint32_t app_image_size; /**< Size of the application image to be transmitted. Zero if no Bootloader image will be transfered. */ |
Vincent Coubard |
638:c90ae1400bf2 | 115 | } dfu_start_packet_t; |
Vincent Coubard |
638:c90ae1400bf2 | 116 | |
Vincent Coubard |
638:c90ae1400bf2 | 117 | /**@brief Structure holding a bootloader init/data packet received. |
Vincent Coubard |
638:c90ae1400bf2 | 118 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 119 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 120 | { |
Vincent Coubard |
638:c90ae1400bf2 | 121 | uint32_t packet_length; /**< Packet length of the data packet. Each data is word size, meaning length of 4 is 4 words, not bytes. */ |
Vincent Coubard |
638:c90ae1400bf2 | 122 | uint32_t * p_data_packet; /**< Data Packet received. Each data is a word size entry. */ |
Vincent Coubard |
638:c90ae1400bf2 | 123 | } dfu_data_packet_t; |
Vincent Coubard |
638:c90ae1400bf2 | 124 | |
Vincent Coubard |
638:c90ae1400bf2 | 125 | /**@brief Structure for holding dfu update packet. Packet type indicate the type of packet. |
Vincent Coubard |
638:c90ae1400bf2 | 126 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 127 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 128 | { |
Vincent Coubard |
638:c90ae1400bf2 | 129 | uint32_t packet_type; /**< Packet type, used to identify the content of the received packet referenced by data packet. */ |
Vincent Coubard |
638:c90ae1400bf2 | 130 | union |
Vincent Coubard |
638:c90ae1400bf2 | 131 | { |
Vincent Coubard |
638:c90ae1400bf2 | 132 | dfu_data_packet_t data_packet; /**< Used when packet type is INIT_PACKET or DATA_PACKET. Packet contains data received for init or data. */ |
Vincent Coubard |
638:c90ae1400bf2 | 133 | 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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 134 | } params; |
Vincent Coubard |
638:c90ae1400bf2 | 135 | } dfu_update_packet_t; |
Vincent Coubard |
638:c90ae1400bf2 | 136 | |
Vincent Coubard |
638:c90ae1400bf2 | 137 | /**@brief DFU status error codes. |
Vincent Coubard |
638:c90ae1400bf2 | 138 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 139 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 140 | { |
Vincent Coubard |
638:c90ae1400bf2 | 141 | DFU_UPDATE_APP_COMPLETE, /**< Status update of application complete.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 142 | 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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 143 | 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. */ |
Vincent Coubard |
638:c90ae1400bf2 | 144 | DFU_UPDATE_BOOT_COMPLETE, /**< Status update complete.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 145 | DFU_BANK_0_ERASED, /**< Status bank 0 erased.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 146 | DFU_TIMEOUT, /**< Status timeout.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 147 | DFU_RESET /**< Status Reset to indicate current update procedure has been aborted and system should reset. */ |
Vincent Coubard |
638:c90ae1400bf2 | 148 | } dfu_update_status_code_t; |
Vincent Coubard |
638:c90ae1400bf2 | 149 | |
Vincent Coubard |
638:c90ae1400bf2 | 150 | /**@brief Structure holding DFU complete event. |
Vincent Coubard |
638:c90ae1400bf2 | 151 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 152 | typedef struct |
Vincent Coubard |
638:c90ae1400bf2 | 153 | { |
Vincent Coubard |
638:c90ae1400bf2 | 154 | dfu_update_status_code_t status_code; /**< Device Firmware Update status. */ |
Vincent Coubard |
638:c90ae1400bf2 | 155 | uint16_t app_crc; /**< CRC of the recieved application. */ |
Vincent Coubard |
638:c90ae1400bf2 | 156 | uint32_t sd_size; /**< Size of the recieved SoftDevice. */ |
Vincent Coubard |
638:c90ae1400bf2 | 157 | uint32_t bl_size; /**< Size of the recieved BootLoader. */ |
Vincent Coubard |
638:c90ae1400bf2 | 158 | uint32_t app_size; /**< Size of the recieved Application. */ |
Vincent Coubard |
638:c90ae1400bf2 | 159 | uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */ |
Vincent Coubard |
638:c90ae1400bf2 | 160 | } dfu_update_status_t; |
Vincent Coubard |
638:c90ae1400bf2 | 161 | |
Vincent Coubard |
638:c90ae1400bf2 | 162 | /**@brief Update complete handler type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 163 | typedef void (*dfu_complete_handler_t)(dfu_update_status_t dfu_update_status); |
Vincent Coubard |
638:c90ae1400bf2 | 164 | |
Vincent Coubard |
638:c90ae1400bf2 | 165 | #endif // DFU_TYPES_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 166 | |
Vincent Coubard |
638:c90ae1400bf2 | 167 | /**@} */ |