Add NXP FB/FBK/SDPV device PID
[mfgtools.git] / libuuu / config.cpp
blob13c6747121968889cf4e6e774b4ccc735caf9974
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{"SDP:", "MX7D", nullptr, FSL_VID, 0x0076});
57 emplace_back(ConfigItem{"SDP:", "MX6Q", nullptr, FSL_VID, 0x0054});
58 emplace_back(ConfigItem{"SDP:", "MX6D", "MX6Q", FSL_VID, 0x0061});
59 emplace_back(ConfigItem{"SDP:", "MX6SL", "MX6Q", FSL_VID, 0x0063});
60 emplace_back(ConfigItem{"SDP:", "MX6SX", "MX6Q", FSL_VID, 0x0071});
61 emplace_back(ConfigItem{"SDP:", "MX6UL", "MX7D", FSL_VID, 0x007D});
62 emplace_back(ConfigItem{"SDP:", "MX6ULL", "MX7D", FSL_VID, 0x0080});
63 emplace_back(ConfigItem{"SDP:", "MX6SLL", "MX7D", NXP_VID, 0x0128});
64 emplace_back(ConfigItem{"SDP:", "MX7ULP", nullptr, NXP_VID, 0x0126});
65 emplace_back(ConfigItem{"SDP:", "MXRT106X", nullptr, NXP_VID, 0x0135});
66 emplace_back(ConfigItem{"SDP:", "MX8MM", "MX8MQ", NXP_VID, 0x0134});
67 emplace_back(ConfigItem{"SDP:", "MX8MQ", "MX8MQ", NXP_VID, 0x012B});
68 emplace_back(ConfigItem{"SDPU:", "SPL", "SPL", 0x0525, 0xB4A4, 0, 0x04FF});
69 emplace_back(ConfigItem{"SDPV:", "SPL1", "SPL", 0x0525, 0xB4A4, 0x0500, 0x9998});
70 emplace_back(ConfigItem{"SDPV:", "SPL1", "SPL", NXP_VID, 0x0151, 0x0500, 0x9998});
71 emplace_back(ConfigItem{"SDPU:", "SPL", "SPL", 0x0525, 0xB4A4, 0x9999, 0x9999}); /*old i.MX8 MQEVk use bcd 9999*/
72 emplace_back(ConfigItem{"SDPU:", "SPL", "SPL", BD_VID, 0x1001, 0, 0x04FF});
73 emplace_back(ConfigItem{"SDPV:", "SPL1", "SPL", BD_VID, 0x1001, 0x0500, 0x9998});
74 emplace_back(ConfigItem{"FBK:", nullptr, nullptr, 0x066F, 0x9AFE});
75 emplace_back(ConfigItem{"FBK:", nullptr, nullptr, 0x066F, 0x9BFF});
76 emplace_back(ConfigItem{"FBK:", nullptr, nullptr, NXP_VID, 0x0153});
77 emplace_back(ConfigItem{"FB:", nullptr, nullptr, 0x0525, 0xA4A5});
78 emplace_back(ConfigItem{"FB:", nullptr, nullptr, 0x18D1, 0x0D02});
79 emplace_back(ConfigItem{"FB:", nullptr, nullptr, BD_VID, 0x0001});
80 emplace_back(ConfigItem{"FB:", nullptr, nullptr, NXP_VID, 0x0152});
83 int uuu_for_each_cfg(uuu_show_cfg fn, void *p)
85 for (const auto &configItem : g_config)
87 if (fn(configItem.m_protocol.c_str(),
88 configItem.m_chip.c_str(),
89 configItem.m_compatible.c_str(),
90 configItem.m_vid,
91 configItem.m_pid,
92 configItem.m_bcdVerMin,
93 configItem.m_bcdVerMax,
94 p))
95 return -1;
97 return 0;
100 Config * get_config() noexcept
102 return &g_config;
105 ConfigItem * Config::find(uint16_t vid, uint16_t pid, uint16_t ver)
107 for (auto it = begin(); it != end(); it++)
109 if (vid == it->m_vid && pid == it->m_pid)
111 if (ver >= it->m_bcdVerMin && ver <= it->m_bcdVerMax)
112 return &(*it);
115 return nullptr;
118 Config Config::find(const string &pro)
120 Config items;
121 for (auto it = begin(); it != end(); it++)
123 if (it->m_protocol == pro)
124 items.emplace_back(*it);
126 return items;
129 int CfgCmd::run(CmdCtx *)
131 size_t pos = 0;
132 string param;
134 ConfigItem item;
135 param = get_next_param(m_cmd, pos);
137 if (str_to_upper(param) == "CFG:")
138 param = get_next_param(m_cmd, pos);
140 if (param.empty())
142 set_last_err_string("Wrong param");
143 return -1;
146 item.m_protocol = str_to_upper(param);
148 bool conversion_succeeded = false;
149 while (pos < m_cmd.size())
151 param = get_next_param(m_cmd, pos);
152 if (param == "-pid")
154 param = get_next_param(m_cmd, pos);
155 item.m_pid = str_to_uint16(param, &conversion_succeeded);
156 if (!conversion_succeeded) return -1;
157 continue;
159 if (param == "-vid")
161 param = get_next_param(m_cmd, pos);
162 item.m_vid = str_to_uint16(param, &conversion_succeeded);
163 if (!conversion_succeeded) return -1;
164 continue;
166 if (param == "-bcdversion")
168 param = get_next_param(m_cmd, pos);
169 item.m_bcdVerMin = item.m_bcdVerMax = str_to_uint16(param, &conversion_succeeded);
170 if (!conversion_succeeded) return -1;
171 continue;
173 if (param == "-bcdmin")
175 param = get_next_param(m_cmd, pos);
176 item.m_bcdVerMin = str_to_uint16(param, &conversion_succeeded);
177 if (!conversion_succeeded) return -1;
178 continue;
180 if (param == "-bcdmax")
182 param = get_next_param(m_cmd, pos);
183 item.m_bcdVerMax = str_to_uint16(param, &conversion_succeeded);
184 if (!conversion_succeeded) return -1;
185 continue;
187 if (param == "-chip")
189 param = get_next_param(m_cmd, pos);
190 item.m_chip = param;
191 continue;
193 if (param == "-compatible")
195 param = get_next_param(m_cmd, pos);
196 item.m_compatible = param;
197 continue;
201 ConfigItem *pItem= g_config.find(item.m_vid, item.m_pid, item.m_bcdVerMax);
202 if (pItem)
203 *pItem = item;
204 else
205 g_config.emplace_back(item);
207 return 0;