forked from gv1/cybootload_linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cybtldr_command.h
519 lines (486 loc) · 24.3 KB
/
cybtldr_command.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
/*******************************************************************************
* Copyright 2011-2012, Cypress Semiconductor Corporation. All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
********************************************************************************/
#ifndef __CYBTLDR_COMMAND_H__
#define __CYBTLDR_COMMAND_H__
#include "cybtldr_utils.h"
/* Maximum number of bytes to allocate for a single command. */
#define MAX_COMMAND_SIZE 512
//STANDARD PACKET FORMAT:
// Multi byte entries are encoded in LittleEndian.
/*******************************************************************************
* [1-byte] [1-byte ] [2-byte] [n-byte] [ 2-byte ] [1-byte]
* [ SOP ] [Command] [ Size ] [ Data ] [Checksum] [ EOP ]
*******************************************************************************/
/* The first byte of any boot loader command. */
#define CMD_START 0x01
/* The last byte of any boot loader command. */
#define CMD_STOP 0x17
/* The minimum number of bytes in a bootloader command. */
#define BASE_CMD_SIZE 0x07
/* Command identifier for verifying the checksum value of the bootloadable project. */
#define CMD_VERIFY_CHECKSUM 0x31
/* Command identifier for getting the number of flash rows in the target device. */
#define CMD_GET_FLASH_SIZE 0x32
/* Command identifier for getting info about the app status. This is only supported on multi app bootloader. */
#define CMD_GET_APP_STATUS 0x33
/* Command identifier for reasing a row of flash data from the target device. */
#define CMD_ERASE_ROW 0x34
/* Command identifier for making sure the bootloader host and bootloader are in sync. */
#define CMD_SYNC 0x35
/* Command identifier for setting the active application. This is only supported on multi app bootloader. */
#define CMD_SET_ACTIVE_APP 0x36
/* Command identifier for sending a block of data to the bootloader without doing anything with it yet. */
#define CMD_SEND_DATA 0x37
/* Command identifier for starting the boot loader. All other commands ignored until this is sent. */
#define CMD_ENTER_BOOTLOADER 0x38
/* Command identifier for programming a single row of flash. */
#define CMD_PROGRAM_ROW 0x39
/* Command identifier for verifying the contents of a single row of flash. */
#define CMD_VERIFY_ROW 0x3A
/* Command identifier for exiting the bootloader and restarting the target program. */
#define CMD_EXIT_BOOTLOADER 0x3B
/*
* This enum defines the different types of checksums that can be
* used by the bootloader for ensuring data integrety.
*/
typedef enum
{
/* Checksum type is a basic inverted summation of all bytes */
SUM_CHECKSUM = 0x00,
/* 16-bit CRC checksum using the CCITT implementation */
CRC_CHECKSUM = 0x01,
} CyBtldr_ChecksumType;
/*******************************************************************************
* Function Name: CyBtldr_ComputeChecksum
********************************************************************************
* Summary:
* Computes the 2byte checksum for the provided command data. The checksum is
* the 2's complement of the 1-byte sum of all bytes.
*
* Parameters:
* buf - The data to compute the checksum on
* size - The number of bytes contained in buf.
*
* Returns:
* The checksum for the provided data.
*
*******************************************************************************/
unsigned short CyBtldr_ComputeChecksum(unsigned char* buf, unsigned long size);
/*******************************************************************************
* Function Name: CyBtldr_SetCheckSumType
********************************************************************************
* Summary:
* Updates what checksum algorithm is used when generating packets
*
* Parameters:
* chksumType - The type of checksum to use when creating packets
*
* Returns:
* NA
*
*******************************************************************************/
void CyBtldr_SetCheckSumType(CyBtldr_ChecksumType chksumType);
/*******************************************************************************
* Function Name: CyBtldr_ParseDefaultCmdResult
********************************************************************************
* Summary:
* Parses the output from any command that returns the default result packet
* data. The default result is just a status byte
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
int CyBtldr_ParseDefaultCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateEnterBootLoaderCmd
********************************************************************************
* Summary:
* Creates the command used to startup the bootloader.
* NB: This command must be sent before the bootloader will respond to any
* other command.
*
* Parameters:
* protect - The flash protection settings.
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateEnterBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseEnterBootLoaderCmdResult
********************************************************************************
* Summary:
* Parses the output from the EnterBootLoader command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The buffer containing the output from the bootloader.
* cmdSize - The number of bytes in cmdBuf.
* siliconId - The silicon ID of the device being communicated with.
* siliconRev - The silicon Revision of the device being communicated with.
* blVersion - The bootloader version being communicated with.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseEnterBootLoaderCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned long* siliconId, unsigned char* siliconRev, unsigned long* blVersion, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateExitBootLoaderCmd
********************************************************************************
* Summary:
* Creates the command used to stop communicating with the boot loader and to
* trigger the target device to restart, running the new bootloadable
* application.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateExitBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_CreateProgramRowCmd
********************************************************************************
* Summary:
* Creates the command used to program a single flash row.
*
* Parameters:
* arrayId - The array id to program.
* rowNum - The row number to program.
* buf - The buffer of data to program into the flash row.
* size - The number of bytes in data for the row.
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateProgramRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* buf, unsigned short size, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseProgramRowCmdResult
********************************************************************************
* Summary:
* Parses the output from the ProgramRow command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseProgramRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateVerifyRowCmd
********************************************************************************
* Summary:
* Creates the command used to verify that the contents of flash match the
* provided row data.
*
* Parameters:
* arrayId - The array id to verify.
* rowNum - The row number to verify.
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateVerifyRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseVerifyRowCmdResult
********************************************************************************
* Summary:
* Parses the output from the VerifyRow command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* checksum - The checksum from the row to verify.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseVerifyRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* checksum, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateEraseRowCmd
********************************************************************************
* Summary:
* Creates the command used to erase a single flash row.
*
* Parameters:
* arrayId - The array id to erase.
* rowNum - The row number to erase.
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateEraseRowCmd(unsigned char arrayId, unsigned short rowNum, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseEraseRowCmdResult
********************************************************************************
* Summary:
* Parses the output from the EraseRow command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseEraseRowCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateVerifyChecksumCmd
********************************************************************************
* Summary:
* Creates the command used to verify that the checkusm value in flash matches
* what is expected.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateVerifyChecksumCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseVerifyChecksumCmdResult
********************************************************************************
* Summary:
* Parses the output from the VerifyChecksum command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* checksumValid - Whether or not the full checksums match (1 = valid, 0 = invalid)
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseVerifyChecksumCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* checksumValid, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateGetFlashSizeCmd
********************************************************************************
* Summary:
* Creates the command used to retreive the number of flash rows in the device.
*
* Parameters:
* arrayId - The array ID to get the flash size of.
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateGetFlashSizeCmd(unsigned char arrayId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseGetFlashSizeCmdResult
********************************************************************************
* Summary:
* Parses the output from the GetFlashSize command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* startRow - The first available row number in the flash array.
* endRow - The last available row number in the flash array.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseGetFlashSizeCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned short* startRow, unsigned short* endRow, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateSendDataCmd
********************************************************************************
* Summary:
* Creates the command used to send a block of data to the target.
*
* Parameters:
* buf - The buffer of data data to program into the flash row.
* size - The number of bytes in data for the row.
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateSendDataCmd(unsigned char* buf, unsigned short size, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseSendDataCmdResult
********************************************************************************
* Summary:
* Parses the output from the SendData command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseSendDataCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateSyncBootLoaderCmd
********************************************************************************
* Summary:
* Creates the command used to ensure that the host application is in sync
* with the bootloader application.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateSyncBootLoaderCmd(unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_CreateGetAppStatusCmd
********************************************************************************
* Summary:
* Creates the command used to get information about the application. This
* command is only supported by the multi application bootloaader.
*
* Parameters:
* appId - The id for the application to get status for
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateGetAppStatusCmd(unsigned char appId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseGetAppStatusCmdResult
********************************************************************************
* Summary:
* Parses the output from the GetAppStatus command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* isValid - Is the application valid.
* isActive- Is the application currently marked as active.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseGetAppStatusCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* isValid, unsigned char* isActive, unsigned char* status);
/*******************************************************************************
* Function Name: CyBtldr_CreateSetActiveAppCmd
********************************************************************************
* Summary:
* Creates the command used to set the active application for the bootloader
* to run. This command is only supported by the multi application
* bootloaader.
*
* Parameters:
* appId - The id for the application to get status for
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* resSize - The number of bytes expected in the bootloader's response packet.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
*
*******************************************************************************/
EXTERN int CyBtldr_CreateSetActiveAppCmd(unsigned char appId, unsigned char* cmdBuf, unsigned long* cmdSize, unsigned long* resSize);
/*******************************************************************************
* Function Name: CyBtldr_ParseSetActiveAppCmdResult
********************************************************************************
* Summary:
* Parses the output from the SetActiveApp command to get the resultant
* data.
*
* Parameters:
* cmdBuf - The preallocated buffer to store command data in.
* cmdSize - The number of bytes in the command.
* status - The status code returned by the bootloader.
*
* Returns:
* CYRET_SUCCESS - The command was constructed successfully
* CYRET_ERR_LENGTH - The packet does not contain enough data
* CYRET_ERR_DATA - The packet's contents are not correct
*
*******************************************************************************/
EXTERN int CyBtldr_ParseSetActiveAppCmdResult(unsigned char* cmdBuf, unsigned long cmdSize, unsigned char* status);
#endif