Forum Discussion
29 Replies
- Altera_Forum
Honored Contributor
First ... have you read this..?
http://www.altera.com/literature/an/an458.pdf Here are some things to know: 1 - The bootloader will expect to see a valid FPGA image at the beginning of the flash. It will read some bits within the FPGA image to determine how long it is. It then jumps to the end of the FPGA image where it expects to see a valid NIOS software image. 2 - The flash programmer programs the FPGA image into flash. It then calculates how long the image is and programs the software file (ELF) at the address immediately following the FPGA image. The problem is that the bootloader truly only works at the base address of the flash (first image location). So you've got two problems you need to solve... 1 - How are you going to load multiple SOF+ELF images at different addresses in the EPCS flash? 2 - Once you've got those images loaded, how are you going to select from and boot them? . I'll work backwards starting with the bootloader issue. I had to modify the existing bootloader to get it to do what I needed it to do. Since you are going to have to modify the bootloader you can kind of choose how you want things to work. For example, you could completely move away from the scheme where the ELF image follows the SOF image in memory and you could place the ELF images somewhere else in the flash. . What I chose to do was leave the SOF+ELF files combined and simply change the address of where the bootloader begins looking for the images depending on which image I was running. I only one application image and one safe image. . The source code for the EPCS bootloader can be found in: C:\altera\81\nios2eds\components\altera_nios2\boot_loader_sources Once you've modified and compiled your new bootloader, you can go into Quartus and override the memory initialization file for the boot RAM inside the EPCS module inside your SoPC system and make it use your compiled MIF instead. Now on to the file creation. You can use the IDE but I think that's going to be more difficult. It's easier to script things. Here are snippets from my scripts:
The final file "app_image.bin" is simply a binary file. You can then program this file into any location in the EPCS flash. You can use the IDE flash programmer to do this or whatever means you are providing in your application to remote download. Sorry, I know this is probably a rough overview of a lot of information but I hope it points you in the right direction. Read the referenced document. Jake# Creating .flash file for the FPGA configuration echo Creating firmware flash file ... "$SOPC_KIT_NIOS2/bin/sof2flash" --epcs --compress --input="../altera/top.sof" --output="firmware.flash" # Creating .flash file for software code echo Creating safe and application flash files ... "$SOPC_KIT_NIOS2/bin/elf2flash" --epcs --after="firmware.flash" --input="../software/top/Release/top.elf" --output="app.flash" # Convert to binary echo Converting flash files to binary ... nios2-elf-objcopy -I srec -O binary firmware.flash firmware.bin nios2-elf-objcopy -I srec -O binary app.flash app.bin # Concatenate echo Concatenating binary files to create final programming file ... cat firmware.bin app.bin > app_image.bin - Altera_Forum
Honored Contributor
Thank u very much.I want to load multiple SOF+ELF images in remote upgrade mode.With your help,now I can write the combined binary file into any location in the EPCS flash.But only the SOF image can be reload.ELF image has no effect.
- Altera_Forum
Honored Contributor
Yes, As I said before, you have to modify the existing bootloader or write your own to be able to boot a different software file.
Jake - Altera_Forum
Honored Contributor
Thank u,and i have a another question that is if i modify the boot location of the existing bootloader.That is meant that when the system power on,the FPGA always load the application sw image?How is the protection of faliure about load?
- Altera_Forum
Honored Contributor
Use the watchdog timer in the remote update core to handle an application load failure. If the timer expires, the safe image will automatically be reloaded.
Jake - Altera_Forum
Honored Contributor
Good idea!!!!
You are a clever man!!!! I adore u for your smart!!!! Is that meant that the remote update mode is designed only for the sof file not for nios code? - Altera_Forum
Honored Contributor
The remote update core is only for loading the FPGA image. It has no knowledge about the NIOS processor. That is why you need to create your own bootloader to handle the software aspect of your design.
- Altera_Forum
Honored Contributor
jakobjones, Sorry for the newbie question but, how do you run your script file? If I open a Nios II Command Shell and type everything in manually, it works. But, I can't figure out how to automate this script.# Creating .flash file for the FPGA configuration echo Creating firmware flash file ... "$SOPC_KIT_NIOS2/bin/sof2flash" --epcs --compress --input="../altera/top.sof" --output="firmware.flash"# Creating .flash file for software code echo Creating safe and application flash files ... "$SOPC_KIT_NIOS2/bin/elf2flash" --epcs --after="firmware.flash" --input="../software/top/Release/top.elf" --output="app.flash"# Convert to binary echo Converting flash files to binary ... nios2-elf-objcopy -I srec -O binary firmware.flash firmware.bin nios2-elf-objcopy -I srec -O binary app.flash app.bin# Concatenate echo Concatenating binary files to create final programming file ... cat firmware.bin app.bin > app_image.bin - Altera_Forum
Honored Contributor
The Nios II command Shell is a cygwin bash shell. So you create and run scripts like any linux shell script. Put the commands into a file with a ".sh" extension. At the very top of the file put a comment like this:
Jake#!/bin/sh - Altera_Forum
Honored Contributor
Thanks Jake!
It's working now. However, I have a couple more questions for you. Currently we are able to update our firmware (on Cyclone II board) like this: 1. make the bin file using a script like your's 2. send the .bin file to the board via TCP/IP using a custom app on the PC 3. Nios writes the new FW image into EPCS 4. we hit the reset button to start the new FW Is there a way to have the board reset and use the new firmware without the user having to hit the reset button? Also, for production we're looking for a way to write the FW to EPCS via JTAG but w/o the full suite of Quartus/Nios IDE installed. I've read the documentation on using the stand-alone programmer but I'm a little confused about how to get it running. Since the IDE won't be installed, we will not have the NiosII Command Shell. To use the stand-alone programmer, do we need to install a Linux command shell (bash/cygwin?). I'm afraid I just don't know much about Linux (it's "all Windows - all the time" around here). Could you give me some pointers on how get this going? Thanks