Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

How to execute NIOS II Command Shell commands from a *.bat file

There is probably a simple solution to this, but I am having a hard time finding it in any of the documentation.

I have four applications that I need to build for a single board. I can build the projects and create the hex files from within the Nios II Command Shell using "make" and "elf2hex". I would like to automate this process. Is there a way to do this with a *.bat file?

Thanks,

John

15 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    "sh -c <command> [args]" might work a bit better.

    Most "bourne-like" shells behave this way. Since the Nios II shell environment is based on Bash ("Bourne Again SHell"), this should work.

    Cheers,

    slacker

    --- Quote End ---

    You don't need 'sh -c' here, that is usually only needed when you need a shell to do filename globbing or stdin/stdout redirection when a program is running something using one of the exec family of functions - eg execl().
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    dsl,

    I'll admit my knowledge of shell files started yesterday, so I have taken your advice.

    slacker,

    I tried a few variations of "sh -c <command> [args]" and it does not work, I cannot get the "Nios II Command Shell.bat" to execute arguments when it is started. I am thinking this is a problem with 9.1.

    Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    This isn't a problem only with 9.1, as I'm in 11.1sp1 and I can't do it either. Being able to auto-execute .sh scripts from my sim and build environments would help streamline things quite a bit, and reduce the amount of user interaction required.

    If ANYONE knows how to automatically run a script at the NIOS shell, it would be greatly greatly appreciated!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The command shell will autorun the script file user.bashrc, so you can use this to make it work.

    My batch file and script file are in a previous post. The batch file renames my script file to user.bashrc so it is autorun and starts the command shell. To prevent the script from running every time the command shell is opened, the last thing the script should do is delete itself.

    It would be nice if arguments worked, but this method has worked for me.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I do the following:

    I put all commands in a shell script, then I execute a wrapper bat file.

    alt_win.cmd

    
    @echo off
    mode con lines=32766
    setlocal enabledelayedexpansion
    SET myPwd=%CD%
    :: 64-bit / 32-bit OS detection
    SET binName=bin
    if "%PROCESSOR_ARCHITECTURE%"=="AMD64" SET binName=bin64
    if "%QUARTUS_ROOTDIR%"=="" echo Env Var QUARTUS_ROOTDIR is missing. Is Quatrus installed? Is the path set correctly & exit /b 1
    SET QUARTUS_BINDIR=%QUARTUS_ROOTDIR%\%binName%
    SET PATH=%PATH%;%QUARTUS_BINDIR%
    for /f "delims=" %%a in ('%SOPC_KIT_NIOS2%\bin\cygpath\cygpath.exe %myPwd%') do @set myCygPwd=%%a
    ::echo %myCygPwd%
    %SOPC_KIT_NIOS2%\"Nios II Command Shell.bat" %myCygPwd%/%*
    

    example.bat

    
    @echo off
    alt_win.cmd %~n0.sh %*
    

    example.sh

    
    # !/usr/bin/env bash
    --SNIP--
    cmd="quartus_pgm -c $uCable -m jtag -o ipv;$binDir/$flashFile"
    echo " Running \"$cmd\""
    $cmd || {
    	echo -e "\e quartus_pgm failed. \e[0m"
    	exitFunc 1
    }
    --SNIP
    

    Using this methods allows you to have a unified interface to Windows and GNU/Linux. Windows users will double click on the example.bat file or even run it from cmd (with parameters and all) and GNU/Linux users will run the example.sh shell script as usual.

    Here is a working example : https://bitbucket.org/ftabunimeh/supportboard/src/default/scripts/