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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [dumpsdram.cpp] - Blame information for rev 105

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    dumpsdram.cpp
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     Read local memory, dump into a file.
8
//
9
//
10
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15 105 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
16 5 dgisselq
//
17
// This program is free software (firmware): you can redistribute it and/or
18
// modify it under the terms of  the GNU General Public License as published
19
// by the Free Software Foundation, either version 3 of the License, or (at
20
// your option) any later version.
21
//
22
// This program is distributed in the hope that it will be useful, but WITHOUT
23
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
// for more details.
26
//
27
// License:     GPL, v3, as defined and found on www.gnu.org,
28
//              http://www.gnu.org/licenses/gpl.html
29
//
30
//
31
////////////////////////////////////////////////////////////////////////////////
32
//
33
//
34
//
35
#include <stdio.h>
36
#include <stdlib.h>
37
#include <unistd.h>
38
#include <strings.h>
39
#include <ctype.h>
40
#include <string.h>
41
#include <signal.h>
42
#include <assert.h>
43
 
44 40 dgisselq
#include "llcomms.h"
45 5 dgisselq
#include "usbi.h"
46
#include "port.h"
47
#include "regdefs.h"
48
 
49
FPGA    *m_fpga;
50
 
51
int main(int argc, char **argv) {
52
        FILE            *fp, *fpin;
53
        unsigned        pos=0;
54 40 dgisselq
        int             port = FPGAPORT, skp;
55 5 dgisselq
        const int       BUFLN = 127;
56
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN],
57
                        *cmp = new FPGA::BUSW[BUFLN];
58 40 dgisselq
        bool            use_usb = true;
59 5 dgisselq
 
60 40 dgisselq
        skp = 1;
61
        for(int argn=0; argn<argc-skp; argn++) {
62
                if (argv[argn+skp][0] == '-') {
63
                        if (argv[argn+skp][1] == 'u')
64
                                use_usb = true;
65
                        else if (argv[argn+skp][1] == 'p') {
66
                                use_usb = false;
67
                                if (isdigit(argv[argn+skp][2]))
68
                                        port = atoi(&argv[argn+skp][2]);
69
                        } skp++; argn--;
70
                } else
71
                        argv[argn] = argv[argn+skp];
72
        } argc -= skp;
73
 
74
        if (argc!=2) {
75
                printf("Usage: dumpsdram [-p [port]] srcfile outfile\n");
76 5 dgisselq
                exit(-1);
77
        }
78
 
79 46 dgisselq
        /*
80 40 dgisselq
        for(int i=0; i<argc; i++) {
81
                printf("ARG[%d] = %s\n", i, argv[i]);
82 46 dgisselq
        } */
83 5 dgisselq
 
84 40 dgisselq
        fpin = fopen(argv[0], "rb");
85 5 dgisselq
        if (fpin == NULL) {
86
                fprintf(stderr, "Could not open %s\n", argv[1]);
87
                exit(-1);
88
        }
89
 
90 40 dgisselq
        if (use_usb)
91
                m_fpga = new FPGA(new USBI());
92
        else
93
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
94
 
95
 
96 105 dgisselq
        // Read our file and copy it into memory
97 5 dgisselq
        try {
98
                int     nr;
99
                pos = SDRAMBASE;
100
                do {
101
                        nr = BUFLN;
102
                        if (nr + pos > SDRAMBASE*2)
103
                                nr = SDRAMBASE*2 - pos;
104
                        nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
105
                        if (nr <= 0)
106
                                break;
107 40 dgisselq
 
108 46 dgisselq
                        if (false) {
109
                                for(int i=0; i<nr; i++)
110
                                        m_fpga->writeio(pos+i, buf[i]);
111
                        } else
112
                                m_fpga->writei(pos, nr, buf);
113 5 dgisselq
                        pos += nr;
114
                } while((nr > 0)&&(pos < 2*SDRAMBASE));
115
 
116
                printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
117
        } catch(BUSERR a) {
118
                fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
119
                fprintf(stderr, "... is your program too long for this memory?\n");
120
                exit(-2);
121 40 dgisselq
        } catch(...) {
122
                fprintf(stderr, "Other error\n");
123
                exit(-3);
124 5 dgisselq
        }
125
 
126
        rewind(fpin);
127
 
128 40 dgisselq
        fp = fopen(argv[1], "wb");
129 5 dgisselq
        if (fp == NULL) {
130
                fprintf(stderr, "Could not open: %s\n", argv[2]);
131
                exit(-1);
132
        }
133
 
134 46 dgisselq
        unsigned        mmaddr[65536], mmval[65536], mmidx = 0;
135
 
136 105 dgisselq
        // Read it back from memory
137 5 dgisselq
        try {
138
                pos = SDRAMBASE;
139
                const unsigned int MAXRAM = SDRAMBASE*2;
140 46 dgisselq
                bool    mismatch = false;
141
                unsigned        total_reread = 0;
142 5 dgisselq
                do {
143
                        int nw, nr;
144
                        if (MAXRAM-pos > BUFLN)
145
                                nr = BUFLN;
146
                        else
147
                                nr = MAXRAM-pos;
148 46 dgisselq
 
149
                        if (false) {
150
                                for(int i=0; i<nr; i++)
151
                                        buf[i] = m_fpga->readio(pos+i);
152
                        } else
153
                                m_fpga->readi(pos, nr, buf);
154
 
155 5 dgisselq
                        pos += nr;
156
                        nw = fwrite(buf, sizeof(FPGA::BUSW), nr, fp);
157
                        if (nw < nr) {
158
                                printf("Only wrote %d of %d words!\n", nw, nr);
159
                                exit(-2);
160 46 dgisselq
                        } // printf("nr = %d, pos = %08x (%08x / %08x)\n", nr,
161
                        //      pos, SDRAMBASE, MAXRAM);
162 5 dgisselq
 
163
                        {int cr;
164
                        cr = fread(cmp, sizeof(FPGA::BUSW), nr, fpin);
165 46 dgisselq
                        total_reread += cr;
166 5 dgisselq
                        for(int i=0; i<cr; i++)
167 46 dgisselq
                                if (cmp[i] != buf[i]) {
168 40 dgisselq
                                        printf("MISMATCH: MEM[%08x] = %08x(read) != %08x(expected)\n",
169 5 dgisselq
                                                pos-nr+i, buf[i], cmp[i]);
170 46 dgisselq
                                        mmaddr[mmidx] = pos-nr+i;
171
                                        mmval[mmidx] = cmp[i];
172
                                        if (mmidx < 65536)
173
                                                mmidx++;
174
                                        mismatch = true;
175
                                }
176 5 dgisselq
                        if (cr != nr) {
177 46 dgisselq
                                printf("Only read %d words from our input file\n", total_reread);
178 5 dgisselq
                                break;
179
                        }
180
                        }
181
                } while(pos < MAXRAM);
182 46 dgisselq
                if (mismatch)
183
                        printf("Read %04x (%6d) words from memory.  These did not match the source file.  (Failed test)\n",
184 5 dgisselq
                                pos-SDRAMBASE, pos-SDRAMBASE);
185 46 dgisselq
                else
186
                        printf("Successfully  read&copied %04x (%6d) words from memory\n",
187
                                pos-SDRAMBASE, pos-SDRAMBASE);
188 5 dgisselq
        } catch(BUSERR a) {
189
                fprintf(stderr, "BUS Err at address 0x%08x\n", a.addr);
190
                fprintf(stderr, "... is your program too long for this memory?\n");
191
                exit(-2);
192 40 dgisselq
        } catch(...) {
193
                fprintf(stderr, "Other error\n");
194
                exit(-3);
195 5 dgisselq
        }
196
 
197 46 dgisselq
        for(unsigned i=0; i<mmidx; i++) {
198
                unsigned bv = m_fpga->readio(mmaddr[i]);
199
                if (bv == mmval[i])
200
                        printf("Re-match, MEM[%08x]\n", mmaddr[i]);
201
                else
202
                        printf("2ndary Fail: MEM[%08x] = %08x(read) != %08x(expected)\n",
203
                                mmaddr[i], bv, mmval[i]);
204
        }
205
 
206 5 dgisselq
        delete  m_fpga;
207
}
208
 

powered by: WebSVN 2.1.0

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