nios programming: check file size first

This commit is contained in:
maliakal_d 2020-01-31 11:24:48 +01:00
parent 5ca3a1b685
commit 89c774dbf7
13 changed files with 48 additions and 55 deletions

View File

@ -12,9 +12,6 @@
#include "INA226.h" // i2c
#include "ALTERA_PLL.h" // pll
#include "blackfin.h"
#ifndef VIRTUAL
#include "programFpgaBlackfin.h"
#endif
#include <string.h>
#include <unistd.h> // usleep

View File

@ -8,9 +8,7 @@
#include "common.h"
#include "ALTERA_PLL_CYCLONE10.h"
#include "ASIC_Driver.h"
#ifndef VIRTUAL
#include "programFpgaNios.h"
#else
#ifdef VIRTUAL
#include "communication_funcs_UDP.h"
#endif

View File

@ -8,9 +8,7 @@
#include "ALTERA_PLL.h" // pll
#include "blackfin.h"
#include "common.h"
#ifndef VIRTUAL
#include "programFpgaBlackfin.h"
#else
#ifdef VIRTUAL
#include "communication_funcs_UDP.h"
#endif

View File

@ -7,9 +7,7 @@
#include "common.h"
#include "RegisterDefs.h"
#include "ALTERA_PLL_CYCLONE10.h"
#ifndef VIRTUAL
#include "programFpgaNios.h"
#else
#ifdef VIRTUAL
#include "communication_funcs_UDP.h"
#endif

View File

@ -3,6 +3,8 @@
#include <stdio.h>
#include <stdint.h>
#define NIOS_MAX_APP_IMAGE_SIZE (0x00580000)
/** Notify microcontroller of successful server start up */
void NotifyServerStartSuccess();

View File

@ -19,7 +19,6 @@ void validate(int arg, int retval, char* modename, enum numberMode nummode);
void validate64(int64_t arg, int64_t retval, char* modename, enum numberMode nummode);
int executeCommand(char* command, char* result, enum TLogLevel level);
int M_nofunc(int);
int M_nofuncMode(int);
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
extern void rebootControllerAndFPGA();
#endif

View File

@ -2,6 +2,13 @@
#include "slsDetectorFunctionList.h"
#include "communication_funcs.h"
#include "clogger.h"
#ifndef VIRTUAL
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
#include "programFpgaNios.h"
#elif defined(CHIPTESTBOARDD) || defined(JUNGFRAUD) || defined(MOENCHD)
#include "programFpgaBlackfin.h"
#endif
#endif
#include <string.h>
#include <arpa/inet.h>
@ -594,27 +601,6 @@ int M_nofunc(int file_des) {
}
// Jungfrau program mode
int M_nofuncMode(int file_des) {
ret = FAIL;
memset(mess, 0, sizeof(mess));
// to receive any arguments
int n = 1;
while (n > 0)
n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER);
sprintf(mess,"This Function %s cannot be executed as the "
"On-board detector server in update mode.\n"
"Restart detector server in normal mode (without any arguments) to continue.\n",
getFunctionName((enum detFuncs)fnum));
FILE_LOG(logERROR, (mess));
return Server_SendResult(file_des, OTHER, NO_UPDATE, NULL, 0);
}
int exec_command(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -3728,19 +3714,27 @@ int program_fpga(int file_des) {
// filesize
if (receiveData(file_des,&filesize,sizeof(filesize),INT64) < 0)
return printSocketReadError();
FILE_LOG(logDEBUG1, ("Total program size is: %lld\n", (long long unsigned int)filesize));
// receive program
char* fpgasrc = (char*)malloc(filesize);
if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0)
return printSocketReadError();
ret = eraseAndWriteToFlash(mess, fpgasrc, filesize);
FILE_LOG(logDEBUG1, ("Total program size is: %llx\n", (long long unsigned int)filesize));
if (filesize > NIOS_MAX_APP_IMAGE_SIZE) {
ret = FAIL;
sprintf(mess,"Could not start programming FPGA. File size 0x%llx exceeds max size 0x%llx. Forgot Compression?\n", (long long unsigned int) filesize, (long long unsigned int)NIOS_MAX_APP_IMAGE_SIZE);
FILE_LOG(logERROR,(mess));
}
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
// receive program
if (ret == OK) {
char* fpgasrc = (char*)malloc(filesize);
if (receiveData(file_des, fpgasrc, filesize, OTHER) < 0)
return printSocketReadError();
//free resources
if (fpgasrc != NULL)
free(fpgasrc);
ret = eraseAndWriteToFlash(mess, fpgasrc, filesize);
Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0);
//free resources
if (fpgasrc != NULL)
free(fpgasrc);
}
#else // jungfrau, ctb, moench
@ -3817,9 +3811,9 @@ int program_fpga(int file_des) {
if (fp != NULL)
fclose(fp);
#endif
#endif // end of Blackfin programming
if (ret == FAIL) {
FILE_LOG(logINFORED, ("Program FPGA fail!\n"));
FILE_LOG(logERROR, ("Program FPGA FAIL!\n"));
} else {
FILE_LOG(logINFOGREEN, ("Programming FPGA completed successfully\n"));
}

View File

@ -2989,8 +2989,6 @@ void slsDetector::programFPGAviaBlackfin(std::vector<char> buffer) {
void slsDetector::programFPGAviaNios(std::vector<char> buffer) {
uint64_t filesize = buffer.size();
// send program from memory to detector
int fnum = F_PROGRAM_FPGA;
int ret = FAIL;
char mess[MAX_STR_LENGTH] = {0};
@ -2999,11 +2997,20 @@ void slsDetector::programFPGAviaNios(std::vector<char> buffer) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum));
// filesize
client.Send(&filesize, sizeof(filesize));
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
client.Receive(mess, sizeof(mess));
std::ostringstream os;
os << "Detector " << detId << " (" << shm()->hostname << ")"
<< " returned error: " << mess;
throw RuntimeError(os.str());
}
// program
client.Send(&buffer[0], filesize);
client.Receive(&ret, sizeof(ret));
if (ret == FAIL) {
printf("\n");
client.Receive(mess, sizeof(mess));
std::ostringstream os;
os << "Detector " << detId << " (" << shm()->hostname << ")"

View File

@ -3,10 +3,10 @@
#define APILIB 0x190723
#define APIRECEIVER 0x190722
#define APIGUI 0x190723
#define APIMOENCH 0x190820
#define APIEIGER 0x200122
#define APIJUNGFRAU 0x200130
#define APICTB 0x200130
#define APIGOTTHARD2 0x200130
#define APIMYTHEN3 0x200130
#define APIGOTTHARD 0x200130
#define APICTB 0x200131
#define APIJUNGFRAU 0x200131
#define APIMOENCH 0x200131
#define APIGOTTHARD2 0x200131
#define APIMYTHEN3 0x200131