Just understanding it this way makes sense for some processes, and it is consistent with what is said in some materials.
The download address and runtime address in the scatter file are used in the compilation and linking stages.
For example, there is the following scatter file, taking the jump from assembly to c file as an example.
LOAD 0x0
{
JMAIN +0
{
jmain.o(jmain,+first)
}
TEST 0x200
{
test.o
*(+RO,+RW,+ZI)
}
}
jmain.s is just a jump,
b __main,
main is defined in test.c.
void main(){}
The 0x0 at LOAD in the scatter file represents the download address, which means that all .o files generated in the entire project file
are arranged from 0x0 from front to back when compiled (jmian.o starts at 0x0, test.o follows jmain.o), of course, there may be some processing in the middle
, but generally speaking, it is like this. For example, it can be understood that the generated .bin file starts from 0x0, jmain.o and test.o
and others. There is no gap between them.
The runtime address in scatter, such as 0x200, is used to guide the compiler to compile instructions. There is a situation:
if 0x200 is changed to 0x100, the compiled binary code is: 0xea00003e, when it is 0x200, the instruction is 0xea00007e.
The difference here shows that the compiler generates the binary code of the instruction according to the runtime address.
Therefore, I think the download address can be regarded as the first address of a memory segment. The instructions stored at this address need to be compiled and generated
when generating binary code .
The CPU will jump to the instruction at 0x200 when it runs . In this way, it
is consistent with the address at run time and download time mentioned in general materials.
But there is still a problem. In the above example, if the .bin file is downloaded to the 0x0 address of the board, the CPU will run 0xea00007e after starting to run from 0x0
, but there is no instruction we want to run at 0x200, such as main(). Therefore, there is a copy process that needs to be
performed before jumping to main().
When compiling and linking, the linker will save the address 0x200 to a certain address. After __main, 0x200 will be taken out from the address
, and test.o and the following things will be copied from the address at the time of downloading (behind jmain.o, that is, the address mentioned above)
to the address 0x200 through the loop, and arranged in sequence. After copying, jump to 0x200, that is, running 0xea00007e will be normal.
This copy process can be done by the compiler, or we can write code ourselves.
Back to the ro base setting in ads, it is the download address in scatter = the runtime address of the root region. In ads, set ro
base=0x10000, and download the generated .bin to the board's ram, such as mx 0x8000, g 0x8000, the program can run normally. This is because
.bin is placed at 0x8000 on the board. The reason for running from 0x8000 is that the CPU's PC is always +4. The instructions before the jump
do not involve absolute addresses, relative addresses, and their binary codes do not involve these addresses. So it can run normally. When running to b
__main, the copy is completed using the loop automatically generated by ads. 0x10000 is involved in the copy. It is this copy and the subsequent
b __rt_entry that enable the program to run normally.
In this way, the load address in the scatter file is not so important.
Reference address:Understanding of ARM load and run-time addresses
The download address and runtime address in the scatter file are used in the compilation and linking stages.
For example, there is the following scatter file, taking the jump from assembly to c file as an example.
LOAD 0x0
{
JMAIN +0
{
jmain.o(jmain,+first)
}
TEST 0x200
{
test.o
*(+RO,+RW,+ZI)
}
}
jmain.s is just a jump,
b __main,
main is defined in test.c.
void main(){}
The 0x0 at LOAD in the scatter file represents the download address, which means that all .o files generated in the entire project file
are arranged from 0x0 from front to back when compiled (jmian.o starts at 0x0, test.o follows jmain.o), of course, there may be some processing in the middle
, but generally speaking, it is like this. For example, it can be understood that the generated .bin file starts from 0x0, jmain.o and test.o
and others. There is no gap between them.
The runtime address in scatter, such as 0x200, is used to guide the compiler to compile instructions. There is a situation:
if 0x200 is changed to 0x100, the compiled binary code is: 0xea00003e, when it is 0x200, the instruction is 0xea00007e.
The difference here shows that the compiler generates the binary code of the instruction according to the runtime address.
Therefore, I think the download address can be regarded as the first address of a memory segment. The instructions stored at this address need to be compiled and generated
when generating binary code .
The CPU will jump to the instruction at 0x200 when it runs . In this way, it
is consistent with the address at run time and download time mentioned in general materials.
But there is still a problem. In the above example, if the .bin file is downloaded to the 0x0 address of the board, the CPU will run 0xea00007e after starting to run from 0x0
, but there is no instruction we want to run at 0x200, such as main(). Therefore, there is a copy process that needs to be
performed before jumping to main().
When compiling and linking, the linker will save the address 0x200 to a certain address. After __main, 0x200 will be taken out from the address
, and test.o and the following things will be copied from the address at the time of downloading (behind jmain.o, that is, the address mentioned above)
to the address 0x200 through the loop, and arranged in sequence. After copying, jump to 0x200, that is, running 0xea00007e will be normal.
This copy process can be done by the compiler, or we can write code ourselves.
Back to the ro base setting in ads, it is the download address in scatter = the runtime address of the root region. In ads, set ro
base=0x10000, and download the generated .bin to the board's ram, such as mx 0x8000, g 0x8000, the program can run normally. This is because
.bin is placed at 0x8000 on the board. The reason for running from 0x8000 is that the CPU's PC is always +4. The instructions before the jump
do not involve absolute addresses, relative addresses, and their binary codes do not involve these addresses. So it can run normally. When running to b
__main, the copy is completed using the loop automatically generated by ads. 0x10000 is involved in the copy. It is this copy and the subsequent
b __rt_entry that enable the program to run normally.
In this way, the load address in the scatter file is not so important.
Previous article:Analysis of the startup process of ARM multi-core processor
Next article:About the interrupt call of 44b0
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- Arduino - 315/433MHz RF Wireless Transceiver Module
- Analysis of the problem of unstable signal and no output when connected to power on of wireless pressure sensor
- SinlinxA33 Development Board Linux Interrupt Programming 4-Final Code (1)
- Production of msp430g2553 emulator download line
- EEWORLD University Hall ---- Computer Vision Course Tsinghua University Wang Mingzhe
-
EEWORLD University Hall----Live Replay:
takes you to learn about ADI's digital health biosensor series - Switching power supply using microcontroller for loop control
- [Recruitment] Shenzhen foreign companies are urgently recruiting RF antenna engineers, looking forward to your joining
- No more confusion! A guide to choosing a cordless vacuum cleaner
- [Raspberry Pi 3B+ Review] GCC Compiles HelloWorld & Lighting Program