mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-07 18:40:42 +02:00
fix for flash
This commit is contained in:
parent
9d30d51da7
commit
b8086dcd70
@ -36,5 +36,7 @@ int setModuleIdInFile(char *mess, int arg, char *fileName);
|
|||||||
int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
||||||
ssize_t bytes);
|
ssize_t bytes);
|
||||||
// fsize is specified only if it is less than intended size (drive)
|
// fsize is specified only if it is less than intended size (drive)
|
||||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname, ssize_t fsize);
|
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname);
|
||||||
|
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||||
|
ssize_t fsize);
|
||||||
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c);
|
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c);
|
@ -196,7 +196,7 @@ int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
|||||||
return verifyChecksum(mess, clientChecksum, &c);
|
return verifyChecksum(mess, clientChecksum, &c);
|
||||||
}
|
}
|
||||||
|
|
||||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname, ssize_t fsize) {
|
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
||||||
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
||||||
|
|
||||||
FILE *fp = fopen(fname, "r");
|
FILE *fp = fopen(fname, "r");
|
||||||
@ -217,7 +217,6 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname, ssize_
|
|||||||
const int readUnitSize = 128;
|
const int readUnitSize = 128;
|
||||||
char buf[readUnitSize];
|
char buf[readUnitSize];
|
||||||
ssize_t bytes = fread(buf, 1, readUnitSize, fp);
|
ssize_t bytes = fread(buf, 1, readUnitSize, fp);
|
||||||
ssize_t totalBytesRead = bytes;
|
|
||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
if (!MD5_Update(&c, buf, bytes)) {
|
if (!MD5_Update(&c, buf, bytes)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -225,26 +224,64 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname, ssize_
|
|||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
// read only until a particular size (drive)
|
|
||||||
/*if (fsize != 0 && totalBytesRead >= fsize) {
|
|
||||||
LOG(logINFOBLUE, ("\tReached %lu bytes. Not reading more\n", totalBytesRead));
|
|
||||||
break;
|
|
||||||
}*/
|
|
||||||
bytes = fread(buf, 1, readUnitSize, fp);
|
bytes = fread(buf, 1, readUnitSize, fp);
|
||||||
totalBytesRead += bytes;
|
|
||||||
}
|
}
|
||||||
// last null character (if size does not match)
|
fclose(fp);
|
||||||
/*if (fsize == totalBytesRead + 1) {
|
return verifyChecksum(mess, clientChecksum, &c);
|
||||||
bytes = 1;
|
}
|
||||||
totalBytesRead += bytes;
|
|
||||||
if (!MD5_Update(&c, buf, bytes)) {
|
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||||
|
ssize_t fsize) {
|
||||||
|
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
||||||
|
|
||||||
|
FILE *fp = fopen(fname, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
sprintf(mess, "Unable to open %s in read mode to get checksum\n",
|
||||||
|
fname);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
MD5_CTX c;
|
||||||
|
if (!MD5_Init(&c)) {
|
||||||
|
fclose(fp);
|
||||||
|
strcpy(mess, "Unable to calculate checksum (MD5_Init)\n");
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG(logINFO, ("\tReading from flash\n"));
|
||||||
|
int oldProgress = 0;
|
||||||
|
ssize_t bytes = 0;
|
||||||
|
while (!feof(fp) && bytes < fsize) {
|
||||||
|
// print progress
|
||||||
|
int progress = (int)(((double)(bytes) / fsize) * 100);
|
||||||
|
if (oldProgress != progress) {
|
||||||
|
printf("%d%%\r", progress);
|
||||||
|
fflush(stdout);
|
||||||
|
oldProgress = progress;
|
||||||
|
}
|
||||||
|
// read source
|
||||||
|
int s = fgetc(fp);
|
||||||
|
if (s < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++bytes;
|
||||||
|
// swap bits
|
||||||
|
int d = 0;
|
||||||
|
for (int i = 0; i < 8; ++i) {
|
||||||
|
d = d | (((s & (1 << i)) >> i) << (7 - i));
|
||||||
|
}
|
||||||
|
// update md5
|
||||||
|
if (!MD5_Update(&c, &d, 1)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", (long int)bytes));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return verifyChecksum(mess, clientChecksum, &c);
|
return verifyChecksum(mess, clientChecksum, &c);
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,8 @@ int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess) {
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verifyChecksumFromFile(mess, clientChecksum, flashDriveName, fsize) == FAIL) {
|
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) ==
|
||||||
|
FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("Checksum in Flash verified\n"));
|
LOG(logINFO, ("Checksum in Flash verified\n"));
|
||||||
|
@ -3795,7 +3795,7 @@ int program_fpga(int file_des) {
|
|||||||
|
|
||||||
// checksum of copied program
|
// checksum of copied program
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
ret = verifyChecksumFromFile(mess, checksum, TEMP_PROG_FILE_NAME, 0);
|
ret = verifyChecksumFromFile(mess, checksum, TEMP_PROG_FILE_NAME);
|
||||||
}
|
}
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
|
@ -1241,7 +1241,7 @@ int DetectorImpl::kbhit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
||||||
/* // validate type of file
|
// validate type of file
|
||||||
bool isPof = false;
|
bool isPof = false;
|
||||||
switch (multi_shm()->multiDetectorType) {
|
switch (multi_shm()->multiDetectorType) {
|
||||||
case JUNGFRAU:
|
case JUNGFRAU:
|
||||||
@ -1353,9 +1353,6 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
throw RuntimeError(
|
throw RuntimeError(
|
||||||
"Could not convert programming file. EOF before end of flash");
|
"Could not convert programming file. EOF before end of flash");
|
||||||
}
|
}
|
||||||
// write 0 to tthe end
|
|
||||||
char c = '\0';
|
|
||||||
write(dst, &c, 1);
|
|
||||||
}
|
}
|
||||||
if (fclose(src) != 0) {
|
if (fclose(src) != 0) {
|
||||||
throw RuntimeError("Program FPGA: Could not close source file");
|
throw RuntimeError("Program FPGA: Could not close source file");
|
||||||
@ -1364,9 +1361,9 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
throw RuntimeError("Program FPGA: Could not close destination file");
|
throw RuntimeError("Program FPGA: Could not close destination file");
|
||||||
}
|
}
|
||||||
LOG(logINFOBLUE) << "File has been converted to " << destfname;
|
LOG(logINFOBLUE) << "File has been converted to " << destfname;
|
||||||
*/
|
|
||||||
// loading dst file to memory
|
// loading dst file to memory
|
||||||
FILE *fp = fopen("/tmp/SLS_DET_MCB.ZpfQln", "r");//
|
FILE *fp = fopen(destfname, "r");
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
throw RuntimeError("Program FPGA: Could not open rawbin file");
|
throw RuntimeError("Program FPGA: Could not open rawbin file");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user