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 3

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

powered by: WebSVN 2.1.0

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