diff --git a/slsDetectorServers/slsDetectorServer/include/programViaBlackfin.h b/slsDetectorServers/slsDetectorServer/include/programViaBlackfin.h index 9abe2e678..384551c30 100644 --- a/slsDetectorServers/slsDetectorServer/include/programViaBlackfin.h +++ b/slsDetectorServers/slsDetectorServer/include/programViaBlackfin.h @@ -14,6 +14,7 @@ int FPGATouchFlash(char *mess); int resetFPGA(char *mess); int emptyTempFolder(char *mess); +int allowKernelUpdate(char *mess); /** * deletes old file * verify memory available to copy diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index 5f6a2b2d6..b76349c16 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -403,7 +403,8 @@ int verifyChecksum(char *mess, char *functionType, char *clientChecksum, if (strcmp(clientChecksum, checksum)) { sprintf(mess, "Could not %s. Checksum of %s does not match. Client " - "checksum:%s, copied checksum:%s\n", + "checksum:%s, copied checksum:%. Please try again before " + "rebooting.\n", functionType, msg, clientChecksum, checksum); LOG(logERROR, (mess)); return FAIL; diff --git a/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c b/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c index 662de51e7..bc418f923 100644 --- a/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c @@ -35,6 +35,9 @@ #define CMD_GET_FPGA_FLASH_DRIVE "awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd" #define CMD_GET_KERNEL_FLASH_DRIVE "awk \'$4== \"\\\"linux\" {print $1}\' /proc/mtd" + +#define CMD_GET_AMD_FLASH "dmesg | grep Amd" + #define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB // clang-format on @@ -245,6 +248,41 @@ int emptyTempFolder(char *mess) { #endif } +int allowKernelUpdate(char *mess) { + LOG(logINFO, ("\tVerifying kernel update allowed...\n")); + +#ifdef VIRTUAL + return OK; +#endif + char retvals[MAX_STR_LENGTH] = {0}; + if (executeCommand(CMD_GET_AMD_FLASH, retvals, logDEBUG1) == FAIL) { + snprintf( + mess, MAX_STR_LENGTH, + "Could not update %s. (Could not figure out if Amd flash: %s)\n", + messageType, retvals); + LOG(logERROR, (mess)); + return FAIL; + } + // amd flash found + if (strlen(retvals) > 1) { + LOG(logINFO, ("\tAmd Flash found\n")); + // only current kernel works with amd flash + if (validateKernelVersion(KERNEL_DATE_VRSN_3GPIO) == FAIL) { + getKernelVersion(retvals); + snprintf(mess, MAX_STR_LENGTH, + "Could not update %s. Kernel version %s is too old to " + "update the Amd flash\n", + messageType, retvals); + LOG(logERROR, (mess)); + return FAIL; + } + } else { + LOG(logINFO, ("\tNot Amd Flash\n")); + } + LOG(logINFO, ("\tKernel and flash ok for updating kernel\n")); + return OK; +} + int preparetoCopyProgram(char *mess, char *functionType, FILE **fd, uint64_t fsize) { diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index da7b40c10..5c82cfb0f 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -9255,10 +9255,11 @@ int get_kernel_version(int file_des) { ret = getKernelVersion(retvals); if (ret == FAIL) { if (snprintf(mess, MAX_STR_LENGTH, "Could not get kernel version. %s\n", - retvals) >= MAX_STR_LENGTH) { + retvals) >= MAX_STR_LENGTH) { ret = FAIL; - strcpy(mess, "Could not get kernel version. Reason too long to copy\n"); - } + strcpy(mess, + "Could not get kernel version. Reason too long to copy\n"); + } LOG(logERROR, (mess)); } else { LOG(logDEBUG1, ("kernel version: [%s]\n", retvals)); @@ -9372,6 +9373,13 @@ 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); + if (ret == FAIL) { + Server_SendResult(file_des, INT32, NULL, 0); + return; + } + // open file and allocate memory for part program FILE *fd = NULL; ret = preparetoCopyProgram(mess, functionType, &fd, filesize);