diff --git a/recipes-app/fofb-init/files/fofb-init.sh b/recipes-app/fofb-init/files/fofb-init.sh index 2067812adfd92ce0c75b54b874152c7fd6f6300b..ef786ce978307d933e83db8a7693b37151fa551d 100755 --- a/recipes-app/fofb-init/files/fofb-init.sh +++ b/recipes-app/fofb-init/files/fofb-init.sh @@ -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 ;; diff --git a/recipes-app/fofb-init/fofb-init_1.2.bb b/recipes-app/fofb-init/fofb-init_1.3.bb similarity index 100% rename from recipes-app/fofb-init/fofb-init_1.2.bb rename to recipes-app/fofb-init/fofb-init_1.3.bb