moved verifykernelversion to common

This commit is contained in:
maliakal_d 2021-10-29 16:43:48 +02:00
parent 2813cd5ac2
commit 45b3514118
9 changed files with 65 additions and 116 deletions

View File

@ -188,7 +188,7 @@ int checkKernelVersion() {
#ifdef VIRTUAL
return OK;
#endif
return Nios_checkKernelVersion(KERNEL_DATE_VRSN);
return validateKernelVersion(KERNEL_DATE_VRSN);
}
int checkType() {

View File

@ -181,7 +181,7 @@ int checkKernelVersion() {
#ifdef VIRTUAL
return OK;
#endif
return Nios_checkKernelVersion(KERNEL_DATE_VRSN);
return validateKernelVersion(KERNEL_DATE_VRSN);
}
int checkType() {

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -7,10 +7,8 @@
#include "sls/ansi.h"
#include "sls/sls_detector_defs.h"
#include <fcntl.h> // open
#include <string.h>
#include <sys/mman.h> // mmap
#include <sys/utsname.h> // uname
#include <fcntl.h> // open
#include <sys/mman.h> // 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;
}

View File

@ -7,7 +7,8 @@
#include <libgen.h> // dirname
#include <string.h>
#include <unistd.h> // readlink
#include <sys/utsname.h> // uname
#include <unistd.h> // 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) {

View File

@ -7,10 +7,8 @@
#include "sls/ansi.h"
#include "sls/sls_detector_defs.h"
#include <fcntl.h> // open
#include <string.h>
#include <sys/mman.h> // mmap
#include <sys/utsname.h> // uname
#include <fcntl.h> // open
#include <sys/mman.h> // 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;
}

View File

@ -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