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

Subversion Repositories xulalx25soc

[/] [xulalx25soc/] [trunk/] [sw/] [dumpflash.cpp] - Blame information for rev 30

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

Line No. Rev Author Line
1 5 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    dumpflash.cpp
4
//
5
// Project:     XuLA2 board
6
//
7
// Purpose:     Read/Empty the entire contents of the flash memory to a file.
8
//              The flash is unchanged by this process.
9
//
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// License:     GPL, v3, as defined and found on www.gnu.org,
29
//              http://www.gnu.org/licenses/gpl.html
30
//
31
//
32
////////////////////////////////////////////////////////////////////////////////
33
//
34
//
35
//
36
#include <stdio.h>
37
#include <stdlib.h>
38
#include <unistd.h>
39
#include <strings.h>
40
#include <ctype.h>
41
#include <string.h>
42
#include <signal.h>
43
#include <assert.h>
44
 
45
#include "port.h"
46
#include "regdefs.h"
47
 
48
FPGA    *m_fpga;
49
void    closeup(int v) {
50
        m_fpga->kill();
51
        exit(0);
52
}
53
 
54
// #define      DUMPMEM         RAMBASE
55
// #define      DUMPWORDS       MEMWORDS
56
 
57
#define DUMPMEM         SPIFLASH
58
#define DUMPWORDS       FLASHWORDS      // 1MB Flash
59
 
60
int main(int argc, char **argv) {
61
        FILE    *fp;
62
        const int       BUFLN = MEMWORDS; // 1MB Flash
63
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN];
64
 
65
        FPGAOPEN(m_fpga);
66
        fprintf(stderr, "Before starting, nread = %ld\n",
67
                m_fpga->m_total_nread);
68
 
69
        // Start with testing the version:
70
        printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
71
 
72
        // SPI flash testing
73
        // Enable the faster (vector) reads
74
        bool    vector_read = false;
75
        unsigned        sz;
76
 
77
        if (vector_read) {
78
                m_fpga->readi(DUMPMEM, BUFLN, buf);
79
        } else {
80
                for(int i=0; i<BUFLN; i++) {
81
                        buf[i] = m_fpga->readio(DUMPMEM+i);
82
                        // if (0 == (i&0x0ff))
83
                                printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
84
                }
85
        }
86
        printf("\nREAD-COMPLETE\n");
87
 
88
        // Now, let's find the end
89
        sz = BUFLN-1;
90
        while((sz>0)&&(buf[sz] == 0xffffffff))
91
                sz--;
92
        sz+=1;
93
        printf("The size of the buffer is 0x%06x or %d words\n", sz, sz);
94
 
95
        fp = fopen("spiftest.bin","w");
96
        fwrite(buf, sizeof(buf[0]), sz, fp);
97
        fclose(fp);
98
 
99
        printf("The read was accomplished in %ld bytes over the UART\n",
100
                m_fpga->m_total_nread);
101
 
102
        if (m_fpga->poll())
103
                printf("FPGA was interrupted\n");
104
        delete  m_fpga;
105
}
106
 
107
 

powered by: WebSVN 2.1.0

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