Linux Startup Analysis (2)-kernel startup address Determination

Source: Internet
Author: User

Http://blogold.chinaunix.net/u/31100/showart_244622.html (reproduced)

======================================

Author: taoyuetao
Email: tao_yuetao@yahoo.com.cn
Blog: taoyuetao.cublog.cn

2006-11-03

======================================

The kernel compilation link process relies on the vmlinux. LDS file. For example, the vmlinux. LDS file of ARM is located in kernel/ARCH/ARM/vmlinux. LDS,
But the file is generated by the vmlinux-armv.lds.in, depending on the different source files of the compilation options can also be the vmlinux-armo.lds.in,
Vmlinux-armv-xip.lds.in.

The vmlinux-armv.lds generation process is in the kernel/ARCH/ARM/makefile

Ldscript = ARCH/ARM/vmlinux-armv.lds.in

ARCH/ARM/vmlinux. LDS: ARCH/ARM/makefile $ (ldscript )\
$ (Wildcard include/config/CPU/32.h )\
$ (Wildcard include/config/CPU/26.h )\
$ (Wildcard include/config/ARCH/*. h)
@ Echo 'generating $ @'
@ SED's/textaddr/$ (textaddr)/; S/dataaddr/$ (dataaddr)/'$ (ldscript) >$ @

Vmlinux-armv.lds.in File Content:

Output_arch (ARM)
Entry (stext)
Sections
{
. = Textaddr;
. Init: {/* init code and Data */
_ Stext = .;
_ Init_begin = .;
* (. Text. init)
_ Proc_info_begin = .;
* (.Proc.info)
_ Proc_info_end = .;
_ Arch_info_begin = .;
* (.Arch.info)
_ Arch_info_end = .;
_ Tagtable_begin = .;
* (. Taglist)
_ Tagtable_end = .;
* (. Data. init)
. = Align (16 );
_ Setup_start = .;
* (. Setup. init)
_ Setup_end = .;
_ Initcall_start = .;
* (. Initcall. init)
_ Initcall_end = .;
. = Align (4096 );
_ Init_end = .;
}
Textaddr is the virtual address of kernel startup, which is defined in kernel/ARCH/ARM/makefile:
Ifeq ($ (config_cpu_32), Y)
Processor = armv
Textaddr = 0xc0008000
Ldscript = ARCH/ARM/vmlinux-armv.lds.in
Endif
Note that this is a virtual address rather than a physical address.

Generally, after vmlinux is generated, the kernel is compressed into zimage, and the compressed directory is kernel/ARCH/ARM/boot.
The files downloaded to flash are compressed zimage files, and zimage is compressed by vmlinux and decompressedProgramAs shown in:

| ----------------- | \ | ----------------- |
| |\| |
| \ | Decompress code |
| Vmlinux | \ | --------------- | zimage
| |\| |
|
|
|
|/| --------------- |
|/
|/
|/
| --------------- |/
The zimage link script is also called vmlinux. LDS and is located in kernel/ARCH/ARM/boot/compressed.
Is generated by the vmlinux. LDS. In file in the same directory. The content is as follows:
Output_arch (ARM)
Entry (_ start)
Sections
{
. = Load_addr;
_ Load_addr = .;
. = Text_start;
_ Text = .;
. Text :{
_ Start = .;
Specifically, load_addr is decompressed in zimage. Code The ram offset address. text_start is the offset address of the kernel Ram startup. This address is the physical address.
Defined in the kernel/ARCH/ARM/boot/MAKEFILE file:
Ztextaddr = 0
Zreladdr = 0xa0008000

Ztextaddr is the ram offset address of the decompressed code, and zreladdr is the offset address of the kernel Ram startup. Here, the ztextaddr address is 0,
Obviously, it is incorrect because the starting address of RAM on my platform is 0xa0000000. In the MAKEFILE file, I saw several lines of comments on this address:
# We now have a pic decompressor implementation. decompressors running
# From RAM shoshould not define ztextaddr. decompressors running directly
# From Rom or flash must define ztextaddr (preferably via the config)
He realized that, when extracting data in Ram, he does not need to specify the running address in Ram. If it is in flash, he must specify the address. So
Here, ztextaddr is specified as 0, that is, no actual address is specified.

There is a script in the kernel/ARCH/ARM/boot/compressed/MAKEFILE file:
Sedflags = s/text_start/$ (ztextaddr)/; S/load_addr/$ (zreladdr)/; S/bss_start/$ (zbssaddr )/
Make text_start = ztextaddr, load_addr = zreladdr.

vmlinux. the lDs generation process is as follows:
vmlinux. LDS: vmlinux. lDs. in makefile $ (topdir)/ARCH/$ (ARCH)/boot/makefile $ (topdir )/. config
@ sed "$ (sedflags)" $ @
the above section analyzes the kernel startup address and summarizes the kernel startup Address Settings:
1. Set
textaddr = 0xc0008000
virtual address of kernel startup in the kernel/ARCH/ARM/MAKEFILE file.
2. Set kernel/ARCH/ARM
zreladdr = 0xa0008000
physical address of kernel startup in the/boot/MAKEFILE file
you need to set the
ztextad Dr address.

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.