binaries in. fixed

This commit is contained in:
maliakal_d 2022-03-24 12:33:19 +01:00
parent 5fe10c19a1
commit 1e564a1b33
11 changed files with 28 additions and 20 deletions

View File

@ -29,9 +29,9 @@ int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
ssize_t fsize, int forceDeleteNormalFile); ssize_t fsize, int forceDeleteNormalFile);
int getDrive(char *mess, enum PROGRAM_INDEX index); int getDrive(char *mess, enum PROGRAM_INDEX index);
/** Notify fpga not to touch flash, open src and flash drive to write */ /** Notify fpga not to touch flash, open src and flash drive to write */
int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd, int openFileForFlash(char *mess, enum PROGRAM_INDEX index, FILE **flashfd, FILE **srcfd,
int forceDeleteNormalFile); int forceDeleteNormalFile);
int checkNormalFile(char *mess, int forceDeleteNormalFile); int checkNormalFile(char *mess, enum PROGRAM_INDEX index, int forceDeleteNormalFile);
int eraseFlash(char *mess); int eraseFlash(char *mess);
/* write from tmp file to flash */ /* write from tmp file to flash */
int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, FILE *srcfd); int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, FILE *srcfd);

View File

@ -335,7 +335,7 @@ int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
FILE *flashfd = NULL; FILE *flashfd = NULL;
FILE *srcfd = NULL; FILE *srcfd = NULL;
if (openFileForFlash(mess, &flashfd, &srcfd, forceDeleteNormalFile) == if (openFileForFlash(mess, index, &flashfd, &srcfd, forceDeleteNormalFile) ==
FAIL) { FAIL) {
return FAIL; return FAIL;
} }
@ -440,7 +440,7 @@ int getDrive(char *mess, enum PROGRAM_INDEX index) {
return OK; return OK;
} }
int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd, int openFileForFlash(char *mess, enum PROGRAM_INDEX index, FILE **flashfd, FILE **srcfd,
int forceDeleteNormalFile) { int forceDeleteNormalFile) {
// open src file // open src file
*srcfd = fopen(TEMP_PROG_FILE_NAME, "r"); *srcfd = fopen(TEMP_PROG_FILE_NAME, "r");
@ -454,8 +454,10 @@ int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd,
} }
LOG(logDEBUG1, ("Temp file ready for reading\n")); LOG(logDEBUG1, ("Temp file ready for reading\n"));
if (checkNormalFile(mess, forceDeleteNormalFile) == FAIL) if (checkNormalFile(mess, index, forceDeleteNormalFile) == FAIL) {
fclose(*srcfd);
return FAIL; return FAIL;
}
// open flash drive for writing // open flash drive for writing
*flashfd = fopen(flashDriveName, "w"); *flashfd = fopen(flashDriveName, "w");
@ -472,7 +474,7 @@ int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd,
return OK; return OK;
} }
int checkNormalFile(char *mess, int forceDeleteNormalFile) { int checkNormalFile(char *mess, enum PROGRAM_INDEX index, int forceDeleteNormalFile) {
#ifndef VIRTUAL #ifndef VIRTUAL
// check if its a normal file or special file // check if its a normal file or special file
struct stat buf; struct stat buf;
@ -484,7 +486,7 @@ int checkNormalFile(char *mess, int forceDeleteNormalFile) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
// non zero = block special file // zero = normal file (not block special file)
if (S_ISBLK(buf.st_mode)) { if (S_ISBLK(buf.st_mode)) {
// kernel memory is not permanent // kernel memory is not permanent
if (index != PROGRAM_FPGA) { if (index != PROGRAM_FPGA) {
@ -496,18 +498,21 @@ int checkNormalFile(char *mess, int forceDeleteNormalFile) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
// fpga memory stays after a reboot, so fix it if user allows
sprintf(mess, // user does not allow to fix it (default)
"Could not %s. The flash drive found is a normal file. To " if (forceDeleteNormalFile == 0) {
"delete this file, create the flash drive and proceed with " sprintf(mess,
"programming, re-run the programming command with parameter " "Could not %s. The flash drive %s found for fpga programming is a normal file. To "
"fix this (by deleting this file, creating the flash drive and proceeding with "
"programming), re-run the programming command 'programfpga' with parameter "
"'--force-delete-normal-file'\n", "'--force-delete-normal-file'\n",
messageType); messageType, flashDriveName);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
// user does not allow (default)
if (!forceDeleteNormalFile) {
return FAIL; return FAIL;
} }
// fpga memory stays after a reboot, user allowed to fix it
LOG(logWARNING, ("Flash drive invalidated (normal file). Fixing it...\n"));
// user allows to fix it, so force delete normal file // user allows to fix it, so force delete normal file
char cmd[MAX_STR_LENGTH] = {0}; char cmd[MAX_STR_LENGTH] = {0};
@ -530,7 +535,7 @@ int checkNormalFile(char *mess, int forceDeleteNormalFile) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
LOG(logINFO, ("\tDeleted Normal File(%s)\n", flashDriveName)); LOG(logINFO, ("\tDeleted Normal File (%s)\n", flashDriveName));
// create special drive // create special drive
if (snprintf(cmd, MAX_STR_LENGTH, "%s %s %s", if (snprintf(cmd, MAX_STR_LENGTH, "%s %s %s",
@ -552,6 +557,8 @@ int checkNormalFile(char *mess, int forceDeleteNormalFile) {
return FAIL; return FAIL;
} }
LOG(logINFO, ("\tSpecial File created (%s)\n", flashDriveName)); LOG(logINFO, ("\tSpecial File created (%s)\n", flashDriveName));
} else {
LOG(logINFO, ("\tValidated flash drive (not a normal file)\n"));
} }
#endif #endif
return OK; return OK;

View File

@ -158,7 +158,7 @@ int openFileForFlash(char *mess, FILE **flashfd) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
// non zero = block special file // zero = normal file (not block special file)
if (S_ISBLK(buf.st_mode)) { if (S_ISBLK(buf.st_mode)) {
// memory is not permanent // memory is not permanent
sprintf(mess, sprintf(mess,
@ -169,6 +169,7 @@ int openFileForFlash(char *mess, FILE **flashfd) {
LOG(logERROR, (mess)); LOG(logERROR, (mess));
return FAIL; return FAIL;
} }
LOG(logINFO, ("\tValidated flash drive (not a normal file)\n"));
#endif #endif
*flashfd = fopen(flashDriveName, "w"); *flashfd = fopen(flashDriveName, "w");

View File

@ -9450,7 +9450,7 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) {
sizeof(forceDeleteNormalFile), INT32) < 0) sizeof(forceDeleteNormalFile), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
LOG(logINFO, LOG(logINFO,
("\tForce Delete Normal File: %d\n", forceDeleteNormalFile)); ("\tForce Delete Normal File flag? %s\n", (forceDeleteNormalFile ? "Y" : "N")));
#endif #endif
// in same folder as current process (will also work for virtual then // in same folder as current process (will also work for virtual then

View File

@ -6,10 +6,10 @@
#define APIRECEIVER 0x211124 #define APIRECEIVER 0x211124
#define APIGUI 0x211124 #define APIGUI 0x211124
#define APIEIGER 0x220324
#define APICTB 0x220324 #define APICTB 0x220324
#define APIGOTTHARD 0x220324 #define APIGOTTHARD 0x220324
#define APIGOTTHARD2 0x220324 #define APIGOTTHARD2 0x220324
#define APIJUNGFRAU 0x220324 #define APIJUNGFRAU 0x220324
#define APIMYTHEN3 0x220324 #define APIMYTHEN3 0x220324
#define APIMOENCH 0x220324 #define APIMOENCH 0x220324
#define APIEIGER 0x220324