mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-02 19:00:05 +02:00
moved verifykernelversion to common
This commit is contained in:
parent
2813cd5ac2
commit
45b3514118
@ -188,7 +188,7 @@ int checkKernelVersion() {
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
return Nios_checkKernelVersion(KERNEL_DATE_VRSN);
|
||||
return validateKernelVersion(KERNEL_DATE_VRSN);
|
||||
}
|
||||
|
||||
int checkType() {
|
||||
|
@ -181,7 +181,7 @@ int checkKernelVersion() {
|
||||
#ifdef VIRTUAL
|
||||
return OK;
|
||||
#endif
|
||||
return Nios_checkKernelVersion(KERNEL_DATE_VRSN);
|
||||
return validateKernelVersion(KERNEL_DATE_VRSN);
|
||||
}
|
||||
|
||||
int checkType() {
|
||||
|
@ -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);
|
@ -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);
|
||||
|
@ -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);
|
@ -8,9 +8,7 @@
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
#include <fcntl.h> // open
|
||||
#include <string.h>
|
||||
#include <sys/mman.h> // mmap
|
||||
#include <sys/utsname.h> // uname
|
||||
|
||||
/* 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;
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <libgen.h> // dirname
|
||||
#include <string.h>
|
||||
#include <sys/utsname.h> // uname
|
||||
#include <unistd.h> // readlink
|
||||
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||
@ -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) {
|
||||
|
@ -8,9 +8,7 @@
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
#include <fcntl.h> // open
|
||||
#include <string.h>
|
||||
#include <sys/mman.h> // mmap
|
||||
#include <sys/utsname.h> // uname
|
||||
|
||||
/* 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;
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user