OpenCores
URL https://opencores.org/ocsvn/radiohdl/radiohdl/trunk

Subversion Repositories radiohdl

[/] [radiohdl/] [trunk/] [quartus/] [run_bsp] - Rev 4

Compare with Previous | Blame | View Log

#!/bin/bash -eu
# -------------------------------------------------------------------------- #
#
# Copyright (C) 2010                                                        
# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
# JIVE (Joint Institute for VLBI in Europe) <http://www.jive.nl/>           
# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands                             
#                                                                           
# This program is free software: you can redistribute it and/or modify      
# it under the terms of the GNU General Public License as published by      
# the Free Software Foundation, either version 3 of the License, or         
# (at your option) any later version.                                       
#                                                                           
# This program is distributed in the hope that it will be useful,           
# but WITHOUT ANY WARRANTY; without even the implied warranty of            
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             
# GNU General Public License for more details.                              
#                                                                           
# You should have received a copy of the GNU General Public License         
# along with this program.  If not, see <http://www.gnu.org/licenses/>.     
#
# -------------------------------------------------------------------------- #

# Run this tool with at least the commandline arguments:
#   run_bsp buildset design_name
# example:
#   run_bsp unb2 unb2_minimal

# read generic functions/definitions
. ${RADIOHDL_GEAR}/generic.sh

# helper function for command parsing
exit_with_error() {
    hdl_error_noexit $0 "$@"
    cat <<@EndOfHelp@
Usage: $(basename $0) [options] buildset project [app]
Arguments: buildset     Name of the buildset to create the app for.
           project      Project file to use for the build.

Options: --no-make:     The make phase is skipped.
         --force:       Force full compilation.
         --bloat:       Compile fullfledged BSP.
--> Note: It does not matter where the options are placed: before, in between or after the arguments.
@EndOfHelp@
    exit 1
}

# parse cmdline
POSITIONAL=()
force=
skip_make=
# BSP HAL settings default to a reduced functionality BSP  (but much less code+data footprint)
# use "--bloat" to compile a fullfledged BSP.
# NOTE: you'll never get C++ or (clean) exit support
hal_lightweight_driver=true
hal_enable_small_libc=1

# parse cmdline
while [[ $# -gt 0 ]]
do
    case $1 in
        --force)
            force="force"
            ;;
        --no-make)
            skip_make="no-make"
            ;;
        --bloat)
            hal_lightweight_driver=false
            hal_enable_small_libc=0
            ;;  
        -*|--*)
            exit_with_error "Unknown option: "$1
            ;;
        *)  POSITIONAL+=("$1")
            ;;
    esac
    shift
done
if [ ${#POSITIONAL[@]} -gt 0 ]; then
    set -- "${POSITIONAL[@]}"
fi

# check the positional parameters
if [ $# -ne 2 ]; then
    exit_with_error "Wrong number of arguments specified."
fi
buildset=$1
project=$2

# read in the configuration based on the user arguments
. ${RADIOHDL_GEAR}/quartus/set_quartus ${buildset}


# check projectfile
PRJS="${RADIOHDL_BUILD_DIR}"
PRJ=
for prj in ${PRJS}
    do
        if [ -d "${prj}/${buildset}/quartus/${project}" ]; then
            PRJ=${prj}
        fi  
    done  
if [ -z "${project}" -o -z "${PRJ}" ]; then
    hdl_error $0 "Please enter a valid project name"
fi

# now we can generate paths
quartusdir="${PRJ}/${buildset}/quartus/${project}"
builddir="${quartusdir}/software"
bspdir="${builddir}/bsp"

# assert the quartusdir exists
hdl_exec $0 msg=no test -d ${quartusdir}

# If we have a makefile see if no-one changed the sopcinfo 
# (since if they did we must re-generate files).
# Otherwise we must generate the BSP package

# if "--force" given we build from scratch
if [ -n "${force}" ]; then
    rm -rf ${bspdir}
fi

if [ -d "${bspdir}" -a -f "${bspdir}/Makefile" ]; then
    #Check if sopcinfo file is newer that current BSP
    # Note: HV/DS  We do this in this clumsy way since
    #       "make -C ${bspdir} -n" and checking the exitcode
    #       does not work on Windows. Winders cannot discriminate
    #       between "time-of-last-access" and "time-of-last-modification"
    #       whereas under Linux this works like a charm.
    #       The result was that under Windows "make -n" would 
    #       always indicate that the target needed to be rebuilt.
    #       Maybe there is another reason - fact is that "make"
    #       didn't work on windows. This does.
    sopcfile=$(ls ${quartusdir}/*sopcinfo 2>/dev/null | sed -n '1p')
    if [ -z "${sopcfile}" ]; then
        hdl_error $0 "No sopc(info) file?!!"
    fi
    if [ ${sopcfile} -nt ${bspdir}/settings.bsp ]; then        
        hdl_info $0 "Someone has been tinkering with .sopcinfo"
        hdl_info $0 "Regenerating the BSP files"
        hdl_exec $0 msg=no nios2-bsp-generate-files \
                                     --bsp-dir ${bspdir} \
                                     --settings ${bspdir}/settings.bsp
    fi
else
    # we must generate the BSP files
    hdl_info $0 "Generating BSP files for ${project}"
    hdl_exec $0 msg=no nios2-bsp hal ${bspdir} ${quartusdir} 
fi

# check if we've already updated the BSP settings to our likings
if [ -f ${bspdir}/public.mk ]; then
        updated_settings=`sed -n '/^ALT_CPPFLAGS *+= *-DALT_USE_DIRECT_DRIVERS/p' ${bspdir}/public.mk`
        if [ -z "${updated_settings}" ]; then
                # nope, not updated yet - set the settings we would like the bsp to have
                hdl_exec $0 nios2-bsp-update-settings --settings ${bspdir}/settings.bsp \
                                        --set hal.enable_lightweight_device_driver_api ${hal_lightweight_driver} \
                                        --set hal.enable_c_plus_plus 0 \
                                        --set hal.enable_clean_exit 0 \
                                        --set hal.enable_exit 0 \
                                        --set hal.enable_small_c_library ${hal_enable_small_libc}
                hdl_exec $0 msg=no nios2-bsp-generate-files \
                                        --bsp-dir ${bspdir} \
                                        --settings ${bspdir}/settings.bsp
                # to prevent the make to complain about settings.bsp newer than Makefile ...
                touch ${bspdir}/Makefile
        fi
fi

if [ -z "${skip_make}" ]; then
    hdl_exec $0 msg=no make -C ${bspdir}
fi

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.