Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17261 Discussions

Is there a way to combine sof and elf files ?

Altera_Forum
Honored Contributor II
5,654 Views

Hi, 

I am trying to download my sof and elf in a multiprocessor Nios system. I know that it can be done separately (convert sof to flash and then the elf to flash and then use the command line), but  

 

1. is it possible to just load the elf inside the sof and then place this sof in the flash ?? 

 

2. I have read at a few places that using the elf2hex can help as then its possible to use this hex as a memory initialization file but I cant seem to find it in the Altera documentation. Has anyone done something similar before ? 

 

Any suggestions are welcome. 

 

Thanks !
0 Kudos
17 Replies
Altera_Forum
Honored Contributor II
4,241 Views

as long as you use onchip memory this will work. 

you can setup onchip memory to be initialized from an mif or hex file. 

so if you alternate your program, update the mif or hex file, do a quartus compile and your sof will contain the new elf 

this will not work if the elf stuff will be stored in external memory as this memory is not part of the sof file (sof is fpga only) 

see nios forum, there some postings how to do that
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

I am using the on-chip memory in my design so it would be pretty useful.  

 

I will take a look at the other forum. Thanks for the reply.
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

so you need to modify your onchip memory in a way that is uses a memory initialization file and specify the filename, then you only need to update this file and do a quartus recompile.

0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

Thanks Michael !! 

 

One more thing, do I 'have' to configure my on chip memory as a 'ROM', I am currently leaving it as a RAM and after my SOPC design updation (modification of the onchip mem to require a mem init file) the hex file is not generated where it shd be. From what I have heard, a blank hex file is generated which needs to be modified later, not the same thing in my case. 

 

This is what I did: 

1. Modified the SOPC design (to require a mem init file in hex format), generated the new design 

 

2. Placed the new ptf in my Nios design and generated a new elf 

 

3. Converted the elf2hex, and placed that hex where all the other hex are placed in the quartus design 

 

4. Recompiled Quartus design and dnld the new sof to the flash 

 

Result: No changes in sof, the programmer just says that the checksum matches the prev sof file so that definitely means that the sof didnt get the new mem content that I wanted it to get... comments ??
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

out of my head i remember that there was an issue with the filename for memory initialisation. 

if i am right the default name given for this file is recomended to be changed to a user choosen filename. like myOnChipMem.MIF 

also i have seen a couple times that quartus modifies MIF and HEX until they were set to read only.  

in some other cases only a MIF was producing a new sof, even if the hex file was correctly entered  

 

i know this is woodoo but try to choose a fileename you created, check that the files produced by sopc / wizzard & co have this filename and it is located within the root of your project. 

 

your memory source file should have an entry like  

altsyncram_component.init_file = "My_Memory_Init.mif", 

 

your memory does not need to be RAM it can be ROM for nios instruction data. 

 

one last comment, i had this pitfall a couple of times when i haven't noticed that quartus wasn't creating a non time limited sof like usually. the licence server was down and quartus created a sof with a different file name _time_limited or so added. my quartus programmer and all comandline batches were trying to update the (not modified) sof. 

so check your project if you have more then sof or if your sof is realy updated
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

YAY - it works now :D 

 

Following advice did the trick: 

 

 

--- Quote Start ---  

check that the files produced by sopc / wizzard & co have this filename and it is located within the root of your project. 

 

--- Quote End ---  

 

 

I was looking for it in the <project_name>_sim (as suggested by Altera documentation) and that is where I put my .hex aswell. No wonder the sof remained the same - the silliest of mistakes --- Thanks a lot man, appreciate it !! 

 

 

The procedure is summarized below in case anyone else with the same problem passes by: 

 

1. Enable the "Non-default memory initialization" option from the SOPC builder and it will show you a name of the hex file. Remember that name as u will need a hex of the same name.  

 

2. Generate the SOPC system, and recompile the Quartus design. The hex file will be generated in the root of your design. Use the new ptf in your Nios design to generate the new elf. 

 

3. Use elf2hex to convert this elf to hex (use the base, end address and width entries from your SOPC system) 

 

4. Copy/paste this in the root of your project (if youe hex has a different name then change the name of the hex file to the one used in the SOPC system for the mem init file) 

 

5. You can save a lot of time by not re-compiling the design, just use the following two commands: 

quartus_cdb --update_mif <your quartus project name>.qpf 

quartus_asm <your quartus project name>.qpf 

and a new sof will be generated with the elf contents inside !! Burn awaaayy....
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

your welcome ! 

 

glad to hear that it finaly worked. 

hope i remember your hint to save time with the last 2 commands.
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

hi xinjia, (http://www.alteraforum.com/forum/member.php?u=10098

I too have similar requirement in my project,i tried as per your instructions but still could not solve..can u please post the instruction indetail.
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

What problem do you have exactly? What do you use in your system? What flash, RAM, do you put your software in on-chip memory or in external RAM?

0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

actually my requirement is to combine the .elf file with the sof . 

I put my S/w in onchip ROM,which i try to make it as a memory initialisation file.I tried the instructions given above by xinjia (http://www.alteraforum.com/forum/member.php?u=10098),but could not succed in doing it.
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

Actually my requirement is to combine the .elf with the .sof 

And now i have made my .hex(NIOS exe) as a memory initialization file to a onchip rom..and set the reset address of nios to this memory 

 

I followed the instructions given above , but could not succed
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

What error do you have?

0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

There wasn't any error, the onchip-memory(rom) was not getting initialized. 

I solved the problem now.I had set that particular module which has the onchip-memory(rom) as DESIGN PARTITION then.so it was not compiling the newly added changes. 

Now it is working obsolutely fine after i deselected the SET AS DESIGN PARTITION option for that module and the nios is executing from the onchip -ROM
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

Hi 

 

I am trying to do the same thing by following the instructions of this post. 

However, in my case, only the sof file works and the elf file is not working. 

I'm wondering if I miss anything and hope someone could kindly help me. 

 

I have a simple project which controls two leds. 

After the sof file is downloaded, the second led is on. 

If the elf file is working on the NiosII CPU, the first led blinks. 

I cannot see the led blink after I download sof file which initializes the on-chip memory with the hex file converted from elf. 

 

Here are some detailed steps: 

1. The reset vector of NiosII CPU is already set in the on-chip memory. 

(Please see my attached qsys file) 

2. The "Enable non-default initialization file" option is checked. The initialization file is "my_nios2_mem" which locates in the root of my project. 

3. The "my_nios2_mem.hex" is generated from elf file with the following command: 

bash-3.1$ elf2hex --input=sof_elf_epcs_niosii.elf --output=my_nios2_mem.hex --base=0x00000000 --end=0x0003ffff --width=32
0 Kudos
Altera_Forum
Honored Contributor II
4,241 Views

Check that the correct .hex file is placed in the Quartus project folder and that Quartus finds it when you recompile the project. Unfortunately if it doesn't find the file it won't generate an error but just a warning (maybe a critical warning, I don't remember) so it can be easy to miss.

0 Kudos
Altera_Forum
Honored Contributor II
4,240 Views

Hi Daixiwen 

 

Thanks for your reply. 

 

If the hex file cannot be found, there will be a critical warning as you remember. 

I had this critical warning in the beginning and I have solved it already. 

So I believe Quartus II can find the hex file.
0 Kudos
Altera_Forum
Honored Contributor II
4,240 Views

IIRC Quartus has a tool that can let you look into single port internal FPGA memory blocks. Maybe you can use it to check that the CPU's RAM has the correct image and not just an empty one.

0 Kudos
Reply