Forum Discussion
boot NIOS and FPGA from EPCS flash
Hi all,
I am having problems booting up my Nios C code from EPCS. I am building my own FPGA board, not using a demo board. I'm using Quartus 15.0 and DE0 NanoBoard( Cyclone IV as FPGA) My application contains: 1. Clock Source 2. Nios II Processor 3. System ID 4. JTAG UART 5. EPCS Serial Flash Controller 6. PIO 7. SDRAM Controller I want to use SDRAM to store instructions and data for NIOS application. In the NIOS II Processor properties reset vector is set to base address of EPCS controller. Exceptions vector is set to base address to SDRAM. In the NIOS EDS for Eclipce I can debug my application, it works. Then, want to store the FPGA configuration data and the nios firmware in the EPCS following the steps below : 1) I generate the file.hex in NIOS terminal 2) Using Convert Programming Files in Quartus, I create a JIC file using the steps below: 2-a) Select EPCS64 (that is the flash chip i'm using) 2-b) Add SOF Page -> Page 0 -> Properties -> Address mode for selected pages: Set to START and Start Address = 0x0 2-c) Add file to SOF page: Add file.sof 2-d) Properties of file.sof select Compression 2-e) Add HEX data 2-f) Add File -> file.hex 2-g) Use absolute addressing offset( the offset was given in reset vector ) 3) Generate JIC file -> NO issues. 4) Program EPCS device using Active Serial Programming. Add my JIC file. Programming succesful. 5) Power cycle my board. The hardware file starts, but the NIOS never boots? So what is going wrong? I am programming using the USB Blaster. I am also not going through JTAG. Any ideas? Thanks in advance Best regards23 Replies
- Altera_Forum
Honored Contributor
When you generate the jic file you should have an output.jic and an output.map file created. Check the output.map file it will tell you the EPCS addresses of the sof and hex files. Make sure the hex file starts right after the sof file. So if the address range of the sof is 0x000 - 0xAAA, the the hex file should start with 0xAAB.
- Altera_Forum
Honored Contributor
The EPCS is not directly addressable. You need to get a small boot loader program and load that into an embedded memory and set the embedded memory as the reset vector. Check out the wiki article http://www.alterawiki.com/wiki/epcs_bootloaders
- Altera_Forum
Honored Contributor
As krasner suggested, you probably have the addresses wrong. See this article: https://www.altera.com/support/support-resources/knowledge-base/solutions/rd10132010_126.html
Using elf2flash and the 'after' argument is how you get them concatenated in the EPCS (there's other ways to do it, this article is just one way). - Altera_Forum
Honored Contributor
Thank for you all. It working now, i had to change to offset in RESET VECTOR.
Best regards, - Altera_Forum
Honored Contributor
Hi again,
I'm actually trying to READ/Write the Flash EPCS64 device from NIOS II , unfortunately i doesn't work correctly. First of all i open my device using this code :
it's ok. Then i Write/read the device using the code below:int epcs_open(void) { int ret_code; int i; fd = alt_flash_open_dev("/dev/epcq_controller_avl_mem"); if (fd== NULL) { printf("** Can't open flash device **\n\n"); }else { printf("\n<----> Running Flash Tests <---->\n\r"); printf("-Testing flash info retrieval..."); ret_code = alt_get_flash_info(fd, ®ions, &number_of_regions); //ret_code =alt_epcq_controller_get_info(fd, ®ions, &number_of_regions); if (ret_code) { printf( "\nERROR: function alt_get_flash_info failed. ret_code %d\n",ret_code); goto finished; } printf("\n\rThis is NIOSII Board Designed by flash Logic\n\r"); printf("Flash name %s\n\r",fd->name); printf("This flash has %d erase regions\n\r", number_of_regions); for (i=0;i<number_of_regions;i++) { printf("Start 0x%08x End 0x%08x Number of Blocks %3d Block Size 0x%08x\n\r",(regions+i)->offset, (regions+i)->region_size+(regions+i)->offset, (regions+i)->number_of_blocks, (regions+i)->block_size); } } printf("passed.\n\r"); printf("Exiting Flash Tests\n\r"); finished: alt_flash_close_dev(fd); return ret_code; }
The problem is that the written/read data is not the same as shown the picture joined. Do you have any idea why ? Best regards.int test_programming( alt_flash_fd* fd, int test_offset) { int i; alt_u8 data_written; alt_u8 data_read; int ret_code = 0; int test_length = sizeof(data_written); for(i=0;i<sizeof(data_written);i++){ data_written = i; printf( "data_written= 0x%08x\n\r",i,data_written); } ret_code = alt_write_flash(fd, test_offset, data_written, test_length); if (!ret_code) { ret_code = alt_read_flash(fd, test_offset, data_read, test_length); if(!ret_code) { for(i=0;i<sizeof(data_read);i++) printf( "Flash+%d= 0x%08x\n\r",i,data_read); } } printf("*"); if (ret_code) { printf( "\nERROR: function alt_write_flash failed. ret_code %d\n", ret_code); return ret_code; } return ret_code; } - Altera_Forum
Honored Contributor
Hi all,
I still have the problem with the EPCS64 flash, the write operation can be done( because when i write in sectors where the FPGA configuration is saved, I can't boot from the EPCS64). I noticed that the problem comes from the read function because i get always 0xFF from the flash. Do you have an idea about this issue ? I really need your help, because i spent a lot of time without success. Thank you in advance. Best regards. - Altera_Forum
Honored Contributor
Maybe try
printf( "Flash+%d= 0x%08x\n\r",i,data_read); - Altera_Forum
Honored Contributor
Thank you Daixiwen for your answer.
After some modification in the code given above.Now, i can write and read to/from my flash device. But the problem i'm facing is that my data written to the flash are shifted, i can see that in the debug mode using the Memory. For example when i Write in the address 0x04FC0000, the data 0x3fa00000, Instead i see 0xF1050000. It seems to be shifted. The routine that writes is : /* write to flash 32 bits at a time */ IOWR_32DIRECT(epcq_flash_info->data_base, write_offset, word_to_write); word_to_write = 0x3fa00000. It's very strange. Do you have an idea what would be the problem? Thank you in advance. Best regards - Altera_Forum
Honored Contributor
You are using a serial flash so it can't be accessed with IOWR/IORD macros. You need to use the alt_write_flash / alt_read_flash functions.
- Altera_Forum
Honored Contributor
Unfortunately, even with using theses functions, i have the same behavior.