添加了牛皮藓,主要方便不知情的人联系我。有洁癖者自己去除代码,在
[ddnasgpl.git] / diag / diag_memory.c
blob4ca64503f2f0e020250ebe21eb0e7e0bf161940f
2 #include <common.h>
4 #include "diag.h"
6 /*******************************************************************************
8 * Name : mem_data_bus_test
9 * Description : The function tests data bus of the DRAM. It writes walking one
10 * pattern to a fixed memory location.
11 * Input arg : None
12 * Output arg : None
13 * Return : Returns 1 on failure, else 0
14 *******************************************************************************/
16 int mem_data_bus_test(void)
18 unsigned int pattern = 1;
19 unsigned int *address = mem_test_start_offset;
21 printf("\tDDR2 data bus test ");
23 for(; pattern != 0; pattern <<= 1)
25 *address = pattern;
27 if(pattern != *address)
29 printf("FAILED\n");
30 printf("\t\tTest failed at offset = 0x%X\n"
31 "\t\tData written = 0x%X\n"
32 "\t\tData read = 0x%X\n", address,
33 pattern, *address);
34 return 1;
37 printf("PASSED\n");
38 return 0;
41 /*******************************************************************************
43 * Name : mem_address_bus_test
44 * Description : The function tests address bus of the DRAM. It writes walking
45 * one pattern while changes the addresses in the same way. i.e.
46 * write 1 to offset 1, 8 to offset 8, etc. Verify the data after
47 * writting to the buffer with length MEM_ADD_TEST_SIZE.
48 * Input arg : None
49 * Output arg : None
50 * Return : Returns 1 on failure, else 0
51 *******************************************************************************/
53 int mem_address_bus_test(void)
55 unsigned int offset = 1, size;
56 unsigned int *base_address = mem_test_start_offset;
58 size = mem_test_end_offset - mem_test_start_offset;
60 printf("\tDDR2 address bus test ");
62 /* We should start with pattern = 1. As we want to use offset and
63 * pattern the same variable, we will decrement base address by 1.
64 * So, even if we start with offset = pattern = 1, we have actually
65 * started from the given base address. */
66 base_address--;
68 for(; offset < size; offset <<= 1)
70 base_address[offset] = offset;
73 for(offset = 1; offset < size; offset <<= 1)
75 if(base_address[offset] != offset)
77 printf("FAILED\n");
78 printf("\t\tTest failed at offset = 0x%X\n"
79 "\t\tData written = 0x%X\n"
80 "\t\tData read = 0x%X\n", base_address
81 + offset, offset, base_address[offset]);
82 return 1;
85 printf("PASSED\n");
86 return 0;
89 /*******************************************************************************
91 * Name : mem_device_test
92 * Description : The function tests address bus of the DRAM. It writes walking
93 * one pattern while changes the addresses in the same way. i.e.
94 * write 1 to offset 1, 8 to offset 8, etc. Verify the data after
95 * writting to the buffer with length MEM_ADD_TEST_SIZE.
96 * Input arg : None
97 * Output arg : None
98 * Return : Returns 1 on failure, else 0
99 *******************************************************************************/
101 int mem_device_test(void)
103 unsigned int offset = 1, size;
104 unsigned int *base_address = mem_test_start_offset;
106 size = mem_test_end_offset - mem_test_start_offset;
108 printf("\tDDR2 device test ");
110 /* Debug print */
111 #ifdef DEBUG
112 printf("Start address = %#X\n", base_address);
113 printf("size = %#X\n", size);
114 #endif
116 /* We should start with pattern = 1. As we want to use offset and
117 * pattern the same variable, we will decrement base address by 1.
118 * So, even if we start with offset = pattern = 1, we have actually
119 * started from the given base address. */
120 base_address--;
122 for(; offset < size; offset++)
124 base_address[offset] = offset;
127 /* Check previously written pattern and write anti-pattern */
128 for(offset = 1; offset < size; offset++)
130 if(base_address[offset] != offset)
132 printf("FAILED\n");
133 printf("\t\tTest failed at offset = 0x%X\n"
134 "\t\tData written = 0x%X\n"
135 "\t\tData read = 0x%X\n", base_address
136 + offset, offset, base_address[offset]);
137 return 1;
140 /* Write anti-pattern */
141 base_address[offset] = ~offset;
144 /* Debug print */
145 #ifdef DEBUG
146 printf("Checking anti-pattern\n");
147 #endif
149 /* Check anti-pattern */
150 for(offset = 1; offset < size; offset++)
152 if(base_address[offset] != ~offset)
154 printf("FAILED\n");
155 printf("\t\tTest failed at offset = 0x%X\n"
156 "\t\tData written = 0x%X\n"
157 "\t\tData read = 0x%X\n", base_address
158 + offset, ~offset, base_address[offset]);
159 return 1;
163 printf("PASSED\n");
164 return 0;