forked from nxp-imx/mfgtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdp.h
299 lines (259 loc) · 7.38 KB
/
sdp.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
/*
* Copyright 2018 NXP.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of the NXP Semiconductor nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#pragma once
#include "cmd.h"
#include "trans.h"
#include "hidreport.h"
#include <climits>
#pragma pack (1)
struct SDPCmd {
uint16_t m_cmd;
uint32_t m_addr;
uint8_t m_format;
uint32_t m_count;
uint32_t m_data;
uint8_t m_rsvd;
};
struct IvtHeader
{
uint32_t IvtBarker;
uint32_t ImageStartAddr;
uint32_t Reserved;
uint32_t DCDAddress;
uint32_t BootData;
uint32_t SelfAddr;
uint32_t Reserved2[2];
};
struct BootData
{
uint32_t ImageStartAddr;
uint32_t ImageSize;
uint32_t PluginFlag;
};
#pragma pack ()
#define ROM_KERNEL_CMD_RD_MEM 0x0101
#define ROM_KERNEL_CMD_WR_MEM 0x0202
#define ROM_KERNEL_CMD_WR_FILE 0x0404
#define ROM_KERNEL_CMD_ERROR_STATUS 0x0505
#define RAM_KERNEL_CMD_HEADER 0x0606
//#define ROM_KERNEL_CMD_RE_ENUM 0x0909
#define ROM_KERNEL_CMD_DCD_WRITE 0x0A0A
#define ROM_KERNEL_CMD_JUMP_ADDR 0x0B0B
#define ROM_KERNEL_CMD_SKIP_DCD_HEADER 0x0C0C
#define MAX_DCD_WRITE_REG_CNT 85
#define ROM_WRITE_ACK 0x128A8A12
#define ROM_STATUS_ACK 0x88888888
#define ROM_OK_ACK 0x900DD009
#define IVT_BARKER_HEADER 0x402000D1
#define IVT_BARKER2_HEADER 0x412000D1
#define HAB_TAG_DCD 0xd2 /**< Device Configuration Data */
class SDPCmdBase:public CmdBase
{
public:
enum HAB_t
{
HabUnknown = -1,
HabEnabled = 0x12343412,
HabDisabled = 0x56787856
};
SDPCmdBase(char *p) :CmdBase(p) { init_cmd(); }
SDPCmd m_spdcmd;
string m_filename;
vector<uint8_t> m_input;
shared_ptr<FileBuffer> m_filebuff;
int init_cmd() { memset(&m_spdcmd, 0, sizeof(m_spdcmd)); return 0; }
int send_cmd(HIDReport *p) { return p->write(&m_spdcmd, sizeof(m_spdcmd), 1); };
int get_status(HIDReport *p, uint32_t &status, uint8_t report_id)
{
m_input.resize(1025);
m_input[0] = report_id;
int ret = p->read(m_input);
if (ret < 0)
return -1;
if (m_input.size() < (1 + sizeof(uint32_t)))
{
set_last_err_string("HID report size is too small");
return -1;
}
status = *(uint32_t*)(m_input.data() + 1);
return 0;
};
IvtHeader * search_ivt_header(shared_ptr<FileBuffer> data, size_t &off, size_t limit=ULLONG_MAX);
HAB_t get_hab_type(HIDReport *report)
{
uint32_t status;
if (get_status(report, status, 3))
return HabUnknown;
if (status == HabEnabled)
return HabEnabled;
if (status == HabDisabled)
return HabDisabled;
set_last_err_string("unknown hab type");
return HabUnknown;
}
int check_ack(HIDReport *report, uint32_t ack)
{
if (get_hab_type(report) == HabUnknown)
return -1;
uint32_t status;
if (get_status(report, status, 4))
return -1;
if (ack != status)
{
set_last_err_string("Status Miss matched");
return -1;
}
return 0;
}
};
class SDPBootlogCmd : public SDPCmdBase
{
public:
SDPBootlogCmd(char *p) :SDPCmdBase(p)
{
insert_param_info("blog", NULL, Param::e_null);
}
int run(CmdCtx *);
};
class SDPDcdCmd : public SDPCmdBase
{
public:
SDPDcdCmd(char *p):SDPCmdBase(p)
{
insert_param_info("dcd", NULL, Param::e_null);
insert_param_info("-f", &m_filename, Param::e_string_filename);
}
int run(CmdCtx *);
};
class SDPReadMemCmd : public SDPCmdBase
{
public:
uint32_t m_mem_addr;
uint8_t m_mem_format;
SDPReadMemCmd(char*p) :SDPCmdBase(p) {
m_spdcmd.m_cmd = ROM_KERNEL_CMD_RD_MEM;
insert_param_info("rdmem", NULL, Param::e_null);
insert_param_info("-addr", &m_mem_addr, Param::e_uint32);
insert_param_info("-format", &m_mem_format, Param::e_uint32);
}
int run(CmdCtx *);
};
class SDPWriteMemCmd : public SDPCmdBase
{
public:
uint32_t m_mem_addr;
uint8_t m_mem_format;
uint32_t m_mem_value;
SDPWriteMemCmd(char*p) :SDPCmdBase(p) {
m_spdcmd.m_cmd = ROM_KERNEL_CMD_WR_MEM;
insert_param_info("wrmem", NULL, Param::e_null);
insert_param_info("-addr", &m_mem_addr, Param::e_uint32);
insert_param_info("-format", &m_mem_format, Param::e_uint32);
insert_param_info("-value", &m_mem_value, Param::e_uint32);
}
int run(CmdCtx *p);
};
class SDPWriteCmd : public SDPCmdBase
{
public:
uint32_t m_download_addr;
int32_t m_Ivt;
int m_PlugIn;
uint32_t m_max_download_pre_cmd;
uint32_t m_offset;
bool m_bIvtReserve;
bool m_bskipspl;
SDPWriteCmd(char*p) :SDPCmdBase(p) {
m_spdcmd.m_cmd = ROM_KERNEL_CMD_WR_FILE;
m_PlugIn = -1;
m_Ivt = -1;
m_max_download_pre_cmd = 0x200000;
m_offset = 0;
m_bIvtReserve = false;
m_download_addr = 0;
m_bskipspl = false;
insert_param_info("write", NULL, Param::e_null);
insert_param_info("-f", &m_filename, Param::e_string_filename);
insert_param_info("-ivt", &m_Ivt, Param::e_uint32);
insert_param_info("-addr", &m_download_addr, Param::e_uint32);
insert_param_info("-offset", &m_offset, Param::e_uint32);
insert_param_info("-skipspl", &m_bskipspl, Param::e_bool);
};
int run(CmdCtx *p);
int run(CmdCtx *p, void *buff, size_t size, uint32_t addr);
};
class SDPJumpCmd : public SDPCmdBase
{
public:
bool m_Ivt;
bool m_PlugIn;
uint32_t m_jump_addr;
SDPJumpCmd(char*p):SDPCmdBase(p)
{
m_jump_addr = 0;
m_spdcmd.m_cmd = ROM_KERNEL_CMD_JUMP_ADDR;
insert_param_info("jump", NULL, Param::e_null);
insert_param_info("-f", &m_filename, Param::e_string_filename);
insert_param_info("-ivt", &m_Ivt, Param::e_bool);
insert_param_info("-plugin", &m_Ivt, Param::e_bool);
insert_param_info("-addr", &m_jump_addr, Param::e_uint32);
};
int run(CmdCtx *p);
};
class SDPSkipDCDCmd :public SDPCmdBase
{
public:
SDPSkipDCDCmd(char *p) :SDPCmdBase(p) { m_spdcmd.m_cmd = ROM_KERNEL_CMD_SKIP_DCD_HEADER; };
int run(CmdCtx *p);
};
class SDPStatusCmd :public SDPCmdBase
{
public:
SDPStatusCmd(char *p) : SDPCmdBase(p)
{
m_spdcmd.m_cmd = ROM_KERNEL_CMD_ERROR_STATUS;
insert_param_info("status", NULL, Param::e_null);
};
int run(CmdCtx *p);
};
class SDPBootCmd : public SDPCmdBase
{
public:
bool m_nojump;
SDPBootCmd(char *p) : SDPCmdBase(p)
{
insert_param_info("boot", NULL, Param::e_null);
insert_param_info("-f", &m_filename, Param::e_string_filename);
insert_param_info("-nojump", &m_nojump, Param::e_bool);
m_nojump = false;
}
int run(CmdCtx *p);
};