Esempio n. 1
0
int writeFirmwarePage(u32 address,u8 *buffer) {
	int i;
	u8 pagebuffer[256];
	readFirmware(address, pagebuffer, 256);
	
	if(memcmp(pagebuffer, buffer, 256) == 0) return 0;
	
	int oldIME = enterCriticalSection();
	
	//write enable
	REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_WREN);
	REG_SPICNT = 0;
	
	//Wait for Write Enable Latch to be set
	REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_RDSR);
	while((readwriteSPI(0) & 0x02) == 0); //Write Enable Latch
	REG_SPICNT = 0;
	
	//page write
	REG_SPICNT = SPI_ENABLE | SPI_CONTINUOUS | SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_PW);
	// Set the address
	readwriteSPI((address>>16) & 0xff);
	readwriteSPI((address>> 8) & 0xff);
	readwriteSPI((address) & 0xff);
	
	for(i = 0; i < 256; i++) {
		readwriteSPI(buffer[i]);
	}
	
	REG_SPICNT = 0;
	
	// wait for programming to finish
	REG_SPICNT = SPI_ENABLE|SPI_CONTINUOUS|SPI_DEVICE_NVRAM;
	readwriteSPI(FIRMWARE_RDSR);
	while(readwriteSPI(0) & 0x01); //Write In Progress
	REG_SPICNT = 0;
	
	leaveCriticalSection(oldIME);
	
	// read it back & verify
	readFirmware(address, pagebuffer, 256);
	if(memcmp(pagebuffer, buffer, 256) == 0) return 0;
	return -1;
}
Esempio n. 2
0
void SynscanDriver::setupParams()
{
    readFirmware();
    //readModel();
    readTracking();

    sendLocation();
    sendTime();
}
Esempio n. 3
0
//---------------------------------------------------------------------------------
void readUserSettings() {
//---------------------------------------------------------------------------------

	PERSONAL_DATA slot1;
	PERSONAL_DATA slot2;

	short slot1count, slot2count;
	short slot1CRC, slot2CRC;

	uint32 userSettingsBase;
	readFirmware( 0x20, &userSettingsBase,2);
	
	uint32 slot1Address = userSettingsBase * 8;
	uint32 slot2Address = userSettingsBase * 8 + 0x100;
	
	readFirmware( slot1Address , &slot1, sizeof(PERSONAL_DATA));
	readFirmware( slot2Address , &slot2, sizeof(PERSONAL_DATA));
	readFirmware( slot1Address + 0x70, &slot1count, 2);
	readFirmware( slot2Address + 0x70, &slot2count, 2);
	readFirmware( slot1Address + 0x72, &slot1CRC, 2);
	readFirmware( slot2Address + 0x72, &slot2CRC, 2);

	// default to slot 1 user Settings
	void *currentSettings = &slot1;
	
	short calc1CRC = swiCRC16( 0xffff, &slot1, sizeof(PERSONAL_DATA));
	short calc2CRC = swiCRC16( 0xffff, &slot2, sizeof(PERSONAL_DATA));

	// bail out if neither slot is valid
	if ( calc1CRC != slot1CRC && calc2CRC != slot2CRC) return;
	
	// if both slots are valid pick the most recent
	if ( calc1CRC == slot1CRC && calc2CRC == slot2CRC ) { 
		currentSettings = (slot2count == (( slot1count + 1 ) & 0x7f) ? &slot2 : &slot1);
	} else {
		if ( calc2CRC == slot2CRC )
			currentSettings = &slot2;
	}
	memcpy ( PersonalData, currentSettings, sizeof(PERSONAL_DATA));
	
}
Esempio n. 4
0
void FlashFirmwareDialog::startFlash(const QString &filename)
{
  bool backup = g.backupOnFlash();

  close();

  ProgressDialog progressDialog(this, tr("Write Firmware to Radio"), CompanionIcon("write_flash.png"));

  // check hardware compatibility if requested
  if (g.checkHardwareCompatibility()) {
    QString tempFirmware = generateProcessUniqueTempFileName("flash-check.bin");
    if (!readFirmware(tempFirmware, progressDialog.progress())) {
      QMessageBox::warning(this, tr("Firmware check failed"), tr("Could not check firmware from radio"));
      return;
    }
    FirmwareInterface previousFirmware(tempFirmware);
    qunlink(tempFirmware);
    FirmwareInterface newFirmware(filename);
    qDebug() << "startFlash: checking firmware compatibility between " << tempFirmware << "and" << filename;
    if (!newFirmware.isHardwareCompatible(previousFirmware)) {
      QMessageBox::warning(this, tr("Firmware check failed"), tr("New firmware is not compatible with the one currently installed!"));
      if (isTempFileName(filename)) {
        qDebug() << "startFlash: removing temporary file" << filename;
        qunlink(filename);
      }
      return;
    }
  }

  // backup if requested
  bool result = true;
  QString backupFilename;
  QString backupPath;
  if (backup) {
    backupPath = g.profile[g.id()].pBackupDir();
    if (backupPath.isEmpty()) {
      backupPath=g.backupDir();
    }     
    backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin";
    result = readEeprom(backupFilename, progressDialog.progress());
    sleep(2);
  }

  // flash
  result = (result && writeFirmware(filename, progressDialog.progress()));

  // restore if backup requested
  if (backup && result) {
    sleep(2);
    QString restoreFilename = generateProcessUniqueTempFileName("restore.bin");
    if (!convertEEprom(backupFilename, restoreFilename, filename)) {
      QMessageBox::warning(this, tr("Conversion failed"), tr("Cannot convert Models and Settings for use with this firmware, original data will be used"));
      restoreFilename = backupFilename;
    }
    if (!writeEeprom(restoreFilename, progressDialog.progress())) {
      QMessageBox::warning(this, tr("Restore failed"), tr("Could not restore Models and Settings to Radio. The models and settings data file can be found at: %1").arg(backupFilename));
    }
  }

  progressDialog.progress()->setInfo(tr("Flashing done"));
  progressDialog.exec();

  if (isTempFileName(filename)) {
    qDebug() << "startFlash: removing temporary file" << filename;
    qunlink(filename);
  }
}
Esempio n. 5
0
void InitFlashData() {
	readFirmware(0,FlashData,512);
}