Skip to content
Snippets Groups Projects
Commit ee5b1861 authored by BRONES Romain's avatar BRONES Romain
Browse files

feat(init): Change daemon logic

* Add a reload statement to only reprog the FPGA
* FPGA bitstream is now linked
* Conf is always read
* Change status
parent 3e56feb3
No related branches found
No related tags found
No related merge requests found
......@@ -2,14 +2,27 @@
. /etc/init.d/functions
PATH_CFG="/opt/fofb/cfg"
PATH_MAP="/opt/fofb/map"
PATH_CFG="/opt/fofb/cfg/"
PATH_MAP="/opt/fofb/map/"
PATH_FPGABIN=${PATH_CFG}/fpga_bitstream.bin
LOCK_FILE=/var/lock/subsys/fofb-init
shopt -s expand_aliases
alias log="logger -t \"fofb-fpgainit\""
link_dev() {
# Installing /dev links
# Reading the configuration file
CFG_FILE=${PATH_CFG}/configuration
log "Reading configuration file ${CFG_FILE}"
if [ ! -f ${CFG_FILE} ]; then
log -p user.error "Configuration file not found: ${CFG_FILE}"
exit 1
fi
source ${CFG_FILE}
########################################################################
# Look for UIO devices, make special symbolic link for axiapp and ddr4
link_uio_dev() {
for uio in /sys/class/uio/*
do
name=$(cat ${uio}/name)
......@@ -18,8 +31,6 @@ link_dev() {
axiapp)
log "Installing link /dev/$name -> /dev/$uiobn"
ln -sf /dev/$uiobn /dev/$name
log "Create dmap file to axi app UIO ${PATH_MAP}/appuio.dmap"
echo "APPUIO (uio:${uiobn}?map=${PATH_MAP}/app.mapt)" > ${PATH_MAP}/appuio.dmap
;;
ddr4)
log "Installing link /dev/$name -> /dev/$uiobn"
......@@ -28,26 +39,55 @@ link_dev() {
*)
;;
esac
done
}
read_conf() {
CFG_FILE=${PATH_CFG}/configuration
log "Reading configuration file ${CFG_FILE}"
if [ ! -f ${CFG_FILE} ]; then
log -p user.error "Configuration file not found: ${CFG_FILE}"
########################################################################
# Link the proper FPGA bitstream depending on the configuration variable FOFB_APP
link_fpga_bitstream() {
if [ -z FOFB_APP ]; then
log -p user.error "Variable FOFB_APP not set in configuration file ${CFG_FILE}"
exit 1
fi
source ${CFG_FILE}
PATH_TARGET=/lib/firmware/base/${FOFB_APP}/pl-full.bit.bin
if [ ! -e $PATH_TARGET ]; then
log -p user.error "Could not establish FOFB application"
exit 1
fi
log "Linking FPGA bitstream ${PATH_TARGET}"
ln -sf ${PATH_TARGET} ${PATH_FPGABIN}
}
########################################################################
# Link the proper MAPT file depending on FOFB_APP
# Generate the DMAP file with correct UIO dev
# Add LNM device if specified in FOFB_LNM
link_mapt() {
if [ -z FOFB_APP ]; then
log -p user.error "Variable FOFB_APP not set in configuration file ${CFG_FILE}"
exit 1
fi
LINK_TARGET="${PATH_MAP}/app_${FOFB_APP}.mapt"
if [ ! -f ${LINK_TARGET} ]; then
log -p user.error "MAPT file not found: ${LINK_TARGET}"
exit 1
fi
log "Linking map file ${LINK_TARGET}"
ln -sf ${LINK_TARGET} ${PATH_MAP}/app.mapt
log "Create dmap file to axi app UIO ${PATH_MAP}/appuio.dmap"
echo "APPUIO (uio:$(basename $(readlink /dev/axiapp))?map=${PATH_MAP}/app.mapt)" > ${PATH_MAP}/appuio.dmap
}
########################################################################
# Link the proper configuration register
link_configuration() {
if [ -z FOFB_CFG ]; then
log -p user.error "Variable FOFB_CFG not set in configuration file ${CFG_FILE}"
......@@ -64,68 +104,68 @@ link_configuration() {
ln -sf ${LINK_TARGET} ${PATH_CFG}/config_register
}
########################################################################
# Write Bitstream
# Reset PS
# Apply register configuration
fpga_reconfig() {
log "Loading FPGA image ${PATH_FPGABIN}"
fpgautil -b ${PATH_FPGABIN} |& log
link_mapt() {
LINK_TARGET="${PATH_MAP}/app_${FOFB_APP}.mapt"
if [ ! -f ${LINK_TARGET} ]; then
log -p user.error "MAPT file not found: ${LINK_TARGET}"
exit 1
fi
log "Reset the FPGA"
/etc/init.d/fw_plreset.sh |& log
log "Linking map file ${LINK_TARGET}"
ln -sf ${LINK_TARGET} ${PATH_MAP}/app.mapt
# Applying configuration
fofb-configurator --config ${PATH_CFG}/config_register --dmap ${PATH_MAP}/appuio.dmap |& log
}
program_fpga() {
if [ -e /lib/firmware/base/${FOFB_APP} ]; then
log "Found configuration ${FOFB_APP}"
else
log -p user.error "Could not establish FOFB application"
########################################################################
########################################################################
########################################################################
# Daemon style handling
reload() {
if [ ! -f $LOCK_FILE ]; then
echo "FOFB application not started, cannot reload"
exit 1
fi
# Taking the last binary file in the sorted list (higher tag)
PATH_FPGABIN=$(ls -S /lib/firmware/base/${FOFB_APP}/*.bin | tail -n 1)
log "Loading FPGA image ${PATH_FPGABIN}"
fpgautil -b ${PATH_FPGABIN} |& log
log "FOFB application: loading application"
fpga_reconfig
echo "started" > $LOCK_FILE
}
reset_fpga() {
# Reset the FPGA
log "Reset the FPGA"
/etc/init.d/fw_plreset.sh |& log
}
start() {
if [ -f $LOCK_FILE ]; then
echo "FOFB application already started, status: $(cat $LOCK_FILE)"
exit 1
fi
configure_fpga() {
# Applying configuration
fofb-configurator --config /opt/fofb/cfg/config_register --dmap /opt/fofb/opcua-server/devices.dmap |& log
}
log "FOFB application: linking configuration"
start() {
rm -f /var/log/fofb-init-done
link_dev
read_conf
link_configuration
link_uio_dev
link_fpga_bitstream
link_mapt
program_fpga
touch /var/log/fofb-init-done
reset_fpga
configure_fpga
link_configuration
echo "configured" > $LOCK_FILE
reload
}
stop() {
log "Nothing to be done"
log "FOFB application: (not really) stopping"
rm -f $LOCK_FILE
}
status() {
if [ -f /var/log/fofb-init-done ]; then
echo "FOFB application initialization done"
if [ -f $LOCK_FILE ]; then
echo "fofb-opcua server status: $(cat $LOCK_FILE)"
else
echo "FOFB application initialization NOT done"
echo "fofb-opcua server status: stopped"
fi
}
### main logic ###
case "$1" in
start)
......@@ -137,7 +177,10 @@ case "$1" in
status)
status
;;
restart|reload|condrestart)
reload)
reload
;;
restart|condrestart)
stop
start
;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment