updates
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
dfu_types.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 /**@file 00034 * 00035 * @defgroup nrf_dfu_types Types and definitions. 00036 * @{ 00037 * 00038 * @ingroup nrf_dfu 00039 * 00040 * @brief Device Firmware Update module type and definitions. 00041 */ 00042 00043 #ifndef DFU_TYPES_H__ 00044 #define DFU_TYPES_H__ 00045 00046 #include <stdint.h> 00047 #include "nrf_sdm.h" 00048 #include "nrf.h" 00049 #include "app_util.h " 00050 00051 #define NRF_UICR_BOOT_START_ADDRESS (NRF_UICR_BASE + 0x14) /**< Register where the bootloader start address is stored in the UICR register. */ 00052 00053 #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. */ 00054 #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. */ 00055 00056 #ifdef NRF51 00057 #ifdef SIGNING 00058 #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. */ 00059 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003D800 /**< The field specifies the page location of the bootloader settings address. */ 00060 #else 00061 #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. */ 00062 #define BOOTLOADER_SETTINGS_ADDRESS 0x0003FC00 /**< The field specifies the page location of the bootloader settings address. */ 00063 #endif 00064 00065 #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. */ 00066 #elif NRF52 00067 #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. */ 00068 #define BOOTLOADER_SETTINGS_ADDRESS 0x0007F000 /**< The field specifies the page location of the bootloader settings address. */ 00069 #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. */ 00070 #else 00071 #error No target defined 00072 #endif 00073 00074 #define DFU_REGION_TOTAL_SIZE (BOOTLOADER_REGION_START - CODE_REGION_1_START) /**< Total size of the region between SD and Bootloader. */ 00075 00076 #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. */ 00077 #define DFU_BANK_PADDING (DFU_APP_DATA_RESERVED % (2 * CODE_PAGE_SIZE)) /**< Padding to ensure that image size banked is always page sized. */ 00078 #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. */ 00079 #define DFU_IMAGE_MAX_SIZE_BANKED ((DFU_REGION_TOTAL_SIZE - \ 00080 DFU_APP_DATA_RESERVED - \ 00081 DFU_BANK_PADDING) / 2) /**< Maximum size of an application, excluding save data from the application. */ 00082 00083 #define DFU_BL_IMAGE_MAX_SIZE (BOOTLOADER_SETTINGS_ADDRESS - BOOTLOADER_REGION_START) /**< Maximum size of a bootloader, excluding save data from the current bootloader. */ 00084 00085 #define DFU_BANK_0_REGION_START CODE_REGION_1_START /**< Bank 0 region start. */ 00086 #define DFU_BANK_1_REGION_START (DFU_BANK_0_REGION_START + DFU_IMAGE_MAX_SIZE_BANKED) /**< Bank 1 region start. */ 00087 00088 #define EMPTY_FLASH_MASK 0xFFFFFFFF /**< Bit mask that defines an empty address in flash. */ 00089 00090 #define INVALID_PACKET 0x00 /**< Invalid packet identifies. */ 00091 #define INIT_PACKET 0x01 /**< Packet identifies for initialization packet. */ 00092 #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. */ 00093 #define START_PACKET 0x03 /**< Packet identifies for the Data Start Packet. */ 00094 #define DATA_PACKET 0x04 /**< Packet identifies for a Data Packet. */ 00095 #define STOP_DATA_PACKET 0x05 /**< Packet identifies for the Data Stop Packet. */ 00096 00097 #define DFU_UPDATE_SD 0x01 /**< Bit field indicating update of SoftDevice is ongoing. */ 00098 #define DFU_UPDATE_BL 0x02 /**< Bit field indicating update of bootloader is ongoing. */ 00099 #define DFU_UPDATE_APP 0x04 /**< Bit field indicating update of application is ongoing. */ 00100 00101 #define DFU_INIT_RX 0x00 /**< Op Code identifies for receiving init packet. */ 00102 #define DFU_INIT_COMPLETE 0x01 /**< Op Code identifies for transmission complete of init packet. */ 00103 00104 // Safe guard to ensure during compile time that the DFU_APP_DATA_RESERVED is a multiple of page size. 00105 STATIC_ASSERT((((DFU_APP_DATA_RESERVED) & (CODE_PAGE_SIZE - 1)) == 0x00)); 00106 00107 /**@brief Structure holding a start packet containing update mode and image sizes. 00108 */ 00109 typedef struct 00110 { 00111 uint8_t dfu_update_mode; /**< Packet type, used to identify the content of the received packet referenced by data packet. */ 00112 uint32_t sd_image_size; /**< Size of the SoftDevice image to be transferred. Zero if no SoftDevice image will be transfered. */ 00113 uint32_t bl_image_size; /**< Size of the Bootloader image to be transferred. Zero if no Bootloader image will be transfered. */ 00114 uint32_t app_image_size; /**< Size of the application image to be transmitted. Zero if no Bootloader image will be transfered. */ 00115 } dfu_start_packet_t; 00116 00117 /**@brief Structure holding a bootloader init/data packet received. 00118 */ 00119 typedef struct 00120 { 00121 uint32_t packet_length; /**< Packet length of the data packet. Each data is word size, meaning length of 4 is 4 words, not bytes. */ 00122 uint32_t * p_data_packet; /**< Data Packet received. Each data is a word size entry. */ 00123 } dfu_data_packet_t; 00124 00125 /**@brief Structure for holding dfu update packet. Packet type indicate the type of packet. 00126 */ 00127 typedef struct 00128 { 00129 uint32_t packet_type; /**< Packet type, used to identify the content of the received packet referenced by data packet. */ 00130 union 00131 { 00132 dfu_data_packet_t data_packet; /**< Used when packet type is INIT_PACKET or DATA_PACKET. Packet contains data received for init or data. */ 00133 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. */ 00134 } params; 00135 } dfu_update_packet_t; 00136 00137 /**@brief DFU status error codes. 00138 */ 00139 typedef enum 00140 { 00141 DFU_UPDATE_APP_COMPLETE, /**< Status update of application complete.*/ 00142 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. */ 00143 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. */ 00144 DFU_UPDATE_BOOT_COMPLETE, /**< Status update complete.*/ 00145 DFU_BANK_0_ERASED, /**< Status bank 0 erased.*/ 00146 DFU_TIMEOUT, /**< Status timeout.*/ 00147 DFU_RESET /**< Status Reset to indicate current update procedure has been aborted and system should reset. */ 00148 } dfu_update_status_code_t; 00149 00150 /**@brief Structure holding DFU complete event. 00151 */ 00152 typedef struct 00153 { 00154 dfu_update_status_code_t status_code; /**< Device Firmware Update status. */ 00155 uint16_t app_crc; /**< CRC of the recieved application. */ 00156 uint32_t sd_size; /**< Size of the recieved SoftDevice. */ 00157 uint32_t bl_size; /**< Size of the recieved BootLoader. */ 00158 uint32_t app_size; /**< Size of the recieved Application. */ 00159 uint32_t sd_image_start; /**< Location in flash where the received SoftDevice image is stored. */ 00160 } dfu_update_status_t; 00161 00162 /**@brief Update complete handler type. */ 00163 typedef void (*dfu_complete_handler_t)(dfu_update_status_t dfu_update_status); 00164 00165 #endif // DFU_TYPES_H__ 00166 00167 /**@} */
Generated on Tue Jul 12 2022 13:49:03 by 1.7.2