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

Revision 1498, 6.8 kB (checked in by ppalmers, 12 years ago)

Merge all changes from 2.0 branch into trunk (since r1361). This _should_ contain all forward merges done in the mean time. At this moment in time both branches should be in sync.

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 #include "version.h"
32
33 #include <iostream>
34 #include <cstdlib>
35 #include <cstring>
36
37 #define MAGIC_THAT_SAYS_I_KNOW_WHAT_IM_DOING 0x001807198000LL
38
39 using namespace std;
40
41 ////////////////////////////////////////////////
42 // arg parsing
43 ////////////////////////////////////////////////
44 const char *argp_program_version = "bridgeco-downloader 0.2";
45 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>";
46 const char *doc = "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n"
47                     "OPERATION: GUID display\n"
48                     "           GUID setguid NEW_GUID\n"
49                     "           GUID firmware FILE\n"
50                     "           GUID cne FILE\n"
51                     "           GUID bcd FILE\n";
52 static struct argp_option _options[] = {
53     {"verbose",   'v', "level",     0,  "Produce verbose output" },
54     {"port",      'p', "PORT",      0,  "Set port" },
55     {"force",     'f', 0,           0,  "Force firmware download" },
56     {"noboot",    'b', 0,           0,  "Do no start bootloader (bootloader is already running)" },
57     {"magic",     'm', "MAGIC",     0,  "A magic number you have to obtain before this code will work."
58                                         "Specifying it means that you accept the risks that come with this tool."},
59     { 0 }
60 };
61 struct argp_option* options = _options;
62
63 int
64 main( int argc, char** argv )
65 {
66     printf("-----------------------------------------------\n");
67     printf("BridgeCo BeBoB platform firmware downloader\n");
68     printf("Part of the FFADO project -- www.ffado.org\n");
69     printf("Version: %s\n", PACKAGE_VERSION);
70     printf("(C) 2008, Daniel Wagner, Pieter Palmers\n");
71     printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
72     printf("-----------------------------------------------\n\n");
73
74     // arg parsing
75     argp_parse (argp, argc, argv, 0, 0, args);
76
77     if (args->nargs < 2) {
78         printDeviceList();
79         exit(0);
80     }
81
82     errno = 0;
83     char* tail;
84     int node_id = -1;
85
86     fb_octlet_t guid = strtoll(args->args[0], &tail, 0);
87     if (errno) {
88         perror("argument parsing failed:");
89         return -1;
90     }
91
92     if(args->magic != MAGIC_THAT_SAYS_I_KNOW_WHAT_IM_DOING) {
93         printf("Magic number not correct. Please specify the correct magic using the '-m' option.\n");
94         printf("Manipulating firmware can cause your device to magically stop working (a.k.a. 'bricking').\n");
95         printf("Specifying the magic number indicates that you accept the risks involved\n");
96         printf("with using this tool. The magic number can be found in the source code.\n\n");
97         return -1;
98     } else {
99         printf("YOU HAVE SPECIFIED THE CORRECT MAGIC NUMBER.\n");
100         printf("HENCE YOU ACCEPT THE RISKS INVOLVED.\n");
101     }
102
103     Ieee1394Service service;
104     if ( !service.initialize( args->port ) ) {
105         cerr << "Could not initialize IEEE 1394 service" << endl;
106         return -1;
107     }
108     service.setVerboseLevel( args->verbose );
109
110     for (int i = 0; i < service.getNodeCount(); i++) {
111         ConfigRom configRom(service, i);
112         configRom.initialize();
113
114         if (configRom.getGuid() == guid)
115             node_id = configRom.getNodeId();
116     }
117
118     if (node_id < 0) {
119         cerr << "Could not find device with matching GUID" << endl;
120         return -1;
121     }
122
123     service.setVerboseLevel( args->verbose );
124
125     BeBoB::BootloaderManager blMgr( service, node_id );
126     if ( args->force == 1 ) {
127         blMgr.setForceOperations( true );
128     }
129     blMgr.getConfigRom()->printConfigRom();
130     blMgr.printInfoRegisters();
131
132     if ( strcmp( args->args[1], "setguid" ) == 0 ) {
133         if (!args->args[2] ) {
134             cerr << "guid argument is missing" << endl;
135             return -1;
136         }
137
138         char* tail;
139         fb_octlet_t guid = strtoll(args->args[2], &tail, 0 );
140
141         if ( !blMgr.programGUID( guid ) ) {
142             cerr << "Failed to set GUID" << endl;
143             return -1;
144         } else {
145             cout << "new GUID programmed" << endl;
146         }
147     } else if ( strcmp( args->args[1], "firmware" ) == 0 ) {
148         if (!args->args[2] ) {
149             cerr << "FILE argument is missing" << endl;
150             return -1;
151         }
152         std::string str( args->args[2] );
153
154         blMgr.setStartBootloader( args->no_bootloader_restart != 1 );
155         if ( !blMgr.downloadFirmware( str ) ) {
156             cerr << "Failed to download firmware" << endl;
157             return -1;
158         } else {
159             cout << "Firmware download was successful" << endl;
160             cout << "Please reboot the device by removing the power and firewire connections." << endl;
161         }
162     } else if ( strcmp( args->args[1], "cne" ) == 0 ) {
163         if (!args->args[2] ) {
164             cerr << "FILE argument is missing" << endl;
165             return -1;
166         }
167         std::string str( args->args[2] );
168
169         if ( !blMgr.downloadCnE( str ) ) {
170             cerr << "Failed to download CnE" << endl;
171             return -1;
172         } else {
173             cout << "CnE download was successful" << endl;
174             cout << "Please reboot the device by removing the power and firewire connections." << endl;
175         }
176     } else if ( strcmp( args->args[1], "display" ) == 0 ) {
177         // nothing to do
178     } else if ( strcmp( args->args[1], "bcd" ) == 0 ) {
179         if ( !args->args[2] ) {
180             cerr << "FILE arguments is missing" << endl;
181             return -1;
182         }
183         BeBoB::BCD* bcd = new BeBoB::BCD::BCD( args->args[2] );
184         if ( !bcd ) {
185             cerr << "Could no open file " << args->args[2] << endl;
186             return -1;
187         }
188         if ( !bcd->parse() ) {
189             cerr << "Could not parse file " << args->args[2] << endl;
190             return -1;
191         }
192
193         bcd->displayInfo();
194         delete bcd;
195     } else {
196         cout << "Unknown operation" << endl;
197     }
198
199     return 0;
200 }
Note: See TracBrowser for help on using the browser.