This commit is contained in:
2021-09-10 16:20:14 +02:00
parent 32317510ad
commit 11864e5de4
3 changed files with 36 additions and 13 deletions

View File

@ -11,6 +11,7 @@ void FPGAdontTouchFlash();
void FPGATouchFlash(); void FPGATouchFlash();
void resetFPGA(); void resetFPGA();
int deleteOldFile(char *mess);
/** /**
* deletes old file * deletes old file
* verify memory available to copy * verify memory available to copy

View File

@ -7,6 +7,8 @@
#include <string.h> #include <string.h>
#include <unistd.h> // readlink #include <unistd.h> // readlink
#define FLASH_CONVERTED_NAME "test.rawbin"
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
int outputMax, int inputValue, int *outputValue) { int outputMax, int inputValue, int *outputValue) {
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n", 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; 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; MD5_CTX c;
if (!MD5_Init(&c)) { if (!MD5_Init(&c)) {
fclose(fp); fclose(fp);
@ -281,6 +291,9 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; 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) // read only until a particular size (drive)
if (fsize != 0 && totalBytesRead >= fsize) { if (fsize != 0 && totalBytesRead >= fsize) {
LOG(logINFOBLUE, ("\tReached %lu bytes. Not reading more\n", totalBytesRead)); 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)); LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
fclose(fp); fclose(fp);
fclose(flashfp);
return verifyChecksum(mess, clientChecksum, &c); return verifyChecksum(mess, clientChecksum, &c);
} }

View File

@ -66,10 +66,7 @@ void resetFPGA() {
usleep(CTRL_SRVR_INIT_TIME_US); usleep(CTRL_SRVR_INIT_TIME_US);
} }
int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess) { int deleteOldFile(char *mess) {
// delete old /var/tmp/file
{
char cmd[MAX_STR_LENGTH] = {0}; char cmd[MAX_STR_LENGTH] = {0};
char retvals[MAX_STR_LENGTH] = {0}; char retvals[MAX_STR_LENGTH] = {0};
sprintf(cmd, "rm -fr %s", TEMP_PROG_FILE_NAME); sprintf(cmd, "rm -fr %s", TEMP_PROG_FILE_NAME);
@ -81,6 +78,13 @@ int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
return OK;
}
int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess) {
if (deleteOldFile(mess) == FAIL) {
return FAIL;
} }
// check available memory to copy program // check available memory to copy program
@ -131,6 +135,10 @@ int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess) {
return FAIL; return FAIL;
} }
if (deleteOldFile(mess) == FAIL) {
return FAIL;
}
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) == if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) ==
FAIL) { FAIL) {
return FAIL; return FAIL;