Lds file:

Source: Internet
Author: User

Similar to scatter files, lds files determine the storage location and entry address of each segment of an executable program, which is also the role of link locating. Description of the U-boot lds file:

 

SECTIONS {

...

Secname start BLOCK (align) (NOLOAD): AT (ldadr)

{Contents}> region: phdr = fill

...

}

Secname and contents are mandatory. The former is used to name this segment, and the latter is used to determine what part of the code is placed in this segment. The following is an explanation of some keywords in this description.

1. secname: segment name

2. contents)

3. start: the Relocation Address of the segment. The Link (run) address of this segment. If there is a location-independent instruction in the code, this segment must be placed on this address when the program is running, start can be described by any symbol describing the address.

4. AT (ldar): defines the address for storing (loading) This section. If this option is not used, the load address is equal to the run address. You can use this option to control the different locations in the output file for each segment.

For example:

/* Nand. lds */

SECTIONS {

First 0x00000000: {head. o init. o}

Second 0x30000000: AT (4096) {main. o}

 

 

}

Above, head. o is placed at the beginning of 0x00000000 address, init. o put in head. o and the running address is 0x00000000, that is, the connection address is the same as the storage address (not specified AT); main. o is placed AT the beginning of 4096 (0x1000 is the storage address specified by AT), but its running address is 0x30000000. Before running, it must start from 0x1000 (loading address) copy to 0x30000000 (run address). In this process, you need to read flash and copy the program to the corresponding location to run it. This is the difference between the storage address and the operation, called loading the time domain and running the time domain, which can be determined separately in the. lds connection script file.

Compiled. LDS file, which is called and executed with-tfilename when you use the arm-Linux-LD connection command, such as arm-Linux-LD-tnand. lds x. o y. o-o xy. o. You can also use the-ttext parameter to directly specify the connection address, for example:

Arm-Linux-LD-ttext 0x30000000 X. o y. O-o xy. o

Since the program has two types of addresses, it involves some jump commands.

1) B step: the B jump command is relative to the current Pc value, and the offset is calculated by the bit [] of the command, this makes the use of the B command not dependent on the position of the Code to jump to, just look at the Command itself.

2) ldr pc, = step; this command is a pseudo command that will generate the following code after compilation:

Ldr pc, 0x30008000

<0x30008000>

Step

It refers to reading data from a location (STEP) in the memory and assigning it to the PC. It also depends on the current Pc value, but the offset is the connection address (runtime address) of step ), so you can use it to redirect from flash to ram.

(3) In addition, it is necessary to repeat the pseudocommands of adr. The relocate code in U-boot implements whether the current program is in RAM or in Flash through adr:

Relocate:/* relocate u-boot to RAM */

Adr r0, _ start r0 is the current position of the Code

/* Adr pseudocommand. The assembler automatically calculates the value of "_ start" in this command based on the value of the current PC, and puts the value of PC to r0 when executing the command to start:

When this segment is executed in flash, r0 = _ start = 0; when this segment is executed in RAM, _ start = _ TEXT_BASE (in board/smdk2410/config. the value specified in mk) is 0x33F80000, that is, the start of the code snippet that U-Boot copied to RAM */

Ldr r1, _ TEXT_BASE/* test whether to start from Flash or from RAM. The result of executing this sentence is always 0x33FF80000, because this value is specified by the link */

Cmp r0, r1/* compare r0 and r1. do not perform relocation during debugging */

 

 

 

 

 

 

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.