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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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