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 2

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

powered by: WebSVN 2.1.0

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