This commit is contained in:
maliakal_d 2021-09-10 13:50:26 +02:00
parent b8086dcd70
commit 5b3e5e8d16
3 changed files with 35 additions and 15 deletions

View File

@ -4,8 +4,7 @@
#include <stdio.h>
#include <sys/types.h>
#define TEMP_PROG_FILE_NAME "/var/tmp/tmp.pof"
#define TEMP_PROG_FILE_NAME "/var/tmp/tmp.rawbin"
void defineGPIOpins();
void FPGAdontTouchFlash();
@ -17,6 +16,7 @@ void resetFPGA();
* verify memory available to copy
* open file to copy
*/
int deleteOldFile(char *mess);
int preparetoCopyFPGAProgram(FILE **fd, uint64_t fsize, char *mess);
int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess);
int getDrive(char *mess);

View File

@ -7,6 +7,8 @@
#include <string.h>
#include <unistd.h> // readlink
#define FLASH_READ_FNAME "/var/tmp/flash.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",
@ -251,6 +253,14 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
return FAIL;
}
FILE *flashfp = fopen(FLASH_READ_FNAME, "w");
if (fp == NULL) {
sprintf(mess, "Unable to open %s in write mode to get from flash\n",
FLASH_READ_FNAME);
LOG(logERROR, (mess));
return FAIL;
}
LOG(logINFO, ("\tReading from flash\n"));
int oldProgress = 0;
ssize_t bytes = 0;
@ -268,6 +278,7 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
break;
}
++bytes;
write(flashfp, &s, 1);
// swap bits
int d = 0;
for (int i = 0; i < 8; ++i) {
@ -283,6 +294,7 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
}
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", (long int)bytes));
fclose(fp);
fclose(flashfp);
return verifyChecksum(mess, clientChecksum, &c);
}

View File

@ -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;