From Uimage to source file

Source: Internet
Author: User
Uimage

Uimage is made out of a script.
scripts/mkuboot.sh Script

The overall command is
scripts/mkuboot.sh-a arm-o linux-c none-t kernel-a 0x80008000-e 0x80008000-n ' Linux-3.10.0 '-D arch/arm/ Boot/zimage arch/arm/boot/uimage

Command parsing:
    -A ARM architecture is an arm-
    o Linux system that is Linux-
    C none uncompressed-
    t kernel The type is kernel-a
    0x80008000 load address is 0x80008000-
    e 0x80008000 The ingress address is 0x80008000-
    n ' Linux-3.10.0 ' name is Linux-3.10.0 -
    d arch/arm/boot/zimage input data file is arch/arm/boot/zimage
    arch/arm/boot/uimage output file is Arch/arm/boot/uimage

scripts/mkuboot.sh the Mkimage command to determine if there is a call to Mkimage $@, and then made out arch/arm/boot/uimage, the options in the parameters written to the first 64 bytes of Uimage, For example, load address and ingress address zimage

Uimage is based on mkimage commands and zimage. Commands can be compiled in the Uboot source tools directory or can be installed directly.

Let's see how Arch/arm/boot/zimage did it.

He's got it by Arch/arm/boot/compressed/vmlinux binary.
Arch/arm/boot/.zimage.cmd wrote in the

Arm-hisiv300-linux-objcopy-o binary-r. comment-s  arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage

Command parsing:
    -o binary   output target is binary file-
    R. Comment does not copy. Comment Segment-
    s                  does not copy relocation information and symbolic information to the output file (destination file) to
    arch/ Arm/boot/compressed/vmlinux input file
    arch/arm/boot/zimage output file
Vmlinux

And then we'll see how Arch/arm/boot/compressed/vmlinux did it.
Arch/arm/boot/compressed/.vmlinux.cmd wrote in the

Arm-hisiv300-linux-ld-el \--defsym _kernel_bss_size=138792 \
                                            --defsym zreladdr=0x80008000 \ P \
                                            --no-undefined \ x \ -T arch/arm/boot/compressed/vmlinux.lds \ arch/arm/boot/ COMPRESSED/HEAD.O ARCH/ARM/BOOT/COMPRESSED/PIGGY.GZIP.O \ Arch/arm/boot/compre SSED/MISC.O ARCH/ARM/BOOT/COMPRESSED/DECOMPRESS.O \ arch/arm/boot/compressed/s TRING.O arch/arm/boot/compressed/hyp-stub.o \ Arch/arm/boot/compressed/lib1fun

CS.O arch/arm/boot/compressed/ashldi3.o\-O arch/arm/boot/compressed/vmlinux Command parsing:-el connection Little-eThe Ndian object.  This affects the default output format--defsym _kernel_bss_size=138792 defines a global variable in the output file _kernel_bss_size value of 138792--defsym zreladdr=0x80008000 Define a global variable in the output file zreladdr value to 0x80008000-p dynamic library problem--no-undefined seems to be the problem of symbolic redefinition, not clear-X Delete all temporary local Symbols-t arch/arm/boot/compressed/vmlinux.lds to replace the default link script with Arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compr ESSED/HEAD.O input file-o arch/arm/boot/compressed/vmlinux output file-rwxrwxr-x 1 Linux linux 3.2M April 20:33 vmlinux*-RW-RW -r--1 Linux linux 3.1M April 20:33 PIGGY.GZIP.O
VmlinuxThis vmlinux is a vmlinux in arch/arm/boot/compressed/, note the vmlinux in the post-paragraph of the article

How did Vmlinux.lds do it? No backup of commands, no print information, only makefile.

Arch/arm/boot/compressed/makefile wrote in the

Sedflags    = s/text_start/$ (ztextaddr)/;s/bss_start/$ (ZBSSADDR)/

$ (obj)/vmlinux.lds: $ (obj)/vmlinux.lds.in Arch/arm/boot/makefile $ (kconfig_config)
    @sed "$ (sedflags)" < $< > $@

parse the above command, which is to replace the vmlinux.lds.in Two strings in the Vmlinux.lds, and then put them in a.

Vmlinux.lds parsing:

ENTRY (_start) indicates that the symbolic _start is set to the entry address, and the entry address (ENTRY point) is the address of the first user space that the process executes in the process address space
SECTIONS
{
  . = 0;                                Place the locator symbol at 0
  _text =.;                            Place the _text symbol in the 0 position

  . Text: {
    _start =.;                     Place the _start symbol in the 0 position
    * (. Start) to put the.                           start segment of all input files into the. Text field of the output file
    * (. Text)                            Put the. Text segment of all the input files into the. Text segment * (. text.*) * (. Fixup) * (. gnu.warning) * (.
    glue_7t) * (.
    glue) of the output file. _7)
  }
}

We saw it before.
-rwxrwxr-x 1 Linux linux 3.2M April 20:33 vmlinux
-rw-rw-r–1 Linux linux 3.1M April 20:33 PIGGY.GZIP.O
So the suspect kernel is mostly in the PIGGY.GZIP.O file. PIGGY.GZIP.O

So under the face of PIGGY.GZIP.O analysis, according to Makefile in this sentence of

$ (obj)/piggy.$ (suffix_y). O:  $ (obj)/piggy.$ (suffix_y) force

judgment, Depending on

The piggy.gzip then look at the next sentence

$ (obj)/piggy.$ (suffix_y): $ (obj)/. /image Force
    $ (call if_changed,$ (suffix_y))

Obviously, this means that when you rely on updates, recall the gzip command, which is to compress the image into a piggy.gzip image

View arch/arm/boot/. Image.cmd

Arm-hisiv300-linux-objcopy-o binary-r. comment-s  vmlinux arch/arm/boot/image

Command parsing:-
    o binary   The output target is a binary file-
    R. Comment does not copy. Comment Segment-
    s                  does not copy relocation information and symbolic information to the output file (destination file) to
    vmlinux the top vmlinux as the input file
    arch/arm/boot/image Output File
VmlinuxThis vmlinux is the top-level vmlinux, note the vmlinux of the previous paragraph of the article
View. Vmlinux.cmd
/bin/bash scripts/link-vmlinux.sh Arm-hisiv300-linux-ld-el-  p--no-undefined-x--build-id


scripts/ link-vmlinux.sh parsing

first uses the following function to link the VMLINUX.O

modpost_link ()
{
    ${ld} ${ldflags}-r-o ${1} ${kbuild_ Vmlinux_init}                   \   
        --start-group ${kbuild_vmlinux_main}--end-group
}

then use scripts/mod/ Modpost checked the VMLINUX.O and generated module.symvers

${make}-F "${srctree}/scripts/makefile.modpost" VMLINUX.O

Then link the contents of the Init directory

${make}-F "${srctree}/scripts/makefile.build" Obj=init

and then used to execute three times kallsyms

every time is Vmlinux_link generates a file, and then kallsyms uses the file to generate a binary file.

Finally, a KALLSYMSO is generated and then generated with KALLSYMSO vmlinux
Vmlinux_link

Vmlinux_link parsing

LD \-
m elf_i386--emit-relocs--build-id \
-O $ (2) \
t \
arch/x86/kernel/head_32.o arch/x86/kernel/ HEAD32.O arch/x86/kernel/head.o init/built-in.o \
--start-group usr/built-in.o arch/x86/built-in.o kernel/ BUILT-IN.O mm/built-in.o fs/built-in.o ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.o test/ BUILT-IN.O lib/lib.a arch/x86/lib/lib.a lib/built-in.o arch/x86/lib/built-in.o drivers/built-in.o sound/ BUILT-IN.OFIRMWARE/BUILT-IN.O ARCH/X86/PCI/BUILT-IN.O ARCH/X86/POWER/BUILT-IN.OARCH/X86/VIDEO/BUILT-IN.O net/ BUILT-IN.O--end-group \
$ (1)
kallsysms

Kallsyms parsing
kallsyms System Compilation Process BUILT-IN.O

View Init/.built-in.o.cmd

arm-hisiv300-linux-ld-el-r-o init/built-in.o init/main.o init/version.o init/mounts.o INIT/INITRAMFS.O init/calibrate.o init/init_task.o 

command parsing:
    -el Connection Little-endian object. This affects the default output format
    -R produces relocatable output -
    o init/built-in.o output file
    init/main.o init/version.o init/mounts.o init/initramfs.o init/calibrate.o init/init _TASK.O in and

out of other directories BUILT-IN.O is also generated in this way. For example, the FS directory generated FS/EXOFS/BUILT-IN.O files under subdirectories, and then chained together, generating fs/fs/ BUILT-IN.O file
References

LDS Syntax parsing
Arch/arm/boot/compressed/vmlinux generation Process
Resolves version checking mechanisms for Linux kernel loadable modules
KALLSYMS System Compilation Process

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.