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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [sw/] [host/] [wbprogram.cpp] - Blame information for rev 18

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

Line No. Rev Author Line
1 18 dgisselq
////////////////////////////////////////////////////////////////////////////////
2 4 dgisselq
//
3
// Filename:    wbprogram.cpp
4
//
5 18 dgisselq
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6 4 dgisselq
//
7
// Purpose:     Program the memory with a given '.bin' file.
8
//
9 18 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11 4 dgisselq
//
12 18 dgisselq
////////////////////////////////////////////////////////////////////////////////
13 4 dgisselq
//
14 18 dgisselq
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15 4 dgisselq
//
16 18 dgisselq
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
//
39 4 dgisselq
#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 "llcomms.h"
50
#include "regdefs.h"
51
#include "flashdrvr.h"
52
 
53
DEVBUS  *m_fpga;
54
void    closeup(int v) {
55
        m_fpga->kill();
56
        exit(0);
57
}
58
 
59 18 dgisselq
unsigned byteswap(unsigned x) {
60
        unsigned r;
61
 
62
        r  = x&0x0ff; x>>=8; r<<= 8;
63
        r |= x&0x0ff; x>>=8; r<<= 8;
64
        r |= x&0x0ff; x>>=8; r<<= 8;
65
        r |= x&0x0ff;
66
 
67
        return r;
68
}
69
 
70 4 dgisselq
int main(int argc, char **argv) {
71
        FILE    *fp;
72
        const int       BUFLN = (1<<20); // 4MB Flash
73 14 dgisselq
        DEVBUS::BUSW    *buf = new DEVBUS::BUSW[BUFLN], v, addr = EQSPIFLASH;
74 4 dgisselq
        FLASHDRVR       *flash;
75
        int             argn = 1;
76
 
77
        if ((argc > argn)&&(NULL != strstr(argv[argn],"tty")))
78
                m_fpga = new FPGA(new TTYCOMMS(argv[argn++]));
79
        else if ((argc > argn)&&(NULL != strchr(argv[argn],':'))) {
80
                char *ptr = strchr(argv[argn],':');
81
                *ptr++ = '\n';
82
                m_fpga = new FPGA(new NETCOMMS(argv[argn++], atoi(ptr)));
83
        } else {
84
                FPGAOPEN(m_fpga);
85
        }
86
 
87
        // Start with testing the version:
88
        try {
89
                printf("VERSION: %08x\n", m_fpga->readio(R_VERSION));
90
        } catch(BUSERR b) {
91
                printf("VERSION: (Bus-Err)\n");
92
                exit(-1);
93
        }
94
 
95
        // SPI flash testing
96
        // Enable the faster (vector) reads
97
        bool    vector_read = true;
98
        unsigned        sz;
99
        bool            esectors[NSECTORS];
100
 
101
        argn = 1;
102
        if (argc <= argn) {
103
                printf("BAD USAGE: program [@<Address>] file.bin\n");
104
                exit(-1);
105
        } else if (argv[argn][0] == '@') {
106
                addr = strtoul(&argv[argn][1], NULL, 0);
107 14 dgisselq
                if ((addr < EQSPIFLASH)||(addr > EQSPIFLASH*2)) {
108 4 dgisselq
                        printf("BAD ADDRESS: 0x%08x (from %s)\n", addr, argv[argn]);
109
                        exit(-1);
110
                } argn++;
111
        }
112
 
113
        if (argc<= argn) {
114
                printf("BAD USAGE: no file argument\n");
115
                exit(-1);
116
        } else if (0 != access(argv[argn], R_OK)) {
117
                printf("Cannot access %s\n", argv[argn]);
118
                exit(-1);
119
        }
120
 
121
        flash = new FLASHDRVR(m_fpga);
122
 
123
        fp = fopen(argv[argn], "r");
124
        sz = fread(buf, sizeof(buf[0]), BUFLN, fp);
125
        fclose(fp);
126
 
127 18 dgisselq
        for(int i=0; i<sz; i++) {
128
                buf[i] = byteswap(buf[i]);
129
        }
130
 
131 4 dgisselq
        try {
132 14 dgisselq
                flash->write(addr, sz, buf, true);
133 4 dgisselq
        } catch(BUSERR b) {
134
                fprintf(stderr, "BUS-ERR @0x%08x\n", b.addr);
135
                exit(-1);
136
        }
137
 
138
        try {
139
                // Turn on the write protect flag
140
                m_fpga->writeio(R_QSPI_EREG, 0);
141
        } catch(BUSERR b) {
142
                fprintf(stderr, "BUS-ERR, trying to read QSPI port\n");
143
                exit(-1);
144
        }
145
 
146
        if (m_fpga->poll())
147
                printf("FPGA was interrupted\n");
148
        delete  m_fpga;
149
}
150
 
151
 

powered by: WebSVN 2.1.0

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