Merge pull request #330 from slsdetectorgroup/programfix

Program firmware for new kernel
This commit is contained in:
Dhanya Thattil
2021-11-03 11:43:37 +01:00
committed by GitHub
18 changed files with 141 additions and 78 deletions

View File

@ -28,6 +28,8 @@ This document describes the differences between vx.x.x and v6.0.0.
- setting rx_hostname to none threw an exception. fixed. - setting rx_hostname to none threw an exception. fixed.
- rx id in config file was not taken into account. fixed. - rx id in config file was not taken into account. fixed.
- programming firmware failure for blackfin, fixed but requires new kernel.
- nios kernel check updated (ensuring right kernel)
3. Known Issues 3. Known Issues
=============== ===============

View File

@ -188,7 +188,9 @@ int checkKernelVersion() {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;
#endif #endif
return Nios_checkKernelVersion(KERNEL_DATE_VRSN); char buf[255] = {0};
strcpy(buf, KERNEL_DATE_VRSN);
return validateKernelVersion(buf);
} }
int checkType() { int checkType() {

View File

@ -4,7 +4,7 @@
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#define REQRD_FRMWRE_VRSN (0x210527) #define REQRD_FRMWRE_VRSN (0x210527)
#define KERNEL_DATE_VRSN "Wed May 20 13:58:38 CEST 2020" #define KERNEL_DATE_VRSN "Mon May 10 18:00:21 CEST 2021"
#define ID_FILE "detid_gotthard2.txt" #define ID_FILE "detid_gotthard2.txt"
#define LINKED_SERVER_NAME "gotthard2DetectorServer" #define LINKED_SERVER_NAME "gotthard2DetectorServer"

View File

@ -181,7 +181,9 @@ int checkKernelVersion() {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;
#endif #endif
return Nios_checkKernelVersion(KERNEL_DATE_VRSN); char buf[255] = {0};
strcpy(buf, KERNEL_DATE_VRSN);
return validateKernelVersion(buf);
} }
int checkType() { int checkType() {

View File

@ -4,7 +4,7 @@
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#define REQRD_FRMWRE_VRSN (0x210910) #define REQRD_FRMWRE_VRSN (0x210910)
#define KERNEL_DATE_VRSN "Wed May 20 13:58:38 CEST 2020" #define KERNEL_DATE_VRSN "Mon May 10 18:00:21 CEST 2021"
#define ID_FILE "detid_mythen3.txt" #define ID_FILE "detid_mythen3.txt"
#define LINKED_SERVER_NAME "mythen3DetectorServer" #define LINKED_SERVER_NAME "mythen3DetectorServer"

View File

@ -26,7 +26,9 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
int getAbsPath(char *buf, size_t bufSize, char *fname); 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, void validate(int *ret, char *mess, int arg, int retval, char *modename,
enum numberMode nummode); enum numberMode nummode);

View File

@ -89,7 +89,3 @@ int mapCSP0(void);
* Get Nios base address * Get Nios base address
*/ */
u_int32_t *Nios_getBaseAddress(); 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

@ -3,6 +3,7 @@
#include "blackfin.h" #include "blackfin.h"
#include "RegisterDefs.h" #include "RegisterDefs.h"
#include "clogger.h" #include "clogger.h"
#include "common.h"
#include "sls/ansi.h" #include "sls/ansi.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
@ -126,4 +127,4 @@ int mapCSP0(void) {
return OK; return OK;
} }
uint32_t *Blackfin_getBaseAddress() { return csp0base; } uint32_t *Blackfin_getBaseAddress() { return csp0base; }

View File

@ -7,7 +7,8 @@
#include <libgen.h> // dirname #include <libgen.h> // dirname
#include <string.h> #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 ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
int outputMax, int inputValue, int *outputValue) { int outputMax, int inputValue, int *outputValue) {
@ -64,15 +65,83 @@ int getAbsPath(char *buf, size_t bufSize, char *fname) {
return OK; 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 (for blackfin)
LOG(logDEBUG, ("buf for time %s\n", buf));
const char *timezone = {"CEST"};
char *res = strstr(buf, timezone);
if (res != NULL) {
size_t cestPos = res - buf;
size_t pos = cestPos + strlen(timezone) + 1;
while (pos != strlen(buf)) {
buf[cestPos] = buf[pos];
++cestPos;
++pos;
}
buf[cestPos] = '\0';
}
LOG(logDEBUG, ("buf after removing CEST %s\n", buf));
// convert to time structure
struct tm t; struct tm t;
if (NULL == strptime(buf, "%a %b %d %H:%M:%S %Z %Y", &t)) { if (NULL == strptime(buf, "%a %b %d %H:%M:%S %Y", &t)) {
return FAIL; return FAIL;
} }
// print time structure
LOG(logDEBUG, ("%d %d %d %d:%d:%d %d (day date month H:M:S year)\n", t.tm_wday, t.tm_mday, t.tm_mon, t.tm_year +1900, t.tm_hour, t.tm_min, t.tm_sec));
*result = mktime(&t); *result = mktime(&t);
return OK; 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, void validate(int *ret, char *mess, int arg, int retval, char *modename,
enum numberMode nummode) { enum numberMode nummode) {
if (*ret == OK && arg != GET_FLAG && retval != arg) { if (*ret == OK && arg != GET_FLAG && retval != arg) {

View File

@ -7,10 +7,8 @@
#include "sls/ansi.h" #include "sls/ansi.h"
#include "sls/sls_detector_defs.h" #include "sls/sls_detector_defs.h"
#include <fcntl.h> // open #include <fcntl.h> // open
#include <string.h> #include <sys/mman.h> // mmap
#include <sys/mman.h> // mmap
#include <sys/utsname.h> // uname
/* global variables */ /* global variables */
u_int32_t *csp0base = 0; u_int32_t *csp0base = 0;
@ -132,49 +130,3 @@ int mapCSP0(void) {
} }
u_int32_t *Nios_getBaseAddress() { return csp0base; } 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

@ -24,18 +24,37 @@ int gpioDefined = 0;
extern int executeCommand(char *command, char *result, enum TLogLevel level); extern int executeCommand(char *command, char *result, enum TLogLevel level);
int latestKernelVerified = -1;
#define KERNEL_DATE_VRSN_3GPIO "Fri Oct 29 00:00:00 2021"
void defineGPIOpins() { void defineGPIOpins() {
#ifdef VIRTUAL #ifdef VIRTUAL
return; return;
#endif #endif
if (latestKernelVerified == -1) {
if (FAIL == validateKernelVersion(KERNEL_DATE_VRSN_3GPIO)) {
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) { if (!gpioDefined) {
// define the gpio pins // define the gpio pins
system("echo 7 > /sys/class/gpio/export"); system("echo 7 > /sys/class/gpio/export");
system("echo 9 > /sys/class/gpio/export"); LOG(logINFO, ("\tgpio7: defined\n"));
// define their direction
system("echo in > /sys/class/gpio/gpio7/direction"); system("echo in > /sys/class/gpio/gpio7/direction");
system("echo out > /sys/class/gpio/gpio9/direction"); LOG(logINFO, ("\tgpio7: setting intput\n"));
LOG(logINFO, ("gpio pins defined\n")); system("echo 9 > /sys/class/gpio/export");
LOG(logINFO, ("\tgpio9: defined\n"));
if (latestKernelVerified == 1) {
// gpio 3 = not chip enable
system("echo 3 > /sys/class/gpio/export");
LOG(logINFO, ("\tgpio3: defined\n"));
}
gpioDefined = 1; gpioDefined = 1;
} else } else
LOG(logDEBUG1, ("gpio pins already defined earlier\n")); LOG(logDEBUG1, ("gpio pins already defined earlier\n"));
@ -45,8 +64,22 @@ void FPGAdontTouchFlash() {
#ifdef VIRTUAL #ifdef VIRTUAL
return; return;
#endif #endif
// define as output pins
system("echo out > /sys/class/gpio/gpio9/direction");
LOG(logINFO, ("\tgpio9: setting output\n"));
if (latestKernelVerified == 1) {
// gpio 3 = not chip enable
system("echo out > /sys/class/gpio/gpio3/direction");
LOG(logINFO, ("\tgpio3: setting output\n"));
}
// tell FPGA to not touch flash // tell FPGA to not touch flash
system("echo 0 > /sys/class/gpio/gpio9/value"); system("echo 0 > /sys/class/gpio/gpio9/value");
LOG(logINFO, ("\tgpio9: fpga dont touch flash\n"));
if (latestKernelVerified == 1) {
system("echo 1 > /sys/class/gpio/gpio3/value");
LOG(logINFO, ("\tgpio3: fpga dont touch flash\n"));
}
// usleep(100*1000); // usleep(100*1000);
} }
@ -55,7 +88,12 @@ void FPGATouchFlash() {
return; return;
#endif #endif
// tell FPGA to touch flash to program itself // tell FPGA to touch flash to program itself
system("echo 1 > /sys/class/gpio/gpio9/value"); system("echo in > /sys/class/gpio/gpio9/direction");
LOG(logINFO, ("\tgpio9: setting input\n"));
if (latestKernelVerified == 1) {
system("echo in > /sys/class/gpio/gpio3/direction");
LOG(logINFO, ("\tgpio3: setting input\n"));
}
} }
void resetFPGA() { void resetFPGA() {
@ -151,10 +189,9 @@ int copyToFlash(ssize_t fsize, char *clientChecksum, char *mess) {
return FAIL; return FAIL;
} }
/* ignoring this until a consistent way to read from bfin flash /* ignoring this until flash fixed
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName, fsize) == FAIL) { return FAIL;
== FAIL) { return FAIL; }
}
*/ */
if (waitForFPGAtoTouchFlash(mess) == FAIL) { if (waitForFPGAtoTouchFlash(mess) == FAIL) {
return FAIL; return FAIL;

View File

@ -6,10 +6,10 @@
#define APILIB 0x211027 #define APILIB 0x211027
#define APIRECEIVER 0x211020 #define APIRECEIVER 0x211020
#define APIGUI 0x211021 #define APIGUI 0x211021
#define APICTB 0x211027
#define APIGOTTHARD 0x211027
#define APIGOTTHARD2 0x211027
#define APIJUNGFRAU 0x211027
#define APIMYTHEN3 0x211027
#define APIMOENCH 0x211025
#define APIEIGER 0x211027 #define APIEIGER 0x211027
#define APICTB 0x211103
#define APIGOTTHARD 0x211103
#define APIGOTTHARD2 0x211103
#define APIJUNGFRAU 0x211103
#define APIMYTHEN3 0x211103
#define APIMOENCH 0x211103