blob: 72622b62b8523785bdaa321891a8bd448d572f33 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*******************************************************************************
2 * Copyright (C) 2016, ZIXC Corporation.
3 *
4 * File Name: cmd_getvar.c
5 * File Mark:
6 * Description: get information such as IMEI,SN,NV CONFIG from UE.
7 * Others:
8 * Version: 1.0
9 * Author: zangxiaofeng
10 * Date: 2013-3-6
11 * History 1:
12 * Date: 2013-11-6
13 * Version:
14 * Author:
15 * Modification: mod for after-sale tool
16 * History 2:
17 ********************************************************************************/
18/****************************************************************************
19* Include files
20****************************************************************************/
21#include <common.h>
22#include <command.h>
23#include <net.h>
24#include "downloader_serial.h"
25#include <jffs2/load_kernel.h>
26#include "downloader_nand.h"
27#include "errno.h"
28
29extern char *tsp_console_buffer;
30
31/****************************************************************************
32* Local Macros
33****************************************************************************/
34
35/*NVR AMT LENGTH*/
36#define ZPS_ImeiLen 20
37#define ZPS_ImeiSvLen 20
38#define ZPS_DEV_MSINFO_MAX_BORDNAME_LEN 20
39#define ZPS_DEV_MSINFO_MAX_MSerialNum_LEN 20
40#define ZPS_DEV_MSINFO_MAX_ValidFlag_LEN 4
41#define ZPS_DEV_MSINFO_MAX_InternalMAC_LEN 20
42#define ZPS_DEV_MSINFO_MAX_ExternalMAC_LEN 20
43#define ZPS_DEV_MSINFO_MAX_WIFIMAC_LEN 20
44#define ZPS_DEV_MSINFO_MAX_NvVersion_LEN 40
45#define ZPS_DEV_MSINFO_MAX_TestInfo_LEN 200
46#define ZPS_DEV_MSINFO_MAX_SOFTVERSION_LEN 10
47#define ZPS_NVR_LEN 394
48
49/*NVRW AMT LENGTH*/
50#define SoftVersion_LEN 10
51#define Register_LEN 77
52#define Bflag_LEN 1
53#define Reserve_LEN 40
54#define AfterSaleVersion_LEN 670
55#define InerVersion_LEN 100
56#define ExVersion_LEN 100
57#define HWVersion_LEN 100
58#define PCUIVersion_LEN 100
59#define InerMdelNum_LEN 32
60#define ExModelNum_LEN 32
61#define ModemVersion_LEN 100
62#define ZPS_NVRW_LEN 1362
63
64/****************************************************************************
65* Local Types
66****************************************************************************/
67typedef struct
68{
69 unsigned int nvID; /*NV file ID */
70 unsigned char nvPart[4]; /* NV partition name,nvr or nvrw */
71 unsigned int addr; /*NV file address */
72 unsigned int size; /*NV file size*/
73}Tsp_Nv_Config_Item; /*NV CONFIG ITEM*/
74
75#define TSP_NV_COUNT 7
76Tsp_Nv_Config_Item tspNvConfig[TSP_NV_COUNT]=
77{
78{0,"nvro",0x0,16384},
79{1,"nvro",0x4000,98304},
80{2,"nvro",0x1c000,32768},
81{3,"nvro",0x24000,16384},
82{4,"nvro",0x28000,32768},
83{5,"nvro",0x30000,32768},
84{6,"nvro",0x38000,32768},
85};
86
87
88typedef struct getvar_info_nvr
89{
90
91 /********************************************************************************
92 ¹¦ÄÜ£º Ó²¼þÉ豸ºÅ
93 ȡֵ·¶Î§£ºIMEIÖÐÿһ¸öBCDÂ뷶ΧΪ0-9
94 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
95 *********************************************************************************/
96 unsigned char abImei[ZPS_ImeiLen];
97
98 /********************************************************************************
99 ¹¦ÄÜ£º Èí¼þ°æ±¾ºÅ
100 ȡֵ·¶Î§£ºIMEISVÖÐÿһ¸öBCDÂ뷶ΧΪ0-9
101 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
102 *********************************************************************************/
103 unsigned char abImeiSv[ZPS_ImeiSvLen];
104
105 /********************************************************************************
106 ¹¦ÄÜ£º Ö÷°åºÅ£¬ÓÉBCDÂë×é³É
107 ȡֵ·¶Î§£ºÖ÷°åºÅÖÐÿһ¸öBCDÂ뷶ΧΪ0-9
108 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
109 *********************************************************************************/
110 unsigned char abBordNum[ZPS_DEV_MSINFO_MAX_BORDNAME_LEN];
111
112 /********************************************************************************
113 ¹¦ÄÜ£º
114 ȡֵ·¶Î§£ºÈÎÒâ×Ö·û´®,ÒÔ'\0'±íʾ½áÊø
115 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
116 *********************************************************************************/
117 unsigned char abMSerialNum[ZPS_DEV_MSINFO_MAX_MSerialNum_LEN];
118
119 /********************************************************************************
120 ¹¦ÄÜ£º MACµØÖ·Ñ¡Ôñ±ê־λ
121 ȡֵ·¶Î§£º0x30»òÕß0x31£¬Ä¬ÈÏΪ0x30
122 ³ö³§Öµ£º0x30
123 *********************************************************************************/
124 unsigned char abValidFlag[ZPS_DEV_MSINFO_MAX_ValidFlag_LEN];
125
126 /********************************************************************************
127 ¹¦ÄÜ£º ÄÚ²¿MAC µØÖ·
128 ȡֵ·¶Î§£ºBCDÂë
129 ³ö³§Öµ£ºÓÉ´ó°æ±¾Ê×´ÎÆô¶¯Ê±Ð´Èë
130 *********************************************************************************/
131 unsigned char abInternalMAC[ZPS_DEV_MSINFO_MAX_InternalMAC_LEN];
132
133 /********************************************************************************
134 ¹¦ÄÜ£º ÍⲿMAC µØÖ·
135 ȡֵ·¶Î§£ºBCDÂë
136 ³ö³§Öµ£ºÓÉ´ó°æ±¾Ê×´ÎÆô¶¯Ê±Ð´Èë
137 *********************************************************************************/
138 unsigned char abExternalMAX[ZPS_DEV_MSINFO_MAX_ExternalMAC_LEN];
139
140 /********************************************************************************
141 ¹¦ÄÜ£º WIFI MACµØÖ·
142 ȡֵ·¶Î§£ºBCDÂë
143 ³ö³§Öµ£ºÓÉ´ó°æ±¾Ê×´ÎÆô¶¯Ê±Ð´Èë
144 *********************************************************************************/
145 unsigned char abWiFiMAC[ZPS_DEV_MSINFO_MAX_WIFIMAC_LEN];
146
147 /********************************************************************************
148 ¹¦ÄÜ£º ָʾNV°æ±¾
149 ȡֵ·¶Î§£º¿É¼ûASCIIÂë×Ö·û£¬ÒÔ×Ö·û'\0'½áÊø£¬Ê£Óà×Ö½ÚÌî³ä0x00
150 ³ö³§Öµ£ºÓÉ´ó°æ±¾Ê×´ÎÆô¶¯Ê±Ð´Èë
151 *********************************************************************************/
152 unsigned char abNVVersion[ZPS_DEV_MSINFO_MAX_NvVersion_LEN];
153
154 /********************************************************************************
155 ¹¦ÄÜ£º Éú²ú²âÊÔ±ê־λ
156 ȡֵ·¶Î§£º
157 ³ö³§Öµ£ºÓÉ´ó°æ±¾Ê×´ÎÆô¶¯Ê±Ð´Èë
158 *********************************************************************************/
159 unsigned char abTestInfo[ZPS_DEV_MSINFO_MAX_TestInfo_LEN];
160
161}getvar_info_nvr_t;
162
163typedef struct getvar_info_nvrw
164{
165
166 /********************************************************************************
167 ¹¦ÄÜ£º Èí¼þ°æ±¾ºÅ
168 ȡֵ·¶Î§£º
169 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
170 *********************************************************************************/
171 unsigned char SoftVersion[SoftVersion_LEN];
172
173 /********************************************************************************
174 ¹¦ÄÜ£º ×Ô×¢²áÐÅÏ¢
175 ȡֵ·¶Î§£º
176 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
177 *********************************************************************************/
178 unsigned char Register[Register_LEN];
179
180 /********************************************************************************
181 ¹¦ÄÜ£º BFLAGСϵͳÆô¶¯Ä£Ê½ÐÅÏ¢
182 ȡֵ·¶Î§£º
183 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
184 ********************************************************************************/
185 unsigned char Bflag[Bflag_LEN];
186
187 /********************************************************************************
188 ¹¦ÄÜ£º ±£Áô
189 ȡֵ·¶Î§£º
190 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
191 ********************************************************************************/
192 unsigned char Reserve[Reserve_LEN];
193
194 /********************************************************************************
195 ¹¦ÄÜ£º ÊÛºó°æ±¾¿ØÖÆ
196 ȡֵ·¶Î§£º
197 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
198 ********************************************************************************/
199 unsigned char AfterSaleVersion[AfterSaleVersion_LEN];
200
201 /********************************************************************************
202 ¹¦ÄÜ£º ÄÚ²¿°æ±¾ºÅ
203 ȡֵ·¶Î§£º
204 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
205 ********************************************************************************/
206 unsigned char InerVersion[InerVersion_LEN];
207
208 /********************************************************************************
209 ¹¦ÄÜ£ºÍⲿ°æ±¾ºÅ
210 ȡֵ·¶Î§£º
211 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
212 ********************************************************************************/
213 unsigned char ExVersion[ExVersion_LEN];
214
215 /********************************************************************************
216 ¹¦ÄÜ£ºÓ²¼þ°æ±¾ºÅ
217 ȡֵ·¶Î§£º
218 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
219 ********************************************************************************/
220 unsigned char HWVersion[HWVersion_LEN];
221
222 /********************************************************************************
223 ¹¦ÄÜ£ºPCUI °æ±¾ºÅ
224 ȡֵ·¶Î§£º
225 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
226 ********************************************************************************/
227 unsigned char PCUIVersion[PCUIVersion_LEN];
228
229 /********************************************************************************
230 ¹¦ÄÜ£ºÄÚ²¿ÐͺÅ
231 ȡֵ·¶Î§£º
232 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
233 ********************************************************************************/
234 unsigned char InerMdelNum[InerMdelNum_LEN];
235
236 /********************************************************************************
237 ¹¦ÄÜ£ºÍⲿÐͺÅ
238 ȡֵ·¶Î§£º
239 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
240 ********************************************************************************/
241 unsigned char ExModelNum[ExModelNum_LEN];
242
243 /********************************************************************************
244 ¹¦ÄÜ£ºMODEM°æ±¾ºÅ
245 ȡֵ·¶Î§£º
246 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
247 ********************************************************************************/
248 unsigned char ModemVersion[ModemVersion_LEN];
249}getvar_info_nvrw_t;
250
251typedef struct getvar_info_dl
252{
253 unsigned char abImei[ZPS_ImeiLen];
254 /********************************************************************************
255 ¹¦ÄÜ£º Ó²¼þÉ豸ºÅ
256 ȡֵ·¶Î§£ºIMEIÖÐÿһ¸öBCDÂ뷶ΧΪ0-9
257 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
258 *********************************************************************************/
259 unsigned char abBordNum[ZPS_DEV_MSINFO_MAX_BORDNAME_LEN];
260 /********************************************************************************
261 ¹¦ÄÜ£º Ö÷°åºÅ£¬ÓÉBCDÂë×é³É
262 ȡֵ·¶Î§£ºÖ÷°åºÅÖÐÿһ¸öBCDÂ뷶ΧΪ0-9
263 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
264 *********************************************************************************/
265 unsigned char InerVersion[InerVersion_LEN];
266 /********************************************************************************
267 ¹¦ÄÜ£º ÄÚ²¿°æ±¾ºÅ
268 ȡֵ·¶Î§£º
269 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
270 ********************************************************************************/
271 unsigned char ExVersion[ExVersion_LEN];
272 /********************************************************************************
273 ¹¦ÄÜ£ºÍⲿ°æ±¾ºÅ
274 ȡֵ·¶Î§£º
275 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
276 ********************************************************************************/
277 unsigned char InerMdelNum[InerMdelNum_LEN];
278 /********************************************************************************
279 ¹¦ÄÜ£ºÄÚ²¿ÐͺÅ
280 ȡֵ·¶Î§£º
281 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
282 ********************************************************************************/
283
284 unsigned char ExModelNum[ExModelNum_LEN];
285 /********************************************************************************
286 ¹¦ÄÜ£ºÍⲿÐͺÅ
287 ȡֵ·¶Î§£º
288 ³ö³§Öµ£ºÓɳö²ú³§É̾ö¶¨
289 ********************************************************************************/
290
291}getvar_info_dl_t;
292
293/*******************************************************************************
294 * Function:do_getvar
295 * Description:Sending UE information to After_sale update toll.
296 * Parameters:
297 * Input:
298 *
299 * Output:
300 *
301 * Returns:0 :success;
302 * -1:fail;
303 *
304 * Others:
305 ********************************************************************************/
306int do_getvar(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
307{
308#if 0 //hsy
309 char *ack = NULL;
310 char *cmd = NULL;
311 int ret = 0;
312 partition_entry_t *part = NULL;
313 getvar_info_nvr_t *info_nvr = NULL;
314 getvar_info_nvrw_t *info_nvrw = NULL;
315 getvar_info_dl_t *info_dl = NULL;
316
317 char *data_nvr = kzalloc(ZPS_NVR_LEN, GFP_KERNEL);
318 char *data_nvrw = kzalloc(ZPS_NVRW_LEN, GFP_KERNEL);
319 ack = tsp_console_buffer;
320 info_dl = kzalloc(4096, GFP_KERNEL);
321 cmd = argv[1];
322 if (argc < 2)
323 {
324 return cmd_usage(cmdtp);
325 }
326 part = downloader_get_part("nvro"); /*NVR READ*/
327 ret = downloader_zftl_read( part, 0, ZPS_NVR_LEN, (unsigned char *)data_nvr);
328
329 part = downloader_get_part("nvrw"); /*NVRW READ*/
330 ret = downloader_zftl_read( part, 0, ZPS_NVRW_LEN, (unsigned char *)data_nvrw);
331 if(ret)
332 {
333 sprintf(ack,"FAIL ZFTL READ ");
334 downloader_serial_write(ack, strlen(ack)+1);
335 kfree(data_nvr);
336 kfree(data_nvrw);
337 kfree(info_dl);
338 return ENOSYS; /* Function not implemented */
339 }
340 info_nvr = (getvar_info_nvr_t *)data_nvr;
341 info_nvrw = (getvar_info_nvrw_t *)data_nvrw;
342
343 memcpy(info_dl->abImei,info_nvr->abImei,ZPS_ImeiLen); /*copy information from NV*/
344 memcpy(info_dl->abBordNum,info_nvr->abBordNum,ZPS_DEV_MSINFO_MAX_BORDNAME_LEN);
345 memcpy(info_dl->InerVersion,info_nvrw->InerVersion,InerVersion_LEN);
346 memcpy(info_dl->ExVersion,info_nvrw->ExVersion,ExVersion_LEN);
347 memcpy(info_dl->InerMdelNum,info_nvrw->InerMdelNum,InerMdelNum_LEN);
348 memcpy(info_dl->ExModelNum,info_nvrw->ExModelNum,ExModelNum_LEN);
349
350 if(strcmp(cmd,"version") == 0)
351 {
352 sprintf(ack,"DATA %08x",sizeof(getvar_info_dl_t));
353 downloader_serial_write(ack, strlen(ack)+1); /* send length info*/
354
355 downloader_readline(tsp_console_buffer);
356 if(memcmp(tsp_console_buffer,"OKAY",4)==0) /* receive OKAY*/
357 {
358 memcpy(ack,info_dl,sizeof(getvar_info_dl_t)); /* send information*/
359 downloader_serial_write_actuallen(ack,sizeof(getvar_info_dl_t));
360 }
361 else
362 {
363 sprintf(ack,"FAIL COMMAND ERROR");
364 downloader_serial_write(ack, strlen(ack)+1);
365 return EBADRQC; /* Invalid request code */
366 }
367 }
368
369 else if(strcmp(cmd,"nv")== 0)
370 {
371 sprintf(ack,"DATA %08x",sizeof(tspNvConfig)+1);
372 downloader_serial_write(ack, strlen(ack)+1); /* send length info*/
373
374 downloader_readline(tsp_console_buffer);
375 if(memcmp(tsp_console_buffer,"OKAY",4)==0) /* receive OKAY*/
376 {
377 ack[0] = TSP_NV_COUNT;
378 memcpy(&ack[1],&tspNvConfig,sizeof(tspNvConfig)); /* send nv config*/
379 downloader_serial_write_actuallen(ack,sizeof(tspNvConfig)+1);
380 }
381 else
382 {
383 sprintf(ack,"FAIL COMMAND ERROR");
384 downloader_serial_write(ack, strlen(ack)+1);
385 return EBADRQC; /* Invalid request code */
386 }
387 }
388 else
389 {
390 sprintf(ack,"FAIL NOINFORMATION");
391 downloader_serial_write(ack,strlen(ack)+1);
392 kfree(data_nvr);
393 kfree(data_nvrw);
394 kfree(info_dl);
395 return -1;
396 }
397 kfree(data_nvr);
398 kfree(data_nvrw);
399 kfree(info_dl);
400#endif
401
402 return 0;
403}
404U_BOOT_CMD(
405 getvar, CONFIG_SYS_MAXARGS, 0, do_getvar,
406 "Downloader get information: getvar [info]",
407 ""
408);
409
410
411