OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [cmds/] [memory.c] - Blame information for rev 676

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 marcus.erl
#include "common.h"
2
#include "support.h"
3 246 julius
#include "spr-defs.h"
4 2 marcus.erl
 
5 406 julius
void show_mem(int start, int stop)
6 2 marcus.erl
{
7 406 julius
        unsigned long i = start;
8
        if ((i & 0xf) != 0x0)
9
                printf("\n%08lx: ", i);
10
        for (; i <= stop; i += 4) {
11
                if ((i & 0xf) == 0x0)
12
                        printf("\n%08lx: ", i);
13
                /* Read one word */
14
                printf("%08lx ", REG32(i));
15
        }
16
        printf("\n");
17 2 marcus.erl
}
18
 
19 406 julius
void testram(unsigned long start_addr, unsigned long stop_addr,
20
             unsigned long testno)
21 2 marcus.erl
{
22 406 julius
        unsigned long addr;
23
        unsigned long err_addr = 0;
24
        unsigned long err_no = 0;
25 2 marcus.erl
 
26 467 julius
        unsigned long stack_top = (unsigned long) &_stack_top;
27 464 julius
 
28
        if (start_addr < stack_top)
29
        {
30
                printf("\n");
31
                printf("Warning: RAM test will overwrite stack.\n");
32
                printf("         Moving start of test to 0x%08x to avoid stack\n",
33
                       stack_top);
34
                start_addr = stack_top;
35
        }
36
 
37
        if (start_addr >= stop_addr)
38
        {
39
                printf("ram_test: Start of test must be after end (0x%08x !< 0x%08x)\n",
40
                       start_addr, stop_addr);
41
                printf("ram_test: Aborting.\n");
42
                return;
43
        }
44
 
45 406 julius
        /* Test 1: Write locations with their addresses */
46
        if ((testno == 1) || (testno == 0)) {
47
                printf("\n1. Writing locations with their addresses: ");
48
                for (addr = start_addr; addr <= stop_addr; addr += 4)
49
                        REG32(addr) = addr;
50 2 marcus.erl
 
51 406 julius
                /* Verify */
52
                for (addr = start_addr; addr <= stop_addr; addr += 4)
53
                        if (REG32(addr) != addr) {
54
                                err_no++;
55
                                err_addr = addr;
56
                        }
57
                if (err_no)
58
                        printf("%04lx times failed. Last at location %08lx",
59
                               err_no, err_addr);
60
                else
61
                        printf("Passed");
62
                err_no = 0;
63
        }
64 2 marcus.erl
 
65 406 julius
        /* Test 2: Write locations with their inverse address */
66
        if ((testno == 2) || (testno == 0)) {
67
                printf("\n2. Writing locations with their inverse addresses: ");
68
                for (addr = start_addr; addr <= stop_addr; addr += 4)
69
                        REG32(addr) = ~addr;
70 2 marcus.erl
 
71 406 julius
                /* Verify */
72
                for (addr = start_addr; addr <= stop_addr; addr += 4)
73
                        if (REG32(addr) != ~addr) {
74
                                err_no++;
75
                                err_addr = addr;
76
                        }
77
                if (err_no)
78
                        printf("%04lx times failed. Last at location %08lx",
79
                               err_no, err_addr);
80
                else
81
                        printf("Passed");
82
                err_no = 0;
83
        }
84 2 marcus.erl
 
85 406 julius
        /* Test 3: Write locations with walking ones */
86
        if ((testno == 3) || (testno == 0)) {
87
                printf("\n3. Writing locations with walking ones: ");
88
                for (addr = start_addr; addr <= stop_addr; addr += 4)
89
                        REG32(addr) = 1 << (addr >> 2);
90 2 marcus.erl
 
91 406 julius
                /* Verify */
92
                for (addr = start_addr; addr <= stop_addr; addr += 4)
93
                        if (REG32(addr) != (1 << (addr >> 2))) {
94
                                err_no++;
95
                                err_addr = addr;
96
                        }
97
                if (err_no)
98
                        printf("%04lx times failed. Last at location %08lx",
99
                               err_no, err_addr);
100
                else
101
                        printf("Passed");
102
                err_no = 0;
103
        }
104
 
105
        /* Test 4: Write locations with walking zeros */
106
        if ((testno == 4) || (testno == 0)) {
107
                printf("\n4. Writing locations with walking zeros: ");
108
                for (addr = start_addr; addr <= stop_addr; addr += 4)
109
                        REG32(addr) = ~(1 << (addr >> 2));
110
 
111
                /* Verify */
112
                for (addr = start_addr; addr <= stop_addr; addr += 4)
113
                        if (REG32(addr) != ~(1 << (addr >> 2))) {
114
                                err_no++;
115
                                err_addr = addr;
116
                        }
117
                if (err_no)
118
                        printf("%04lx times failed. Last at location %08lx",
119
                               err_no, err_addr);
120
                else
121
                        printf("Passed");
122
                err_no = 0;
123
        }
124 2 marcus.erl
}
125
 
126 140 julius
// Do proper walking 0 as byte writes
127 406 julius
void better_ram_test(unsigned long start_addr, unsigned long stop_addr,
128
                     unsigned test_no)
129 140 julius
{
130 406 julius
        unsigned long addr;
131
        unsigned long err_addr = 0;
132
        unsigned long err_no = 0;
133
        int b;
134
        printf("\nSetting memory contents to all 1'b1  ");
135
        for (addr = start_addr; addr <= stop_addr; addr += 1)
136
                REG8(addr) = 0xff;
137
        printf("\rVerifying memory contents all set to 1'b1:  ");
138
        /* Verify */
139
        for (addr = start_addr; addr <= stop_addr; addr += 1) {
140
                if (REG8(addr) != 0xff) {
141
                        err_no++;
142
                        err_addr = addr;
143
                        printf("\n%04lx times failed. Last at location %08lx  ",
144
                               err_no, err_addr);
145
                }
146
        }
147 140 julius
 
148 406 julius
        if (err_no == 0)
149
                printf("Passed");
150
        else
151
                printf("Finished");
152
 
153
        err_no = 0;
154
 
155
        printf("\nWalking zero through memory, verify just itself: ");
156
        for (addr = start_addr; addr <= stop_addr; addr += 1) {
157
                for (b = 0; b < 8; b++) {
158
                        // Write, verify
159
                        REG8(addr) = ~(1 << b);
160
 
161
                        if (REG8(addr) != ~(1 << b)) {
162
                                err_no++;
163
                                err_addr = addr;
164
                                printf
165
                                    ("\n%04lx times failed. Last at location %08lx",
166
                                     err_no, err_addr);
167
                        }
168
                        REG8(addr) = 0xff;
169
                }
170 140 julius
        }
171 406 julius
        if (err_no == 0)
172
                printf("Passed");
173
        else
174
                printf("Finished");
175
        err_no = 0;
176
 
177
        printf("\nWriting across rows, row size configured as %d bytes",
178
               SDRAM_ROW_SIZE);
179
        unsigned long start_row = start_addr / SDRAM_ROW_SIZE;
180
        unsigned long end_row = stop_addr / SDRAM_ROW_SIZE;
181
        for (addr = start_row; addr <= end_row; addr += 1) {
182
                REG32(addr * SDRAM_ROW_SIZE) = addr;
183 140 julius
        }
184 406 julius
 
185
        printf("\rVerifying row write test: ");
186
 
187
        for (addr = start_row; addr <= end_row; addr += 1) {
188
                if (REG32(addr * SDRAM_ROW_SIZE) != addr) {
189
                        err_no++;
190
                        err_addr = addr * SDRAM_ROW_SIZE;
191
                        printf
192
                            ("\n%04lx times failed. Last at location %08lx (row %d)",
193
                             err_no, err_addr, addr);
194
                }
195
        }
196
 
197
        if (err_no == 0)
198
                printf("Passed");
199
        else
200
                printf("Finished");
201
        err_no = 0;
202
 
203 140 julius
}
204
 
205 406 julius
int dm_cmd(int argc, char *argv[])
206 2 marcus.erl
{
207 406 julius
        unsigned long a1, a2;
208
        a1 = strtoul(argv[0], 0, 0);
209
        switch (argc) {
210
        case 1:
211
                show_mem(a1, a1);
212
                return 0;
213
        case 2:
214
                a2 = strtoul(argv[1], 0, 0);
215
                show_mem(a1, a2);
216
                return 0;
217
        default:
218
                return -1;
219
        }
220 2 marcus.erl
}
221
 
222 406 julius
int pm_cmd(int argc, char *argv[])
223 2 marcus.erl
{
224 406 julius
        unsigned long addr, stop_addr, value;
225
        if ((argc == 3) || (argc == 2)) {
226
                addr = strtoul(argv[0], 0, 0);
227
 
228
                if (argc == 2) {
229
                        stop_addr = strtoul(argv[0], 0, 0);
230
                        value = strtoul(argv[1], 0, 0);
231
                } else {
232
                        stop_addr = strtoul(argv[1], 0, 0);
233
                        value = strtoul(argv[2], 0, 0);
234
                }
235
 
236
                for (; addr <= stop_addr; addr += 4)
237
                        REG32(addr) = value;
238
 
239
                /*show_mem(strtoul (argv[0], 0, 0), stop_addr); */
240
        } else
241
                return -1;
242
        return 0;
243 2 marcus.erl
}
244
 
245 406 julius
int ram_test_cmd(int argc, char *argv[])
246 2 marcus.erl
{
247 406 julius
        switch (argc) {
248
        case 2:
249
                testram(strtoul(argv[0], 0, 0), strtoul(argv[1], 0, 0), 0);
250
                return 0;
251
        case 3:
252
                testram(strtoul(argv[0], 0, 0), strtoul(argv[1], 0, 0),
253
                        strtoul(argv[2], 0, 0));
254
                return 0;
255
        default:
256
                return -1;
257
        }
258 2 marcus.erl
}
259
 
260 406 julius
int better_ram_test_cmd(int argc, char *argv[])
261 140 julius
{
262 406 julius
        if (argc < 2)
263
                return -1;
264
 
265
        better_ram_test(strtoul(argv[0], 0, 0), strtoul(argv[1], 0, 0), 0);
266
        return 0;
267 140 julius
}
268
 
269 406 julius
unsigned long crc32(unsigned long crc, const unsigned char *buf,
270
                    unsigned long len)
271 2 marcus.erl
{
272 406 julius
        /* Create bitwise CRC table first */
273
        unsigned long crc_table[256];
274
        int i, k;
275
        for (i = 0; i < 256; i++) {
276
                unsigned long c = (unsigned long)i;
277
                for (k = 0; k < 8; k++)
278
                        c = c & 1 ? 0xedb88320 ^ (c >> 1) : c >> 1;
279
                crc_table[i] = c;
280
        }
281 2 marcus.erl
 
282 406 julius
        /* Calculate crc on buf */
283
        crc = crc ^ 0xffffffffL;
284
        while (len--)
285
                crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
286
        return crc ^ 0xffffffffL;
287 2 marcus.erl
}
288
 
289 406 julius
int crc_cmd(int argc, char *argv[])
290 2 marcus.erl
{
291 406 julius
        unsigned long addr = global.src_addr;
292
        unsigned long len = global.length;
293
        unsigned long init_crc = 0;
294
 
295
        switch (argc) {
296
        case 3:
297
                init_crc = strtoul(argv[2], 0, 0);
298
        case 2:
299
                len = strtoul(argv[1], 0, 0);
300
        case 1:
301
                addr = strtoul(argv[0], 0, 0);
302
        case 0:
303
                printf("CRC [%08lx-%08lx] = %08lx\n", addr, addr + len - 1,
304
                       crc32(init_crc, (unsigned char *)addr, len));
305
                return 0;
306
        }
307
        return -1;
308 2 marcus.erl
}
309
 
310 406 julius
void module_memory_init(void)
311 2 marcus.erl
{
312 406 julius
        register_command("dm", "<start addr> [<end addr>]",
313
                         "display 32-bit memory location(s)", dm_cmd);
314
        register_command("pm", "<addr> [<stop_addr>] <value>",
315
                         "patch 32-bit memory location(s)", pm_cmd);
316
        register_command("ram_test", "<start_addr> <stop_addr> [<test_no>]",
317
                         "run a simple RAM test", ram_test_cmd);
318
        register_command("better_ram_test", "<start_addr> <stop_addr>",
319
                         "run a better RAM test", better_ram_test_cmd);
320 140 julius
 
321 406 julius
        register_command("crc", "[<src_addr> [<length> [<init_crc>]]]",
322
                         "Calculates a 32-bit CRC on specified memory region",
323
                         crc_cmd);
324 2 marcus.erl
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.