OK6410A 开发板 (六) 4 OK6410A linux-5.11 镜像生成过程解析

  • 内核 镜像 解析
  • uImage 的 入口符号地址

linux-5.11 镜像 的生成过程

vmlinux               				-objcopy->   		    			             arch/arm/boot/Image
arch/arm/boot/Image         		-gzip & add arch/arm/boot/compressed/head.S->  	 arch/arm/boot/compressed/vmlinux
arch/arm/boot/compressed/vmlinux  	-objcopy->    				   	                 arch/arm/boot/zImage
arch/arm/boot/zImage        		-mkuboot->     						             arch/arm/boot/uImage

五种镜像的感性区别

vmlinux 							: 	5M
arch/arm/boot/Image 				: 	6.5M
arch/arm/boot/compressed/vmlinux 	:  	1.9M
arch/arm/boot/zImage 				: 	1.8M // 在这个层次,有两种镜像 zImage  和 bzImage(像是x86独有)
arch/arm/boot/uImage 				: 	1.8M

// 我们其实可以用 uImage/zImage/Image 三个中的一种被bootloader加载

五种镜像

  • vmlinux

arm-linux-gnueabi-gcc 
-E -Wp,-MMD,arch/arm/kernel/.vmlinux.lds.d  
-nostdinc 
-isystem /home/mmt/work/BiscuitOS/output/linux-5.10-arm32/arm-linux-gnueabi/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabi/7.4.1/include 
-I./arch/arm/include -I./arch/arm/include/generated  -I./include -I./arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I./include/uapi -I./include/generated/uapi 
-include ./include/linux/kconfig.h 
-D__KERNEL__ 
-mlittle-endian     
	//            Generate little-endian code.  This is the default when GCC is configured for an aarch64-*-* but not an aarch64_be-*-* target.

-DTEXT_OFFSET=0x00008000 
-P 

-Uarm
	//            Cancel any previous definition of name, either built in or provided with a -D option.

-D__ASSEMBLY__ 
-DLINKER_SCRIPT 
-o arch/arm/kernel/vmlinux.lds arch/arm/kernel/vmlinux.lds.S


arm-linux-gnueabi-ld 
-EL 
//        -EL Compile code for little endian targets.  Use of these options is now deprecated.  Users wanting little-endian code should use the "arc-elf32" and "arc-linux-uclibc" targets when building the tool chain, for which little-endian is the

--no-undefined
	//            Report unresolved symbol references from regular object files.  This is done even if the linker is creating a non-symbolic shared library.  The switch --[no-]allow-shlib-undefined controls the behaviour for reporting unresolved references
    //       found in shared libraries being linked in.

-X 
	//            Delete all temporary local symbols.  (These symbols start with system-specific local label prefixes, typically .L for ELF systems or L for traditional a.out systems.)

--pic-veneer
	// 没找到解释 
-z norelro
	//                Don't create an ELF "PT_GNU_RELRO" segment header in the object.

    //       now When generating an executable or shared library, mark it to tell the dynamic linker to resolve all symbols when the program is started, or when the shared library is linked to using dlopen, instead of deferring function call
    //           resolution to the point when the function is first called.

--build-id=sha1
//           Request the creation of a ".note.gnu.build-id" ELF note section or a ".buildid" COFF section.  The contents of the note are unique bits identifying this linked file.  style can be "uuid" to use 128 random bits, "sha1" to use a 160-bit
//           SHA1 hash on the normative parts of the output contents, "md5" to use a 128-bit MD5 hash on the normative parts of the output contents, or "0xhexstring" to use a chosen bit string specified as an even number of hexadecimal digits ("-" and
//           ":" characters between digit pairs are ignored).  If style is omitted, "sha1" is used.//

//           The "md5" and "sha1" styles produces an identifier that is always the same in an identical output file, but will be unique among all nonidentical output files.  It is not intended to be compared as a checksum for the file's contents.  A
//           linked file may be changed later by other tools, but the build ID bit string identifying the original linked file does not change.//

//           Passing "none" for style disables the setting from any "--build-id" options earlier on the command line.//

//       The i386 PE linker supports the -shared option, which causes the output to be a dynamically linked library (DLL) instead of a normal executable.  You should name the output "*.dll" when you use this option.  In addition, the linker fully
//       supports the standard "*.def" files, which may be specified on the linker command line like an object file (in fact, it should precede archives it exports symbols from, to ensure that they get linked in, just like a normal object file).//

//       In addition to the options common to all targets, the i386 PE linker support additional command line options that are specific to the i386 PE target.  Options that take values may be separated from their values by either a space or an equals
//       sign.
--orphan-handling=warn 
// Control how orphan sections are handled.  An orphan section is one not specifically mentioned in a linker script.

// MODE can have any of the following values:

// "place"
//    Orphan sections are placed into a suitable output section following the strategy described in Orphan // Sections.  The option --unique also effects how sections are placed.

// "discard"
//    All orphan sections are discarded, by placing them in the /DISCARD/ section.

// "warn"
//    The linker will place the orphan section as for "place" and also issue a warning.

// "error"
//    The linker will exit with an error if any orphan section is found.

// The default if --orphan-handling is not given is "place".
-o vmlinux 
-T ./arch/arm/kernel/vmlinux.lds 
--whole-archive 
           For each archive mentioned on the command line after the --whole-archive option, include every object file in the archive in the link, rather than searching the archive for the required object files.  This is normally used to turn an
           archive file into a shared library, forcing every object to be included in the resulting shared library.  This option may be used more than once.

           Two notes when using this option from gcc: First, gcc doesn't know about this option, so you have to use -Wl,-whole-archive.  Second, don't forget to use -Wl,-no-whole-archive after your list of archives, because gcc will add its own list
           of archives to your link and you may not want this flag to affect those as well.

arch/arm/kernel/head.o 
init/built-in.a 
usr/built-in.a 
arch/arm/built-in.a 
arch/arm/mach-s3c/built-in.a 
kernel/built-in.a 
certs/built-in.a 
mm/built-in.a 
fs/built-in.a 
ipc/built-in.a 
security/built-in.a 
crypto/built-in.a 
block/built-in.a 
arch/arm/lib/built-in.a 
lib/built-in.a 
drivers/built-in.a 
sound/built-in.a 
net/built-in.a 
virt/built-in.a 
--no-whole-archive 
//            Turn off the effect of the --whole-archive option for subsequent archive files.

--start-group 
arch/arm/lib/lib.a 
lib/lib.a 
--end-group 
.tmp_vmlinux.kallsyms2.o
  • arch/arm/boot/Image
arm-linux-gnueabi-objcopy 
-O binary 
           Write the output file using the object format bfdname.

-R .comment 
           Remove any section matching sectionpattern from the output file.  This option may be given more than once.  Note that using this option inappropriately may make the output file unusable.  Wildcard characters are accepted in
           sectionpattern.  Using both the -j and -R options together results in undefined behaviour.

-S  
           Do not copy relocation and symbol information from the source file.
vmlinux 
	infile
arch/arm/boot/Image
	outfile
  • arch/arm/boot/compressed/vmlinux
cat arch/arm/boot/compressed/../Image | 
gzip 
-n 
              When  compressing,  do  not  save  the  original file name and time stamp by default. (The original name is always saved if the name had to be
              truncated.) When decompressing, do not restore the original file name if present (remove only the gzip suffix from the compressed  file  name)
              and do not restore the original time stamp if present (copy it from the compressed file). This option is the default when decompressing.

-f 
              Force  compression or decompression even if the file has multiple links or the corresponding file already exists, or if the compressed data is
              read from or written to a terminal. If the input data is not in a format recognized by gzip, and if the option --stdout is  also  given,  copy
              the  input  data  without  change to the standard output: let zcat behave as cat.  If -f is not given, and when not running in the background,
              gzip prompts to verify whether an existing file should be overwritten.

-9 
              Regulate  the speed of compression using the specified digit #, where -1 or --fast indicates the fastest compression method (less compression)
              and -9 or --best indicates the slowest compression method (best compression).  The default compression level is -6 (that  is,  biased  towards
              high compression at expense of speed).

> arch/arm/boot/compressed/piggy_data



$ cat arch/arm/boot/compressed/piggy.S  
/* SPDX-License-Identifier: GPL-2.0 */
        .section .piggydata, "a"
        .globl  input_data
input_data:
        .incbin "arch/arm/boot/compressed/piggy_data"
        .globl  input_data_end
input_data_end:


arm-linux-gnueabi-gcc 
-Wp,-MMD,arch/arm/boot/compressed/.piggy.o.d  
-nostdinc 
-isystem /home/suws/ok6410/system-new/toolchain/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabi/7.4.1/include 
-I./arch/arm/include 
-I./arch/arm/include/generated  
-I./include 
-I./arch/arm/include/uapi 
-I./arch/arm/include/generated/uapi 
-I./include/uapi 
-I./include/generated/uapi 
-include ./include/linux/kconfig.h 
-D__KERNEL__ 
-mlittle-endian 
-D__ASSEMBLY__ 
-fno-PIE 
-mabi=aapcs-linux 
-mfpu=vfp 
	           Use hardware FPP floating point.  This is the default.  (FIS floating point on the PDP-11/40 is not supported.)

-funwind-tables
           Similar to -fexceptions, except that it just generates any needed static data, but does not affect the generated code in any other way.  You normally do not need to enable this option; instead, a language processor that needs this
           handling enables it on your behalf.
 
-marm 
           Select between generating code that executes in ARM and Thumb states.  The default for most configurations is to generate code that executes in ARM state, but the default can be changed by configuring GCC with the --with-mode=state
           configure option.

-Wa,-mno-warn-deprecated
	// 没找到 
-D__LINUX_ARM_ARCH__=6 
-march=armv6k 
-mtune=arm1136j-s
           Tune to cpu-type everything applicable about the generated code, except for the ABI and the set of available instructions.  While picking a specific cpu-type schedules things appropriately for that particular chip, the compiler does not
           generate any code that cannot run on the default machine type unless you use a -march=cpu-type option.  For example, if GCC is configured for i686-pc-linux-gnu then -mtune=pentium4 generates code that is tuned for Pentium 4 but still runs
           on i686 machines.

           The choices for cpu-type are the same as for -march.  In addition, -mtune supports 2 extra choices for cpu-type:

-include asm/unified.h 
-msoft-float
           Generate output containing library calls for floating point.

           Warning: the requisite libraries are not part of GCC.  Normally the facilities of the machine's usual C compiler are used, but this can't be done directly in cross-compilation.  You must make your own arrangements to provide suitable
           library functions for cross-compilation.

           On machines where a function returns floating-point results in the 80387 register stack, some floating-point opcodes may be emitted even if -msoft-float is used.


-DZIMAGE    
-c 
-o arch/arm/boot/compressed/piggy.o 
arch/arm/boot/compressed/piggy.S


arm-linux-gnueabi-gcc 
-E -Wp,-MMD,arch/arm/boot/compressed/.vmlinux.lds.d  
-nostdinc 
-isystem /home/mmt/work/BiscuitOS/output/linux-5.10-arm32/arm-linux-gnueabi/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabi/bin/../lib/gcc/arm-linux-gnueabi/7.4.1/include 
-I./arch/arm/include -I./arch/arm/include/generated  -I./include -I./arch/arm/include/uapi -I./arch/arm/include/generated/uapi -I./include/uapi -I./include/generated/uapi 
-include ./include/linux/kconfig.h 
-D__KERNEL__ 
-mlittle-endian     
-DTEXT_START="0" 
-DBSS_START="ALIGN(8)" 
-DTEXT_OFFSET="0x00008000" 
-DMALLOC_SIZE="65536" 
-P 
-Uarm 
-D__ASSEMBLY__ 
-DLINKER_SCRIPT 
-o arch/arm/boot/compressed/vmlinux.lds 
arch/arm/boot/compressed/vmlinux.lds.S



arm-linux-gnueabi-ld  
-EL   
--defsym _kernel_bss_size=190768 
			--defsym=symbol=expression
           Create a global symbol in the output file, containing the absolute address given by expression.  You may use this option as many times as necessary to define multiple symbols in the command line.  A limited form of arithmetic is supported
           for the expression in this context: you may give a hexadecimal constant or the name of an existing symbol, or use "+" and "-" to add or subtract hexadecimal constants or symbols.  If you need more elaborate expressions, consider using the
           linker command language from a script.  Note: there should be no white space between symbol, the equals sign ("="), and expression.

--no-undefined 
-X
--orphan-handling=warn 
-T arch/arm/boot/compressed/vmlinux.lds 
arch/arm/boot/compressed/head.o 
arch/arm/boot/compressed/piggy.o 
arch/arm/boot/compressed/misc.o 
arch/arm/boot/compressed/decompress.o 
arch/arm/boot/compressed/string.o 
arch/arm/boot/compressed/hyp-stub.o 
arch/arm/boot/compressed/lib1funcs.o 
arch/arm/boot/compressed/ashldi3.o 
arch/arm/boot/compressed/bswapsdi2.o 
-o arch/arm/boot/compressed/vmlinux

  • arch/arm/boot/zImage
arm-linux-gnueabi-objcopy 
-O binary 
-R .comment 
-S  
arch/arm/boot/compressed/vmlinux 
arch/arm/boot/zImage
  • arch/arm/boot/uImage
bash 
./scripts/mkuboot.sh 
-A arm 
	-A arm 架构是arm
-O linux
	-O linux 系统是linux
-C none  
	-C none 没压缩
-T kernel 
	-T kernel 类型是kernel
-a 0x50008000 
	加载地址
-e 0x50008000 
	入口地址
-n 'Linux-5.11.0-187606-gd64fe683e8d' 
	名字
-d arch/arm/boot/zImage 
	输入文件
arch/arm/boot/uImage
	输入文件

五种镜像的使用

  • uImage 的使用
bootcmd=fatload mmc 0:1 0x50008000 uImage;bootm 0x50008000;

fatload  就是一个一个字节的拷贝,下面就看 bootm 做了什么了

你可能感兴趣的:(ok6410开发板)