blob: 0f1cf52efbf45e8aeec743310c422ec7f1e6b596 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*******************************************************************************
2 * Copyright (C) 2016, ZIXC Corporation.
3 *
4 * File Name:cmd_bbt_count.c
5 * File Mark:
6 * Description:
7 * Others:
8 * Version: 1.0
9 * Author: lankai
10 * Date: 2017-12-14
11 * History 1:
12 * Date:
13 * Version:
14 * Author:
15 * Modification:
16 * History 2:
17 ********************************************************************************/
18
19
20/****************************************************************************
21* Include files
22****************************************************************************/
23#include <common.h>
24#include <command.h>
25#include <nand.h>
26
27#include "downloader_serial.h"
28#include "errno.h"
29#include <partition_table.h>
30#include <boot_mode.h>
31
32/****************************************************************************
33* Global Function Prototypes
34****************************************************************************/
35int crc_switch_flag = 0;
36extern char *tsp_console_buffer;
37extern partition_table_t *g_partition_table_dl;
38extern partition_table_t *g_partition_table;
39
40
41/*******************************************************************************
42 * Function:do_bbt_count
43 * Description:
44 * Parameters:
45 * Input:
46 *
47 * Output:
48 *
49 * Returns:
50 *
51 *
52 * Others:
53 ********************************************************************************/
54 int do_bbt_count(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
55{
56 struct mtd_info *mtd = get_mtd_info();
57 struct nand_chip *this = NULL;
58 int bad_block_num = 0;
59 int total_block_num = 0;
60 char ack[64] = {0};
61
62 if(argc != 1)
63 {
64 return cmd_usage(cmdtp);
65 }
66
67 if (NULL == mtd)
68 {
69 printf("FAIL\n");
70 return ENODEV;
71 }
72
73 this = mtd->priv;
74 bad_block_num = mtd->ecc_stats.badblocks;
75 total_block_num = this->chipsize >> this->bbt_erase_shift;
76
77 sprintf(ack, "bad_block_num:%04d total_block_num:%04d", bad_block_num, total_block_num);
78 downloader_serial_write(ack, strlen(ack) + 1);
79
80 return 0;
81}
82
83U_BOOT_CMD(
84 bbt_count, CONFIG_SYS_MAXARGS, 0, do_bbt_count, "bbt_count", ""
85);
86
87/*******************************************************************************
88 * Function:do_crc
89 * Description:
90 * Parameters:
91 * Input:
92 *
93 * Output:
94 *
95 * Returns:
96 *
97 *
98 * Others:
99 ********************************************************************************/
100 int do_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
101{
102 u_char *crc_flag = NULL;
103 char *ack = tsp_console_buffer;
104
105 if(argc<2)
106 {
107 return cmd_usage(cmdtp);
108 }
109 crc_flag = argv[1];
110
111 if (strcmp((const char *)crc_flag,"on") == 0)
112 {
113 crc_switch_flag = 1;
114 sprintf(ack,"OKAY");
115 }
116 else if (strcmp((const char *)crc_flag,"off") == 0)
117 {
118 crc_switch_flag = 0;
119 sprintf(ack,"OKAY");
120 }
121 else
122 {
123 sprintf(ack,"FAIL COMMAND ERROR");
124 }
125
126 downloader_serial_write(ack, strlen(ack)+1);
127
128 return 0;
129}
130
131U_BOOT_CMD(
132 crc, CONFIG_SYS_MAXARGS, 0, do_crc, "crc_check", ""
133);
134
135
136/*******************************************************************************
137 * Function:do_crc
138 * Description:
139 * Parameters:
140 * Input:
141 *
142 * Output:
143 *
144 * Returns:
145 *
146 *
147 * Others:
148 ********************************************************************************/
149 int do_partition_bbc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
150{
151 int i, j, len, bad_nums, partition_nums;
152 char *ack = tsp_console_buffer;
153 nand_info_t *nand = &nand_info[nand_curr_device];
154
155 if(argc != 1)
156 {
157 return cmd_usage(cmdtp);
158 }
159
160 partition_entry_t *entry = NULL;
161 uint32_t entry_nums = 0;
162 if(get_load_mode() == TLOAD_MODE)
163 {
164 entry_nums = g_partition_table_dl->entrys;
165 entry = &g_partition_table_dl->table[0];
166 }
167 else
168 {
169 entry_nums = g_partition_table->entrys;
170 entry = &g_partition_table->table[0];
171 }
172
173 sprintf(ack, "partition_nums:%04d", entry_nums - 2);
174
175 printf("entry_nums=%d\n", entry_nums - 2);
176
177 for(i = 0; i < entry_nums - 2; i++)
178 {
179 printf("entry->part_offset=0x%x, entry->part_size=0x%x\n",
180 entry->part_offset, entry->part_size);
181 bad_nums = 0;
182 partition_nums = entry->part_size / nand->erasesize;
183 for(j = 0; j < partition_nums; j++)
184 {
185 if(nand_block_isbad (nand, entry->part_offset + (loff_t)j * nand->erasesize))
186 {
187 printf("bad block addr = 0x%x\n", (entry->part_offset + j * nand->erasesize));
188 bad_nums++;
189 }
190 }
191
192 len = strlen(ack);
193 sprintf(ack + len, " %s,%04d,%04d", entry->part_name, bad_nums, partition_nums);
194 entry++;
195 }
196
197 printf("partition_bbc:%s\n", ack);
198
199 downloader_serial_write(ack, strlen(ack) + 1);
200
201 return 0;
202}
203
204U_BOOT_CMD(
205 part_bbc, CONFIG_SYS_MAXARGS, 0, do_partition_bbc, "partition bad block count", ""
206);
207
208
209/*******************************************************************************
210 * Function:do_single_partition_bbc
211 * Description:
212 * Parameters:
213 * Input:
214 *
215 * Output:
216 *
217 * Returns:
218 *
219 *
220 * Others:
221 ********************************************************************************/
222 int do_single_partition_bbc(cmd_tbl_t *cmdtp, int flag,
223 int argc, char * const argv[])
224{
225 int j, bad_nums, part_block_nums;
226 u_char *partition_name = NULL;
227 char *ack = tsp_console_buffer;
228 nand_info_t *nand = &nand_info[nand_curr_device];
229 partition_entry_t *entry = NULL;
230
231 if(argc < 2)
232 {
233 return cmd_usage(cmdtp);
234 }
235
236 partition_name = argv[1];
237
238 entry = find_partition_para(partition_name);
239 if(entry == NULL)
240 {
241 BOOT_PRINTF(UBOOT_ERR, "[%s]: can't find the partition...\n", partition_name);
242 return 1;
243 }
244
245 printf("entry->part_offset=0x%x, entry->part_size=0x%x\n",
246 entry->part_offset, entry->part_size);
247 bad_nums = 0;
248 part_block_nums = entry->part_size / nand->erasesize;
249 for(j = 0; j < part_block_nums; j++)
250 {
251 if(nand_block_isbad (nand, entry->part_offset + (loff_t)j * nand->erasesize))
252 {
253 printf("bad block addr = 0x%x\n", (entry->part_offset + j * nand->erasesize));
254 bad_nums++;
255 }
256 }
257
258 sprintf(ack, "%s,%04d,%04d", entry->part_name, bad_nums, part_block_nums);
259 printf("single_partition_bbc:%s\n", ack);
260 downloader_serial_write(ack, strlen(ack) + 1);
261
262 return 0;
263}
264
265U_BOOT_CMD(
266 single_part_bbc, CONFIG_SYS_MAXARGS, 0, do_single_partition_bbc,
267 "single partition bad block count", ""
268);
269
270
271/*******************************************************************************
272 * Function:do_badblock_query
273 * Description:
274 * Parameters:
275 * Input:
276 *
277 * Output:
278 *
279 * Returns:
280 *
281 *
282 * Others:
283 ********************************************************************************/
284 int do_badblock_query(cmd_tbl_t *cmdtp,
285 int flag,
286 int argc,
287 char * const argv[])
288{
289 u_char *crc_flag = NULL;
290 int flash_type = 0;
291 char *ack = tsp_console_buffer;
292
293 if(argc != 1)
294 {
295 return cmd_usage(cmdtp);
296 }
297
298 crc_flag = argv[0];
299 if(strcmp((const char *)crc_flag,"badblock_query") != 0)
300 {
301 sprintf(ack,"COMMAND ERROR");
302 downloader_serial_write(ack, strlen(ack) + 1);
303 return -1;
304 }
305
306 flash_type = read_boot_flashtype();
307 switch(flash_type)
308 {
309 case IF_TYPE_NAND:
310 case IF_TYPE_SPI_NAND:
311 sprintf(ack,"SUPPORT");
312 break;
313 default:
314 sprintf(ack,"UNSUPPORT");
315 break;
316 }
317 downloader_serial_write(ack, strlen(ack) + 1);
318
319 return 0;
320}
321
322U_BOOT_CMD(
323 badblock_query, CONFIG_SYS_MAXARGS, 0, do_badblock_query,
324 "is support bad block query", ""
325);
326
327/*
328 ******************************************************************************
329 * Function:do_part_valid_space_query
330 * Description:
331 * Parameters:
332 * Input:
333 * Output:
334 * Returns:
335 * Others:
336 *******************************************************************************
337 */
338 int do_part_valid_space_query(cmd_tbl_t *cmdtp, int flag,
339 int argc, char * const argv[])
340{
341 int j, bad_nums, part_block_nums;
342 u_char *partition_name = NULL;
343 char *ack = tsp_console_buffer;
344 nand_info_t *nand = &nand_info[nand_curr_device];
345 partition_entry_t *entry = NULL;
346 int flash_type = 0;
347 unsigned int valid_space_size = 0;
348
349 if(argc < 2)
350 {
351 return cmd_usage(cmdtp);
352 }
353
354 partition_name = argv[1];
355
356 entry = find_partition_para(partition_name);
357 if(entry == NULL)
358 {
359 BOOT_PRINTF(UBOOT_ERR, "[%s]: can't find the partition...\n", partition_name);
360 sprintf(ack,"FAIL INVALID PARTITION");
361 downloader_serial_write(ack, strlen(ack)+1);
362 return -1;
363 }
364
365 flash_type = read_boot_flashtype();
366 if(flash_type == IF_TYPE_NOR)
367 {
368 valid_space_size = entry->part_size;
369 }
370 else
371 {
372 bad_nums = 0;
373 part_block_nums = entry->part_size / nand->erasesize;
374 for(j = 0; j < part_block_nums; j++)
375 {
376 if(nand_block_isbad (nand, entry->part_offset + (loff_t)j * nand->erasesize))
377 {
378 printf("bad block addr = 0x%x\n", (entry->part_offset + j * nand->erasesize));
379 bad_nums++;
380 }
381 }
382 valid_space_size = entry->part_size - bad_nums * nand->erasesize;
383 }
384
385 sprintf(ack, "%s,%08x", entry->part_name, valid_space_size);
386 printf("part_valid_space_query:%s\n", ack);
387 downloader_serial_write(ack, strlen(ack) + 1);
388
389 return 0;
390}
391
392U_BOOT_CMD(
393 part_valid_space_query, CONFIG_SYS_MAXARGS, 0, do_part_valid_space_query,
394 "get partition valid physics space size", ""
395);
396
397
398