Changeset 900
- Timestamp:
- 03/02/08 12:15:55 (16 years ago)
- Files:
-
- trunk/libffado/support/firmware/bridgeco-downloader.cpp (modified) (9 diffs)
- trunk/libffado/support/firmware/downloader.cpp (added)
- trunk/libffado/support/firmware/downloader.h (added)
- trunk/libffado/support/firmware/fireworks-downloader.cpp (modified) (7 diffs)
- trunk/libffado/support/firmware/SConscript (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/support/firmware/bridgeco-downloader.cpp
r864 r900 22 22 */ 23 23 24 #include "downloader.h" 25 24 26 #include "src/bebob/bebob_dl_mgr.h" 25 27 #include "src/bebob/bebob_dl_bcd.h" … … 28 30 #include "libieee1394/ieee1394service.h" 29 31 30 #include <argp.h>31 32 #include <iostream> 32 33 34 using namespace std; 33 35 34 36 //////////////////////////////////////////////// 35 37 // arg parsing 36 38 //////////////////////////////////////////////// 37 const char *argp_program_version = "bridgeco-downloader 0. 1";39 const char *argp_program_version = "bridgeco-downloader 0.2"; 38 40 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; 39 static char doc[]= "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n"41 char* doc = "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n" 40 42 "OPERATION: display\n" 41 43 " setguid GUID\n" … … 43 45 " cne FILE\n" 44 46 " bcd FILE\n"; 45 static char args_doc[] = "NODE_ID OPERATION"; 46 static struct argp_option options[] = { 47 static struct argp_option _options[] = { 47 48 {"verbose", 'v', "level", 0, "Produce verbose output" }, 48 49 {"port", 'p', "PORT", 0, "Set port" }, … … 51 52 { 0 } 52 53 }; 53 54 struct arguments 55 { 56 arguments() 57 : verbose( 0 ) 58 , port( 0 ) 59 , force( 0 ) 60 { 61 args[0] = 0; 62 args[1] = 0; 63 args[2] = 0; 64 } 65 66 char* args[3]; 67 short verbose; 68 int port; 69 int force; 70 int no_bootloader_restart; 71 } arguments; 72 73 // Parse a single option. 74 static error_t 75 parse_opt( int key, char* arg, struct argp_state* state ) 76 { 77 // Get the input argument from `argp_parse', which we 78 // know is a pointer to our arguments structure. 79 struct arguments* arguments = ( struct arguments* ) state->input; 80 81 char* tail; 82 switch (key) { 83 case 'v': 84 if (arg) { 85 arguments->verbose = strtol( arg, &tail, 0 ); 86 if ( errno ) { 87 fprintf( stderr, "Could not parse 'verbose' argument\n" ); 88 return ARGP_ERR_UNKNOWN; 89 } 90 } 91 break; 92 case 'p': 93 errno = 0; 94 arguments->port = strtol(arg, &tail, 0); 95 if (errno) { 96 perror("argument parsing failed:"); 97 return errno; 98 } 99 break; 100 case 'f': 101 arguments->force = 1; 102 break; 103 case 'b': 104 arguments->no_bootloader_restart = 1; 105 break; 106 case ARGP_KEY_ARG: 107 if (state->arg_num >= 3) { 108 // Too many arguments. 109 argp_usage (state); 110 } 111 arguments->args[state->arg_num] = arg; 112 break; 113 case ARGP_KEY_END: 114 if (state->arg_num < 2) { 115 // Not enough arguments. 116 argp_usage (state); 117 } 118 break; 119 default: 120 return ARGP_ERR_UNKNOWN; 121 } 122 return 0; 123 } 124 125 static struct argp argp = { options, parse_opt, args_doc, doc }; 126 54 struct argp_option* options = _options; 127 55 128 56 int 129 57 main( int argc, char** argv ) 130 58 { 131 using namespace std;132 59 133 60 // arg parsing 134 argp_parse ( &argp, argc, argv, 0, 0, &arguments);61 argp_parse (argp, argc, argv, 0, 0, args); 135 62 136 63 errno = 0; 137 64 char* tail; 138 int node_id = strtol(arguments.args[0], &tail, 0); 65 int node_id = -1; 66 67 fb_octlet_t guid = strtoll(args->args[0], &tail, 0); 139 68 if (errno) { 140 perror("argument parsing failed:");141 return -1;69 perror("argument parsing failed:"); 70 return -1; 142 71 } 143 72 144 73 Ieee1394Service service; 145 if ( !service.initialize( arg uments.port ) ) {74 if ( !service.initialize( args->port ) ) { 146 75 cerr << "Could not initialize IEEE 1394 service" << endl; 147 76 return -1; 148 77 } 78 service.setVerboseLevel( args->verbose ); 149 79 150 service.setVerboseLevel( arguments.verbose ); 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 151 95 BeBoB::BootloaderManager blMgr( service, node_id ); 152 if ( arg uments.force == 1 ) {96 if ( args->force == 1 ) { 153 97 blMgr.setForceOperations( true ); 154 98 } … … 156 100 blMgr.printInfoRegisters(); 157 101 158 if ( strcmp( arg uments.args[1], "setguid" ) == 0 ) {159 if (!arg uments.args[2] ) {102 if ( strcmp( args->args[1], "setguid" ) == 0 ) { 103 if (!args->args[2] ) { 160 104 cerr << "guid argument is missing" << endl; 161 105 return -1; … … 163 107 164 108 char* tail; 165 fb_octlet_t guid = strtoll(arg uments.args[2], &tail, 0 );109 fb_octlet_t guid = strtoll(args->args[2], &tail, 0 ); 166 110 167 111 if ( !blMgr.programGUID( guid ) ) { … … 171 115 cout << "new GUID programmed" << endl; 172 116 } 173 } else if ( strcmp( arg uments.args[1], "firmware" ) == 0 ) {174 if (!arg uments.args[2] ) {117 } else if ( strcmp( args->args[1], "firmware" ) == 0 ) { 118 if (!args->args[2] ) { 175 119 cerr << "FILE argument is missing" << endl; 176 120 return -1; 177 121 } 178 std::string str( arg uments.args[2] );122 std::string str( args->args[2] ); 179 123 180 blMgr.setStartBootloader( arg uments.no_bootloader_restart != 1 );124 blMgr.setStartBootloader( args->no_bootloader_restart != 1 ); 181 125 if ( !blMgr.downloadFirmware( str ) ) { 182 126 cerr << "Failed to download firmware" << endl; … … 185 129 cout << "Firmware download was successful" << endl; 186 130 } 187 } else if ( strcmp( arg uments.args[1], "cne" ) == 0 ) {188 if (!arg uments.args[2] ) {131 } else if ( strcmp( args->args[1], "cne" ) == 0 ) { 132 if (!args->args[2] ) { 189 133 cerr << "FILE argument is missing" << endl; 190 134 return -1; 191 135 } 192 std::string str( arg uments.args[2] );136 std::string str( args->args[2] ); 193 137 194 138 if ( !blMgr.downloadCnE( str ) ) { … … 198 142 cout << "CnE download was successful" << endl; 199 143 } 200 } else if ( strcmp( arg uments.args[1], "display" ) == 0 ) {144 } else if ( strcmp( args->args[1], "display" ) == 0 ) { 201 145 // nothing to do 202 } else if ( strcmp( arg uments.args[1], "bcd" ) == 0 ) {203 if ( !arg uments.args[2] ) {146 } else if ( strcmp( args->args[1], "bcd" ) == 0 ) { 147 if ( !args->args[2] ) { 204 148 cerr << "FILE arguments is missing" << endl; 205 149 return -1; 206 150 } 207 BeBoB::BCD* bcd = new BeBoB::BCD::BCD( arg uments.args[2] );151 BeBoB::BCD* bcd = new BeBoB::BCD::BCD( args->args[2] ); 208 152 if ( !bcd ) { 209 cerr << "Could no open file " << arg uments.args[2] << endl;153 cerr << "Could no open file " << args->args[2] << endl; 210 154 return -1; 211 155 } 212 156 if ( !bcd->parse() ) { 213 cerr << "Could not parse file " << arg uments.args[2] << endl;157 cerr << "Could not parse file " << args->args[2] << endl; 214 158 return -1; 215 159 } trunk/libffado/support/firmware/fireworks-downloader.cpp
r864 r900 23 23 */ 24 24 25 #include "downloader.h" 26 25 27 #include "src/fireworks/fireworks_device.h" 26 28 #include "src/fireworks/fireworks_firmware.h" … … 33 35 #include "devicemanager.h" 34 36 35 #include <argp.h>36 37 #include <iostream> 37 38 … … 39 40 #include <string> 40 41 42 using namespace FireWorks; 43 41 44 DECLARE_GLOBAL_DEBUG_MODULE; 42 45 43 using namespace FireWorks;44 46 //////////////////////////////////////////////// 45 47 // arg parsing 46 48 //////////////////////////////////////////////// 47 const char *argp_program_version = "fireworks-downloader 0. 1";49 const char *argp_program_version = "fireworks-downloader 0.2"; 48 50 const char *argp_program_bug_address = "<ffado-devel@lists.sf.net>"; 49 static char doc[]= "fireworks-downloader -- firmware downloader application for ECHO Fireworks devices\n\n"51 char* doc = "fireworks-downloader -- firmware downloader application for ECHO Fireworks devices\n\n" 50 52 "OPERATION: display\n" 51 53 " firmware FILE\n"; 52 static char args_doc[] = "NODE_ID OPERATION"; 53 static struct argp_option options[] = {54 55 static struct argp_option _options[] = { 54 56 {"verbose", 'v', "level", 0, "Produce verbose output" }, 55 57 {"port", 'p', "PORT", 0, "Set port" }, 56 58 { 0 } 57 59 }; 58 59 struct arguments 60 { 61 arguments() 62 : verbose( 0 ) 63 , port( 0 ) 64 { 65 args[0] = 0; 66 args[1] = 0; 67 args[2] = 0; 68 } 69 70 char* args[3]; 71 short verbose; 72 int port; 73 } arguments; 74 75 // Parse a single option. 76 static error_t 77 parse_opt( int key, char* arg, struct argp_state* state ) 78 { 79 // Get the input argument from `argp_parse', which we 80 // know is a pointer to our arguments structure. 81 struct arguments* arguments = ( struct arguments* ) state->input; 82 83 char* tail; 84 switch (key) { 85 case 'v': 86 if (arg) { 87 arguments->verbose = strtol( arg, &tail, 0 ); 88 if ( errno ) { 89 debugError( "Could not parse 'verbose' argument\n" ); 90 return ARGP_ERR_UNKNOWN; 91 } 92 } 93 break; 94 case 'p': 95 errno = 0; 96 arguments->port = strtol(arg, &tail, 0); 97 if (errno) { 98 debugError("argument parsing failed: %s\n", 99 strerror(errno)); 100 return errno; 101 } 102 break; 103 case ARGP_KEY_ARG: 104 if (state->arg_num >= 3) { 105 // Too many arguments. 106 argp_usage (state); 107 } 108 arguments->args[state->arg_num] = arg; 109 break; 110 case ARGP_KEY_END: 111 if (state->arg_num < 2) { 112 // Not enough arguments. 113 argp_usage (state); 114 } 115 break; 116 default: 117 return ARGP_ERR_UNKNOWN; 118 } 119 return 0; 120 } 121 122 static struct argp argp = { options, parse_opt, args_doc, doc }; 123 60 struct argp_option* options = _options; 124 61 125 62 int … … 128 65 using namespace std; 129 66 130 // arg parsing 131 argp_parse (&argp, argc, argv, 0, 0, &arguments); 67 argp_parse (argp, argc, argv, 0, 0, args); 132 68 133 69 errno = 0; 134 70 char* tail; 135 int node_id = strtol(arguments.args[0], &tail, 0); 71 int node_id = -1; 72 73 fb_octlet_t guid = strtoll(args->args[0], &tail, 0); 136 74 if (errno) { 137 75 debugError("argument parsing failed: %s\n", … … 141 79 142 80 Ieee1394Service service; 143 if ( !service.initialize( arg uments.port ) ) {81 if ( !service.initialize( args->port ) ) { 144 82 debugError("Could not initialize IEEE 1394 service\n"); 145 83 return -1; 146 84 } 147 service.setVerboseLevel( arguments.verbose ); 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 } 148 99 149 100 ConfigRom *configRom = new ConfigRom(service, node_id ); … … 152 103 return -1; 153 104 } 154 configRom->setVerboseLevel( arg uments.verbose );105 configRom->setVerboseLevel( args->verbose ); 155 106 156 107 if ( !configRom->initialize() ) { … … 178 129 // create the firmware util class 179 130 FirmwareUtil util = FirmwareUtil(*dev); 180 util.setVerboseLevel( arg uments.verbose );131 util.setVerboseLevel( args->verbose ); 181 132 182 if ( strcmp( arg uments.args[1], "firmware" ) == 0 ) {183 if (!arg uments.args[2] ) {133 if ( strcmp( args->args[1], "firmware" ) == 0 ) { 134 if (!args->args[2] ) { 184 135 cerr << "FILE argument is missing" << endl; 185 136 delete dev; 186 137 return -1; 187 138 } 188 std::string str( arg uments.args[2] );139 std::string str( args->args[2] ); 189 140 190 141 // load the file 191 142 Firmware f = Firmware(); 192 f.setVerboseLevel( arg uments.verbose );143 f.setVerboseLevel( args->verbose ); 193 144 194 145 f.loadFile(str); 195 146 f.show(); 196 147 197 } else if ( strcmp( arg uments.args[1], "display" ) == 0 ) {148 } else if ( strcmp( args->args[1], "display" ) == 0 ) { 198 149 // nothing to do 199 150 dev->showDevice(); trunk/libffado/support/firmware/SConscript
r864 r900 46 46 47 47 if env['ENABLE_BEBOB']: 48 apps["ffado-bridgeco-downloader"] = " bridgeco-downloader.cpp"48 apps["ffado-bridgeco-downloader"] = "downloader.cpp bridgeco-downloader.cpp" 49 49 installapps += [ "ffado-bridgeco-downloader" ] 50 50 51 51 if env['ENABLE_FIREWORKS']: 52 apps["ffado-fireworks-downloader"] = " fireworks-downloader.cpp"52 apps["ffado-fireworks-downloader"] = "downloader.cpp fireworks-downloader.cpp" 53 53 installapps += [ "ffado-fireworks-downloader" ] 54 54