From 45b3514118dd705c8962f4fd5bcdd29da8f1d731 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 29 Oct 2021 16:43:48 +0200 Subject: [PATCH] moved verifykernelversion to common --- .../slsDetectorFunctionList.c | 2 +- .../slsDetectorFunctionList.c | 2 +- .../slsDetectorServer/include/blackfin.h | 4 -- .../slsDetectorServer/include/common.h | 4 +- .../slsDetectorServer/include/nios.h | 4 -- .../slsDetectorServer/src/blackfin.c | 52 +------------------ .../slsDetectorServer/src/common.c | 51 +++++++++++++++++- .../slsDetectorServer/src/nios.c | 52 +------------------ .../src/programFpgaBlackfin.c | 10 ++-- 9 files changed, 65 insertions(+), 116 deletions(-) diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index a9ae54ae6..7046f4a16 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -188,7 +188,7 @@ int checkKernelVersion() { #ifdef VIRTUAL return OK; #endif - return Nios_checkKernelVersion(KERNEL_DATE_VRSN); + return validateKernelVersion(KERNEL_DATE_VRSN); } int checkType() { diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 51a0c0895..496126a91 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -181,7 +181,7 @@ int checkKernelVersion() { #ifdef VIRTUAL return OK; #endif - return Nios_checkKernelVersion(KERNEL_DATE_VRSN); + return validateKernelVersion(KERNEL_DATE_VRSN); } int checkType() { diff --git a/slsDetectorServers/slsDetectorServer/include/blackfin.h b/slsDetectorServers/slsDetectorServer/include/blackfin.h index 6edecd541..e3a2d50f7 100644 --- a/slsDetectorServers/slsDetectorServer/include/blackfin.h +++ b/slsDetectorServers/slsDetectorServer/include/blackfin.h @@ -105,7 +105,3 @@ uint32_t *Blackfin_getBaseAddress(); * Map FPGA */ int mapCSP0(void); - -/** check kernel version against expected version string (complain if too old) - * @returns OK or FAIL */ -int blackfin_checkKernelVersion(char *expectedVersion); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/include/common.h b/slsDetectorServers/slsDetectorServer/include/common.h index 6a0ab83c2..0435c7df2 100644 --- a/slsDetectorServers/slsDetectorServer/include/common.h +++ b/slsDetectorServers/slsDetectorServer/include/common.h @@ -26,7 +26,9 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int getAbsPath(char *buf, size_t bufSize, char *fname); -int GetTimeFromString(char *buf, time_t *result); +int getTimeFromString(char *buf, time_t *result); + +int validateKernelVersion(char *expectedVersion); void validate(int *ret, char *mess, int arg, int retval, char *modename, enum numberMode nummode); diff --git a/slsDetectorServers/slsDetectorServer/include/nios.h b/slsDetectorServers/slsDetectorServer/include/nios.h index 33b0d4252..71e66072c 100644 --- a/slsDetectorServers/slsDetectorServer/include/nios.h +++ b/slsDetectorServers/slsDetectorServer/include/nios.h @@ -89,7 +89,3 @@ int mapCSP0(void); * Get Nios base address */ u_int32_t *Nios_getBaseAddress(); - -/** check kernel version against expected version string (complain if too old) - * @returns OK or FAIL */ -int Nios_checkKernelVersion(char *expectedVersion); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/blackfin.c b/slsDetectorServers/slsDetectorServer/src/blackfin.c index e3a15613e..30bc58937 100644 --- a/slsDetectorServers/slsDetectorServer/src/blackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/blackfin.c @@ -7,10 +7,8 @@ #include "sls/ansi.h" #include "sls/sls_detector_defs.h" -#include // open -#include -#include // mmap -#include // uname +#include // open +#include // mmap /* global variables */ u_int32_t *csp0base = 0; @@ -130,49 +128,3 @@ int mapCSP0(void) { } uint32_t *Blackfin_getBaseAddress() { return csp0base; } - -int blackfin_checkKernelVersion(char *expectedVersion) { - // extract kernel date string - struct utsname buf; - if (uname(&buf) == -1) { - LOG(logERROR, ("Could not get kernel version\n")); - return FAIL; - } - - // remove first word (#version number) - const char *ptr = strchr(buf.version, ' '); - if (ptr == NULL) { - LOG(logERROR, ("Could not parse kernel version\n")); - return FAIL; - } - char output[256]; - memset(output, 0, 256); - strcpy(output, buf.version + (ptr - buf.version + 1)); - - // convert kernel date string into time - time_t kernelDate; - if (GetTimeFromString(output, &kernelDate) == FAIL) { - LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); - return FAIL; - } - - // convert expected date into time - time_t expDate; - if (GetTimeFromString(expectedVersion, &expDate) == FAIL) { - LOG(logERROR, - ("Could not parse expected kernel date, %s\n", expectedVersion)); - return FAIL; - } - - // compare if kernel time is older than expected time - if (kernelDate < expDate) { - LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], " - "Got [%s]\n", - expectedVersion, output)); - return FAIL; - } - - LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, - expectedVersion)); - return OK; -} \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index dead04abb..fd0a60c9e 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -7,7 +7,8 @@ #include // dirname #include -#include // readlink +#include // uname +#include // readlink int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int outputMax, int inputValue, int *outputValue) { @@ -64,7 +65,7 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) { return OK; } -int GetTimeFromString(char *buf, time_t *result) { +int getTimeFromString(char *buf, time_t *result) { // remove timezone as strptime cannot validate timezone despite // documentation const char *timezone = {"CEST"}; @@ -89,6 +90,52 @@ int GetTimeFromString(char *buf, time_t *result) { return OK; } +int validateKernelVersion(char *expectedVersion) { + // extract kernel date string + struct utsname buf = {0}; + if (uname(&buf) == -1) { + LOG(logERROR, ("Could not get kernel version\n")); + return FAIL; + } + + // remove first word (#version number) + const char *ptr = strchr(buf.version, ' '); + if (ptr == NULL) { + LOG(logERROR, ("Could not parse kernel version\n")); + return FAIL; + } + char output[255]; + memset(output, 0, sizeof(output)); + strcpy(output, buf.version + (ptr - buf.version + 1)); + + // convert kernel date string into time + time_t kernelDate; + if (getTimeFromString(output, &kernelDate) == FAIL) { + LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); + return FAIL; + } + + // convert expected date into time + time_t expDate; + if (getTimeFromString(expectedVersion, &expDate) == FAIL) { + LOG(logERROR, + ("Could not parse expected kernel date, %s\n", expectedVersion)); + return FAIL; + } + + // compare if kernel time is older than expected time + if (kernelDate < expDate) { + LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], " + "Got [%s]\n", + expectedVersion, output)); + return FAIL; + } + + LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, + expectedVersion)); + return OK; +} + void validate(int *ret, char *mess, int arg, int retval, char *modename, enum numberMode nummode) { if (*ret == OK && arg != GET_FLAG && retval != arg) { diff --git a/slsDetectorServers/slsDetectorServer/src/nios.c b/slsDetectorServers/slsDetectorServer/src/nios.c index 03c9f364a..ddee51e55 100644 --- a/slsDetectorServers/slsDetectorServer/src/nios.c +++ b/slsDetectorServers/slsDetectorServer/src/nios.c @@ -7,10 +7,8 @@ #include "sls/ansi.h" #include "sls/sls_detector_defs.h" -#include // open -#include -#include // mmap -#include // uname +#include // open +#include // mmap /* global variables */ u_int32_t *csp0base = 0; @@ -132,49 +130,3 @@ int mapCSP0(void) { } u_int32_t *Nios_getBaseAddress() { return csp0base; } - -int Nios_checkKernelVersion(char *expectedVersion) { - // extract kernel date string - struct utsname buf; - if (uname(&buf) == -1) { - LOG(logERROR, ("Could not get kernel version\n")); - return FAIL; - } - - // remove first word (#version number) - const char *ptr = strchr(buf.version, ' '); - if (ptr == NULL) { - LOG(logERROR, ("Could not parse kernel version\n")); - return FAIL; - } - char output[256]; - memset(output, 0, 256); - strcpy(output, buf.version + (ptr - buf.version + 1)); - - // convert kernel date string into time - time_t kernelDate; - if (GetTimeFromString(output, &kernelDate) == FAIL) { - LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); - return FAIL; - } - - // convert expected date into time - time_t expDate; - if (GetTimeFromString(expectedVersion, &expDate) == FAIL) { - LOG(logERROR, - ("Could not parse expected kernel date, %s\n", expectedVersion)); - return FAIL; - } - - // compare if kernel time is older than expected time - if (kernelDate < expDate) { - LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], " - "Got [%s]\n", - expectedVersion, output)); - return FAIL; - } - - LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, - expectedVersion)); - return OK; -} \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c b/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c index e2f2351ff..e7827eb39 100644 --- a/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/programFpgaBlackfin.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package #include "programFpgaBlackfin.h" -#include "blackfin.h" #include "clogger.h" #include "common.h" #include "sls/ansi.h" @@ -33,8 +32,13 @@ void defineGPIOpins() { return; #endif if (latestKernelVerified == -1) { - latestKernelVerified = - ((OK == blackfin_checkKernelVersion(KERNEL_DATE_VRSN)) ? 1 : 0); + if (FAIL == validateKernelVersion(KERNEL_DATE_VRSN)) { + latestKernelVerified = 0; + LOG(logWARNING, ("Kernel too old to use gpio 3 pins. Not the end " + "of the world. Continuing with current kernel\n")); + } else { + latestKernelVerified = 1; + } } if (!gpioDefined) { // define the gpio pins