blob: ea98e1593c5f518f1859fc29d7074c42c4b41a73 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
2 * (C) Copyright 2013 Marvell company.
3 */
4#include <common.h>
5#include "ddr_tests.h"
6
7#define MTSP_MSG_WRITING_OFFSET 13
8
9uint32_t exit_when_error = 1;
10uint32_t mtsp_total_error;
11uint32_t smtd_stat;
12uint32_t smtd_pat = 0x55555555;
13static uint32_t bit_byte_check;
14static uint32_t byte_err_sta[4];
15static uint32_t bit_err_sta[32];
16
17#ifdef LOG_SILENT
18static enum print_mode logout_mode = SILENT_MODE;
19#else
20static enum print_mode logout_mode = FULL_MODE;
21#endif
22
23static const struct pattern_dword pattern_list[] = {
24 {0x00000000, 0xFFFFFFFF},
25 {0x55AA55AA, 0xAA55AA55},
26 {0x7FFF7FFF, 0x80008000},
27 {0xFFFFFFFF, 0xFFFFFFFF},/*+decrement*/
28 {0x55555555, 0xAAAAAAAA},
29 {0x7F7F7F7F, 0x80808080},/*+rotate*/
30 {0x7FFF7FFF, 0x80008000},/*+rotate*/
31 {0x7FFFFFFF, 0x80000000},/*+rotate*/
32 {0x01010101, 0xFEFEFEFE},/*+rotate left*/
33 {0x00010001, 0xFFFEFFFE},/*+rotate left*/
34 {0x00000001, 0xFFFFFFFE},/*+rotate left*/
35 {0x7F7F7F7F, 0x7F7F7F7F},/*+rotate + without second pattern*/
36 {0x7FFF7FFF, 0x7FFF7FFF},/*+rotate + without second pattern*/
37 {0x7FFFFFFF, 0x7FFFFFFF},/*+rotate + without second pattern*/
38 {0x01010101, 0x01010101},/*+rotate left*/
39 {0x00010001, 0x00010001},/*+rotate left*/
40 {0x00000001, 0x00000001},/*+rotate left*/
41 {0x01010101, 0xFFFFFFFF},/*+rotate left*/
42 {0x00010001, 0xFFFFFFFF},/*+rotate left*/
43 {0x00000001, 0xFFFFFFFF},/*+rotate left*/
44 {0xFEFEFEFE, 0x00000000},/*+rotate left*/
45 {0xFFFEFFFE, 0x00000000},/*+rotate left*/
46 {0xFFFFFFFE, 0x00000000},/*+rotate left*/
47 {0x00000000, 0x00000001},/*+32 bytes+rotate left*/
48 {0x00000001, 0x00000001},/*+32 bytes+rotate left*/
49 {0x00000000, 0x00000001},/*+32 bytes+rotate left*/
50 {0x00000000, 0x00000001},/*+32 bytes+rotate left*/
51 {0x00000000, 0xFFFFFFFF},/*FREQ*/
52 {0x00000000, 0x00000000},/*increment*/
53 {0x00000001, 0x00000000},/*special test*/
54 {0x00000001, 0xFFFFFFFF},/*special test*/
55 {0x00000001, 0x00000000},/*special test*/
56};
57
58#ifndef LOG_SILENT
59const char mtsp_msg_read[7] = {"Reading"};
60const char mtsp_msg_write[7] = {"Writing"};
61char mtsp_test_msg[32][85] = {
62 {"0x00000001 - Writing Analog data pattern - Start\n"},
63 {"0x00000002 - Writing Constant data pattern - Start\n"},
64 {"0x00000004 - Writing Complement data pattern - Start\n"},
65 {"0x00000008 - Writing Decrement data pattern - Start\n"},
66 {"0x00000010 - Writing Miller Effect data pattern - Start\n"},
67 {"0x00000020 - Writing Zero Rotate Right & Invert Byte data "
68 "pattern - Start\n"},
69 {"0x00000040 - Writing Zero Rotate Right & Invert Word data "
70 "pattern - Start\n"},
71 {"0x00000080 - Writing Zero Rotate Right & Invert DoubleWord data "
72 "pattern - Start\n"},
73 {"0x00000100 - Writing One Rotate left & Invert Byte data "
74 "pattern - Start\n"},
75 {"0x00000200 - Writing One Rotate left & Invert Word data "
76 "pattern - Start\n"},
77 {"0x00000400 - Writing One Rotate left & Invert DoubleWord data "
78 "pattern - Start\n"},
79 {"0x00000800 - Writing Zero Rotate Right Byte data "
80 "pattern - Start\n"},
81 {"0x00001000 - Writing Zero Rotate Right Word data pattern - Start\n"},
82 {"0x00002000 - Writing Zero Rotate Right DoubleWord data "
83 "pattern - Start\n"},
84 {"0x00004000 - Writing One Rotate left Byte data pattern - Start\n"},
85 {"0x00008000 - Writing One Rotate left Word data pattern - Start\n"},
86 {"0x00010000 - Writing One Rotate left DoubleWord data "
87 "pattern - Start\n"},
88 {"0x00020000 - Writing Walking 1 Byte data pattern - Start\n"},
89 {"0x00040000 - Writing Walking 1 Word data pattern - Start\n"},
90 {"0x00080000 - Writing Walking 1 DoubleWord data pattern - Start\n"},
91 {"0x00100000 - Writing Walking Zero Byte data pattern - Start\n"},
92 {"0x00200000 - Writing Walking Zero Word data pattern - Start\n"},
93 {"0x00400000 - Writing Walking Zero DoubleWord data "
94 "pattern - Start\n"},
95 {"0x00800000 - Writing Single Signal Tailgating 0101_0000 data "
96 "pattern - Start\n"},
97 {"0x01000000 - Writing Single Signal Tailgating 0101_1111 data "
98 "pattern - Start\n"},
99 {"0x02000000 - Writing Single Signal Tailgating 0101_1010 data "
100 "pattern - Start\n"},
101 {"0x04000000 - Writing Multiple Signal Tailgating data "
102 "pattern - Start\n"},
103 {"0x08000000 - Writing Frequency Sweep data pattern - Start\n"},
104 {"0x10000000 - Writing Vertical increment data pattern - Start\n"},
105 {"0x20000000 - Writing Horzontal increment data pattern - Start\n"},
106 {"0x40000000 - Writing fixed 2nd pattern 0xFFFFFFFF - Start\n"},
107 {"0x80000000 - Writing fixed 2nd pattern 0x00000000 - Start\n"},
108};
109#endif
110
111/**
112* print_error - This function prints an error message to the user
113* @addr - where data failed
114* @access - BYTE,HWORD or WORD
115* @data - the current read
116* @expected - expected data
117*/
118void print_error(uint32_t addr, enum access_type access,
119 uint32_t data, uint32_t expected)
120{
121 int bit, byte;
122 if (bit_byte_check) {
123 for (bit = 0; bit < 32; bit++) {
124 if ((data & (1 << bit)) != (expected & (1 << bit)))
125 bit_err_sta[bit % 32]++;
126 }
127 for (byte = 0; byte < 4; byte++) {
128 if ((data & (0xFF << (byte * 8))) !=
129 (expected & (0xFF << (byte * 8))))
130 byte_err_sta[byte % 4]++;
131 }
132 }
133 if (logout_mode == FULL_MODE) {
134 printf("\nERROR: Expecting ");
135 switch (access) {
136 case ACCESS_TYPE_BYTE:
137 printb((uint8_t)expected & 0xFF);
138 break;
139 case ACCESS_TYPE_HWORD:
140 printh((uint16_t)expected & 0xFFFF);
141 break;
142 case ACCESS_TYPE_WORD:
143 printw(expected);
144 break;
145 default:
146 break;
147 }
148 printf(" at address ");
149 printw(addr);
150 printf(". Actual = ");
151 switch (access) {
152 case ACCESS_TYPE_BYTE:
153 printb((uint8_t)data & 0xFF);
154 break;
155 case ACCESS_TYPE_HWORD:
156 printh((uint16_t)data & 0xFFFF);
157 break;
158 case ACCESS_TYPE_WORD:
159 printw(data);
160 break;
161 default:
162 break;
163 }
164 printf("\n");
165 }
166}
167
168/**
169* memory_test_type1 - This function tests the wanted memory
170* according to parameters
171* @addr - start address for memory to be tested
172* @size - size of memory to be tested
173* @first_pattern - pattern to test the memory
174* @second_pattern - pattern to test the memory
175* @pattern - kind of pattern to test the memory
176* if test pass, returen 0;if test failed - see error value
177*/
178uint32_t memory_test_type1(uint32_t addr, uint32_t size,
179 uint32_t first_pattern,
180 uint32_t second_pattern, uint32_t pattern)
181{
182 uint32_t i = 0, j = 0, error = 0;
183 uint32_t *temp = (uint32_t *)addr;
184 uint32_t first_pattern_restore = first_pattern;
185 uint32_t second_pattern_restore = second_pattern;
186
187 while (j < size) {
188 /*Write the data*/
189 temp[i++] = (uint32_t)(first_pattern);
190 temp[i++] = (uint32_t)(second_pattern);
191 j += 8;
192 }
193 printf("write pass\n");
194#ifndef LOG_SILENT
195 /*Inform user that test has continue - read sequence*/
196 for (i = 0; i < 7; i++) {
197 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
198 mtsp_msg_read[i];
199 }
200 if (logout_mode == FULL_MODE)
201 printf("%s", (char *)mtsp_test_msg[pattern]);
202#endif
203 j = 0;
204 i = 0;
205 /*Restore patterns*/
206 first_pattern = first_pattern_restore;
207 second_pattern = second_pattern_restore;
208 while (j < size) {
209 /*Read the data and compare it to the pattern*/
210 if (temp[i++] != (uint32_t)(first_pattern)) {
211 if (!error)
212 printf("\n Read Fail\n");
213 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
214 temp[i-1], first_pattern);
215 mtsp_total_error++;
216 error++;
217 if (exit_when_error)
218 return MTSP_READ_FAIL;
219 }
220 if (temp[i++] != (uint32_t)(second_pattern)) {
221 if (!error)
222 printf("\n Read Fail\n");
223 print_error((uint32_t)temp + j + 4, ACCESS_TYPE_WORD,
224 temp[i-1], second_pattern);
225 mtsp_total_error++;
226 error++;
227 if (exit_when_error)
228 return MTSP_READ_FAIL;
229 }
230 j += 8;
231 }
232 if (error == 0)
233 printf("read pass");
234 return MTSP_OPERATION_OK;
235}
236
237/**
238* memory_test_type2 - This function tests the wanted memory
239* according to parameters
240* @addr - start address for memory to be tested
241* @size - size of memory to be tested
242* @first_pattern - pattern to test the memory
243* @pattern - kind of pattern to test the memory
244* @increment - if its increment or decrement
245* if test pass, returen 0;if test failed - see error value
246*/
247uint32_t memory_test_type2(uint32_t addr, uint32_t size,
248 uint32_t first_pattern,
249 uint32_t pattern, uint8_t increment)
250{
251 uint32_t i = 0, j = 0, error = 0;
252 uint32_t *temp = (uint32_t *)addr;
253 uint32_t first_pattern_restore = first_pattern;
254 int inc;
255
256 if (increment)
257 inc = 1;
258 else
259 inc = -1;
260 while (j < size) {
261 /*Write the data*/
262 temp[i++] = (uint32_t)(first_pattern);
263 j += 4;
264 first_pattern = first_pattern + inc;
265 }
266 printf("write pass\n");
267#ifndef LOG_SILENT
268 /*Inform user that test has continue - read sequence*/
269 for (i = 0; i < 7; i++) {
270 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
271 mtsp_msg_read[i];
272 }
273 if (logout_mode == FULL_MODE)
274 printf("%s", (char *)mtsp_test_msg[pattern]);
275#endif
276 /*Perform activities between write to read*/
277 j = 0;
278 i = 0;
279 /*Restore patterns*/
280 first_pattern = first_pattern_restore;
281 while (j < size) {
282 /*Read the data and compare it to the pattern*/
283 if (temp[i++] != (uint32_t)(first_pattern)) {
284 if (!error)
285 printf("\n Read Fail\n");
286 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
287 temp[i-1], first_pattern);
288 mtsp_total_error++;
289 error++;
290 if (exit_when_error)
291 return MTSP_READ_FAIL;
292 }
293 j += 4;
294 first_pattern = first_pattern + inc;
295 }
296 if (error == 0)
297 printf("read pass");
298 return MTSP_OPERATION_OK;
299}
300
301/**
302* memory_test_type3 - This function tests the wanted memory
303* according to parameters
304* @addr - start address for memory to be tested
305* @size - size of memory to be tested
306* @first_pattern - pattern to test the memory
307* @second_pattern - pattern to test the memory
308* @pattern - kind of pattern to test the memory
309* @left - it the rotation is left or right
310* if test pass, returen 0;if test failed - see error value
311*/
312uint32_t memory_test_type3(uint32_t addr, uint32_t size,
313 uint32_t first_pattern,
314 uint32_t second_pattern,
315 uint32_t pattern, uint8_t left)
316{
317 uint32_t i = 0, j = 0, error = 0;
318 uint32_t *temp = (uint32_t *)addr;
319 uint32_t first_pattern_restore = first_pattern;
320 uint32_t second_pattern_restore = second_pattern;
321 uint32_t rotate_number;
322
323 if (left)
324 rotate_number = 31;
325 else
326 rotate_number = 1;
327 while (j < size) {
328 /*Write the data*/
329 temp[i++] = (uint32_t)(first_pattern);
330 temp[i++] = (uint32_t)(second_pattern);
331 j += 8;
332 rotate(first_pattern, rotate_number);
333 rotate(second_pattern, rotate_number);
334 }
335 printf("write pass\n");
336#ifndef LOG_SILENT
337 /*Inform user that test has continue - read sequence*/
338 for (i = 0; i < 7; i++) {
339 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
340 mtsp_msg_read[i];
341 }
342 if (logout_mode == FULL_MODE)
343 printf("%s", (char *)mtsp_test_msg[pattern]);
344#endif
345 j = 0;
346 i = 0;
347 /*Restore patterns*/
348 first_pattern = first_pattern_restore;
349 second_pattern = second_pattern_restore;
350 while (j < size) {
351 /*Read the data and compare it to the pattern*/
352 if (temp[i++] != (uint32_t)(first_pattern)) {
353 if (!error)
354 printf("\n Read Fail\n");
355 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
356 temp[i-1], first_pattern);
357 mtsp_total_error++;
358 error++;
359 if (exit_when_error)
360 return MTSP_READ_FAIL;
361 }
362 if (temp[i++] != (uint32_t)(second_pattern)) {
363 if (!error)
364 printf("\n Read Fail\n");
365 print_error((uint32_t)temp + j + 4, ACCESS_TYPE_WORD,
366 temp[i-1], second_pattern);
367 mtsp_total_error++;
368 error++;
369 if (exit_when_error)
370 return MTSP_READ_FAIL;
371 }
372 j += 8;
373 rotate(first_pattern, rotate_number);
374 rotate(second_pattern, rotate_number);
375 }
376 if (error == 0)
377 printf("read pass");
378 return MTSP_OPERATION_OK;
379}
380
381/**
382* memory_test_type4 - This function tests the wanted memory
383* according to parameters
384* @addr - start address for memory to be tested
385* @size - size of memory to be tested
386* @first_pattern - pattern to test the memory
387* @pattern - kind of pattern to test the memory
388* @left - it the rotation is left or right
389* if test pass, returen 0;if test failed - see error value
390*/
391uint32_t memory_test_type4(uint32_t addr, uint32_t size,
392 uint32_t first_pattern,
393 uint32_t pattern, uint8_t left)
394{
395 uint32_t i = 0, j = 0, error = 0;
396 uint32_t *temp = (uint32_t *)addr;
397 uint32_t first_pattern_restore = first_pattern;
398 uint32_t rotate_number;
399 if (left)
400 rotate_number = 31;
401 else
402 rotate_number = 1;
403 while (j < size) {
404 /*Write the data*/
405 temp[i++] = (uint32_t)(first_pattern);
406 j += 4;
407 rotate(first_pattern, rotate_number);
408 }
409 printf("write pass\n");
410#ifndef LOG_SILENT
411 /*Inform user that test has continue - read sequence*/
412 for (i = 0; i < 7; i++) {
413 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
414 mtsp_msg_read[i];
415 }
416 if (logout_mode == FULL_MODE)
417 printf("%s", (char *)mtsp_test_msg[pattern]);
418#endif
419 j = 0;
420 i = 0;
421 /*Restore patterns*/
422 first_pattern = first_pattern_restore;
423 while (j < size) {
424 /*Read the data and compare it to the pattern*/
425 if (temp[i++] != (uint32_t)(first_pattern)) {
426 if (!error)
427 printf("\n Read Fail\n");
428 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
429 temp[i-1], first_pattern);
430 mtsp_total_error++;
431 error++;
432 if (exit_when_error)
433 return MTSP_READ_FAIL;
434 }
435 j += 4;
436 rotate(first_pattern, rotate_number);
437 }
438 if (error == 0)
439 printf("read pass");
440 return MTSP_OPERATION_OK;
441}
442
443/**
444* memory_test_type5 - This function tests the wanted memory
445* according to parameters
446* @addr - start address for memory to be tested
447* @size - size of memory to be tested
448* @first_pattern - pattern to test the memory
449* @second_pattern - pattern to test the memory
450* @pattern - kind of pattern to test the memory
451* if test pass, returen 0;if test failed - see error value
452*/
453uint32_t memory_test_type5(uint32_t addr, uint32_t size,
454 uint32_t first_pattern,
455 uint32_t second_pattern, uint32_t pattern)
456{
457 uint32_t i = 0, j = 0, error = 0;
458 uint32_t *temp = (uint32_t *)addr;
459 uint32_t first_pattern_restore = first_pattern;
460 uint32_t second_pattern_restore = second_pattern;
461
462 while (j < size) {
463 /*Write the data*/
464 temp[i++] = (uint32_t)(first_pattern);
465 temp[i++] = (uint32_t)(second_pattern);
466 j += 8;
467 rotate(first_pattern, 31);
468 }
469 printf("write pass\n");
470#ifndef LOG_SILENT
471 /*Inform user that test has continue - read sequence*/
472 for (i = 0; i < 7; i++) {
473 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
474 mtsp_msg_read[i];
475 }
476 if (logout_mode == FULL_MODE)
477 printf("%s", (char *)mtsp_test_msg[pattern]);
478#endif
479 j = 0;
480 i = 0;
481 /*Restore patterns*/
482 first_pattern = first_pattern_restore;
483 second_pattern = second_pattern_restore;
484 while (j < size) {
485 /*Read the data and compare it to the pattern*/
486 if (temp[i++] != (uint32_t)(first_pattern)) {
487 if (!error)
488 printf("\n Read Fail\n");
489 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
490 temp[i-1], first_pattern);
491 mtsp_total_error++;
492 error++;
493 if (exit_when_error)
494 return MTSP_READ_FAIL;
495 }
496 if (temp[i++] != (uint32_t)(second_pattern)) {
497 if (!error)
498 printf("\n Read Fail\n");
499 print_error((uint32_t)temp + j + 4, ACCESS_TYPE_WORD,
500 temp[i-1], second_pattern);
501 mtsp_total_error++;
502 error++;
503 if (exit_when_error)
504 return MTSP_READ_FAIL;
505 }
506 j += 8;
507 rotate(first_pattern, 31);
508 }
509 if (error == 0)
510 printf("read pass");
511 return MTSP_OPERATION_OK;
512}
513
514/**
515* memory_test_type6 - This function tests the wanted memory
516* according to parameters
517* @addr - start address for memory to be tested
518* @size - size of memory to be tested
519* @first_pattern - pattern to test the memory
520* @second_pattern - pattern to test the memory
521* @pattern - kind of pattern to test the memory
522* if test pass, returen 0;if test failed - see error value
523*/
524uint32_t memory_test_type6(uint32_t addr, uint32_t size,
525 uint32_t first_pattern,
526 uint32_t second_pattern, uint32_t pattern)
527{
528 uint32_t i = 0, j = 0, error = 0;
529 uint32_t temp_val;
530 uint32_t *temp = (uint32_t *)addr;
531 uint32_t first_pattern_restore = first_pattern;
532 uint32_t second_pattern_restore = second_pattern;
533
534 while (j < size) {
535 /*Write the data*/
536 temp[i++] = 0x0;
537 temp_val = (uint32_t)(first_pattern | second_pattern);
538 temp[i++] = temp_val;
539 temp[i++] = 0x0;
540 temp[i++] = temp_val;
541 temp[i++] = (uint32_t)(first_pattern);
542 temp[i++] = (uint32_t)(first_pattern);
543 temp[i++] = (uint32_t)(first_pattern);
544 temp[i++] = (uint32_t)(first_pattern);
545 j += 32;
546 rotate(first_pattern, 31);
547 rotate(second_pattern, 31);
548 }
549 printf("write pass\n");
550#ifndef LOG_SILENT
551 /*Inform user that test has continue - read sequence*/
552 for (i = 0; i < 7; i++) {
553 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
554 mtsp_msg_read[i];
555 }
556 if (logout_mode == FULL_MODE)
557 printf("%s", (char *)mtsp_test_msg[pattern]);
558#endif
559 j = 0;
560 i = 0;
561 /*Restore patterns*/
562 first_pattern = first_pattern_restore;
563 second_pattern = second_pattern_restore;
564 while (j < size) {
565 /*Read the data and compare it to the pattern*/
566 if (temp[i++] != 0x0) {
567 if (!error)
568 printf("\n Read Fail");
569 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
570 temp[i-1], 0x0);
571 mtsp_total_error++;
572 error++;
573 if (exit_when_error)
574 return MTSP_READ_FAIL;
575 }
576 temp_val = (uint32_t)(first_pattern | second_pattern);
577 if (temp[i++] != temp_val) {
578 if (!error)
579 printf("\n Read Fail");
580 print_error((uint32_t)temp + j + 4, ACCESS_TYPE_WORD,
581 temp[i-1], temp_val);
582 mtsp_total_error++;
583 error++;
584 if (exit_when_error)
585 return MTSP_READ_FAIL;
586 }
587 if (temp[i++] != 0x0) {
588 if (!error)
589 printf("\n Read Fail");
590 print_error((uint32_t)temp + j + 8, ACCESS_TYPE_WORD,
591 temp[i-1], 0x0);
592 mtsp_total_error++;
593 error++;
594 if (exit_when_error)
595 return MTSP_READ_FAIL;
596 }
597 if (temp[i++] != temp_val) {
598 if (!error)
599 printf("\n Read Fail");
600 print_error((uint32_t)temp + j + 12, ACCESS_TYPE_WORD,
601 temp[i-1], temp_val);
602 mtsp_total_error++;
603 error++;
604 if (exit_when_error)
605 return MTSP_READ_FAIL;
606 }
607 if (temp[i++] != (uint32_t)(first_pattern)) {
608 if (!error)
609 printf("\n Read Fail");
610 print_error((uint32_t)temp + j + 16, ACCESS_TYPE_WORD,
611 temp[i-1], first_pattern);
612 mtsp_total_error++;
613 error++;
614 if (exit_when_error)
615 return MTSP_READ_FAIL;
616 }
617 if (temp[i++] != (uint32_t)(first_pattern)) {
618 if (!error)
619 printf("\n Read Fail");
620 print_error((uint32_t)temp + j + 20, ACCESS_TYPE_WORD,
621 temp[i-1], first_pattern);
622 mtsp_total_error++;
623 error++;
624 if (exit_when_error)
625 return MTSP_READ_FAIL;
626 }
627 if (temp[i++] != (uint32_t)(first_pattern)) {
628 if (!error)
629 printf("\n Read Fail");
630 print_error((uint32_t)temp + j + 24, ACCESS_TYPE_WORD,
631 temp[i-1], first_pattern);
632 mtsp_total_error++;
633 error++;
634 if (exit_when_error)
635 return MTSP_READ_FAIL;
636 }
637 if (temp[i++] != (uint32_t)(first_pattern)) {
638 if (!error)
639 printf("\n Read Fail");
640 print_error((uint32_t)temp + j + 28, ACCESS_TYPE_WORD,
641 temp[i-1], first_pattern);
642 mtsp_total_error++;
643 error++;
644 if (exit_when_error)
645 return MTSP_READ_FAIL;
646 }
647 j += 32;
648 rotate(first_pattern, 31);
649 rotate(second_pattern, 31);
650 }
651 if (error == 0)
652 printf("read pass");
653 return MTSP_OPERATION_OK;
654}
655
656/**
657* memory_test_type7 - This function tests the wanted memory
658* according to parameters
659* @addr - start address for memory to be tested
660* @size - size of memory to be tested
661* @first_pattern - pattern to test the memory
662* @second_pattern - pattern to test the memory
663* @pattern - kind of pattern to test the memory
664* if test pass, returen 0;if test failed - see error value
665*/
666uint32_t memory_test_type7(uint32_t addr, uint32_t size,
667 uint32_t first_pattern,
668 uint32_t second_pattern, uint32_t pattern)
669{
670 uint32_t i = 0, j = 0, error = 0;
671 uint32_t temp_val;
672 uint32_t *temp = (uint32_t *)addr;
673 uint32_t first_pattern_restore = first_pattern;
674 uint32_t second_pattern_restore = second_pattern;
675
676 while (j < size) {
677 /*Write the data*/
678 temp[i++] = 0x0;
679 temp_val = (uint32_t)(first_pattern | second_pattern);
680 temp[i++] = temp_val;
681 temp[i++] = 0x0;
682 temp[i++] = temp_val;
683 temp[i++] = (uint32_t)(first_pattern);
684 temp[i++] = 0x0;
685 temp[i++] = (uint32_t)(first_pattern);
686 temp[i++] = 0x0;
687 j += 32;
688 rotate(first_pattern, 31);
689 rotate(second_pattern, 31);
690 }
691 printf("write pass\n");
692#ifndef LOG_SILENT
693 /*Inform user that test has continue - read sequence*/
694 for (i = 0; i < 7; i++) {
695 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
696 mtsp_msg_read[i];
697 }
698 if (logout_mode == FULL_MODE)
699 printf("%s", (char *)mtsp_test_msg[pattern]);
700#endif
701 j = 0;
702 i = 0;
703 /*Restore patterns*/
704 first_pattern = first_pattern_restore;
705 second_pattern = second_pattern_restore;
706 while (j < size) {
707 /*Read the data and compare it to the pattern*/
708 if (temp[i++] != 0x0) {
709 if (!error)
710 printf("\n Read Fail");
711 print_error((uint32_t)temp + j, ACCESS_TYPE_WORD,
712 temp[i-1], 0x0);
713 mtsp_total_error++;
714 error++;
715 if (exit_when_error)
716 return MTSP_READ_FAIL;
717 }
718 temp_val = (uint32_t)(first_pattern | second_pattern);
719 if (temp[i++] != temp_val) {
720 if (!error)
721 printf("\n Read Fail");
722 print_error((uint32_t)temp + j + 4, ACCESS_TYPE_WORD,
723 temp[i-1], temp_val);
724 mtsp_total_error++;
725 error++;
726 if (exit_when_error)
727 return MTSP_READ_FAIL;
728 }
729 if (temp[i++] != 0x0) {
730 if (!error)
731 printf("\n Read Fail");
732 print_error((uint32_t)temp + j + 8, ACCESS_TYPE_WORD,
733 temp[i-1], 0x0);
734 mtsp_total_error++;
735 error++;
736 if (exit_when_error)
737 return MTSP_READ_FAIL;
738 }
739 if (temp[i++] != temp_val) {
740 if (!error)
741 printf("\n Read Fail");
742 print_error((uint32_t)temp + j + 12, ACCESS_TYPE_WORD,
743 temp[i-1], temp_val);
744 mtsp_total_error++;
745 error++;
746 if (exit_when_error)
747 return MTSP_READ_FAIL;
748 }
749 if (temp[i++] != (uint32_t)(first_pattern)) {
750 if (!error)
751 printf("\n Read Fail");
752 print_error((uint32_t)temp + j + 16, ACCESS_TYPE_WORD,
753 temp[i-1], first_pattern);
754 mtsp_total_error++;
755 error++;
756 if (exit_when_error)
757 return MTSP_READ_FAIL;
758 }
759
760 if (temp[i++] != 0x0) {
761 if (!error)
762 printf("\n Read Fail");
763 print_error((uint32_t)temp + j + 20, ACCESS_TYPE_WORD,
764 temp[i-1], 0x0);
765 mtsp_total_error++;
766 error++;
767 if (exit_when_error)
768 return MTSP_READ_FAIL;
769 }
770
771 if (temp[i++] != (uint32_t)(first_pattern)) {
772 if (!error)
773 printf("\n Read Fail");
774 print_error((uint32_t)temp + j + 24, ACCESS_TYPE_WORD,
775 temp[i-1], first_pattern);
776 mtsp_total_error++;
777 error++;
778 if (exit_when_error)
779 return MTSP_READ_FAIL;
780 }
781
782 if (temp[i++] != 0x0) {
783 if (!error)
784 printf("\n Read Fail");
785 print_error((uint32_t)temp + j + 28, ACCESS_TYPE_WORD,
786 temp[i-1], 0x0);
787 mtsp_total_error++;
788 error++;
789 if (exit_when_error)
790 return MTSP_READ_FAIL;
791 }
792
793 j += 32;
794
795 rotate(first_pattern, 31);
796 rotate(second_pattern, 31);
797 }
798
799 if (error == 0)
800 printf("read pass");
801 return MTSP_OPERATION_OK;
802}
803
804/**
805* memory_test_type8 - This function tests the wanted memory
806* according to parameters
807* @addr - start address for memory to be tested
808* @size - size of memory to be tested
809* @first_pattern - pattern to test the memory
810* @second_pattern - pattern to test the memory
811* @pattern - kind of pattern to test the memory
812* if test pass, returen 0;if test failed - see error value
813*/
814uint32_t memory_test_type8(uint32_t addr, uint32_t size,
815 uint32_t first_pattern,
816 uint32_t second_pattern, uint32_t pattern)
817{
818 uint32_t i = 0, j = 0, error = 0;
819 int loop = 1, freq;
820 int end_test = 0;
821 uint32_t *temp = (uint32_t *)addr;
822 uint32_t first_pattern_restore = first_pattern;
823 uint32_t second_pattern_restore = second_pattern;
824
825 /*Infinite loop - if J=>size break the loop*/
826 for (;;) {
827 /*Write the data*/
828 freq = loop;
829 while (freq) {
830 temp[i++] = (uint32_t)(first_pattern);
831 j += 4;
832 if (j >= size) {
833 end_test = 1;
834 freq = 1;
835 break;
836 }
837 freq--;
838 }
839 if (end_test)
840 break;
841 freq = loop;
842 while (freq) {
843 temp[i++] = (uint32_t)(second_pattern);
844 j += 4;
845 if (j >= size) {
846 end_test = 1;
847 freq = 1;
848 break;
849 }
850 freq--;
851 }
852 if (end_test)
853 break;
854 loop++;
855 if (loop == 0x100)
856 loop = 1;
857 }
858 printf("write pass\n");
859#ifndef LOG_SILENT
860 /*Inform user that test has continue - read sequence*/
861 for (i = 0; i < 7; i++) {
862 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
863 mtsp_msg_read[i];
864 }
865 if (logout_mode == FULL_MODE)
866 printf("%s", (char *)mtsp_test_msg[pattern]);
867#endif
868 j = 0;
869 i = 0;
870 loop = 1;
871 /*Restore patterns*/
872 first_pattern = first_pattern_restore;
873 second_pattern = second_pattern_restore;
874 /*Infinite loop - if J=>size break the loop*/
875 for (;;) {
876 /*Write the data*/
877 freq = loop;
878 while (freq) {
879 if (temp[i++] != (uint32_t)(first_pattern)) {
880 if (!error)
881 printf("\n Read Fail");
882 print_error((uint32_t)temp + j,
883 ACCESS_TYPE_WORD, temp[i-1],
884 first_pattern);
885 mtsp_total_error++;
886 error++;
887 if (exit_when_error)
888 return MTSP_READ_FAIL;
889 }
890 j += 4;
891 if (j >= size) {
892 end_test = 1;
893 freq = 1;
894 break;
895 }
896 freq--;
897 }
898 if (end_test)
899 break;
900 freq = loop;
901 while (freq) {
902 if (temp[i++] != (uint32_t)(second_pattern)) {
903 if (!error)
904 printf("\n Read Fail");
905 print_error((uint32_t)temp + j,
906 ACCESS_TYPE_WORD, temp[i-1],
907 second_pattern);
908 mtsp_total_error++;
909 error++;
910 if (exit_when_error)
911 return MTSP_READ_FAIL;
912 }
913 j += 4;
914 if (j >= size) {
915 end_test = 1;
916 freq = 1;
917 break;
918 }
919 freq--;
920 }
921 if (end_test)
922 break;
923 loop++;
924 if (loop == 0x100)
925 loop = 1;
926 }
927 if (error == 0)
928 printf("read pass");
929 return MTSP_OPERATION_OK;
930}
931
932/**
933* memory_test_type9 - This function tests the wanted memory
934* according to parameters
935* @addr - start address for memory to be tested
936* @size - size of memory to be tested
937* @first_pattern - pattern to test the memory
938* @second_pattern - pattern to test the memory
939* @pattern - kind of pattern to test the memory
940* if test pass, returen 0;if test failed - see error value
941*/
942uint32_t memory_test_type9(uint32_t addr, uint32_t size,
943 uint32_t first_pattern,
944 uint32_t second_pattern, uint32_t pattern)
945{
946 uint32_t i = 0, j = 0, error = 0;
947 uint32_t *temp = (uint32_t *)addr;
948 uint32_t first_pattern_restore = first_pattern;
949 uint32_t second_pattern_restore = second_pattern;
950 uint32_t addr_restore = addr;
951
952 while (j < size) {
953 /*Write the data*/
954 if (addr & 0x20) {
955 temp[i] = (uint32_t)(first_pattern);
956 temp[i + 1] = (uint32_t)(second_pattern);
957 } else {
958 temp[i] = 0x0;
959 temp[i + 1] = 0x0;
960 }
961 if (addr & 0x40) {
962 temp[i + 2] = (uint32_t)(first_pattern);
963 temp[i + 3] = (uint32_t)(second_pattern);
964 } else {
965 temp[i + 2] = 0x0;
966 temp[i + 3] = 0x0;
967 }
968 if (addr&0x80) {
969 temp[i + 4] = (uint32_t)(first_pattern);
970 temp[i + 5] = (uint32_t)(second_pattern);
971 } else {
972 temp[i + 4] = 0x0;
973 temp[i + 5] = 0x0;
974 }
975 if (addr&0x100) {
976 temp[i + 6] = (uint32_t)(first_pattern);
977 temp[i + 7] = (uint32_t)(second_pattern);
978 } else {
979 temp[i + 6] = 0x0;
980 temp[i + 7] = 0x0;
981 }
982 i += 8;
983 j += 32;
984 addr += 32;
985 if (!(addr & 0x1E0)) {
986 if (((uint32_t)(first_pattern)) == 0x80000000) {
987 second_pattern = 0x1;
988 first_pattern = 0x0;
989 } else if (((uint32_t)(second_pattern)) == 0x80000000) {
990 second_pattern = 0x0;
991 first_pattern = 0x1;
992 } else {
993 second_pattern = second_pattern << 1;
994 first_pattern = first_pattern << 1;
995 }
996 }
997 }
998 printf("write pass\n");
999#ifndef LOG_SILENT
1000 /*Inform user that test has continue - read sequence*/
1001 for (i = 0; i < 7; i++) {
1002 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i] =
1003 mtsp_msg_read[i];
1004 }
1005 if (logout_mode == FULL_MODE)
1006 printf("%s", (char *)mtsp_test_msg[pattern]);
1007#endif
1008 j = 0;
1009 i = 0;
1010 /*Restore patterns*/
1011 first_pattern = first_pattern_restore;
1012 second_pattern = second_pattern_restore;
1013 addr = addr_restore;
1014 while (j < size) {
1015 /*Write the data*/
1016 if (addr & 0x20) {
1017 if (temp[i] != (uint32_t)(first_pattern)) {
1018 if (!error)
1019 printf("\n Read Fail");
1020 print_error((uint32_t)temp + j,
1021 ACCESS_TYPE_WORD,
1022 temp[i], first_pattern);
1023 mtsp_total_error++;
1024 error++;
1025 if (exit_when_error)
1026 return MTSP_READ_FAIL;
1027 }
1028 if (temp[i + 1] != (uint32_t)(second_pattern)) {
1029 if (!error)
1030 printf("\n Read Fail");
1031 print_error((uint32_t)temp + j + 4,
1032 ACCESS_TYPE_WORD,
1033 temp[i + 1], second_pattern);
1034 mtsp_total_error++;
1035 error++;
1036 if (exit_when_error)
1037 return MTSP_READ_FAIL;
1038 }
1039 } else {
1040 if (temp[i] != 0x0) {
1041 if (!error)
1042 printf("\n Read Fail");
1043 print_error((uint32_t)temp + j,
1044 ACCESS_TYPE_WORD,
1045 temp[i], 0x0);
1046 mtsp_total_error++;
1047 error++;
1048 if (exit_when_error)
1049 return MTSP_READ_FAIL;
1050 }
1051 if (temp[i + 1] != 0x0) {
1052 if (!error)
1053 printf("\n Read Fail");
1054 print_error((uint32_t)temp + j + 4,
1055 ACCESS_TYPE_WORD,
1056 temp[i + 1], 0x0);
1057 mtsp_total_error++;
1058 error++;
1059 if (exit_when_error)
1060 return MTSP_READ_FAIL;
1061 }
1062 }
1063 if (addr&0x40) {
1064 if (temp[i + 2] != (uint32_t)(first_pattern)) {
1065 if (!error)
1066 printf("\n Read Fail");
1067 print_error((uint32_t)temp + j + 8,
1068 ACCESS_TYPE_WORD,
1069 temp[i + 2], first_pattern);
1070 mtsp_total_error++;
1071 error++;
1072 if (exit_when_error)
1073 return MTSP_READ_FAIL;
1074 }
1075 if (temp[i + 3] != (uint32_t)(second_pattern)) {
1076 if (!error)
1077 printf("\n Read Fail");
1078 print_error((uint32_t)temp + j + 12,
1079 ACCESS_TYPE_WORD,
1080 temp[i + 3], second_pattern);
1081 mtsp_total_error++;
1082 error++;
1083 if (exit_when_error)
1084 return MTSP_READ_FAIL;
1085 }
1086 } else {
1087 if (temp[i + 2] != 0x0) {
1088 if (!error)
1089 printf("\n Read Fail");
1090 print_error((uint32_t)temp + j + 8,
1091 ACCESS_TYPE_WORD,
1092 temp[i + 2], 0x0);
1093 mtsp_total_error++;
1094 error++;
1095 if (exit_when_error)
1096 return MTSP_READ_FAIL;
1097 }
1098 if (temp[i + 3] != 0x0) {
1099 if (!error)
1100 printf("\n Read Fail");
1101 print_error((uint32_t)temp + j + 12,
1102 ACCESS_TYPE_WORD,
1103 temp[i + 3], 0x0);
1104 mtsp_total_error++;
1105 error++;
1106 if (exit_when_error)
1107 return MTSP_READ_FAIL;
1108 }
1109 }
1110 if (addr&0x80) {
1111 if (temp[i + 4] != (uint32_t)(first_pattern)) {
1112 printf("\n Read Fail");
1113 if (!error)
1114 printf("\n Read Fail");
1115 print_error((uint32_t)temp + j + 16,
1116 ACCESS_TYPE_WORD,
1117 temp[i + 4], first_pattern);
1118 mtsp_total_error++;
1119 error++;
1120 if (exit_when_error)
1121 return MTSP_READ_FAIL;
1122 }
1123 if (temp[i + 5] != (uint32_t)(second_pattern)) {
1124 if (!error)
1125 printf("\n Read Fail");
1126 print_error((uint32_t)temp + j + 20,
1127 ACCESS_TYPE_WORD,
1128 temp[i + 5], second_pattern);
1129 mtsp_total_error++;
1130 error++;
1131 if (exit_when_error)
1132 return MTSP_READ_FAIL;
1133 }
1134 } else {
1135 if (temp[i + 4] != 0x0) {
1136 if (!error)
1137 printf("\n Read Fail");
1138 print_error((uint32_t)temp + j + 16,
1139 ACCESS_TYPE_WORD,
1140 temp[i + 4], 0x0);
1141 mtsp_total_error++;
1142 error++;
1143 if (exit_when_error)
1144 return MTSP_READ_FAIL;
1145 }
1146 if (temp[i + 5] != 0x0) {
1147 if (!error)
1148 printf("\n Read Fail");
1149 print_error((uint32_t)temp + j + 20,
1150 ACCESS_TYPE_WORD,
1151 temp[i + 5], 0x0);
1152 mtsp_total_error++;
1153 error++;
1154 if (exit_when_error)
1155 return MTSP_READ_FAIL;
1156 }
1157 }
1158 if (addr&0x100) {
1159 if (temp[i + 6] != (uint32_t)(first_pattern)) {
1160 if (!error)
1161 printf("\n Read Fail");
1162 print_error((uint32_t)temp + j + 24,
1163 ACCESS_TYPE_WORD,
1164 temp[i + 6], first_pattern);
1165 mtsp_total_error++;
1166 error++;
1167 if (exit_when_error)
1168 return MTSP_READ_FAIL;
1169 }
1170 if (temp[i + 7] != (uint32_t)(second_pattern)) {
1171 if (!error)
1172 printf("\n Read Fail");
1173 print_error((uint32_t)temp + j + 28,
1174 ACCESS_TYPE_WORD,
1175 temp[i + 7], second_pattern);
1176 mtsp_total_error++;
1177 error++;
1178 if (exit_when_error)
1179 return MTSP_READ_FAIL;
1180 }
1181 } else {
1182 if (temp[i + 6] != 0x0) {
1183 if (!error)
1184 printf("\n Read Fail");
1185 print_error((uint32_t)temp + j + 24,
1186 ACCESS_TYPE_WORD,
1187 temp[i + 6], 0x0);
1188 mtsp_total_error++;
1189 error++;
1190 if (exit_when_error)
1191 return MTSP_READ_FAIL;
1192 }
1193 if (temp[i + 7] != 0x0) {
1194 if (!error)
1195 printf("\n Read Fail");
1196 print_error((uint32_t)temp + j + 28,
1197 ACCESS_TYPE_WORD,
1198 temp[i + 7], 0x0);
1199 mtsp_total_error++;
1200 error++;
1201 if (exit_when_error)
1202 return MTSP_READ_FAIL;
1203 }
1204 }
1205 i += 8;
1206 j += 32;
1207 addr += 32;
1208 if (!(addr & 0x1E0)) {
1209 if (((uint32_t)(first_pattern)) == 0x80000000) {
1210 second_pattern = 0x1;
1211 first_pattern = 0x0;
1212 } else if (((uint32_t)(second_pattern)) == 0x80000000) {
1213 second_pattern = 0x0;
1214 first_pattern = 0x1;
1215 } else {
1216 second_pattern = second_pattern << 1;
1217 first_pattern = first_pattern << 1;
1218 }
1219 }
1220 }
1221 if (error == 0)
1222 printf("read pass");
1223 return MTSP_OPERATION_OK;
1224}
1225
1226/**
1227* memory_test - This function tests the wanted memory
1228* according to parameters
1229* @addr - start address for memory to be tested
1230* @size - size of memory to be tested
1231* @pattern - kind of pattern to test the memory
1232* @access - BYTE,WORD or DWORD
1233* @mtsp - to define if the test is MTSP type
1234* if test pass, returen 0;if test failed - see error value
1235*/
1236uint32_t memory_test(uint32_t addr, uint32_t size,
1237 enum pattern_number pattern, uint8_t access, uint8_t mtsp)
1238{
1239 uint32_t i = 0, j = 0;
1240 uint8_t mtsp_rc = MTSP_OPERATION_OK;
1241 uint32_t first_pattern = 0, second_pattern = 0;
1242 uint8_t *t_addr8 = (uint8_t *)addr;
1243 uint16_t *t_addr16 = (uint16_t *)addr;
1244 uint32_t *temp = (uint32_t *)addr;
1245#ifndef LOG_SILENT
1246 char SUCCESS_SIGN = '.';
1247#endif
1248 /*Get the desired pattern but only for WORD patterns*/
1249 if (mtsp) {
1250 if (smtd_stat&0x1) {
1251 first_pattern = smtd_pat;
1252 second_pattern = ~smtd_pat;
1253 } else {
1254 first_pattern = pattern_list[pattern].first_pattern;
1255 second_pattern = pattern_list[pattern].second_pattern;
1256 }
1257#ifndef LOG_SILENT
1258 if (logout_mode == FULL_MODE) {
1259 /*Inform user that test has begun - write sequence*/
1260 printf("%s", (char *)mtsp_test_msg[pattern]);
1261 } else if (logout_mode == SIGN_MODE)
1262 putc(SUCCESS_SIGN);
1263#endif
1264 /*Call test functions*/
1265 switch (pattern) {
1266 case PATTERN_NUMBER_ONE:
1267 case PATTERN_NUMBER_TWO:
1268 case PATTERN_NUMBER_THREE:
1269 case PATTERN_NUMBER_FIVE:
1270 mtsp_rc = memory_test_type1(addr, size, first_pattern,
1271 second_pattern, pattern);
1272 break;
1273 case PATTERN_NUMBER_FOUR:
1274 mtsp_rc = memory_test_type2(addr, size, first_pattern,
1275 pattern, 0);
1276 break;
1277 case PATTERN_NUMBER_SIX:
1278 case PATTERN_NUMBER_SEVEN:
1279 case PATTERN_NUMBER_EIGHT:
1280 mtsp_rc = memory_test_type3(addr, size, first_pattern,
1281 second_pattern, pattern, 0);
1282 break;
1283 case PATTERN_NUMBER_NINE:
1284 case PATTERN_NUMBER_TEN:
1285 case PATTERN_NUMBER_ELEVEN:
1286 mtsp_rc = memory_test_type3(addr, size, first_pattern,
1287 second_pattern, pattern, 1);
1288 break;
1289 case PATTERN_NUMBER_TWELVE:
1290 case PATTERN_NUMBER_THIRTEEN:
1291 case PATTERN_NUMBER_FOURTEEN:
1292 mtsp_rc = memory_test_type4(addr, size, first_pattern,
1293 pattern, 0);
1294 break;
1295 case PATTERN_NUMBER_FIFTEEN:
1296 case PATTERN_NUMBER_SIXTEEN:
1297 case PATTERN_NUMBER_SEVENTEEN:
1298 mtsp_rc = memory_test_type4(addr, size,
1299 first_pattern, pattern, 1);
1300 break;
1301 case PATTERN_NUMBER_EIGHTEEN:
1302 case PATTERN_NUMBER_NINETEEN:
1303 case PATTERN_NUMBER_TWENTY:
1304 case PATTERN_NUMBER_TWENTYONE:
1305 case PATTERN_NUMBER_TWENTYTWO:
1306 case PATTERN_NUMBER_TWENTYTHREE:
1307 mtsp_rc = memory_test_type5(addr, size, first_pattern,
1308 second_pattern, pattern);
1309 break;
1310 case PATTERN_NUMBER_TWENTYFOUR:
1311 case PATTERN_NUMBER_TWENTYFIVE:
1312 case PATTERN_NUMBER_TWENTYSEVEN:
1313 mtsp_rc = memory_test_type6(addr, size, first_pattern,
1314 second_pattern, pattern);
1315 break;
1316 case PATTERN_NUMBER_TWENTYSIX:
1317 mtsp_rc = memory_test_type7(addr, size, first_pattern,
1318 second_pattern, pattern);
1319 break;
1320 case PATTERN_NUMBER_TWENTYEIGHT:
1321 mtsp_rc = memory_test_type8(addr, size, first_pattern,
1322 second_pattern, pattern);
1323 break;
1324 case PATTERN_NUMBER_TWENTYNINE:
1325 mtsp_rc = memory_test_type2(addr, size, first_pattern,
1326 pattern, 1);
1327 break;
1328 case PATTERN_NUMBER_THIRTY:
1329 mtsp_rc = memory_test_type9(addr, size, first_pattern,
1330 second_pattern, pattern);
1331 break;
1332 case PATTERN_NUMBER_THIRTYONE:
1333 mtsp_rc = memory_test_type1(addr, size, first_pattern,
1334 0xFFFFFFFF, pattern);
1335 break;
1336 case PATTERN_NUMBER_THIRTYTWO:
1337 mtsp_rc = memory_test_type1(addr, size, first_pattern,
1338 0x00000000, pattern);
1339 break;
1340 default:
1341 break;
1342 }
1343#ifndef LOG_SILENT
1344 if (logout_mode == FULL_MODE)
1345 printf("\n");
1346 /*Change back the string to write*/
1347 for (i = 0; i < 7; i++) {
1348 mtsp_test_msg[pattern][MTSP_MSG_WRITING_OFFSET + i]
1349 = mtsp_msg_write[i];
1350 }
1351#endif
1352 } else {
1353#ifndef LOG_SILENT
1354 /*Inform user for regular memory test on the desired memory*/
1355 if (logout_mode == FULL_MODE)
1356 printf("Regular memory test begins.\n");
1357#endif
1358 while (j < size) {
1359 switch (access) {
1360 case ACCESS_TYPE_BYTE:
1361 t_addr8[i] = (uint8_t)(pattern&0xFF);
1362 if (t_addr8[i++] != (uint8_t)(pattern&0xFF)) {
1363 print_error((uint32_t)t_addr8+j, access,
1364 t_addr8[i-1], pattern);
1365 mtsp_total_error++;
1366 if (exit_when_error)
1367 return MTSP_READ_FAIL;
1368 }
1369 j += 1;
1370 break;
1371 case ACCESS_TYPE_HWORD:
1372 t_addr16[i] = (uint16_t)(pattern&0xFFFF);
1373
1374 if (t_addr16[i++] !=
1375 (uint16_t)(pattern&0xFFFF)) {
1376 print_error((uint32_t)t_addr16+j,
1377 access, t_addr16[i-1],
1378 pattern);
1379 mtsp_total_error++;
1380 if (exit_when_error)
1381 return MTSP_READ_FAIL;
1382 }
1383 j += 2;
1384 break;
1385 case ACCESS_TYPE_WORD:
1386 temp[i] = (uint32_t)(pattern);
1387 if (temp[i++] != (uint32_t)(pattern)) {
1388 print_error((uint32_t)temp + j, access,
1389 temp[i-1], pattern);
1390 mtsp_total_error++;
1391 if (exit_when_error)
1392 return MTSP_READ_FAIL;
1393 }
1394 j += 4;
1395 break;
1396 default:
1397 return MTSP_WRONG_PARAMETER;
1398 }
1399 }
1400 mtsp_rc = MTSP_OPERATION_OK;
1401 }
1402 return mtsp_rc;
1403}
1404
1405uint32_t mtsp_test(uint32_t addr, uint32_t size, uint32_t pattern,
1406 uint32_t pre_read)
1407{
1408 uint32_t cur_pattern = 0;
1409 uint32_t index = 0x1;
1410 size_t i;
1411 uint8_t mtsp_rc = MTSP_OPERATION_OK;
1412 uint32_t tmsec = 0;
1413
1414 mtsp_total_error = 0;
1415 if (bit_byte_check) {
1416 for (i = 0; i < sizeof(byte_err_sta)/sizeof(uint32_t); i++)
1417 byte_err_sta[i] = 0;
1418 for (i = 0; i < sizeof(bit_err_sta)/sizeof(uint32_t); i++)
1419 bit_err_sta[i] = 0;
1420 }
1421 if (logout_mode == FULL_MODE) {
1422 /*Need to add many prints to the user - OR*/
1423 printf("MTSP test starts from:");
1424 printw(addr);
1425 printf(" to :");
1426 printw(addr + size);
1427 printf("\n");
1428 tmsec = get_timer(0);
1429 }
1430 for (i = 0; i < 32; i++) {
1431 cur_pattern = pattern & (index << i);
1432 if (cur_pattern) {
1433 mtsp_rc = memory_test(addr, size, i,
1434 ACCESS_TYPE_WORD, 1);
1435 if (mtsp_rc)
1436 break;
1437 }
1438
1439 }
1440 if (logout_mode == FULL_MODE) {
1441 tmsec = get_timer(0) - tmsec;
1442 printf("Elapsed time: %d msec\n", tmsec);
1443 if (mtsp_total_error)
1444 printf("mtsp mem test finished and %d errors occur\n",
1445 mtsp_total_error);
1446 else
1447 printf("mtsp memory test finished successfully.\n");
1448 } else if (logout_mode == SIGN_MODE)
1449 printf("\n");
1450
1451 if (logout_mode >= MINIMAL_MODE && logout_mode < FULL_MODE &&
1452 mtsp_total_error)
1453 printf("mstp--> Test failed\n");
1454 if (mtsp_total_error) {
1455 if (bit_byte_check) {
1456 printf("*** MTSP BYTE & BIT error statistics ***\n");
1457 for (i = 0; i < sizeof(byte_err_sta)/sizeof(uint32_t);
1458 i++)
1459 printf("BYTE %d error: %d\n",
1460 i, byte_err_sta[i]);
1461 printf("----------\n");
1462 for (i = 0; i < sizeof(bit_err_sta)/sizeof(uint32_t);
1463 i++)
1464 printf("BIT %d error: %d\n",
1465 i, bit_err_sta[i]);
1466 }
1467 return MTSP_READ_FAIL;
1468 }
1469 return mtsp_rc;
1470}
1471
1472int mtsp(int argc, uint8_t **argv)
1473{
1474 uint32_t mem_test_size, patterns_to_activate;
1475 uint32_t startAddr, test_times, i;
1476
1477 logout_mode = FULL_MODE;
1478 test_times = 1;
1479 switch (argc) {
1480 case 1:
1481 printf("mtsp--> Enter the start addr to be tested\n");
1482 break;
1483 case 2:
1484 printf("mtsp--> Enter number of byte to be tested\n");
1485 break;
1486 case 3:
1487 printf("mtsp--> Set bits of the test to be run\n");
1488 break;
1489 case 5:
1490 test_times = conv_dec((char *)argv[4]);
1491 case 4:
1492 mem_test_size = conv_hex((char *)argv[2]);
1493 startAddr = conv_hex((char *)argv[1]);
1494 patterns_to_activate = conv_hex((char *)argv[3]);
1495 for (i = 0; i < test_times; i++) {
1496 printf("\n**** MTSP TEST LOOP: %d *****\n", i + 1);
1497 if (mtsp_test(startAddr, mem_test_size,
1498 patterns_to_activate, 0))
1499 return -1;
1500 }
1501 break;
1502 default:
1503 break;
1504 }
1505 return 0;
1506}
1507
1508void bbu_smtd_help(void)
1509{
1510 printf("smtd - Set Memory Test Defaults.\n");
1511 printf("The SMTD command is used to set the memory test\n");
1512 printf("Usage:smtd [<pattern>]\n");
1513 printf("pattern = The first pattern for mtsp test\n");
1514 printf("Note: 1. Use 'smtd ena' to enable/disable default pattern\n");
1515 printf("2. Use 'smtd mode' to switch the mtsp test mode:\n");
1516 printf(" continue or terminate the test when error occurs\n");
1517 printf("3. Use 'smtd check' to enable/disable byte&bit check\n");
1518 printf("If no argument entered, will display current defaults\n");
1519}
1520
1521int smtd(int argc, uint8_t **argv)
1522{
1523 switch (argc) {
1524 case 1:
1525 if (smtd_stat == 0)
1526 printf("\nsmtd--> The default pattern is enabled\n");
1527 else
1528 printf("\nsmtd--> The default pattern is disabled\n");
1529 if (exit_when_error == 0)
1530 printf(" --> continue test when error happens\n");
1531 else
1532 printf(" --> exit test when error happens\n");
1533 if (bit_byte_check == 0)
1534 printf(" --> Byte and bit check is disabled\n");
1535 else
1536 printf(" --> Byte and bit check is enabled\n");
1537 break;
1538 case 2:
1539 if (!strcmp((const char *)argv[1], "ena")) {
1540 if (smtd_stat == 0) {
1541 smtd_stat = 1;
1542 printf("smtd--> default pattern is disabled\n");
1543 } else {
1544 smtd_stat = 0;
1545 printf("smtd--> default pattern is enabled\n");
1546 }
1547 } else if (!strcmp((const char *)argv[1], "mode")) {
1548 if (exit_when_error) {
1549 exit_when_error = 0;
1550 printf("smtd--> error occurs, test continue\n");
1551 } else {
1552 exit_when_error = 1;
1553 printf("smtd--> error occurs, test exit\n");
1554 }
1555 } else if (!strcmp((const char *)argv[1], "check")) {
1556 if (bit_byte_check) {
1557 bit_byte_check = 0;
1558 printf("smtd--> byte&bit check is disabled\n");
1559 } else {
1560 bit_byte_check = 1;
1561 printf("smtd--> byte&bit check is enabled\n");
1562 }
1563 } else
1564 smtd_pat = conv_hex((char *)argv[1]);
1565 break;
1566 default:
1567 bbu_smtd_help();
1568 break;
1569 }
1570 return 1;
1571}
1572
1573int do_mtsp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1574{
1575 return mtsp(argc, argv);
1576}
1577
1578U_BOOT_CMD(
1579 mtsp, 5, 1, do_mtsp,
1580 "Switch UART to another cpu",
1581 "Usage:\nuartsw [cpu id]"
1582 );
1583
1584int do_smtd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1585{
1586 return smtd(argc, argv);
1587}
1588
1589U_BOOT_CMD(
1590 smtd, 5, 1, do_smtd,
1591 "Switch UART to another cpu",
1592 "Usage:\nuartsw [cpu id]"
1593 );