mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-03 11:20:03 +02:00
wip
This commit is contained in:
parent
9c9f2d5c70
commit
20deeb8dcc
@ -45,11 +45,6 @@ int startWritingFPGAprogram(FILE **filefp);
|
|||||||
*/
|
*/
|
||||||
int stopWritingFPGAprogram(FILE *filefp);
|
int stopWritingFPGAprogram(FILE *filefp);
|
||||||
|
|
||||||
/**
|
int startCopyingFPGAProgram(FILE **fd, uint64_t fsize, char *mess);
|
||||||
* Write FPGA Program to flash
|
int writeFPGAProgram(uint64_t fsize, FILE *fd, char *src, char *msg,
|
||||||
* @param fpgasrc source program
|
char *mess);
|
||||||
* @param fsize size of program
|
|
||||||
* @param filefp pointer to flash
|
|
||||||
* @return 0 for success, 1 for fail (cannot write)
|
|
||||||
*/
|
|
||||||
int writeFPGAProgram(char *fpgasrc, uint64_t fsize, FILE *filefp);
|
|
||||||
|
@ -5,14 +5,19 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h> // usleep
|
#include <unistd.h> // usleep
|
||||||
|
#include <sys/sysinfo.h>
|
||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
#define MTDSIZE 10
|
#define MTDSIZE 10
|
||||||
#define MAX_TIME_FPGA_TOUCH_FLASH_US (10 * 1000 * 1000) // 10s
|
#define MAX_TIME_FPGA_TOUCH_FLASH_US (10 * 1000 * 1000) // 10s
|
||||||
|
#define TEMP_PROG_FILE_NAME "/var/tmp/tmp.pof"
|
||||||
|
|
||||||
|
|
||||||
int gpioDefined = 0;
|
int gpioDefined = 0;
|
||||||
char mtdvalue[MTDSIZE] = {0};
|
char mtdvalue[MTDSIZE] = {0};
|
||||||
|
|
||||||
|
extern int executeCommand(char *command, char *result, enum TLogLevel level);
|
||||||
|
|
||||||
void defineGPIOpins() {
|
void defineGPIOpins() {
|
||||||
if (!gpioDefined) {
|
if (!gpioDefined) {
|
||||||
// define the gpio pins
|
// define the gpio pins
|
||||||
@ -70,11 +75,11 @@ int startWritingFPGAprogram(FILE **filefp) {
|
|||||||
"awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
|
"awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
LOG(logERROR, ("popen returned NULL. Need that to get mtd drive.\n"));
|
LOG(logERROR, ("popen returned NULL. Need that to get mtd drive.\n"));
|
||||||
return 1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (fgets(output, sizeof(output), fp) == NULL) {
|
if (fgets(output, sizeof(output), fp) == NULL) {
|
||||||
LOG(logERROR, ("fgets returned NULL. Need that to get mtd drive.\n"));
|
LOG(logERROR, ("fgets returned NULL. Need that to get mtd drive.\n"));
|
||||||
return 1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
memset(mtdvalue, 0, MTDSIZE);
|
memset(mtdvalue, 0, MTDSIZE);
|
||||||
@ -82,7 +87,7 @@ int startWritingFPGAprogram(FILE **filefp) {
|
|||||||
char *pch = strtok(output, ":");
|
char *pch = strtok(output, ":");
|
||||||
if (pch == NULL) {
|
if (pch == NULL) {
|
||||||
LOG(logERROR, ("Could not get mtd value\n"));
|
LOG(logERROR, ("Could not get mtd value\n"));
|
||||||
return 1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
strcat(mtdvalue, pch);
|
strcat(mtdvalue, pch);
|
||||||
LOG(logINFO, ("Flash drive found: %s\n", mtdvalue));
|
LOG(logINFO, ("Flash drive found: %s\n", mtdvalue));
|
||||||
@ -93,11 +98,11 @@ int startWritingFPGAprogram(FILE **filefp) {
|
|||||||
*filefp = fopen(mtdvalue, "w");
|
*filefp = fopen(mtdvalue, "w");
|
||||||
if (*filefp == NULL) {
|
if (*filefp == NULL) {
|
||||||
LOG(logERROR, ("Unable to open %s in write mode\n", mtdvalue));
|
LOG(logERROR, ("Unable to open %s in write mode\n", mtdvalue));
|
||||||
return 1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("Flash ready for writing\n"));
|
LOG(logINFO, ("Flash ready for writing\n"));
|
||||||
|
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stopWritingFPGAprogram(FILE *filefp) {
|
int stopWritingFPGAprogram(FILE *filefp) {
|
||||||
@ -120,7 +125,7 @@ int stopWritingFPGAprogram(FILE *filefp) {
|
|||||||
usleep(1000);
|
usleep(1000);
|
||||||
timeSpent += 1000;
|
timeSpent += 1000;
|
||||||
if (timeSpent >= MAX_TIME_FPGA_TOUCH_FLASH_US) {
|
if (timeSpent >= MAX_TIME_FPGA_TOUCH_FLASH_US) {
|
||||||
return 1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
FILE *sysFile = popen("cat /sys/class/gpio/gpio7/value", "r");
|
FILE *sysFile = popen("cat /sys/class/gpio/gpio7/value", "r");
|
||||||
fgets(output, sizeof(output), sysFile);
|
fgets(output, sizeof(output), sysFile);
|
||||||
@ -129,21 +134,60 @@ int stopWritingFPGAprogram(FILE *filefp) {
|
|||||||
LOG(logDEBUG1, ("gpi07 returned %d\n", res));
|
LOG(logDEBUG1, ("gpi07 returned %d\n", res));
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
LOG(logINFO, ("FPGA has picked up the program from flash\n"));
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int writeFPGAProgram(char *fpgasrc, uint64_t fsize, FILE *filefp) {
|
|
||||||
|
|
||||||
|
int startCopyingFPGAProgram(FILE **fd, uint64_t fsize, char *mess) {
|
||||||
|
|
||||||
|
// delete old /var/tmp/file
|
||||||
|
{
|
||||||
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
|
memset(cmd, 0, MAX_STR_LENGTH);
|
||||||
|
sprintf(cmd, "rm -fr %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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check available memory to copy program
|
||||||
|
struct sysinfo info;
|
||||||
|
sysinfo(&info);
|
||||||
|
if (fsize >= info.freeram) {
|
||||||
|
sprintf(mess,
|
||||||
|
"Could not program fpga. Not enough memory to copy "
|
||||||
|
"program. [File size:l%dMB, free RAM: l%dMB]\n",
|
||||||
|
(fsize / (1024 * 1024)), (info.freeram / (1024 * 1024)));
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// open file to copy program
|
||||||
|
*fd = fopen(TEMP_PROG_FILE_NAME, "w");
|
||||||
|
if (*fd == NULL) {
|
||||||
|
sprintf(mess, "Unable to open %s in write mode\n", TEMP_PROG_FILE_NAME);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
LOG(logINFO, ("%s ready to copy program\n", TEMP_PROG_FILE_NAME));
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int writeFPGAProgram(uint64_t fsize, FILE *fd, char *src, char* msg, char* mess) {
|
||||||
LOG(logDEBUG1,
|
LOG(logDEBUG1,
|
||||||
("Writing of FPGA Program\n"
|
("%s [fsize:%lu,fd:%p,src:%p\n", msg, (long long unsigned int)fsize, (void *)fd, (void *)src));
|
||||||
"\taddress of fpgasrc:%p\n"
|
|
||||||
"\tfsize:%llu\n\tpointer:%p\n",
|
|
||||||
(void *)fpgasrc, (long long unsigned int)fsize, (void *)filefp));
|
|
||||||
|
|
||||||
if (fwrite((void *)fpgasrc, sizeof(char), fsize, filefp) != fsize) {
|
if (fwrite((void *)src, sizeof(char), fsize, fd) != fsize) {
|
||||||
LOG(logERROR, ("Could not write FPGA source to flash (size:%llu)\n",
|
sprintf(mess, "Could not %s (size:%lu)\n", msg, (long long unsigned int)fsize);
|
||||||
(long long unsigned int)fsize));
|
LOG(logERROR, (mess));
|
||||||
return 1;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logDEBUG1, ("program written to flash\n"));
|
LOG(logDEBUG1, ("%s\n", msg));
|
||||||
return 0;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/sysinfo.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
// defined in the detector specific Makefile
|
// defined in the detector specific Makefile
|
||||||
@ -35,10 +34,6 @@ const enum detectorType myDetectorType = GOTTHARD2;
|
|||||||
const enum detectorType myDetectorType = GENERIC;
|
const enum detectorType myDetectorType = GENERIC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD)
|
|
||||||
#define TEMP_PROG_FILE_NAME "/var/tmp/tmp.pof"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Global variables from communication_funcs
|
// Global variables from communication_funcs
|
||||||
extern int lockStatus;
|
extern int lockStatus;
|
||||||
extern uint32_t lastClientIP;
|
extern uint32_t lastClientIP;
|
||||||
@ -3716,6 +3711,10 @@ int program_fpga(int file_des) {
|
|||||||
// free resources
|
// free resources
|
||||||
free(fpgasrc);
|
free(fpgasrc);
|
||||||
}
|
}
|
||||||
|
if (ret == FAIL) {
|
||||||
|
LOG(logERROR, ("Program FPGA FAIL!\n"));
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
#else // jungfrau, ctb, moench
|
#else // jungfrau, ctb, moench
|
||||||
|
|
||||||
@ -3726,109 +3725,67 @@ int program_fpga(int file_des) {
|
|||||||
LOG(logINFOBLUE, ("Program size is: %lld\n",
|
LOG(logINFOBLUE, ("Program size is: %lld\n",
|
||||||
(long long unsigned int)filesize));
|
(long long unsigned int)filesize));
|
||||||
|
|
||||||
// delete old /var/tmp/file
|
// open file and allocate memory for part program
|
||||||
{
|
FILE *fd = NULL;
|
||||||
char cmd[MAX_STR_LENGTH] = {0};
|
ret = startCopyingFPGAProgram(&fd, filesize, mess);
|
||||||
memset(cmd, 0, MAX_STR_LENGTH);
|
char *src = NULL;
|
||||||
sprintf(cmd, "rm -fr %s", TEMP_PROG_FILE_NAME);
|
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
|
||||||
memset(retvals, 0, MAX_STR_LENGTH);
|
|
||||||
ret = executeCommand(cmd, retvals, logDEBUG1);
|
|
||||||
if (ret == FAIL) {
|
|
||||||
strcpy(mess, retvals);
|
|
||||||
// LOG(logERROR, (mess)); already printed in executecommand
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check available memory to copy program
|
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
struct sysinfo info;
|
src = malloc(MAX_FPGAPROGRAMSIZE);
|
||||||
sysinfo(&info);
|
if (src == NULL) {
|
||||||
if (filesize >= info.freeram) {
|
strcpy(mess, "Could not allocate memory to get fpga program\n");
|
||||||
ret = FAIL;
|
|
||||||
sprintf(mess,
|
|
||||||
"Could not program fpga. Not enough memory to copy "
|
|
||||||
"program. [File size:%dMb, free RAM: %dMb]\n",
|
|
||||||
(filesize / (1024 * 1024), (info.freeram / (1024 * 1024))));
|
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
|
fclose(fd);
|
||||||
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// open file to copy
|
|
||||||
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
|
||||||
|
// copying program part by part
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
size_t fsize = filesize;
|
|
||||||
fpgasrc = malloc(fsize);
|
|
||||||
if (fpgasrc == NULL) {
|
|
||||||
LOG(logERROR, ("Could not malloc\n"));
|
|
||||||
ret = FAIL;
|
|
||||||
}*/
|
|
||||||
// fpgasrc = malloc(filesize + 1);
|
|
||||||
char *fpgasrc = NULL;
|
|
||||||
FILE *fp = NULL;
|
|
||||||
uint64_t offset = 0;
|
|
||||||
uint64_t totalsize = filesize;
|
uint64_t totalsize = filesize;
|
||||||
|
|
||||||
// writing to flash part by part
|
|
||||||
int clientSocketCrash = 0;
|
|
||||||
while (ret != FAIL && filesize) {
|
while (ret != FAIL && filesize) {
|
||||||
|
|
||||||
uint64_t unitprogramsize = MAX_FPGAPROGRAMSIZE; // 2mb
|
uint64_t unitprogramsize = MAX_FPGAPROGRAMSIZE; // 2mb
|
||||||
if (unitprogramsize > filesize) // less than 2mb
|
if (unitprogramsize > filesize) // less than 2mb
|
||||||
unitprogramsize = filesize;
|
unitprogramsize = filesize;
|
||||||
LOG(logINFOBLUE,
|
LOG(logINFOBLUE,
|
||||||
("unit size to receive is:%lld [ooffset:%lld, filesize:%lld]\n",
|
("unit size to receive is:%lld [filesize:%lld]\n",
|
||||||
(long long unsigned int)unitprogramsize,
|
(long long unsigned int)unitprogramsize,
|
||||||
(long long unsigned int)offset,
|
|
||||||
(long long unsigned int)filesize));
|
(long long unsigned int)filesize));
|
||||||
|
|
||||||
// receive part of program
|
// receive part of program
|
||||||
if (receiveData(file_des, fpgasrc, unitprogramsize, OTHER) < 0) {
|
if (receiveData(file_des, src, unitprogramsize, OTHER) < 0) {
|
||||||
printSocketReadError();
|
printSocketReadError();
|
||||||
clientSocketCrash = 1;
|
break;
|
||||||
ret = FAIL;
|
|
||||||
LOG(logERROR, ("error, not receiverd\n"));
|
|
||||||
}
|
}
|
||||||
// client has not crashed yet, so write to flash and send ret
|
|
||||||
else {
|
if (unitprogramsize - filesize == 0) {
|
||||||
LOG(logINFOBLUE, ("receiverd\n"));
|
src[unitprogramsize] = '\0';
|
||||||
offset += unitprogramsize;
|
filesize -= unitprogramsize;
|
||||||
|
unitprogramsize++;
|
||||||
|
} else
|
||||||
filesize -= unitprogramsize;
|
filesize -= unitprogramsize;
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
|
|
||||||
// print progress
|
// copy program
|
||||||
LOG(logINFOBLUE,
|
ret = writeFPGAProgram(unitprogramsize, fd, src, "copy program to /var/tmp", mess);
|
||||||
("Writing to Flash:%d%%\r",
|
|
||||||
(int)(((double)(totalsize - filesize) / totalsize) *
|
|
||||||
100)));
|
|
||||||
fflush(stdout);
|
|
||||||
|
|
||||||
/*
|
|
||||||
// write part to flash
|
|
||||||
ret = writeFPGAProgram(fpgasrc, unitprogramsize, fp);
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
if (ret == FAIL) {
|
if (ret == FAIL) {
|
||||||
strcpy(mess, "Could not write to flash. Breaking out of "
|
break;
|
||||||
"program receiving. Try to flash again "
|
}
|
||||||
"without rebooting.\n");
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
} else {
|
|
||||||
// print progress
|
// print progress
|
||||||
LOG(logINFO,
|
LOG(logINFO,
|
||||||
("Writing to Flash:%d%%\r",
|
("Copying Program to /var/tmp/:%d%%\r",
|
||||||
(int)(((double)(totalsize - filesize) / totalsize) *
|
(int)(((double)(totalsize - filesize) / totalsize) *
|
||||||
100)));
|
100)));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
*/
|
if (ret == FAIL) {
|
||||||
}
|
free(src);
|
||||||
|
fclose(fd);
|
||||||
|
LOG(logERROR, ("Program FPGA FAIL!\n"));
|
||||||
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
free(src);
|
||||||
|
fclose(fd);
|
||||||
|
|
||||||
/* if (ret != FAIL) {
|
/* if (ret != FAIL) {
|
||||||
fpgasrc[totalsize] = '\0';
|
fpgasrc[totalsize] = '\0';
|
||||||
}*/
|
}*/
|
||||||
@ -3864,25 +3821,11 @@ int program_fpga(int file_des) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// free resources
|
|
||||||
free(fpgasrc);
|
|
||||||
if (fp != NULL)
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
// send final ret (if no client crash)
|
|
||||||
if (clientSocketCrash == 0) {
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // end of Blackfin programming
|
#endif // end of Blackfin programming
|
||||||
if (ret == FAIL) {
|
|
||||||
LOG(logERROR, ("Program FPGA FAIL!\n"));
|
|
||||||
} else {
|
|
||||||
LOG(logINFOGREEN, ("Programming FPGA completed successfully\n"));
|
LOG(logINFOGREEN, ("Programming FPGA completed successfully\n"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -3450,16 +3450,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
|||||||
}
|
}
|
||||||
filesize -= unitprogramsize;
|
filesize -= unitprogramsize;
|
||||||
currentPointer += unitprogramsize;
|
currentPointer += unitprogramsize;
|
||||||
|
|
||||||
// print progress
|
|
||||||
printf(
|
|
||||||
"%d%%\r",
|
|
||||||
static_cast<int>(
|
|
||||||
(static_cast<double>(totalsize - filesize) / totalsize) * 100));
|
|
||||||
std::cout << std::flush;
|
|
||||||
}
|
}
|
||||||
std::cout << '\n';
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// error in detector at opening file pointer to flash
|
// error in detector at opening file pointer to flash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user