Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21607 Discussions

Writing EPCS64 Device For Remote Update

Altera_Forum
Honored Contributor II
3,243 Views

Hi, 

 

I would like to use the Remote Update mode of Cyclone III device. I have achieved lots of things but I could not accomplish writing EPCS64. I want to write my factory image hw1+sw1 at base 0x00000000 and my application image hw2+sw2 at base 0x00200000 by using the tools in Quartus II 8.1 and Nios II 8.1 IDE but not using Nios II software tools of EPCS Flash Controller. 

 

I could write my two .sof file to EPCS64 device by combining them in .jig file by using Convert Programming Files tool. However, I could not write my .elf files. 

 

Could anyone help me about this issue? 

 

Thanks.
0 Kudos
19 Replies
Altera_Forum
Honored Contributor II
2,402 Views

I have never tried it, but if you convert your .elf files to .hex files first, I expect you should be able to add them in the Convert Programming Files dialog. There is a utility in the Nios console named "elf2hex" which may work for this. 

 

An additional word of warning: the default EPCS boot loader will not be able to boot a software image other than the first hw+sw image at address 0.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Thanks, Kevin 

 

I have also tried it, but I could not convert my .elf file to .hex file. 

 

My code in The Nios II Command Shell for elf2hex is 

 

"$SOPC_KIT_NIOS2/bin/elf2hex" --base=0x001C664B --end=0x001CED0B --little-endian-mem --no-zero-fill --input="remote_with_nios.elf" --output="remote_with_nios.hex" --width=8  

 

However, I have got only one line, in other words the hex file has not been created. 

 

Where is the problem? 

 

Thanks for your answer again.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

The more I think about it, I don't think the elf2hex utility will work for this purpose. I think elf2hex may only work when there is one simple section in your ELF file you are trying to convert. What you need is the entire object file in a format compatible with the boot loader. 

 

Perhaps you could try elf2flash and then use srec_cat to convert the flash file to a hex file. 

 

Is there a reason you don't just use the Nios II flash programmer? That would probably be easier.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Hi Kevin, 

 

Can I use Nios II Flash Programmer for writing flash both hw1+sw1 and hw2+sw2?
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

Can I use Nios II Flash Programmer for writing flash both hw1+sw1 and hw2+sw2? 

--- Quote End ---  

Yes you can.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Thanks, Kelvin one more question 

 

How can I achieve programming hw1+sw1 and hw2+sw2 by using Nios II Flash Programmer? I have searched lots of document of Altera but I have not found the answer.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

The easiest way to get the NIOS II Flash Programmer working is using the GUI. I think there is a menu item for it in the Eclipse SBTs or you can run nios2-flash-programmer-gui from the console. 

 

In the GUI, choose "New" on the File menu and then point it to your .sopcinfo file. Click the "Add..." button to add your sof and elf files. Click the "Start" button to program the flash. 

 

Before the Nios II Flash Programmer can work, you must already have the SOF file corresponding to the .sopcinfo file you used active in the FPGA. You can use the Nios II Programmer or the nios2-configure-sof command line to load the SOF file first.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Hi Omernuz, 

 

You can use the stock Nios II Flash Programmer for programming your first flash SOF/ELF pair into flash, but for the second pair you'll need to know a bit more. 

 

You'd also have to modify the bootloader for the second pair or, like I've done in the past, just use a separate onchip memory for this bootloader. 

 

I can describe an approach for doing this, if you like, but I'd recommend reading the following AN (and, perhaps, playing with the source code) before that: 

 

http://www.altera.com/literature/an/an458.pdf 

 

Best Regards, 

 

slacker
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Hi Kevin and Slacker, 

 

I have tried nios2-flash-programmer-gui to program the EPCS64 device. However, I could not find how I can program the second hw/sw pair to the base address 0x00200000.  

 

Do I have to modify the bootlooder in order to program the second pair? 

 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

I have tried nios2-flash-programmer-gui to program the EPCS64 device. However, I could not find how I can program the second hw/sw pair to the base address 0x00200000.  

 

Do I have to modify the bootlooder in order to program the second pair? 

--- Quote End ---  

 

 

No, the GUI isn't capable of doing what you're asking of it. You'll have to use (and understand) the command line tools (sof2flash, elf2flash, and nios2-flash-programmer) in order to do what you'd like. 

 

You'd only have to modify the bootloader for the second pair of images. The first pair of images can use the stock bootloader. Alternately, you can use the methodology presented in AN-458. 

 

Also, before you go through any of this sort of exercise, you'd better make sure you actually have enough space in the EPCS device to do what you'd like to do. 

 

Regards, 

 

slacker
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

No, the GUI isn't capable of doing what you're asking of it. You'll have to use (and understand) the command line tools (sof2flash, elf2flash, and nios2-flash-programmer) in order to do what you'd like. 

 

You'd only have to modify the bootloader for the second pair of images. The first pair of images can use the stock bootloader. Alternately, you can use the methodology presented in AN-458. 

 

Also, before you go through any of this sort of exercise, you'd better make sure you actually have enough space in the EPCS device to do what you'd like to do. 

 

Regards, 

 

slacker 

--- Quote End ---  

 

 

slacker thanks very much, 

 

I have tried the sof2flash and elf2flash commands before I asked the forum. The problem was that when I have tried to give an offset to sof2flash command for example --offset=0x00200000, the created flash beginning address was still 0x00000000. Then when I looked at the datasheet of EPCS devices, I saw that the offset command is valid only for CFI Flashes.  

 

What can I do so as to give an offset? 

 

thanks again.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

I have tried the sof2flash and elf2flash commands before I asked the forum. The problem was that when I have tried to give an offset to sof2flash command for example --offset=0x00200000, the created flash beginning address was still 0x00000000. Then when I looked at the datasheet of EPCS devices, I saw that the offset command is valid only for CFI Flashes.  

 

What can I do so as to give an offset? 

--- Quote End ---  

 

 

I've used Peter Miller's SRecord utilities to do this sort of thing in the past (available on Sourceforge), but (though I've not tried it) I think nios2-elf-objcopy could work as well. You just need something that shifts the addresses up to where you want your next hardware image to start. 

 

Cheers, 

 

slacker
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Now that I look back at a past project where I did something similar, I see that I did in fact use the srecord (http://srecord.sourceforge.net/) utilities in my script file as slacker has just suggested. 

 

Using sof2flash and elf2flash I created the required .flash files (which are just s-record files AFAIK) all at offset zero. I then used srec_cat to apply an offset and combine all the files together. This combined file can be used with nios2-flash-programmer to actually program the flash. 

 

An example command line to combine and offset files with SRecord: 

srec_cat file1.flash --offset 0x10000 file2.flash --offset 0x20000 > combined.flash
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Hi Kevin, thanks for replying. 

 

Kevin, I tried the srec_cat.exe, but it was not succesful. I have downloaded the version 1.47 from this link. 

 

http://sourceforge.net/projects/srecord/files/srecord-win32/srecord-1.47.zip/download 

 

Then, I executed the srec_cat.exe then wrote your command , but it gave an error like this: srec_cat: standard input :0x0002: warning: ignoring garbage lines. 

 

Actually, whatever I wrote it gives the same error. 

 

What can I do Kevin? 

 

Thanks again. 

 

Best Regards
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

I executed the srec_cat.exe then wrote your command 

--- Quote End ---  

The example command line I gave in my previous post should be all executed as one command. If you just run srec_cat and then type the rest of the command you will get the error you are seeing.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Hi Kevin, 

 

Thanks very much again,  

 

I had typed all command in one line as you said. Despite of this it gave the error. In other words, I run the srec_cat.exe then in the opened window I executed "srec_cat file1.flash --offset 0x10000 file2.flash --offset 0x20000 > combined.flash". 

 

Which location do the file1.flash and file2.flash have to be? Are they at the same location with srec_cat.exe? I did them at the same location, but it gave the error. 

 

What should I do so as to solve this problem?  

 

Thanks again, 

 

Best Regards
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

I run the srec_cat.exe then in the opened window I executed... 

--- Quote End ---  

You need to run srec_cat from a command line instead of running it from the Windows GUI. You can use either the Windows "Command Prompt" or the "Nios II Command Shell". I would recommend using the Nios II Command Shell as it is easier to use the other Nios command line tools this way. On my system I have also added the location of srec_cat.exe to the system path so that it can be more conveniently executed from any location.
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

Hi Kevin and slacker, thanks for answering my questions. 

 

I have solved the problem by using the method of Kevin, and finally I programmed my EPCS64 device with offsets. The only thing remaining is changing the bootlooder for second software. 

 

Thanks for everything. 

 

Best Regards, 

 

Sincerly, 

 

omernuz
0 Kudos
Altera_Forum
Honored Contributor II
2,402 Views

 

--- Quote Start ---  

 

 

You'd also have to modify the bootloader for the second pair or, like I've done in the past, just use a separate onchip memory for this bootloader. 

 

I can describe an approach for doing this, if you like, but I'd recommend reading the following AN (and, perhaps, playing with the source code) before that: 

 

http://www.altera.com/literature/an/an458.pdf 

 

 

--- Quote End ---  

 

 

Hi slacker, 

 

I have read the AN458 document however I could not do examples because I use Qautus 8.1 and Nios 8.1. How did you achieve remote update by using a seperate on-chip memory?  

 

best regards, 

 

thanks
0 Kudos
Reply