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

Revision 2803, 6.8 kB (checked in by jwoithe, 3 years ago)

Cosmetic: capitalise "L" in "Linux".

"Linux" is a proper noun so it should start with a capital letter. These
changes are almost all within comments.

This patch was originally proposed by pander on the ffado-devel mailing
list. It has been expanded to cover all similar cases to maintain
consistency throughout the source tree.

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