Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,620 Views

cycloneive boot from sd card

Hello to all! 

I'm working with a cycloneive board. 

 

I use the program university avalon sd card interface, and i can read and write a file (fat16) from/to a 2GB sd card. 

I would copy a .bin file to sd card, generated with "nios2-elf-objcopy -O binary file.elf output_file.hex" command, and store it in in sdram memory for execute it: 

 

int mem=0; 

int* pt_sdram=(SDRAM_0_BASE +0x00100000); 

unsigned char midata[4]; 

 

 

for(i=2020;i>0;i--){ 

mem=0; 

midata[0]= alt_up_sd_card_read(sd_fileh); 

midata[1]= alt_up_sd_card_read(sd_fileh); 

midata[2]= alt_up_sd_card_read(sd_fileh); 

midata[3]= alt_up_sd_card_read(sd_fileh); 

 

 

/*  

*/ 

 

mem=midata[0]; 

mem<<=8; 

mem|=midata[1]; 

mem<<=8; 

mem|=midata[2]; 

mem<<=8; 

mem|=midata[3]; 

IOWR(pt_sdram,0,mem); 

++pt_sdram; 

 

 

 

 

//andrun it with: 

 

asm ( 

"call (SDRAM_0_BASE +0x00100000);" 

 

); 

 

 

Is it possible? 

 

TNX, Luca
0 Kudos
13 Replies
Altera_Forum
Honored Contributor I
32 Views

I believe this is possible, although I don't know it's a simple task. 

You are actually writing a custom boot loader, which is a common practice. 

Make sure you build and link project according to the sdram addresses where it's is supposed to be executed, 

otherwise you'll mess up with jump addresses.
Altera_Forum
Honored Contributor I
32 Views

ThanKs Cris. 

How can i link the project with offset?
Altera_Forum
Honored Contributor I
32 Views

You need two separate projects. 

The first one is the bootloader which transfer data from SD card to the sdram and starts program execution. I think you plan to generate a hex file to be used as initialization file for onchip memory, so that the loader starts just after fpga configuration. 

The second project is the 'true' program which is supposed to run from sdram. In the nios project you need to link it in a memory section which resides at address SDRAM_0_BASE +0x00100000, since this is what you'll have after you have loaded code from sd card. 

The standard bootloader takes care to place all code sections in the right places, but in this case you do it manually, so the placement must be consistent with the linking process. 

This should not be difficult: my concern is rather on the fact the hex file generated from elf is really a 1:1 map of the final memory configuration; I don't know if you need to initialize any extra data.
Altera_Forum
Honored Contributor I
32 Views

Read the program sections from the elf file itself isn't that hard (they are designed for simple loaders to process). 

'objdump -p' will list the headers. 

So I would put the unmodified 'elf' file onto the SD card. 

 

For simple code that will read from FAT16(and FAT12) you could look at something like the NetBSD fatboot.S file. 

http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/i386/stand/fatboot/fatboot.s?annotate=1.4&only_with... 

It will need translating from x86 asm and needs a 'read sectors' command.
Altera_Forum
Honored Contributor I
32 Views

I can read the sd card, but I have a problem writing to the sdram. 

my boot he resides in sdram .. 

help !! 

 

i don't understand how to set the linker from bsp editor..
Altera_Forum
Honored Contributor I
32 Views

 

--- Quote Start ---  

I can read the sd card, but I have a problem writing to the sdram. 

 

--- Quote End ---  

 

What's exactly the problem? 

You have pt_sdram, then you can simply write or memcpy at that address. 

 

 

--- Quote Start ---  

 

my boot he resides in sdram .. 

 

--- Quote End ---  

 

What do you mean with this? 

The bootloader can't reside in sdram, because it is supposed to be already there when fpga gets configured.  

So, it must be in the initialization file of any onchip memory. And nios reset vector must be set to point here. 

 

 

--- Quote Start ---  

 

i don't understand how to set the linker from bsp editor.. 

--- Quote End ---  

 

 

--- Quote End ---  

 

Open bsp editor and in the linker section set sdram to all code and data sections
Altera_Forum
Honored Contributor I
32 Views

I build the nios II core with qsys. 

I build boot code with eclipse. 

I program whit NIOS flas programmer. 

It writes the sof file (fpga) and elf file to eeprom epcs16. 

 

At power up the boot is copied from epcs16 to sdram at address 0x02000000. 

The boot can write the sdram but only at adress 0x02000000 + BIGOFFSET. (0x02000000 is the base address sdram) 

If i write sdram 0x02000000 + 0x100 (for example) the NIOS II processor crash. 

 

 

I build the app code with eclipse. 

the problem is that I can not write the .exception (app code) section to an address different from 0x020000xx. 

 

My nios bsp boot settings in jpg.
Altera_Forum
Honored Contributor I
32 Views

I think the problem is here: 

 

--- Quote Start ---  

 

At power up the boot is copied from epcs16 to sdram at address 0x02000000. 

 

--- Quote End ---  

 

You CAN'T run your boot code from the same area of sdram which is supposed to store the application code you read from sd card. 

The boot code must run from a reserved area or, better, a dedicated onchip memory.
Altera_Forum
Honored Contributor I
32 Views

is not possible make a "reserved area" on the sdram?

Altera_Forum
Honored Contributor I
32 Views

 

--- Quote Start ---  

is not possible make a "reserved area" on the sdram? 

--- Quote End ---  

 

 

Yes. You can create two separate memory sections sdram1 and sdram2 and map the boot code into sdram1, while you load sd code and execute application into sdram2. 

If I remember correctly you need to go to the linker script page of bsp editor: remove the default sdram memory region and define two non-overlapping regions sdram1 and sdram2 at the desired addresses.
Altera_Forum
Honored Contributor I
32 Views

i have 2 bsp files. bsp for boot and bsf for application. 

i need to do it in both files?
Altera_Forum
Honored Contributor I
32 Views

Yes, but this is not mandatory. 

You could actually define sdram1 region only in boot application and sdram2 region only in real application. 

The other part of the physical sdram address range remains unassigned, so it will not be available for mapping in linker .
Altera_Forum
Honored Contributor I
32 Views

ok. 

i attach the bsp config for boot and app. 

i attach also the object file app. 

 

this work only if the boot command calls the app at the address 0x02000048: 

asm ( 

"call 0x02000048" 

 

); 

 

But the app code is mapped to address 0x02000000.
Reply