Link and program relationship

Source: Internet
Author: User

DDR = double data rate double rate synchronous dynamic random memory. Strictly speaking, DDR should be called ddr sdram, which is often called DDR,

Now let's analyze the DDR initialization.

A program can be divided into code segments, data segments, and BSS segments.

Code segment: commands and other things

Data Segment: Global or static variable with an initial value and the initial value is not 0

BSS segment: global variables and static variables with an initial value of 0 or no initial value, for example:

Volatile int I = 0;

 

Volatile Int J = 0x12345678;

Volatile int K = 0;

Volatile int g;

/* Set gpm0, 1, 2, 3 to the output pin */

* Gpmcon = 0x1111;

I, K, and G exist in BSS segments.

J exists in the Data Segment

For * gpmcon = 0x1111; this is suitable for the code segment.

First, let's take a look at program burning:

1. Our program was first written on NAND Flash.

2. When we set it to NAND boot, 6410 pieces of memory will have 8 KB, And the CPU will copy the content of the first 8 KB of NAND Flash to ram through internal hardware (the starting address is 00000000).

Now there is a problem: What should we do if the number of programs we write exceeds 8 KB?

If our program exceeds 8 K, we need to use DDR and copy the entire program to DDR. Where can we copy the program to DDR, my DDR has m space. At this time, the link address is used, that is, the program will be copied to the link address.

Here is an example of a link script.

Sections // represents a segment

{

. = 0x5000;/**. indicates the current address. Assign the address 0 x, that is, the link address of the entire program **/

. Text: {/**. You can modify the text segment name ********/

Start. O/** start. O indicates the entire start. o file (including code, data, and BSS segments )**/

* (. Text)/** code segment for storing all other files **/

}

. Data: {/** data Segment **/

* (. Data)/** data segment of all other files **/

}

Bss_start =.;/* defines the variable and assigns the variable bss_start to the current address (the current address is the address discharged in sequence )*/

. Bss :{

* (. Bss)/** Bss segments of all other files **/

}

Bss_end =.;/** defines the variable and assigns the variable bss_end to the current address. Similarly, the current address is the address 6 after the last bss address discharged in sequence **/

}

The comments are already very detailed.

Relocation: we have already mentioned the concept of relocation.

When the link address we set is not 0x50000000 (for example, 0 x), we need to relocate it. That is, after the hardware copies the original program to the internal 8 k ram, because the link address is not 0x00, the relocation function will copy the program to the starting address 0x50000000.

Obviously, a piece of code must be run before the relocation is completed. Why can this code be run? This involves another concept-location-independent code, because location-independent code is used (the so-called location-independent code can be run at any connection location ).

Location-independent code usage:

1. Use the relative commands B and bl when redirecting

2. Do not access global variables or static variables

Summary:

1. When running the program, it should be located at its link address. Assume that its link address is 0x50000000.

2. The hardware determines that the program starts to run from 0 at the beginning, so it needs to be relocated (the previous code segment copies the program to the link address)

3. Why can the previous code run? Because location-independent codes (B and bl commands) are used)

Finally, let's analyze the startup process of the entire program:

1. If we burn the generated axf image file to nand flash, set the link address to 0x00000100.

2. An on-chip hardware automatically copies 8 K to OK6410 in-chip memory

3. Then start running from address zero

4. Move the program to the link address.

5. Finally, use the location-related code BL to jump to the connection and execute it.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Then execute the program 0x100 here.

 

The location code is redirected here.

Zero x 00000000

 

 

 

 

 

Copy the program

Zero x 00000100

 

 

 

 

8 K

 

Ok6410-bit RAM

 

 

 

 

 

8 K

59.9 K

Zero X 00000000

 

Nand flash

 

 

 

 

 

 

 

Assume 59.9 K

AXF file burning

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.