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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [dumpsdram.cpp] - Diff between revs 5 and 40

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 5 Rev 40
Line 39... Line 39...
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <signal.h>
#include <signal.h>
#include <assert.h>
#include <assert.h>
 
 
 
#include "llcomms.h"
#include "usbi.h"
#include "usbi.h"
#include "port.h"
#include "port.h"
#include "regdefs.h"
#include "regdefs.h"
 
 
FPGA    *m_fpga;
FPGA    *m_fpga;
 
 
int main(int argc, char **argv) {
int main(int argc, char **argv) {
        FILE            *fp, *fpin;
        FILE            *fp, *fpin;
        unsigned        pos=0;
        unsigned        pos=0;
 
        int             port = FPGAPORT, skp;
        const int       BUFLN = 127;
        const int       BUFLN = 127;
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN],
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN],
                        *cmp = new FPGA::BUSW[BUFLN];
                        *cmp = new FPGA::BUSW[BUFLN];
 
        bool            use_usb = true;
 
 
        if (argc<=2) {
        skp = 1;
                printf("Usage: dumpsdram srcfile outfile\n");
        for(int argn=0; argn<argc-skp; argn++) {
 
                if (argv[argn+skp][0] == '-') {
 
                        if (argv[argn+skp][1] == 'u')
 
                                use_usb = true;
 
                        else if (argv[argn+skp][1] == 'p') {
 
                                use_usb = false;
 
                                if (isdigit(argv[argn+skp][2]))
 
                                        port = atoi(&argv[argn+skp][2]);
 
                        } skp++; argn--;
 
                } else
 
                        argv[argn] = argv[argn+skp];
 
        } argc -= skp;
 
 
 
        if (argc!=2) {
 
                printf("Usage: dumpsdram [-p [port]] srcfile outfile\n");
                exit(-1);
                exit(-1);
        }
        }
 
 
        FPGAOPEN(m_fpga);
        for(int i=0; i<argc; i++) {
 
                printf("ARG[%d] = %s\n", i, argv[i]);
 
        }
 
 
        fpin = fopen(argv[1], "rb");
        fpin = fopen(argv[0], "rb");
        if (fpin == NULL) {
        if (fpin == NULL) {
                fprintf(stderr, "Could not open %s\n", argv[1]);
                fprintf(stderr, "Could not open %s\n", argv[1]);
                exit(-1);
                exit(-1);
        }
        }
 
 
 
        if (use_usb)
 
                m_fpga = new FPGA(new USBI());
 
        else
 
                m_fpga = new FPGA(new NETCOMMS(FPGAHOST, port));
 
 
 
 
        try {
        try {
                int     nr;
                int     nr;
                pos = SDRAMBASE;
                pos = SDRAMBASE;
                do {
                do {
                        nr = BUFLN;
                        nr = BUFLN;
                        if (nr + pos > SDRAMBASE*2)
                        if (nr + pos > SDRAMBASE*2)
                                nr = SDRAMBASE*2 - pos;
                                nr = SDRAMBASE*2 - pos;
                        nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
                        nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
                        if (nr <= 0)
                        if (nr <= 0)
                                break;
                                break;
 
 
                        m_fpga->writei(pos, nr, buf);
                        m_fpga->writei(pos, nr, buf);
                        pos += nr;
                        pos += nr;
                } while((nr > 0)&&(pos < 2*SDRAMBASE));
                } while((nr > 0)&&(pos < 2*SDRAMBASE));
 
 
                printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
                printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
        } catch(BUSERR a) {
        } catch(BUSERR a) {
                fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
                fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
                fprintf(stderr, "... is your program too long for this memory?\n");
                fprintf(stderr, "... is your program too long for this memory?\n");
                exit(-2);
                exit(-2);
 
        } catch(...) {
 
                fprintf(stderr, "Other error\n");
 
                exit(-3);
        }
        }
 
 
        rewind(fpin);
        rewind(fpin);
 
 
        fp = fopen(argv[2], "wb");
        fp = fopen(argv[1], "wb");
        if (fp == NULL) {
        if (fp == NULL) {
                fprintf(stderr, "Could not open: %s\n", argv[2]);
                fprintf(stderr, "Could not open: %s\n", argv[2]);
                exit(-1);
                exit(-1);
        }
        }
 
 
Line 116... Line 145...
 
 
                        {int cr;
                        {int cr;
                        cr = fread(cmp, sizeof(FPGA::BUSW), nr, fpin);
                        cr = fread(cmp, sizeof(FPGA::BUSW), nr, fpin);
                        for(int i=0; i<cr; i++)
                        for(int i=0; i<cr; i++)
                                if (cmp[i] != buf[i])
                                if (cmp[i] != buf[i])
                                        fprintf(stderr, "MISMATCH: MEM[%08x] = %08x != %08x\n",
                                        printf("MISMATCH: MEM[%08x] = %08x(read) != %08x(expected)\n",
                                                pos-nr+i, buf[i], cmp[i]);
                                                pos-nr+i, buf[i], cmp[i]);
                        if (cr != nr) {
                        if (cr != nr) {
                                printf("Only read %d words from our input file\n", cr);
                                printf("Only read %d words from our input file\n", cr);
                                break;
                                break;
                        }
                        }
Line 130... Line 159...
                                pos-SDRAMBASE, pos-SDRAMBASE);
                                pos-SDRAMBASE, pos-SDRAMBASE);
        } catch(BUSERR a) {
        } catch(BUSERR a) {
                fprintf(stderr, "BUS Err at address 0x%08x\n", a.addr);
                fprintf(stderr, "BUS Err at address 0x%08x\n", a.addr);
                fprintf(stderr, "... is your program too long for this memory?\n");
                fprintf(stderr, "... is your program too long for this memory?\n");
                exit(-2);
                exit(-2);
 
        } catch(...) {
 
                fprintf(stderr, "Other error\n");
 
                exit(-3);
        }
        }
 
 
        delete  m_fpga;
        delete  m_fpga;
}
}
 
 

powered by: WebSVN 2.1.0

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