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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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