mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
changes for nios similar to bfin
This commit is contained in:
@ -7,7 +7,9 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h> // readlink
|
||||
|
||||
#ifdef JUNGFRAUD
|
||||
#define FLASH_CONVERTED_NAME "/var/tmp/tests.rawbin"
|
||||
#endif
|
||||
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||
int outputMax, int inputValue, int *outputValue) {
|
||||
@ -337,6 +339,7 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||
return verifyChecksum(mess, clientChecksum, &c, "flash");
|
||||
}
|
||||
*/
|
||||
#ifdef JUNGFRAUD
|
||||
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||
ssize_t fsize) {
|
||||
LOG(logINFO, ("\tVerifying FlashChecksum...\n"));
|
||||
@ -364,7 +367,6 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
const int readUnitSize = 128;
|
||||
int character = fgetc(fp);
|
||||
int oldProgress = 0;
|
||||
ssize_t totalBytesRead = 1;
|
||||
@ -398,9 +400,72 @@ 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, "flash");
|
||||
int ret = verifyChecksum(mess, clientChecksum, &c, "flash");
|
||||
if (ret == OK) {
|
||||
LOG(logINFO, ("Checksum in Flash verified\n"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
||||
ssize_t fsize) {
|
||||
LOG(logINFO, ("\tVerifying FlashChecksum...\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;
|
||||
}
|
||||
const int readUnitSize = 128;
|
||||
char buf[readUnitSize];
|
||||
ssize_t bytes = fread(buf, 1, readUnitSize, fp);
|
||||
ssize_t totalBytesRead = bytes;
|
||||
int oldProgress = 0;
|
||||
|
||||
while (bytes > 0) {
|
||||
int progress = (int)(((double)(totalBytesRead) / fsize) * 100);
|
||||
if (oldProgress != progress) {
|
||||
printf("%d%%\r", progress);
|
||||
fflush(stdout);
|
||||
oldProgress = progress;
|
||||
}
|
||||
|
||||
if (!MD5_Update(&c, buf, bytes)) {
|
||||
fclose(fp);
|
||||
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
||||
LOG(logERROR, (mess));
|
||||
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);
|
||||
totalBytesRead += bytes;
|
||||
}
|
||||
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
||||
fclose(fp);
|
||||
int ret = verifyChecksum(mess, clientChecksum, &c, "flash");
|
||||
if (ret == OK) {
|
||||
LOG(logINFO, ("Checksum in Flash verified\n"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c, char *msg) {
|
||||
unsigned char out[MD5_DIGEST_LENGTH];
|
||||
if (!MD5_Final(out, c)) {
|
||||
|
Reference in New Issue
Block a user