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

Subversion Repositories xulalx25soc

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

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
#include "usbi.h"
45
#include "port.h"
46
#include "regdefs.h"
47
 
48
FPGA    *m_fpga;
49
 
50
int main(int argc, char **argv) {
51
        FILE            *fp, *fpin;
52
        unsigned        pos=0;
53
        const int       BUFLN = 127;
54
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN],
55
                        *cmp = new FPGA::BUSW[BUFLN];
56
 
57
        if (argc<=2) {
58
                printf("Usage: dumpsdram srcfile outfile\n");
59
                exit(-1);
60
        }
61
 
62
        FPGAOPEN(m_fpga);
63
 
64
        fpin = fopen(argv[1], "rb");
65
        if (fpin == NULL) {
66
                fprintf(stderr, "Could not open %s\n", argv[1]);
67
                exit(-1);
68
        }
69
 
70
        try {
71
                int     nr;
72
                pos = SDRAMBASE;
73
                do {
74
                        nr = BUFLN;
75
                        if (nr + pos > SDRAMBASE*2)
76
                                nr = SDRAMBASE*2 - pos;
77
                        nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
78
                        if (nr <= 0)
79
                                break;
80
                        m_fpga->writei(pos, nr, buf);
81
                        pos += nr;
82
                } while((nr > 0)&&(pos < 2*SDRAMBASE));
83
 
84
                printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
85
        } catch(BUSERR a) {
86
                fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
87
                fprintf(stderr, "... is your program too long for this memory?\n");
88
                exit(-2);
89
        }
90
 
91
        rewind(fpin);
92
 
93
        fp = fopen(argv[2], "wb");
94
        if (fp == NULL) {
95
                fprintf(stderr, "Could not open: %s\n", argv[2]);
96
                exit(-1);
97
        }
98
 
99
        try {
100
                pos = SDRAMBASE;
101
                const unsigned int MAXRAM = SDRAMBASE*2;
102
                do {
103
                        int nw, nr;
104
                        if (MAXRAM-pos > BUFLN)
105
                                nr = BUFLN;
106
                        else
107
                                nr = MAXRAM-pos;
108
                        m_fpga->readi(pos, nr, buf);
109
                        pos += nr;
110
                        nw = fwrite(buf, sizeof(FPGA::BUSW), nr, fp);
111
                        if (nw < nr) {
112
                                printf("Only wrote %d of %d words!\n", nw, nr);
113
                                exit(-2);
114
                        } printf("nr = %d, pos = %08x (%08x / %08x)\n", nr,
115
                                pos, SDRAMBASE, MAXRAM);
116
 
117
                        {int cr;
118
                        cr = fread(cmp, sizeof(FPGA::BUSW), nr, fpin);
119
                        for(int i=0; i<cr; i++)
120
                                if (cmp[i] != buf[i])
121
                                        fprintf(stderr, "MISMATCH: MEM[%08x] = %08x != %08x\n",
122
                                                pos-nr+i, buf[i], cmp[i]);
123
                        if (cr != nr) {
124
                                printf("Only read %d words from our input file\n", cr);
125
                                break;
126
                        }
127
                        }
128
                } while(pos < MAXRAM);
129
                printf("Successfully  read&copied %04x (%6d) words from memory\n",
130
                                pos-SDRAMBASE, pos-SDRAMBASE);
131
        } catch(BUSERR a) {
132
                fprintf(stderr, "BUS Err at address 0x%08x\n", a.addr);
133
                fprintf(stderr, "... is your program too long for this memory?\n");
134
                exit(-2);
135
        }
136
 
137
        delete  m_fpga;
138
}
139
 

powered by: WebSVN 2.1.0

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