Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
command_packet.h
1 /*
2  * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(__COMMAND_PACKET_H__)
31 #define __COMMAND_PACKET_H__
32 
33 #include "bootloader_common.h"
34 
37 
39 // Declarations
41 
44 {
45  kMinPacketBufferSize = 32,
46  kDefaultMaxPacketSize = kMinPacketBufferSize,
48  (kMinPacketBufferSize / sizeof(uint32_t)) - 2,
49 
52  (kMinPacketBufferSize / sizeof(uint32_t)) - 3,
53  kCommandTagCount = 12
55 };
56 
59 {
60  kCommandTag_GenericResponse = 0xa0,
61  kCommandTag_FlashEraseAll = 0x01,
62  kCommandTag_FlashEraseRegion = 0x02,
63  kCommandTag_ReadMemory = 0x03,
64  kCommandTag_ReadMemoryResponse = 0xa3,
65  kCommandTag_WriteMemory = 0x04,
66  kCommandTag_FillMemory = 0x05,
67  kCommandTag_FlashSecurityDisable = 0x06,
68  kCommandTag_GetProperty = 0x07,
69  kCommandTag_GetPropertyResponse = 0xa7,
70  kCommandTag_ReceiveSbFile = 0x08,
71  kCommandTag_Execute = 0x09,
72  kCommandTag_Call = 0x0a,
73  kCommandTag_Reset = 0x0b,
74  kCommandTag_SetProperty = 0x0c,
75  kCommandTag_FlashEraseAllUnsecure = 0x0d,
76  kCommandTag_FlashProgramOnce = 0x0e,
77  kCommandTag_FlashReadOnce = 0x0f,
78  kCommandTag_FlashReadOnceResponse = 0xaf,
79  kCommandTag_FlashReadResource = 0x10,
80  kCommandTag_FlashReadResourceResponse = 0xb0,
81  kCommandTag_ConfigureQuadSpi = 0x11,
82  kCommandTag_ReliableUpdate = 0x12,
83 
84  kCommandTag_ConfigureI2c = 0xc1,
87 
88  kFirstCommandTag = kCommandTag_FlashEraseAll,
89 
91  kLastCommandTag = kCommandTag_ReliableUpdate,
92 
94  0xa0
95 };
96 
99 {
100  kCommandFlag_None = 0,
101  kCommandFlag_HasDataPhase = 1
102 };
103 
106 {
107  kFlashMemInternal = 0,
108  kFlashMemQuadSpi0 = 1,
109  kFlashMemExecuteOnly = 0x10
110 };
111 
113 typedef struct CommandPacket
114 {
115  uint8_t commandTag;
116  uint8_t flags;
117  uint8_t reserved;
118  uint8_t parameterCount;
120 
122 
123 
125 typedef struct FlashEraseAllPacket
126 {
128  uint32_t memoryId;
130 
132 typedef struct FlashEraseRegionPacket
133 {
135  uint32_t startAddress;
136  uint32_t byteCount;
138 
140 typedef struct GetPropertyPacket
141 {
143  uint32_t propertyTag;
144  uint32_t memoryId;
146 
148 typedef struct SetPropertyPacket
149 {
151  uint32_t propertyTag;
152  uint32_t propertyValue;
154 
156 typedef struct ReceiveSbFilePacket
157 {
159  uint32_t byteCount;
161 
163 typedef struct WriteMemoryPacket
164 {
166  uint32_t startAddress;
167  uint32_t byteCount;
169 
171 typedef struct ReadMemoryPacket
172 {
174  uint32_t startAddress;
175  uint32_t byteCount;
177 
179 typedef struct FillMemoryPacket
180 {
182  uint32_t startAddress;
183  uint32_t byteCount;
184  uint32_t patternWord;
186 
188 typedef status_t (*call_function_t)(uint32_t);
189 
191 typedef struct ExecuteCallPacket
192 {
194  uint32_t callAddress;
195  uint32_t argumentWord;
196  uint32_t stackpointer;
198 
200 typedef struct FlashSecurityDisablePacket
201 {
203  uint32_t keyLow;
204  uint32_t keyHigh;
206 
208 typedef struct ProgramOncePacket
209 {
211  uint32_t index;
212  uint32_t byteCount;
213  uint32_t data[kMaxProgramOnceValues];
215 
217 typedef struct ReadOncePacket
218 {
220  uint32_t index;
221  uint32_t byteCount;
223 
225 typedef struct FlashReadResourcePacket
226 {
228  uint32_t startAddress;
229  uint32_t byteCount;
230  uint32_t option;
232 
234 typedef struct ConfigureQuadSpiPacket
235 {
237  uint32_t flashMemId;
240 
242 typedef struct ReliableUpdatePacket
243 {
245  uint32_t address;
248 
250 typedef struct ConfigureI2cPacket
251 {
253  uint32_t address;
254  uint32_t speed;
256 
258 typedef struct ConfigureSpiPacket
259 {
261  uint32_t speedKhz;
262  uint32_t polarity;
263  uint32_t phase;
264  uint32_t direction;
266 
268 typedef struct ConfigureCanPacket
269 {
271  uint32_t speed;
272  uint32_t txid;
273  uint32_t rxid;
275 
277 
279 
280 
282 typedef struct GenericResponsePacket
283 {
285  uint32_t status;
286  uint32_t commandTag;
288 
290 typedef struct GetPropertyResponsePacket
291 {
293  uint32_t status;
294  uint32_t propertyValue[kMaxPropertyReturnValues];
296 
298 typedef struct ReadMemoryResponsePacket
299 {
301  uint32_t status;
302  uint32_t dataByteCount;
304 
306 typedef struct FlashReadOnceResponsePacket
307 {
309  uint32_t status;
310  uint32_t byteCount;
311  uint32_t data[kMaxProgramOnceValues];
313 
315 typedef struct FlashReadResourceResponsePacket
316 {
318  uint32_t status;
319  uint32_t dataByteCount;
321 
323 
325 
326 #endif // __COMMAND_PACKET_H__
327 // EOF
uint32_t phase
Parameter 2: phase.
Definition: command_packet.h:263
uint32_t dataByteCount
parameter 1
Definition: command_packet.h:302
ReliableUpdate packet format.
Definition: command_packet.h:242
uint32_t propertyValue
Parameter 1: value to set.
Definition: command_packet.h:152
Mask for the high nibble of a command tag that identifies it as a response command.
Definition: command_packet.h:93
_command_tags
Commands codes.
Definition: command_packet.h:58
ConfigureQuadSpi packet format.
Definition: command_packet.h:234
Read Memory response packet format.
Definition: command_packet.h:298
uint32_t keyLow
Paremeter 0: key bytes 0-3.
Definition: command_packet.h:203
uint32_t byteCount
Parameter 1: number of bytes.
Definition: command_packet.h:136
ReadMemory packet format.
Definition: command_packet.h:171
uint32_t commandTag
parameter 1
Definition: command_packet.h:286
ReceiveSbFile packet format.
Definition: command_packet.h:156
Definition: command_packet.h:47
_flash_mem_id
Flash memory identifiers.
Definition: command_packet.h:105
uint32_t callAddress
Paremeter 0: function address.
Definition: command_packet.h:194
WriteMemory packet format.
Definition: command_packet.h:163
uint32_t option
Parameter 2: option for flash read resource command.
Definition: command_packet.h:230
uint32_t argumentWord
Parameter 1: argument.
Definition: command_packet.h:195
Command packet format.
Definition: command_packet.h:113
GetProperty packet format.
Definition: command_packet.h:140
uint8_t commandTag
A command tag.
Definition: command_packet.h:115
Get Property response packet format.
Definition: command_packet.h:290
FlashEraseAll packet format.
Definition: command_packet.h:125
uint32_t rxid
Parameter 2: rxid.
Definition: command_packet.h:273
uint32_t keyHigh
Parameter 1: key bytes 4-7.
Definition: command_packet.h:204
Generic response packet format.
Definition: command_packet.h:282
ConfigureCan packet format.
Definition: command_packet.h:268
ConfigureSpi packet format.
Definition: command_packet.h:258
FlashReadOnce packet format.
Definition: command_packet.h:217
Reserved command tag for Bus Pal.
Definition: command_packet.h:88
command_packet_t commandPacket
header
Definition: command_packet.h:127
Reserved command tag for Bus Pal.
Definition: command_packet.h:85
uint32_t status
parameter 0
Definition: command_packet.h:285
uint32_t speed
Parameter 1: speed.
Definition: command_packet.h:254
One word is header, two parameters reserved for index and byteCount.
Definition: command_packet.h:54
Flash Read Once response packet format.
Definition: command_packet.h:306
uint32_t configBlockAddress
Parameter 1: address of config block to use.
Definition: command_packet.h:238
_command_packet_constants
Command/Data Packet constants.
Definition: command_packet.h:43
Flash Read Resource response packet format.
Definition: command_packet.h:315
Reserved command tag for Bus Pal.
Definition: command_packet.h:86
uint32_t flashMemId
Parameter 0: quadspi ID.
Definition: command_packet.h:237
ConfigureI2c packet format.
Definition: command_packet.h:250
FlashEraseRegion packet format.
Definition: command_packet.h:132
Maximum linearly incrementing command tag value, excluding the response commands and bus pal commands...
Definition: command_packet.h:91
uint32_t startAddress
Paremeter 0: start address.
Definition: command_packet.h:135
_command_packet_flags
Command packet flags.
Definition: command_packet.h:98
uint32_t index
Parameter 0: index of pragram once field.
Definition: command_packet.h:211
FlashProgramOnce packet format.
Definition: command_packet.h:208
Execute/Call packet format.
Definition: command_packet.h:191
Definition: command_packet.h:51
FlashReadResource packet format.
Definition: command_packet.h:225
uint8_t flags
Combination of packet flags.
Definition: command_packet.h:116
uint32_t memoryId
Paremeter 0: Flash memory identifiers.
Definition: command_packet.h:128
uint8_t parameterCount
Number of parameters that follow in buffer.
Definition: command_packet.h:118
uint32_t polarity
Parameter 1: polarity.
Definition: command_packet.h:262
FillMemory packet format.
Definition: command_packet.h:179
uint32_t patternWord
Parameter 1: pattern word.
Definition: command_packet.h:184
uint32_t txid
Parameter 1: txid.
Definition: command_packet.h:272
uint32_t address
Definition: command_packet.h:245
uint32_t speedKhz
Parameter 0: spped Khz.
Definition: command_packet.h:261
SetProperty packet format.
Definition: command_packet.h:148
status_t(* call_function_t)(uint32_t)
Execute/Call command function pointer definition.
Definition: command_packet.h:188
uint32_t stackpointer
Parameter 2: stack pointer.
Definition: command_packet.h:196
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
FlashSecurityDisable packet format.
Definition: command_packet.h:200
uint32_t direction
Parameter 3: directionpolarity.
Definition: command_packet.h:264
uint32_t propertyTag
Parameter 0: requested property tag.
Definition: command_packet.h:143
uint8_t reserved
Reserved, helpful for alignment, set to zero.
Definition: command_packet.h:117