| 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 |
18 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
| 59 |
|
|
//
|
| 60 |
|
|
// Filename: dumpflash.cpp
|
| 61 |
|
|
//
|
| 62 |
|
|
// Project: OpenArty, an entirely open SoC based upon the Arty platform
|
| 63 |
|
|
//
|
| 64 |
|
|
// Purpose: The purpose of this program is to read the entire flash memory,
|
| 65 |
|
|
// and dump it to a file.
|
| 66 |
|
|
//
|
| 67 |
|
|
//
|
| 68 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
| 69 |
|
|
// Gisselquist Technology, LLC
|
| 70 |
|
|
//
|
| 71 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 72 |
|
|
//
|
| 73 |
|
|
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
| 74 |
|
|
//
|
| 75 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
| 76 |
|
|
// modify it under the terms of the GNU General Public License as published
|
| 77 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
| 78 |
|
|
// your option) any later version.
|
| 79 |
|
|
//
|
| 80 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
| 81 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
| 82 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
| 83 |
|
|
// for more details.
|
| 84 |
|
|
//
|
| 85 |
|
|
// You should have received a copy of the GNU General Public License along
|
| 86 |
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
| 87 |
|
|
// target there if the PDF file isn't present.) If not, see
|
| 88 |
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
| 89 |
|
|
//
|
| 90 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
| 91 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
| 92 |
|
|
//
|
| 93 |
|
|
//
|
| 94 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
| 95 |
|
|
//
|
| 96 |
|
|
//
|
| 97 |
4 |
dgisselq |
// #define DUMPWORDS MEMWORDS
|
| 98 |
|
|
|
| 99 |
|
|
#define DUMPMEM EQSPIFLASH
|
| 100 |
|
|
#define DUMPWORDS FLASHWORDS // 1MB Flash
|
| 101 |
|
|
|
| 102 |
|
|
int main(int argc, char **argv) {
|
| 103 |
|
|
FILE *fp;
|
| 104 |
18 |
dgisselq |
const int BUFLN = FLASHWORDS;
|
| 105 |
4 |
dgisselq |
FPGA::BUSW *buf = new FPGA::BUSW[BUFLN];
|
| 106 |
|
|
|
| 107 |
|
|
FPGAOPEN(m_fpga);
|
| 108 |
|
|
fprintf(stderr, "Before starting, nread = %ld\n",
|
| 109 |
|
|
m_fpga->m_total_nread);
|
| 110 |
|
|
|
| 111 |
|
|
// Start with testing the version:
|
| 112 |
|
|
printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
|
| 113 |
|
|
|
| 114 |
|
|
// SPI flash testing
|
| 115 |
|
|
// Enable the faster (vector) reads
|
| 116 |
|
|
bool vector_read = true;
|
| 117 |
|
|
unsigned sz;
|
| 118 |
|
|
|
| 119 |
|
|
if (vector_read) {
|
| 120 |
|
|
m_fpga->readi(DUMPMEM, BUFLN, buf);
|
| 121 |
|
|
} else {
|
| 122 |
|
|
for(int i=0; i<BUFLN; i++) {
|
| 123 |
|
|
buf[i] = m_fpga->readio(DUMPMEM+i);
|
| 124 |
|
|
// if (0 == (i&0x0ff))
|
| 125 |
|
|
printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
|
| 126 |
|
|
}
|
| 127 |
|
|
}
|
| 128 |
|
|
printf("\nREAD-COMPLETE\n");
|
| 129 |
|
|
|
| 130 |
|
|
// Now, let's find the end
|
| 131 |
|
|
sz = BUFLN-1;
|
| 132 |
|
|
while((sz>0)&&(buf[sz] == 0xffffffff))
|
| 133 |
|
|
sz--;
|
| 134 |
|
|
sz+=1;
|
| 135 |
|
|
printf("The size of the buffer is 0x%06x or %d words\n", sz, sz);
|
| 136 |
|
|
|
| 137 |
14 |
dgisselq |
#define FLASHFILE "eqspidump.bin"
|
| 138 |
|
|
|
| 139 |
|
|
if (access(FLASHFILE, F_OK)==0) {
|
| 140 |
|
|
fprintf(stderr, "Cowardly refusing to overwrite %s\n", FLASHFILE);
|
| 141 |
|
|
exit(EXIT_FAILURE);
|
| 142 |
|
|
}
|
| 143 |
|
|
|
| 144 |
|
|
fp = fopen(FLASHFILE,"w");
|
| 145 |
4 |
dgisselq |
fwrite(buf, sizeof(buf[0]), sz, fp);
|
| 146 |
|
|
fclose(fp);
|
| 147 |
|
|
|
| 148 |
|
|
printf("The read was accomplished in %ld bytes over the UART\n",
|
| 149 |
|
|
m_fpga->m_total_nread);
|
| 150 |
|
|
|
| 151 |
|
|
if (m_fpga->poll())
|
| 152 |
|
|
printf("FPGA was interrupted\n");
|
| 153 |
|
|
delete m_fpga;
|
| 154 |
|
|
}
|
| 155 |
|
|
|
| 156 |
|
|
|