diff --git a/slsDetectorServers/slsDetectorServer/include/programFpgaBlackfin.h b/slsDetectorServers/slsDetectorServer/include/programFpgaBlackfin.h index 465a4b467..0fff822d2 100644 --- a/slsDetectorServers/slsDetectorServer/include/programFpgaBlackfin.h +++ b/slsDetectorServers/slsDetectorServer/include/programFpgaBlackfin.h @@ -11,6 +11,7 @@ void FPGAdontTouchFlash(); void FPGATouchFlash(); void resetFPGA(); +int deleteOldFile(char *mess); /** * deletes old file * verify memory available to copy diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index e59b08801..56db264d9 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -7,6 +7,8 @@ #include #include // readlink +#define FLASH_CONVERTED_NAME "test.rawbin" + int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax, int inputValue, int *outputValue) { LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n", @@ -245,6 +247,14 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname, return FAIL; } + FILE *flashfp = fopen(FLASH_CONVERTED_NAME, "w"); + if (flashfp == NULL) { + sprintf(mess, "Unable to open %s in write mode to write checksum\n", + FLASH_CONVERTED_NAME); + LOG(logERROR, (mess)); + return FAIL; + } + MD5_CTX c; if (!MD5_Init(&c)) { fclose(fp); @@ -281,6 +291,9 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname, LOG(logERROR, (mess)); return FAIL; } + if (fwrite((void *)buf, sizeof(char), bytes, flashfp) != bytes) { + LOG(logERROR, ("Could not write to flash fp file\n")); + } // read only until a particular size (drive) if (fsize != 0 && totalBytesRead >= fsize) { LOG(logINFOBLUE, ("\tReached %lu bytes. Not reading more\n", totalBytesRead)); @@ -302,6 +315,7 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname, }*/ LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead)); fclose(fp); + fclose(flashfp); return verifyChecksum(mess, clientChecksum, &c); } diff --git a/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c b/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c index 20c3e366b..c27bc8ba1 100644 --- a/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c @@ -66,21 +66,25 @@ void resetFPGA() { usleep(CTRL_SRVR_INIT_TIME_US); } +int deleteOldFile(char *mess) { + char cmd[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + sprintf(cmd, "rm -fr %s", TEMP_PROG_FILE_NAME); + if (FAIL == executeCommand(cmd, retvals, logDEBUG1)) { + strcpy(mess, + "Could not program fpga. (could not delete old file: "); + strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1); + strcat(mess, "\n"); + LOG(logERROR, (mess)); + return FAIL; + } + return OK; +} + int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess) { - // delete old /var/tmp/file - { - char cmd[MAX_STR_LENGTH] = {0}; - char retvals[MAX_STR_LENGTH] = {0}; - sprintf(cmd, "rm -fr %s", TEMP_PROG_FILE_NAME); - if (FAIL == executeCommand(cmd, retvals, logDEBUG1)) { - strcpy(mess, - "Could not program fpga. (could not delete old file: "); - strncat(mess, retvals, sizeof(mess) - strlen(mess) - 1); - strcat(mess, "\n"); - LOG(logERROR, (mess)); - return FAIL; - } + if (deleteOldFile(mess) == FAIL) { + return FAIL; } // check available memory to copy program @@ -131,6 +135,10 @@ int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess) { return FAIL; } + if (deleteOldFile(mess) == FAIL) { + return FAIL; + } + if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) == FAIL) { return FAIL;