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

Revision 900, 5.1 kB (checked in by wagi, 16 years ago)

Use GUID instead node id for download application. Furthermore, factor out common code from both firmware downloaders

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 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     errno = 0;
64     char* tail;
65     int node_id = -1;
66
67     fb_octlet_t guid = strtoll(args->args[0], &tail, 0);
68     if (errno) {
69         perror("argument parsing failed:");
70         return -1;
71     }
72
73     Ieee1394Service service;
74     if ( !service.initialize( args->port ) ) {
75         cerr << "Could not initialize IEEE 1394 service" << endl;
76         return -1;
77     }
78     service.setVerboseLevel( args->verbose );
79
80     for (int i = 0; i < service.getNodeCount(); i++) {
81         ConfigRom configRom(service, i);
82         configRom.initialize();
83        
84         if (configRom.getGuid() == guid)
85             node_id = configRom.getNodeId();
86     }
87
88     if (node_id < 0) {
89         cerr << "Could not find device with matching GUID" << endl;
90         return -1;
91     }
92
93     service.setVerboseLevel( args->verbose );
94
95     BeBoB::BootloaderManager blMgr( service, node_id );
96     if ( args->force == 1 ) {
97         blMgr.setForceOperations( true );
98     }
99     blMgr.getConfigRom()->printConfigRom();
100     blMgr.printInfoRegisters();
101
102     if ( strcmp( args->args[1], "setguid" ) == 0 ) {
103         if (!args->args[2] ) {
104             cerr << "guid argument is missing" << endl;
105             return -1;
106         }
107
108         char* tail;
109         fb_octlet_t guid = strtoll(args->args[2], &tail, 0 );
110
111         if ( !blMgr.programGUID( guid ) ) {
112             cerr << "Failed to set GUID" << endl;
113             return -1;
114         } else {
115             cout << "new GUID programmed" << endl;
116         }
117     } else if ( strcmp( args->args[1], "firmware" ) == 0 ) {
118         if (!args->args[2] ) {
119             cerr << "FILE argument is missing" << endl;
120             return -1;
121         }
122         std::string str( args->args[2] );
123
124         blMgr.setStartBootloader( args->no_bootloader_restart != 1 );
125         if ( !blMgr.downloadFirmware( str ) ) {
126             cerr << "Failed to download firmware" << endl;
127             return -1;
128         } else {
129             cout << "Firmware download was successful" << endl;
130         }
131     } else if ( strcmp( args->args[1], "cne" ) == 0 ) {
132         if (!args->args[2] ) {
133             cerr << "FILE argument is missing" << endl;
134             return -1;
135         }
136         std::string str( args->args[2] );
137
138         if ( !blMgr.downloadCnE( str ) ) {
139             cerr << "Failed to download CnE" << endl;
140             return -1;
141         } else {
142             cout << "CnE download was successful" << endl;
143         }
144     } else if ( strcmp( args->args[1], "display" ) == 0 ) {
145         // nothing to do
146     } else if ( strcmp( args->args[1], "bcd" ) == 0 ) {
147         if ( !args->args[2] ) {
148             cerr << "FILE arguments is missing" << endl;
149             return -1;
150         }
151         BeBoB::BCD* bcd = new BeBoB::BCD::BCD( args->args[2] );
152         if ( !bcd ) {
153             cerr << "Could no open file " << args->args[2] << endl;
154             return -1;
155         }
156         if ( !bcd->parse() ) {
157             cerr << "Could not parse file " << args->args[2] << endl;
158             return -1;
159         }
160
161         bcd->displayInfo();
162         delete bcd;
163     } else {
164         cout << "Unknown operation" << endl;
165     }
166
167     return 0;
168 }
Note: See TracBrowser for help on using the browser.