#!/bin/bash # This is a utility script to (semi) automatically generate files necessary for an Altera HPS build # and move all the generated files to a "deploy" folder. # # Written by: Joshua Einstein # Date: 2015-10-15 # Local Variables EMBEDDED_SHELL=~/altera/14.1/embedded/embedded_command_shell.sh DESIRED_EXTENSION="sopcinfo" printhelp() { echo "Usage: ./makesopc.sh [option] filename.sopcinfo" echo "" echo "Description: Automatically generates necessary output files for an HPS project" echo "based on a compiled FPGA project. filename is required if no options specified" echo "" echo " -s : Enter Altera embedded shell" echo " -d : Deploy files to deploy directory" echo " -g : Generate HPS header files" echo " -h : Print this help" } deploy () { [ -d deploy ] || mkdir deploy cp output_files/soc_system.rbf deploy/ cp software/spl_bsp/preloader-mkpimage.bin deploy/ cp socfpga.dts deploy/ cp socfpga.dtb deploy/ echo "Files moved to deploy folder" } generateheaders () { [ -d software/headers ] || mkdir -p software/headers cd software/headers sopc-create-header-files ../../$1 >/dev/null cd ../.. echo "Headers generated" } testshell() { # Test for if we are in the Altera embedded shell if [ -z ${QUARTUS_ROOTDIR+x} ] then echo "Not in embedded command shell." echo "Please run makesopc.sh -s or enter desired shell manually." exit fi } fullrun () { echo "Beginning file generation process:" echo "Running sopc2dts dts file generation..." sopc2dts --input $1 --output socfpga.dts --type dts --board hps_common_board_info_111.xml --board soc_system_board_info_111.xml --bridge-removal all --clocks echo "Running sopc2dtb dtb file generation..." sopc2dts --input $1 --output socfpga.dtb --type dtb --board hps_common_board_info_111.xml --board soc_system_board_info_111.xml --bridge-removal all --clocks echo "Converting output file..." quartus_cpf --convert output_files/output_file.cof >/dev/null echo "Removing preloader directory..." rm -rf software/spl_bsp echo "Opening bsp-editor for preloader generation..." bsp-editor >/dev/null echo "Running preloader make..." cd software/spl_bsp make all >/dev//null # Return to project root cd ../.. echo "Generating and backing up HPS header files" [ -d software/headers ] || cp -r software/headers software/headers-bu rm -rf software/headers/* generateheaders $1 echo "Moving files for deploy..." deploy } testextension() { if [[ $1 != $DESIRED_EXTENSION ]] then echo "File must be sopcinfo file and have sopcinfo extension." exit fi } # Test file name # extension="${filename##*.}" # Test whether or not to run command based on argument number if [ $# -gt 2 ] || [ $# -eq 0 ] then printhelp exit fi # Save filename and extension of the last parameter passed in for tests. SOPCFILE=${!#} SOPCEXTENSION="${SOPCFILE##*.}" # Get command line options and store in variable option while getopts sdg option; do # Have command to allow script automatically enter shell case "${option}" in s) echo "Entering Altera embedded shell..." $EMBEDDED_SHELL exit;; d) echo "Moving files for deploy..." deploy exit;; g) testextension $SOPCEXTENSION echo "Generating Headers..." generateheaders ${!#} exit;; esac done # Test if we're in the Altera embedded shell or not testshell # Test file extension testextension $SOPCEXTENSION if [[ $SOPCFILE && ${SOPCFILE-x} ]] then fullrun $SOPCFILE else printhelp fi