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++
12610 Discussions

generate epcs flash file from srec

Altera_Forum
Honored Contributor II
1,801 Views

Hi all, 

 

Some of you will probably know how to create .flash filew with the sof2flash and elf2flash tools. I need however a tool that converts a srec file to a flash file. Basically I create an srec file for my application, and add some lines to it for some custom initialisations of memory locations during program load.  

 

I looked to some tools, there is a nios2-srec2flash, but I don't think this will give me tha correct result.  

 

Stefaan
0 Kudos
7 Replies
Altera_Forum
Honored Contributor II
431 Views

The .flash file is a binary file (a memory image that is programmed into flash). Why not add the custom initialization to the .flash file instead? I do this in my builds and it works well. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
431 Views

The .flash file _is_ an SREC file with very minor differences. A conversion program (if even necessary) should be trivial.

0 Kudos
Altera_Forum
Honored Contributor II
431 Views

Ewww, you're right! Sorry about that - we convert it to binary and *then* add our extra stuff to it! 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
431 Views

 

--- Quote Start ---  

The .flash file _is_ an SREC file with very minor differences. A conversion program (if even necessary) should be trivial. 

--- Quote End ---  

 

 

Indeed it looks like an srec file packed in an srec file. I think a conversion is needed, because the destination addresses in the file are for the EPCS device. The data section should contain the information about where to store the instructions/data in the main memory of the processor. 

 

Is there a description of how the .flash looks like in detail. Creating a conversion program is not the problem, but with a description, it saves me lot of time.  

 

Is there a possibility to get the source code of the elf2flash utility program? 

I think that the elf2flash utility creates a standard srec anyway in the background first of all...  

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
431 Views

Stefaan, 

 

I doubt there's a description of it, but I recall that the delta was _very_ minor. Here's what you can do to determine the difference between SREC and .flash. 

 

  1. Convert the .flash to binary using objcopy. 

  2. Create an SREC from that binary, again using objcopy. (format it to closely match the original .flash). 

  3. Compare the two SREC files. 

 

 

I think there's only 1 or 2 extra SRecords, one of which is a timestamp...I believe. 

 

[UPDATE: You do realize that you can program an SREC directly to the flash using nios2-flash-programmer, right?] 

 

Cheers, 

 

--slacker
0 Kudos
Altera_Forum
Honored Contributor II
431 Views

Slacker,  

 

I think there is a mistake here : 

 

What I want :  

  • generate an elf file of my software with nios2-elf-objcopy 

  • concatenate to this srecord some other lines (things to write to some addresses in the system), also in srecord format 

  • take this combined file to use with nios2-download : works great 

  • also use the same file for putting in the epcs to be able to use the board without jtag connection
What I do now :
  • create a flash file for the sof : sof2flash ok 

  • create a flash file for the software : elf2flash ok 

  • program these two with the flash programmer : ok 

  • BUT : the extra initialisations I want in the boot process is not available.
What I think that happens :
  • the elf2flash creates an image for the processor system : data x must go on address y... (this data is also in the srecord if generated with nios2-elf-objcopy, see above) 

  • all (x,y) data is packed as information for the bootloader (where to write content) : call it BOOTDATA 

  • the BOOTDATA is packed in an srecord file to instruct the flash programmer where to program DATA in the EPCS. so the address information in this srecord is not related to BOOTDATA in any way 

  • the bootloader in the epcs sopc component handles BOOTDATA, decodes the records and uses (x,y) for initialising memories...
So what I want to do is just converting my own srec to a flash file. The step from elf to srecord is already done by me, and should not be executed anymore in the elf2flash utility then.  

 

 

 

Stefaan
0 Kudos
Altera_Forum
Honored Contributor II
431 Views

An alternative approach might be to add the additional initialisation into the object file than contains the rest of the software. 

(ie as C/asm initialised data in a named section and get the linker to place it at the correct address.) 

 

Of course, the problem might be in the way the bootloader code processes the information stored in the flash. For instance (I've no idea if this is true) if it always did byte copies any hardware initialisation would likely be wrong. 

 

For our systems we have a PCIe slave interface - and all the code is written through that.
0 Kudos
Reply