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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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