1 /******************************************************************************
3 @file oad_image_preamble.h
5 @brief This file contains the image preable information.
7 Group: WCS, BTS
8 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350, CC1352$
10 ******************************************************************************
11 $License: BSD3 2016 $
13 Copyright (c) 2015, Texas Instruments Incorporated
14 All rights reserved.
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
20 * Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
27 * Neither the name of Texas Instruments Incorporated nor the names of
28 its contributors may be used to endorse or promote products derived
29 from this software without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ******************************************************************************
43 $Release Name: TI-15.4Stack Linux x64 SDK$
44 $Release Date: Sept 27, 2017 (2.04.00.13)$
45 ******************************************************************************/
47 #ifndef _OAD_IMAGE_PREAMBLE_H
48 #define _OAD_IMAGE_PREAMBLE_H
50 #ifdef __cplusplus
51 extern "C"
52 {
53 #endif
55 /*******************************************************************************
56 * INCLUDES
57 ******************************************************************************/
59 /*******************************************************************************
60 * CONSTANTS
61 ******************************************************************************/
63 /*
64 * BIM Varible Address
65 * The bim_var is a variable stored in RAM that is used to control switching
66 * between persistent and user application in the BIM
67 * On 26xx platforms RAM is retained between resets and this is possible
68 *
69 * Warning! placement of the BIM variable must respect the following
70 * reserved RAM regions ( Valid for CC2640R2):
71 * - TI-RTOS in ROM reserved region: 0x20000100-0x20000280
72 * - BLE Stack memory: < ICALL_RAM0_START
73 * - Vector Table in RAM: 0x20000000-0x200000C8
74 * Failing to respect either of the above boundaries will result in a
75 * linker error
76 */
77 #ifdef OAD_ONCHIP
78 #define BIM_VAR_ADDR 0x20000400
79 extern uint32_t _bim_var;
80 #endif // OAD_ONCHIP
82 /*
83 * NV Page Setting:
84 * This define is used ensure the stack is built with a compatible NV setting
85 * Note: this restriction does not apply to the stack library configuration
86 * for off-chip OAD
87 */
88 #define OAD_NUM_NV_PGS 1
90 #ifdef OSAL_SNV
91 #if OSAL_SNV != OAD_NUM_NV_PGS
92 #error "Incompatible NV settings detected. OAD supports 1 NV page"
93 #endif //OSAL_SNV != OAD_NUM_NV_PGS
94 #endif //OSAL_SNV
96 // Image types
97 #define OAD_IMG_TYPE_PERSISTENT_APP 0
98 #define OAD_IMG_TYPE_APP 1
99 #define OAD_IMG_TYPE_STACK 2
100 #define OAD_IMG_TYPE_APP_STACK 3
101 #define OAD_IMG_TYPE_NP 4
102 #define OAD_IMG_TYPE_FACTORY 5
103 #define OAD_IMG_TYPE_BIM 6
104 #define OAD_IMG_TYPE_APPSTACKLIB 7
105 #define OAD_IMG_TYPE_USR_BEGIN 16
106 #define OAD_IMG_TYPE_USR_END 31
107 #define OAD_IMG_TYPE_HOST_BEGIN 32
108 #define OAD_IMG_TYPE_HOST_END 63
109 #define OAD_IMG_TYPE_RSVD_BEGIN 64
110 #define OAD_IMG_TYPE_RSVD_END 255
112 //!< Wireless Technology Types
113 #define OAD_WIRELESS_TECH_BLE 0xFFFE
114 #define OAD_WIRELESS_TECH_TIMAC_SUBG 0xFFFD
115 #define OAD_WIRELESS_TECH_TIMAC_2_4G 0xFFFB
116 #define OAD_WIRELESS_TECH_ZIGBEE 0xFFF7
117 #define OAD_WIRELESS_TECH_RF4CE 0xFFEF
118 #define OAD_WIRELESS_TECH_THREAD 0xFFDF
119 #define OAD_WIRELESS_TECH_EASYLINK 0xFFBF
121 /*
122 * These values are modified from source/ti/common/26xx/oad/oad_image_header.h
123 * Any device specific #ifdef's had to be removed and modified to seperate #define
124 * statements since the linux collector has no knowledge of device type
125 */
126 #define CC26X2_OAD_IMG_ID_VAL "CC26x2R1"
127 #define CC13X2_OAD_IMG_ID_VAL "CC13x2R1"
128 #define OAD_IMG_ID_VAL "OAD IMG "
130 // External flash metadata identification value
131 #define OAD_EXTFL_ID_VAL "OAD NVM1"
133 #define OAD_IMG_ID_LEN 8 /* OAD image identification bytes length */
134 #define OAD_SW_VER_LEN 4 /* OAD software version length in bytes */
135 #define OAD_IMG_HDR_LEN sizeof(imgFixedHdr_t) /* The length of just the OAD Header */
136 #define CRC_OFFSET offsetof(imgHdr_t, fixedHdr.crc32) /* Supported metadata version */
137 #define BIM_VER_OFFSET offsetof(imgHdr_t, fixedHdr.bimVer) /* BIM metadata version offset */
138 #define IMG_DATA_OFFSET BIM_VER_OFFSET /* Start of data after CRC bytes */
139 #define IMG_INFO_OFFSET offsetof(imgHdr_t, fixedHdr.imgCpStat) /* ImageInfo Bytes offset */
140 #define IMG_COPY_STAT_OFFSET IMG_INFO_OFFSET /* Image copy status */
141 #define CRC_STAT_OFFSET offsetof(imgHdr_t, fixedHdr.crcStat) /* Offset to CRC status byte */
142 #define IMG_TYPE_OFFSET offsetof(imgHdr_t, fixedHdr.imgType) /* Offset to CRC status byte */
143 #define BOUNDARY_SEG_OFFSET offsetof(imgHdr_t, fixedHdr.segTypeBd) /* Offset into image header for boundary */
145 #define SEG_LEN_OFFSET 4 /* Offset from seg header to seg len */
146 #define SEG_HDR_LEN 12 /* Length of the segment header bytes */
148 #define IMG_PAYLOAD_SEG_ID 1 /* Id of the image payload segment */
149 #define IMG_BOUNDARY_SEG_ID 0 /* Id of RAM/stack boundary segment */
150 #define IMG_NONCOUNT_SEG_ID 2 /* Id of non contigouous image segment */
151 #define IMG_SECURITY_SEG_ID 3 /* Id of security segment */
153 #define BIM_VER 0x3 /* Supported BIM version */
154 #define META_VER 0x1 /* Supported metadata version */
155 #define DEFAULT_STATE 0xFF /* default status */
156 #define CRC_VALID 0xFE
157 #define CRC_INVALID 0xFC
158 #define NEED_COPY 0xFE /* Image to be copied on on-chip flash at location indicated in the image */
159 #define COPY_DONE 0xFC /* Image already copied */
161 #define EFL_MATADATA_HDR_LEN OAD_IMG_HDR_LEN + 8 /* External flash meta-data header length */
163 #define INVALID_ADDR 0xFFFFFFFF
164 #define INVALID_LEN INVALID_ADDR
165 #define DEFAULT_CRC 0xFFFFFFFF
167 /*******************************************************************************
168 * Typedefs
169 */
170 #if defined (__IAR_SYSTEMS_ICC__)
171 #define TYPEDEF_STRUCT_PACKED __packed typedef struct
172 #elif defined __TI_COMPILER_VERSION || defined __TI_COMPILER_VERSION__
173 #define TYPEDEF_STRUCT_PACKED typedef struct __attribute__((packed))
174 #elif defined (__GNUC__)
175 #define TYPEDEF_STRUCT_PACKED typedef struct __attribute__((__packed__))
176 #endif
178 /* Image Preamble */
179 TYPEDEF_STRUCT_PACKED
180 {
181 uint8_t imgID[8]; //!< User-defined Image Identification bytes. */
182 uint32_t crc32; //!< Image's crc32 value */
183 uint8_t bimVer; //!< BIM version */
184 uint8_t metaVer; //!< Metadata version */
185 uint16_t techType; //!< Wireless protocol type BLE/TI-MAC/ZIGBEE etc. */
186 uint8_t imgCpStat; //!< Image copy status */
187 uint8_t crcStat; //!< CRC status */
188 uint8_t imgType; //!< Image Type */
189 uint8_t imgNo; //!< Image number of 'image type' */
190 uint32_t imgVld; //!< In indicates if the current image in valid 0xff - valid, 0x00 invalid image */
191 uint32_t len; //!< Image length in bytes. */
192 uint32_t prgEntry; //!< Program entry address */
193 uint8_t softVer[4]; //!< Software version of the image */
194 uint32_t imgEndAddr; //!< Address of the last byte of a contiguous image */
195 uint16_t hdrLen; //!< Total length of the image header */
196 uint16_t rfu; //!< Reserved bytes */
197 } imgFixedHdr_t;
199 /* Image payload segment */
200 TYPEDEF_STRUCT_PACKED
201 {
202 uint8_t segTypeImg; //!< Segment type - for Contiguous image payload */
203 uint16_t wirelessTech; //!< Wireless technology type */
204 uint8_t rfu; //!< Reserved byte */
205 uint32_t imgSegLen; //!< Payload segment length */
206 uint32_t startAddr; //!< Start address of image on internal flash */
207 } imgPayloadSeg_t;
209 /* Image boundary segment */
210 TYPEDEF_STRUCT_PACKED
211 {
212 uint8_t segTypeBd; //!< Segment type - for boundary segment */
213 uint16_t wirelessTech; //!< Wireless technology type */
214 uint8_t rfu; //!< Reserved byte */
215 uint32_t boundarySegLen; //!< Boundary segment length */
216 uint32_t stackStartAddr; //!< Start address of stack image on internal flash */
217 uint32_t stackEntryAddr; //!< Stack start address */
218 uint32_t ram0StartAddr; //!< RAM entry start address */
219 uint32_t ram0EndAddr; //!< RAM entry end address */
220 } boundarySeg_t;
222 /* Complete Image Header */
223 TYPEDEF_STRUCT_PACKED
224 {
225 imgFixedHdr_t fixedHdr;
226 #if (!defined(STACK_LIBRARY) && (defined(SPLIT_APP_STACK_IMAGE)))
227 boundarySeg_t boundarySeg;
228 #endif
229 imgPayloadSeg_t imgPayload;
230 } imgHdr_t;
231 #ifdef __cplusplus
232 }
233 #endif
235 #endif /* _OAD_IMAGE_PREAMBLE_H */