1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* Copyright (C) 2005-2008 by Daniel Wagner |
---|
4 |
* |
---|
5 |
* This file is part of FFADO |
---|
6 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
7 |
* |
---|
8 |
* FFADO is based upon FreeBoB |
---|
9 |
* |
---|
10 |
* This program is free software: you can redistribute it and/or modify |
---|
11 |
* it under the terms of the GNU General Public License as published by |
---|
12 |
* the Free Software Foundation, either version 2 of the License, or |
---|
13 |
* (at your option) version 3 of the License. |
---|
14 |
* |
---|
15 |
* This program is distributed in the hope that it will be useful, |
---|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 |
* GNU General Public License for more details. |
---|
19 |
* |
---|
20 |
* You should have received a copy of the GNU General Public License |
---|
21 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
22 |
* |
---|
23 |
*/ |
---|
24 |
|
---|
25 |
#include "downloader.h" |
---|
26 |
|
---|
27 |
#include "src/fireworks/fireworks_device.h" |
---|
28 |
#include "src/fireworks/fireworks_firmware.h" |
---|
29 |
|
---|
30 |
#include "libieee1394/configrom.h" |
---|
31 |
#include "libieee1394/ieee1394service.h" |
---|
32 |
|
---|
33 |
#include "debugmodule/debugmodule.h" |
---|
34 |
|
---|
35 |
#include "devicemanager.h" |
---|
36 |
|
---|
37 |
#include <iostream> |
---|
38 |
|
---|
39 |
#include <string.h> |
---|
40 |
#include <string> |
---|
41 |
|
---|
42 |
using namespace FireWorks; |
---|
43 |
|
---|
44 |
DECLARE_GLOBAL_DEBUG_MODULE; |
---|
45 |
|
---|
46 |
//////////////////////////////////////////////// |
---|
47 |
// arg parsing |
---|
48 |
//////////////////////////////////////////////// |
---|
49 |
const char *argp_program_version = "fireworks-downloader 0.2"; |
---|
50 |
const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; |
---|
51 |
const char *doc = "fireworks-downloader -- firmware downloader application for ECHO Fireworks devices\n\n" |
---|
52 |
"OPERATION: display\n" |
---|
53 |
" firmware FILE\n"; |
---|
54 |
|
---|
55 |
static struct argp_option _options[] = { |
---|
56 |
{"verbose", 'v', "level", 0, "Produce verbose output" }, |
---|
57 |
{"port", 'p', "PORT", 0, "Set port" }, |
---|
58 |
{ 0 } |
---|
59 |
}; |
---|
60 |
struct argp_option* options = _options; |
---|
61 |
|
---|
62 |
int |
---|
63 |
main( int argc, char** argv ) |
---|
64 |
{ |
---|
65 |
using namespace std; |
---|
66 |
|
---|
67 |
argp_parse (argp, argc, argv, 0, 0, args); |
---|
68 |
|
---|
69 |
errno = 0; |
---|
70 |
char* tail; |
---|
71 |
int node_id = -1; |
---|
72 |
|
---|
73 |
fb_octlet_t guid = strtoll(args->args[0], &tail, 0); |
---|
74 |
if (errno) { |
---|
75 |
debugError("argument parsing failed: %s\n", |
---|
76 |
strerror(errno)); |
---|
77 |
return -1; |
---|
78 |
} |
---|
79 |
|
---|
80 |
Ieee1394Service service; |
---|
81 |
if ( !service.initialize( args->port ) ) { |
---|
82 |
debugError("Could not initialize IEEE 1394 service\n"); |
---|
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 |
ConfigRom *configRom = new ConfigRom(service, node_id ); |
---|
101 |
if (configRom == NULL) { |
---|
102 |
debugError("Could not create ConfigRom\n"); |
---|
103 |
return -1; |
---|
104 |
} |
---|
105 |
configRom->setVerboseLevel( args->verbose ); |
---|
106 |
|
---|
107 |
if ( !configRom->initialize() ) { |
---|
108 |
debugError( "Could not read config rom from device (node id %d).\n", |
---|
109 |
node_id ); |
---|
110 |
delete configRom; |
---|
111 |
return -1; |
---|
112 |
} |
---|
113 |
|
---|
114 |
if ( !Device::probe(*configRom) ) { |
---|
115 |
debugError( "Device with node id %d is not an ECHO FireWorks device.\n", |
---|
116 |
node_id ); |
---|
117 |
delete configRom; |
---|
118 |
return -1; |
---|
119 |
} |
---|
120 |
|
---|
121 |
DeviceManager d = DeviceManager(); |
---|
122 |
Device *dev = new Device(d, std::auto_ptr<ConfigRom>(configRom) ); |
---|
123 |
if (dev == NULL) { |
---|
124 |
debugError("Could not create FireWorks::Device\n"); |
---|
125 |
delete configRom; |
---|
126 |
return -1; |
---|
127 |
} |
---|
128 |
|
---|
129 |
// create the firmware util class |
---|
130 |
FirmwareUtil util = FirmwareUtil(*dev); |
---|
131 |
util.setVerboseLevel( args->verbose ); |
---|
132 |
|
---|
133 |
if ( strcmp( args->args[1], "firmware" ) == 0 ) { |
---|
134 |
if (!args->args[2] ) { |
---|
135 |
cerr << "FILE argument is missing" << endl; |
---|
136 |
delete dev; |
---|
137 |
return -1; |
---|
138 |
} |
---|
139 |
std::string str( args->args[2] ); |
---|
140 |
|
---|
141 |
// load the file |
---|
142 |
Firmware f = Firmware(); |
---|
143 |
f.setVerboseLevel( args->verbose ); |
---|
144 |
|
---|
145 |
f.loadFile(str); |
---|
146 |
f.show(); |
---|
147 |
|
---|
148 |
} else if ( strcmp( args->args[1], "display" ) == 0 ) { |
---|
149 |
// nothing to do |
---|
150 |
dev->showDevice(); |
---|
151 |
} else { |
---|
152 |
cout << "Unknown operation" << endl; |
---|
153 |
} |
---|
154 |
|
---|
155 |
delete dev; |
---|
156 |
return 0; |
---|
157 |
} |
---|