1.In Nios II Command Shell.bat file:

@ REM : SDK Shell Batch File for Nios II Add-On Kit
@ REM : ——————————————-
@ REM : Invokes bash (in Quartus) with SOPC Builder’s nios_bash
@ REM : as its startup script.  This in turn sources all add-on
@ REM : kits’ shell setup files.
@ REM :
@
@ set SOPC_BUILDER_PATH_72=%SOPC_KIT_NIOS2%+%SOPC_BUILDER_PATH_72%
@ if not exist "%QUARTUS_ROOTDIR%\bin\cygwin\bin\bash.exe" goto errorQ
@ if not exist "%SOPC_KIT_NIOS2%\nios2_sdk_shell_bashrc" goto errorN
@ cd examples
@ "%QUARTUS_ROOTDIR%\bin\cygwin\bin\bash.exe" –rcfile "%SOPC_KIT_NIOS2%

\nios2_sdk_shell_bashrc"
@
@ exit
:errorQ
@ echo .
@ echo . Cannot locate Quartus installation (QUARTUS_ROOTDIR) at:
@ echo .
@ echo .    %QUARTUS_ROOTDIR%
@ echo .    (specifically, the bin\cygwin\bin\bash.exe program within)
@ echo .
@ echo . Please check your paths and try again (running Quartus from
@ echo . the Start Menu may update the paths and fix this problem).
@ echo . Your Quartus II installation may need to be repaired.
@ echo .
@ pause
@ exit

:errorN
@ echo .
@ echo . Cannot locate Nios II Development Kit (SOPC_KIT_NIOS2) at:
@ echo .
@ echo .    %SOPC_KIT_NIOS2%
@ echo .    (specifically, the nios2_sdk_shell_bashrc file within)
@ echo .
@ echo . Your Nios II installation may need to be repaired.
@ echo .
@ pause
@ exit

@ REM : end of file

2. So this .dat file will actually invoke bash to execute nios2_sdk_shell_bashrc, let’s look into this script:

# file: nios2_sdk_shell_bashrc
#
# 2004.03.15 dvb
#
# +————————————————
# | This is the Nios II Kit SDK Shell rc file
# |
# | It calls the standard SOPC Builder rc file, first, and
# | then patches a few things up to do with replicated
# | scripts and revisions, so that the ones provided
# | with Nios II take precedence.
# |

# |
# | call the SOPC Builder standard script
# |

. "$QUARTUS_ROOTDIR/sopc_builder/bin/nios_bash"

# |
# | Alias things we like very much
# |

alias nb=nios2-build
alias nios-build=nios2-build
alias nr=nios2-run
alias nios-run=nios2-run
alias nd=nios2-debug
alias nios-debug=nios2-debug
alias nc=nios2-console
alias nios-console=nios2-console

# End of file

3. Now here come the real work for script thing, which is H:\Altera\72\quartus\sopc_builder\bin\nios_bash:

#
# nios_bash – set up nios development environment for ‘bash’ shell
#             ($sopc_builder must point to installation directory)
#
#

# +—————————
# | source_kit_bashes
# |
# | loop through all the installed kits,
# | and for each, if it has a kit_bash, source
# | it.
# |
# | (SOPC_BUILDER_PATH has things besides kits,
# | but thats ok. kit_bash’s get sourced, that’s the
# | important thing.)
# |
# | dvb 2003

source_kit_bashes ()
    {
    old_IFS=$IFS
    IFS="+"

    for potential_kit_dir in $SOPC_BUILDER_PATH${SOPC_BUILDER_PATH:++}$SOPC_BUILDER_PATH_72
    do
        IFS=$old_IFS
        if [ -f "$potential_kit_dir/kit_bash" ]
        then
            old_dir=`pwd`
            cd "$potential_kit_dir"
            . ./kit_bash
            cd "$old_dir"
        fi
        IFS="+"
    done

    IFS=$old_IFS
    }

# safe_alias
#  will only set alias if it’s not set.
#  $1 is alias name, $2 is alias command
safe_alias ()
{
    if [ -z "$(alias | grep ‘$1=’)" ]
    then
        alias $1="$2"
    fi
}

if [ "$NIOS_BASH_RUN_7_2" != "" ]
then
    return 0
    # already we’ve run once!
fi
NIOS_BASH_RUN_7_2=1

#
# IF the old path had a cygwin1.dll in it, then we
# surely dont want to add it back to the path. Sorry.
# It would conflict with the one we know we have.
# (This could only happen on Windows/Cygwin; will
# have no effect on linux, &c.) dvb05
#

do_append_previous_path=1

if [ -f /bin/cygpath ]
then
    if [ "`/bin/which cygwin1.dll 2> /dev/null`" != "" ]
    then
        do_append_previous_path=0
        echo "."
        echo ". Removing old PATH, because a copy of"
        echo ". cygwin1.dll was found at: "
        echo ".     `/bin/which cygwin1.dll`"
        echo ". You can remove or rename it to avoid conflict."
        echo "."
    fi
fi

PATH_BEFORE_NIOS_BASH=$PATH
export PATH_BEFORE_NIOS_BASH
PATH="/bin:/usr/bin"

if [ $do_append_previous_path = "1" ]
then
    PATH=$PATH:$PATH_BEFORE_NIOS_BASH
fi

unset do_append_previous_path

# correct paths which may come from DOS
export QUARTUS_ROOTDIR=${QUARTUS_ROOTDIR//\\\\/\/}
export sopc_builder=${sopc_builder:-$QUARTUS_ROOTDIR/sopc_builder}

# set up environment via nios_sh, which deals with paths, etc.
# this is the essential setup; everything else is convenience
source "$sopc_builder/bin/nios_sh"

# set window title
printf "33]2;SOPC Builder 7.2\a"

# set prompt
PS1="\[\e[32;2m\]\w\[\e[0m\]\n[SOPC Builder]$ "

echo ————————————————
echo Welcome To Altera SOPC Builder
echo
echo Version 7.2, Built Tue Nov 20 21:50:25 PST 2007
echo ————————————————

# +———————-
# | conveniences
# |
alias nb=nios-build
safe_alias ll ‘ls -lF’
safe_alias vi ‘vim’
safe_alias view ‘vim -R’
safe_alias m ‘make -s’

# +———————-
# | safety features for typical
# | users. Disable at great risk.
# |

safe_alias cp ‘cp -ip’
safe_alias mv ‘mv -i’
safe_alias rm ‘rm -i’
safe_alias ls ‘ls -AF’

safe_alias awk gawk
safe_alias clear clearn

    # +—————
    # | handy things for other kits
    # |

    source_kit_bashes

    # +—————

# |
# | And while we are busy printing helpful tips,
# | let us inform the user if they have a
# | particularly bad version of cygwin1.dll
# |
# | (If we dont see it in the usual spot, we
# | remain silent on the issue.)
# |

if [ -f /bin/cygwin1.dll ]
then
    cygwin_dll_size=`find /bin -name cygwin1.dll -printf %s`
    if [ $cygwin_dll_size = 804728 ]
    then
        echo .
        echo .
        echo . By the by:
        echo .
        echo .  You should STRONGLY CONSIDER upgrading your
        echo .  version 1.0 /bin/cygwin1.dll file. The version
        echo .  you have may crash GDB, among other problems.
        echo .  We have tested 1.3.10 with good results.
        echo .
        echo ————————————————
    fi
fi

unset safe_alias
unset source_kit_bashes
So if anything need to be added for Nios II SOPC Builder, just add those scripts in this file.

Advertisements