Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
host_command.h
1 /*
2  * Copyright (c) 2013 - 2014, 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 
31 #ifndef __HOST_COMMAND_H__
32 #define __HOST_COMMAND_H__
33 
34 #include <stdio.h>
35 #include <stdint.h>
36 #include "bootloader_common.h"
37 #include "property/property.h"
38 #include "packet/serial_packet.h"
39 #include "blsh.h"
40 
41 /*******************************************************************************
42  * Definitions
43  ******************************************************************************/
45 enum _transfer_mode_type
46 {
47  kIdle_mode = 0,
48  kSPI_mode = 1,
49  kI2C_mode = 2,
50  kUART_mode = 3,
51  kCAN_mode = 4
52 };
53 
54 #if DEBUG && !DEBUG_PRINT_DISABLE
55 
56 static const char *const kCommandNames[] = { "flash-erase-all",
57  "flash-erase-region",
58  "read-memory",
59  "write-memory",
60  "fill-memory",
61  "flash-security-disable",
62  "get-property",
63  "receive-sb-file",
64  "execute",
65  "call",
66  "reset",
67  "set-property",
68  "flash-erase-all-unsecure",
69  "flash-program-once",
70  "flash-read-once",
71  "flash-read-resource",
72  "configure-quadspi",
73  "reliable-update",
74  "flash-image",
75  "i2c",
76  "spi",
77  "can" };
78 #endif
79 
80 #pragma pack(1)
81 
82 typedef struct _command_frame_packet
83 {
84  framing_data_packet_t framing_data;
85  command_packet_t command_data;
86  uint32_t param[7];
88 #pragma pack()
89 
90 #pragma pack(1)
91 
92 typedef struct _generic_response_frame_packet
93 {
94  framing_data_packet_t framing_data;
95  uint8_t commandTag;
96  uint8_t flags;
97  uint8_t reserved;
98  uint8_t parameterCount;
99  uint32_t status;
100  uint32_t param_commandTag;
102 #pragma pack()
103 
104 #pragma pack(1)
105 
106 typedef struct _flash_read_once_response_frame_packet
107 {
108  framing_data_packet_t framing_data;
111 #pragma pack()
112 
113 #pragma pack(1)
114 
115 typedef struct _property_response_frame_packet
116 {
117  framing_data_packet_t framing_data;
118  get_property_response_packet_t generic_response;
120 #pragma pack()
121 
123 typedef struct _memory_info
124 {
125  bool is_info_reday;
126  uint32_t flashStart;
127  uint32_t flashSize;
128  uint32_t ramStart;
129  uint32_t ramSize;
130 
131  uint32_t reservedFlashStart;
132  uint32_t reservedFlashEnd;
133  uint32_t reservedRamStart;
134  uint32_t reservedRamEnd;
135 
136  uint32_t blankFlashStart;
137  uint32_t blankFlashSize;
138  uint32_t blankRamStart;
139  uint32_t blankRamSize;
140 } memory_info_t;
141 
143 typedef struct _write_memory_test_option
144 {
145  uint32_t address;
146  uint32_t writeLength;
147  uint32_t testTimes;
148  uint64_t averageCost;
149  uint32_t averageSpeed;
150  uint8_t divider;
152 
154 typedef struct _command_info
155 {
156  bool is_info_reday;
157  uint32_t cmd_mask;
159 
161 typedef status_t (*transfer_data_t)(uint8_t *data, uint32_t length);
162 extern transfer_data_t write_serial_data;
163 extern transfer_data_t read_serial_data;
164 
165 /*******************************************************************************
166  * API
167  ******************************************************************************/
168 #if defined(__cplusplus)
169 extern "C" {
170 #endif /* __cplusplus */
171 
173 status_t handle_getProperty_command(uint8_t input_param, uint32_t *response_param);
174 
176 status_t handle_setProperty_command(uint8_t property_tag, uint32_t property_value);
177 
179 status_t handle_flashEraseAllUnsecure_command(void);
180 
182 status_t handle_flashEraseAll_command(void);
183 
185 status_t handle_flashEraseRegion_command(uint32_t start_address, uint32_t erase_bytes);
186 
188 status_t handle_reset_command(void);
189 
191 status_t handle_writeMemory_command(uint32_t start_address, uint8_t *buffer, uint32_t length);
192 
194 status_t handle_readMemory_command(uint32_t start_address, uint8_t *buffer, uint32_t length);
195 
197 status_t handle_fillMemory_command(uint32_t start_address, uint32_t pattern_word, uint32_t byte_count);
198 
200 status_t handle_flashSecurityDisable_command(uint32_t backdoorkey_low, uint32_t backdoorkey_high);
201 
203 status_t handle_execute_command(uint32_t address, uint32_t arg, uint32_t stack_pointer);
204 
206 status_t handle_call_command(uint32_t address, uint32_t arg);
207 
209 status_t handle_flashProgramOnce_command(uint32_t index, uint32_t byte_count, uint32_t data1, uint32_t data2);
210 
212 status_t handle_flashReadOnce_command(uint32_t index, uint32_t byte_count, uint32_t *data1, uint32_t *data2);
213 
215 status_t handle_flashReadResource_command(uint32_t start_address, uint8_t *buffer, uint32_t length, uint32_t option);
216 
218 status_t handle_receiveSBFile_command(uint32_t address, uint32_t length);
219 
221 status_t get_memory_info(memory_info_t *info);
222 
224 status_t get_command_info(command_info_t *info);
225 
227 status_t run_ping_command(void);
228 
230 status_t wait_ping_response(uint8_t try_count);
231 
233 status_t wait_ack_packet(void);
234 
236 status_t wait_command_response(generic_response_frame_packet_t *command_response);
237 
239 void check_transfer_bus(uint8_t transfer_bus, uint32_t *input_freq);
240 
242 void configure_transfer_bus(uint8_t transfer_bus, uint32_t freq);
243 
244 #if defined(__cplusplus)
245 }
246 #endif /* __cplusplus */
247 
248 #endif /* __HOST_COMMAND_H__ */
uint8_t parameterCount
Definition: host_command.h:98
target memory info
Definition: host_command.h:123
uint8_t flags
Definition: host_command.h:96
Command packet format.
Definition: command_packet.h:113
generic response packet
Definition: host_command.h:106
Get Property response packet format.
Definition: command_packet.h:290
generic response packet
Definition: host_command.h:115
memory test options
Definition: host_command.h:143
generic response packet
Definition: host_command.h:92
uint8_t commandTag
Definition: host_command.h:95
uint32_t param_commandTag
Definition: host_command.h:100
Flash Read Once response packet format.
Definition: command_packet.h:306
Serial framing data packet.
Definition: serial_packet.h:106
uint8_t reserved
Definition: host_command.h:97
command packet
Definition: host_command.h:82
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
bootloader command info
Definition: host_command.h:154
uint32_t status
Definition: host_command.h:99