Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12748 Discussions

Using the Nios II Command Shell

Altera_Forum
Honored Contributor II
3,653 Views

Hello, 

 

Because of problems with the IDE I've decided to use another editor for coding. This has been working quite well except for everything not having to do with code writing itself (e.g., compiling, downloading, project management, etc...). Basically this means I still have to have the IDE open and running in the background to do those things. I like this better than having to use the IDE all the time except that one of the problems I've been having is with the IDE freezing once it opens the project. 

 

Using the Altera Software Developer's Handbook (section IV, chapter 11) and the --help from the commands I've been able to use nios2-configure-sof and nios2-download to work with their particular areas. Using nios-terminal kind of speaks for itself. That leaves compiling and debugging. Debugging is a beast that I may just stay with the IDE for now unless someone reading this knows of something better (I'll look further into it when I have more time). Compiling, however, is something that I don't want to have to touch the IDE for. 

 

The handbook refers to nios-build-project but doesn't give a lot of detail with it and Internet searching doesn't give a whole lot more. I've tried Altera's MySupport but they've been less than helpful. 

 

To boil it all down, I'm looking for a nudge in the right direction to get me going with building a project from the command line. I know it can't be too difficult since it seems like the IDE uses the command line tools to do its building. 

 

Any help would be greatly appreciated. 

 

 

Thanks
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
2,174 Views

Hello again, 

 

A little bit after posting this request I had a thought about what the captured console text was saying. The first line is 'make -s all.' I gave it a shot. 

 

Knowing the tool chain is GCC this is something I had tried but I either wasn't in the right spot or there was something else I was doing wrong (obviously). 

 

Even though I have my answer on this part of it, I'd still be interested in any problems anyone has come across with getting rid of the IDE. One REALLY nice positive is not having to wait for the indexer in the IDE. That alone will save lots of time. 

 

If there is anyone who would like the list of commands to do the basic operations manually, just ask. I'll be happy to post them. 

 

 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
2,174 Views

Hi, 

 

If you enable verbose mode, then you'll see that all the commands used by IDE showed in the console window. 

 

BTW, could you write down your experience in a document and share with us. 

 

Thanks in advance, 

David
0 Kudos
Altera_Forum
Honored Contributor II
2,174 Views

Hello all, 

 

There's not much to describe about my experience. The Nios II IDE 6.0 (and 5.0, 5.1 for that matter) were leaving me longing for more. Constant lock ups, no help from MySupport, the indexer (need I say more with this one?), and the newest problem occurred with version 6.0. Tabbing (left or right) or commenting (Ctrl+/) a large block of text would mash the blocked lines into the left side of the window by about 4 or 5 (sometimes more) tab stops. Needless to say, I had enough with the IDE. 

 

MySupport couldn't recreate the block tabbing/commenting issue (I couldn't reliably do it either though) so I asked them to provide me with the commands necessary to circumvent the IDE. The person I was talking to said to look at the HTML files included in the installation. They were no help. After my second post in this thread I did manage to figure out what the commands were and I've created a script file to help out. I am no scripting genius so it may look kind of raw for the more experienced people out there. 

 

 

#! /bin/sh BUILD_PATH="path/to/build/folder" ELF_NAME=".elf" SOF_PATH="path/to/sof/file" SOF_NAME=".sof" case "$1" in     sof)  nios2-configure-sof $SOF_PATH/$SOF_NAME     ;;     clean)  make -C $BUILD_PATH clean     ;;     build)  make -C $BUILD_PATH -s all    if ; then      echo " "      echo "Build complete"      echo " "  fi     ;;     run)  nios2-download $BUILD_PATH/$ELF_NAME -g     ;;     br)  echo "----------------------------------------------"  echo "Building..."  echo " "    make -C $BUILD_PATH -s all    if ; then      echo " "      echo "----------------------------------------------"      echo "Downloading..."      echo " "            nios2-download $BUILD_PATH/$ELF_NAME -g  fi     ;;     brt)  echo "----------------------------------------------"  echo "Building..."  echo " "    make -C $BUILD_PATH -s all    if ; then      echo " "      echo "----------------------------------------------"      echo "Downloading..."      echo " "            nios2-download $BUILD_PATH/$ELF_NAME -g            if ; then    echo " "    echo "----------------------------------------------"    echo "Starting terminal..."    echo " "    nios2-terminal    echo " "      fi  fi     ;;     *)  echo ""  echo "Usage: $0 sof|clean|build|run|br|brt"  echo ""  echo "   sof    Configure the target"  echo "   clean  Clear all object and executable files from the build"  echo "   build  Build the project"  echo "   run    Program the target and run"  echo "   br     Build the project, program the target and run"  echo "   brt    Build the project, program the target and run, open the terminal"  echo ""     ;; esac 

 

My usage of the file consists of putting it in the project folder (not the workspace folder) and I have the BASH init script dump me into the folder which contains the above script. Technically it shouldn't matter where the script is located as long as the variables at the top of the script are set properly. 

 

There are a few caveats that I've found with working with the command line and they're not pretty: 

 

1) A project still has to be started in the IDE although I've seen commands that get around this. The script I have above does not do this. 

 

2) Step debugging doesn't work (yet). I still have to use the IDE for this. I'm sure there are programs out there which play nicely with GDB but I haven't gone looking yet. 

 

3) New files won't be included in a build--they have to be opened in the IDE to be registered. This one was a pain in the butt when I first came across it. What I do now is open the IDE and create the file where I need it using the IDE's build-in commands. I've seen a command that gets around this but I haven't looked into it yet since my project is nearing completion and I rarely need a new file to be created. 

 

4) There is an occasional time where doing a clean and build doesn't work. For some reason the compiler doesn't recreate the necessary items after they were cleaned. I've only had this happen twice though. The solution is to open the IDE and have it build the project again. Sometimes it'll error out saying a folder is missing but if you keep hitting build it will go. 

 

Overall I've been much happier using my preferred IDE. Compile times are noticeably quicker without having to wait for the indexer. Fixing compile issues aren't as simple as double clicking on the item in the Problems pane and editing the line but you still see the problem file and line number. If your IDE shows line numbers then it's pretty easy to find the problem. 

 

My IDE allows for the outputted console text to be displayed in a pane so this is my next venture. My earlier attempts have failed but that's probably in part to my lack of knowledge of Cygwin. 

 

Hopefully Altera will clean up their software and not force the level of IDE integration that they have now. If they cleaned up some of the bugs I brought up with them with version 5.1 that they said they were fixing with 6.0 then I would still be using the IDE.  

 

Let me know if there is anything I missed or if there are some things I can add. If anyone reading this knows how to get Cygwin to run a command and use the provided environment variables from a Windows command line, please add it to the thread. I do plan on looking further into this later though and will post my results when I figure it all out. 

 

 

Regards, 

Philip
0 Kudos
Altera_Forum
Honored Contributor II
2,174 Views

main objective of our project is to test spi master that we have built on MAX 2 cpld with nios acting as slave and also a host for our master. 

we are not able to figure out how to use nios 2 as spi slave. 

can we use spi core available with avalon interface for our purpose. 

we also need ide code for nios 2 slave. 

thanks in advance
0 Kudos
Altera_Forum
Honored Contributor II
2,174 Views

 

--- Quote Start ---  

originally posted by ashish@Dec 20 2006, 10:49 PM 

main objective of our project is to test spi master that we have built on max 2 cpld with nios acting as slave and also a host for our master. 

we are not able to figure out how to use nios 2 as spi slave. 

can we use spi core available with avalon interface for our purpose. 

we also need ide code for nios 2 slave. 

thanks in advance 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=20155) 

--- quote end ---  

 

--- Quote End ---  

 

 

Hi ashish, 

 

I&#39;m sorry but you&#39;re in the wrong thread for what you want. Please repost your question in the appropriate area. You will get more help that way. 

 

With that said, I&#39;d try to help but I&#39;m not familiar enough with Quartus to give you a good answer. I&#39;ve only ever used Nios as an SPI master. 

 

 

Thanks, 

Philip
0 Kudos
Altera_Forum
Honored Contributor II
2,174 Views

Hi PhillipD 

 

To get rid of the IDE was the first thing I did after it was introduced. I my humble opinion it sucks. No way I could live with that as a programmer. Way too slow, very hard to document your compiler settings etc, just a plain pain. 

 

Now I uses my favourite editor slickedit and a makefile and GNU make (3.80 remember something about problems with never versions) via CYGWIN. 

 

I spent quite some time figuring out what to compile etc. But now this sort of makefile works nicely in several projects. 

Hope it might help you too. 

 

You will need the linker script created by the IDE too.  

 

Makefile is below. 

 

Regards Jacob 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

#!/bin/bash TOOLS   = ..\tools PROJECT = ..\\..\\sandbox.pj PROGRAM_NAME = Firmware PTF = ./cpu/FirmwareCpu.ptf OBJDIR  = c:/temp/$(PROGRAM_NAME)/obj OBJLIB  = alt_exception_entry.o          alt_do_ctors.o   alt_do_dtors.o   alt_usleep.o   alt_busy_sleep.o   alt_irq_register.o   alt_irq_entry.o   alt_irq_handler.o   alt_malloc_lock.o   alt_exit.o   alt_errno.o   alt_write.o   alt_env_lock.o   alt_lseek.o   alt_close.o   alt_read.o   alt_fstat.o          alt_getpid.o          alt_kill.o   alt_sbrk.o   alt_dev.o   alt_release_fd.o   alt_isatty.o          alt_load.o   alt_dcache_flush_all.o   alt_icache_flush_all.o   alt_icache_flush.o   alt_dcache_flush.o   alt_irq_vars.o   CRT0    = crt0.o SOURCE    = ..\\Firmware\\Firmware.cpp       ..\\Firmware\\kernel.cpp         ..\\Firmware\\CardDecode.cpp     ..\\Firmware\\i2c.cpp     ..\\Userware\\usb.cpp     ..\\Userware\\Hal4d12.cpp     ..\\Userware\\proto.cpp     ..\\Firmware\\ccd.cpp     ..\\common\\flash.cpp           ..\\common\\log.cpp             ..\\common\\safe_sprintf.cpp     ..\\common\\random.cpp           ..\\common\\crc32.cpp           ..\\common\\regexpclass.cpp OBJECTS = $(addsuffix .o, $(notdir $(basename $(SOURCE)))) NIOSKIT    = nios2_51 SOPC_KIT_NIOS2_REVISED = /cygdrive/c/altera/kits/$(NIOSKIT) VPATH = ../common:../UserWare:../Firmware:$(SOPC_KIT_NIOS2_REVISED)/components/altera_nios2/HAL/src:$(SOPC_KIT_NIOS2_REVISED)/components/altera_hal/HAL/src # +--------------------------------# | First, some traditional defines# | for our particular tool chain GNU_TOOLS_PREFIX = nios2-elf AS = $(GNU_TOOLS_PREFIX)-gcc CC = $(GNU_TOOLS_PREFIX)-gcc AR = $(GNU_TOOLS_PREFIX)-ar LD = $(GNU_TOOLS_PREFIX)-g++ OC = $(GNU_TOOLS_PREFIX)-objcopy NM = $(GNU_TOOLS_PREFIX)-nm OD = $(GNU_TOOLS_PREFIX)-objdump INCLUDE_PATH  = -I ./ INCLUDE_PATH += -I ../include INCLUDE_PATH += -I ../UserWare INCLUDE_PATH += -I $(SOPC_KIT_NIOS2)/components/altera_nios2/HAL/inc INCLUDE_PATH += -I $(SOPC_KIT_NIOS2)/components/altera_hal/HAL/inc # +------------------------------------# | Switches for the compiler, the assembler,# | and the linker# | ASFlags = CCFLAGS     = $(INCLUDE_PATH) CCFLAGS      += -DTERMINAL # #  CCFLAGS      += -DBOOTLOADER CCFLAGS  += -DNIOS2 -fshort-enums CCFLAGS  += -DSYSTEM_BUS_WIDTH=32 CCFLAGS    += -mhw-mul -mno-hw-mulx -mhw-div -g# # CCFLAGS    += -DUSESAFEMALLOC # # CCFLAGS    += -DTRACELOG# # CCFLAGS    += -DNOLOG CCFLAGS    += -O3 -Wall CCFLAGS  += -DALT_MAX_HEAP_BYTES=524288 LDFLAGS = -pipe -Tlinker.ld# LDFLAGS  += -Wl,--defsym,exit=_exit# LDFLAGS  += -msmallc # Rules $(OBJDIR)/%.o : %.cpp     @Echo Compiling $<     @$(CC) -c -xc++ $(CCFLAGS) $< -o $@      $(OBJDIR)/%.o : %.cxx     @Echo Compiling $<     @$(CC) -c -xc++ $(CCFLAGS) $< -o $@ $(OBJDIR)/%.o : %.S     @Echo Assembling $<             @$(AS) -c  $(CCFLAGS) $< -o $@      $(OBJDIR)/%.o : %.c     @Echo Compiling $<     @$(CC) -c -xc $(CCFLAGS) $< -o $@ system.h: system.stf $(PTF)     @Echo Generating system.h     gtf-generate --output-directory=. --gtf=$(SOPC_KIT_NIOS2)/bin/gtf/system.h.gtf --stf=system.stf     @touch system.h       dep :         @Echo Making dependencies $<     for i in $(SOURCE);     do  $(CC) -MM -c $(CCFLAGS) $$i >> dependencies;     done     sed -e &#39;s/^/$$(OBJDIR)\/&/g&#39; dependencies > $(PROGRAM_NAME).dep     @rm -rf dependencies clean :     @Echo Removing objects     rm -rf $(OBJDIR)/*.o     rm -rf $(PROGRAM_NAME).objdump     rm -rf $(PROGRAM_NAME).elf     rm -rf ./Firmware/system.h     rm -rf $(PROGRAM_NAME).bin     rm -rf libsys.a      $(PROGRAM_NAME).elf : $(addprefix $(OBJDIR)/,$(OBJECTS)) $(addprefix $(OBJDIR)/,$(CRT0))     @Echo Linking $@     $(LD) $(LDFLAGS) -msys-lib=sys -L &#39;.&#39; -msys-crt0=$(addprefix $(OBJDIR)/,$(CRT0)) -o $@ $(addprefix $(OBJDIR)/,$(OBJECTS))      $(PROGRAM_NAME).bin : $(PROGRAM_NAME).elf     @Echo converting elf->bin     nios2-elf-objcopy -O binary $(PROGRAM_NAME).elf $(PROGRAM_NAME).bin     # | Handy auxilliary files $(PROGRAM_NAME).objdump : $(PROGRAM_NAME).elf     @Echo Making $(PROGRAM_NAME).objdump     nios2-elf-objdump -t -d -S $(PROGRAM_NAME).elf > $(PROGRAM_NAME).objdump      # Library libsys.a: $(addprefix $(OBJDIR)/,$(OBJLIB)) system.h     @echo Archiving into libsys.a     @$(AR) -src libsys.a $(addprefix $(OBJDIR)/,$(OBJLIB))           lib:  libsys.a misc:     -@mkdir -p $(OBJDIR)        # +-------------------------------------# | Shortcut Targets elf  : $(PROGRAM_NAME).elf bin  : misc lib $(PROGRAM_NAME).bin   nios2-elf-size $(PROGRAM_NAME).elf aux  : $(PROGRAM_NAME).objdump include $(PROGRAM_NAME).dep        [/b] 

--- Quote End ---  

0 Kudos
Reply