mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
server side fixed
This commit is contained in:
parent
7b4f8c118b
commit
64a25a242b
@ -17,7 +17,7 @@ add_executable(ctbDetectorServer_virtual
|
|||||||
../slsDetectorServer/src/INA226.c
|
../slsDetectorServer/src/INA226.c
|
||||||
../slsDetectorServer/src/LTC2620.c
|
../slsDetectorServer/src/LTC2620.c
|
||||||
../slsDetectorServer/src/MAX1932.c
|
../slsDetectorServer/src/MAX1932.c
|
||||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
../slsDetectorServer/src/programViaBlackfin.c
|
||||||
../slsDetectorServer/src/sharedMemory.c
|
../slsDetectorServer/src/sharedMemory.c
|
||||||
../slsDetectorServer/src/loadPattern.c
|
../slsDetectorServer/src/loadPattern.c
|
||||||
../../slsSupportLib/src/md5.c
|
../../slsSupportLib/src/md5.c
|
||||||
|
@ -16,7 +16,7 @@ DESTDIR ?= bin
|
|||||||
INSTMODE = 0777
|
INSTMODE = 0777
|
||||||
|
|
||||||
SRCS = slsDetectorFunctionList.c
|
SRCS = slsDetectorFunctionList.c
|
||||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)/sharedMemory.c $(main_src)/loadPattern.c $(md5_dir)md5.c
|
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programViaBlackfin.c $(main_src)/sharedMemory.c $(main_src)/loadPattern.c $(md5_dir)md5.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ add_executable(gotthard2DetectorServer_virtual
|
|||||||
../slsDetectorServer/src/LTC2620_Driver.c
|
../slsDetectorServer/src/LTC2620_Driver.c
|
||||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||||
../slsDetectorServer/src/ASIC_Driver.c
|
../slsDetectorServer/src/ASIC_Driver.c
|
||||||
../slsDetectorServer/src/programFpgaNios.c
|
../slsDetectorServer/src/programViaNios.c
|
||||||
../slsDetectorServer/src/sharedMemory.c
|
../slsDetectorServer/src/sharedMemory.c
|
||||||
../../slsSupportLib/src/md5.c
|
../../slsSupportLib/src/md5.c
|
||||||
)
|
)
|
||||||
|
@ -15,7 +15,7 @@ DESTDIR ?= bin
|
|||||||
INSTMODE = 0777
|
INSTMODE = 0777
|
||||||
|
|
||||||
SRCS = slsDetectorFunctionList.c
|
SRCS = slsDetectorFunctionList.c
|
||||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)common.c $(main_src)DAC6571.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)ASIC_Driver.c $(main_src)/programFpgaNios.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)common.c $(main_src)DAC6571.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)ASIC_Driver.c $(main_src)/programViaNios.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ add_executable(gotthardDetectorServer_virtual
|
|||||||
../slsDetectorServer/src/LTC2620.c
|
../slsDetectorServer/src/LTC2620.c
|
||||||
../slsDetectorServer/src/common.c
|
../slsDetectorServer/src/common.c
|
||||||
../slsDetectorServer/src/commonServerFunctions.c
|
../slsDetectorServer/src/commonServerFunctions.c
|
||||||
|
../slsDetectorServer/src/programViaBlackfin.c
|
||||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||||
../slsDetectorServer/src/sharedMemory.c
|
../slsDetectorServer/src/sharedMemory.c
|
||||||
../../slsSupportLib/src/md5.c
|
../../slsSupportLib/src/md5.c
|
||||||
|
@ -15,7 +15,7 @@ DESTDIR ?= bin
|
|||||||
INSTMODE = 0777
|
INSTMODE = 0777
|
||||||
|
|
||||||
SRCS = slsDetectorFunctionList.c
|
SRCS = slsDetectorFunctionList.c
|
||||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)AD9252.c $(main_src)AD9257.c $(main_src)LTC2620.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)AD9252.c $(main_src)AD9257.c $(main_src)LTC2620.c $(main_src)programViaBlackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
all: clean $(PROGS)
|
all: clean $(PROGS)
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#define LINKED_SERVER_NAME "gotthardDetectorServer"
|
#define LINKED_SERVER_NAME "gotthardDetectorServer"
|
||||||
|
|
||||||
|
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
||||||
|
|
||||||
/* Enums */
|
/* Enums */
|
||||||
enum ADCINDEX { TEMP_FPGA, TEMP_ADC };
|
enum ADCINDEX { TEMP_FPGA, TEMP_ADC };
|
||||||
enum DACINDEX {
|
enum DACINDEX {
|
||||||
|
@ -12,7 +12,7 @@ add_executable(jungfrauDetectorServer_virtual
|
|||||||
../slsDetectorServer/src/ALTERA_PLL.c
|
../slsDetectorServer/src/ALTERA_PLL.c
|
||||||
../slsDetectorServer/src/LTC2620.c
|
../slsDetectorServer/src/LTC2620.c
|
||||||
../slsDetectorServer/src/MAX1932.c
|
../slsDetectorServer/src/MAX1932.c
|
||||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
../slsDetectorServer/src/programViaBlackfin.c
|
||||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||||
../slsDetectorServer/src/sharedMemory.c
|
../slsDetectorServer/src/sharedMemory.c
|
||||||
../../slsSupportLib/src/md5.c
|
../../slsSupportLib/src/md5.c
|
||||||
|
@ -15,7 +15,7 @@ DESTDIR ?= bin
|
|||||||
INSTMODE = 0777
|
INSTMODE = 0777
|
||||||
|
|
||||||
SRCS = slsDetectorFunctionList.c
|
SRCS = slsDetectorFunctionList.c
|
||||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programViaBlackfin.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ add_executable(moenchDetectorServer_virtual
|
|||||||
../slsDetectorServer/src/ALTERA_PLL.c
|
../slsDetectorServer/src/ALTERA_PLL.c
|
||||||
../slsDetectorServer/src/LTC2620.c
|
../slsDetectorServer/src/LTC2620.c
|
||||||
../slsDetectorServer/src/MAX1932.c
|
../slsDetectorServer/src/MAX1932.c
|
||||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
../slsDetectorServer/src/programViaBlackfin.c
|
||||||
../slsDetectorServer/src/loadPattern.c
|
../slsDetectorServer/src/loadPattern.c
|
||||||
../slsDetectorServer/src/sharedMemory.c
|
../slsDetectorServer/src/sharedMemory.c
|
||||||
../../slsSupportLib/src/md5.c
|
../../slsSupportLib/src/md5.c
|
||||||
|
@ -16,7 +16,7 @@ DESTDIR ?= bin
|
|||||||
INSTMODE = 0777
|
INSTMODE = 0777
|
||||||
|
|
||||||
SRCS = slsDetectorFunctionList.c
|
SRCS = slsDetectorFunctionList.c
|
||||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)loadPattern.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programViaBlackfin.c $(main_src)loadPattern.c $(main_src)/sharedMemory.c $(md5_dir)md5.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ add_executable(mythen3DetectorServer_virtual
|
|||||||
../slsDetectorServer/src/common.c
|
../slsDetectorServer/src/common.c
|
||||||
../slsDetectorServer/src/LTC2620_Driver.c
|
../slsDetectorServer/src/LTC2620_Driver.c
|
||||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||||
../slsDetectorServer/src/programFpgaNios.c
|
../slsDetectorServer/src/programViaNios.c
|
||||||
../slsDetectorServer/src/loadPattern.c
|
../slsDetectorServer/src/loadPattern.c
|
||||||
../slsDetectorServer/src/sharedMemory.c
|
../slsDetectorServer/src/sharedMemory.c
|
||||||
../../slsSupportLib/src/md5.c
|
../../slsSupportLib/src/md5.c
|
||||||
|
@ -16,7 +16,7 @@ DESTDIR ?= bin
|
|||||||
INSTMODE = 0777
|
INSTMODE = 0777
|
||||||
|
|
||||||
SRCS = slsDetectorFunctionList.c
|
SRCS = slsDetectorFunctionList.c
|
||||||
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programFpgaNios.c $(main_src)/sharedMemory.c $(main_src)/loadPattern.c mythen3.c $(md5_dir)md5.c
|
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programViaNios.c $(main_src)/sharedMemory.c $(main_src)/loadPattern.c mythen3.c $(md5_dir)md5.c
|
||||||
|
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
enum numberMode { DEC, HEX };
|
enum numberMode { DEC, HEX };
|
||||||
|
enum PROGRAM_INDEX { PROGRAM_FPGA, PROGRAM_KERNEL, PROGRAM_SERVER };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a value from a range to a different range (eg voltage to dac or vice
|
* Convert a value from a range to a different range (eg voltage to dac or vice
|
||||||
@ -28,7 +29,7 @@ int getAbsPath(char *buf, size_t bufSize, char *fname);
|
|||||||
|
|
||||||
int getTimeFromString(char *buf, time_t *result);
|
int getTimeFromString(char *buf, time_t *result);
|
||||||
|
|
||||||
int getKernelVersion(char* retvals);
|
int getKernelVersion(char *retvals);
|
||||||
|
|
||||||
int validateKernelVersion(char *expectedVersion);
|
int validateKernelVersion(char *expectedVersion);
|
||||||
|
|
||||||
@ -38,9 +39,11 @@ void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
|
|||||||
char *modename, enum numberMode nummode);
|
char *modename, enum numberMode nummode);
|
||||||
|
|
||||||
int getModuleIdInFile(int *ret, char *mess, char *fileName);
|
int getModuleIdInFile(int *ret, char *mess, char *fileName);
|
||||||
int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
int verifyChecksumFromBuffer(char *mess, char *functionType,
|
||||||
ssize_t bytes);
|
char *clientChecksum, char *buffer, ssize_t bytes);
|
||||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname);
|
int verifyChecksumFromFile(char *mess, char *functionType, char *clientChecksum,
|
||||||
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
char *fname);
|
||||||
ssize_t fsize);
|
int verifyChecksumFromFlash(char *mess, char *functionType,
|
||||||
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c, char *msg);
|
char *clientChecksum, char *fname, ssize_t fsize);
|
||||||
|
int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
|
||||||
|
MD5_CTX *c, char *msg);
|
@ -2,6 +2,8 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -21,15 +23,17 @@ int emptyTempFolder(char *mess);
|
|||||||
* verify memory available to copy
|
* verify memory available to copy
|
||||||
* open file to copy
|
* open file to copy
|
||||||
*/
|
*/
|
||||||
int preparetoCopyProgram(FILE **fd, uint64_t fsize, char *mess);
|
int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
|
||||||
int copyToFlash(enum PROGRAMINDEX index, char *mType, ssize_t fsize,
|
uint64_t fsize);
|
||||||
char *clientChecksum, char *mess);
|
int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
|
||||||
int getDrive(enum PROGRAMINDEX index, char *mess);
|
char *functionType, char *clientChecksum,
|
||||||
|
ssize_t fsize);
|
||||||
|
int getDrive(char *mess, enum PROGRAM_INDEX index);
|
||||||
/** Notify fpga not to touch flash, open src and flash drive to write */
|
/** Notify fpga not to touch flash, open src and flash drive to write */
|
||||||
int openFileForFlash(FILE **flashfd, FILE **srcfd, char *mess);
|
int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd);
|
||||||
int eraseFlash(char *mess);
|
int eraseFlash(char *mess);
|
||||||
/* write from tmp file to flash */
|
/* write from tmp file to flash */
|
||||||
int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess);
|
int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, FILE *srcfd);
|
||||||
/** Notify fpga to pick up firmware from flash and wait for status confirmation
|
/** Notify fpga to pick up firmware from flash and wait for status confirmation
|
||||||
*/
|
*/
|
||||||
int waitForFPGAtoTouchFlash(char *mess);
|
int waitForFPGAtoTouchFlash(char *mess);
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -13,9 +15,10 @@ void NotifyServerStartSuccess();
|
|||||||
/** reset fpga and controller(only implemented for >= v1.1 boards) */
|
/** reset fpga and controller(only implemented for >= v1.1 boards) */
|
||||||
void rebootControllerAndFPGA();
|
void rebootControllerAndFPGA();
|
||||||
|
|
||||||
int eraseAndWriteToFlash(char *mess, char *checksum, char *fpgasrc,
|
int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
|
||||||
|
char *functionType, char *checksum, char *fpgasrc,
|
||||||
uint64_t fsize);
|
uint64_t fsize);
|
||||||
int getDrive(char *mess);
|
int getDrive(char *mess, enum PROGRAM_INDEX index);
|
||||||
int openFileForFlash(FILE **flashfd, char *mess);
|
int openFileForFlash(char *mess, FILE **flashfd);
|
||||||
int eraseFlash(char *mess);
|
int eraseFlash(char *mess);
|
||||||
int writeToFlash(ssize_t fsize, FILE *flashfd, char *buffer, char *mess);
|
int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, char *buffer);
|
@ -13,7 +13,8 @@
|
|||||||
|
|
||||||
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
#if defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||||
#include "programViaNios.h"
|
#include "programViaNios.h"
|
||||||
#elif defined(CHIPTESTBOARDD) || defined(JUNGFRAUD) || defined(MOENCHD)
|
#elif defined(CHIPTESTBOARDD) || defined(JUNGFRAUD) || defined(MOENCHD) || \
|
||||||
|
defined(GOTTHARDD)
|
||||||
#include "programViaBlackfin.h"
|
#include "programViaBlackfin.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -60,7 +61,6 @@ typedef struct udpStruct_s {
|
|||||||
int isInitCheckDone();
|
int isInitCheckDone();
|
||||||
int getInitResult(char **mess);
|
int getInitResult(char **mess);
|
||||||
void basictests();
|
void basictests();
|
||||||
int getKernelVersion(char *retvals);
|
|
||||||
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || \
|
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || \
|
||||||
defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
|
defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
|
||||||
int checkType();
|
int checkType();
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#define GOODBYE (-200)
|
#define GOODBYE (-200)
|
||||||
#define REBOOT (-400)
|
#define REBOOT (-400)
|
||||||
|
|
||||||
enum PROGRAMINDEX {FPGA_PROGRAM, KERNEL_PROGRAM, SERVER_PROGRAM}
|
|
||||||
|
|
||||||
// initialization functions
|
// initialization functions
|
||||||
int printSocketReadError();
|
int printSocketReadError();
|
||||||
void init_detector();
|
void init_detector();
|
||||||
@ -121,10 +119,6 @@ int get_transmission_delay_left(int);
|
|||||||
int set_transmission_delay_right(int);
|
int set_transmission_delay_right(int);
|
||||||
int get_transmission_delay_right(int);
|
int get_transmission_delay_right(int);
|
||||||
int program_fpga(int);
|
int program_fpga(int);
|
||||||
void program_fpga_via_blackfin(int file_des, enum PROGRAMINDEX index,
|
|
||||||
uint64_t filesize, char *checksum);
|
|
||||||
void program_fpga_via_nios(int file_des, enum PROGRAMINDEX index,
|
|
||||||
uint64_t filesize, char *checksum);
|
|
||||||
int reset_fpga(int);
|
int reset_fpga(int);
|
||||||
int power_chip(int);
|
int power_chip(int);
|
||||||
int set_activate(int);
|
int set_activate(int);
|
||||||
@ -284,4 +278,12 @@ int set_udp_first_dest(int);
|
|||||||
int get_readout_speed(int);
|
int get_readout_speed(int);
|
||||||
int set_readout_speed(int);
|
int set_readout_speed(int);
|
||||||
int get_kernel_version(int);
|
int get_kernel_version(int);
|
||||||
int program_kernel(int);
|
int update_kernel(int);
|
||||||
|
int update_detector_server(int);
|
||||||
|
int receive_program(int file_des, enum PROGRAM_INDEX index);
|
||||||
|
void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
|
||||||
|
char *functionType, uint64_t filesize,
|
||||||
|
char *checksum);
|
||||||
|
void receive_program_default(int file_des, enum PROGRAM_INDEX index,
|
||||||
|
char *functionType, uint64_t filesize,
|
||||||
|
char *checksum);
|
@ -92,13 +92,15 @@ int getTimeFromString(char *buf, time_t *result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print time structure
|
// 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));
|
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 getKernelVersion(char* retvals) {
|
int getKernelVersion(char *retvals) {
|
||||||
struct utsname buf = {0};
|
struct utsname buf = {0};
|
||||||
if (uname(&buf) == -1) {
|
if (uname(&buf) == -1) {
|
||||||
strcpy(retvals, "Failed to get utsname structure from uname\n");
|
strcpy(retvals, "Failed to get utsname structure from uname\n");
|
||||||
@ -135,7 +137,8 @@ int validateKernelVersion(char *expectedVersion) {
|
|||||||
// convert kernel date string into time
|
// convert kernel date string into time
|
||||||
time_t kernelDate;
|
time_t kernelDate;
|
||||||
if (getTimeFromString(currentVersion, &kernelDate) == FAIL) {
|
if (getTimeFromString(currentVersion, &kernelDate) == FAIL) {
|
||||||
LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", currentVersion));
|
LOG(logERROR,
|
||||||
|
("Could not parse retrieved kernel date, %s\n", currentVersion));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,8 +158,8 @@ int validateKernelVersion(char *expectedVersion) {
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", currentVersion,
|
LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n",
|
||||||
expectedVersion));
|
currentVersion, expectedVersion));
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,30 +238,39 @@ int getModuleIdInFile(int *ret, char *mess, char *fileName) {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int verifyChecksumFromBuffer(char *mess, char *clientChecksum, char *buffer,
|
int verifyChecksumFromBuffer(char *mess, char *functionType,
|
||||||
|
char *clientChecksum, char *buffer,
|
||||||
ssize_t bytes) {
|
ssize_t bytes) {
|
||||||
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
if (!MD5_Init_SLS(&c)) {
|
if (!MD5_Init_SLS(&c)) {
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Init_SLS)\n");
|
sprintf(mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Init_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (!MD5_Update_SLS(&c, buffer, bytes)) {
|
if (!MD5_Update_SLS(&c, buffer, bytes)) {
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Update_SLS)\n");
|
sprintf(mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Update_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
return verifyChecksum(mess, clientChecksum, &c, "copied program");
|
return verifyChecksum(mess, functionType, clientChecksum, &c,
|
||||||
|
"copied program");
|
||||||
}
|
}
|
||||||
|
|
||||||
int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
int verifyChecksumFromFile(char *mess, char *functionType, char *clientChecksum,
|
||||||
|
char *fname) {
|
||||||
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
LOG(logINFO, ("\tVerifying Checksum...\n"));
|
||||||
|
|
||||||
FILE *fp = fopen(fname, "r");
|
FILE *fp = fopen(fname, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
sprintf(mess, "Unable to open %s in read mode to get checksum\n",
|
sprintf(
|
||||||
fname);
|
mess,
|
||||||
|
"Could not %s. Unable to open %s in read mode to get checksum\n",
|
||||||
|
functionType, fname);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -266,7 +278,9 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
|||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
if (!MD5_Init_SLS(&c)) {
|
if (!MD5_Init_SLS(&c)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Init_SLS)\n");
|
sprintf(mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Init_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -277,7 +291,10 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
|||||||
while (bytes > 0) {
|
while (bytes > 0) {
|
||||||
if (!MD5_Update_SLS(&c, buf, bytes)) {
|
if (!MD5_Update_SLS(&c, buf, bytes)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Update_SLS)\n");
|
sprintf(
|
||||||
|
mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Update_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -286,17 +303,20 @@ int verifyChecksumFromFile(char *mess, char *clientChecksum, char *fname) {
|
|||||||
}
|
}
|
||||||
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return verifyChecksum(mess, clientChecksum, &c, "copied program");
|
return verifyChecksum(mess, functionType, clientChecksum, &c,
|
||||||
|
"copied program");
|
||||||
}
|
}
|
||||||
|
|
||||||
int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
int verifyChecksumFromFlash(char *mess, char *functionType,
|
||||||
ssize_t fsize) {
|
char *clientChecksum, char *fname, ssize_t fsize) {
|
||||||
LOG(logINFO, ("\tVerifying FlashChecksum...\n"));
|
LOG(logINFO, ("\tVerifying FlashChecksum...\n"));
|
||||||
|
|
||||||
FILE *fp = fopen(fname, "r");
|
FILE *fp = fopen(fname, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
sprintf(mess, "Unable to open %s in read mode to get checksum\n",
|
sprintf(
|
||||||
fname);
|
mess,
|
||||||
|
"Could not %s. Unable to open %s in read mode to get checksum\n",
|
||||||
|
functionType, fname);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -304,7 +324,9 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
|||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
if (!MD5_Init_SLS(&c)) {
|
if (!MD5_Init_SLS(&c)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Init_SLS)\n");
|
sprintf(mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Init_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -324,7 +346,10 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
|||||||
|
|
||||||
if (!MD5_Update_SLS(&c, buf, bytes)) {
|
if (!MD5_Update_SLS(&c, buf, bytes)) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Update_SLS)\n");
|
sprintf(
|
||||||
|
mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Update_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -340,17 +365,20 @@ int verifyChecksumFromFlash(char *mess, char *clientChecksum, char *fname,
|
|||||||
}
|
}
|
||||||
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
LOG(logINFO, ("\tRead %lu bytes to calculate checksum\n", totalBytesRead));
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
int ret = verifyChecksum(mess, clientChecksum, &c, "flash");
|
int ret = verifyChecksum(mess, functionType, clientChecksum, &c, "flash");
|
||||||
if (ret == OK) {
|
if (ret == OK) {
|
||||||
LOG(logINFO, ("Checksum in Flash verified\n"));
|
LOG(logINFO, ("\tChecksum in Flash verified\n"));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c, char *msg) {
|
int verifyChecksum(char *mess, char *functionType, char *clientChecksum,
|
||||||
|
MD5_CTX *c, char *msg) {
|
||||||
unsigned char out[MD5_DIGEST_LENGTH];
|
unsigned char out[MD5_DIGEST_LENGTH];
|
||||||
if (!MD5_Final_SLS(out, c)) {
|
if (!MD5_Final_SLS(out, c)) {
|
||||||
strcpy(mess, "Unable to calculate checksum (MD5_Final_SLS)\n");
|
sprintf(mess,
|
||||||
|
"Could not %s. Unable to calculate checksum (MD5_Final_SLS)\n",
|
||||||
|
functionType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -370,9 +398,9 @@ int verifyChecksum(char *mess, char *clientChecksum, MD5_CTX *c, char *msg) {
|
|||||||
// compare checksum
|
// compare checksum
|
||||||
if (strcmp(clientChecksum, checksum)) {
|
if (strcmp(clientChecksum, checksum)) {
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Checksum of %s does not match. Client "
|
"Could not %s. Checksum of %s does not match. Client "
|
||||||
"checksum:%s, copied checksum:%s\n",
|
"checksum:%s, copied checksum:%s\n",
|
||||||
msg, clientChecksum, checksum);
|
functionType, msg, clientChecksum, checksum);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,19 @@
|
|||||||
#define CMD_FPGA_PICKED_STATUS "cat /sys/class/gpio/gpio7/value"
|
#define CMD_FPGA_PICKED_STATUS "cat /sys/class/gpio/gpio7/value"
|
||||||
|
|
||||||
#define CMD_GET_FPGA_FLASH_DRIVE "awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd"
|
#define CMD_GET_FPGA_FLASH_DRIVE "awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd"
|
||||||
#define CMD_GET_KERNEL_FLASH_DRIVE "awk \'$4== \"\\\"linux kernel(nor)\\\"\" {print $1}\' /proc/mtd"
|
#define CMD_GET_KERNEL_FLASH_DRIVE "awk \'$4== \"\\\"linux\\\"\" {print $1}\' /proc/mtd"
|
||||||
|
|
||||||
#define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB
|
#define FLASH_BUFFER_MEMORY_SIZE (128 * 1024) // 500 KB
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#define FLASH_DRIVE_NAME_SIZE 16
|
#define FLASH_DRIVE_NAME_SIZE 16
|
||||||
|
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = "/tmp/SLS_mtd3";
|
||||||
|
#else
|
||||||
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
||||||
|
#endif
|
||||||
|
|
||||||
char messageType[SHORT_STR_LENGTH] = {0};
|
char messageType[SHORT_STR_LENGTH] = {0};
|
||||||
int gpioDefined = 0;
|
int gpioDefined = 0;
|
||||||
|
|
||||||
@ -109,6 +115,7 @@ int FPGAdontTouchFlash(char *mess) {
|
|||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
// define gpio9 as output
|
// define gpio9 as output
|
||||||
if (executeCommand(CMD_GPIO9_DEFINE_OUT, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(CMD_GPIO9_DEFINE_OUT, retvals, logDEBUG1) == FAIL) {
|
||||||
snprintf(mess, MAX_STR_LENGTH,
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
@ -155,6 +162,7 @@ int FPGATouchFlash(char *mess) {
|
|||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
// tell FPGA to touch flash to program itself
|
// tell FPGA to touch flash to program itself
|
||||||
if (executeCommand(CMD_GPIO9_DEFINE_IN, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(CMD_GPIO9_DEFINE_IN, retvals, logDEBUG1) == FAIL) {
|
||||||
snprintf(mess, MAX_STR_LENGTH,
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
@ -211,7 +219,8 @@ int emptyTempFolder(char *mess) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int preparetoCopyProgram(FILE **fd, uint64_t fsize, char *mess) {
|
int preparetoCopyProgram(char *mess, char *functionType, FILE **fd,
|
||||||
|
uint64_t fsize) {
|
||||||
|
|
||||||
if (emptyTempFolder(mess) == FAIL) {
|
if (emptyTempFolder(mess) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -223,9 +232,9 @@ int preparetoCopyProgram(FILE **fd, uint64_t fsize, char *mess) {
|
|||||||
sysinfo(&info);
|
sysinfo(&info);
|
||||||
if (fsize >= info.freeram) {
|
if (fsize >= info.freeram) {
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Could not update program. Not enough memory to copy "
|
"Could not %s. Not enough memory to copy "
|
||||||
"program. [File size:%ldMB, free RAM: %ldMB]\n",
|
"program. [File size:%ldMB, free RAM: %ldMB]\n",
|
||||||
(long int)(fsize / (1024 * 1024)),
|
functionType, (long int)(fsize / (1024 * 1024)),
|
||||||
(long int)(info.freeram / (1024 * 1024)));
|
(long int)(info.freeram / (1024 * 1024)));
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -235,7 +244,8 @@ int preparetoCopyProgram(FILE **fd, uint64_t fsize, char *mess) {
|
|||||||
// open file to copy program
|
// open file to copy program
|
||||||
*fd = fopen(TEMP_PROG_FILE_NAME, "w");
|
*fd = fopen(TEMP_PROG_FILE_NAME, "w");
|
||||||
if (*fd == NULL) {
|
if (*fd == NULL) {
|
||||||
sprintf(mess, "Unable to open %s in write mode\n", TEMP_PROG_FILE_NAME);
|
sprintf(mess, "Could not %s. Unable to open %s in write mode\n",
|
||||||
|
functionType, TEMP_PROG_FILE_NAME);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -243,24 +253,25 @@ int preparetoCopyProgram(FILE **fd, uint64_t fsize, char *mess) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int copyToFlash(enum PROGRAMINDEX index, char *mType, ssize_t fsize,
|
int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
|
||||||
char *clientChecksum, char *mess) {
|
char *functionType, char *clientChecksum,
|
||||||
|
ssize_t fsize) {
|
||||||
|
|
||||||
memset(messageType, 0, sizeof(messageType));
|
memset(messageType, 0, sizeof(messageType));
|
||||||
strcpy(messageType, mType);
|
strcpy(messageType, functionType);
|
||||||
|
|
||||||
if (getDrive(index, messageType, mess) == FAIL) {
|
if (getDrive(mess, index) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *flashfd = NULL;
|
FILE *flashfd = NULL;
|
||||||
FILE *srcfd = NULL;
|
FILE *srcfd = NULL;
|
||||||
if (openFileForFlash(&flashfd, &srcfd, mess) == FAIL) {
|
if (openFileForFlash(mess, &flashfd, &srcfd) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == FPGA_PROGRAM) {
|
if (index == PROGRAM_FPGA) {
|
||||||
if (FPGAdontTouchFlash(char *mess) == FAIL) {
|
if (FPGAdontTouchFlash(mess) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,7 +282,7 @@ int copyToFlash(enum PROGRAMINDEX index, char *mType, ssize_t fsize,
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeToFlash(fsize, flashfd, srcfd, mess) == FAIL) {
|
if (writeToFlash(mess, fsize, flashfd, srcfd) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,14 +291,14 @@ int copyToFlash(enum PROGRAMINDEX index, char *mType, ssize_t fsize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* remove condition when flash fpga fixed */
|
/* remove condition when flash fpga fixed */
|
||||||
if (index == KERNEL_PROGRAM) {
|
if (index == PROGRAM_KERNEL) {
|
||||||
if (verifyChecksumFromFlash(mess, clientChecksum, flashDriveName,
|
if (verifyChecksumFromFlash(mess, messageType, clientChecksum,
|
||||||
fsize) == FAIL) {
|
flashDriveName, fsize) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index == FPGA_PROGRAM) {
|
if (index == PROGRAM_FPGA) {
|
||||||
if (waitForFPGAtoTouchFlash(mess) == FAIL) {
|
if (waitForFPGAtoTouchFlash(mess) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -295,6 +306,7 @@ int copyToFlash(enum PROGRAMINDEX index, char *mType, ssize_t fsize,
|
|||||||
|
|
||||||
// kernel
|
// kernel
|
||||||
else {
|
else {
|
||||||
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
if (executeCommand("sync", retvals, logDEBUG1) == FAIL) {
|
if (executeCommand("sync", retvals, logDEBUG1) == FAIL) {
|
||||||
snprintf(mess, MAX_STR_LENGTH,
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
"Could not update %s. (could not sync)\n", messageType);
|
"Could not update %s. (could not sync)\n", messageType);
|
||||||
@ -306,9 +318,8 @@ int copyToFlash(enum PROGRAMINDEX index, char *mType, ssize_t fsize,
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDrive(enum PROGRAMINDEX index, char *mess) {
|
int getDrive(char *mess, enum PROGRAM_INDEX index) {
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
strcpy(flashDriveName, "/tmp/SLS_tmpDrive");
|
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
LOG(logDEBUG1, ("Finding flash drive...\n"));
|
LOG(logDEBUG1, ("Finding flash drive...\n"));
|
||||||
@ -323,23 +334,23 @@ int getDrive(enum PROGRAMINDEX index, char *mess) {
|
|||||||
char cmd[MAX_STR_LENGTH] = {0};
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
|
|
||||||
if (index == FPGA_PROGRAM) {
|
if (index == PROGRAM_FPGA) {
|
||||||
strcpy(cmd, CMD_GET_FPGA_FLASH_DRIVE);
|
strcpy(cmd, CMD_GET_FPGA_FLASH_DRIVE);
|
||||||
} else {
|
} else {
|
||||||
strcpy(cmd, CMD_GET_KERNEL_FLASH_DRIVE);
|
strcpy(cmd, CMD_GET_KERNEL_FLASH_DRIVE);
|
||||||
}
|
}
|
||||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
snprintf(mess, MAX_STR_LENGTH,
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
"Could not update %s. (could not get flash drive: %s)\n",
|
"Could not %s. (could not get flash drive: %s)\n", messageType,
|
||||||
messageType, retvals);
|
retvals);
|
||||||
// LOG(logERROR, (mess)); already printed in executecommand
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pch = strtok(retvals, ":");
|
char *pch = strtok(retvals, ":");
|
||||||
if (pch == NULL) {
|
if (pch == NULL) {
|
||||||
strcpy(mess,
|
sprintf(mess,
|
||||||
"Could not update %s. Could not get mtd drive to flash (strtok "
|
"Could not %s. Could not get mtd drive to flash (strtok "
|
||||||
"fail).\n",
|
"fail).\n",
|
||||||
messageType);
|
messageType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
@ -347,19 +358,17 @@ int getDrive(enum PROGRAMINDEX index, char *mess) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memset(flashDriveName, 0, sizeof(flashDriveName));
|
memset(flashDriveName, 0, sizeof(flashDriveName));
|
||||||
strcpy(flashDriveName, "/dev/");
|
sprintf(flashDriveName, "/dev/%s", pch);
|
||||||
strcat(flashDriveName, pch);
|
|
||||||
LOG(logINFO, ("\tFlash drive found: %s\n", flashDriveName));
|
LOG(logINFO, ("\tFlash drive found: %s\n", flashDriveName));
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int openFileForFlash(FILE **flashfd, FILE **srcfd, char *mess) {
|
int openFileForFlash(char *mess, FILE **flashfd, FILE **srcfd) {
|
||||||
// open src file
|
// open src file
|
||||||
*srcfd = fopen(TEMP_PROG_FILE_NAME, "r");
|
*srcfd = fopen(TEMP_PROG_FILE_NAME, "r");
|
||||||
if (*srcfd == NULL) {
|
if (*srcfd == NULL) {
|
||||||
sprintf(
|
sprintf(mess,
|
||||||
mess,
|
"Could not %s. Unable to open temp program file %s in read "
|
||||||
"Could not update %s. Unable to open temp program file %s in read "
|
|
||||||
"mode\n",
|
"mode\n",
|
||||||
messageType, TEMP_PROG_FILE_NAME);
|
messageType, TEMP_PROG_FILE_NAME);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
@ -372,7 +381,7 @@ int openFileForFlash(FILE **flashfd, FILE **srcfd, char *mess) {
|
|||||||
if (*flashfd == NULL) {
|
if (*flashfd == NULL) {
|
||||||
fclose(*srcfd);
|
fclose(*srcfd);
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Could not update %s. Unable to open flash drive %s in write "
|
"Could not %s. Unable to open flash drive %s in write "
|
||||||
"mode\n",
|
"mode\n",
|
||||||
messageType, flashDriveName);
|
messageType, flashDriveName);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
@ -393,8 +402,7 @@ int eraseFlash(char *mess) {
|
|||||||
char *format = "flash_eraseall %s";
|
char *format = "flash_eraseall %s";
|
||||||
if (snprintf(cmd, MAX_STR_LENGTH, format, flashDriveName) >=
|
if (snprintf(cmd, MAX_STR_LENGTH, format, flashDriveName) >=
|
||||||
MAX_STR_LENGTH) {
|
MAX_STR_LENGTH) {
|
||||||
sprintf(mess,
|
sprintf(mess, "Could not %s. Command to erase flash is too long\n",
|
||||||
"Could not update %s. Command to erase flash is too long\n",
|
|
||||||
messageType);
|
messageType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -410,7 +418,7 @@ int eraseFlash(char *mess) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, FILE *srcfd) {
|
||||||
LOG(logDEBUG1, ("writing to flash\n"));
|
LOG(logDEBUG1, ("writing to flash\n"));
|
||||||
|
|
||||||
char *buffer = malloc(FLASH_BUFFER_MEMORY_SIZE);
|
char *buffer = malloc(FLASH_BUFFER_MEMORY_SIZE);
|
||||||
@ -418,7 +426,7 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
|||||||
fclose(flashfd);
|
fclose(flashfd);
|
||||||
fclose(srcfd);
|
fclose(srcfd);
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Could not update %s. Memory allocation to write to "
|
"Could not %s. Memory allocation to write to "
|
||||||
"flash failed.\n",
|
"flash failed.\n",
|
||||||
messageType);
|
messageType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
@ -442,7 +450,7 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
|||||||
fclose(flashfd);
|
fclose(flashfd);
|
||||||
fclose(srcfd);
|
fclose(srcfd);
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Could not update %s. Could not write to flash (bytes "
|
"Could not %s. Could not write to flash (bytes "
|
||||||
"written:%ld, expected: "
|
"written:%ld, expected: "
|
||||||
"%ld, total written:%ld)\n",
|
"%ld, total written:%ld)\n",
|
||||||
messageType, (long int)bytesWritten, (long int)bytes,
|
messageType, (long int)bytesWritten, (long int)bytes,
|
||||||
@ -475,7 +483,7 @@ int writeToFlash(ssize_t fsize, FILE *flashfd, FILE *srcfd, char *mess) {
|
|||||||
|
|
||||||
if (totalBytes != fsize) {
|
if (totalBytes != fsize) {
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Could not update %s. Incorrect bytes written to flash %lu "
|
"Could not %s. Incorrect bytes written to flash %lu "
|
||||||
"[expected: %lu]\n",
|
"[expected: %lu]\n",
|
||||||
messageType, totalBytes, fsize);
|
messageType, totalBytes, fsize);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
|
@ -11,10 +11,19 @@
|
|||||||
|
|
||||||
/* global variables */
|
/* global variables */
|
||||||
|
|
||||||
#define CMD_GET_FLASH "awk \'$5== \"Application\" {print $1}\' /proc/mtd"
|
#define CMD_GET_FPGA_FLASH_DRIVE \
|
||||||
|
"awk \'$5== \"Application\" {print $1}\' /proc/mtd"
|
||||||
|
#define CMD_GET_KERNEL_FLASH_DRIVE "awk \'$5== \"Linux\" {print $1}\' /proc/mtd"
|
||||||
|
|
||||||
#define FLASH_DRIVE_NAME_SIZE 16
|
#define FLASH_DRIVE_NAME_SIZE 16
|
||||||
|
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = "/tmp/SLS_mtd3";
|
||||||
|
#else
|
||||||
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
char flashDriveName[FLASH_DRIVE_NAME_SIZE] = {0};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char messageType[SHORT_STR_LENGTH] = {0};
|
||||||
#define MICROCONTROLLER_FILE "/dev/ttyAL0"
|
#define MICROCONTROLLER_FILE "/dev/ttyAL0"
|
||||||
|
|
||||||
extern int executeCommand(char *command, char *result, enum TLogLevel level);
|
extern int executeCommand(char *command, char *result, enum TLogLevel level);
|
||||||
@ -35,15 +44,19 @@ void rebootControllerAndFPGA() {
|
|||||||
system(command);
|
system(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
int eraseAndWriteToFlash(char *mess, char *checksum, char *fpgasrc,
|
int eraseAndWriteToFlash(char *mess, enum PROGRAM_INDEX index,
|
||||||
|
char *functionType, char *checksum, char *fpgasrc,
|
||||||
uint64_t fsize) {
|
uint64_t fsize) {
|
||||||
|
|
||||||
if (getDrive(mess) == FAIL) {
|
memset(messageType, 0, sizeof(messageType));
|
||||||
|
strcpy(messageType, functionType);
|
||||||
|
|
||||||
|
if (getDrive(mess, index) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *flashfd = NULL;
|
FILE *flashfd = NULL;
|
||||||
if (openFileForFlash(&flashfd, mess) == FAIL) {
|
if (openFileForFlash(mess, &flashfd) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,21 +65,33 @@ int eraseAndWriteToFlash(char *mess, char *checksum, char *fpgasrc,
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeToFlash(fsize, flashfd, fpgasrc, mess) == FAIL) {
|
if (writeToFlash(mess, fsize, flashfd, fpgasrc) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
/* ignoring this until a consistent way to read from nios flash
|
|
||||||
if (verifyChecksumFromFlash(mess, checksum, flashDriveName, fsize) ==
|
/* remove condition when flash fpga fixed */
|
||||||
FAIL) {
|
if (index == PROGRAM_KERNEL) {
|
||||||
|
if (verifyChecksumFromFlash(mess, messageType, checksum, flashDriveName,
|
||||||
|
fsize) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
if (index == PROGRAM_KERNEL) {
|
||||||
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
|
if (executeCommand("sync", retvals, logDEBUG1) == FAIL) {
|
||||||
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
|
"Could not update %s. (could not sync)\n", messageType);
|
||||||
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getDrive(char *mess) {
|
int getDrive(char *mess, enum PROGRAM_INDEX index) {
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
strcpy(flashDriveName, "/tmp/SLS_mtd3");
|
|
||||||
return OK;
|
return OK;
|
||||||
#endif
|
#endif
|
||||||
LOG(logDEBUG1, ("Finding flash drive...\n"));
|
LOG(logDEBUG1, ("Finding flash drive...\n"));
|
||||||
@ -82,10 +107,15 @@ int getDrive(char *mess) {
|
|||||||
|
|
||||||
char cmd[MAX_STR_LENGTH] = {0};
|
char cmd[MAX_STR_LENGTH] = {0};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH] = {0};
|
||||||
strcpy(cmd, CMD_GET_FLASH);
|
|
||||||
|
if (index == PROGRAM_FPGA) {
|
||||||
|
strcpy(cmd, CMD_GET_FPGA_FLASH_DRIVE);
|
||||||
|
} else {
|
||||||
|
strcpy(cmd, CMD_GET_KERNEL_FLASH_DRIVE);
|
||||||
|
}
|
||||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
snprintf(mess, MAX_STR_LENGTH,
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
"Could not program fpga. (could not get flash drive: %s)\n",
|
"Could not %s. (could not get flash drive: %s)\n", messageType,
|
||||||
retvals);
|
retvals);
|
||||||
// LOG(logERROR, (mess)); already printed in executecommand
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -93,7 +123,10 @@ int getDrive(char *mess) {
|
|||||||
|
|
||||||
char *pch = strtok(retvals, ":");
|
char *pch = strtok(retvals, ":");
|
||||||
if (pch == NULL) {
|
if (pch == NULL) {
|
||||||
strcpy(mess, "Could not get mtd drive to flash (strtok fail).\n");
|
sprintf(
|
||||||
|
mess,
|
||||||
|
"Could not %s. Could not get mtd drive to flash (strtok fail).\n",
|
||||||
|
messageType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -105,11 +138,12 @@ int getDrive(char *mess) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int openFileForFlash(FILE **flashfd, char *mess) {
|
int openFileForFlash(char *mess, FILE **flashfd) {
|
||||||
*flashfd = fopen(flashDriveName, "w");
|
*flashfd = fopen(flashDriveName, "w");
|
||||||
if (*flashfd == NULL) {
|
if (*flashfd == NULL) {
|
||||||
sprintf(mess, "Unable to open flash drive %s in write mode\n",
|
sprintf(mess,
|
||||||
flashDriveName);
|
"Could not %s. Unable to open flash drive %s in write mode\n",
|
||||||
|
messageType, flashDriveName);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@ -129,14 +163,14 @@ int eraseFlash(char *mess) {
|
|||||||
char *format = "flash_erase %s 0 0";
|
char *format = "flash_erase %s 0 0";
|
||||||
if (snprintf(cmd, MAX_STR_LENGTH, format, flashDriveName) >=
|
if (snprintf(cmd, MAX_STR_LENGTH, format, flashDriveName) >=
|
||||||
MAX_STR_LENGTH) {
|
MAX_STR_LENGTH) {
|
||||||
strcpy(mess,
|
sprintf(mess, "Could not %s. Command to erase flash is too long\n",
|
||||||
"Could not program fpga. Command to erase flash is too long\n");
|
messageType);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) {
|
||||||
snprintf(mess, MAX_STR_LENGTH,
|
snprintf(mess, MAX_STR_LENGTH,
|
||||||
"Could not program fpga. (could not erase flash: %s)\n",
|
"Could not %s. (could not erase flash: %s)\n", messageType,
|
||||||
retvals);
|
retvals);
|
||||||
// LOG(logERROR, (mess)); already printed in executecommand
|
// LOG(logERROR, (mess)); already printed in executecommand
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@ -146,16 +180,16 @@ int eraseFlash(char *mess) {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int writeToFlash(ssize_t fsize, FILE *flashfd, char *buffer, char *mess) {
|
int writeToFlash(char *mess, ssize_t fsize, FILE *flashfd, char *buffer) {
|
||||||
LOG(logINFO, ("\tWriting to Flash...\n"));
|
LOG(logINFO, ("\tWriting to Flash...\n"));
|
||||||
|
|
||||||
ssize_t bytesWritten = fwrite((void *)buffer, sizeof(char), fsize, flashfd);
|
ssize_t bytesWritten = fwrite((void *)buffer, sizeof(char), fsize, flashfd);
|
||||||
if (bytesWritten != fsize) {
|
if (bytesWritten != fsize) {
|
||||||
fclose(flashfd);
|
fclose(flashfd);
|
||||||
sprintf(mess,
|
sprintf(mess,
|
||||||
"Could not program fpga. Incorrect bytes written to flash %lu "
|
"Could not %s. Incorrect bytes written to flash %lu "
|
||||||
"[expected: %lu]\n",
|
"[expected: %lu]\n",
|
||||||
(long int)bytesWritten, (long int)fsize);
|
messageType, (long int)bytesWritten, (long int)fsize);
|
||||||
LOG(logERROR, (mess));
|
LOG(logERROR, (mess));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,8 @@ void function_table() {
|
|||||||
flist[F_GET_READOUT_SPEED] = &get_readout_speed;
|
flist[F_GET_READOUT_SPEED] = &get_readout_speed;
|
||||||
flist[F_SET_READOUT_SPEED] = &set_readout_speed;
|
flist[F_SET_READOUT_SPEED] = &set_readout_speed;
|
||||||
flist[F_GET_KERNEL_VERSION] = &get_kernel_version;
|
flist[F_GET_KERNEL_VERSION] = &get_kernel_version;
|
||||||
flist[F_PROGRAM_KERNEL] = &program_kernel;
|
flist[F_UPDATE_KERNEL] = &update_kernel;
|
||||||
|
flist[F_UPDATE_DETECTOR_SERVER] = &update_detector_server;
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||||
@ -3648,195 +3649,11 @@ int program_fpga(int file_des) {
|
|||||||
n = receiveData(file_des, mess, MAX_STR_LENGTH, OTHER);
|
n = receiveData(file_des, mess, MAX_STR_LENGTH, OTHER);
|
||||||
functionNotImplemented();
|
functionNotImplemented();
|
||||||
#else
|
#else
|
||||||
// only set
|
receive_program(file_des, PROGRAM_FPGA);
|
||||||
if (Server_VerifyLock() == OK) {
|
|
||||||
|
|
||||||
LOG(logINFOBLUE, ("Programming FPGA...\n"));
|
|
||||||
|
|
||||||
// filesize
|
|
||||||
uint64_t filesize = 0;
|
|
||||||
if (receiveData(file_des, &filesize, sizeof(filesize), INT64) < 0)
|
|
||||||
return printSocketReadError();
|
|
||||||
LOG(logDEBUG1, ("Program size is: %lld\n", (long long int)filesize));
|
|
||||||
|
|
||||||
// checksum
|
|
||||||
char checksum[MAX_STR_LENGTH];
|
|
||||||
memset(checksum, 0, MAX_STR_LENGTH);
|
|
||||||
if (receiveData(file_des, checksum, MAX_STR_LENGTH, OTHER) < 0)
|
|
||||||
return printSocketReadError();
|
|
||||||
LOG(logDEBUG1, ("checksum is: %s\n\n", checksum));
|
|
||||||
|
|
||||||
switch (myDetectorType) {
|
|
||||||
case MYTHEN3:
|
|
||||||
case GOTTHARD2:
|
|
||||||
program_fpga_via_nios(file_des, FPGA_PROGRAM, filesize, checksum);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
program_fpga_via_blackfin(file_des, FPGA_PROGRAM, filesize,
|
|
||||||
checksum);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == OK) {
|
|
||||||
LOG(logINFOGREEN, ("Programming FPGA completed successfully\n"));
|
|
||||||
} else {
|
|
||||||
LOG(logERROR, ("Program FPGA FAIL!\n"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void program_fpga_via_blackfin(int file_des, enum PROGRAMINDEX index,
|
|
||||||
uint64_t filesize, char *checksum) {
|
|
||||||
char messageType[SHORT_STR_LENGTH] = {0};
|
|
||||||
switch (index) {
|
|
||||||
case FPGA_PROGRAM:
|
|
||||||
strcpy(messageType, "fpga program");
|
|
||||||
break;
|
|
||||||
case KERNEL_PROGRAM:
|
|
||||||
strcpy(messageType, "kernel program");
|
|
||||||
break;
|
|
||||||
case SERVER_PROGRAM:
|
|
||||||
strcpy(messageType, "server program");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ret = FAIL;
|
|
||||||
sprintf(mess, "Unknown program index %d\n", index);
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// open file and allocate memory for part program
|
|
||||||
FILE *fd = NULL;
|
|
||||||
ret = preparetoCopyProgram(&fd, filesize, mess);
|
|
||||||
char *src = NULL;
|
|
||||||
if (ret == OK) {
|
|
||||||
src = malloc(MAX_BLACKFIN_PROGRAM_SIZE);
|
|
||||||
if (src == NULL) {
|
|
||||||
fclose(fd);
|
|
||||||
struct sysinfo info;
|
|
||||||
sysinfo(&info);
|
|
||||||
sprintf(mess,
|
|
||||||
"Could not allocate memory to get %s. Free "
|
|
||||||
"space: %d MB\n",
|
|
||||||
messageType, (int)(info.freeram / (1024 * 1024)));
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
ret = FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
if (ret == FAIL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copying program part by part
|
|
||||||
uint64_t totalsize = filesize;
|
|
||||||
while (ret == OK && filesize) {
|
|
||||||
uint64_t unitprogramsize = MAX_BLACKFIN_PROGRAM_SIZE;
|
|
||||||
if (unitprogramsize > filesize)
|
|
||||||
unitprogramsize = filesize;
|
|
||||||
LOG(logDEBUG1, ("unit size to receive is:%lld [filesize:%lld]\n",
|
|
||||||
(long long unsigned int)unitprogramsize,
|
|
||||||
(long long unsigned int)filesize));
|
|
||||||
|
|
||||||
// receive part of program
|
|
||||||
if (receiveData(file_des, src, unitprogramsize, OTHER) < 0) {
|
|
||||||
printSocketReadError();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
filesize -= unitprogramsize;
|
|
||||||
|
|
||||||
// copy program
|
|
||||||
if (fwrite((void *)src, sizeof(char), unitprogramsize, fd) !=
|
|
||||||
unitprogramsize) {
|
|
||||||
ret = FAIL;
|
|
||||||
sprintf(mess, "Could not copy program to /var/tmp (size:%ld)\n",
|
|
||||||
(long int)unitprogramsize);
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
}
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
if (ret == FAIL) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// print progress
|
|
||||||
LOG(logINFO,
|
|
||||||
("\t%d%%\r",
|
|
||||||
(int)(((double)(totalsize - filesize) / totalsize) * 100)));
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
free(src);
|
|
||||||
fclose(fd);
|
|
||||||
|
|
||||||
// checksum of copied program
|
|
||||||
if (ret == OK) {
|
|
||||||
ret = verifyChecksumFromFile(mess, checksum, TEMP_PROG_FILE_NAME);
|
|
||||||
}
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
if (ret == FAIL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// erase and copy to flash
|
|
||||||
ret = copyToFlash(index, messageType, totalsize, checksum, mess);
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void program_fpga_via_nios(int file_des, uint64_t filesize, char *checksum) {
|
|
||||||
// validate file size
|
|
||||||
if (filesize > NIOS_MAX_APP_IMAGE_SIZE) {
|
|
||||||
ret = FAIL;
|
|
||||||
sprintf(mess,
|
|
||||||
"Could not start programming FPGA. File size 0x%llx "
|
|
||||||
"exceeds max size 0x%llx. Forgot Compression?\n",
|
|
||||||
(long long unsigned int)filesize,
|
|
||||||
(long long unsigned int)NIOS_MAX_APP_IMAGE_SIZE);
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
}
|
|
||||||
// memory allocation
|
|
||||||
char *src = NULL;
|
|
||||||
if (ret == OK) {
|
|
||||||
src = malloc(filesize);
|
|
||||||
if (src == NULL) {
|
|
||||||
fclose(fd);
|
|
||||||
struct sysinfo info;
|
|
||||||
sysinfo(&info);
|
|
||||||
sprintf(mess,
|
|
||||||
"Could not allocate memory to get %s. Free "
|
|
||||||
"space: %d MB\n",
|
|
||||||
messageType, (int)(info.freeram / (1024 * 1024)));
|
|
||||||
LOG(logERROR, (mess));
|
|
||||||
ret = FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
if (ret == FAIL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// receive program
|
|
||||||
if (receiveData(file_des, src, filesize, OTHER) < 0) {
|
|
||||||
free(src);
|
|
||||||
ret = printSocketReadError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// checksum of copied program
|
|
||||||
if (ret == OK) {
|
|
||||||
ret = verifyChecksumFromBuffer(mess, checksum, src, fsize);
|
|
||||||
}
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
if (ret == FAIL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// erase and program
|
|
||||||
ret = eraseAndWriteToFlash(mess, checksum, src, filesize);
|
|
||||||
Server_SendResult(file_des, INT32, NULL, 0);
|
|
||||||
free(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
int reset_fpga(int file_des) {
|
int reset_fpga(int file_des) {
|
||||||
ret = OK;
|
ret = OK;
|
||||||
memset(mess, 0, sizeof(mess));
|
memset(mess, 0, sizeof(mess));
|
||||||
@ -3850,16 +3667,24 @@ int reset_fpga(int file_des) {
|
|||||||
if (Server_VerifyLock() == OK) {
|
if (Server_VerifyLock() == OK) {
|
||||||
if (isControlServer) {
|
if (isControlServer) {
|
||||||
basictests(); // mapping of control server at least
|
basictests(); // mapping of control server at least
|
||||||
if (initError == OK) {
|
char *message = NULL;
|
||||||
|
if (getInitResult(&message) == FAIL) {
|
||||||
|
ret = FAIL;
|
||||||
|
strcpy(mess, message);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
} else {
|
||||||
initControlServer();
|
initControlServer();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
initStopServer(); // remapping of stop server
|
initStopServer(); // remapping of stop server
|
||||||
}
|
}
|
||||||
if (initError == FAIL) {
|
if (ret == OK) {
|
||||||
|
char *message = NULL;
|
||||||
|
if (getInitResult(&message) == FAIL) {
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
strcpy(mess, initErrorMessage);
|
strcpy(mess, message);
|
||||||
// LOG(ERROR (mess));already printed
|
LOG(logERROR, (mess));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -9492,9 +9317,261 @@ int get_kernel_version(int file_des) {
|
|||||||
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
|
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
|
||||||
}
|
}
|
||||||
|
|
||||||
int program_kernel(int file_des) {
|
int update_kernel(int file_des) {
|
||||||
ret = OK;
|
ret = OK;
|
||||||
memset(mess, 0, sizeof(mess));
|
memset(mess, 0, sizeof(mess));
|
||||||
|
#if !defined(JUNGFRAUD) && !defined(CHIPTESTBOARDD) && !defined(MOENCHD) && \
|
||||||
|
!defined(GOTTHARDD)
|
||||||
|
// to receive any arguments
|
||||||
|
int n = 1;
|
||||||
|
while (n > 0)
|
||||||
|
n = receiveData(file_des, mess, MAX_STR_LENGTH, OTHER);
|
||||||
|
functionNotImplemented();
|
||||||
|
#else
|
||||||
|
receive_program(file_des, PROGRAM_FPGA);
|
||||||
|
#endif
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int update_detector_server(int file_des) {
|
||||||
|
ret = OK;
|
||||||
|
memset(mess, 0, sizeof(mess));
|
||||||
|
return receive_program(file_des, PROGRAM_SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
int receive_program(int file_des, enum PROGRAM_INDEX index) {
|
||||||
|
// only set
|
||||||
|
if (Server_VerifyLock() == OK) {
|
||||||
|
char functionType[SHORT_STR_LENGTH] = {0};
|
||||||
|
switch (index) {
|
||||||
|
case PROGRAM_FPGA:
|
||||||
|
strcpy(functionType, "Update Firmware");
|
||||||
|
break;
|
||||||
|
case PROGRAM_KERNEL:
|
||||||
|
strcpy(functionType, "Update Kernel");
|
||||||
|
break;
|
||||||
|
case PROGRAM_SERVER:
|
||||||
|
strcpy(functionType, "Update Server");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
LOG(logINFOBLUE, ("%s ...\n", functionType));
|
||||||
|
|
||||||
|
// filesize
|
||||||
|
uint64_t filesize = 0;
|
||||||
|
if (receiveData(file_des, &filesize, sizeof(filesize), INT64) < 0)
|
||||||
|
return printSocketReadError();
|
||||||
|
LOG(logDEBUG1, ("Program size is: %lld\n", (long long int)filesize));
|
||||||
|
|
||||||
|
// client checksum
|
||||||
|
char checksum[MAX_STR_LENGTH];
|
||||||
|
memset(checksum, 0, MAX_STR_LENGTH);
|
||||||
|
if (receiveData(file_des, checksum, MAX_STR_LENGTH, OTHER) < 0)
|
||||||
|
return printSocketReadError();
|
||||||
|
LOG(logDEBUG1, ("checksum is: %s\n\n", checksum));
|
||||||
|
|
||||||
|
#if defined(GOTTHARD2D) || defined(MYTHEN3D) || defined(EIGERD)
|
||||||
|
receive_program_default(file_des, index, functionType, filesize,
|
||||||
|
checksum);
|
||||||
|
#else
|
||||||
|
receive_program_via_blackfin(file_des, index, functionType, filesize,
|
||||||
|
checksum);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ret == OK) {
|
||||||
|
LOG(logINFOGREEN, ("%s completed successfully\n", functionType));
|
||||||
|
} else {
|
||||||
|
LOG(logERROR, ("%s FAIL!\n", functionType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
|
||||||
|
char *functionType, uint64_t filesize,
|
||||||
|
char *checksum) {
|
||||||
|
|
||||||
|
#if !defined(JUNGFRAUD) && !defined(CHIPTESTBOARDD) && !defined(MOENCHD) && \
|
||||||
|
!defined(GOTTHARDD)
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(mess,
|
||||||
|
"Could not %s. program via blackfin not implmented for this "
|
||||||
|
"detector.\n",
|
||||||
|
functionType);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
#else
|
||||||
|
// open file and allocate memory for part program
|
||||||
|
FILE *fd = NULL;
|
||||||
|
ret = preparetoCopyProgram(mess, functionType, &fd, filesize);
|
||||||
|
char *src = NULL;
|
||||||
|
if (ret == OK) {
|
||||||
|
src = malloc(MAX_BLACKFIN_PROGRAM_SIZE);
|
||||||
|
if (src == NULL) {
|
||||||
|
fclose(fd);
|
||||||
|
struct sysinfo info;
|
||||||
|
sysinfo(&info);
|
||||||
|
sprintf(mess,
|
||||||
|
"Could not %s. Memory allocation failure. Free "
|
||||||
|
"space: %d MB\n",
|
||||||
|
functionType, (int)(info.freeram / (1024 * 1024)));
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
if (ret == FAIL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copying program part by part
|
||||||
|
uint64_t totalsize = filesize;
|
||||||
|
while (ret == OK && filesize) {
|
||||||
|
uint64_t unitprogramsize = MAX_BLACKFIN_PROGRAM_SIZE;
|
||||||
|
if (unitprogramsize > filesize)
|
||||||
|
unitprogramsize = filesize;
|
||||||
|
LOG(logDEBUG1, ("unit size to receive is:%lld [filesize:%lld]\n",
|
||||||
|
(long long unsigned int)unitprogramsize,
|
||||||
|
(long long unsigned int)filesize));
|
||||||
|
|
||||||
|
// receive part of program
|
||||||
|
if (receiveData(file_des, src, unitprogramsize, OTHER) < 0) {
|
||||||
|
printSocketReadError();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
filesize -= unitprogramsize;
|
||||||
|
|
||||||
|
// copy program
|
||||||
|
if (fwrite((void *)src, sizeof(char), unitprogramsize, fd) !=
|
||||||
|
unitprogramsize) {
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(
|
||||||
|
mess,
|
||||||
|
"Could not %s. Could not copy program to /var/tmp (size:%ld)\n",
|
||||||
|
functionType, (long int)unitprogramsize);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
}
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
if (ret == FAIL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// print progress
|
||||||
|
LOG(logINFO,
|
||||||
|
("\t%d%%\r",
|
||||||
|
(int)(((double)(totalsize - filesize) / totalsize) * 100)));
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
free(src);
|
||||||
|
fclose(fd);
|
||||||
|
|
||||||
|
// checksum of copied program
|
||||||
|
if (ret == OK) {
|
||||||
|
ret = verifyChecksumFromFile(mess, functionType, checksum,
|
||||||
|
TEMP_PROG_FILE_NAME);
|
||||||
|
}
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
if (ret == FAIL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// appropriate functions
|
||||||
|
switch (index) {
|
||||||
|
case PROGRAM_FPGA:
|
||||||
|
case PROGRAM_KERNEL:
|
||||||
|
ret =
|
||||||
|
eraseAndWriteToFlash(mess, index, functionType, checksum, filesize);
|
||||||
|
break;
|
||||||
|
case PROGRAM_SERVER:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
modeNotImplemented("Program index", (int)index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// erase and copy to flash
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void receive_program_default(int file_des, enum PROGRAM_INDEX index,
|
||||||
|
char *functionType, uint64_t filesize,
|
||||||
|
char *checksum) {
|
||||||
|
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D) && !defined(EIGERD)
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(mess,
|
||||||
|
"Could not %s. program via blackfin not implmented for this "
|
||||||
|
"detector.\n",
|
||||||
|
functionType);
|
||||||
|
LOG(logERROR, (mess))
|
||||||
|
#else
|
||||||
|
#if defined(GOTTHARD2D) || defined(MYTHEN3D)
|
||||||
|
// validate file size
|
||||||
|
if (filesize > NIOS_MAX_APP_IMAGE_SIZE) {
|
||||||
|
ret = FAIL;
|
||||||
|
sprintf(mess,
|
||||||
|
"Could not %s. File size 0x%llx "
|
||||||
|
"exceeds max size 0x%llx. Forgot Compression?\n",
|
||||||
|
functionType, (long long unsigned int)filesize,
|
||||||
|
(long long unsigned int)NIOS_MAX_APP_IMAGE_SIZE);
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// memory allocation
|
||||||
|
char *src = NULL;
|
||||||
|
if (ret == OK) {
|
||||||
|
src = malloc(filesize);
|
||||||
|
if (src == NULL) {
|
||||||
|
struct sysinfo info;
|
||||||
|
sysinfo(&info);
|
||||||
|
sprintf(mess,
|
||||||
|
"Could not %s. Memory allocation failure. Free "
|
||||||
|
"space: %d MB\n",
|
||||||
|
functionType, (int)(info.freeram / (1024 * 1024)));
|
||||||
|
LOG(logERROR, (mess));
|
||||||
|
ret = FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
if (ret == FAIL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// receive program
|
||||||
|
if (receiveData(file_des, src, filesize, OTHER) < 0) {
|
||||||
|
free(src);
|
||||||
|
ret = printSocketReadError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// checksum of copied program
|
||||||
|
if (ret == OK) {
|
||||||
|
ret = verifyChecksumFromBuffer(mess, functionType, checksum, src,
|
||||||
|
filesize);
|
||||||
|
}
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
if (ret == FAIL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(GOTTHARD2D) || defined(MYTHEN3D)
|
||||||
|
// appropriate functions
|
||||||
|
switch (index) {
|
||||||
|
case PROGRAM_FPGA:
|
||||||
|
case PROGRAM_KERNEL:
|
||||||
|
ret = eraseAndWriteToFlash(mess, index, functionType, checksum, src,
|
||||||
|
filesize);
|
||||||
|
break;
|
||||||
|
case PROGRAM_SERVER:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
modeNotImplemented("Program index", (int)index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// send result
|
||||||
|
Server_SendResult(file_des, INT32, NULL, 0);
|
||||||
|
|
||||||
|
// free resources
|
||||||
|
free(src);
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user