Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12409 Discussions

Altera Cyclone IV Programming .elf file to flash?

Honored Contributor II

I am working on a DE2-115 dev board and have finished my design.  


Now i need to program Flash memories so that my code will be non-viotile.  

I have successfully converted the .sof file to .pof and programmed a Active Serial device EPS64. 


However I cannot get the .elf file programmed in the ISSI 8MB Flash correctly. I followed the tutorial on terasic 



by creating a CFI flash controller ,creating a tri-state bus and setting the reset vector to cfi_flash. I am able to program the flash and everything seems ok, but the code is not running correctly. 


Any idea why this could be happening? If i run as 'Nios II hardware' in eclipse the program works great, but if i flash the .elf file and recycle power I get strange things like half of the program works. My LCD display works, but the UART doesn't. 


Any ideas?
0 Kudos
6 Replies
Honored Contributor II



You can find many topics with the same doubts here at forum  



Honored Contributor II

can someone at least tell me,  


when i hit the 'Run as NIOS II Hardware' in the eclipse IDE, what exactly is this doing?  


This can be a clue for me to fix my issue.
Honored Contributor II

when you hit run the nios 2 download your software to your sopc ram............ 


if you want to boot your sopc from flash you need to convert your .elf file to .flash file and write to flash ........ 


your exception vector need to point to ram and reset vector to flash  


you are use epcs and cfi flash at your design?
Honored Contributor II



I converted the .sof file to be programmed on the EPCS flash. This looks to be good. 


I converted the .elf file to be programmed on CFI FLash. This also seems good, and verification comes back with a successful result. 


I have pointed Reset vector to CFI flash and Exception vector to op-chip memory. 



I am thinking the problem may have something to do with the code running much quicker in RAM than it does in Flash? I thought I read that the boot process automatically takes the Code from Flash and puts it into RAM before its starts to execute the program? Is this true, Do i need to do anything to make this happen?
Honored Contributor II

I am using NIOS Economy

Honored Contributor II




why you dont use only the epcs flash........... you put the .sof and .elf in epcs  



put .sof and .elf at same directory command shell enter in this directory  


convert the .sof 


sof2flash --input=(your.sof) --output=(yoursof.flash) --epcs --verbose --offset=0x0 


write the yoursof.flash 


nios2-flash-programmer --epcs --debug --base=(yourepcsaddress) yoursof.flash 


yourepcsaddess = epcs base address + pipeline bridge(if you use) + clock crossing bridge (if you use) 


to convert .elf type 


elf2flash --after=(yoursof.flash) --input=(your.elf) --output=yourelf.flash --epcs --boot=/home/altera/11/ip/altera/nios2_ip/altera_nios2/boot_loader_epcs.srec 


write the yourelf.flash 


nios2-flash-programmer --epcs --debug --base=(yourepcsaddress) yourelf.flash 



reboot your system (reset vector =>epcs_controller exception vector => ram)