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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [dumpflash.cpp] - Blame information for rev 14

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

Line No. Rev Author Line
1 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    dumpflash.cpp
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
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
// Creator:     Dan Gisselquist, Ph.D.
11
//              Gisselquist Technology, LLC
12
//
13
////////////////////////////////////////////////////////////////////////////////
14
//
15
// Copyright (C) 2015-2016, 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
// You should have received a copy of the GNU General Public License along
28
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
29
// target there if the PDF file isn't present.)  If not, see
30
// <http://www.gnu.org/licenses/> for a copy.
31
//
32
// License:     GPL, v3, as defined and found on www.gnu.org,
33
//              http://www.gnu.org/licenses/gpl.html
34
//
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
//
38
//
39
#include <stdio.h>
40
#include <stdlib.h>
41
#include <unistd.h>
42
#include <strings.h>
43
#include <ctype.h>
44
#include <string.h>
45
#include <signal.h>
46
#include <assert.h>
47
 
48
#include "port.h"
49
#include "regdefs.h"
50
 
51
FPGA    *m_fpga;
52
void    closeup(int v) {
53
        m_fpga->kill();
54
        exit(0);
55
}
56
 
57
// #define      DUMPMEM         RAMBASE
58
// #define      DUMPWORDS       MEMWORDS
59
 
60
#define DUMPMEM         EQSPIFLASH
61
#define DUMPWORDS       FLASHWORDS      // 1MB Flash
62
 
63
int main(int argc, char **argv) {
64
        FILE    *fp;
65
        const int       BUFLN = MEMWORDS; // 1MB Flash
66
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN];
67
 
68
        FPGAOPEN(m_fpga);
69
        fprintf(stderr, "Before starting, nread = %ld\n",
70
                m_fpga->m_total_nread);
71
 
72
        // Start with testing the version:
73
        printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
74
 
75
        // SPI flash testing
76
        // Enable the faster (vector) reads
77
        bool    vector_read = true;
78
        unsigned        sz;
79
 
80
        if (vector_read) {
81
                m_fpga->readi(DUMPMEM, BUFLN, buf);
82
        } else {
83
                for(int i=0; i<BUFLN; i++) {
84
                        buf[i] = m_fpga->readio(DUMPMEM+i);
85
                        // if (0 == (i&0x0ff))
86
                                printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
87
                }
88
        }
89
        printf("\nREAD-COMPLETE\n");
90
 
91
        // Now, let's find the end
92
        sz = BUFLN-1;
93
        while((sz>0)&&(buf[sz] == 0xffffffff))
94
                sz--;
95
        sz+=1;
96
        printf("The size of the buffer is 0x%06x or %d words\n", sz, sz);
97
 
98 14 dgisselq
#define FLASHFILE       "eqspidump.bin"
99
 
100
        if (access(FLASHFILE, F_OK)==0) {
101
                fprintf(stderr, "Cowardly refusing to overwrite %s\n", FLASHFILE);
102
                exit(EXIT_FAILURE);
103
        }
104
 
105
        fp = fopen(FLASHFILE,"w");
106 4 dgisselq
        fwrite(buf, sizeof(buf[0]), sz, fp);
107
        fclose(fp);
108
 
109
        printf("The read was accomplished in %ld bytes over the UART\n",
110
                m_fpga->m_total_nread);
111
 
112
        if (m_fpga->poll())
113
                printf("FPGA was interrupted\n");
114
        delete  m_fpga;
115
}
116
 
117
 

powered by: WebSVN 2.1.0

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