mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 15:00:02 +02:00
wip done with md5
This commit is contained in:
parent
b7f694142a
commit
664c2ca80f
@ -18,12 +18,14 @@ add_executable(ctbDetectorServer_virtual
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../slsDetectorServer/src/loadPattern.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsDetectorSoftware/include/sls/
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
target_include_directories(ctbDetectorServer_virtual
|
||||
|
@ -6,11 +6,13 @@ set(src
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
../slsDetectorServer/src/common.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
add_executable(eigerDetectorServerMaster_virtual
|
||||
|
@ -12,11 +12,13 @@ add_executable(gotthard2DetectorServer_virtual
|
||||
../slsDetectorServer/src/ASIC_Driver.c
|
||||
../slsDetectorServer/src/programFpgaNios.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
target_include_directories(gotthard2DetectorServer_virtual
|
||||
|
@ -11,11 +11,13 @@ add_executable(gotthardDetectorServer_virtual
|
||||
../slsDetectorServer/src/commonServerFunctions.c
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
target_include_directories(gotthardDetectorServer_virtual
|
||||
|
@ -13,12 +13,14 @@ add_executable(jungfrauDetectorServer_virtual
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
target_include_directories(jungfrauDetectorServer_virtual
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
target_compile_definitions(jungfrauDetectorServer_virtual
|
||||
|
@ -15,12 +15,14 @@ add_executable(moenchDetectorServer_virtual
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/loadPattern.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsDetectorSoftware/include/sls/
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
target_include_directories(moenchDetectorServer_virtual
|
||||
|
@ -13,12 +13,14 @@ add_executable(mythen3DetectorServer_virtual
|
||||
../slsDetectorServer/src/programFpgaNios.c
|
||||
../slsDetectorServer/src/loadPattern.c
|
||||
../slsDetectorServer/src/sharedMemory.c
|
||||
../../slsSupportLib/opensslMd5/md5.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
../slsDetectorServer/include
|
||||
../../slsSupportLib/include
|
||||
../../slsDetectorSoftware/include/sls/
|
||||
../../slsSupportLib/opensslMd5
|
||||
)
|
||||
|
||||
target_include_directories(mythen3DetectorServer_virtual
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "md5.h"
|
||||
#include <stdint.h> // int64_t
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
@ -30,4 +31,8 @@ void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
|
||||
char *modename, enum numberMode nummode);
|
||||
|
||||
int getModuleIdInFile(int *ret, char *mess, char *fileName);
|
||||
int setModuleIdInFile(char *mess, int arg, char *fileName);
|
||||
int setModuleIdInFile(char *mess, int arg, char *fileName);
|
||||
int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
||||
ssize_t bytes);
|
||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname);
|
||||
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c);
|
@ -10,30 +10,8 @@ void NotifyServerStartSuccess();
|
||||
|
||||
/** reset fpga and controller(only implemented for >= v1.1 boards) */
|
||||
void rebootControllerAndFPGA();
|
||||
|
||||
/** finds the right mtd drive
|
||||
* @param mess error message
|
||||
* @returns ok or fail
|
||||
*/
|
||||
int findFlash(char *mess);
|
||||
|
||||
/** erase flash */
|
||||
void eraseFlash();
|
||||
|
||||
/** erase and write flash
|
||||
* @param mess error message
|
||||
* @param fpgasrc program source
|
||||
* @param fsize file size
|
||||
* @returns ok or fail
|
||||
*/
|
||||
int eraseAndWriteToFlash(char *mess, char *fpgasrc, uint64_t fsize);
|
||||
|
||||
/**
|
||||
* Write FPGA Program to flash
|
||||
* @param mess error message
|
||||
* @param fpgasrc source program
|
||||
* @param fsize size of program
|
||||
* @param filefp pointer to flash
|
||||
* @return ok or fail
|
||||
*/
|
||||
int eraseAndWriteToFlash(char *mess, char *checksum, char *fpgasrc,
|
||||
uint64_t fsize);
|
||||
int writeFPGAProgram(char *mess, char *fpgasrc, uint64_t fsize, FILE *filefp);
|
||||
|
@ -178,3 +178,81 @@ int setModuleIdInFile(char *mess, int arg, char *fileName) {
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
||||
ssize_t bytes) {
|
||||
MD5_CTX c;
|
||||
if (!MD5_Init(&c)) {
|
||||
strcpy(mess, "Unable to calculate checksum (MD5_Init)\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
if (!MD5_Update(&c, buffer, bytes)) {
|
||||
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return verifyChecksum(mess, clientChecksum, &c);
|
||||
}
|
||||
|
||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
||||
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)) {
|
||||
strcpy(mess, "Unable to calculate checksum (MD5_Init)\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
char buf[512];
|
||||
ssize_t bytes = fread(buf, 1, 512, fp);
|
||||
while (bytes > 0) {
|
||||
if (!MD5_Update(&c, buf, bytes)) {
|
||||
strcpy(mess, "Unable to calculate checksum (MD5_Update)\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
bytes = fread(buf, 1, 512, fp);
|
||||
}
|
||||
fclose(fp);
|
||||
return verifyChecksum(mess, clientChecksum, &c);
|
||||
}
|
||||
|
||||
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c) {
|
||||
unsigned char out[MD5_DIGEST_LENGTH];
|
||||
if (!MD5_Final(out, c)) {
|
||||
strcpy(mess, "Unable to calculate checksum (MD5_Final)\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
char checksum[512];
|
||||
memset(checksum, 0, 512);
|
||||
for (int i = 0; i != MD5_DIGEST_LENGTH; ++i) {
|
||||
char part[16];
|
||||
memset(byteparts, 0, 16);
|
||||
sprintf(part, "%02x", out[i]);
|
||||
strcat(checksum, part);
|
||||
}
|
||||
|
||||
LOG(logDEBUG1,
|
||||
("\nC checksum: %s\nS checksum: %s\n", clientChecksum, checksum));
|
||||
|
||||
// compare checksum
|
||||
if (strcmp(clientChecksum, checksum)) {
|
||||
sprintf(mess,
|
||||
"Checksum of copied fpga program does not match. Client "
|
||||
"checksum:%s, copied checksum:%s\n",
|
||||
clientChecksum, checksum);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("\tChecksum verified from copied program\n"));
|
||||
return OK;
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#include "programFpgaBlackfin.h"
|
||||
#include "clogger.h"
|
||||
#include "common.h"
|
||||
#include "sls/ansi.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
@ -193,32 +194,5 @@ int writeFPGAProgram(FILE *fd, char *src, uint64_t fsize, char* msg, char* mess)
|
||||
}
|
||||
|
||||
int verifyCheckSumofProgram(char* clientChecksum, char* mess) {
|
||||
LOG(logINFOBLUE, ("\tVerifying Checksum\n"));
|
||||
|
||||
// get checksum from copied file
|
||||
char cmd[MAX_STR_LENGTH] = {0};
|
||||
memset(cmd, 0, MAX_STR_LENGTH);
|
||||
sprintf(cmd, "md5sum %s", TEMP_PROG_FILE_NAME);
|
||||
char retvals[MAX_STR_LENGTH] = {0};
|
||||
memset(retvals, 0, MAX_STR_LENGTH);
|
||||
if (FAIL == executeCommand(cmd, retvals, logDEBUG1)) {
|
||||
strcpy(mess, retvals);
|
||||
// LOG(logERROR, (mess)); already printed in executecommand
|
||||
return FAIL;
|
||||
}
|
||||
char checksum[MAX_STR_LENGTH];
|
||||
memset(checksum, 0, sizeof(checksum));
|
||||
if (sscanf(retvals, "%s", checksum) != 1) {
|
||||
sprintf(mess, "Could not get checksum of fpga program copied over");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
// compare checksum
|
||||
if (strcmp(clientChecksum, checksum)) {
|
||||
sprintf(mess, "Checksum of copied fpga program does not match. Client checksum:%s, copied checksum:%s\n", clientChecksum, checksum);
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO, ("\tChecksum verified from copied program\n"));
|
||||
return OK;
|
||||
return verifyChecksumFromFile(mess, clientChecksum, TEMP_PROG_FILE_NAME);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#include "programFpgaNios.h"
|
||||
#include "clogger.h"
|
||||
#include "common.h"
|
||||
#include "sls/ansi.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
|
||||
@ -74,10 +75,16 @@ void eraseFlash() {
|
||||
LOG(logINFO, ("\tFlash erased\n"));
|
||||
}
|
||||
|
||||
int eraseAndWriteToFlash(char *mess, char *fpgasrc, uint64_t fsize) {
|
||||
int eraseAndWriteToFlash(char *mess, char *checksum, char *fpgasrc,
|
||||
uint64_t fsize) {
|
||||
if (findFlash(mess) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
if (verifyChecksumFromBuffer(mess, checksum, fpgasrc, fsize) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
eraseFlash();
|
||||
|
||||
// open file pointer to flash
|
||||
|
@ -3680,13 +3680,20 @@ int program_fpga(int file_des) {
|
||||
|
||||
LOG(logINFOBLUE, ("Programming FPGA...\n"));
|
||||
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
uint64_t filesize = 0;
|
||||
// filesize
|
||||
uint64_t filesize = 0;
|
||||
if (receiveData(file_des, &filesize, sizeof(filesize), INT64) < 0)
|
||||
return printSocketReadError();
|
||||
LOG(logDEBUG1, ("Total program size is: %llx\n",
|
||||
(long long unsigned int)filesize));
|
||||
LOG(logDEBUG1, ("Program size is: %lld\n", (long long int)filesize));
|
||||
|
||||
// checksum
|
||||
char checksum[MAX_STR_LENGTH];
|
||||
memset(checksum, 0, MAX_STR_LENGTH);
|
||||
if (receiveData(file_des, checksum, MAX_STR_LENGTH, OTHER) < 0)
|
||||
return printSocketReadError();
|
||||
LOG(logDEBUG1, ("checksum is: %s\n\n", checksum));
|
||||
|
||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||
if (filesize > NIOS_MAX_APP_IMAGE_SIZE) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,
|
||||
@ -3718,20 +3725,6 @@ int program_fpga(int file_des) {
|
||||
|
||||
#else // jungfrau, ctb, moench
|
||||
|
||||
// filesize
|
||||
uint64_t filesize = 0;
|
||||
if (receiveData(file_des, &filesize, sizeof(filesize), INT64) < 0)
|
||||
return printSocketReadError();
|
||||
LOG(logDEBUG1,
|
||||
("Program size is: %lld\n", (long long unsigned int)filesize));
|
||||
|
||||
// checksum
|
||||
char checksum[MAX_STR_LENGTH];
|
||||
memset(checksum, 0, MAX_STR_LENGTH);
|
||||
if (receiveData(file_des, checksum, MAX_STR_LENGTH, OTHER) < 0)
|
||||
return printSocketReadError();
|
||||
LOG(logDEBUG1, ("checksum is: %s\n\n", checksum));
|
||||
|
||||
// open file and allocate memory for part program
|
||||
FILE *fd = NULL;
|
||||
ret = startCopyingFPGAProgram(&fd, filesize, mess);
|
||||
|
@ -3424,16 +3424,17 @@ std::string Module::calculateChecksum(char *buffer, ssize_t bytes) {
|
||||
}
|
||||
|
||||
void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
||||
uint64_t filesize = buffer.size();
|
||||
std::string checksum = calculateChecksum(buffer.data(), filesize);
|
||||
LOG(logDEBUG1) << "Checksum:" << checksum;
|
||||
|
||||
// send program from memory to detector
|
||||
LOG(logINFO) << "Sending programming binary (from pof) to module "
|
||||
<< moduleId << " (" << shm()->hostname << ")";
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_PROGRAM_FPGA);
|
||||
uint64_t filesize = buffer.size();
|
||||
client.Send(filesize);
|
||||
|
||||
// checksum
|
||||
std::string checksum = calculateChecksum(buffer.data(), filesize);
|
||||
LOG(logDEBUG1) << "Checksum:" << checksum;
|
||||
char cChecksum[MAX_STR_LENGTH];
|
||||
memset(cChecksum, 0, MAX_STR_LENGTH);
|
||||
strcpy(cChecksum, checksum.c_str());
|
||||
@ -3537,6 +3538,15 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
|
||||
client.Send(F_PROGRAM_FPGA);
|
||||
uint64_t filesize = buffer.size();
|
||||
client.Send(filesize);
|
||||
|
||||
// checksum
|
||||
std::string checksum = calculateChecksum(buffer.data(), filesize);
|
||||
LOG(logDEBUG1) << "Checksum:" << checksum;
|
||||
char cChecksum[MAX_STR_LENGTH];
|
||||
memset(cChecksum, 0, MAX_STR_LENGTH);
|
||||
strcpy(cChecksum, checksum.c_str());
|
||||
client.Send(cChecksum);
|
||||
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
std::ostringstream os;
|
||||
os << "Detector " << moduleId << " (" << shm()->hostname << ")"
|
||||
|
Loading…
x
Reference in New Issue
Block a user