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