#!/bin/bash

# check variables, like all scripts herein do
WRS_SCRIPT_NAME=$(basename $0)

. ${WRS_BASE_DIR}/scripts/wrs_functions

wrs_check_vars WRS_OUTPUT_DIR

wrs_echo "--- Deploying FPGA firmware"

FWDIR="${WRS_OUTPUT_DIR}/images/wr/lib/firmware"
mkdir -p "$FWDIR"

echo "Using pre-compiled (binaries/) RT firmware"
cp ${WRS_BASE_DIR}/../binaries/rt_cpu.elf "$FWDIR"

if [ "$WRS_HW_DIR" != "" ]; then
    wrs_echo "Copying binaries from $WRS_HW_DIR"
	cp ${WRS_HW_DIR}/syn/scb_8ports/scb_top_synthesis.bin \
	    $FWDIR/8p_mb-LX240T.bin
	cp ${WRS_HW_DIR}/syn/scb_18ports/scb_top_synthesis.bin \
	    $FWDIR/18p_mb-LX240T.bin
else
	tarname="wrs-gw-v5.1-dev1-20190611.tar.gz"
	wrs_echo "Using pre-built binaries from $tarname"
	wrs_download $tarname
	tar xzf $WRS_DOWNLOAD_DIR/$tarname -C $FWDIR
fi
