[rendering] All hail pyflakes... fix the name
[wikipediardware.git] / mbr / memory-test.c
blobb5497fe9ed2bde76141405421a9cf31b9de09ca8
1 // taken from Qi boot loader
3 /*
4 * (C) Copyright 2007 OpenMoko, Inc.
5 * Author: Andy Green <andy@openmoko.com>
7 * Memory test routines
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
27 #define APPLICATION_TITLE "32MB memory test";
28 #include "application.h"
31 #define RAM_START ((u8 *)0x10000000)
32 #define RAM_SIZE (32 * 1024 * 1024)
34 // redirect Qi routines to the correct EEPROM routines
35 #define puts print
36 #define print32 print_u32
37 #define printdec print_u32
40 void memory_test(void *start, unsigned int length);
42 // this must be the first executable code as the loader executes from the first program address
43 ReturnType mem(int block, int status)
45 APPLICATION_INITIALISE();
47 memory_test(RAM_START, RAM_SIZE);
49 APPLICATION_FINALISE(0, 0);
53 int memory_test_const32(void * start, unsigned int length, u32 value)
55 int errors = 0;
56 u32 * p = (u32 *)start;
57 u32 * pend = (u32 *)(start + length);
58 int count = length >> 2;
60 puts(".");
62 while (p < pend)
63 *p++ = value;
65 p = (u32 *)start;
66 count = length >> 2;
68 while (count--)
69 if (*p++ != value) {
70 puts("*A*");
71 print32((long)p - 4);
72 puts("=");
73 print32((u32)p[-4]);
74 puts("/");
75 print32((u32)value);
76 errors++;
79 return errors;
82 int memory_test_ads(void * start, unsigned int length, u32 mask)
84 int errors = 0;
85 u32 * p = (u32 *)start;
86 u32 * pend = (u32 *)(start + length);
88 puts(".");
90 while (p < pend)
91 if ((u32)p & mask)
92 *p++ = 0xffffffff;
93 else
94 *p++ = 0;
96 p = (u32 *)start;
98 while (p < pend) {
99 if ((u32)p & mask) {
100 if (*p++ != 0xffffffff) {
101 puts("*B:");
102 print32((long)p - 4);
103 puts("/");
104 print32((u32)mask);
105 errors++;
107 } else {
108 if (*p++) {
109 puts("*C:");
110 print32((long)p - 4);
111 puts("/");
112 print32((u32)mask);
113 errors++;
117 return errors;
120 int memory_test_walking1(void * start, unsigned int length)
122 int errors = 0;
123 u32 value = 1;
125 while (value) {
126 errors += memory_test_const32(start, length, value);
127 value <<= 1;
130 return errors;
133 /* negative runs == run forever */
135 #define INTERRUPT_HERE() \
136 do { \
137 if (serial_input_available()) { \
138 serial_input_char(); \
139 return; \
141 } while (0)
143 void memory_test(void *start, unsigned int length)
145 int errors = 0;
146 int series = 0;
147 int mask;
149 puts("\nMemory: ");
150 print32((u32)start);
151 puts(" length ");
152 printdec(length >> 20);
153 puts(" MB\n");
155 for (;;) {
156 puts("Test series ");
157 printdec(series + 1);
158 puts(" ");
160 /* these are looking at data issues, they flood the whole
161 * array with the same data
164 errors += memory_test_const32(start, length, 0x55555555);
165 INTERRUPT_HERE();
166 errors += memory_test_const32(start, length, 0xaaaaaaaa);
167 INTERRUPT_HERE();
168 errors += memory_test_const32(start, length, 0x55aa55aa);
169 INTERRUPT_HERE();
170 errors += memory_test_const32(start, length, 0xaa55aa55);
171 INTERRUPT_HERE();
172 errors += memory_test_const32(start, length, 0x00ff00ff);
173 INTERRUPT_HERE();
174 errors += memory_test_const32(start, length, 0xff00ff00);
175 INTERRUPT_HERE();
176 errors += memory_test_walking1(start, length);
177 INTERRUPT_HERE();
178 puts("+");
180 /* this is looking at addressing issues, it floods only
181 * addresses meeting a walking mask with 0xffffffff (the rest
182 * is zeroed), and makes sure all the bits are only seen where
183 * they were placed
186 mask = 1;
187 while (! (length & mask)) {
188 errors += memory_test_ads(start, length, mask);
189 INTERRUPT_HERE();
190 mask = mask << 1;
193 puts("Errors: ");
194 printdec(errors);
195 puts("\n");
197 series++;