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

Subversion Repositories openarty

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3 51 dgisselq
// Filename:    dumpflash.cpp
4 4 dgisselq
//
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 51 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
16 4 dgisselq
//
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 51 dgisselq
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
29 4 dgisselq
// 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         EQSPIFLASH
58 51 dgisselq
#define DUMPWORDS       (FLASHLEN>>2)
59 4 dgisselq
 
60
int main(int argc, char **argv) {
61
        FILE    *fp;
62 51 dgisselq
        const int       BUFLN = FLASHLEN;
63
        char    *buf = new char[FLASHLEN];
64 4 dgisselq
 
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 = true;
75
        unsigned        sz;
76
 
77
        if (vector_read) {
78 51 dgisselq
                m_fpga->readi(DUMPMEM, BUFLN>>2, (DEVBUS::BUSW *)&buf[0]);
79
                byteswapbuf(BUFLN>>2, buf);
80 4 dgisselq
        } else {
81 51 dgisselq
                for(int i=0; i<BUFLN; i+=4) {
82
                        DEVBUS::BUSW    word;
83
 
84
                        word = m_fpga->readio(DUMPMEM+i);
85
 
86
                        buf[i  ] = (word>>24) & 0x0ff;
87
                        buf[i+1] = (word>>16) & 0x0ff;
88
                        buf[i+2] = (word>> 8) & 0x0ff;
89
                        buf[i+3] = (word    ) & 0x0ff;
90 4 dgisselq
                }
91
        }
92
        printf("\nREAD-COMPLETE\n");
93
 
94
        // Now, let's find the end
95
        sz = BUFLN-1;
96 51 dgisselq
        while((sz>0)&&((unsigned char)buf[sz] == 0xff))
97 4 dgisselq
                sz--;
98
        sz+=1;
99
 
100 14 dgisselq
#define FLASHFILE       "eqspidump.bin"
101
 
102
        if (access(FLASHFILE, F_OK)==0) {
103
                fprintf(stderr, "Cowardly refusing to overwrite %s\n", FLASHFILE);
104
                exit(EXIT_FAILURE);
105
        }
106
 
107
        fp = fopen(FLASHFILE,"w");
108 4 dgisselq
        fwrite(buf, sizeof(buf[0]), sz, fp);
109
        fclose(fp);
110
 
111
        printf("The read was accomplished in %ld bytes over the UART\n",
112
                m_fpga->m_total_nread);
113
 
114
        if (m_fpga->poll())
115
                printf("FPGA was interrupted\n");
116
        delete  m_fpga;
117
}
118
 
119
 

powered by: WebSVN 2.1.0

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