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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [readflash.cpp] - Diff between revs 11 and 45

Only display areas with differences | Details | Blame | View Log

Rev 11 Rev 45
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Filename:    readflash.cpp
// Filename:    readflash.cpp
//
//
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
//
//
// Purpose:     Read/Empty the entire contents of the flash memory to a file.
// Purpose:     Read/Empty the entire contents of the flash memory to a file.
//              The flash is unchanged by this process.
//              The flash is unchanged by this process.
//
//
// Creator:     Dan Gisselquist, Ph.D.
// Creator:     Dan Gisselquist, Ph.D.
//              Gisselquist Technology, LLC
//              Gisselquist Technology, LLC
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
//
//
// This program is free software (firmware): you can redistribute it and/or
// 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
// 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
// by the Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
// your option) any later version.
//
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
// for more details.
//
//
// You should have received a copy of the GNU General Public License along
// You should have received a copy of the GNU General Public License along
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
// target there if the PDF file isn't present.)  If not, see
// target there if the PDF file isn't present.)  If not, see
// <http://www.gnu.org/licenses/> for a copy.
// <http://www.gnu.org/licenses/> for a copy.
//
//
// License:     GPL, v3, as defined and found on www.gnu.org,
// License:     GPL, v3, as defined and found on www.gnu.org,
//              http://www.gnu.org/licenses/gpl.html
//              http://www.gnu.org/licenses/gpl.html
//
//
//
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <strings.h>
#include <strings.h>
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include <signal.h>
#include <signal.h>
#include <assert.h>
#include <assert.h>
 
 
#include "devbus.h"
#include "devbus.h"
#include "llcomms.h"
#include "llcomms.h"
#include "deppi.h"
#include "deppi.h"
#include "ttybus.h"
#include "ttybus.h"
#include "regdefs.h"
#include "regdefs.h"
 
 
#define FPGAOPEN(SN)    new FPGA(new DEPPI(SN))
#define FPGAOPEN(SN)    new FPGA(new DEPPI(SN))
 
 
FPGA    *m_fpga;
FPGA    *m_fpga;
void    closeup(int v) {
void    closeup(int v) {
        m_fpga->kill();
        m_fpga->kill();
        exit(0);
        exit(0);
}
}
 
 
// #define      DUMPMEM         RAMBASE
// #define      DUMPMEM         RAMBASE
// #define      DUMPWORDS       MEMWORDS
// #define      DUMPWORDS       MEMWORDS
 
 
#define DUMPMEM         SPIFLASH
#define DUMPMEM         SPIFLASH
#define DUMPWORDS       FLASHWORDS      // 1MB Flash
#define DUMPWORDS       FLASHWORDS      // 1MB Flash
 
 
int main(int argc, char **argv) {
int main(int argc, char **argv) {
        FILE    *fp;
        FILE    *fp;
        const int       BUFLN = DUMPWORDS;
        const int       BUFLN = DUMPWORDS;
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN];
        FPGA::BUSW      *buf = new FPGA::BUSW[BUFLN];
 
 
        char    szSel[64];
        char    szSel[64];
        strcpy(szSel, "SN:210282768825");
        strcpy(szSel, S6SN);
        m_fpga = FPGAOPEN(szSel);
        m_fpga = FPGAOPEN(szSel);
 
 
        fprintf(stderr, "Before starting, nread = %ld\n",
        fprintf(stderr, "Before starting, nread = %ld\n",
                m_fpga->m_total_nread);
                m_fpga->m_total_nread);
 
 
        // Start with testing the version:
        // Start with testing the version:
        printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
        printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
 
 
        // SPI flash testing
        // SPI flash testing
        // Enable the faster (vector) reads
        // Enable the faster (vector) reads
        bool    vector_read = true;
        bool    vector_read = true;
        unsigned        sz;
        unsigned        sz;
 
 
        if (vector_read) {
        if (vector_read) {
                try {
                try {
                for(int i=0; i<BUFLN; i+= 2048) {
                for(int i=0; i<BUFLN; i+= 2048) {
                        printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
                        printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
 
 
                        m_fpga->readi(DUMPMEM+i, 2048, &buf[i]);
                        m_fpga->readi(DUMPMEM+i, 2048, &buf[i]);
                }} catch(BUSERR a) {
                }} catch(BUSERR a) {
                        printf("%08x : BUS-ERR\n", a.addr);
                        printf("%08x : BUS-ERR\n", a.addr);
                }
                }
        } else {
        } else {
                for(int i=0; i<BUFLN; i++) {
                for(int i=0; i<BUFLN; i++) {
                        buf[i] = m_fpga->readio(DUMPMEM+i);
                        buf[i] = m_fpga->readio(DUMPMEM+i);
                        // if (0 == (i&0x0ff))
                        // if (0 == (i&0x0ff))
                                printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
                                printf("i = %02x / %04x, addr = i + %04x = %08x\n", i, BUFLN, DUMPMEM, i+DUMPMEM);
                }
                }
        }
        }
        printf("\nREAD-COMPLETE\n");
        printf("\nREAD-COMPLETE\n");
 
 
        // Now, let's find the end
        // Now, let's find the end
        sz = BUFLN-1;
        sz = BUFLN-1;
        while((sz>0)&&(buf[sz] == 0xffffffff))
        while((sz>0)&&(buf[sz] == 0xffffffff))
                sz--;
                sz--;
        sz+=1;
        sz+=1;
        printf("The size of the buffer is 0x%06x or %d words\n", sz, sz);
        printf("The size of the buffer is 0x%06x or %d words\n", sz, sz);
 
 
        fp = fopen("qspiflash.bin","w");
        fp = fopen("qspiflash.bin","w");
        fwrite(buf, sizeof(buf[0]), sz, fp);
        fwrite(buf, sizeof(buf[0]), sz, fp);
        fclose(fp);
        fclose(fp);
 
 
        printf("The read was accomplished in %ld bytes over the UART\n",
        printf("The read was accomplished in %ld bytes over the UART\n",
                m_fpga->m_total_nread);
                m_fpga->m_total_nread);
 
 
        if (m_fpga->poll())
        if (m_fpga->poll())
                printf("FPGA was interrupted\n");
                printf("FPGA was interrupted\n");
        delete  m_fpga;
        delete  m_fpga;
}
}
 
 
 
 
 
 

powered by: WebSVN 2.1.0

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