Generally, a program includes read-only segments and data segments that can be read and written.In the integrated development environment of arm, read-only code segments and constants are called Ro segments (readonly). read-write global variables and static variables are called RW segments (readwrite ); the variable to be initialized to zero in the RW segment is called the Zi segment (zeroinit ).For embedded systems, program images are stored in some non-volatile devices such as flash memory. during runtime, the RW segment of the program must be reloaded into the read/write Ram. This involves loading and running time domains of programs. Simply put, the programLoading time domainIt refers to the state in which the program is burned into flash,Operation Time DomainIt refers to the status when the program is executed. In simple cases, you can specify Ro base and RW base in the arm linker option of the analyticdb integrated development environment to inform the connector of the connection Base Address of RO and RW. In complex cases, for example, when the RO segment is divided into several parts and mapped to multiple locations in the bucket, you need to create aDistributed Load description fileTo notify the connector to connect a part of the program to an address space in the memory. It should be noted that the definition in the Distributed Loading description file should be based on the memory distribution after system redirection. After the boot program completes the initialization task, the main program should be transferred to ram for running to speed up the system.
What is an arm image file,The arm image file is actually an executable file, including the bin or hex format, which can be directly burned into the ROM for execution.In the axd debugging process, we debug the axf file. In fact, this is also an image file.A file header and some debugging information are added to the binfile..Generally, an image file consists of three output segments (RO, RW, and Zi. The so-called domain refers to the region where the entire bin image file is located. It is divided into loading and running domains.The loading domain is the work area where the image file is statically stored. Generally, the address space of the entire binfile in Flash is the loading domain. Of course, the program will not be executed in flash, generally, jobs are moved to the SDRAM to run. The address space in which the jobs are moved to the SDRAM is the runtime domain. The entered Code generally includes the code part and data part. This is the so-called input segment. After compilation, it becomes the RO and RW segments in the binfile, and the so-called Zi segments, this is the output segment.For the output segment in the loading field, generally the RO segment is followed by the RW segment, and the RW segment is followed by the Zi segment.These output segments are not consecutive in the running domain, but RW and Zi must be connected. Data in the Zi and RW segments can be RW attributes.
| Image $ Ro $ base | image $ Ro $ limit | image $ RW $ base | image $ Zi $ base | image $ zi $ limit | these variables are notified by the compiler, we can see their values in the MAKEFILE file. They indicate the address space of each output segment in the running domain,| Image $ Ro $ base | the starting address of the RO segment in the running domain. | image $ Ro $ limit | it is the end address of the RO segment in the running domain, and so on.We can specify it in linker output. In simple mode, RO base corresponds to | image $ Ro $ base |, RW base corresponds to | image $ RW $ base |,Because RW is connected to Zi, | image $ Zi $ base | equal to | image $ RW $ limit |. Other values are automatically calculated by the compiler.
Below is the handling part of the 2410 startup code. I will give a comment:
Baseofrom DCD | image $ Ro $ base |
Topofrom DCD | image $ Ro $ limit |
Baseofbss DCD | image $ RW $ base |
Baseofzero DCD | image $ Zi $ base |
Endofbss DCD | image $ Zi $ limit |
ADR r0, resetentry; resetentry is the starting address of the reset operation time domain, which is generally 0 in Boot Nand
LDR R2, baseofrom;
CMP r0, r2
Ldreq r0, topofrom; topofrom = 0x30001de0, end of the code segment address
Beq initram
LDR R3, topofrom
; Part 1: Move Ro to SDRAM through comparison. the destination address is from | image $ Ro $ base | to | image $ Ro $ limit | End
0
Ldmia R0 !, {R4-r7}; the R0 value is transferred to R4, R5, R6, R7 in turn as four consecutive 32 digits at the address (resetentry), while R0 increases.
Stmia R2 !, {R4-r7}; Save the values of R4, R5, R6, R7 in sequence to | image $ Ro $ base | Address, and R2.
CMP R2, R3
BCC % B0;
; Part 2: Move the RW segment to SDRAM. the destination address is from | image $ RW $ base | start to | image $ Zi $ base | End
Sub R2, R2, R3; r2 = 0; during the above copy, four dual characters (32-bit) are copied each time, but the RO segment size is not necessarily an integer multiple of 4, so it is possible to copy a few more double size, r2-r3 to get the number of multiple copies
Sub r0, R0, R2;R0-(r2-r3) can point R0 to the end address of RO in Boot Nand
Initram; carry RW to baseofbss
LDR R2, baseofbss; topofrom = 0x30001de0, baseofrw
LDR R3, baseofzero; baseofzero = 0x30001de0
0
CMP R2, R3
Ldrcc R1, [R0], #4
Strcc R1, [R2], #4
BCC % B0
; Part 3: Initialize the SDRAM Zi to 0 and the address ranges from | image $ Zi $ base | to | image $ Zi $ limit |
MoV r0, #0; init 0
LDR R3, endofbss; endofbss = 30001e40
1
CMP R2, R3
Strcc r0, [R2], #4
BCC % B1
So far, the three output segments (RO, RW, zi) are copied and initialized.
**************************************** ********************
Ro, RW, and Zi -- image $ ?? $ Limit meaning
Arm Program Composition
The "arm program" mentioned here refers to the program being executed in the arm system, rather than the bin image file stored in the Rom.
An arm program contains three parts: RO, RW, and Zi.
Ro is the instruction and constant in the program.
RW is the initialized variable in the program.
Zi is an uninitialized variable in the program.
The above three points can be understood:
Ro is readonly,
RW is read/write,
Zi is zero.
Arm image file Composition
The so-called arm image file refers to the binary file burned into the ROM and also becomes an image file. The following is called an image file.
The image file contains Ro and RW data.
The reason why the image file does not contain the Zi data is that the Zi data is 0 and does not need to be included. You only need to clear the region where the Zi data is located before running the program. It wastes storage space.
Q: Why must image contain Ro and RW?
A: The commands and constants in RO and the initialized variables in RW cannot be "born out of nothing" like Zi.
Arm Program Execution Process
From the above two points, we can know that the image file burned to the Rom is not exactly the same as the actual running arm program. Therefore, it is necessary to understand how the arm Program reaches the actual running state from the image in the Rom.
In fact, the commands in Rom should have at least the following functions:
1. Move RW from Rom to ram. Because RW is a variable, the variable cannot exist in Rom.
2. Clear all the ram regions where Zi is located. Because the Zi region is not in the image, the program needs to clear the desired Ram region based on the Zi address and size given by the compiler. Zi is also a variable. Similarly, the variable cannot exist in Rom. At the initial stage of the program running, the C program can access the variables normally after the commands in RO Have completed these two tasks. Otherwise, only codes without variables can be run.
Note: If a variable is initialized to 0, the variable will be processed in the Zi region in the same way as the volume of changes not initialized. That is, in the arm C program, all uninitialized variables are automatically initialized to 0. RO contains code and Ro data.
Summary:
1. commands and constants in C are compiled into Ro data.
2. The variable in C that is not initialized or initialized to 0 is compiled with Zi data.
3. A variable initialized to a non-0 value in C is compiled with RW data.