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++
Announcements
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.
12455 Discussions

.hex file generate for Nios-II C code

Altera_Forum
Honored Contributor II
1,839 Views

Hi, 

 

I am using Quartus-II Version 9.1sp2 and i am also using Nios-II IDE Version 9.1. I have a Custom board with Cyclone-I FPGA EP1C12Q240C8N. I made Nios-II Base project using SOPC Builder and write a program for blinking LED in Nios-II IDE. 

 

I am not using Flash programmer for loading Nios-II Program. I made .hex file of my C program from adding "mem_init_generate" in make target>>Build of Nios-II Project and add in Quartus-II. Problem is, after adding .hex file in Quartus-II, i update Memory Initialization file and reassemble the Quartus project, but then also my program not run. So please suggest solution for this problem. 

 

Below is message of Nios-II IDE after Build project. 

 

Post-processing to create mem_init/Program_Memory.hex... 

elf2hex STQFP.elf 0x00004000 0x00007fff --width=32  

--create-lanes=0 mem_init/Program_Memory.hex 

Post-processing to create mem_init/hdl_sim/Program_Memory.dat... 

elf2dat --infile=STQFP.elf --outfile=mem_init/hdl_sim/Program_Memory.dat  

--base=0x00004000 --end=0x00007fff --width=32  

--create-lanes=0  

Post-processing to create mem_init/hdl_sim/Program_Memory.sym... 

nios2-elf-nm -n STQFP.elf > mem_init/hdl_sim/Program_Memory.sym 

 

 

 

Thanks 

 

Nandish Jasani.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
632 Views

Hi, 

 

try to append "--record=4" after "elf2hex STQFP.elf 0x00004000 0x00007fff --width=32" before the backslash (in your projects mem_init.mk file).  

 

I have to do this for years, now. I don't know how other people get a working hex file out of the automatic Nios II build process. Once i regenerate my BSP, I have to add this line, again, because it overwrites the mem_init.mk file. 

 

I'm not a "build process"- / make- /toolchain- /whatever-guru, so I was not able to find an automatic solution for this issue. I just take it as a little drawback of the tools which I found my own workaround for. 

 

Please report, if it also solved you problem. 

 

Regards, 

Maik
Altera_Forum
Honored Contributor II
633 Views

Thanks Maik, 

 

I successfully appended “--record=4” in my make file, still I am facing the same issue. 

 

What file should I add to Quartus-II Projects after make target (I have added .mk and .hex in Quartus-II Project according one of the altera forum threads)? 

 

We have another custom board with Cyclone-IV and we are using Quartus-II Version 13.0 for different project. In Nios-II, make target generates .qip file which we added to Quartus project and the project works as required. So we tried similarly for Quartus-II Version 9.1sp2. 

 

Below is the build message. 

 

Post-processing to create mem_init/Program_Memory.hex... 

elf2hex STQFP.elf 0x00000000 0x00003fff --width=32 --record=4 

--create-lanes=0 mem_init/Program_Memory.hex 

Post-processing to create mem_init/hdl_sim/Program_Memory.dat... 

elf2dat --infile=STQFP.elf --outfile=mem_init/hdl_sim/Program_Memory.dat  

--base=0x00000000 --end=0x00003fff --width=32  

--create-lanes=0  

Post-processing to create mem_init/hdl_sim/Program_Memory.sym... 

nios2-elf-nm -n STQFP.elf > mem_init/hdl_sim/Program_Memory.sym 

 

 

Regards, 

Nandish Jasani
Altera_Forum
Honored Contributor II
632 Views

Hi, 

 

starting with Quartus 9.1 SP2, I got these hex file generation generation issues. Though I do not exactly understand what exactly your problem is. 

 

What I have to do with this very version of the build tools is the following: 

 

I generate a BSP project from my sopcinfo file. After that I generate a firmware project which refers to the just created BSP. All this I perform with the "Nios II Software Build Tools for Eclipse" Project Wizzard. 

 

After that I do have to make two changes in the automatically generated make files. 

 

The one is the change I posted above. The other is in the Makefile of the BSP in the line "CREATE_ELF_DERIVED_FILES := 1" which I have to set to one as shown here. This is responsible for creating the hex file at all. 

The --record=4 flag is responsible for the layout or alignment of the hex file.  

 

If I follow these steps with the exact tools version you mentioned, then I can work with it succesfully for years, now. 

 

Still, I'm intereseted in suggestions leading to a more convinient way to handle this hex file creation because as I said, once you run the BSP editor, you have to reset those settings in order to get your hex file. 

 

I hope this helps. 

 

Regards, 

Maik
Altera_Forum
Honored Contributor II
633 Views

As additional info, here is one of my hex creation build message that sucessfully creates a usabel hex file (one for onchip ram and one for onchip rom which contains the program data). 

 

Post-processing to create mem_init/onchip_ram.hex... 

bash -c 'elf2hex e_fpga_0100_firmware.elf 0x00424000 0x00427fff --width=32 --record=4 

--little-endian-mem --create-lanes=0 mem_init/onchip_ram.hex' 

`mem_init/onchip_ram.hex' -> `../../onchip_ram.hex' 

Post-processing to create mem_init/onchip_rom.hex... 

bash -c 'elf2hex e_fpga_0100_firmware.elf 0x00410000 0x0041c7ff --width=32 --record=4 

--little-endian-mem --create-lanes=0 mem_init/onchip_rom.hex' 

`mem_init/onchip_rom.hex' -> `../../onchip_rom.hex' 

 

Regards, 

Maik
Altera_Forum
Honored Contributor II
633 Views

没有看懂是怎么弄的,有相应的使用文档吗?

Reply