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 4

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
                        "    -c               Scan for Cypres EZ-USB devices without ZTEX firmware\n"+
39
                        "    -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 3 ZTEX
                        "    -w               Enable certain workaraounds\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
                        "    -rf              Reset FPGA\n"+
53
                        "    -uf <bitstream>  Upload <bitstream>\n"+
54
                        "    -re              Reset EEPROM Firmware\n"+
55 3 ZTEX
                        "    -ue <ihx file>   Upload Firmware to EEPROM\n"+
56
                        "    -rm              Reset FLASH bitstream\n"+
57
                        "    -um <bitstream>  Upload Firmware to FLASH");
58 2 ZTEX
 
59
 
60
// process global parameters
61
        try {
62
 
63 4 ZTEX
            int usbVendorId = ZtexDevice1.ztexVendorId;
64 2 ZTEX
            int usbProductId = -1;
65
            boolean cypress = false;
66
            int devNum = 0;
67
            boolean forceUpload = false;
68
            boolean printBus = false;
69
            boolean workarounds = false;
70
 
71
            for (int i=0; i<args.length; i++ ) {
72
                if ( args[i].equals("-c") ) {
73
                    cypress = true;
74
                }
75
                else if ( args[i].equals("-v") ) {
76
                    i++;
77
                    try {
78
                        if (i>=args.length)
79
                            throw new Exception();
80
                        usbVendorId = Integer.decode( args[i] );
81
                    }
82
                    catch (Exception e) {
83
                        System.err.println("Error: Vendor ID expected after -v");
84
                        System.err.println(helpMsg);
85
                        System.exit(1);
86
                    }
87
                    i++;
88
                    try {
89
                        if (i>=args.length)
90
                            throw new Exception();
91
                        usbProductId = Integer.decode( args[i] );
92
                    }
93
                    catch (Exception e) {
94
                        System.err.println("Error: Product ID expected after -v <VID>");
95
                        System.err.println(helpMsg);
96
                        System.exit(1);
97
                    }
98
                }
99
                else if ( args[i].equals("-vc") ) {
100 4 ZTEX
                    usbVendorId = ZtexDevice1.cypressVendorId;
101
                    usbProductId = ZtexDevice1.cypressProductId;
102 2 ZTEX
                }
103
                else if ( args[i].equals("-f") ) {
104
                    forceUpload = true;
105
                }
106
                else if ( args[i].equals("-p") ) {
107
                    printBus = true;
108
                }
109
                else if ( args[i].equals("-w") ) {
110
                    workarounds = true;
111
                }
112
                else if ( args[i].equals("-d") ) {
113
                    i++;
114
                    try {
115
                        if (i>=args.length)
116
                            throw new Exception();
117
                        devNum = Integer.parseInt( args[i] );
118
                    }
119
                    catch (Exception e) {
120
                        System.err.println("Error: Device number expected after -d");
121
                        System.err.println(helpMsg);
122
                        System.exit(1);
123
                    }
124
                }
125
                else if ( args[i].equals("-h") ) {
126
                        System.err.println(helpMsg);
127
                        System.exit(0);
128
                }
129 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") ) {
130 2 ZTEX
                }
131 3 ZTEX
                else if ( args[i].equals("-uu") || args[i].equals("-uf") || args[i].equals("-ue") || args[i].equals("-um") ) {
132 2 ZTEX
                    i+=1;
133
                }
134
                else {
135
                    System.err.println("Error: Invalid Parameter: "+args[i]);
136
                    System.err.println(helpMsg);
137
                    System.exit(1);
138
                }
139
            }
140
 
141
// process ordered parameters
142
            ZtexScanBus1 bus = new ZtexScanBus1( usbVendorId, usbProductId, cypress, false, 1);
143
            if ( bus.numberOfDevices() <= 0 ) {
144
                System.err.println("No devices found");
145
                System.exit(0);
146
            }
147
            if ( printBus )
148
                bus.printBus(System.out);
149
 
150
            Ztex1v1 ztex = new Ztex1v1 ( bus.device(devNum) );
151
            ztex.certainWorkarounds = workarounds;
152
 
153
            for (int i=0; i<args.length; i++ ) {
154
                if ( args[i].equals("-i") ) {
155
                    System.out.println( ztex );
156
                }
157
                if ( args[i].equals("-ii") ) {
158
                    System.out.println( ztex );
159 3 ZTEX
                    String str = ztex.capabilityInfo("\n      ");
160 2 ZTEX
                    if ( str.equals("") ) {
161
                        System.out.println( "   No capabilities");
162
                    }
163
                    else {
164 3 ZTEX
                        System.out.println( "   Capabilities:\n      "+str);
165 2 ZTEX
                    }
166
                }
167 4 ZTEX
                if ( args[i].equals("-if") ) {
168
                    ztex.printFpgaState();
169
                }
170 2 ZTEX
                else if ( args[i].equals("-ru") ) {
171
                    ztex.resetEzUsb();
172
                }
173
                else if ( args[i].equals("-uu") ) {
174
                    i++;
175
                    if ( i >= args.length ) {
176
                        System.err.println("Error: Filename expected after -uu");
177
                        System.err.println(helpMsg);
178
                        System.exit(1);
179
                    }
180
                    System.out.println("Firmware upload time: " + ztex.uploadFirmware( args[i], forceUpload ) + " ms");
181
                }
182
                else if ( args[i].equals("-re") ) {
183
                    ztex.eepromDisable();
184
                }
185
                else if ( args[i].equals("-ue") ) {
186
                    i++;
187
                    if ( i >= args.length ) {
188
                        System.err.println("Error: Filename expected after -ue");
189
                        System.err.println(helpMsg);
190
                        System.exit(1);
191
                    }
192
                    System.out.println("Firmware to EEPROM upload time: " + ztex.eepromUpload( args[i], forceUpload ) + " ms");
193
                }
194
                else if ( args[i].equals("-rf") ) {
195
                    ztex.resetFpga();
196
                }
197
                else if ( args[i].equals("-uf") ) {
198
                    i++;
199
                    if ( i >= args.length ) {
200
                        System.err.println("Error: Filename expected after -uf");
201
                        System.err.println(helpMsg);
202
                        System.exit(1);
203
                    }
204
                    System.out.println("FPGA configuration time: " + ztex.configureFpga( args[i], forceUpload ) + " ms");
205
                }
206 3 ZTEX
                else if ( args[i].equals("-rm") ) {
207
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
208
                    ztex.flashResetBitstream();
209
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
210
                }
211
                else if ( args[i].equals("-um") ) {
212
                    i++;
213
                    if ( i >= args.length ) {
214
                        System.err.println("Error: Filename expected after -uf");
215
                        System.err.println(helpMsg);
216
                        System.exit(1);
217
                    }
218
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
219
                    System.out.println("FPGA configuration time: " + ztex.flashUploadBitstream( args[i] ) + " ms");
220
                    System.out.println("First free sector: " + ztex.flashFirstFreeSector() );
221
                }
222 2 ZTEX
            }
223
        }
224
        catch (Exception e) {
225
            System.out.println("Error: "+e.getLocalizedMessage() );
226
        }
227
   }
228
 
229
}

powered by: WebSVN 2.1.0

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