Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

Where does the boot loader come from

Altera_Forum
Honored Contributor II
3,426 Views

Hello: 

 

I've got a NIOS 2 running out of DRAM. So I plan to put the configuration into epcs (done) and put the application program into a FLASH (also done).  

 

I used elf2flash to create the srec filt that I loaded using a serial port bacause that's the way it will be done in the field. 

 

I ran elf2flash --verbose --log=log.txt --input-Project.elf --output-ProjectOut.srec --base=0x09000000 --end=0x09FFFFFF --reset=0x08000000 -flash=U23 --boot=boot_loader_cfi.srec 

 

All this ran OK and I found the boot_loader data infront of the applicatio code as expected. 

 

My question are: 

1. Is this the proper boot loader to use. 

2. The sof file does not use a cfi interface but the flash device works since I can store data and erase blocks. 

3. My flash interface is 16 bits wide but the boot loader looks like it's working 8 bits at a time. 

4. How can I create a custom bot loader? 

 

Thanks 

George
0 Kudos
14 Replies
Altera_Forum
Honored Contributor II
882 Views

Ooops 

 

Type in this line. should be --base=0x08000000 not --base=0x09000000 

 

I ran elf2flash --verbose --log=log.txt --input-Project.elf --output-ProjectOut.srec --base=0x08000000 --end=0x09FFFFFF --reset=0x08000000 -flash=U23 --boot=boot_loader_cfi.srec
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

For starters, I'd take a look at the boot_loader_sources directory: 

 

<nios2_install_dir>/components/altera_nios2/sdk/src/boot_loader_sources 

 

Cheers, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

OK i&#39;ve done that and it looks like a fine boot loader moving 8 bits at a time. 

 

But is this the correct one to use? How do I/you/anyone know? 

 

Did that source generated the srec file of the same name? 

 

thanks 

george
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

Yes, those are the sources for the CFI and EPCS based boot loaders. There&#39;s even a Makefile, in this directory, which will build these sources, for you, so you can play around with the source easily.... 

 

Personally, I would backup the existing sources prior to doing any serious experiementing, however. 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

Hello Slaker 

 

Are you an Altera person saying that this is the correct loader or just typical user like me. 

The reason I ask is that this is a tedious, confusing and time consuming step in the process and I really don&#39;t want to spend days just to find out it&#39;s not the correct approach. 

 

Please, Please don&#39;t take offense since none is intended. 

It&#39;s the pressures of trying to ship a unit. 

 

Thanks 

George
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

I ran the makefile on the source that came with the NIOS2 kit. I&#39;m using 1.0. 

 

The srec file that was produced matches the srec file Altera provided. 

 

So..............Has anyone used that with sucess??? 

 

George
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

George, 

 

Most anyone who&#39;s programmed flash (either CFI or EPCS) on one of Altera&#39;s dev. kits has used these bootloaders. They are what&#39;s used to boot the "factory" designs. 

 

In the case of the EPCS device, the bootloader gets placed into a small onchip memory that&#39;s part of the epcs_controller. When booting from a CFI flash, the bootloader gets prepended to whatever application code you&#39;d like to copy from the flash into volatile memory. The code is pretty well commented, as well! 

 

Cheers,  

 

- slacker 

 

P.S.: Yes, I work for Altera.
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

Well I&#39;ve confirmed with Altera Technical that that is the correct boot loader program. 

 

I&#39;ve programmed the epcs device and I&#39;ve programmed my flash device with the loader and application code(s). 

 

But on porwe up the epcs configures the FPGA but no code is executed. It seems that the SDRAM 0x400 0000 to 0x7FF FFFF (spacing for clarity) in connected to both the NIOS instruction and data masters. But the flaos 0x800 0000 to 0x9FF FFFF is only connected to the NIOS data master. How can I get the NIOS to execute code from the FLASH. 

 

Reset vector is pointing to FLASH. 

 

gm
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

George, 

 

Are you sure you programmed the application code into the EPCS? Your reset vector is pointed to the epcs_controller, right? You ensure that all of the rest of the linker sections point to volatile memory, as well. 

 

Additionally, you can&#39;t run code from the EPCS flash and you probably wouldn&#39;t want to anyway. (very slow) The epcs_controller has a small onchip memory which is filled with the epcs-flavored bootloader when the system is generated and compiled. 

 

The only caveat I would add to this is that this particular flow will not work for Stratix II and EPCS devices. 

 

Regards, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

I&#39;ve been speaking with Altera Regional support and.............. 

 

It looks like the NIOS instruction master can&#39;t access the FLASH.  

I have a large SDRAM 0x400 0000 to 0x7FF FFFF that is connected to the NIOS instruction and data master buses. This is working properly. And a FLASH 0x800 0000 to 0x9FF FFFF connected to an avalon tristate bus. That tri state bus controller is also connected to both the NIOS instruction and data masters. 

 

I can access the data in flash reading locations as data. I CAN NOT access the data in flash using DMA transfers. The DMA transfers were selected to show up any weekness in the FLASH interface. I also believe that the DMA transfers perform more like trying to fetch instructinos from FLASH; reads after reads with one clock delat between them. THe Logic Analizer shows the data available out of the FLASH to the FPGA. But no Data is transfered into the SDRAM. 

 

I&#39;ve concluded that the FLASH-Tristate interface is not working properly. But why is the real question. 

 

GM
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

To close this topic. 

 

That boot loader was the correct one to use. 

The tools put together the proper load sequence and operate as advertized. 

The 8 bit transfer in the boot loader is fast enough. 

 

I had several problems all of which interfeared with proper operation. 

 

1.) I did a FLASH erase as a seperate process to loading code. My erase routine only erased every other block. I could not pass this off as a feature. SO I fixed it. 

 

2.) The FLASH devices were connected to the tri-state bus. That bus was not connected to the instruction and data master on the NIOS side. 

 

3.) The DMA transfers have not been tested since the 8 bit transfers are fast enough.
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

 

--- Quote Start ---  

originally posted by gmm50@Oct 25 2005, 08:48 AM 

2.)  the flash devices were connected to the tri-state bus.  that bus was not connected to the instruction and data master on the nios side. 

--- Quote End ---  

 

Yeah, that&#39;s one of those mistakes everyone makes once and never again. 

 

BTW, the rationale for 8-bit transfers is that the various blocks of data in the program may not necessarily have sizes that are multiples of 2 or 4 bytes. It&#39;s barely alluded to in the bootloader source comments.
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

"Yeah, that&#39;s one of those mistakes everyone makes once and never again." 

 

I sure hope so........... 

 

 

I thought an image aws an image so 16 bits would be 2x as fast as 8 bits??? 

 

gm
0 Kudos
Altera_Forum
Honored Contributor II
882 Views

 

--- Quote Start ---  

originally posted by gmm50@Oct 26 2005, 03:44 PM 

i thought an image aws an image so 16 bits would be 2x as fast as 8 bits??? 

--- Quote End ---  

 

That&#39;s correct. But reading 16 (or even 32) bits at a time would require 16 (or 32) bit alignment, which is not guaranteed by the toolchain. If the .data segment had an odd size (as it might if the last thing in it is an odd-sized char array, or maybe even just a bool or char global variable), things would get difficult fast. 

 

Generally speaking, though, initialization code runs only once, and isn&#39;t usually worth optimizing for speed like that.
0 Kudos
Reply