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

Subversion Repositories xulalx25soc

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

Go to most recent revision | 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
// Copyright (C) 2015, Gisselquist Technology, LLC
16
//
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 40 dgisselq
        for(int i=0; i<argc; i++) {
80
                printf("ARG[%d] = %s\n", i, argv[i]);
81
        }
82 5 dgisselq
 
83 40 dgisselq
        fpin = fopen(argv[0], "rb");
84 5 dgisselq
        if (fpin == NULL) {
85
                fprintf(stderr, "Could not open %s\n", argv[1]);
86
                exit(-1);
87
        }
88
 
89 40 dgisselq
        if (use_usb)
90
                m_fpga = new FPGA(new USBI());
91
        else
92
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
93
 
94
 
95 5 dgisselq
        try {
96
                int     nr;
97
                pos = SDRAMBASE;
98
                do {
99
                        nr = BUFLN;
100
                        if (nr + pos > SDRAMBASE*2)
101
                                nr = SDRAMBASE*2 - pos;
102
                        nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
103
                        if (nr <= 0)
104
                                break;
105 40 dgisselq
 
106 5 dgisselq
                        m_fpga->writei(pos, nr, buf);
107
                        pos += nr;
108
                } while((nr > 0)&&(pos < 2*SDRAMBASE));
109
 
110
                printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
111
        } catch(BUSERR a) {
112
                fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
113
                fprintf(stderr, "... is your program too long for this memory?\n");
114
                exit(-2);
115 40 dgisselq
        } catch(...) {
116
                fprintf(stderr, "Other error\n");
117
                exit(-3);
118 5 dgisselq
        }
119
 
120
        rewind(fpin);
121
 
122 40 dgisselq
        fp = fopen(argv[1], "wb");
123 5 dgisselq
        if (fp == NULL) {
124
                fprintf(stderr, "Could not open: %s\n", argv[2]);
125
                exit(-1);
126
        }
127
 
128
        try {
129
                pos = SDRAMBASE;
130
                const unsigned int MAXRAM = SDRAMBASE*2;
131
                do {
132
                        int nw, nr;
133
                        if (MAXRAM-pos > BUFLN)
134
                                nr = BUFLN;
135
                        else
136
                                nr = MAXRAM-pos;
137
                        m_fpga->readi(pos, nr, buf);
138
                        pos += nr;
139
                        nw = fwrite(buf, sizeof(FPGA::BUSW), nr, fp);
140
                        if (nw < nr) {
141
                                printf("Only wrote %d of %d words!\n", nw, nr);
142
                                exit(-2);
143
                        } printf("nr = %d, pos = %08x (%08x / %08x)\n", nr,
144
                                pos, SDRAMBASE, MAXRAM);
145
 
146
                        {int cr;
147
                        cr = fread(cmp, sizeof(FPGA::BUSW), nr, fpin);
148
                        for(int i=0; i<cr; i++)
149
                                if (cmp[i] != buf[i])
150 40 dgisselq
                                        printf("MISMATCH: MEM[%08x] = %08x(read) != %08x(expected)\n",
151 5 dgisselq
                                                pos-nr+i, buf[i], cmp[i]);
152
                        if (cr != nr) {
153
                                printf("Only read %d words from our input file\n", cr);
154
                                break;
155
                        }
156
                        }
157
                } while(pos < MAXRAM);
158
                printf("Successfully  read&copied %04x (%6d) words from memory\n",
159
                                pos-SDRAMBASE, pos-SDRAMBASE);
160
        } catch(BUSERR a) {
161
                fprintf(stderr, "BUS Err at address 0x%08x\n", a.addr);
162
                fprintf(stderr, "... is your program too long for this memory?\n");
163
                exit(-2);
164 40 dgisselq
        } catch(...) {
165
                fprintf(stderr, "Other error\n");
166
                exit(-3);
167 5 dgisselq
        }
168
 
169
        delete  m_fpga;
170
}
171
 

powered by: WebSVN 2.1.0

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