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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [dumpsdram.cpp] - Rev 33

Go to most recent revision | Compare with Previous | Blame | View Log

////////////////////////////////////////////////////////////////////////////////
//
// Filename: 	dumpsdram.cpp
//
// Project:	XuLA2 board
//
// Purpose:	Read local memory, dump into a file.
//
//
// Creator:	Dan Gisselquist, Ph.D.
//		Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015, Gisselquist Technology, LLC
//
// This program is free software (firmware): you can redistribute it and/or
// modify it under the terms of  the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// License:	GPL, v3, as defined and found on www.gnu.org,
//		http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
//
//
//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <assert.h>
 
#include "usbi.h"
#include "port.h"
#include "regdefs.h"
 
FPGA	*m_fpga;
 
int main(int argc, char **argv) {
	FILE		*fp, *fpin;
	unsigned	pos=0;
	const int	BUFLN = 127;
	FPGA::BUSW	*buf = new FPGA::BUSW[BUFLN],
			*cmp = new FPGA::BUSW[BUFLN];
 
	if (argc<=2) {
		printf("Usage: dumpsdram srcfile outfile\n");
		exit(-1);
	}
 
	FPGAOPEN(m_fpga);
 
	fpin = fopen(argv[1], "rb");
	if (fpin == NULL) {
		fprintf(stderr, "Could not open %s\n", argv[1]);
		exit(-1);
	}
 
	try {
		int	nr;
		pos = SDRAMBASE;
		do {
			nr = BUFLN;
			if (nr + pos > SDRAMBASE*2)
				nr = SDRAMBASE*2 - pos;
			nr = fread(buf, sizeof(FPGA::BUSW), nr, fpin);
			if (nr <= 0)
				break;
			m_fpga->writei(pos, nr, buf);
			pos += nr;
		} while((nr > 0)&&(pos < 2*SDRAMBASE));
 
		printf("SUCCESS::fully wrote full file to memory (pos = %08x)\n", pos);
	} catch(BUSERR a) {
		fprintf(stderr, "BUS Err while writing at address 0x%08x\n", a.addr);
		fprintf(stderr, "... is your program too long for this memory?\n");
		exit(-2);
	}
 
	rewind(fpin);
 
	fp = fopen(argv[2], "wb");
	if (fp == NULL) {
		fprintf(stderr, "Could not open: %s\n", argv[2]);
		exit(-1);
	}
 
	try {
		pos = SDRAMBASE;
		const unsigned int MAXRAM = SDRAMBASE*2;
		do {
			int nw, nr;
			if (MAXRAM-pos > BUFLN)
				nr = BUFLN;
			else
				nr = MAXRAM-pos;
			m_fpga->readi(pos, nr, buf);
			pos += nr;
			nw = fwrite(buf, sizeof(FPGA::BUSW), nr, fp);
			if (nw < nr) {
				printf("Only wrote %d of %d words!\n", nw, nr);
				exit(-2);
			} printf("nr = %d, pos = %08x (%08x / %08x)\n", nr,
				pos, SDRAMBASE, MAXRAM);
 
			{int cr;
			cr = fread(cmp, sizeof(FPGA::BUSW), nr, fpin);
			for(int i=0; i<cr; i++)
				if (cmp[i] != buf[i])
					fprintf(stderr, "MISMATCH: MEM[%08x] = %08x != %08x\n",
						pos-nr+i, buf[i], cmp[i]);
			if (cr != nr) {
				printf("Only read %d words from our input file\n", cr);
				break;
			}
			}
		} while(pos < MAXRAM);
		printf("Successfully  read&copied %04x (%6d) words from memory\n",
				pos-SDRAMBASE, pos-SDRAMBASE);
	} catch(BUSERR a) {
		fprintf(stderr, "BUS Err at address 0x%08x\n", a.addr);
		fprintf(stderr, "... is your program too long for this memory?\n");
		exit(-2);
	}
 
	delete	m_fpga;
}
 
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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