. LDS in arm uboot

Source: Internet
Author: User
For the. LDS file, it defines the connection process after the program is compiled, and determines the storage location of each segment of the executable program. Although I have not used it yet, it is very important to know about it. Let's take a look at the complete description of the. LDS file format on the GNU Official Website:

Sections {
...
SecnameStartBlock (Align) (Noload): (Ldadr)
{Contents}>Region:Phdr=Fill
...
}
Secname and contents are mandatory, and others are optional. Below are some common examples:
1. secname: segment name 2. Contents: determines which content is placed in this segment. It can be the entire target file or a segment in the target file (code segment, data segment, etc) 3. Start: the connection (run) Address of the current segment. If at (ldadr) is not used, the address stored in this segment is also start. On the GNU website, start can be described using any type of address description symbol. 4. At (ldadr): defines the address for storing (loading) This section. Let's look at a simple example: (from "2410 full development")

/* NAND. LDS */
Sections {
Firtst 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, their running address is also 0x00000000, that is, the connection and storage address are the same (not specified at); main. O is placed at the beginning of 4096 (0x1000, which is specified by at, the storage address), but its running address is 0x30000000. Before running, it must start from 0x1000 (loading location) copy to 0x30000000 (runtime), and read the NAND Flash. This is the difference between the storage address and the connection (run) Address, known as loading the time domain and running the time domain, which can be specified separately in the. LDS connection script file. The compiled. LDS file is called and executed with-tfilename when you use the arm-Linux-LD connection command, as shown in figure
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, as shown in figure
Arm-Linux-LD-ttext 0x30000000 X. o y. O-o xy. O. Since the program has two types of addresses, there are some differences between jump commands. Here we write them down. If you forget them, you can check them, I have forgotten a lot of things before... In arm assembly, there are two jump Methods: B jump command and LDR command assign value to PC. I have summarized as follows: (1) B Step1: 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 program using the B command not dependent on the position of the Code to be jumped, only the instruction itself. (2) ldr pc, = Step1: This command reads data from a location in the memory (Step1) and assigns it to the PC. It also depends on the value of the current PC, however, the offset is the connection address (runtime address) at that position (step 1), so you can use it to redirect from flash to ram. (3) In addition, it is necessary to review the pseudocommands of ADR. The relocate code in U-boot is to use ADR to realize whether the current program is in Ram or flash. Still use the comments at the time:

Relocate:/* relocate U-boot to Ram */
ADR r0, _ start/* R0 is the current position of the Code */
/* ADR pseudocommand. The assembler automatically calculates the Pc value when executing the command _ start based on the current Pc value and puts it in R0:
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, U-boot copies the code to the beginning of the code snippet executed in Ram )*/
LDR R1, _ text_base/* test whether it is started from flash or Ram */
/* The result of executing this sentence R1 is always 0x33ff80000, because this value is specified by the compiler (set in ads or-d )*/
CMP r0, R1/* compare R0 and R1. do not perform relocation during debugging */
Next, take a look at a formal connection script file with the u-boot.lds. The basic functions of this file can still be seen clearly. Although I have analyzed a lot above, the GNU-style symbols still confuse me, despise yourself... Output_format ("elf32 & shy; littlearm", "elf32 & shy; littlearm", "elf32 & shy; littlearm ")
; Specifies that the output executable file is in the ELF format, 32-bit arm command, small-end
Output_arch (ARM)
; Specify the platform for outputting executable files as arm
Entry (_ start)
; Specifies the starting code segment of the output executable file as _ start.
Sections
{
. = 0x00000000; Starting from 0x0
. = Align (4); the Code is 4 bytes aligned
. Text:; specifies the code segment
{
CPU/ARM920T/start. O (. Text); the first part of the code
* (. Text); Other code
}
. = Align (4)
. Rodata: {* (. rodata)}; specifies the read-only data segment.
. = Align (4 );
. Data: {* (. Data)}; specifies the read/write data segment.
. = Align (4 );
. Got: {* (. Got)}; specifies the got segment. The got segment is a custom segment of uboot and is not a standard segment.
_ U_boot_cmd_start =.; assign _ u_boot_cmd_start to the current position, that is, the start position.
. U_boot_cmd: {* (. u_boot_cmd)}; specify the u_boot_cmd segment. uboot puts all uboot commands in this segment.
_ U_boot_cmd_end =.; assign _ u_boot_end _end to the current position, that is, the end position.
. = Align (4 );
_ Bss_start =.; assign _ bss_start to the current position, that is, the start position of the BSS segment.
. BSS: {* (. BSS)}; specifies the BSS segment
_ End =.; assign the value of _ end to the current position, that is, the end position of the BSS segment.
}

88888888 **********************************

Difference between R and ADR

From: http://coon.blogbus.com/logs/2738861.html

LDR r0, _ start

ADR r0, _ start

LDR r0, = _ start

NOP

MoV PC, LR

_ Start:

NOP

Set Ro to 0x0c008000 during compilation

Please refer to the following link for more information:

0c008000 start-0x14>:

C008000: e59f000c LDR r0, [PC, #12]; c008014 <_ Start>

C008004: e28f0008 add r0, PC, #8; 0x8

C008008: e59f0008 LDR r0, [PC, #8]; c008018 <_ start + 0x4>

C00800c: e1a00000 Nop (mov r0, R0)

C008010: e1a0f00e mov PC, LR

0c008014 <_ Start>:

C008014: e1a00000 Nop (mov r0, R0)

C008018: 0c008014 stceq 0, cr8, [R0],-#80

Analysis:

LDR r0, _ start

Read the value from the memory address _ start. After executing this command, R0 = 0xe1a00000

ADR r0, _ start

Get the address of _ start to r0, but please refer to The Decompilation result, it is irrelevant to location. In fact, the relative position obtained. For example, if the code runs at 0x0c008000, then R0 = 0x0c008014 is obtained for ADR R0 and _ start. If the code runs at address 0, it is 0x00000014.

LDR r0, = _ start

Obtain the absolute address of _ start. This absolute address is determined during link. It seems that this is only an instruction, but it takes up two 32bit spaces. One is the instruction and the other is the data of _ start (because the value of _ start cannot be determined during compilation, in addition, the mov command cannot be used to assign a 32bit constant to R0. Therefore, an extra space is required to store the real data of _ start, which is 0x0c008014 ).

Therefore, we can see that this is an absolute addressing. No matter where the code runs, the result is R0 = 0x0c008014.

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.