#include <trberror.h>
+static const uint16_t HardwareId = 0x0042;
static const uint16_t CtrlReg = 0xd000;
static const uint16_t SetupReg = 0xd001;
static const uint16_t BlockRam = 0xd100;
typedef enum {
FLASH_INVALID = 0,
- FLASH_ADCM1 = 1,
- FLASH_ADCM23_SHOWER = 2,
- FLASH_MDC = 3
+
+ FLASH_RICH_ADCM_V1 = 1,
+ FLASH_RICH_ADCM_V2 = 2,
+ FLASH_RICH_ADCM_V3 = 3,
+
+ FLASH_MDC_HUB_V2_FPGA1234 = 4,
+ FLASH_MDC_HUB_V2_FPGA5 = 5,
+
+ FLASH_MDC_OEP_V2 = 6,
+ FLASH_MDC_OEP_V3 = 7,
+
+ FLASH_SHOWER_ADDON_V2_FPGA1 = 8,
+ FLASH_SHOWER_ADDON_V2_FPGA2 = 9,
+ FLASH_SHOWER_ADDON_V2_FPGA3 = 10,
+
+ FLASH_CTS_FPGA1 = 11,
+ FLASH_CTS_FPGA2 = 12
+
} FlashType;
static const char FlashTypeStr[][32] =
- {"INVALID", "ADCM1", "ADCM2&3 / SHOWER / MDCHub", "MDC OEP"};
+ {
+ "INVALID",
+ "RICH_ADCM_V1", "RICH_ADCM_V2", "RICH_ADCM_V3",
+ "MDC_HUB_V2_FPGA1234", "MDC_HUB_V2_FPGA5",
+ "MDC_OEP_V2", "MDC_OEP_V3",
+ "SHOWER_ADDON_V2_FPGA1", "SHOWER_ADDON_V2_FPGA2", "SHOWER_ADDON_V2_FPGA3",
+ "CTS_FPGA1", "CTS_FPGA2"
+ };
static FlashType flashType = FLASH_INVALID;
-
-static const char trbflash_version[] = "$Revision: 2.13 $";
+static uint32_t manId = 0;
+static const char trbflash_version[] = "$Revision: 2.14 $";
static uint32_t mdcFlashSelect = 1;
-static int force = 0;
+static int yesToAll = 0;
+
+static int skipFirmwareIdCheck = 0;
+
+static int skipHwIdCheck = 0;
/* ------ Local Functions ----------------------------------------------- */
ret = 0;
for (i = 0; i < status; i += 2) {
- if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM23_SHOWER)) {
- /* Check EPE Bit (ADCM and Shower only) */
+ if ((manId == 0x01461f) ||
+ (manId == 0x00471f)) {
+ /* Check EPE Bit (ADCM and SHOWER) */
if (((trbBuffer[i + 1] >> 5) & 0x01) == 1) {
fprintf(logFile, "Error > checkStatus: Erase or program error on "
"EndPoint 0x%04x\n", trbBuffer[i] & 0xffff);
uint32_t trbcmd;
int status;
unsigned int counter = 0;
- int success = 0;
int i;
+
+ /* Read HardwareIds from all Boards and validate (all must be the same) */
+ if ((status =
+ trb_register_read(trb_address, HardwareId, trbBuffer,
+ TRB_BUFFER_SIZE)) == -1) {
+ fprintf(logFile, "Error > initTransfer: read HardwareIds TRBNet %s\n",
+ trb_strerror(trb_errno));
+ return -1;
+ }
- /* Read ManId */
+ flashType = FLASH_INVALID;
+ for (i = 0; i < status; i += 2) {
+ FlashType fType = FLASH_INVALID;
+
+ uint16_t hardwareId = (uint16_t)((trbBuffer[i + 1] >> 16) & 0xffff);
+ switch (hardwareId) {
+
+ /* Rich */
+ case 0x3100:
+ fType = FLASH_RICH_ADCM_V1;
+ break;
+ case 0x3200:
+ fType = FLASH_RICH_ADCM_V2;
+ break;
+ case 0x3300:
+ fType = FLASH_RICH_ADCM_V3;
+ break;
+
+ /* MDC HUB */
+ case 0x1210:
+ fType = FLASH_MDC_HUB_V2_FPGA1234;
+ break;
+ case 0x1250:
+ fType = FLASH_MDC_HUB_V2_FPGA5;
+ break;
+
+ /* MDC OEP */
+ case 0x2200:
+ fType = FLASH_MDC_OEP_V2;
+ break;
+ case 0x2300:
+ fType = FLASH_MDC_OEP_V3;
+ break;
+
+ /* SHOWER */
+ case 0x4210:
+ fType = FLASH_SHOWER_ADDON_V2_FPGA1;
+ break;
+ case 0x4220:
+ fType = FLASH_SHOWER_ADDON_V2_FPGA2;
+ break;
+ case 0x4230:
+ fType = FLASH_SHOWER_ADDON_V2_FPGA3;
+ break;
+
+ /* CTS */
+ case 5100:
+ fType = FLASH_CTS_FPGA1;
+ break;
+ case 5200:
+ fType = FLASH_CTS_FPGA1;
+ break;
+
+ default:
+ /* Error: Unknown FlashType */
+ fprintf(logFile, "Error > initTransfer: "
+ "Unsupported HardwareId 0x%04x on EndPoint 0x%04x\n",
+ hardwareId, trbBuffer[i] & 0xffff);
+ return -1;
+ }
+
+ if (flashType == FLASH_INVALID) {
+ flashType = fType;
+ continue;
+ }
+ if (fType != flashType) {
+ fprintf(logFile, "Error > initTransfer: "
+ "HardwareId 0x%04x differs on EndPoint 0x%04x\n",
+ hardwareId, trbBuffer[i] & 0xffff);
+ return -1;
+ }
+ }
+
+ /* Read ManIds from all Boards and validate (all must be the same as well) */
trbcmd = 0x9f << 24;
if (sendCommand(trb_address, trbcmd, 2) == -1) {
return -1;
if ((status =
trb_register_read(trb_address, BlockRam, trbBuffer,
TRB_BUFFER_SIZE)) == -1) {
- fprintf(logFile, "Error > initTransfer: TRBNet %s\n",
+ fprintf(logFile, "Error > initTransfer: read ManIds TRBNet %s\n",
trb_strerror(trb_errno));
return -1;
}
return -1;
}
- flashType = FLASH_INVALID;
- success = 0;
- for (i = 0; i < status; i += 2) {
- switch ((trbBuffer[i + 1] & 0x00ffffff)) {
- case 0x01461f:
- /* ADCM */
- if ((flashType != FLASH_INVALID) && (flashType != FLASH_ADCM1)) {
- success = -2;
- }
- NUM_PAGES = 8192;
- flashType = FLASH_ADCM1;
- break;
-
- case 0x00471f:
- /* ADCM */
- if ((flashType != FLASH_INVALID) && (flashType != FLASH_ADCM23_SHOWER)) {
- success = -2;
- }
- NUM_PAGES = 16384;
- flashType = FLASH_ADCM23_SHOWER;
- break;
-
- case 0x1520c2:
- /* MDC */
- if ((flashType != FLASH_INVALID) && (flashType != FLASH_MDC)) {
- success = -2;
- }
- NUM_PAGES = 8192;
- flashType = FLASH_MDC;
- break;
-
- default:
- flashType = FLASH_INVALID;
- success = -1;
- break;
- }
-
- if (success == -2) {
- fprintf(logFile, "Error > initTransfer: "
- "Incompatible ManId(s) 0x%04x on EndPoint 0x%04x\n",
- trbBuffer[i + 1], trbBuffer[i] & 0xffff);
- return -1;
- }
+ manId = 0;
+ counter = 0;
+ for (i = 0; i < status; i += 2,counter++) {
+ uint32_t tmpManId = (trbBuffer[i + 1] & 0x00ffffff);
- if (flashType == FLASH_INVALID) {
+ if (!((tmpManId == 0x01461f) ||
+ (tmpManId == 0x00471f) ||
+ (tmpManId == 0x1520c2))) {
fprintf(logFile, "Error > initTransfer: "
"Unsupported ManId(s) 0x%04x on EndPoint 0x%04x\n",
- trbBuffer[i + 1], trbBuffer[i] & 0xffff);
+ tmpManId, trbBuffer[i] & 0xffff);
return -1;
}
+ if (manId == 0) {
+ manId = tmpManId;
+ continue;
+ }
+ if (tmpManId != manId) {
+ fprintf(logFile, "Error > initTransfer: ManId 0x%04x differs"
+ "on EndPoint 0x%04x\n",
+ manId, trbBuffer[i] & 0xffff);
+ return -1;
+ }
+ }
+
+ /* Set NUM_PAGES */
+ switch (manId) {
+
+ case 0x01461f:
+ NUM_PAGES = 8192;
+ break;
+
+ case 0x00471f:
+ NUM_PAGES = 16384;
+ break;
- counter++;
+ case 0x1520c2:
+ NUM_PAGES = 8192;
+ break;
+
+ default:
+ abort();
}
+
NUM_BLOCKS = (NUM_PAGES * PAGE_SIZE) / BLOCK_SIZE;
/* Buffer holding the entire rom-image */
int bytesWritten = size;
int tmp;
- if ((mode != PMODE_VERIFY) && (force == 0)) {
+ if ((mode != PMODE_VERIFY) && (yesToAll == 0)) {
/* Be nice and ask before start flashing the roms */
char c;
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (mdcFlashSelect == 0) {
fprintf(stdout, "You decided to reprogram the FlashRom(s) #0 of "
- "MDC, the so called 'GoldenImage'. Do you really know what "
- "you're about to do [N,y]: ");
- } else {
- fprintf(stdout, "You decided to reprogram the FlashRom(s) #1 of "
- "MDC, are you sure [N,y]: ");
- }
+ "MDC_OEP, the so called 'GoldenImage'. "
+ "Do you really know what you're about to do [N,y]: ");
+ }
} else {
fprintf(stdout, "You decided to reprogram the FlashRom(s) of "
- "RICH, are you sure [N,y]: ");
+ "%s, are you sure [N,y]: ", FlashTypeStr[flashType]);
}
c = getc(stdin);
errorCtr = 0;
- if ((flashType == FLASH_MDC) && (mode != PMODE_VERIFY)) {
+ if ((mode != PMODE_VERIFY) && (manId == 0x1520c2)) {
/* Unprotect all Sectors */
if (writeStatusRegister(trb_address, 0) == -1) {
fprintf(stderr,
return -1;
}
}
-
-
+
for (block = 0; (block < NUM_BLOCKS); block++) {
int error = 0;
int writeInfoPage = (block == NUM_BLOCKS - 1) && (mode == PMODE_PROGRAM)
if ((mode != PMODE_VERIFY) &&
((bytesWritten > 0) || (writeInfoPage == 1))) {
- if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM23_SHOWER)) {
+ if ((manId == 0x01461f) ||
+ (manId == 0x00471f)) {
/* Enable writing */
if (sendCommand(trb_address, 0x06 << 24, 0) == -1) {
fprintf(stderr, "\nError > program: write enable, aborting\n");
return -1;
}
}
-
- if ((flashType == FLASH_ADCM1) || (flashType == FLASH_ADCM23_SHOWER)) {
+ if ((manId == 0x01461f) ||
+ (manId == 0x00471f)) {
/* Enable writing */
if (sendCommand(trb_address, 0x06 << 24, 0x00) == -1) {
fprintf(stderr, "\nError > program: write enable, aborting\n");
}
}
- if ((mode != PMODE_VERIFY) && (flashType == FLASH_MDC)) {
+ if ((mode != PMODE_VERIFY) && (manId == 0x1520c2)) {
/* Protect all Sectors i.e. write 0x3c to statusRegister */
if (writeStatusRegister(trb_address, 0x00) == -1) {
fprintf(stderr, "\nError > program: protect all sectors, aborting\n");
static int prepareImageBuffer()
{
- char strId[4][32] = {"", ""};
- unsigned int numIds = 0;
+ char* strId = "INVALID";
int found;
unsigned int end;
unsigned int i;
- unsigned int j;
/* Verify imageFile Id */
switch (flashType) {
- case FLASH_ADCM1:
- strncpy(strId[0], "edif_adcmv1", 32);
- numIds = 1;
+
+ case FLASH_RICH_ADCM_V1:
+ strId = "edif_adcmv1";
break;
- case FLASH_ADCM23_SHOWER:
- strncpy(strId[0], "edif_adcmv2", 32);
- strncpy(strId[1], "edif_adcmv3", 32);
- strncpy(strId[2], "shower", 32);
- strncpy(strId[3], "mdchub", 32);
- numIds = 4;
+ case FLASH_RICH_ADCM_V2:
+ strId = "edif_adcmv2";
break;
- case FLASH_MDC:
- strncpy(strId[0], "mdc_oepb", 32);
- numIds = 1;
+ case FLASH_RICH_ADCM_V3:
+ strId = "edif_adcmv3";
+ break;
+
+ case FLASH_MDC_HUB_V2_FPGA1234:
+ strId = "mdchub_fpga1234";
+ break;
+ case FLASH_MDC_HUB_V2_FPGA5:
+ strId = "mdchub_fpga5";
+ break;
+
+ case FLASH_MDC_OEP_V2:
+ case FLASH_MDC_OEP_V3:
+ strId = "mdc_oepb";
+ break;
+
+ case FLASH_SHOWER_ADDON_V2_FPGA1:
+ strId = "shower_fpga1";
+ break;
+ case FLASH_SHOWER_ADDON_V2_FPGA2:
+ strId = "shower_fpga2";
+ break;
+ case FLASH_SHOWER_ADDON_V2_FPGA3:
+ strId = "shower_fpga3";
+ break;
+
+ case FLASH_CTS_FPGA1:
+ strId = "cts_fpga1";
+ case FLASH_CTS_FPGA2:
+ strId = "cts_fpga2";
break;
default:
/* Verify imageFile Id */
found = 0;
- for (j = 0; j < numIds; j++) {
- for (i = 0; i < 2 * PAGE_SIZE; i++) {
- if (memcmp(imageBuffer + i, strId[j], strlen(strId[j])) == 0) {
- found = 1;
- j = numIds;
- break;
- }
+ for (i = 0; i < 2 * PAGE_SIZE; i++) {
+ if (memcmp(imageBuffer + i, strId, strlen(strId)) == 0) {
+ found = 1;
+ break;
}
}
- if (found == 0) {
- fprintf(logFile, "Error > prepareImageBuffer: invalid Firmware-Id\n");
+ if ((skipFirmwareIdCheck == 0) && (found == 0)) {
+ fprintf(logFile, "Error > prepareImageBuffer: "
+ "invalid Firmware-Id of Image-File, should be: %s\n", strId);
return -1;
}
void usage(const char *progName)
{
- printf("Usage: %s [-s str] [-g] [-y] [-h] [-V] <COMMAND>\n",
+ printf("Usage: %s [-s str] [-g] [-y] [-f] [-h] [-V] <COMMAND>\n",
progName);
printf("Options:\n");
printf(" -s set user-string of info page (default: empty string)\n");
printf(" -g select 'FlashRom #0 (the 'Golden Image') "
"(MDC only, default = no)\n");
- printf(" -y assume yes to all questions which would be asked\n");
+ printf(" -y assume yes to all questions which might will be asked\n");
+ printf(" -f do not validate FirmwareId of ImageFile (DON'T USE, for "
+ "EXPERTS ONLY)\n");
+ /* printf(" -F do not crosscheck HardwareIDs of Endpoints "
+ "(DON'T USE, for EXPERTS ONLY)\n"); */
printf(" -h give this help\n");
printf(" -V Version number\n");
printf("\nCommands:\n");
printf(" program <trbaddress> <bit-file> -> "
"program bit-file to flash-memory\n");
printf(" verify <trbaddress> <bit-file> -> "
- "compare bit-file to flash-memory\n");
+ "compare bit-file with flash-memory\n");
printf(" backup <trbaddress> <raw-file> -> "
"write entire flash-memory to raw-file\n");
printf(" restore <trbaddress> <raw-file> -> "
trb_debug = 0;
logFile = stderr;
mdcFlashSelect = 1;
- force = 0;
+ yesToAll = 0;
+ skipFirmwareIdCheck = 0;
+ skipHwIdCheck = 0;
/* Parse Arguments */
- while ((i = getopt(argc, argv, "+hd:s:gyV")) != -1) {
+ while ((i = getopt(argc, argv, "+hd:s:gyVf")) != -1) {
switch (i) {
case '?':
usage(basename(argv[0]));
trb_debug = strtoul(optarg, NULL, 0);
break;
case 'y':
- force = 1;
+ yesToAll = 1;
+ break;
+ case 'f':
+ skipFirmwareIdCheck = 1;
+ break;
+ case 'F':
+ skipHwIdCheck = 2;
break;
case 'V':
printf("%s %s, using libtrbnet %s\n",
/* Check for correct ManId */
if (initTransfer(trb_address) == -1) {
- fprintf(stderr, "Invalid ManId(s), aborting\n");
+ fprintf(stderr, "InitTransfer failed, aborting\n");
exit(EXIT_FAILURE);
}
createInfoPage(imageFileName, userInfoStr);
/* In case of MDC: select FlashRom */
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
exit(EXIT_FAILURE);
}
/* Check for correct ManId */
if (initTransfer(trb_address) == -1) {
- fprintf(stderr, "Invalid ManId(s), aborting\n");
+ fprintf(stderr, "InitTransfer failed, aborting\n");
exit(EXIT_FAILURE);
}
}
/* In case of MDC: select FlashRom */
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
exit(EXIT_FAILURE);
}
}
/* In case of MDC: select FlashRom */
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
exit(EXIT_FAILURE);
}
}
if (initTransfer(trb_address) == -1) {
+ fprintf(stderr, "InitTransfer failed, aborting\n");
exit(EXIT_FAILURE);
}
/* Check for correct ManId */
if (initTransfer(trb_address) == -1) {
- fprintf(stderr, "Invalid ManId(s), aborting\n");
+ fprintf(stderr, "InitTransfer failed, aborting\n");
exit(EXIT_FAILURE);
}
/* Check ImageBuffer ??? */
/* In case of MDC: select FlashRom */
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
exit(EXIT_FAILURE);
}
/* Check for correct ManId */
if (initTransfer(trb_address) == -1) {
- fprintf(stderr, "Invalid ManId(s), aborting\n");
+ fprintf(stderr, "InitTransfer failed, aborting\n");
exit(EXIT_FAILURE);
}
/* In case of MDC: select FlashRom */
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
exit(EXIT_FAILURE);
}
/* Check for correct ManId */
if (initTransfer(trb_address) == -1) {
- fprintf(stderr, "Invalid ManId(s), aborting\n");
+ fprintf(stderr, "InitTransfer failed, aborting\n");
exit(EXIT_FAILURE);
}
/* In case of MDC: select FlashRom */
- if (flashType == FLASH_MDC) {
+ if ((flashType == FLASH_MDC_OEP_V2) ||
+ (flashType == FLASH_MDC_OEP_V3)) {
if (selectMdcFlashRom(trb_address, mdcFlashSelect) == -1) {
exit(EXIT_FAILURE);
}