AlcapDAQ  1
Data Structures | Macros | Typedefs | Functions
cvupgrade.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include "flash.h"
#include "CFASegment.h"

Go to the source code of this file.

Data Structures

struct  UpgradeParams
 

Macros

#define REVISION   "2.4"
 

Typedefs

typedef struct UpgradeParams cvUpgradeParams
 

Functions

static void Usage ()
 
static int ReadConfigurationROM (cvFlashAccess *Flash, CROM_MAP *crom)
 
static int ReadLicense (cvFlashAccess *Flash, uint8_t licenseData[LICENSE_DATA_SIZE])
 
static int EraseLicense (cvFlashAccess *Flash)
 
static void PrintCROM2File (FILE *fp, const CROM_MAP *map)
 
static int KeyInfo (cvUpgradeParams *Config, cvFlashAccess *Flash)
 
static int GetFWRel (cvUpgradeParams *Config, cvFlashAccess *Flash)
 
static int License (cvUpgradeParams *Config, cvFlashAccess *Flash)
 
int WriteKey (cvUpgradeParams *Config, cvFlashAccess *Flash)
 
int validateModel (cvUpgradeParams *config, cvFlashAccess *flash, char **fwData, int *fwSize)
 
int cvUpgrade (cvUpgradeParams *Config, cvFlashAccess *Flash)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

#define REVISION   "2.4"

Definition at line 75 of file cvupgrade.c.

Referenced by main().

Typedef Documentation

Function Documentation

int cvUpgrade ( cvUpgradeParams Config,
cvFlashAccess Flash 
)

Definition at line 466 of file cvupgrade.c.

References UpgradeParams::BaseAddress, UpgradeParams::BdNum, c, CAENCOM_INVALID_FILE_HANDLE, CAENComm_CloseDevice(), CAENComm_OpenDevice(), CAENComm_Success, UpgradeParams::cfa, UpgradeParams::ConfFile, CvUpgrade_CAENCommError, CvUpgrade_FileAccessError, UpgradeParams::FirstPageBck, UpgradeParams::FirstPageStd, FlashAccess::Handle, i, UpgradeParams::image, UpgradeParams::Link, UpgradeParams::Models, UpgradeParams::noverify, FlashAccess::PageSize, printf(), ReadFlashPage(), UpgradeParams::Type, Usage, validateModel(), UpgradeParams::verifyonly, Wait_ms, WriteFlashPage(), and WriteKey().

Referenced by main().

467 {
468  unsigned int i, j, page, pa, NumPages, err=0, done;
469  unsigned int CFsize;
470  unsigned char c, *CFdata = NULL;
471  unsigned char pdr[2048];
472  int res;
473 
474  FILE *cf;
475 
476  /* initialize the connection */
477  res = CAENComm_OpenDevice(Config->Type, Config->Link, Config->BdNum, Config->BaseAddress, &Flash->Handle);
478  if (res != CAENComm_Success) {
479  printf("Cannot open the Device!\n");
480  return(CvUpgrade_CAENCommError);
481  }
482 
483 
484  // ************************************************
485  // Open Binary Configuration File
486  // ************************************************
487  if (!Config->cfa) {
488  // open and read the configuration file
489  cf = fopen(Config->ConfFile,"rb");
490  if(cf == 0) {
491  printf("Can't open file %s\n",Config->ConfFile);
492  Usage();
495  }
496  // calculate the size
497  fseek (cf, 0, SEEK_END);
498  CFsize = ftell (cf);
499  fseek (cf, 0, SEEK_SET);
500  if ( (CFdata = (unsigned char *)malloc(CFsize)) == NULL ) {
501  printf("Can't allocate %d bytes\n",CFsize);
503  return(-3);
504  }
505 
506  for(i=0; i<CFsize; i++) {
507  // read one byte from file and mirror it (lsb becomes msb)
508  c = (unsigned char)fgetc(cf);
509  CFdata[i]=0;
510  for(j=0; j<8; j++)
511  CFdata[i] |= ( (c >> (7-j)) & 1) << j;
512  }
513  fclose(cf);
514 
515  } else {
516  printf("CFA Mode. Reading archive.\n");
517  if (validateModel(Config, Flash, &CFdata, &CFsize)) {
518  printf("Error: no compatible firmware found in archive!\n");
520  return -99;
521  }
522  printf("Compatible firmware found in archive.\n");
523 
524  for (i=0; i<CFsize; i++) {
525  char c = CFdata[i];
526  CFdata[i] = 0;
527  for (j=0; j<8; j++)
528  CFdata[i] |= ( (c >> (7-j)) & 1) << j;
529  }
530  }
531 
532 
533  NumPages = (CFsize % Flash->PageSize == 0) ? (CFsize / Flash->PageSize) : (CFsize / Flash->PageSize) + 1;
534 
535  printf("Board Types: %s\n", Config->Models);
536  if (Config->image == 0) {
537  if(!Config->verifyonly)
538  printf("Overwriting Standard image of the firmware with %s\n", Config->ConfFile);
539  else
540  printf("Verifying Standard image of the firmware with %s\n", Config->ConfFile);
541  pa = Config->FirstPageStd;
542  }
543  else {
544  if(!Config->verifyonly)
545  printf("Overwriting Backup image of the firmware with %s\n", Config->ConfFile);
546  else
547  printf("Verifying Backup image of the firmware with %s\n", Config->ConfFile);
548  pa = Config->FirstPageBck;
549  }
550 
551  printf("0%% Done\n");
552  done = 10;
553 
554  // ************************************************
555  // Start for loop
556  // ************************************************
557  for(page=0; page < NumPages; page++) {
558  if(!Config->verifyonly) {
559  // Write Page
560  if (WriteFlashPage(Flash, CFdata + page*Flash->PageSize, pa + page) < 0) {
561  printf("\nCommunication Error: the board at Base Address %08X does not respond\n", (unsigned int) (Config->BaseAddress));
562  err = 1;
563  break;
564  }
565  }
566 
567  if(!Config->noverify) {
568  // Read Page
569  if (ReadFlashPage(Flash, pdr, pa + page) < 0) {
570  printf("\nCommunication Error: the board at Base Address %08X does not respond\n", (unsigned int) (Config->BaseAddress));
571  err = 1;
572  break;
573  }
574  // Verify Page
575  for(i=0; (i<Flash->PageSize) && ((page*Flash->PageSize+i) < CFsize); i++) {
576  if(pdr[i] != CFdata[page*Flash->PageSize + i]) {
577  printf("\nFlash verify error (byte %d of page %d)!\n", i, pa + page);
578  if ((Config->image == 0) && !Config->verifyonly)
579  printf("The STD image can be corrupted! \nMove the jumper to Backup image and cycle the power\n");
580  err = 1;
581  break;
582  }
583  }
584  }
585  if (err)
586  break;
587 
588  if (page == (NumPages-1)) {
589  printf("100%% Done\n");
590  } else if ( page >= (NumPages*done/100) ) {
591  printf("%d%% Done\n", done);
592  done += 10;
593  }
594  } // end of for loop
595 
596  if(!err) {
597  if (Config->verifyonly) {
598  printf("\nFirmware verified successfully. Read %d bytes\n", CFsize);
599  } else {
600  printf("\nFirmware updated successfully. Written %d bytes\n", CFsize);
601  printf("The new firmware will be loaded after a power cycle\n");
602  }
603  }
604 
605  if (CFdata != NULL)
606  free(CFdata);
607 
608  if( !err) {
609  err= WriteKey( Config, Flash);
610  }
613  Wait_ms(1000);
614 
615  return err;
616 
617 }
static int EraseLicense ( cvFlashAccess Flash)
static

Definition at line 187 of file cvupgrade.c.

References AT45_PAGE_SIZE, LICENSE_FLASH_PAGE, and WriteFlashPage().

Referenced by License().

188 {
189  unsigned char data[AT45_PAGE_SIZE];
190 
191  memset( data, 0xff, sizeof( data));
192  return WriteFlashPage(Flash, data, LICENSE_FLASH_PAGE);
193 }
static int GetFWRel ( cvUpgradeParams Config,
cvFlashAccess Flash 
)
static

Definition at line 267 of file cvupgrade.c.

References UpgradeParams::AMCFwm, UpgradeParams::BaseAddress, UpgradeParams::BdNum, CAENCOM_INVALID_FILE_HANDLE, CAENComm_CloseDevice(), CAENComm_OpenDevice(), CAENComm_Read16(), CAENComm_Read32(), CAENComm_Success, CvUpgrade_FileAccessError, FlashAccess::Handle, i, UpgradeParams::Link, UpgradeParams::Models, printf(), UpgradeParams::ROCFwm, and UpgradeParams::Type.

Referenced by main().

267  {
268  /* initialize the connection */
269  int ret,d32,i;
270  unsigned char x,y;
271  int chNum = 2;
272  uint16_t BuildHexCode,d16;
273  if( CAENComm_OpenDevice(Config->Type, Config->Link, Config->BdNum, Config->BaseAddress, &Flash->Handle)!= CAENComm_Success){
274  printf("Cannot open the Device!\n");
276  }
277 
278  if (strcmp(Config->Models,"DIGITIZERS") == 0) {
279  // DIGITIZERS
280  if ((ret = CAENComm_Read32(Flash->Handle,Config->ROCFwm, &d32)) != CAENComm_Success) {
281  printf("unable to find ROC FPGA release\n");
282  return -1;
283  }
284  y = (uint8_t) (d32 & 0xff);
285  x = (uint8_t) ((d32 & 0xff00)>> 8);
286  BuildHexCode = (uint16_t) ((d32 & 0xffff0000)>> 16);
287  printf("ROC FPGA Release is %02d.%02d - Build %04X\n",x,y, BuildHexCode);
288 
289  for (i = 0; i< chNum; i++) {
290  if ((ret = CAENComm_Read32(Flash->Handle, Config->AMCFwm | (i<<8), &d32)) == CAENComm_Success) {
291  if ( (uint16_t)((d32 & 0xffff0000)>> 16) != 0x0000 ) break; // HACK this is for x780 support! AMC Build must be != 0000
292  }
293  }
294  if (i == (int32_t)chNum) {
295  printf("unable to find AMC FPGA release\n");
296  return -1;
297  }
298  y = (uint8_t) (d32 & 0xff);
299  x = (uint8_t) ((d32 & 0xff00)>> 8);
300  BuildHexCode = (uint16_t) ((d32 & 0xffff0000)>> 16);
301  printf("AMC FPGA Release is %02d.%02d - Build %04X",x,y, BuildHexCode);
302  }
303  else {
304  if (strcmp(Config->Models,"V1190,V1290") == 0) {
305  if ((ret = CAENComm_Read16(Flash->Handle,Config->ROCFwm, &d16)) != CAENComm_Success) {
306  printf("unable to find firmware release\n");
307  return -1;
308  }
309  y = (uint8_t) (d16 & 0xff);
310  x = (uint8_t) ((d16 & 0xff00)>> 8);
311  printf("Firmware Release is %02d.%02d\n",x,y);
312  }
313  else {
314  if ((ret = CAENComm_Read32(Flash->Handle,Config->ROCFwm, &d32)) != CAENComm_Success) {
315  printf("unable to find firmware release\n");
316  return -1;
317  }
318  y = (uint8_t) (d32 & 0xff);
319  x = (uint8_t) ((d32 & 0xff00)>> 8);
320  printf("Firmware Release is %02d.%02d\n",x,y);
321  }
322  }
325 
326  printf("\n");
327  printf("Program exits successfully.\n");
328  return 0;
329 }
static int KeyInfo ( cvUpgradeParams Config,
cvFlashAccess Flash 
)
static

Definition at line 215 of file cvupgrade.c.

References AT45_IDREG_LENGTH, UpgradeParams::BaseAddress, UpgradeParams::BdNum, CAENCOM_INVALID_FILE_HANDLE, CAENComm_CloseDevice(), CAENComm_OpenDevice(), CAENComm_Success, CROM_MAP::crom_serial, CvUpgrade_FileAccessError, UpgradeParams::filepath, FlashAccess::Handle, i, UpgradeParams::Link, UpgradeParams::modelName, PrintCROM2File(), printf(), ReadConfigurationROM(), ReadFlashSecurityReg(), sprintf(), and UpgradeParams::Type.

Referenced by main().

215  {
216  int i;
217  unsigned char security_vme[AT45_IDREG_LENGTH];
218  // unsigned long vboard_base_address;
219  char KeyFilename[200];
220  FILE *cf = NULL;
221  int res;
222 
223  CROM_MAP rom;
224 
225  /* initialize the connection */
226  res = CAENComm_OpenDevice(Config->Type, Config->Link, Config->BdNum, Config->BaseAddress, &Flash->Handle);
227  if (res != CAENComm_Success) {
228  printf("Cannot open the Device!\n");
230  }
231 
232  if (ReadFlashSecurityReg(Flash, security_vme)) {
233  printf("Error while reading on-board flash memory!\n");
235  }
236  if (ReadConfigurationROM(Flash, &rom)) {
237  printf("Error while reading on-board flash memory!\n");
239  }
240  if( strlen( Config->modelName)) {
241  sprintf(KeyFilename, "%s/BoardInfo-%s-%d.dat", Config->filepath, Config->modelName, rom.crom_serial);
242  } else {
243  sprintf(KeyFilename, "%s/BoardInfo-%d.dat", Config->filepath, rom.crom_serial);
244  }
245  cf = fopen(KeyFilename,"w");
246  if(cf == 0) {
247  printf("Cannot open %s file! Exiting ...\n", KeyFilename);
249  }
250 
251  printf("Writing output file %s\n", KeyFilename);
252  for(i=0; i < 64; i++) {
253  fprintf(cf, "%02X", security_vme[64+i]);
254  fprintf(cf, (i < 63) ? ":" : "\n");
255  }
256  PrintCROM2File(cf, &rom);
257 
260 
261  printf("\n");
262  printf("Program exits successfully.\n");
263  fclose(cf);
264  return 0;
265 }
static int License ( cvUpgradeParams Config,
cvFlashAccess Flash 
)
static

Definition at line 334 of file cvupgrade.c.

References UpgradeParams::BaseAddress, UpgradeParams::BdNum, CAENCOM_INVALID_FILE_HANDLE, CAENComm_CloseDevice(), CAENComm_OpenDevice(), CAENComm_Success, CvUpgrade_FileAccessError, UpgradeParams::delete, EraseLicense(), FlashAccess::Handle, i, LICENSE_DATA_SIZE, UpgradeParams::Link, printf(), ReadLicense(), and UpgradeParams::Type.

Referenced by main().

334  {
335 
336  /* initialize the connection */
337  if( CAENComm_OpenDevice(Config->Type, Config->Link, Config->BdNum, Config->BaseAddress, &Flash->Handle)!= CAENComm_Success){
338  printf("Cannot open the Device!\n");
340  }
341 
342  if( Config->delete) {
343  // delete the license data
344  if( EraseLicense( Flash)) {
345  printf("Error deleting license data! Exiting ...\n");
347  }
348  } else {
349  uint8_t licenseData[LICENSE_DATA_SIZE];
350  if( ReadLicense( Flash, licenseData)) {
351  printf("Error reading license data! Exiting ...\n");
353  }
354  // print the license data
355  // check if a valid license
356  printf("\n");
357  if( ( licenseData[0]!= 0x00) || ( licenseData[1]!= 0x04)) {
358  printf("No valid license found!");
359  } else {
360  int i;
361  for( i= 0; i< LICENSE_DATA_SIZE; i++) {
362  printf( "%02X ", licenseData[i]);
363  }
364  }
365  }
368 
369  printf("\n");
370  printf("Program exits successfully.\n");
371  return 0;
372 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 623 of file cvupgrade.c.

References UpgradeParams::AMCFwm, UpgradeParams::BaseAddress, UpgradeParams::BdNum, CAENCOM_INVALID_FILE_HANDLE, CAENComm_PCI_OpticalLink, CAENComm_USB, UpgradeParams::cfa, UpgradeParams::ConfFile, cvUpgrade(), CvUpgrade_GenericError, UpgradeParams::delete, UpgradeParams::family, UpgradeParams::filepath, UpgradeParams::FirstPageBck, UpgradeParams::FirstPageStd, FlashAccess::FlashEnable, GetFWRel(), FlashAccess::Handle, UpgradeParams::image, UpgradeParams::key, key, KeyInfo(), License(), UpgradeParams::Link, UpgradeParams::modelName, UpgradeParams::Models, UpgradeParams::noverify, FlashAccess::PageSize, printf(), FlashAccess::RegSize, REVISION, UpgradeParams::ROCFwm, FlashAccess::RW_Flash, FlashAccess::Sel_Flash, sprintf(), UpgradeParams::Type, Usage, UpgradeParams::verifyonly, and WriteKey().

624 {
625  int err=0;
626  int key = 0;
627  int license = 0;
628  int fwrel = 0;
629  int writeKey= 0;
630  cvUpgradeParams Params;
631  cvFlashAccess FlashInfo;
632  char ParamFile[1000] = "cvUpgrade_params.txt";
633  int argIndex= 1;
634 
635  FILE *bdf;
636 
637  printf("\n");
638  printf("********************************************************\n");
639  printf(" CAEN SpA - Front-End Division \n");
640  printf("--------------------------------------------------------\n");
641  printf(" CAEN Board Firmware Upgrade \n");
642  printf(" Version %s \n", REVISION);
643  printf("********************************************************\n\n");
644 
645  // Check command arguments (must be at least 2)
646  if (argc < 3) {
647  Usage();
648  return(-1);
649  }
650 
651  // Inizialize defaults
653  FlashInfo.FlashEnable = 0;
654  Params.Link = 0;
655  Params.BdNum = 0;
656  Params.image = 0; // Default = standard
657  Params.noverify = 0;
658  Params.verifyonly = 0;
659  Params.BaseAddress = 0;
660  Params.key = 0;
661  *Params.modelName= '\0';
662  Params.delete = 0;
663  Params.cfa = 1;
664 
665  strstr(Params.ConfFile, "cvUpgrade_params.txt");
666  if (strcmp(argv[argIndex],"-KeyInfo") == 0 ) {
667  key = 1;
668  } else if (strcmp(argv[argIndex],"-License") == 0 ) {
669  license = 1;
670  } else if (strcmp(argv[argIndex],"-Key") == 0 ) {
671  sscanf(argv[++argIndex], "%llx", &Params.key);
672  writeKey = 1;
673  } else if (strcmp(argv[argIndex],"-fwrel") == 0 ) {
674  fwrel = 1;
675  } else {
676  sprintf(Params.ConfFile, argv[argIndex]);
677  }
678  argIndex++;
679  if (strcmp(argv[argIndex],"USB") == 0) Params.Type = CAENComm_USB;
680  if (strcmp(argv[argIndex],"OPTLINK") == 0) Params.Type = CAENComm_PCI_OpticalLink;
681 // if (strcmp(argv[argIndex],"PCIE_OPTLINK") == 0) Params.Type = CAENComm_PCIE_OpticalLink;
682  argIndex++;
683  for (; argIndex<argc; argIndex++) {
684  if ( strcmp(argv[argIndex],"-backup") == 0 )
685  Params.image = 1;
686  if ( strcmp(argv[argIndex],"-no_verify") == 0 )
687  Params.noverify = 1;
688  if ( strcmp(argv[argIndex],"-verify_only") == 0 )
689  Params.verifyonly = 1;
690  if ( strcmp(argv[argIndex],"-param") == 0 )
691  sprintf(ParamFile, "%s", argv[++argIndex]);
692  if ( strcmp(argv[argIndex],"-rbf") == 0 )
693  Params.cfa = 0;
694  if ( strcmp(argv[argIndex],"-VMEbaseaddress") == 0 )
695  sscanf(argv[++argIndex], "%x", (unsigned int *) (&Params.BaseAddress));
696  if ( strcmp(argv[argIndex],"-key") == 0 )
697  sscanf(argv[++argIndex], "%llx", &Params.key);
698  if ( strcmp(argv[argIndex],"-link") == 0 )
699  Params.Link = atoi(argv[++argIndex]);
700  if ( strcmp(argv[argIndex],"-bdnum") == 0 )
701  Params.BdNum = atoi(argv[++argIndex]);
702  if ( strcmp(argv[argIndex],"-modelname") == 0 ) {
703  strncpy( Params.modelName, argv[++argIndex], sizeof( Params.modelName));
704  Params.modelName[ sizeof( Params.modelName)- 1]= '\0';
705  }
706  if ( strcmp(argv[argIndex],"-modelfamily") == 0 ) {
707  strncpy( Params.family, argv[++argIndex], sizeof( Params.family));
708  Params.family[ sizeof( Params.family)- 1]= '\0';
709  }
710  if ( strcmp(argv[argIndex],"-filepath") == 0 ) {
711  strncpy( Params.filepath, argv[++argIndex], sizeof( Params.filepath));
712  Params.filepath[ sizeof( Params.filepath)- 1]= '\0';
713  }
714  if ( strcmp(argv[argIndex],"-delete") == 0 )
715  Params.delete = 1;
716  }
717 
718  // open the board descriptor file
719  if ((!Params.cfa) || (fwrel) || (license) || (key) | (writeKey)) {
720  bdf = fopen(ParamFile,"r");
721  if(bdf == 0) {
722  printf("Can't open file %s\n", ParamFile);
723  Usage();
724  return (-2);
725  }
726 
727  fscanf(bdf, "%s", Params.Models);
728  fscanf(bdf, "%x", (unsigned int *) (&FlashInfo.Sel_Flash));
729  fscanf(bdf, "%x", (unsigned int *) (&FlashInfo.RW_Flash));
730  fscanf(bdf, "%d", &FlashInfo.RegSize);
731  fscanf(bdf, "%d", &FlashInfo.PageSize);
732  fscanf(bdf, "%d", &Params.FirstPageStd);
733  fscanf(bdf, "%d", &Params.FirstPageBck);
734  if (!feof(bdf)) {
735  int tmp;
736  if (fscanf(bdf, "%d", &tmp) > 0)
737  FlashInfo.FlashEnable = tmp;
738  }
739  fscanf(bdf, "%x", &Params.ROCFwm);
740  fscanf(bdf, "%x", &Params.AMCFwm);
741  fclose(bdf);
742  }
743 
744  // Call cvUpgrade function
745  //if (key == 0)
746  // err = cvUpgrade(&Params, &FlashInfo);
747  //else {
748  // if ((!strncmp(Params.Models,"DIGITIZERS",1000)) ||
749  // (!strncmp(Params.Models,"V1495",1000)) ) {
750  // err = KeyInfo(&Params, &FlashInfo);
751  // }
752  //}
753  if (key ) {
754  if ((!strncmp(Params.Models,"DIGITIZERS",1000)) ||
755  (!strncmp(Params.Models,"V1495",1000)) ) {
756  err = KeyInfo(&Params, &FlashInfo);
757  }
758  } else if (license ) {
759  if ((!strncmp(Params.Models,"DIGITIZERS",1000)) ||
760  (!strncmp(Params.Models,"V1495",1000)) ) {
761  err = License(&Params, &FlashInfo);
762  }
763  } else if (writeKey ) {
764  err = WriteKey(&Params, &FlashInfo);
765  } else if (fwrel ) {
766  err = GetFWRel(&Params, &FlashInfo);
767  } else {
768  err = cvUpgrade(&Params, &FlashInfo);
769  if (err) return err;
770  }
771  if (err)
772  return (CvUpgrade_GenericError);
773  else
774  return 0;
775 }
static void PrintCROM2File ( FILE *  fp,
const CROM_MAP map 
)
static

Definition at line 198 of file cvupgrade.c.

References CROM_MAP::crom_board_id, CROM_MAP::crom_c_code, CROM_MAP::crom_chksum, CROM_MAP::crom_chksum_len, CROM_MAP::crom_const, CROM_MAP::crom_OUI, CROM_MAP::crom_r_code, CROM_MAP::crom_revision, CROM_MAP::crom_serial, CROM_MAP::crom_VCXO_type, and CROM_MAP::crom_version.

Referenced by KeyInfo().

198  {
199  fprintf(fp,"Checksum = %X\n", map->crom_chksum);
200  fprintf(fp,"Checksum Length = %X\n", map->crom_chksum_len);
201  fprintf(fp,"Constant field = %X\n", map->crom_const);
202  fprintf(fp,"C Code = %X\n", map->crom_c_code);
203  fprintf(fp,"R Code = %X\n", map->crom_r_code);
204  fprintf(fp,"OUI = %X\n", map->crom_OUI);
205  fprintf(fp,"Version = %X\n", map->crom_version);
206  fprintf(fp,"Board ID = %X\n", map->crom_board_id);
207  fprintf(fp,"PCB Revision = %d\n", map->crom_revision);
208  fprintf(fp,"Serial Number = %d\n", map->crom_serial);
209  fprintf(fp,"VCXO Type ID = %d\n", map->crom_VCXO_type);
210 }
static int ReadConfigurationROM ( cvFlashAccess Flash,
CROM_MAP crom 
)
static

Definition at line 144 of file cvupgrade.c.

References AT45_PAGE_SIZE, CROM_MAP::crom_board_id, CROM_MAP::crom_c_code, CROM_MAP::crom_chksum, CROM_MAP::crom_chksum_len, CROM_MAP::crom_const, CROM_MAP::crom_OUI, CROM_MAP::crom_r_code, CROM_MAP::crom_revision, CROM_MAP::crom_serial, CROM_MAP::crom_VCXO_type, CROM_MAP::crom_version, ReadFlashPage(), and ROM_FLASH_PAGE.

Referenced by KeyInfo().

145 {
146  unsigned char data[AT45_PAGE_SIZE];
147  int res = 0;
148 
149  res = ReadFlashPage(Flash, data, ROM_FLASH_PAGE);
150 
151  if (res == 0) {
152  crom->crom_chksum = (uint8_t)(data[0]);
153  crom->crom_chksum_len = (uint32_t) ((data[1] << 16) | (data[2] << 8) | data[3]);
154  crom->crom_const = (uint32_t) ((data[4] << 16) | (data[5] << 8) | data[6]);
155  crom->crom_c_code = (uint8_t)(data[7]);
156  crom->crom_r_code = (uint8_t)(data[8]);
157  crom->crom_OUI = (uint32_t) ((data[9] << 16) | (data[10] << 8) | data[11]);
158  crom->crom_version = (uint8_t)(data[12]);
159  crom->crom_board_id = (uint32_t) ((data[13] << 16) | (data[14] << 8) | data[15]);
160  crom->crom_revision = (uint32_t) ( (data[16] << 24) | (data[17] << 16) | (data[18] << 8) | data[19]);
161  crom->crom_serial = (uint16_t) ((data[32] << 8) | (data[33]));
162  crom->crom_VCXO_type = (uint8_t)(data[34]);
163  }
164  return res;
165 }
static int ReadLicense ( cvFlashAccess Flash,
uint8_t  licenseData[LICENSE_DATA_SIZE] 
)
static

Definition at line 171 of file cvupgrade.c.

References AT45_PAGE_SIZE, LICENSE_FLASH_PAGE, and ReadFlashPage().

Referenced by License().

172 {
173  unsigned char data[AT45_PAGE_SIZE];
174  int res = 0;
175 
176  if( (res = ReadFlashPage(Flash, data, LICENSE_FLASH_PAGE))!= 0) {
177  return res;
178  }
179  memcpy( licenseData, data, LICENSE_DATA_SIZE);
180  return 0;
181 }
static void Usage ( )
static

Definition at line 109 of file cvupgrade.c.

References printf().

109  {
110  printf("Syntax: cvUpgrade ConfFile ConnType[USB|OPTLINK] [ConfigOptions][DeviceOptions]\n");
111  printf("Syntax: cvUpgrade -KeyInfo ConnType[USB|OPTLINK] [DeviceOptions]\n");
112  printf("Syntax: cvUpgrade -License ConnType[USB|OPTLINK] [LicenseOptions]\n");
113  printf("Syntax: cvUpgrade -Key N ConnType[USB|OPTLINK] [DeviceOptions]\n\n");
114  printf("Syntax: cvUpgrade -fvrel ConnType[USB|OPTLINK] [DeviceOptions]\n\n");
115  printf("Description: write the file 'ConfFile' (Altera Raw Binary Format) into\n");
116  printf("the flash memory of board connected by the specified connection type OR\n");
117  printf("retrieve the keyinfo data from the board and store it on BoardInfo.dat file OR\n");
118  printf("retrieve or delete the license data from the board:\n");
119  printf(" to delete the license file you must specify -delete option\n\n");
120  printf("ConfigOptions:\n\n");
121  printf("-backup: write backup image\n\n");
122  printf("-key N: The key value to enable the DPP firmware\n\n");
123  printf("-no_verify: disable verify (don't read and compare the flash content)\n\n");
124  printf("-verify_only: read the flash content and compare with the ConfFile file\n\n");
125  printf("DeviceOptions:\n\n");
126  printf("-param filename: allow to specify the file that contain the parameters for the\n");
127  printf(" board that is being upgraded (default is cvUpgrade_params.txt)\n");
128  printf(" With CFA files this option is not required.\n\n");
129  printf("-rbf: specifies that the config file to be updated is in RBF format.\n");
130  printf("-link N: when using CONET, it is the optical link number to be used\n");
131  printf(" when using USB, it is the USB device number to be used (default is 0)\n\n");
132  printf("-bdnum N: select board number in a chainable link (V2718 only)\n\n");
133  printf("-VMEbaseaddress N: The base address of the VME slave board to be upgraded (Hex 32 bit)\n\n");
134  printf("-modelname ModelName: specify the model name (e.g. V1724B)\n\n");
135  printf("-filepath Folder: specify the folder where store the KeyInfo file\n\n");
136  printf("LicenseOptions:\n\n");
137  printf("-delete : deletes the license data\n");
138 }
int validateModel ( cvUpgradeParams config,
cvFlashAccess flash,
char **  fwData,
int *  fwSize 
)

Definition at line 413 of file cvupgrade.c.

References CFASegmentType1_t::accessType, CFAModelType1_t::address, CAENComm_Read16(), CAENComm_Read32(), CFA_SEGMENT_TYPE_1, UpgradeParams::ConfFile, deleteSegment(), UpgradeParams::FirstPageBck, UpgradeParams::FirstPageStd, CFASegmentType1_t::flashBckAddress, CFASegmentType1_t::flashCsAddress, CFASegmentType1_t::flashCwAddress, FlashAccess::FlashEnable, CFASegmentType1_t::flashEnLevel, CFASegmentType1_t::flashPageSize, CFASegmentType1_t::flashStdAddress, CFASegmentType1_t::fwData, CFASegmentType1_t::fwSizeBytes, getSegmentType(), FlashAccess::Handle, i, last, CFAModelType1_t::modelId, CFASegmentType1_t::models, UpgradeParams::Models, newSegment(), CFAModelType1_t::numChecks, CFASegmentType1_t::numModels, FlashAccess::PageSize, CFAModelType1_t::registerChecks, FlashAccess::RegSize, FlashAccess::RW_Flash, FlashAccess::Sel_Flash, sprintf(), toType1, value, and CFAModelType1_t::value.

413  {
414  FILE* fin = fopen(config->ConfFile, "rb");
415  while (!feof(fin)) {
416  int last;
417  CFASegmentPtr segm = newSegment(fin, &last);
418  if (segm == NULL) {
419  fclose(fin);
420  return -2;
421  }
422  if (getSegmentType(segm) == CFA_SEGMENT_TYPE_1) {
423  CFASegmentType1* t1s = toType1(segm);
424  int i, j;
425  for (i = 0; i < t1s->numModels; i++) {
426  for (j = 0; j<t1s->models[i]->numChecks; j++) {
427  uint32_t address = t1s->models[i]->registerChecks[j].address;
428  uint32_t value;
429  if (t1s->accessType == 2) CAENComm_Read16(flash->Handle, address, (uint16_t*)&value);
430  else CAENComm_Read32(flash->Handle, address, &value);
431  if (value != t1s->models[i]->registerChecks[j].value) break;
432  }
433  if (j == t1s->models[i]->numChecks) { /* this means that all the checks match */
434  flash->PageSize = t1s->flashPageSize;
435  flash->RegSize = t1s->accessType;
436  flash->Sel_Flash = t1s->flashCsAddress;
437  flash->RW_Flash = t1s->flashCwAddress;
438  flash->FlashEnable = t1s->flashEnLevel;
439  config->FirstPageStd = t1s->flashStdAddress;
440  config->FirstPageBck = t1s->flashBckAddress;
441 
442  *fwData = malloc(t1s->fwSizeBytes);
443  memcpy(*fwData, t1s->fwData, t1s->fwSizeBytes);
444  *fwSize = t1s->fwSizeBytes;
445 
446  sprintf(config->Models, "id %d", t1s->models[i]->modelId);
447 
448  deleteSegment(segm);
449  fclose(fin);
450  return 0;
451  }
452  }
453  }
454  deleteSegment(segm);
455  if (last) break;
456  }
457  fclose(fin);
458  return -1;
459 }
int WriteKey ( cvUpgradeParams Config,
cvFlashAccess Flash 
)

Definition at line 377 of file cvupgrade.c.

References UpgradeParams::BaseAddress, UpgradeParams::BdNum, CAENCOM_INVALID_FILE_HANDLE, CAENComm_CloseDevice(), CAENComm_OpenDevice(), CAENComm_Success, CvUpgrade_FileAccessError, FlashAccess::Handle, UpgradeParams::key, LICENSE_DATA_SIZE, LICENSE_FLASH_PAGE, UpgradeParams::Link, UpgradeParams::Models, printf(), UpgradeParams::Type, Wait_ms, and WriteFlashPage().

Referenced by cvUpgrade(), and main().

378 {
379  unsigned int err=0, res, handleToClose= 0;
380  unsigned char key_page[LICENSE_DATA_SIZE];
381  int k;
382 
383  if ((Config->key != 0) &&
384  ((!strncmp(Config->Models,"DIGITIZERS",1000)) ||
385  (!strncmp(Config->Models,"V1495",1000)))) {
386  if( Flash->Handle== CAENCOM_INVALID_FILE_HANDLE) {
387  res = CAENComm_OpenDevice(Config->Type, Config->Link, Config->BdNum, Config->BaseAddress, &Flash->Handle);
388  if (res != CAENComm_Success) {
389  printf("Cannot open the Device!\n");
391  }
392  handleToClose= 1;
393  }
394 
395  memset(key_page, 0, LICENSE_DATA_SIZE);
396  for (k = LICENSE_DATA_SIZE- 1; k > -1; k--) {
397  key_page[LICENSE_DATA_SIZE- 1- k] = (unsigned char) ((Config->key >> (k * 8)) & 0xFF);
398  }
399  WriteFlashPage(Flash, key_page, LICENSE_FLASH_PAGE);
400  if( handleToClose) {
402  Wait_ms(1000);
404  }
405  printf("\nKey written successfully\n");
406  }
407  return err;
408 }