Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
17 years ago

[HELP]question about loading different sof+elf files in remote upgrade

hello:

I've completed the things about loading application sof file in remote upgrade and that is successful.Now I want to load the sof+elf file.How could i do?Can i use the ide flash programmer to write sof+elf files to different address of epcs?And if i can't use the ide flash programmer,how could i write them to the epcs?The requirement of the form of the location of sof+elf files in epcs?

thanks

29 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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:

    #!/bin/sh

    Jake
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    #  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
    

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored 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:

    
    #  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
    

    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