示例#1
0
int main(int argc, const char * argv[])
{
    printf("dfu-util, utility to flash dfu firmware into USB devices on OS X.\n");
    printf("Based on original dfu-tool & dfu-programmer for Linux.\n\n");
    
    if (argc != 4)
    {
        printf("Usage: dfu-util <vendorId hex> <productId hex> <firmware.dfu>\n");
        return -1;
    }
    
    // Parse device vendor & product
    unsigned short idVendor = strtoul(argv[1], NULL, 16);
    unsigned short idProduct = strtoul(argv[2], NULL, 16);
    
    printf("[i] Initiating DFU for USB device [%04x:%04x].\n", idVendor, idProduct);
    
    firmware.name = argv[3];
    dfu_load_file(&firmware, NEEDS_SUFFIX);
    
    show_suffix_and_prefix(&firmware);
  
    IOUSBDeviceInterface300** device = NULL;
    
    if ((device = prepareDFU(idVendor, idProduct)) != NULL)
        uploadFirmware(device);
    else
        fprintf(stderr, "[!] Failed to enter DFU mode.\n");

    free(firmware.firmware);
    
    return 0;
}
IOService* BrcmPatchRAM::probe(IOService *provider, SInt32 *probeScore)
{
    extern kmod_info_t kmod_info;
    uint64_t start_time, end_time, nano_secs;
    
    DebugLog("probe\n");
    
    AlwaysLog("Version %s starting on OS X Darwin %d.%d.\n", kmod_info.version, version_major, version_minor);

    clock_get_uptime(&start_time);

    mWorkLock = IOLockAlloc();
    if (!mWorkLock)
        return NULL;

    mCompletionLock = IOLockAlloc();
    if (!mCompletionLock)
        return NULL;

    mDevice = OSDynamicCast(IOUSBDevice, provider);
    if (!mDevice)
    {
        AlwaysLog("Provider is not a USB device.\n");
        return NULL;
    }
    mDevice->retain();
    
    initBrcmStrings();
    OSString* displayName = OSDynamicCast(OSString, getProperty(kDisplayName));
    if (displayName)
        provider->setProperty(kUSBProductString, displayName);
    
    mVendorId = mDevice->GetVendorID();
    mProductId = mDevice->GetProductID();

    // get firmware here to pre-cache for eventual use on wakeup or now
    if (BrcmFirmwareStore* firmwareStore = getFirmwareStore())
        firmwareStore->getFirmware(OSDynamicCast(OSString, getProperty(kFirmwareKey)));

    uploadFirmware();
    publishPersonality();

    clock_get_uptime(&end_time);
    absolutetime_to_nanoseconds(end_time - start_time, &nano_secs);
    uint64_t milli_secs = nano_secs / 1000000;
    AlwaysLog("Processing time %llu.%llu seconds.\n", milli_secs / 1000, milli_secs % 1000);
    
    return this;
}
DeviceWidget::DeviceWidget(QWidget *parent) :
    QWidget(parent)
{
    myDevice = new Ui_deviceWidget();
    myDevice->setupUi(this);

    // Initialization of the Device icon display
    myDevice->verticalGroupBox_loaded->setVisible(false);
    myDevice->groupCustom->setVisible(false);
    myDevice->confirmCheckBox->setVisible(false);
    myDevice->gVDevice->setScene(new QGraphicsScene(this));
    connect(myDevice->retrieveButton, SIGNAL(clicked()), this, SLOT(downloadFirmware()));
    connect(myDevice->updateButton, SIGNAL(clicked()), this, SLOT(uploadFirmware()));
    connect(myDevice->pbLoad, SIGNAL(clicked()), this, SLOT(loadFirmware()));
    connect(myDevice->confirmCheckBox, SIGNAL(stateChanged(int)), this, SLOT(confirmCB(int)));
    myDevice->statusIcon->setPixmap(QPixmap(":uploader/images/view-refresh.svg"));

    myDevice->lblCertified->setText("");
}
示例#4
0
/** Called when asyn clients call pasynInt32->write().
  * This function performs actions for some parameters, including ADAcquire, ADBinX, etc.
  * For all parameters it sets the value in the parameter library and calls any registered callbacks..
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus FastCCD::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;

    asynStatus status = asynSuccess;
    static const char *functionName = "writeInt32";

    //Set in param lib so the user sees a readback straight away. Save a backup in case of errors.
    setIntegerParam(function, value);

    int _status = 0; // For return of cin functions

    if(function == ADAcquire){
      if(value){ // User clicked 'Start' button

         // Send the hardware a start trigger command
         int n_images, t_mode, i_mode;
         double t_exp, t_period;

         getIntegerParam(ADTriggerMode, &t_mode);
         getIntegerParam(ADImageMode, &i_mode);
         getIntegerParam(ADNumImages, &n_images);
         getDoubleParam(ADAcquireTime, &t_exp);
         getDoubleParam(ADAcquirePeriod, &t_period);

         switch(i_mode) {
           case ADImageSingle:
             this->framesRemaining = 1;
             n_images = 1;
             break;
           case ADImageMultiple:
             this->framesRemaining = n_images;
             break;
           case ADImageContinuous:
             this->framesRemaining = -1;
             n_images = 0;
             break;
         }

         if(t_mode == 0){
           _status |= cin_ctl_set_cycle_time(&cin_ctl_port, (float)t_period);
           _status |= cin_ctl_set_exposure_time(&cin_ctl_port, (float)t_exp);
           if(!_status){
             _status |= cin_ctl_int_trigger_start(&cin_ctl_port, n_images);
           }
         } else {
           _status |= cin_ctl_ext_trigger_start(&cin_ctl_port, t_mode);
         }

         if(!_status){
           setIntegerParam(ADAcquire, 1);
           setIntegerParam(ADStatus, ADStatusAcquire);
           setParamStatus(ADAcquire, asynSuccess);
           setParamStatus(ADStatus, asynSuccess);
         } else {
           setIntegerParam(ADAcquire, 1);
           setIntegerParam(ADStatus, ADStatusIdle);
           setParamStatus(ADAcquire, asynError);
           setParamStatus(ADStatus, asynError);
         }

      } else {
         // Send the hardware a stop trigger command
         if(!cin_ctl_int_trigger_stop(&cin_ctl_port)){
           setIntegerParam(ADStatus, ADStatusIdle);
           setIntegerParam(ADAcquire, 0);
         }
         if(!cin_ctl_ext_trigger_stop(&cin_ctl_port)){
           setIntegerParam(ADStatus, ADStatusIdle);
           setIntegerParam(ADAcquire, 0);
         }
      }

    } else if (function == FastCCDFirmwareUpload) {

      uploadFirmware();
      epicsEventSignal(statusEvent);

    } else if (function == FastCCDClockUpload) {

      _status = uploadConfig(FastCCDClockUpload, FastCCDClockPath);

    } else if (function == FastCCDBiasUpload) {

      _status = uploadConfig(FastCCDBiasUpload, FastCCDBiasPath);

    } else if (function == FastCCDFCRICUpload) {

      _status = uploadConfig(FastCCDFCRICUpload, FastCCDFCRICPath);

    } else if (function == FastCCDPower) {

      if(value) {
        _status |= cin_ctl_pwr(&cin_ctl_port, 1);
      } else {
        _status |= cin_ctl_pwr(&cin_ctl_port, 0);
      }

      epicsEventSignal(statusEvent);

    } else if (function == FastCCDFPPower) {

      if(value) {
        _status |= cin_ctl_fp_pwr(&cin_ctl_port, 1);
      } else {
        _status |= cin_ctl_fp_pwr(&cin_ctl_port, 0);
      }

      epicsEventSignal(statusEvent);

    } else if (function == FastCCDCameraPower) {

      if(value){
        _status |= cin_ctl_set_camera_pwr(&cin_ctl_port, 1);
      } else {
        _status |= cin_ctl_set_camera_pwr(&cin_ctl_port, 0);
      }

      epicsEventSignal(statusEvent);

    } else if ((function == FastCCDMux1) || (function == FastCCDMux2)) {

      int _val, _val1, _val2;
      getIntegerParam(FastCCDMux1, &_val1);
      getIntegerParam(FastCCDMux2, &_val2);
      _val = (_val2 << 4) | _val1;
      _status |= cin_ctl_set_mux(&cin_ctl_port, _val);   

      epicsEventSignal(statusEvent);

    } else if (function == FastCCDResetStats) {

      cin_data_reset_stats();

    } else if ((function == ADSizeY) || (function == FastCCDOverscan)) {

      // The Y size changed, change the descramble routine
      int _val1, _val2;
      getIntegerParam(ADSizeY, &_val1);
      getIntegerParam(FastCCDOverscan, &_val2);
      _status |= cin_data_set_descramble_params(_val1, _val2);

      // Read back to check all OK

      int _x, _y;
      cin_data_get_descramble_params(&_val1, &_val2, &_x, &_y);
      setIntegerParam(ADSizeX, _x);
      setIntegerParam(ADSizeY, _y);

    } else if (function == FastCCDFclk) {

      _status |= cin_ctl_set_fclk(&cin_ctl_port, value);
      epicsEventSignal(statusEvent);

    } else if (function == FastCCDFCRICGain){

      _status |= cin_ctl_set_fcric_gain(&cin_ctl_port, value);

    } else {
      status = ADDriver::writeInt32(pasynUser, value);
    }

    if(_status){
      status = asynError;
      setParamStatus(function, asynError);
    } else {
      setParamStatus(function, asynSuccess);
    }

    if (status) {
      asynPrint(pasynUser, ASYN_TRACE_ERROR,
            "%s:%s: error, status=%d function=%d, value=%d\n",
            driverName, functionName, status, function, value);
    } else {
      asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
            "%s:%s: function=%d, value=%d\n",
            driverName, functionName, function, value);
    }

    /* Do callbacks so higher layers see any changes */
    callParamCallbacks();

    return status;
}
IOService* BrcmPatchRAM::probe(IOService *provider, SInt32 *probeScore)
{
    uint64_t start_time, end_time, nano_secs;

    DebugLog("probe\n");

    AlwaysLog("Version %s starting on OS X Darwin %d.%d.\n", OSKextGetCurrentVersionString(), version_major, version_minor);

#ifdef TARGET_ELCAPITAN
    // preference towards starting BrcmPatchRAM2.kext when BrcmPatchRAM.kext also exists
    *probeScore = 2000;
#endif

#ifndef TARGET_ELCAPITAN
    // BrcmPatchRAM.kext, if installed on 10.11+... fails immediately
    if (version_major >= 15)
    {
        AlwaysLog("Aborting -- BrcmPatchRAM.kext should not be installed on 10.11+.  Use BrcmPatchRAM2.kext instead.\n");
        return NULL;
    }
#endif

    clock_get_uptime(&start_time);

#ifndef NON_RESIDENT
    mWorkLock = IOLockAlloc();
    if (!mWorkLock)
        return NULL;

    // Note: mLoadFirmwareLock is static (global), not instance data...
    if (!mLoadFirmwareLock)
        return NULL;
#endif

    mCompletionLock = IOLockAlloc();
    if (!mCompletionLock)
        return NULL;

    mDevice.setDevice(provider);
    if (!mDevice.getValidatedDevice())
    {
        AlwaysLog("Provider type is incorrect (not IOUSBDevice or IOUSBHostDevice)\n");
        return NULL;
    }

    // personality strings depend on version
    initBrcmStrings();

#ifndef NON_RESIDENT
    // longest time seen in normal re-probe was ~200ms (400+ms on 10.11)
    if (version_major >= 15)
        mBlurpWait = 800;
    else
        mBlurpWait = 400;
#endif

    OSString* displayName = OSDynamicCast(OSString, getProperty(kDisplayName));
    if (displayName)
        provider->setProperty(kUSBProductString, displayName);
    
    mVendorId = mDevice.getVendorID();
    mProductId = mDevice.getProductID();

    // get firmware here to pre-cache for eventual use on wakeup or now
    if (OSString* firmwareKey = OSDynamicCast(OSString, getProperty(kFirmwareKey)))
    {
        if (BrcmFirmwareStore* firmwareStore = getFirmwareStore())
            firmwareStore->getFirmware(mVendorId, mProductId, firmwareKey);
    }

    uploadFirmware();
    publishPersonality();

    clock_get_uptime(&end_time);
    absolutetime_to_nanoseconds(end_time - start_time, &nano_secs);
    uint64_t milli_secs = nano_secs / 1000000;
    AlwaysLog("Processing time %llu.%llu seconds.\n", milli_secs / 1000, milli_secs % 1000);

#ifdef NON_RESIDENT
    // maybe residency is not required for 10.11?
    mDevice.setDevice(NULL);
    return NULL;
#endif

    return this;
}