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

Subversion Repositories usb_fpga_1_2

[/] [usb_fpga_1_2/] [trunk/] [java/] [FWLoader.java] - Blame information for rev 5

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

Line No. Rev Author Line
1 2 ZTEX
/*!
2
   Firmware / Bitstream loader for the ZTEX Firmware Kit
3 4 ZTEX
   Copyright (C) 2009-2010 ZTEX e.K.
4 2 ZTEX
   http://www.ztex.de
5
 
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License version 3 as
8
   published by the Free Software Foundation.
9
 
10
   This program is distributed in the hope that it will be useful, but
11
   WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
   General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, see http://www.gnu.org/licenses/.
17
!*/
18
 
19
/*
20
    Firmware Loader and FPGA Configurater
21
*/
22
 
23
import java.io.*;
24
import java.util.*;
25
 
26
import ch.ntb.usb.*;
27
 
28
import ztex.*;
29
 
30
class FWLoader {
31
 
32
// ******* main ****************************************************************
33
    public static void main (String args[]) {
34
        LibusbJava.usb_init();
35
 
36
        final String helpMsg = new String (
37
                        "Global parameters:\n"+
38 5 ZTEX
                        "    -c               Scan for Cypress EZ-USB devices without ZTEX firmware\n"+
39 2 ZTEX
                        "    -v <VID> <PID>   Scan for devices with ZTEX firmware and the given Vendor ID and Product ID\n"+
40
                        "    -vc              Equal to -v 0x4b4 0x8613\n"+
41
                        "    -d <number>      Device Number (default: 0)\n"+
42
                        "    -f               Force uploads\n"+
43
                        "    -p               Print bus info\n"+
44 5 ZTEX
                        "    -w               Enable certain workarounds\n"+
45 2 ZTEX
                        "    -h               This help \n\n"+
46
                        "Ordered parameters:\n"+
47
                        "    -i               Info\n"+
48
                        "    -ii              Info + capabilities\n"+
49 4 ZTEX
                        "    -if              Read FPGA state\n"+
50 2 ZTEX
                        "    -ru              Reset EZ-USB Microcontroller\n"+
51
                        "    -uu <ihx file>   Upload EZ-USB Firmware\n"+
52 5 ZTEX
                        "    -bs 0|1|A        Bit swapping for bitstreams: 0: disable, 1: enable, A: automatic detection\n"+
53 2 ZTEX
                        "    -rf              Reset FPGA\n"+
54 5 ZTEX
                        "    -uf <bitstream>  Upload bitstream to FPGA\n"+
55 2 ZTEX
                        "    -re              Reset EEPROM Firmware\n"+
56 3 ZTEX
                        "    -ue <ihx file>   Upload Firmware to EEPROM\n"+
57
                        "    -rm              Reset FLASH bitstream\n"+
58 5 ZTEX
                        "    -um <bitstream>  Upload bitstream to Flash");
59 2 ZTEX
 
60
 
61
// process global parameters
62
        try {
63
 
64 4 ZTEX
            int usbVendorId = ZtexDevice1.ztexVendorId;
65 2 ZTEX
            int usbProductId = -1;
66
            boolean cypress = false;
67
            int devNum = 0;
68
            boolean forceUpload = false;
69
            boolean printBus = false;
70
            boolean workarounds = false;
71 5 ZTEX
            int bs = -1;
72 2 ZTEX
 
73
            for (int i=0; i<args.length; i++ ) {
74
                if ( args[i].equals("-c") ) {
75
                    cypress = true;
76
                }
77
                else if ( args[i].equals("-v") ) {
78
                    i++;
79
                    try {
80
                        if (i>=args.length)
81
                            throw new Exception();
82
                        usbVendorId = Integer.decode( args[i] );
83
                    }
84
                    catch (Exception e) {
85
                        System.err.println("Error: Vendor ID expected after -v");
86
                        System.err.println(helpMsg);
87
                        System.exit(1);
88
                    }
89
                    i++;
90
                    try {
91
                        if (i>=args.length)
92
                            throw new Exception();
93
                        usbProductId = Integer.decode( args[i] );
94
                    }
95
                    catch (Exception e) {
96
                        System.err.println("Error: Product ID expected after -v <VID>");
97
                        System.err.println(helpMsg);
98
                        System.exit(1);
99
                    }
100
                }
101
                else if ( args[i].equals("-vc") ) {
102 4 ZTEX
                    usbVendorId = ZtexDevice1.cypressVendorId;
103
                    usbProductId = ZtexDevice1.cypressProductId;
104 2 ZTEX
                }
105
                else if ( args[i].equals("-f") ) {
106
                    forceUpload = true;
107
                }
108
                else if ( args[i].equals("-p") ) {
109
                    printBus = true;
110
                }
111
                else if ( args[i].equals("-w") ) {
112
                    workarounds = true;
113
                }
114
                else if ( args[i].equals("-d") ) {
115
                    i++;
116
                    try {
117
                        if (i>=args.length)
118
                            throw new Exception();
119
                        devNum = Integer.parseInt( args[i] );
120
                    }
121
                    catch (Exception e) {
122
                        System.err.println("Error: Device number expected after -d");
123
                        System.err.println(helpMsg);
124
                        System.exit(1);
125
                    }
126
                }
127
                else if ( args[i].equals("-h") ) {
128
                        System.err.println(helpMsg);
129
                        System.exit(0);
130
                }
131 4 ZTEX
                else if ( args[i].equals("-i") || args[i].equals("-ii") || args[i].equals("-if") || args[i].equals("-ru") || args[i].equals("-rf") || args[i].equals("-re") || args[i].equals("-rm") ) {
132 2 ZTEX
                }
133 5 ZTEX
                else if ( args[i].equals("-uu") || args[i].equals("-uf") || args[i].equals("-ue") || args[i].equals("-um") || args[i].equals("-bs") ) {
134 2 ZTEX
                    i+=1;
135
                }
136
                else {
137
                    System.err.println("Error: Invalid Parameter: "+args[i]);
138
                    System.err.println(helpMsg);
139
                    System.exit(1);
140
                }
141
            }
142
 
143
// process ordered parameters
144
            ZtexScanBus1 bus = new ZtexScanBus1( usbVendorId, usbProductId, cypress, false, 1);
145
            if ( bus.numberOfDevices() <= 0 ) {
146
                System.err.println("No devices found");
147
                System.exit(0);
148
            }
149
            if ( printBus )
150
                bus.printBus(System.out);
151
 
152
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
153
            ztex.certainWorkarounds = workarounds;
154
 
155
            for (int i=0; i<args.length; i++ ) {
156
                if ( args[i].equals("-i") ) {
157
                    System.out.println( ztex );
158
                }
159
                if ( args[i].equals("-ii") ) {
160
                    System.out.println( ztex );
161 3 ZTEX
                    String str = ztex.capabilityInfo("\n      ");
162 2 ZTEX
                    if ( str.equals("") ) {
163
                        System.out.println( "   No capabilities");
164
                    }
165
                    else {
166 3 ZTEX
                        System.out.println( "   Capabilities:\n      "+str);
167 2 ZTEX
                    }
168
                }
169 4 ZTEX
                if ( args[i].equals("-if") ) {
170
                    ztex.printFpgaState();
171
                }
172 2 ZTEX
                else if ( args[i].equals("-ru") ) {
173
                    ztex.resetEzUsb();
174
                }
175
                else if ( args[i].equals("-uu") ) {
176
                    i++;
177
                    if ( i >= args.length ) {
178
                        System.err.println("Error: Filename expected after -uu");
179
                        System.err.println(helpMsg);
180
                        System.exit(1);
181
                    }
182
                    System.out.println("Firmware upload time: " + ztex.uploadFirmware( args[i], forceUpload ) + " ms");
183
                }
184 5 ZTEX
                else if ( args[i].equals("-bs") ) {
185 2 ZTEX
                    i++;
186 5 ZTEX
                    if ( (i>=args.length) || !( args[i].equals("0") || args[i].equals("1") || args[i].equalsIgnoreCase("A") ) ) {
187
                        System.err.println("Error: `0',`1' or `A' expected after -bs");
188 2 ZTEX
                        System.err.println(helpMsg);
189
                        System.exit(1);
190
                    }
191 5 ZTEX
                    if ( args[i].equals("0") )
192
                        bs = 0;
193
                    else if ( args[i].equals("1") )
194
                        bs = 1;
195
                    else bs = -1;
196 2 ZTEX
                }
197
                else if ( args[i].equals("-rf") ) {
198
                    ztex.resetFpga();
199
                }
200
                else if ( args[i].equals("-uf") ) {
201
                    i++;
202
                    if ( i >= args.length ) {
203
                        System.err.println("Error: Filename expected after -uf");
204
                        System.err.println(helpMsg);
205
                        System.exit(1);
206
                    }
207 5 ZTEX
                    System.out.println("FPGA configuration time: " + ztex.configureFpga( args[i], forceUpload, bs ) + " ms");
208 2 ZTEX
                }
209 5 ZTEX
                else if ( args[i].equals("-re") ) {
210
                    ztex.eepromDisable();
211
                }
212
                else if ( args[i].equals("-ue") ) {
213
                    i++;
214
                    if ( i >= args.length ) {
215
                        System.err.println("Error: Filename expected after -ue");
216
                        System.err.println(helpMsg);
217
                        System.exit(1);
218
                    }
219
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( args[i], forceUpload ) + " ms");
220
                }
221 3 ZTEX
                else if ( args[i].equals("-rm") ) {
222
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
223
                    ztex.flashResetBitstream();
224
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
225
                }
226
                else if ( args[i].equals("-um") ) {
227
                    i++;
228
                    if ( i >= args.length ) {
229
                        System.err.println("Error: Filename expected after -uf");
230
                        System.err.println(helpMsg);
231
                        System.exit(1);
232
                    }
233
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
234 5 ZTEX
                    System.out.println("FPGA configuration time: " + ztex.flashUploadBitstream( args[i], bs ) + " ms");
235 3 ZTEX
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
236
                }
237 2 ZTEX
            }
238
        }
239
        catch (Exception e) {
240
            System.out.println("Error: "+e.getLocalizedMessage() );
241
        }
242
   }
243
 
244
}

powered by: WebSVN 2.1.0

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