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

Revision 1234, 5.2 kB (checked in by holin, 16 years ago)

fix gcc 4.3 compile errors and some warnings (largely from Adrian Knoth)

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 #include <cstdlib>
34 #include <cstring>
35
36 using namespace std;
37
38 ////////////////////////////////////////////////
39 // arg parsing
40 ////////////////////////////////////////////////
41 const char *argp_program_version = "bridgeco-downloader 0.2";
42 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
43 const char *doc = "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n"
44                     "OPERATION: display\n"
45                     "           setguid GUID\n"
46                     "           firmware FILE\n"
47                     "           cne FILE\n"
48                     "           bcd FILE\n";
49 static struct argp_option _options[] = {
50     {"verbose",   'v', "level",     0,  "Produce verbose output" },
51     {"port",      'p', "PORT",      0,  "Set port" },
52     {"force",     'f', 0,           0,  "Force firmware download" },
53     {"noboot",    'b', 0,           0,  "Do no start bootloader (bootloader is already running)" },
54     { 0 }
55 };
56 struct argp_option* options = _options;
57
58 int
59 main( int argc, char** argv )
60 {
61
62     // arg parsing
63     argp_parse (argp, argc, argv, 0, 0, args);
64
65     if (args->nargs < 2) {
66         printDeviceList();
67         exit(0);
68     }
69
70     errno = 0;
71     char* tail;
72     int node_id = -1;
73
74     fb_octlet_t guid = strtoll(args->args[0], &tail, 0);
75     if (errno) {
76         perror("argument parsing failed:");
77         return -1;
78     }
79
80     Ieee1394Service service;
81     if ( !service.initialize( args->port ) ) {
82         cerr << "Could not initialize IEEE 1394 service" << endl;
83         return -1;
84     }
85     service.setVerboseLevel( args->verbose );
86
87     for (int i = 0; i < service.getNodeCount(); i++) {
88         ConfigRom configRom(service, i);
89         configRom.initialize();
90        
91         if (configRom.getGuid() == guid)
92             node_id = configRom.getNodeId();
93     }
94
95     if (node_id < 0) {
96         cerr << "Could not find device with matching GUID" << endl;
97         return -1;
98     }
99
100     service.setVerboseLevel( args->verbose );
101
102     BeBoB::BootloaderManager blMgr( service, node_id );
103     if ( args->force == 1 ) {
104         blMgr.setForceOperations( true );
105     }
106     blMgr.getConfigRom()->printConfigRom();
107     blMgr.printInfoRegisters();
108
109     if ( strcmp( args->args[1], "setguid" ) == 0 ) {
110         if (!args->args[2] ) {
111             cerr << "guid argument is missing" << endl;
112             return -1;
113         }
114
115         char* tail;
116         fb_octlet_t guid = strtoll(args->args[2], &tail, 0 );
117
118         if ( !blMgr.programGUID( guid ) ) {
119             cerr << "Failed to set GUID" << endl;
120             return -1;
121         } else {
122             cout << "new GUID programmed" << endl;
123         }
124     } else if ( strcmp( args->args[1], "firmware" ) == 0 ) {
125         if (!args->args[2] ) {
126             cerr << "FILE argument is missing" << endl;
127             return -1;
128         }
129         std::string str( args->args[2] );
130
131         blMgr.setStartBootloader( args->no_bootloader_restart != 1 );
132         if ( !blMgr.downloadFirmware( str ) ) {
133             cerr << "Failed to download firmware" << endl;
134             return -1;
135         } else {
136             cout << "Firmware download was successful" << endl;
137         }
138     } else if ( strcmp( args->args[1], "cne" ) == 0 ) {
139         if (!args->args[2] ) {
140             cerr << "FILE argument is missing" << endl;
141             return -1;
142         }
143         std::string str( args->args[2] );
144
145         if ( !blMgr.downloadCnE( str ) ) {
146             cerr << "Failed to download CnE" << endl;
147             return -1;
148         } else {
149             cout << "CnE download was successful" << endl;
150         }
151     } else if ( strcmp( args->args[1], "display" ) == 0 ) {
152         // nothing to do
153     } else if ( strcmp( args->args[1], "bcd" ) == 0 ) {
154         if ( !args->args[2] ) {
155             cerr << "FILE arguments is missing" << endl;
156             return -1;
157         }
158         BeBoB::BCD* bcd = new BeBoB::BCD::BCD( args->args[2] );
159         if ( !bcd ) {
160             cerr << "Could no open file " << args->args[2] << endl;
161             return -1;
162         }
163         if ( !bcd->parse() ) {
164             cerr << "Could not parse file " << args->args[2] << endl;
165             return -1;
166         }
167
168         bcd->displayInfo();
169         delete bcd;
170     } else {
171         cout << "Unknown operation" << endl;
172     }
173
174     return 0;
175 }
Note: See TracBrowser for help on using the browser.