-
Notifications
You must be signed in to change notification settings - Fork 1
/
oad_storage.h
253 lines (222 loc) · 7.69 KB
/
oad_storage.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/******************************************************************************
@file oad_storage.h
@brief OAD Storage Header
Group: WCS LPC
$Target Device: DEVICES $
******************************************************************************
$License: BSD3 2016 $
******************************************************************************
$Release Name: PACKAGE NAME $
$Release Date: PACKAGE RELEASE DATE $
*****************************************************************************/
#ifndef OADStorage_H
#define OADStorage_H
#ifdef __cplusplus
extern "C"
{
#endif
/*********************************************************************
* INCLUDES
*/
#include <stdint.h>
#include <stdbool.h>
#include <oad_image_header.h>
#ifndef __unix__
#include <ti_154stack_oad_config.h>
#endif
/*********************************************************************
* CONSTANTS
*/
// OAD payload overheads
#define OADStorage_ATT_OVERHEAD 3
#define OADStorage_BLK_NUM_HDR_SZ 2 //4
#ifndef OAD_BLOCK_SIZE
#ifdef FREQ_2_4G
/* 2.4G defaults to a 64 byte block size */
#define OADStorage_BLOCK_SIZE 64 + OADStorage_BLK_NUM_HDR_SZ
#else
/* Sub1G defaults to a 128 byte block size */
#define OADStorage_BLOCK_SIZE 128 + OADStorage_BLK_NUM_HDR_SZ
#endif /* FREQ_2_4G */
#else
#define OADStorage_BLOCK_SIZE OAD_BLOCK_SIZE + OADStorage_BLK_NUM_HDR_SZ
#endif /* OAD_BLOCK_SIZE */
/// OADStorage_Status_t status codes
typedef enum {
OADStorage_Status_Success, ///< Success
OADStorage_Failed, ///< Fail
OADStorage_CrcError, ///< Acknowledgment or Response Timed out
OADStorage_FlashError, ///< flash access error
OADStorage_Aborted, ///< Canceled by application
OADStorage_Rejected, ///< OAD request rejected by application
} OADStorage_Status_t;
/* Image Identify Payload */
typedef struct __attribute__((packed))
{
uint8_t imgID[8]; //!< User-defined Image Identification bytes. */
uint8_t bimVer; //!< BIM version */
uint8_t metaVer; //!< Metadata version */
uint8_t imgCpStat; //!< Image copy status bytes */
uint8_t crcStat; //!< CRC status */
uint8_t imgType; //!< Image Type */
uint8_t imgNo; //!< Image number of 'image type' */
uint32_t len; //!< Image length in bytes
uint8_t softVer[4]; //!< Software version of the image */
uint8_t isDeltaImg; //!< Indicates if payload is delta image */
uint8_t toadMetaVer; //!< Turbo OAD header version */
uint8_t toadVer; //!< Turbo OAD version */
uint8_t memoryCfg; //!< Flash configuration used */
uint32_t oldImgCrc; //!< CRC of the current app image */
uint32_t newImgLen; //!< Length of the new app image */
} OADStorage_imgIdentifyPld_t;
/*********************************************************************
* MACROS
*/
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* FUNCTIONS
*/
/*********************************************************************
* @fn OADStorage_init
*
* @brief Initialise the OAD Target Profile.
*
* @param None.
*
* @return None.
*/
extern void OADStorage_init(void);
/*********************************************************************
* @fn OADStorage_imgIdentifyRead
*
* @brief Read Image header and return number of blocks.
*
* @param imageType - image type indicating which image to read
* @param pImgHdr - pointer to image header data
*
* @return Total Blocks if image accepted, 0 if Image invalid
*/
uint16_t OADStorage_imgIdentifyRead(uint8_t imageType, OADStorage_imgIdentifyPld_t* pImgId);
/*********************************************************************
* @fn OADStorage_imgIdentifyWrite
*
* @brief Process the Image Identify Write. Determine from the received OAD
* Image Header if the Downloaded Image should be acquired.
*
* @param pValue - pointer to data to be written
*
* @return Total Blocks if image accepted, 0 if Image rejected
*/
extern uint16_t OADStorage_imgIdentifyWrite(uint8_t *pValue);
/*********************************************************************
* @fn OADStorage_imgBlockRead
*
* @brief Read Image Block.
*
* @param blockNum - block number to be written
* @param pBlockData - pointer for data to be read
*
* @return none
*/
extern OADStorage_Status_t OADStorage_imgBlockRead(uint16_t blockNum, uint8_t *pBlockData);
/*********************************************************************
* @fn OADStorage_imgInfoRead
*
* @brief Read an Image info.
*
* @param pimgInfo - pointer for data to be read
*
* @return none
*/
extern void OADStorage_imgInfoRead(uint8_t *pimgInfo);
/*********************************************************************
* @fn OADStorage_imgBlockWrite
*
* @brief Write Image Block.
*
* @param blockNum - block number to be written
* @param pBlockData - pointer to data to be written
* @param len - length of the block
*
* @return status
*/
extern OADStorage_Status_t OADStorage_imgBlockWrite(uint32_t blockNum, uint8_t *pBlockData, uint16_t len);
/*********************************************************************
* @fn OADStorage_imgDataWrite
*
* @brief Write image data.
*
* @param addrOffset - starting address offset to write block data
* @param pBlockData - pointer to data to be written
* @param blockOffset - offset in the block data pointer to start writing data
* @param len - length of the block
*
* @return status
*/
extern OADStorage_Status_t OADStorage_imgDataWrite(uint32_t addrOffset, uint8_t *pBlockData, uint32_t blockOffset, uint32_t len);
/*********************************************************************
* @fn OADStorage_eraseImgPage
*
* @brief Erases an Image page. Note this is only needed if an image
* page has been corrupted typically OADStorage_imgBlockWrite
* pre-erase all pages
*
* @param none
*
* @return OADStorage_Status_t
*/
extern OADStorage_Status_t OADStorage_eraseImgPage(uint32_t page);
/*********************************************************************
* @fn OADStorage_imgFinalise
*
* @brief Process the Image Block Write.
*
* @param none
*
* @return status
*/
extern OADStorage_Status_t OADStorage_imgFinalise(void);
/*********************************************************************
* @fn OADStorage_createFactoryImageBackup
*
* @brief This function creates factory image backup of current running image
*
* @param None
*
* @return status OADStorage_Status_Success/OADStorage_FlashError
*
*/
extern uint8_t OADStorage_createFactoryImageBackup(void);
/*********************************************************************
* @fn OADStorage_checkFactoryImage
*
* @brief This function check if the valid factory image exists on external
* flash
*
* @param None
*
* @return TRUE If factory image exists on external flash, else FALSE
*
*/
extern bool OADStorage_checkFactoryImage(void);
/*********************************************************************
* @fn OADStorage_close
*
* @brief Releases the resource required for OAD stoarage.
*
* @param none
*
* @return none
*/
extern void OADStorage_close(void);
/*********************************************************************
*********************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* OADStorage_H */