Forum Discussion

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

Copy an application from serial flash to sdram

Hello,

I'm trying to make an application that loads another application image from serial flash to sdram and jumps to it. But its not working. I know I'm copying the data properly to sdram, but the problem is that I don't know if I am correctly creating the image of the application.

Here is my code:

# include <stdio.h>

# include <sys/alt_cache.h>

# include <sys\alt_flash.h>

# include "sys/alt_irq.h"

# include "system.h"

# include "altera_avalon_epcs_flash_controller.h"

# define APP_START_ADDR SDRAM_BASE+0x00400000+0x1c8 // '_start'....you have to look at the object dump file (of your nios application you are loading) to get this address

alt_u8 *pSdram;

static volatile alt_u8 pio_0_val=0;

static alt_flash_fd *p_epcs_fd;

static flash_region *p_epcs_reg_info;

static int num_epcs_regs,block;

static unsigned long total_size;

int main ()

{

int i;

alt_u8 buffer_block[65536];

p_epcs_fd=alt_flash_open_dev(EPCS_FLASH_CONTROLLER_NAME);

alt_epcs_flash_get_info(p_epcs_fd, &p_epcs_reg_info, &num_epcs_regs);

pSdram = (alt_u8 *)SDRAM_BASE+0x00400000;

void (*AppStartP)(); // a pointer to a function;

for(i=4;i<8;i++)

{

alt_epcs_flash_read(p_epcs_fd, i*p_epcs_reg_info->block_size, (void*)pSdram, sizeof(buffer_block));

pSdram+=sizeof(buffer_block);

}

alt_icache_flush_all();

alt_dcache_flush_all();

alt_irq_disable_all ();

AppStartP = (void(*)())APP_START_ADDR; //_start

AppStartP();

}

This is the way that I'm creating my application image:

elf2flash" --epcs --input="application2.elf" --output="application2.flash"

"nios2-elf-objcopy" -I srec -O binary application2.flash application2.bin

I dont know what I'm doing wrong. Can someone help me?

Hagen
No RepliesBe the first to reply