Fix sdp jump command ivt implement to support uboot plugin
[mfgtools.git] / libuuu / sdp.h
bloba94510b81dbb13af1d6736c68555875dad9e5e8e
1 /*
2 * Copyright 2018 NXP.
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright notice, this
11 * list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
14 * Neither the name of the NXP Semiconductor nor the names of its
15 * contributors may be used to endorse or promote products derived from this
16 * software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 #pragma once
34 #include "cmd.h"
36 #include <climits>
38 class FileBuffer;
39 class HIDReport;
41 #pragma pack (1)
42 struct SDPCmd {
43 uint16_t m_cmd;
44 uint32_t m_addr;
45 uint8_t m_format;
46 uint32_t m_count;
47 uint32_t m_data;
48 uint8_t m_rsvd;
51 struct IvtHeader
53 uint32_t IvtBarker;
54 uint32_t ImageStartAddr;
55 uint32_t Reserved;
56 uint32_t DCDAddress;
57 uint32_t BootData;
58 uint32_t SelfAddr;
59 uint32_t Reserved2[2];
62 struct BootData
64 uint32_t ImageStartAddr;
65 uint32_t ImageSize;
66 uint32_t PluginFlag;
69 #pragma pack ()
71 #define ROM_KERNEL_CMD_RD_MEM 0x0101
72 #define ROM_KERNEL_CMD_WR_MEM 0x0202
73 #define ROM_KERNEL_CMD_WR_FILE 0x0404
74 #define ROM_KERNEL_CMD_ERROR_STATUS 0x0505
75 #define RAM_KERNEL_CMD_HEADER 0x0606
76 //#define ROM_KERNEL_CMD_RE_ENUM 0x0909
77 #define ROM_KERNEL_CMD_DCD_WRITE 0x0A0A
78 #define ROM_KERNEL_CMD_JUMP_ADDR 0x0B0B
79 #define ROM_KERNEL_CMD_SKIP_DCD_HEADER 0x0C0C
81 #define MAX_DCD_WRITE_REG_CNT 85
82 #define ROM_WRITE_ACK 0x128A8A12
83 #define ROM_STATUS_ACK 0x88888888
84 #define ROM_OK_ACK 0x900DD009
86 #define IVT_BARKER_HEADER 0x402000D1
87 #define IVT_BARKER2_HEADER 0x412000D1
89 #define HAB_TAG_DCD 0xd2 /**< Device Configuration Data */
91 class SDPCmdBase:public CmdBase
93 public:
95 enum HAB_t
97 HabUnknown = -1,
98 HabEnabled = 0x12343412,
99 HabDisabled = 0x56787856
102 SDPCmdBase(char *p) :CmdBase(p) { init_cmd(); }
104 protected:
105 int check_ack(HIDReport *report, uint32_t ack);
106 HAB_t get_hab_type(HIDReport *report);
107 int get_status(HIDReport *p, uint32_t &status, uint8_t report_id);
108 int init_cmd();
109 IvtHeader * search_ivt_header(std::shared_ptr<FileBuffer> data, size_t &off, size_t limit=ULLONG_MAX);
111 std::string m_filename;
112 SDPCmd m_spdcmd;
114 private:
115 int send_cmd(HIDReport *p);
117 std::vector<uint8_t> m_input;
120 class SDPBootlogCmd : public SDPCmdBase
122 public:
123 SDPBootlogCmd(char *p);
124 int run(CmdCtx *) override;
127 class SDPDcdCmd : public SDPCmdBase
129 public:
130 SDPDcdCmd(char *p);
131 int run(CmdCtx *) override;
133 private:
134 uint32_t m_dcd_addr;
137 class SDPReadMemCmd : public SDPCmdBase
139 public:
140 SDPReadMemCmd(char*p);
141 int run(CmdCtx *) override;
143 private:
144 uint32_t m_mem_addr;
145 uint8_t m_mem_format;
148 class SDPWriteMemCmd : public SDPCmdBase
150 public:
151 SDPWriteMemCmd(char*p);
152 int run(CmdCtx *p) override;
154 private:
155 uint32_t m_mem_addr;
156 uint8_t m_mem_format;
157 uint32_t m_mem_value;
160 class SDPWriteCmd : public SDPCmdBase
162 public:
163 SDPWriteCmd(char*p);
165 int run(CmdCtx *p) override;
166 int run(CmdCtx *p, void *buff, size_t size, uint32_t addr);
168 private:
169 uint32_t m_download_addr;
170 int32_t m_Ivt;
171 int m_PlugIn;
172 uint32_t m_max_download_pre_cmd;
173 uint32_t m_offset;
174 bool m_bIvtReserve;
175 bool m_bskipspl;
176 bool m_bskipfhdr;
179 class SDPJumpCmd : public SDPCmdBase
181 public:
182 SDPJumpCmd(char*p);
183 int run(CmdCtx *p) override;
185 private:
186 bool m_clear_dcd = false;
187 int32_t m_Ivt;
188 uint32_t m_jump_addr = 0;
189 bool m_PlugIn;
192 class SDPSkipDCDCmd :public SDPCmdBase
194 public:
195 SDPSkipDCDCmd(char *p);
196 int run(CmdCtx *p) override;
199 class SDPStatusCmd :public SDPCmdBase
201 public:
202 SDPStatusCmd(char *p);
203 int run(CmdCtx *p) override;
206 class SDPBootCmd : public SDPCmdBase
208 public:
209 SDPBootCmd(char *p);
210 int run(CmdCtx *p) override;
212 private:
213 bool m_clear_dcd = false;
214 uint32_t m_dcd_addr = 0;
215 bool m_nojump = false;