root/trunk/libffado/support/firmware/bridgeco-downloader.cpp

Revision 1009, 5.2 kB (checked in by ppalmers, 14 years ago)

fiddle around with the argument parsing to ease the reuse by other firmware loaders

Line 
1 /*
2  * Copyright (C) 2005-2008 by Daniel Wagner
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "downloader.h"
25
26 #include "src/bebob/bebob_dl_mgr.h"
27 #include "src/bebob/bebob_dl_bcd.h"
28
29 #include "libieee1394/configrom.h"
30 #include "libieee1394/ieee1394service.h"
31
32 #include <iostream>
33
34 using namespace std;
35
36 ////////////////////////////////////////////////
37 // arg parsing
38 ////////////////////////////////////////////////
39 const char *argp_program_version = "bridgeco-downloader 0.2";
40 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
41 const char *doc = "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n"
42                     "OPERATION: display\n"
43                     "           setguid GUID\n"
44                     "           firmware FILE\n"
45                     "           cne FILE\n"
46                     "           bcd FILE\n";
47 static struct argp_option _options[] = {
48     {"verbose",   'v', "level",     0,  "Produce verbose output" },
49     {"port",      'p', "PORT",      0,  "Set port" },
50     {"force",     'f', 0,           0,  "Force firmware download" },
51     {"noboot",    'b', 0,           0,  "Do no start bootloader (bootloader is already running)" },
52     { 0 }
53 };
54 struct argp_option* options = _options;
55
56 int
57 main( int argc, char** argv )
58 {
59
60     // arg parsing
61     argp_parse (argp, argc, argv, 0, 0, args);
62
63     if (args->nargs < 2) {
64         printDeviceList();
65         exit(0);
66     }
67
68     errno = 0;
69     char* tail;
70     int node_id = -1;
71
72     fb_octlet_t guid = strtoll(args->args[0], &tail, 0);
73     if (errno) {
74         perror("argument parsing failed:");
75         return -1;
76     }
77
78     Ieee1394Service service;
79     if ( !service.initialize( args->port ) ) {
80         cerr << "Could not initialize IEEE 1394 service" << endl;
81         return -1;
82     }
83     service.setVerboseLevel( args->verbose );
84
85     for (int i = 0; i < service.getNodeCount(); i++) {
86         ConfigRom configRom(service, i);
87         configRom.initialize();
88        
89         if (configRom.getGuid() == guid)
90             node_id = configRom.getNodeId();
91     }
92
93     if (node_id < 0) {
94         cerr << "Could not find device with matching GUID" << endl;
95         return -1;
96     }
97
98     service.setVerboseLevel( args->verbose );
99
100     BeBoB::BootloaderManager blMgr( service, node_id );
101     if ( args->force == 1 ) {
102         blMgr.setForceOperations( true );
103     }
104     blMgr.getConfigRom()->printConfigRom();
105     blMgr.printInfoRegisters();
106
107     if ( strcmp( args->args[1], "setguid" ) == 0 ) {
108         if (!args->args[2] ) {
109             cerr << "guid argument is missing" << endl;
110             return -1;
111         }
112
113         char* tail;
114         fb_octlet_t guid = strtoll(args->args[2], &tail, 0 );
115
116         if ( !blMgr.programGUID( guid ) ) {
117             cerr << "Failed to set GUID" << endl;
118             return -1;
119         } else {
120             cout << "new GUID programmed" << endl;
121         }
122     } else if ( strcmp( args->args[1], "firmware" ) == 0 ) {
123         if (!args->args[2] ) {
124             cerr << "FILE argument is missing" << endl;
125             return -1;
126         }
127         std::string str( args->args[2] );
128
129         blMgr.setStartBootloader( args->no_bootloader_restart != 1 );
130         if ( !blMgr.downloadFirmware( str ) ) {
131             cerr << "Failed to download firmware" << endl;
132             return -1;
133         } else {
134             cout << "Firmware download was successful" << endl;
135         }
136     } else if ( strcmp( args->args[1], "cne" ) == 0 ) {
137         if (!args->args[2] ) {
138             cerr << "FILE argument is missing" << endl;
139             return -1;
140         }
141         std::string str( args->args[2] );
142
143         if ( !blMgr.downloadCnE( str ) ) {
144             cerr << "Failed to download CnE" << endl;
145             return -1;
146         } else {
147             cout << "CnE download was successful" << endl;
148         }
149     } else if ( strcmp( args->args[1], "display" ) == 0 ) {
150         // nothing to do
151     } else if ( strcmp( args->args[1], "bcd" ) == 0 ) {
152         if ( !args->args[2] ) {
153             cerr << "FILE arguments is missing" << endl;
154             return -1;
155         }
156         BeBoB::BCD* bcd = new BeBoB::BCD::BCD( args->args[2] );
157         if ( !bcd ) {
158             cerr << "Could no open file " << args->args[2] << endl;
159             return -1;
160         }
161         if ( !bcd->parse() ) {
162             cerr << "Could not parse file " << args->args[2] << endl;
163             return -1;
164         }
165
166         bcd->displayInfo();
167         delete bcd;
168     } else {
169         cout << "Unknown operation" << endl;
170     }
171
172     return 0;
173 }
Note: See TracBrowser for help on using the browser.