
build_factory_source: For advanced users

	The build_restore.sh script generates the restore 
	factory flash file from file created by various Altera tools.	


 This directory contains the files used to build the BUP restore flash object files. 

 Build_restore.sh script commands may be run individually at a unix, linux, or Nios II EDS command shell.

 c5gt_fpga_bup hardware sof files from the project directories are converted
 using Nios II Tool sof2flash to attain flash files:

sof2flash --offset=0x020000 --input=c5gt_fpga_bup.sof --output=c5gt_fpga_bup.flash
sof2flash --offset=<USER!_IMAGE_ADDRESS> --input=<USER_DESIGN_FILENAME>.sof --output=<USER_DESIGN_FILENAME>.flash

 c5gt_fpga_bup software - run make flash from the app\web_server dir 
 after running make to build software elf:

make flash

 actual rebuilding script of restore files can happen here for the end user:

./build_restore.sh


 To restore flash after building the restore files, follow instructions as specified in  
 the User's Guide, chapter entitled: "Restoring the Flash Device with the Factory Settings"

 Note that the flash files may also be programmed individually using nios2-flash-programmer as follows:

 nios2-flash-programmer -b 0x0 c5gt_fpga_bup.flash
 nios2-flash-programmer -b 0x0 signal_integrity_demo1.flash
 nios2-flash-programmer -b 0x0 s5gtea7_html.flash
 nios2-flash-programmer -b 0x0 ext_flash.flash
 nios2-flash-programmer -b 0x0 pfl_bits.flash
 nios2-flash-programmer -b 0x0 boot_code.srec

 For proper restore to work, the board FPGA should still also be one-time configured as described in 
 the User's Guide, entitled: "Restoring the Flash Device with the Factory Settings"
 

Errata: Re: Nios II EDS 9.1 tool : sof2flash.exe

-------------------------------------------------------------------------------------

Board Update Portal Design - Flash Recovery - Errata   Sept. 17, 2009

-------------------------------------------------------------------------------------

Problem Description:
The release of Nios II EDS 9.1 tool "sof2flash" does not include support for Stratix IV GX .

Work-around:
To create the recovery files, Quartus II "Convert Programming Files" option was used to create a POF file.

This file was written to the flash on the board. The individual flash files "c5gt_fpga_bup.flash"
and "signal_integrity_demo1.flash" and the PFL Option register section "pfl_bits.flash" were then read using 
Nios II EDS nios2-flash-programmer command on the command line.

Please read instructions for using Quartus II "Convert Programming Files" and Quartus II Programmer 
before attempting to prepare a design to be written to flash.

At any time, the board factory files may be restored using the factory_recovery build script 
"./restore.sh" command. Please consult the User Guide for more instructions before proceeding! 

Instructions for performing the work-around on your_design design:
--------------------------------------------------------------------------------

1. Convert the Quartus II HW design sof to pof using Quartus II "Convert Programming Files" option.
	a. Under "Conversion setup files", select "Open Conversion Setup Data" and choose 

<kit_ver>/c5gt_fpga_bup/software_examples/factory_recovery/build_factory_source/<your_design>.pof

	b. Select Generate to create the "<your_design>.pof" file
	
	2. Cycle power to the board.
	
3. Use Quartus II Programmer to configure  "s5gtea7_pfl_programming.sof"  as described in 
   the User Guide chapter entitled: "Configuring the FPGA Using the Quartus II Programmer"

4. Write the pof "your_design.pof" to the device using Quartus II Programmer as described in 
   the "Using FPGA-Based Parallel Flash Loader with the Quartus II Software" chapter entitled:
   "Programming the Parallel Flash Device Using PFL in User Design"

	www.altera.com/literature/an/an478.pdf 

5. Use nios2-flash-programmer to read (thus create) the configuration images to .flash files:
	
	>nios2-flash-programmer --base=0x8000000 --read=your_design.flash
	--read-bytes=0x0c20000,0x00B52D29

	>nios2-flash-programmer --base=0x8000000 --read=plf_bits.flash
	--read-bytes=0x018000,0x91

6. Use these as reliable flash images in a similar script to the build_restore.sh found 
   in build_factory_source directory.

7. Use the ./restore script in factory_recovery directory to write the generated restore flash files 
   as described in the User's Guide chapter entitled: "Restoring the Flash Device with the Factory Settings"
 
	Please consult the User Guide for instructions before proceeding!

