fix 'ret' have not initialized
[mfgtools.git] / libuuu / config.cpp
blob049f6f29104acdeaa1baa3265aca646d88b6f958
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 #include "config.h"
33 #include "cmd.h"
34 #include "libcomm.h"
35 #include "liberror.h"
36 #include "libuuu.h"
38 using namespace std;
40 static Config g_config;
42 constexpr uint16_t FSL_VID = 0x15A2;
43 constexpr uint16_t NXP_VID = 0x1FC9;
44 constexpr uint16_t BD_VID = 0x3016;
46 Config::Config()
48 emplace_back(ConfigItem{"SDPS:", "MX8QXP", nullptr, NXP_VID, 0x012F, 0x0002});
49 emplace_back(ConfigItem{"SDPS:", "MX8QM", "MX8QXP", NXP_VID, 0x0129, 0x0002});
50 emplace_back(ConfigItem{"SDPS:", "MX8DXL", "MX8QXP", NXP_VID, 0x0147});
51 emplace_back(ConfigItem{"SDPS:", "MX28", nullptr, FSL_VID, 0x004f});
52 emplace_back(ConfigItem{"SDPS:", "MX815", nullptr, NXP_VID, 0x013E});
53 emplace_back(ConfigItem{"SDPS:", "MX865", "MX815", NXP_VID, 0x0146});
54 emplace_back(ConfigItem{"SDPS:", "MX8ULP", "MX815", NXP_VID, 0x014A});
55 emplace_back(ConfigItem{"SDPS:", "MX8ULP", "MX815", NXP_VID, 0x014B});
56 emplace_back(ConfigItem{"SDPS:", "MX93", "MX815", NXP_VID, 0x014E});
57 emplace_back(ConfigItem{"SDPS:", "MX95", nullptr, NXP_VID, 0x015D});
58 emplace_back(ConfigItem{"SDP:", "MX7D", nullptr, FSL_VID, 0x0076});
59 emplace_back(ConfigItem{"SDP:", "MX6Q", nullptr, FSL_VID, 0x0054});
60 emplace_back(ConfigItem{"SDP:", "MX6D", "MX6Q", FSL_VID, 0x0061});
61 emplace_back(ConfigItem{"SDP:", "MX6SL", "MX6Q", FSL_VID, 0x0063});
62 emplace_back(ConfigItem{"SDP:", "MX6SX", "MX6Q", FSL_VID, 0x0071});
63 emplace_back(ConfigItem{"SDP:", "MX6UL", "MX7D", FSL_VID, 0x007D});
64 emplace_back(ConfigItem{"SDP:", "MX6ULL", "MX7D", FSL_VID, 0x0080});
65 emplace_back(ConfigItem{"SDP:", "MX6SLL", "MX7D", NXP_VID, 0x0128});
66 emplace_back(ConfigItem{"SDP:", "MX7ULP", nullptr, NXP_VID, 0x0126});
67 emplace_back(ConfigItem{"SDP:", "MXRT106X", nullptr, NXP_VID, 0x0135});
68 emplace_back(ConfigItem{"SDP:", "MX8MM", "MX8MQ", NXP_VID, 0x0134});
69 emplace_back(ConfigItem{"SDP:", "MX8MQ", "MX8MQ", NXP_VID, 0x012B});
70 emplace_back(ConfigItem{"SDPU:", "SPL", "SPL", 0x0525, 0xB4A4, 0, 0x04FF});
71 emplace_back(ConfigItem{"SDPV:", "SPL1", "SPL", 0x0525, 0xB4A4, 0x0500, 0x9998});
72 emplace_back(ConfigItem{"SDPV:", "SPL1", "SPL", NXP_VID, 0x0151, 0x0500, 0x9998});
73 emplace_back(ConfigItem{"SDPU:", "SPL", "SPL", 0x0525, 0xB4A4, 0x9999, 0x9999}); /*old i.MX8 MQEVk use bcd 9999*/
74 emplace_back(ConfigItem{"SDPU:", "SPL", "SPL", BD_VID, 0x1001, 0, 0x04FF});
75 emplace_back(ConfigItem{"SDPV:", "SPL1", "SPL", BD_VID, 0x1001, 0x0500, 0x9998});
76 emplace_back(ConfigItem{"FBK:", nullptr, nullptr, 0x066F, 0x9AFE});
77 emplace_back(ConfigItem{"FBK:", nullptr, nullptr, 0x066F, 0x9BFF});
78 emplace_back(ConfigItem{"FBK:", nullptr, nullptr, NXP_VID, 0x0153});
79 emplace_back(ConfigItem{"FB:", nullptr, nullptr, 0x0525, 0xA4A5});
80 emplace_back(ConfigItem{"FB:", nullptr, nullptr, 0x18D1, 0x0D02});
81 emplace_back(ConfigItem{"FB:", nullptr, nullptr, BD_VID, 0x0001});
82 emplace_back(ConfigItem{"FB:", nullptr, nullptr, NXP_VID, 0x0152});
83 emplace_back(ConfigItem{"FB:", nullptr, nullptr, 0x0483, 0x0afb});
86 int uuu_for_each_cfg(uuu_show_cfg fn, void *p)
88 for (const auto &configItem : g_config)
90 if (fn(configItem.m_protocol.c_str(),
91 configItem.m_chip.c_str(),
92 configItem.m_compatible.c_str(),
93 configItem.m_vid,
94 configItem.m_pid,
95 configItem.m_bcdVerMin,
96 configItem.m_bcdVerMax,
97 p))
98 return -1;
100 return 0;
103 Config * get_config() noexcept
105 return &g_config;
108 ConfigItem * Config::find(uint16_t vid, uint16_t pid, uint16_t ver)
110 for (auto it = begin(); it != end(); it++)
112 if (vid == it->m_vid && pid == it->m_pid)
114 if (ver >= it->m_bcdVerMin && ver <= it->m_bcdVerMax)
115 return &(*it);
118 return nullptr;
121 Config Config::find(const string &pro)
123 Config items;
124 for (auto it = begin(); it != end(); it++)
126 if (it->m_protocol == pro)
127 items.emplace_back(*it);
129 return items;
132 int CfgCmd::run(CmdCtx *)
134 size_t pos = 0;
135 string param;
137 ConfigItem item;
138 param = get_next_param(m_cmd, pos);
140 if (str_to_upper(param) == "CFG:")
141 param = get_next_param(m_cmd, pos);
143 if (param.empty())
145 set_last_err_string("Wrong param");
146 return -1;
149 item.m_protocol = str_to_upper(param);
151 bool conversion_succeeded = false;
152 while (pos < m_cmd.size())
154 param = get_next_param(m_cmd, pos);
155 if (param == "-pid")
157 param = get_next_param(m_cmd, pos);
158 item.m_pid = str_to_uint16(param, &conversion_succeeded);
159 if (!conversion_succeeded) return -1;
160 continue;
162 if (param == "-vid")
164 param = get_next_param(m_cmd, pos);
165 item.m_vid = str_to_uint16(param, &conversion_succeeded);
166 if (!conversion_succeeded) return -1;
167 continue;
169 if (param == "-bcdversion")
171 param = get_next_param(m_cmd, pos);
172 item.m_bcdVerMin = item.m_bcdVerMax = str_to_uint16(param, &conversion_succeeded);
173 if (!conversion_succeeded) return -1;
174 continue;
176 if (param == "-bcdmin")
178 param = get_next_param(m_cmd, pos);
179 item.m_bcdVerMin = str_to_uint16(param, &conversion_succeeded);
180 if (!conversion_succeeded) return -1;
181 continue;
183 if (param == "-bcdmax")
185 param = get_next_param(m_cmd, pos);
186 item.m_bcdVerMax = str_to_uint16(param, &conversion_succeeded);
187 if (!conversion_succeeded) return -1;
188 continue;
190 if (param == "-chip")
192 param = get_next_param(m_cmd, pos);
193 item.m_chip = param;
194 continue;
196 if (param == "-compatible")
198 param = get_next_param(m_cmd, pos);
199 item.m_compatible = param;
200 continue;
204 ConfigItem *pItem= g_config.find(item.m_vid, item.m_pid, item.m_bcdVerMax);
205 if (pItem)
206 *pItem = item;
207 else
208 g_config.emplace_back(item);
210 return 0;