75 #define REVISION "2.4"
84 #include "CFASegment.h"
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");
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]);
157 crom->
crom_OUI = (uint32_t) ((data[9] << 16) | (data[10] << 8) | data[11]);
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]));
179 memcpy( licenseData, data, LICENSE_DATA_SIZE);
191 memset( data, 0xff,
sizeof( data));
201 fprintf(fp,
"Constant field = %X\n", map->
crom_const);
204 fprintf(fp,
"OUI = %X\n", map->
crom_OUI);
208 fprintf(fp,
"Serial Number = %d\n", map->
crom_serial);
219 char KeyFilename[200];
228 printf(
"Cannot open the Device!\n");
233 printf(
"Error while reading on-board flash memory!\n");
237 printf(
"Error while reading on-board flash memory!\n");
245 cf = fopen(KeyFilename,
"w");
247 printf(
"Cannot open %s file! Exiting ...\n", KeyFilename);
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");
262 printf(
"Program exits successfully.\n");
272 uint16_t BuildHexCode,d16;
274 printf(
"Cannot open the Device!\n");
278 if (strcmp(Config->
Models,
"DIGITIZERS") == 0) {
281 printf(
"unable to find ROC FPGA release\n");
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);
289 for (i = 0; i< chNum; i++) {
291 if ( (uint16_t)((d32 & 0xffff0000)>> 16) != 0x0000 )
break;
294 if (i == (int32_t)chNum) {
295 printf(
"unable to find AMC FPGA release\n");
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);
304 if (strcmp(Config->
Models,
"V1190,V1290") == 0) {
306 printf(
"unable to find firmware release\n");
309 y = (uint8_t) (d16 & 0xff);
310 x = (uint8_t) ((d16 & 0xff00)>> 8);
311 printf(
"Firmware Release is %02d.%02d\n",x,y);
315 printf(
"unable to find firmware release\n");
318 y = (uint8_t) (d32 & 0xff);
319 x = (uint8_t) ((d32 & 0xff00)>> 8);
320 printf(
"Firmware Release is %02d.%02d\n",x,y);
327 printf(
"Program exits successfully.\n");
338 printf(
"Cannot open the Device!\n");
345 printf(
"Error deleting license data! Exiting ...\n");
351 printf(
"Error reading license data! Exiting ...\n");
357 if( ( licenseData[0]!= 0x00) || ( licenseData[1]!= 0x04)) {
358 printf(
"No valid license found!");
362 printf(
"%02X ", licenseData[i]);
370 printf(
"Program exits successfully.\n");
379 unsigned int err=0, res, handleToClose= 0;
383 if ((Config->
key != 0) &&
384 ((!strncmp(Config->
Models,
"DIGITIZERS",1000)) ||
385 (!strncmp(Config->
Models,
"V1495",1000)))) {
389 printf(
"Cannot open the Device!\n");
405 printf(
"\nKey written successfully\n");
414 FILE* fin = fopen(config->
ConfFile,
"rb");
468 unsigned int i, j, page, pa, NumPages, err=0, done;
470 unsigned char c, *CFdata = NULL;
471 unsigned char pdr[2048];
479 printf(
"Cannot open the Device!\n");
497 fseek (cf, 0, SEEK_END);
499 fseek (cf, 0, SEEK_SET);
500 if ( (CFdata = (
unsigned char *)malloc(CFsize)) == NULL ) {
501 printf(
"Can't allocate %d bytes\n",CFsize);
506 for(i=0; i<CFsize; i++) {
508 c = (
unsigned char)fgetc(cf);
511 CFdata[i] |= ( (c >> (7-j)) & 1) << j;
516 printf(
"CFA Mode. Reading archive.\n");
518 printf(
"Error: no compatible firmware found in archive!\n");
522 printf(
"Compatible firmware found in archive.\n");
524 for (i=0; i<CFsize; i++) {
528 CFdata[i] |= ( (c >> (7-j)) & 1) << j;
536 if (Config->
image == 0) {
538 printf(
"Overwriting Standard image of the firmware with %s\n", Config->
ConfFile);
540 printf(
"Verifying Standard image of the firmware with %s\n", Config->
ConfFile);
545 printf(
"Overwriting Backup image of the firmware with %s\n", Config->
ConfFile);
547 printf(
"Verifying Backup image of the firmware with %s\n", Config->
ConfFile);
557 for(page=0; page < NumPages; page++) {
561 printf(
"\nCommunication Error: the board at Base Address %08X does not respond\n", (
unsigned int) (Config->
BaseAddress));
570 printf(
"\nCommunication Error: the board at Base Address %08X does not respond\n", (
unsigned int) (Config->
BaseAddress));
576 if(pdr[i] != CFdata[page*Flash->
PageSize + i]) {
577 printf(
"\nFlash verify error (byte %d of page %d)!\n", i, pa + page);
579 printf(
"The STD image can be corrupted! \nMove the jumper to Backup image and cycle the power\n");
588 if (page == (NumPages-1)) {
590 }
else if ( page >= (NumPages*done/100) ) {
591 printf(
"%d%% Done\n", done);
598 printf(
"\nFirmware verified successfully. Read %d bytes\n", CFsize);
600 printf(
"\nFirmware updated successfully. Written %d bytes\n", CFsize);
601 printf(
"The new firmware will be loaded after a power cycle\n");
623 int main(
int argc,
char *argv[])
632 char ParamFile[1000] =
"cvUpgrade_params.txt";
638 printf(
"********************************************************\n");
639 printf(
" CAEN SpA - Front-End Division \n");
640 printf(
"--------------------------------------------------------\n");
641 printf(
" CAEN Board Firmware Upgrade \n");
643 printf(
"********************************************************\n\n");
665 strstr(Params.
ConfFile,
"cvUpgrade_params.txt");
666 if (strcmp(argv[argIndex],
"-KeyInfo") == 0 ) {
668 }
else if (strcmp(argv[argIndex],
"-License") == 0 ) {
670 }
else if (strcmp(argv[argIndex],
"-Key") == 0 ) {
671 sscanf(argv[++argIndex],
"%llx", &Params.
key);
673 }
else if (strcmp(argv[argIndex],
"-fwrel") == 0 ) {
683 for (; argIndex<argc; argIndex++) {
684 if ( strcmp(argv[argIndex],
"-backup") == 0 )
686 if ( strcmp(argv[argIndex],
"-no_verify") == 0 )
688 if ( strcmp(argv[argIndex],
"-verify_only") == 0 )
690 if ( strcmp(argv[argIndex],
"-param") == 0 )
691 sprintf(ParamFile,
"%s", argv[++argIndex]);
692 if ( strcmp(argv[argIndex],
"-rbf") == 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 ) {
706 if ( strcmp(argv[argIndex],
"-modelfamily") == 0 ) {
707 strncpy( Params.
family, argv[++argIndex],
sizeof( Params.
family));
710 if ( strcmp(argv[argIndex],
"-filepath") == 0 ) {
714 if ( strcmp(argv[argIndex],
"-delete") == 0 )
719 if ((!Params.
cfa) || (fwrel) || (license) || (
key) | (writeKey)) {
720 bdf = fopen(ParamFile,
"r");
722 printf(
"Can't open file %s\n", ParamFile);
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);
736 if (fscanf(bdf,
"%d", &tmp) > 0)
739 fscanf(bdf,
"%x", &Params.
ROCFwm);
740 fscanf(bdf,
"%x", &Params.
AMCFwm);
754 if ((!strncmp(Params.
Models,
"DIGITIZERS",1000)) ||
755 (!strncmp(Params.
Models,
"V1495",1000)) ) {
756 err =
KeyInfo(&Params, &FlashInfo);
758 }
else if (license ) {
759 if ((!strncmp(Params.
Models,
"DIGITIZERS",1000)) ||
760 (!strncmp(Params.
Models,
"V1495",1000)) ) {
761 err =
License(&Params, &FlashInfo);
763 }
else if (writeKey ) {
764 err =
WriteKey(&Params, &FlashInfo);
766 err =
GetFWRel(&Params, &FlashInfo);