The bad news is that to get true "push button" run from flash support, you will need to wait for the 1.1 version of the kit. However the good news is that you can get it working for yourself in the 1.0 version without too much extra effort.
The problem is that currently when you assign the text and read only data sections to flash, no boot loader will be present in the system to load the initial values of the read/write data into RAM, which is why your code failed.
Here's a recipe for creating a run from flash system using the 1.0 kit:
1. Create a Nios II system where the reset and exception vectors both point to flash.
2. Assign the .text and .rodata sections to the flash device that contains the reset vector, and the .rwdata section to an appropriate RAM device.
3. Build the project so that you create the auto-generated linker script (generated.x). Copy this linker script to another location within the system library project, and then edit it to replace the current .rwdata section with:
.rwdata :AT (LOADADDR (.rodata) + SIZEOF (.rodata))
{
PROVIDE (__ram_rwdata_start = ABSOLUTE(.));
. = ALIGN(32 / 8);
*(.got.plt) *(.got)
*(.data1)
*(.data .data.* .gnu.linkonce.d.*)
_gp = ABSOLUTE(. + 0x8000);
PROVIDE(gp = _gp);
*(.sdata .sdata.* .gnu.linkonce.s.*)
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
. = ALIGN(32 / 8);
_edata = ABSOLUTE(.);
PROVIDE (edata = ABSOLUTE(.));
PROVIDE (__ram_rwdata_end = ABSOLUTE(.));
} > sdram
PROVIDE (__flash_rwdata_start = LOADADDR(.rwdata));
(Note: you need to replace "sdram" with the name of the RAM component you're using for the .rwdata section).
This causes the initial contents of the .rwdata section to be stored in flash, but be linked as if it is located in RAM.
4. Add the line:
. = ALIGN(32 / 8);
to the end of the .rodata section (just like in the .rwdata section above). This ensures that the start of the .rwdata section is word aligned.
5. Select "Custom Linker Script" on the system library properties page, and then set the linker script to be the one you've just created (Note that the linker script must be part of your system library project for it to be found by the IDE).
6. Create a source file in your system library project which contains the following function:
# include "alt_types.h"
void alt_load_section (alt_u32* from, alt_u32* to, alt_u32* end)
{
if (to != from)
{
while( to != end )
{
*to++ = *from++;
}
}
}
7. Copy alt_main.c from the altera_hal component into your system library project, and then add the following call to the top of the alt_main function:
alt_load_section (&__flash_rwdata_start,
&__ram_rwdata_start,
&__ram_rwdata_end);
you will also need to add the following external declarations to alt_main.c:
extern void __flash_rwdata_start;
extern void __ram_rwdata_start;
extern void __ram_rwdata_end;
8. Rebuild the projects, and program the executable as normal using the flash programmer.
The only remaining gotcha is that you won't be able to use software breakpoints when debugging code in flash. Instead you'll need to use hardware breakpoints.
Hope that helps, and good luck!