cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Mentor
Mentor
8,910 Views
Registered: ‎06-09-2011

Minimum hardware for bootloader

Jump to solution

Hi all,

I have a custom board containing SP6, DDR-2 and SPI Flash. I am runing Microblaze on my FPGA and am going to create a bootloader for it. My questions are below:

  1. Can I use my SPI Flash as a storage device for bootloader?
  2. How can I create SREC file from my test application? - I have a simple application uses DDR for code/heap/data section.
  3. How can I create a bootloader to read that space of flash and load it to DDR memory?

I would really appreciate if someone can give me a clue on an Embedded System fundamental based on Microblaze.

How it reads the code from storage and loads it to DDR?

Which format do I need to convert my application - which resides in DDR memory?

Do I only need a MIG for connecting my DDR to Microblaze?

and so on.

 

Thanks,

Hossein

 

Thanks,
Hossein
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Scholar
Scholar
15,578 Views
Registered: ‎09-05-2011

Converting the *.elf to *.bin file should work. What are the linker script settings of your bootloader and the application ?

 

Please check the attached code. To use this code, split your application file into rest_section and vector_section. 

 

You can use mb-objcopy command to create the two bin files – vector_section.bin and rest_section.bin.

 

Use the commands as shown in the screenshots below:

vector_rest_section.png

 

After splitting the elf into these sections, you can create the mcs file. For e.g.,

write_cfgmem -format mcs -size 128 -checksum FF -interface spix4 -loaddata "up 0x0 KC705_EXAMPLE_wrapper.bit up 0xb00000 rest_section.bin up 0xc00000 vector_section.bin" -force newMCSFile

 

 

View solution in original post

12 Replies
Highlighted
Xilinx Employee
Xilinx Employee
8,909 Views
Registered: ‎08-02-2007

hi,

 

refer to http://www.xilinx.com/support/documentation/application_notes/xapp1053.pdf

 

--hs

----------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful and reply oriented.
----------------------------------------------------------------------------------------------
Highlighted
Xilinx Employee
Xilinx Employee
8,897 Views
Registered: ‎08-01-2008

A bootloader is typically an application that is required to boot up your processor system and possibly load the next set of instructions or applications. Hence it is normally used when say, you have to load a set of instructions from a non-volatile memory like Flash into an SDRAM and then execute from it.

Now,if your application resides entirely within the BRAM, the bitstream would contain all the necessary software. So even if you were to configure from the Flash, a bootloader would not be required.
Thanks and Regards
Balkrishan
--------------------------------------------------------------------------------------------
Please mark the post as an answer "Accept as solution" in case it helped resolve your query.
Give kudos in case a post in case it guided to the solution.
0 Kudos
Highlighted
Mentor
Mentor
8,887 Views
Registered: ‎06-09-2011

@balkris thank you for your answer.

There are lots of applications which do not fit in the BRAM and we need a larger memory space for them. For such applications and OS based ones I guess that we use external memories like DDR which they need a bootloader to read from a non-volatile memory and load it to DDR. However, I am wondering what the steps need to be done for an application which resides in DDR.

 

@htsvn Thank you for the reference. I would read it and come back to you with a feedback.

Thanks,
Hossein
0 Kudos
Highlighted
Mentor
Mentor
8,575 Views
Registered: ‎06-09-2011

Hi @htsvn,

I read the reference and tried to implement it in my design. I have created two applications: one using DDR memory as application, the other one is bootloader that I wrote it very similar to the bootloader code of the reference. I have a problem in transfering SPI Flash data to DDR memory. I have defined a pointer to DDR similar to the reference code example and I read SPI Flash page-by-page and copy it to the DDR Memory. However, I see that after some page copy my processor stops and it seems to me it has memory overflow or something else! Below is part of my bootloader application:

 

 

Xuint8 *Destination_Address =(unsigned char *) _Destination_Address;

//SPI, UART initialization....

	// get the base address of DDR-2 memory extern to FPGA
    int baseaddress = XPAR_DDR2_S0_AXI_BASEADDR;
    u8 i;
     //declare a pointer to int (add4 to base address)
    volatile int *txframe = (volatile int *)baseaddress;
//------------------------------------------------------------------//
//    Simple test to check if DDR memory is working properly		//
    *(txframe) = 5;
    *(txframe+1) = 6;
    *(txframe+2) = 7;
    *(txframe+3) = 8;
    *(txframe+4) = 9;
    *(txframe+5) = 10;
    *(txframe+6) = 11;
    *(txframe+7) = 12;
    for (i=0;i<8;i++)
    	if (*(txframe+i)!=(i+5))
    		xil_printf("\n\r Wrong location!.%d",i);
    	else
    		print("\n\r Correct Data");
//-----------		End of DDR Memory Check		------------------//
	for (PageCount=0;PageCount<_Pages_to_Copy;PageCount++){
		Read1PageApplicationCode(PageCount, temp);
		for(k=0;k<256;k++){
			*Destination_Address++ =temp[k+4];
		}

	}
	print("\n\r Finished Copy");
	while(1);
	Xil_ICacheDisable();
	Xil_DCacheDisable();
	return XST_SUCCESS;

My application - which I merged it to my FPGA config and wrote it to SPI flash with iMPACT - has 50 pages - 256Bytes per page -

 

I am checking page counts and printing the Page Start Add in below function:

Read1PageApplicationCode()

 I see that all strings on UART when I have commented below line of code - it deals with data transfer to DDR:

		for(k=0;k<256;k++){
			*Destination_Address++ =temp[k+4];
		}

 And, here is what I see in UART when commenting those lines, and it is correct.

 

Page Add: 16A7E1                                                                                                                                                 
 Page Add: 16A8E1                                                                                                                                                 
 Page Add: 16A9E1                                                                                                                                                 
 Page Add: 16AAE1                                                                                                                                                 
 Page Add: 16ABE1                                                                                                                                                 
 Page Add: 16ACE1                                                                                                                                                 
 Page Add: 16ADE1                                                                                                                                                 
 Page Add: 16AEE1                                                                                                                                                 
 Page Add: 16AFE1                                                                                                                                                 
 Page Add: 16B0E1                                                                                                                                                 
 Page Add: 16B1E1                                                                                                                                                 
 Page Add: 16B2E1                                                                                                                                                 
 Page Add: 16B3E1                                                                                                                                                 
 Page Add: 16B4E1                                                                                                                                                 
 Page Add: 16B5E1                                                                                                                                                 
 Page Add: 16B6E1                                                                                                                                                 
 Page Add: 16B7E1                                                                                                                                                 
 Page Add: 16B8E1                                                                                                                                                 
 Page Add: 16B9E1                                                                                                                                                 
 Page Add: 16BAE1                                                                                                                                                 
 Page Add: 16BBE1                                                                                                                                                 
 Page Add: 16BCE1                                                                                                                                                 
 Page Add: 16BDE1                                                                                                                                                 
 Page Add: 16BEE1                                                                                                                                                 
 Page Add: 16BFE1                                                                                                                                                 
 Page Add: 16C0E1                                                                                                                                                 
 Page Add: 16C1E1                                                                                                                                                 
 Page Add: 16C2E1                                                                                                                                                 
 Page Add: 16C3E1                                                                                                                                                 
 Page Add: 16C4E1                                                                                                                                                 
 Page Add: 16C5E1                                                                                                                                                 
 Page Add: 16C6E1                                                                                                                                                 
 Page Add: 16C7E1                                                                                                                                                 
 Page Add: 16C8E1                                                                                                                                                 
 Page Add: 16C9E1                                                                                                                                                 
 Page Add: 16CAE1                                                                                                                                                 
 Page Add: 16CBE1                                                                                                                                                 
 Page Add: 16CCE1                                                                                                                                                 
 Page Add: 16CDE1                                                                                                                                                 
 Page Add: 16CEE1                                                                                                                                                 
 Page Add: 16CFE1                                                                                                                                                 
 Page Add: 16D0E1                                                                                                                                                 
 Page Add: 16D1E1                                                                                                                                                 
 Page Add: 16D2E1                                                                                                                                                 
 Page Add: 16D3E1                                                                                                                                                 
 Page Add: 16D4E1                                                                                                                                                 
 Page Add: 16D5E1                                                                                                                                                 
 Page Add: 16D6E1                                                                                                                                                 
 Page Add: 16D7E1                                                                                                                                                 
 Page Add: 16D8E1                                                                                                                                                 
 Page Add: 16D9E1                                                                                                                                                 
 Page Add: 16DAE1                                                                                                                                                 
 Page Add: 16DBE1                                                                                                                                                 
 Page Add: 16DCE1                                                                                                                                                 
 Page Add: 16DDE1                                                                                                                                                 
 Page Add: 16DEE1                                                                                                                                                 
 Page Add: 16DFE1                                                                                                                                                 
 Page Add: 16E0E1                                                                                                                                                 
 Page Add: 16E1E1                                                                                                                                                 
 Page Add: 16E2E1                                                                                                                                                 
 Page Add: 16E3E1                                                                                                                                                 
 Page Add: 16E4E1                                                                                                                                                 
 Page Add: 16E5E1                                                                                                                                                 
 Page Add: 16E6E1                                                                                                                                                 
 Page Add: 16E7E1                                                                                                                                                 
 Page Add: 16E8E1                                                                                                                                                 
 Page Add: 16E9E1                                                                                                                                                 
 Page Add: 16EAE1                                                                                                                                                 
 Page Add: 16EBE1                                                                                                                                                 
 Page Add: 16ECE1                                                                                                                                                 
 Page Add: 16EDE1                                                                                                                                                 
 Page Add: 16EEE1                                                                                                                                                 
 Page Add: 16EFE1                                                                                                                                                 
 Page Add: 16F0E1                                                                                                                                                 
 Page Add: 16F1E1                                                                                                                                                 
 Page Add: 16F2E1                                                                                                                                                 
 Page Add: 16F3E1                                                                                                                                                 
 Page Add: 16F4E1                                                                                                                                                 
 Page Add: 16F5E1                                                                                                                                                 
 Page Add: 16F6E1                                                                                                                                                 
 Finished Copy  

As you see everything is OK. However, after removing the comment I see just some messages, bootloader doesn't reach to the end?!..

 

 Page Add: 16A7E1                                                                                                                                                 
 Page Add: 16A8E1                                                                                                                                                 
 Page Add: 16A9E1                                                                                                                                                 
 Page Add: 16AAE1                                                                                                                                                 
 Page Add: 16ABE1                                                                                                                                                 
 Page Add: 16ACE1                                                                                                                                                 
 Page Add: 16ADE1                                                                                                                                                 
 Page Add: 16AEE1                                                                                                                                                 
 Page Add: 16AFE1                                                                                                                                                 
 Page Add: 16B0E1                                                                                                                                                 
 Page Add: 16B1E1                                                                                                                                                 
 Page Add: 16B2E1                                                                                                                                                 
 Page Add: 16B3E1                                                                                                                                                 
 Page Add: 16B4E1                                                                                                                                                 
 Page Add: 16B5E1                                                                                                                                                 
 Page Add: 16B6E1                                                                                                                                                 
 Page Add: 16B7E1                                                                                                                                                 
 Page Add: 16B8E1                                                                                                                                                 
 Page Add: 16B9E1                                                                                                                                                 
 Page Add: 16BAE1                                                                                                                                                 
 Page Add: 16BBE1                                                                                                                                                 
 Page Add: 16BCE1                                                                                                                                                 
 Page Add: 16BDE1                                                                                                                                                 
 Page Add: 16BEE1                                                                                                                                                 
 Page Add: 16BFE1                                                                                                                                                 
 Page Add: 16C0E1                                                                                                                                                 
 Page Add: 16C1E1                                                                                                                                                 
 Page Add: 16C2E1                                                                                                                                                 
 Page Add: 16C3E1                                                                                                                                                 
 Page Add: 16C4E1                                                                                                                                                 
 Page Add: 16C5E1                                                                                                                                                 
 Page Add: 16C6E1  !0   !0   !0   !0   !0   !0   !0             

It is very wierd beahvior, isn't it? Would you please advise?

 

Thanks,

Hossein

Thanks,
Hossein
0 Kudos
Highlighted
Mentor
Mentor
8,556 Views
Registered: ‎06-09-2011

Hi @balkris and @htsvn,

 

I found the source of problem. I just needed to increase the Heap/Stack Size and that bizarre behavior was gone. Now, I read from SPI and write it to my DDR. However, the last step of work - jumping to DDR memory for execution - doesn't work!.

Here is the code I have just replicated from reference design:

 

 

//----------	PROTOTYPES		----------------------------------//
int (*boot_app) (void);
int Init_PERIPHs();
void Transfer_application2DDR(void);
//----------------------------------------------------------------//

int main(void){
	Init_PERIPHs();
	Transfer_application2DDR();
	// function pointer that is set to point to the address of
	//DESTINATION_ADDR
	boot_app = (int (*) (void)) XPAR_DDR2_S0_AXI_BASEADDR;
	// jump to start execution code at the address START_ADDR
	boot_app();
	print("\n\r It didn't jump to DDR! :-(");
	while(1);
	Xil_ICacheDisable();
	Xil_DCacheDisable();
	return XST_SUCCESS;
}

 

What I see in the UART terminal:

 

 

 

 UART INIT OK.                                                                                                                                                    
 SPI Configured.                                                                                                                                                  
 MicronID: 0, 20, BA, 16, 10, 0                                                                                                                                   
 Destination Address is :A8000000                                                                                                                                 
 The Third Project.                                                                                                                                               
 Finished Copy                                                                                                                                                    
 It didn't jump to DDR! :-(     

 

As you see my application on DDR is not running!.

 

Here, there are two questions that arise:

  1. As I have converted my application.elf to binary format, merged it to FPGA Config data and wrote it to SPI Flash, Can I make sure that this converted file is correctly binary format of that elf code? I should add that when I inspect the binary file I can see those parts of my application for example has some strings to be printed in UART - print messages!.
  2. Does these pieces of code really implement a jump to DDR memory and Address?
	// function pointer that is set to point to the address of
	//DESTINATION_ADDR
	boot_app = (int (*) (void)) XPAR_DDR2_S0_AXI_BASEADDR;
	// jump to start execution code at the address START_ADDR
	boot_app();

I would really appreciate a fast response.

 

Thanks,

Hossein

Thanks,
Hossein
0 Kudos
Highlighted
Scholar
Scholar
15,579 Views
Registered: ‎09-05-2011

Converting the *.elf to *.bin file should work. What are the linker script settings of your bootloader and the application ?

 

Please check the attached code. To use this code, split your application file into rest_section and vector_section. 

 

You can use mb-objcopy command to create the two bin files – vector_section.bin and rest_section.bin.

 

Use the commands as shown in the screenshots below:

vector_rest_section.png

 

After splitting the elf into these sections, you can create the mcs file. For e.g.,

write_cfgmem -format mcs -size 128 -checksum FF -interface spix4 -loaddata "up 0x0 KC705_EXAMPLE_wrapper.bit up 0xb00000 rest_section.bin up 0xc00000 vector_section.bin" -force newMCSFile

 

 

View solution in original post

Highlighted
Mentor
Mentor
8,403 Views
Registered: ‎06-09-2011

Hi @sampatd

Thank you very much for your answer. I am doing the same method of the attached code and see that DDR value is like what I stored in flash.I have set code/Data & heap/stack section of bootloader to BRAM in linker script:

Boot.jpg

And, for the application which I intend to run from DDR I am placing them in the DDR section:

application.jpg

Is it OK?

However, there are only two differences I observed here that I remark below:

  • my command for changing .elf to .bin was copied from a batch file in XAPP1053 and is as below:

mb-objcopy  -O  binary  -R .vectors.reset -R .vectors.sw_exception -R .vectors.interrupt -R .vectors.debug_sw_break -R .vectors.hw_exception PERIPHTest/Debug/PERIPHTest.elf  PERIPHTest/Debug/PERIPHTest.b You see that it looks like yours but doesn't run the first series with -J Do I have to use it as well?

 

  • For merging application binary with FPGA config I do it in the iMPACT with those ordinary steps - not the last command in your comment. Do I have to follow your method? Below are some simple shots of iMPACT:

Processor Data.jpg

I would really appreciate any help and comment.

Hossein

Thanks,
Hossein
0 Kudos
Highlighted
Scholar
Scholar
8,394 Views
Registered: ‎09-05-2011
The above steps are correct.For the following headers,

#define REST_SECTION_BYTE_NUM
#define VECTOR_SECTION_BYTE_NUM

I normally get their sizes from iMPACT as shown above
0 Kudos
Highlighted
Mentor
Mentor
8,349 Views
Registered: ‎06-09-2011

Hi @sampatd,

Thank you for your help. Where do I need to place those Headers? Which value should I assign to them? However, I know the application start address and how many pages - 256Byte - I should read from flash.

There are some points in your comments. Do I have to separate reset/interrupt vectors and place them in BRAM? Did I get it correctly? I am referring to those lines of making binary from elf.

Thanks,
Hossein
0 Kudos
Highlighted
Mentor
Mentor
6,585 Views
Registered: ‎06-09-2011

Hi @sampatd,

I am short of time. I would really appreciate any help and comment. It seems that no one had a similar experience in this regard.

 

 

Thanks,
Hossein
0 Kudos
Highlighted
Mentor
Mentor
6,706 Views
Registered: ‎06-09-2011

Hi @htsvn@balkris@sampatd,

 

I finally found the problem. I was not defining a correct pointer to DDR memory!. I read SPI Flash in byte format.So, I need to write it to DDR as well. In spite of that, I had defined an int pointer to DDR memory!..

 

	// get the base address of DDR-2 memory extern to FPGA
    int baseaddress = XPAR_DDR2_S0_AXI_BASEADDR;
     //declare a pointer to int (add4 to base address)
    volatile int *txframe = (volatile int *)baseaddress;

I was reading XAP1053 sample bootloader code for the n'th time (n-->infinity) ;-) that I realized I am doing this wrong!..

I changed it to below line and I got everything working:

 

    Xuint8* txframe = (unsigned char *) DESTINATION_ADDR;

Thank you for your help and comments.

Hossein M.S

Thanks,
Hossein
0 Kudos
Highlighted
Mentor
Mentor
6,442 Views
Registered: ‎06-09-2011

Hi @sampatd,

It has been some days since I was working on interrupt from an application which resides in DDR memory. I came across to your comment and I realized what you mentioned regarding vector split from the rest of code.
I really appreciate your helpful comment. In fact, your comment - if I had considered defining u8 pointer for DDR memory addressing - was the complete solution to my problem. So, I accept it as the solution and I wanted let you know that. Thank you so much.

 

 

Hossein

Thanks,
Hossein
0 Kudos