adding the check for copydetector server and updatemode (also for any kind of updatedetectorserver, programfpga and updatekernel)

This commit is contained in:
maliakal_d 2021-11-23 16:25:28 +01:00
parent ed2e6e4e28
commit f39f93b2c8
3 changed files with 46 additions and 30 deletions

View File

@ -14,7 +14,7 @@ int FPGATouchFlash(char *mess);
int resetFPGA(char *mess);
int emptyTempFolder(char *mess);
int allowKernelUpdate(char *mess, char *functionType);
int allowUpdate(char *mess, char *functionType);
/**
* deletes old file
* verify memory available to copy

View File

@ -10,6 +10,7 @@
#include <sys/sysinfo.h>
#include <unistd.h> // usleep
#define BLACKFIN_DEFINED
/* global variables */
// clang-format off
#define MAX_TIME_FPGA_TOUCH_FLASH_US (10 * 1000 * 1000) // 10s
@ -248,8 +249,8 @@ int emptyTempFolder(char *mess) {
#endif
}
int allowKernelUpdate(char *mess, char *functionType) {
LOG(logINFO, ("\tVerifying kernel update allowed...\n"));
int allowUpdate(char *mess, char *functionType) {
LOG(logINFO, ("\tVerifying %s allowed...\n", functionType));
#ifdef VIRTUAL
return OK;

View File

@ -4143,20 +4143,28 @@ int copy_detector_server(int file_des) {
LOG(logINFOBLUE, ("Copying server %s from host %s\n", sname, hostname));
char cmd[MAX_STR_LENGTH] = {0};
#if BLACKFIN_DEFINED
// check update is allowed (Non Amd OR AMD + current kernel)
ret = allowUpdate(mess, "copy detector server");
#endif
// tftp server
if (snprintf(cmd, MAX_STR_LENGTH, "tftp %s -r %s -g", hostname,
sname) >= MAX_STR_LENGTH) {
ret = FAIL;
strcpy(mess, "Could not copy detector server. Command to copy "
"server too long\n");
LOG(logERROR, (mess));
} else if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (tftp). %s\n", retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tServer copied\n"));
if (ret == OK) {
if (snprintf(cmd, MAX_STR_LENGTH, "tftp %s -r %s -g", hostname,
sname) >= MAX_STR_LENGTH) {
ret = FAIL;
strcpy(mess, "Could not copy detector server. Command to copy "
"server too long\n");
LOG(logERROR, (mess));
} else if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
ret = FAIL;
snprintf(mess, MAX_STR_LENGTH,
"Could not copy detector server (tftp). %s\n",
retvals);
// LOG(logERROR, (mess)); already printed in executecommand
} else {
LOG(logINFO, ("\tServer copied\n"));
}
}
if (ret == OK) {
@ -9373,8 +9381,8 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
functionType);
LOG(logERROR, (mess));
#else
// check kernel update is allowed (Non Amd OR AMD + current kernel)
ret = allowKernelUpdate(mess, functionType);
// check update is allowed (Non Amd OR AMD + current kernel)
ret = allowUpdate(mess, functionType);
if (ret == FAIL) {
Server_SendResult(file_des, INT32, NULL, 0);
return;
@ -9599,18 +9607,25 @@ int set_update_mode(int file_des) {
return printSocketReadError();
LOG(logDEBUG1, ("Setting update mode to \n", arg));
switch (arg) {
case 0:
ret = deleteFile(mess, UPDATE_FILE, "unset update mode");
break;
case 1:
ret = createEmptyFile(mess, UPDATE_FILE, "set update mode");
break;
default:
ret = FAIL;
sprintf(mess, "Could not set updatemode. Options: 0 or 1\n");
LOG(logERROR, (mess));
break;
#if BLACKFIN_DEFINED
// check update is allowed (Non Amd OR AMD + current kernel)
ret = allowUpdate(mess, "copy detector server");
#endif
if (ret == OK) {
switch (arg) {
case 0:
ret = deleteFile(mess, UPDATE_FILE, "unset update mode");
break;
case 1:
ret = createEmptyFile(mess, UPDATE_FILE, "set update mode");
break;
default:
ret = FAIL;
sprintf(mess, "Could not set updatemode. Options: 0 or 1\n");
LOG(logERROR, (mess));
break;
}
}
return Server_SendResult(file_des, INT32, NULL, 0);