Index: /trunk/libffado/SConstruct =================================================================== --- /trunk/libffado/SConstruct (revision 640) +++ /trunk/libffado/SConstruct (revision 688) @@ -232,4 +232,5 @@ Default( 'external' ) Default( 'src' ) + Default( 'support' ) if env['BUILD_TESTS']: Default( 'tests' ) Index: /trunk/libffado/src/SConscript =================================================================== --- /trunk/libffado/src/SConscript (revision 665) +++ /trunk/libffado/src/SConscript (revision 688) @@ -109,8 +109,10 @@ fireworks/fireworks_device.cpp \ fireworks/fireworks_control.cpp \ + fireworks/fireworks_firmware.cpp \ fireworks/efc/efc_avc_cmd.cpp \ fireworks/efc/efc_cmd.cpp \ fireworks/efc/efc_cmds_hardware.cpp \ fireworks/efc/efc_cmds_hardware_ctrl.cpp \ + fireworks/efc/efc_cmds_flash.cpp \ fireworks/efc/efc_cmds_mixer.cpp \ fireworks/efc/efc_cmds_monitor.cpp \ @@ -250,10 +252,4 @@ installapps = [] -if env['ENABLE_BEBOB']: - apps["bebob-sync"] = "bebob-sync.cpp" - apps["bridgeco-downloader"] = "bridgeco-downloader.cpp" - installapps += [ "bebob-sync", "bridgeco-downloader" ] - - for app in apps.keys(): env2.Program( target=app, source = env.Split( apps[app] ) ) Index: /trunk/libffado/src/bebob/bebob_dl_mgr.h =================================================================== --- /trunk/libffado/src/bebob/bebob_dl_mgr.h (revision 445) +++ /trunk/libffado/src/bebob/bebob_dl_mgr.h (revision 688) @@ -55,27 +55,27 @@ bool programGUID( octlet_t guid ); - void busresetHandler(); + void busresetHandler(); - Ieee1394Service* get1394Serivce() const - { return m_ieee1394service; } + Ieee1394Service* get1394Serivce() const + { return m_ieee1394service; } - bool setForceOperations( bool enabled ) - { m_forceEnabled = enabled; return true; } + bool setForceOperations( bool enabled ) + { m_forceEnabled = enabled; return true; } - bool setStartBootloader( bool bStartBootloader ) - { m_bStartBootloader = bStartBootloader; return true; } - protected: - enum EObjectType { - eOT_Application, - eOT_CnE - }; + bool setStartBootloader( bool bStartBootloader ) + { m_bStartBootloader = bStartBootloader; return true; } + protected: + enum EObjectType { + eOT_Application, + eOT_CnE + }; - void waitForBusReset(); + void waitForBusReset(); bool writeRequest( CommandCodes& cmd ); - bool readResponse( CommandCodes& writeRequestCmd ); - bool downloadObject( BCD& bcd, EObjectType eObject ); + bool readResponse( CommandCodes& writeRequestCmd ); + bool downloadObject( BCD& bcd, EObjectType eObject ); bool programGUIDCmd( octlet_t guid ); - bool startBootloaderCmd(); + bool startBootloaderCmd(); bool startApplicationCmd(); bool initializePersParamCmd(); @@ -115,13 +115,13 @@ info_register_t m_cachedInfoRegs; - pthread_mutex_t m_mutex; - pthread_cond_t m_cond; + pthread_mutex_t m_mutex; + pthread_cond_t m_cond; - Functor* m_functor; + Functor* m_functor; - bool m_forceEnabled; - bool m_bStartBootloader; + bool m_forceEnabled; + bool m_bStartBootloader; - DECLARE_DEBUG_MODULE; + DECLARE_DEBUG_MODULE; }; } Index: /trunk/libffado/src/bebob/bebob_dl_codes.h =================================================================== --- /trunk/libffado/src/bebob/bebob_dl_codes.h (revision 618) +++ /trunk/libffado/src/bebob/bebob_dl_codes.h (revision 688) @@ -21,7 +21,4 @@ * MA 02110-1301 USA */ - -#ifdef ENABLE_BEBOB - #ifndef BEBOB_DL_CODES_H #define BEBOB_DL_CODES_H @@ -316,4 +313,2 @@ }; #endif - -#endif //#ifdef ENABLE_BEBOB Index: /trunk/libffado/src/fireworks/fireworks_firmware.cpp =================================================================== --- /trunk/libffado/src/fireworks/fireworks_firmware.cpp (revision 688) +++ /trunk/libffado/src/fireworks/fireworks_firmware.cpp (revision 688) @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2007 by Pieter Palmers + * + * This file is part of FFADO + * FFADO = Free Firewire (pro-)audio drivers for linux + * + * FFADO is based upon FreeBoB. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#include "fireworks_device.h" +#include "fireworks_firmware.h" +#include "efc/efc_avc_cmd.h" +#include "efc/efc_cmd.h" +#include "efc/efc_cmds_flash.h" + +#include +#include + +using namespace std; + +// These classes provide support for reading/writing the firmware on +// echo fireworks based devices +namespace FireWorks { +IMPL_DEBUG_MODULE( Firmware, Firmware, DEBUG_LEVEL_NORMAL ); +IMPL_DEBUG_MODULE( FirmwareUtil, FirmwareUtil, DEBUG_LEVEL_NORMAL ); + +// the firmware class + +// some generic string generation functions +const char *Firmware::eDatTypeToString(const enum eDatType type) { + switch (type) { + case eDT_DspCode: + return "Dsp Code"; + case eDT_IceLynxCode: + return "IceLynx Code"; + case eDT_Data: + return "Data"; + case eDT_FPGACode: + return "FPGA Code"; + case eDT_DeviceName: + return "Device Name"; + default: + return "invalid"; + } +} + +Firmware::Firmware() +{ +} + +Firmware::~Firmware() +{ +} + +void +Firmware::show() +{ + debugOutput(DEBUG_LEVEL_NORMAL, "Firmware from %s\n", m_filename.c_str()); + debugOutput(DEBUG_LEVEL_NORMAL, " Type : %s\n", eDatTypeToString(m_Type)); + debugOutput(DEBUG_LEVEL_NORMAL, " Address Offset : %08llX\n", m_flash_offset_address); + debugOutput(DEBUG_LEVEL_NORMAL, " Lenght (Quadlets) : %08llX\n", m_length_quads); + debugOutput(DEBUG_LEVEL_NORMAL, " CRC 32 : %08llX\n", m_CRC32); + debugOutput(DEBUG_LEVEL_NORMAL, " Checksum : %08llX\n", m_checksum); + debugOutput(DEBUG_LEVEL_NORMAL, " Firmware version : %08llX\n", m_version); + debugOutput(DEBUG_LEVEL_NORMAL, " Append CRC : %s\n", (m_append_crc?"Yes":"No")); + debugOutput(DEBUG_LEVEL_NORMAL, " Footprint (Quadlets) : %08llX\n", m_footprint_quads); + +} + +bool +Firmware::loadFile(std::string filename) +{ + debugOutput(DEBUG_LEVEL_VERBOSE, "Loading firmware from file %s\n", filename.c_str()); + + + m_filename = filename; + return false; +} + +// the firmware loader helper class +FirmwareUtil::FirmwareUtil(FireWorks::Device& p, FireWorks::Firmware& f) +: m_Parent(p) +, m_Firmware(f) +{ +} + +FirmwareUtil::~FirmwareUtil() +{ +} + +void +FirmwareUtil::show() +{ + debugOutput(DEBUG_LEVEL_NORMAL, "FirmwareUtil\n"); +} + +} // FireWorks Index: /trunk/libffado/src/fireworks/fireworks_firmware.h =================================================================== --- /trunk/libffado/src/fireworks/fireworks_firmware.h (revision 688) +++ /trunk/libffado/src/fireworks/fireworks_firmware.h (revision 688) @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2005-2007 by Pieter Palmers + * + * This file is part of FFADO + * FFADO = Free Firewire (pro-)audio drivers for linux + * + * FFADO is based upon FreeBoB. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation; + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef FIREWORKS_FIRMWARE_H +#define FIREWORKS_FIRMWARE_H + +#include "debugmodule/debugmodule.h" + +#include "efc/efc_cmd.h" +#include "efc/efc_cmds_hardware.h" +#include "efc/efc_cmds_flash.h" + +#include + +class ConfigRom; +class Ieee1394Service; + +namespace FireWorks { + +#define ECHO_FIRMWARE_MAGIC_VALUES {1651,1,0,0,0} +#define ECHO_FIRMWARE_NB_MAGIC_VALUES 5 + +#define ECHO_FIRMWARE_HEADER_LENGTH_BYTES 256 +#define ECHO_FIRMWARE_HEADER_LENGTH_QUADLETS (ECHO_FIRMWARE_HEADER_LENGTH_BYTES / 4) + +#define ECHO_FIRMWARE_FILE_MAX_LENGTH_BYTES (384*1024 + ECHO_FIRMWARE_HEADER_LENGTH_BYTES) +#define ECHO_FIRMWARE_FILE_MAX_LENGTH_QUADLETS (ECHO_FIRMWARE_HEADER_LENGTH_BYTES / 4) + +class Firmware +{ +public: + enum eDatType { + eDT_DspCode = 0, + eDT_IceLynxCode = 1, + eDT_Data = 2, + eDT_FPGACode = 3, + eDT_DeviceName = 4, + eDT_Invalid = 0xFF, + }; + static const char *eDatTypeToString(const enum eDatType target); + +public: + Firmware(); + virtual ~Firmware(); + + virtual bool loadFile(std::string filename); + + virtual void show(); + +protected: + // filename + std::string m_filename; + + // header data + enum eDatType m_Type; + uint32_t m_flash_offset_address; + uint32_t m_length_quads; + uint32_t m_CRC32; + uint32_t m_checksum; + uint32_t m_version; + bool m_append_crc; // true to append + uint32_t m_footprint_quads; + +private: + DECLARE_DEBUG_MODULE; +}; + +class FirmwareUtil +{ + +public: + FirmwareUtil(FireWorks::Device& parent, + FireWorks::Firmware& f); + virtual ~FirmwareUtil(); + + virtual void show(); + +protected: + FireWorks::Device& m_Parent; + FireWorks::Firmware& m_Firmware; +private: + DECLARE_DEBUG_MODULE; +}; + +} // namespace FireWorks + +#endif Index: /unk/libffado/src/bridgeco-downloader.cpp =================================================================== --- /trunk/libffado/src/bridgeco-downloader.cpp (revision 445) +++ (revision ) @@ -1,224 +1,0 @@ -/* - * Copyright (C) 2005-2007 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * FFADO is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with FFADO; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA. - */ - -#include "bebob/bebob_dl_mgr.h" -#include "bebob/bebob_dl_bcd.h" - -#include "libieee1394/configrom.h" -#include "libieee1394/ieee1394service.h" - -#include -#include - - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "bridgeco-downloader 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n" - "OPERATION: display\n" - " setguid GUID\n" - " firmware FILE\n" - " cne FILE\n" - " bcd FILE\n"; -static char args_doc[] = "NODE_ID OPERATION"; -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - {"force", 'f', 0, 0, "Force firmware download" }, - {"noboot", 'b', 0, 0, "Do no start bootloader (bootloader is already running)" }, - { 0 } -}; - -struct arguments -{ - arguments() - : verbose( 0 ) - , port( 0 ) - , force( 0 ) - { - args[0] = 0; - args[1] = 0; - args[2] = 0; - } - - char* args[3]; - short verbose; - int port; - int force; - int no_bootloader_restart; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'p': - errno = 0; - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case 'f': - arguments->force = 1; - break; - case 'b': - arguments->no_bootloader_restart = 1; - break; - case ARGP_KEY_ARG: - if (state->arg_num >= 3) { - // Too many arguments. - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - break; - case ARGP_KEY_END: - if (state->arg_num < 2) { - // Not enough arguments. - argp_usage (state); - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - - -int -main( int argc, char** argv ) -{ - using namespace std; - - // arg parsing - argp_parse (&argp, argc, argv, 0, 0, &arguments); - - errno = 0; - char* tail; - int node_id = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - - Ieee1394Service service; - if ( !service.initialize( arguments.port ) ) { - cerr << "Could not initialize IEEE 1394 service" << endl; - return -1; - } - - service.setVerboseLevel( arguments.verbose ); - BeBoB::BootloaderManager blMgr( service, node_id ); - if ( arguments.force == 1 ) { - blMgr.setForceOperations( true ); - } - blMgr.getConfigRom()->printConfigRom(); - blMgr.printInfoRegisters(); - - if ( strcmp( arguments.args[1], "setguid" ) == 0 ) { - if (!arguments.args[2] ) { - cerr << "guid argument is missing" << endl; - return -1; - } - - char* tail; - fb_octlet_t guid = strtoll(arguments.args[2], &tail, 0 ); - - if ( !blMgr.programGUID( guid ) ) { - cerr << "Failed to set GUID" << endl; - return -1; - } else { - cout << "new GUID programmed" << endl; - } - } else if ( strcmp( arguments.args[1], "firmware" ) == 0 ) { - if (!arguments.args[2] ) { - cerr << "FILE argument is missing" << endl; - return -1; - } - std::string str( arguments.args[2] ); - - blMgr.setStartBootloader( arguments.no_bootloader_restart != 1 ); - if ( !blMgr.downloadFirmware( str ) ) { - cerr << "Failed to download firmware" << endl; - return -1; - } else { - cout << "Firmware download was successful" << endl; - } - } else if ( strcmp( arguments.args[1], "cne" ) == 0 ) { - if (!arguments.args[2] ) { - cerr << "FILE argument is missing" << endl; - return -1; - } - std::string str( arguments.args[2] ); - - if ( !blMgr.downloadCnE( str ) ) { - cerr << "Failed to download CnE" << endl; - return -1; - } else { - cout << "CnE download was successful" << endl; - } - } else if ( strcmp( arguments.args[1], "display" ) == 0 ) { - // nothing to do - } else if ( strcmp( arguments.args[1], "bcd" ) == 0 ) { - if ( !arguments.args[2] ) { - cerr << "FILE arguments is missing" << endl; - return -1; - } - BeBoB::BCD* bcd = new BeBoB::BCD::BCD( arguments.args[2] ); - if ( !bcd ) { - cerr << "Could no open file " << arguments.args[2] << endl; - return -1; - } - if ( !bcd->parse() ) { - cerr << "Could not parse file " << arguments.args[2] << endl; - return -1; - } - - bcd->displayInfo(); - delete bcd; - } else { - cout << "Unknown operation" << endl; - } - - return 0; -} Index: /unk/libffado/src/bebob-sync.cpp =================================================================== --- /trunk/libffado/src/bebob-sync.cpp (revision 554) +++ (revision ) @@ -1,209 +1,0 @@ -/* - * Copyright (C) 2005-2007 by Daniel Wagner - * - * This file is part of FFADO - * FFADO = Free Firewire (pro-)audio drivers for linux - * - * FFADO is based upon FreeBoB. - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * FFADO is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with FFADO; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA. - */ - -#include "devicemanager.h" -#include "ffadodevice.h" -#include "bebob/bebob_avdevice.h" - -#include -#include - - -//////////////////////////////////////////////// -// arg parsing -//////////////////////////////////////////////// -const char *argp_program_version = "bebob-sync 0.1"; -const char *argp_program_bug_address = ""; -static char doc[] = "bebob-sync -- select sync mode on a BeBoB device\n\n" - "OPERATION: set \n"; -static char args_doc[] = "NODE_ID OPERATION"; -static struct argp_option options[] = { - {"verbose", 'v', "level", 0, "Produce verbose output" }, - {"port", 'p', "PORT", 0, "Set port" }, - { 0 } -}; - -// IMPL_GLOBAL_DEBUG_MODULE( bebob-sync, DebugModule::eDL_Normal ); -DECLARE_GLOBAL_DEBUG_MODULE; - -struct arguments -{ - arguments() - : verbose( 0 ) - , port( 0 ) - { - args[0] = 0; - args[1] = 0; - args[2] = 0; - } - - char* args[3]; - short verbose; - int port; -} arguments; - -// Parse a single option. -static error_t -parse_opt( int key, char* arg, struct argp_state* state ) -{ - // Get the input argument from `argp_parse', which we - // know is a pointer to our arguments structure. - struct arguments* arguments = ( struct arguments* ) state->input; - - char* tail; - switch (key) { - case 'v': - if (arg) { - arguments->verbose = strtol( arg, &tail, 0 ); - if ( errno ) { - fprintf( stderr, "Could not parse 'verbose' argument\n" ); - return ARGP_ERR_UNKNOWN; - } - } - break; - case 'p': - errno = 0; - arguments->port = strtol(arg, &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return errno; - } - break; - case ARGP_KEY_ARG: - if (state->arg_num >= 3) { - argp_usage (state); - } - arguments->args[state->arg_num] = arg; - break; - case ARGP_KEY_END: - if (state->arg_num < 1) { - argp_usage (state); - } - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; -} - -static struct argp argp = { options, parse_opt, args_doc, doc }; - - -int -main( int argc, char** argv ) -{ - using namespace std; - - // arg parsing - argp_parse (&argp, argc, argv, 0, 0, &arguments); - - errno = 0; - char* tail; - int node_id = strtol(arguments.args[0], &tail, 0); - if (errno) { - perror("argument parsng failed:"); - return -1; - } - - std::auto_ptr pDeviceManager - = std::auto_ptr( new DeviceManager() ); - if ( !pDeviceManager.get() ) { - debugFatal( "Could not allocate DeviceManager\n" ); - return -1; - } - if ( !pDeviceManager->initialize( arguments.port ) ) { - debugFatal( "Could not initialize device manager\n" ); - return -1; - } - if ( arguments.verbose ) { - pDeviceManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); - } - if ( !pDeviceManager->discover( ) ) { - debugError( "Could not discover devices\n" ); - return -1; - } - - FFADODevice* pAvDevice = pDeviceManager->getAvDevice( node_id ); - if ( !pAvDevice ) { - printf( "No recognized device found with id %d\n", node_id ); - return 0; - } - - BeBoB::AvDevice* pBeBoBAvDevice - = dynamic_cast( pAvDevice ); - if ( !pBeBoBAvDevice ) { - printf( "Not a BeBoB device, cannot set sync\n" ); - return 0; - } - - int i = 0; - for ( BeBoB::AvDevice::SyncInfoVector::const_iterator it - = pBeBoBAvDevice->getSyncInfos().begin(); - it != pBeBoBAvDevice->getSyncInfos().end(); - ++it ) - { - const BeBoB::AvDevice::SyncInfo* pSyncInfo = &*it; - printf( " %2d) %s\n", i, pSyncInfo->m_description.c_str() ); - ++i; - } - - printf( "Active Sync mode:\n" ); - if ( !pBeBoBAvDevice->getActiveSyncInfo() ) { - debugError( "Could not retrieve active sync information\n" ); - return 0; - } - printf( " %s\n", pBeBoBAvDevice->getActiveSyncInfo()->m_description.c_str() ); - - if ( argc >= 4 ) { - if ( strcmp( "set", arguments.args[1] ) == 0 ) { - errno = 0; - unsigned int syncId = strtol(arguments.args[2], &tail, 0); - if (errno) { - perror("argument parsing failed:"); - return -1; - } - - if (syncId >= pBeBoBAvDevice->getSyncInfos().size() ) { - printf( "Invalid sync mode id given (%d). " - "Valid range is 0 - %d\n", - syncId, pBeBoBAvDevice->getSyncInfos().size()-1 ); - return -1; - } - - const BeBoB::AvDevice::SyncInfo& syncInfo - = pBeBoBAvDevice->getSyncInfos()[syncId]; - printf( "Setting Sync Mode to \"%s\"... ", - syncInfo.m_description.c_str() ); - - if ( pBeBoBAvDevice->setActiveSync( syncInfo ) ) { - printf( "done\n" ); - } else { - printf( "failed\n" ); - } - } - } - - return 0; -} - - Index: /trunk/libffado/support/SConscript =================================================================== --- /trunk/libffado/support/SConscript (revision 561) +++ /trunk/libffado/support/SConscript (revision 688) @@ -18,4 +18,4 @@ # -env.SConscript( dirs="mixer", exports="env" ) +env.SConscript( dirs=["mixer","firmware"], exports="env" ) Index: /trunk/libffado/support/firmware/SConscript =================================================================== --- /trunk/libffado/support/firmware/SConscript (revision 688) +++ /trunk/libffado/support/firmware/SConscript (revision 688) @@ -0,0 +1,36 @@ +#! /usr/bin/env python + +Import( 'env' ) + +env = env.Copy() + +# +# For the debugging apps +# +env.PrependUnique( LIBPATH=env['build_base']+"src" ) +env.PrependUnique( LIBS="ffado" ) +env.AppendUnique( CPPPATH=["#/", "#/src"] ) + +if not env.GetOption( "clean" ): + env.MergeFlags( "-lrt" ) + env.MergeFlags( env['LIBRAW1394_FLAGS'] ) + env.MergeFlags( env['LIBAVC1394_FLAGS'] ) + env.MergeFlags( env['LIBIEC61883_FLAGS'] ) + env.MergeFlags( env['ALSA_FLAGS'] ) + env.MergeFlags( env['LIBXML26_FLAGS'] ) + env.MergeFlags( env['LIBLO_FLAGS'] ) + +apps = { +} + +installapps = [] + +if env['ENABLE_BEBOB']: + apps["bridgeco-downloader"] = "bridgeco-downloader.cpp" + installapps += [ "bridgeco-downloader" ] + + +for app in apps.keys(): + env.Program( target=app, source = env.Split( apps[app] ) ) + if app.find( "test" ) == -1: + env.Install( "$bindir", app ) Index: /trunk/libffado/support/firmware/bridgeco-downloader.cpp =================================================================== --- /trunk/libffado/support/firmware/bridgeco-downloader.cpp (revision 688) +++ /trunk/libffado/support/firmware/bridgeco-downloader.cpp (revision 688) @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2005-2007 by Daniel Wagner + * + * This file is part of FFADO + * FFADO = Free Firewire (pro-)audio drivers for linux + * + * FFADO is based upon FreeBoB. + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * FFADO is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FFADO; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA. + */ + +#include "src/bebob/bebob_dl_mgr.h" +#include "src/bebob/bebob_dl_bcd.h" + +#include "libieee1394/configrom.h" +#include "libieee1394/ieee1394service.h" + +#include +#include + + +//////////////////////////////////////////////// +// arg parsing +//////////////////////////////////////////////// +const char *argp_program_version = "bridgeco-downloader 0.1"; +const char *argp_program_bug_address = ""; +static char doc[] = "bridgeco-downloader -- firmware downloader application for BridgeCo devices\n\n" + "OPERATION: display\n" + " setguid GUID\n" + " firmware FILE\n" + " cne FILE\n" + " bcd FILE\n"; +static char args_doc[] = "NODE_ID OPERATION"; +static struct argp_option options[] = { + {"verbose", 'v', "level", 0, "Produce verbose output" }, + {"port", 'p', "PORT", 0, "Set port" }, + {"force", 'f', 0, 0, "Force firmware download" }, + {"noboot", 'b', 0, 0, "Do no start bootloader (bootloader is already running)" }, + { 0 } +}; + +struct arguments +{ + arguments() + : verbose( 0 ) + , port( 0 ) + , force( 0 ) + { + args[0] = 0; + args[1] = 0; + args[2] = 0; + } + + char* args[3]; + short verbose; + int port; + int force; + int no_bootloader_restart; +} arguments; + +// Parse a single option. +static error_t +parse_opt( int key, char* arg, struct argp_state* state ) +{ + // Get the input argument from `argp_parse', which we + // know is a pointer to our arguments structure. + struct arguments* arguments = ( struct arguments* ) state->input; + + char* tail; + switch (key) { + case 'v': + if (arg) { + arguments->verbose = strtol( arg, &tail, 0 ); + if ( errno ) { + fprintf( stderr, "Could not parse 'verbose' argument\n" ); + return ARGP_ERR_UNKNOWN; + } + } + break; + case 'p': + errno = 0; + arguments->port = strtol(arg, &tail, 0); + if (errno) { + perror("argument parsing failed:"); + return errno; + } + break; + case 'f': + arguments->force = 1; + break; + case 'b': + arguments->no_bootloader_restart = 1; + break; + case ARGP_KEY_ARG: + if (state->arg_num >= 3) { + // Too many arguments. + argp_usage (state); + } + arguments->args[state->arg_num] = arg; + break; + case ARGP_KEY_END: + if (state->arg_num < 2) { + // Not enough arguments. + argp_usage (state); + } + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp argp = { options, parse_opt, args_doc, doc }; + + +int +main( int argc, char** argv ) +{ + using namespace std; + + // arg parsing + argp_parse (&argp, argc, argv, 0, 0, &arguments); + + errno = 0; + char* tail; + int node_id = strtol(arguments.args[0], &tail, 0); + if (errno) { + perror("argument parsing failed:"); + return -1; + } + + Ieee1394Service service; + if ( !service.initialize( arguments.port ) ) { + cerr << "Could not initialize IEEE 1394 service" << endl; + return -1; + } + + service.setVerboseLevel( arguments.verbose ); + BeBoB::BootloaderManager blMgr( service, node_id ); + if ( arguments.force == 1 ) { + blMgr.setForceOperations( true ); + } + blMgr.getConfigRom()->printConfigRom(); + blMgr.printInfoRegisters(); + + if ( strcmp( arguments.args[1], "setguid" ) == 0 ) { + if (!arguments.args[2] ) { + cerr << "guid argument is missing" << endl; + return -1; + } + + char* tail; + fb_octlet_t guid = strtoll(arguments.args[2], &tail, 0 ); + + if ( !blMgr.programGUID( guid ) ) { + cerr << "Failed to set GUID" << endl; + return -1; + } else { + cout << "new GUID programmed" << endl; + } + } else if ( strcmp( arguments.args[1], "firmware" ) == 0 ) { + if (!arguments.args[2] ) { + cerr << "FILE argument is missing" << endl; + return -1; + } + std::string str( arguments.args[2] ); + + blMgr.setStartBootloader( arguments.no_bootloader_restart != 1 ); + if ( !blMgr.downloadFirmware( str ) ) { + cerr << "Failed to download firmware" << endl; + return -1; + } else { + cout << "Firmware download was successful" << endl; + } + } else if ( strcmp( arguments.args[1], "cne" ) == 0 ) { + if (!arguments.args[2] ) { + cerr << "FILE argument is missing" << endl; + return -1; + } + std::string str( arguments.args[2] ); + + if ( !blMgr.downloadCnE( str ) ) { + cerr << "Failed to download CnE" << endl; + return -1; + } else { + cout << "CnE download was successful" << endl; + } + } else if ( strcmp( arguments.args[1], "display" ) == 0 ) { + // nothing to do + } else if ( strcmp( arguments.args[1], "bcd" ) == 0 ) { + if ( !arguments.args[2] ) { + cerr << "FILE arguments is missing" << endl; + return -1; + } + BeBoB::BCD* bcd = new BeBoB::BCD::BCD( arguments.args[2] ); + if ( !bcd ) { + cerr << "Could no open file " << arguments.args[2] << endl; + return -1; + } + if ( !bcd->parse() ) { + cerr << "Could not parse file " << arguments.args[2] << endl; + return -1; + } + + bcd->displayInfo(); + delete bcd; + } else { + cout << "Unknown operation" << endl; + } + + return 0; +}