Detailed analysis and summary of the top-level makefile of "Current Year Plan" 1-u-boot (combined with a large number of online experts)

Source: Internet
Author: User
Tags srec

Version = 1
Patchlevel = 1
Sublevel = 6
Extraversion =
U_boot_version = $ (version ). $ (patchlevel ). $ (sublevel) $ (extraversion) # $ (XXX) is equivalent to the macro definition in C. $ (version) is 1, because version = 1, the other three are similar
Version_file = $ (OBJ) include/version_autogenerated.h # define the version File

# Uname: Write the operating system name in use to the standard output.
#-M Displays the machine ID of the hardware running system
# Define the variable. hostarch stores the machine ID, that is, the Host Architecture type. | the pipe $ (shell XXX): XXX represents the shell command, and the shell command is executed.
# SED is an online editor that processes a row of content at a time.
# When processing, store the currently processed rows in the temporary buffer zone, which is called the pattern space. Then, use the SED command to process the content in the buffer zone. After processing, send the buffer content to the screen.
# Process the next row until the end of the file. The file content is not changed unless you use the redirection storage output. Sed is mainly used to automatically edit one or more files, simplify repeated operations on files, and write conversion programs.
# Sed-e '1, 5d '-E's/test/check/'example ----- (-e) option allows multiple commands to be executed in the same line.
# As shown in the example, the First Command deletes lines 1 to 5, and the second command replaces test with check. The command execution sequence has an impact on the result.
# If both commands are replacement commands, the first replacement command will affect the result of the second replacement command.
Hostarch: = $ (shell uname-M |/
Sed-e s/I .86/i386 // # Replace i386 with I .86
-E s/sun4u/sparc64 //
-E s/arm. */ARM // # pass the uname-M result (Host Architecture type or machine ID number) to the SED command through the pipeline, and then replace all the modes prefixed with arm
-E s/sa110/ARM //
-E s/PowerPC/PPC //
-E s/macppc/PPC /)

# The defined variable Hostos stores the host-installed operating system that is currently running.
Hostos: = $ (shell uname-S | tr '[: Upper:] ''[: lower:]' |/sed-E's // (cygwin /). */cygwin/') # TR is a shell command that can implement many sed functions. Here, TR' [: Upper:] '[: lower:] 'means to convert the upper-case letter l in Linux in the pipeline to the lower-case letter L
# This statement indicates that the host is installed and the operating system name is currently running, and the upper-case letters in the system name are converted to lower-case letters.

# Then match all the "/(cygwin/). *" modes in the system name in the SED stream editor, and then replace them with the "cygwin" mode.
Export hostarch Hostos # output two makefile variables hostarch and Hostos

# Deal with colliding definitions from tcsh etc. # used to handle conflicting definitions from tcsh and so on
# In general, shell can be divided into two types. The first category is derived from the Bourne shell, including
# SH, KSh, Bash, and zsh. The second type is derived from C shell, including CSH and
# Tcsh. In addition, there is also an RC, some people think that this class is a class, some people think that the class is in the Bourne shell.
Vendor = # developer

######################################## #################################
#
# U-boot build supports producing a object files to the separate external
# The u- boot compilation process supports generating the final target file from a defined path
# Directory. Two use cases are supported:
# Two methods are provided here
#1) add O = to the make command line # first usage: run the make o =/DIR command on the terminal (that is, the directory where the generated target file is stored)
# 'Make o =/tmp/build all'
#
#2) Set environement variable build_dir to point to the desired location # Second usage: Specify the target file storage directory by setting environment variables, as shown below:
# 'Export build_dir =/tmp/build'
# 'Make'
#
# The second approach can also be used with a makeall script # The second method can also be written as a makeall script and then run makeall, as shown below:
# 'Export build_dir =/tmp/build'
# './Makeall'
#
# Command line 'o = 'setting overrides build_dir environent variable. # The command line 'o = 'setting overwrites the setting of the Environment Variable build_dir.
#
# When none of the above methods is used the local build is saved med and # if you do not use the above two methods, then the target file is placed in the source code top-level directory, that is, the top-level directory of the U-BOOT
# The object files are placed in the source directory.
#
# Method 1
Ifdef o # If O has been defined
Ifeq ("$ (Origin O)", "command line") # If 'O' is defined in the command line
Build_dir: = $ (o) # assign the 'O' value to build_dir.
Endif
Endif
# Method 2
Ifneq ($ (build_dir),) # If build_dir is not empty
Saved-output: = $ (build_dir) # assign the value of build_dir to saved-output.

# Attempt to create a output directory. # generate an output path, that is, the build_dir directory of the target file.
$ (Shell [-d $ {build_dir}] | mkdir-p $ {build_dir}) # judge whether build_dir is a directory. If not, create it. [] is a condition judgment statement.

# Verify if it was successful. test whether the directory is successfully created.
Build_dir: = $ (shell CD $ (build_dir) &/bin/pwd) # enter the build_dir directory, use the PWD command to display the current path, and then assign this path to build_dir
$ (If $ (build_dir), $ (error output directory "$ (saved-output)" does not exist) # Here we use an IF function, this means that if $ (build_dir) is not empty, nothing is executed (null is returned). Otherwise, the error function is executed and the error message is output.
Endif # ifneq ($ (build_dir ),)
# Ifneq ($ (build_dir),) # indicates that if the target file storage directory is not defined
# Makefile defines the source code and the directory where the target file is stored. The build_dir directory of the target file can be specified through make o = dir. If not specified, it is set to the top-level directory of the source code.
# If the output directory is not specified during compilation, build_dir is empty. Other directory variables are as follows:
# The three directories topdir srctree objtree will be called for makefile in the lower layer. You need to specify and export
# Objtree and lndir are the directories for storing generated files, and topdir and srctree are the source code directories.
Objtree: = $ (if $ (build_dir), $ (build_dir), $ (curdir) # If $ (build_dir) is not empty, $ (build_dir) is returned ), and assigned to the objtree, that is, the custom target storage directory.
Srctree: = $ (curdir) # assign the current source code directory $ (curdir) to srctree
Topdir: = $ (srctree) # assign the current source code directory $ (curdir) to topdir
Lndir: =$ (objtree) # store the generated directory file
Export topdir srctree objtree

Mkconfig: = $ (srctree)/mkconfig # defines the variable mkconfig: this variable points to a script, that is, mkconfig in the directory where the top source code is located.
Export mkconfig # export this variable

Ifneq ($ (objtree), $ (srctree) # If the objtree and srctree represent different paths
Remote_build: = 1 # Set the variable remote_build = 1, which is equivalent to flag.
Export remote_build # export this variable
Endif

# $ (OBJ) and (SRC) are defined in config. MK but here in main makefile # $ (OBJ) and $ (SRC) are all defined in the config. in the MK script configuration file,
# We also need them before config. mk is wrongly ded which is the case for # But in this main makefile, we also need them,
# Some targets like unconfig, clean, clobber, distclean, etc. # Because the main makefile contains config. before MK, $ (OBJ) and $ (SRC) occasionally become the case for targets such as unconfig, clean, clobber, distclean, and etc:
Ifneq ($ (objtree), $ (srctree) # When the target storage directory is not the U-BOOT top-level directory (source directory)
OBJ: = $ (objtree)/# define OBJ to make it equal to the target storage directory
SRC: = $ (srctree)/# define SRC to make it equal to the directory where the source code is located, that is, the top-level directory of U-boot
Else # otherwise, it is set to null.
OBJ: =
SRC: =
Endif
Export obj src # export these two directories

######################################## #################################
# Wildcards can be automatically extended in rules, but they are not normally extended in variables or in function parameters.
# If you need to extend the wildcard in these scenarios, you should use the wildcard function in the following format:
# $ (Wildcard pattern ...)
Ifeq ($ (objtree)/include/config. mk, $ (wildcard $ (objtree)/include/config. mk ))

# Load arch, board, and CPU configuration download configurations
Include $ (objtree)/include/config. mk # the above two config. mk values are the same before they contain config. mk.
Export arch CPU board vendor SOC

Ifndef cross_compile # If no cross compiler is defined
Ifeq ($ (hostarch), PPC)
Cross_compile =
Else
Ifeq ($ (ARCH), PPC)
Cross_compile = PowerPC-Linux-
Endif
# Here you can add the installation path of the cross compiler to the arm-Linux-before, for example, if your cross-compiler installation path is/root/U-boot/usr/local/ARM/3.3.2/bin/
# You can define cross_compile =/root/U-boot/usr/local/ARM/3.3.2/bin/ARM-Linux-
# In this way, you do not need to specify cross_compile = arm-Linux-when compiling on the terminal.
# Note: during kernel compilation, the cross-compiler must be installed in/usr/local/arm; otherwise, an error will occur !!!!!
Ifeq ($ (ARCH), arm) # If arch = arm
Cross_compile = arm-Linux-# specify the path of the Cross Compiler
Endif
Ifeq ($ (ARCH), i386)
Ifeq ($ (hostarch), i386)
Cross_compile =
Else
Cross_compile = i386-linux-
Endif
Endif
Ifeq ($ (ARCH), MIPS)
Cross_compile = mips_4kc-
Endif
Ifeq ($ (ARCH), NiO)
Cross_compile = nios-elf-
Endif
Ifeq ($ (ARCH), nios2)
Cross_compile = nios2-elf-
Endif
Ifeq ($ (ARCH), m68k)
Cross_compile = m68k-elf-
Endif
Ifeq ($ (ARCH), microblaze)
Cross_compile = Mb-
Endif
Ifeq ($ (ARCH), Blackfin)
Cross_compile = bfin-elf-
Endif
Ifeq ($ (ARCH), avr32)
Cross_compile = avr32-
Endif
Endif
Endif

Export cross_compile # export the Cross Compiler

# Load other configuration
# Load other settings. Here is the config. mk configuration file under the top-level directory. This file mainly performs three tasks:
#1. Cross-compiler is defined. 2. Compilation options are defined. 3. compilation rules are defined.
Include $ (topdir)/config. mk

######################################## #################################
# U-boot objects... order is important (I. e. Start must be first)
# Start. O must be placed first in the target file, because the first code executed by uboot is start. S.
# The following section is based on our $ (CPU) to determine the objs
Objs = CPU/$ (CPU)/start. o
Ifeq ($ (CPU), i386)
Objs + = CPU/$ (CPU)/start16.o
Objs + = CPU/$ (CPU)/reset. o
Endif
Ifeq ($ (CPU), ppc4xx)
Objs + = CPU/$ (CPU)/resetvec. o
Endif
Ifeq ($ (CPU), mpc83xx)
Objs + = CPU/$ (CPU)/resetvec. o
Endif
Ifeq ($ (CPU), mpc85xx)
Objs + = CPU/$ (CPU)/resetvec. o
Endif
Ifeq ($ (CPU), mpc86xx)
Objs + = CPU/$ (CPU)/resetvec. o
Endif
Ifeq ($ (CPU), BF533)
Objs + = CPU/$ (CPU)/start1.o CPU/$ (CPU)/interrupt. o cpu/$ (CPU)/cache. o
Objs + = CPU/$ (CPU)/cplbhdlr. o cpu/$ (CPU)/cplbmgr. o cpu/$ (CPU)/flush. o
Endif

Objs: = $ (addprefix $ (OBJ), $ (objs) # This sentence means to add the path of the target file to start in the form of an fix. o, and then assigned to objs
# Below are the library files required for uboot Compilation
Libs = lib_generic/libgeneric.
Libs + = Board/$ (boarddir)/Lib $ (board). A # based on the platform used
Libs + = CPU/$ (CPU)/Lib $ (CPU). A # based on the platform used
Ifdef SOC
Libs + = CPU/$ (CPU)/$ (SOC)/Lib $ (SOC). A # based on the platform used
Endif
Libs + = lib _ $ (ARCH)/Lib $ (ARCH). A # based on the platform used
# Common library files
Libs + = FS/cramfs/libcramfs. A fs/fat/libfat. A fs/fdos/libfdos. A fs/jffs2/libjffs2.a/
FS/reiserfs/libreiserfs. A fs/ext2/libext2fs.
Libs + = net/Libnet.
Libs + = Disk/libdisk.
Libs + = RTC/librtc.
Libs + = DTT/libdtt.
Libs + = Drivers/libdrivers.
Libs + = Drivers/NAND/libnand.
Libs + = Drivers/nand_legacy/libnand_legacy.a
Libs + = Drivers/sk98lin/libsk98lin.
Libs + = post/libpost. A post/CPU/libcpu.
Libs + = Common/libcommon.
Libs + = $ (boardlibs)

Libs: =$ (addprefix $ (OBJ), $ (libs ))
. Phony: $ (libs) # pseudo target
# According to the generated include/config. mk file, we can define several variables such as arch, CPU, board, and SOC.
# Determine the directory files that the hardware platform depends on. The related (dependent) directories of the smdk2410 platform and the generated library files are as follows:
# Board/smdk2410/: library file board/smdk2410/libsmdk2410.a
# CPU/ARM920T/: library file CPU/ARM920T/libarm920t.
# CPU/ARM920T/s3c24x0: library file CPU/ARM920T/s3c24x0/libs3c24x0.
# Lib_arm: library file lib_arm/libarm.
# Include/ASM-arm: header file
# Include/cnofigs/smdk2410.h: header file
# Add GCC lib
Platform_libs + =-L $ (shell dirname '$ (CC) $ (cflags)-print-libgcc-file-name')-lgcc

# The "Tools" are needed early, so put this first
# Don't include stuff already done in $ (libs) do not include anything already in $ (libs)
# Pseudo-target subdirs: used to execute make files in the tools, examples, post, and post/CPU subdirectories
Subdirs = tools/
Examples/
Post/
Post/CPU
. Phony: $ (subdirs)

Ifeq ($ (config_nand_u_boot), Y)
Nand_spl = nand_spl
U_boot_nand = $ (OBJ) u-boot-nand.bin
Endif

_ Objs: = $ (SUBST $ (OBJ), $ (objs ))
_ Libs: = $ (SUBST $ (OBJ), $ (libs ))

######################################## #################################
######################################## #################################
# The following final generation of various image files, the final file to be generated, u_boot_nand defined in the front, for the u-boot-nand.bin
All = $ (OBJ) u-boot.srec $ (OBJ) u-boot.bin $ (OBJ) system. Map $ (u_boot_nand)
# All depends on $ (all) to generate the image file. Pay attention to various dependencies.
ALL: $ (all)

$ (OBJ) u-boot.hex: $ (OBJ) U-boot
$ (Objcopy) $ {objcflags}-O ihex $ <$ @

$ (OBJ) u-boot.srec: $ (OBJ) U-boot
$ (Objcopy) $ {objcflags}-o srec $ <$ @

$ (OBJ) u-boot.bin: $ (OBJ) U-boot
$ (Objcopy) $ {objcflags}-O binary $ <$ @

$ (OBJ) u-boot.img: $ (OBJ) u-boot.bin
./Tools/mkimage-A $ (ARCH)-T Firmware-c none/
-A $ (text_base)-E 0/
-N $ (shell sed-n-e's/. * u_boot_version // P' $ (version_file) |/
Sed-E's/"[] * $/for $ (board) Board "/')/
-D $ <$ @

$ (OBJ) u-boot.dis: $ (OBJ) U-boot
$ (Objdump)-d $ <>$ @

$ (OBJ) U-boot: depend version $ (subdirs) $ (objs) $ (libs) $ (ldscript)
Undef_sym = '$ (objdump)-x $ (libs) | sed-n-e's /. */(_ u_boot_cmd _. */)/-U/1/P' | sort | uniq ';/
CD $ (lndir) & $ (LD) $ (ldflags) $ undef_sym $ (_ objs )/
-- Start-group $ (_ libs) -- end-group $ (platform_libs )/
-Map u-boot.map-o u-boot

$ (Objs ):
$ (Make)-c cpu/$ (CPU) $ (if $ (remote_build), $ @, $ (notdir $ @))

$ (Libs ):
$ (Make)-C $ (DIR $ (SUBST $ (OBJ), $ @))

$ (Subdirs ):
$ (Make)-C $ @ All

$ (Nand_spl): Version
$ (Make)-C nand_spl/board/$ (boarddir) All

$ (U_boot_nand): $ (nand_spl) $ (OBJ) u-boot.bin
Cat $ (OBJ) nand_spl/u-boot-spl-16k.bin $ (OBJ) u-boot.bin> $ (OBJ) u-boot-nand.bin

Version:
@ Echo-n "# define u_boot_version/" U-Boot ">$ (version_file );/
Echo-n "$ (u_boot_version)" >$ (version_file );/
Echo-N $ (shell $ (config_shell) $ (topdir)/tools/setlocalversion/
$ (Topdir) >>$ (version_file );/
Echo "/" ">>$ (version_file)

Gdbtools:
$ (Make)-C tools/GDB all | Exit 1

Updater:
$ (Make)-C tools/Updater all | Exit 1

Env:
$ (Make)-C tools/ENV all | Exit 1

Depend Dep:
For dir in $ (subdirs); do $ (make)-C $ dir _ depend; done

Tags ctags:
Ctags-w-o $ (objtree)/ctags 'Find $ (subdirs) include/
Lib_generic board/$ (boarddir) CPU/$ (CPU) lib _ $ (ARCH )/
FS/cramfs fs/fat fs/fdos fs/jffs2/
Net disk rtc dtt drivers Drivers/sk98lin common/
/(-Name CVS-prune/)-O/(-name '*. [CH]'-print /)'

Etags:
Etags-a-o $ (objtree)/etags 'Find $ (subdirs) include/
Lib_generic board/$ (boarddir) CPU/$ (CPU) lib _ $ (ARCH )/
FS/cramfs fs/fat fs/fdos fs/jffs2/
Net disk rtc dtt drivers Drivers/sk98lin common/
/(-Name CVS-prune/)-O/(-name '*. [CH]'-print /)'

$ (OBJ) system. MAP: $ (OBJ) U-boot
@ $ (Nm) $ <|/
Grep-V '/(Compiled/)/| /(/. o $/)/|/([auw]/)/| /(/. /. ng $/)/|/(lash [RL] di/) '|/
Sort> $ (OBJ) system. Map

######################################## #################################
Else
All $ (OBJ) u-boot.hex $ (OBJ) u-boot.srec $ (OBJ) u-boot.bin/
$ (OBJ) u-boot.img $ (OBJ) u-boot.dis $ (OBJ) U-boot/
$ (Subdirs) version gdbtools Updater env depend/
Dep tags ctags etags $ (OBJ) system. MAP:
@ Echo "system not configured-see readme"> & 2
@ Exit 1
Endif

. Phony: changelog
Changelog:
Git log -- no-merges U-Boot-1_1_5 .. |/
Unexpand-A | sed-E's // S/S * $ // '> $ @

 

######################################## #################################

Unconfig:
@ RM-F $ (OBJ) include/config. h $ (OBJ) include/config. mk/
$ (OBJ) Board/*/config. tmp $ (OBJ) Board/*/config. tmp
# This statement has been analyzed, that is, the first operation in mkconfig is performed, that is, deleting the header file and contained file in the last makexxx operation.
# The next step is the xxx_config definition related to the platform and Development Board. For example, when you execute make smdk2410_config
# The following definition is found:
Smdk2410_config: unconfig

A long segment is omitted.

Smdk2410_config: unconfig is found.

# Before analyzing this and the following commands, we need to understand that before compiling the U-BOOT, We need to execute # Make smdk2410_config
# Smdk2410_config is a target of makefile, which is defined as follows:
# Smdk2410_config: unconfig
# @ $ (Mkconfig) $ (@: _ Config =) arm ARM920T smdk2410 null s3c24x0
# Unconfig:
# @ RM-F $ (OBJ) include/config. h $ (OBJ) include/config. mk/
# $ (OBJ) Board/*/config. tmp $ (OBJ) Board/*/config. tmp
# First, run unconfig. obj src is defined above. This command clears the header file generated when the last make * _ config command is executed and the inclusion file of makefile. Mainly include/config. h and include/config. mk files.
# Then run @ $ (mkconfig) $ (@: _ Config =) arm ARM920T smdk2410 null s3c24x0
# Mkconfig is the mkcofig script file in the top-level directory, and the last five are input parameters. Mkcofig in the top-level directory will be analyzed later
# Generate a makefile that contains the include/config. mk file. Use five input parameters to define five variables.
# Arch = arm
# CPU = ARM920T
# Board = smdk2410
# Vendor = NULL
# SOC = s3c24x0

Smdk2410_config: unconfig # $ (@: _ Config =) removes "_ config" from "smdk2410_config" and returns "smdk2410 ".
@ $ (Mkconfig) $ (@: _ Config =) arm ARM920T smdk2410 null s3c24x0 # input 5 parameters

I will not analyze the rest in detail .. Limited time, limited capacity .. Haha

In conclusion, of course, we also refer to the valuable experience of our predecessors. The main task of top-level makefile is to organize the compilation of the entire U-boot project, which can be divided into several steps:

1. First, run make * _ config to input $ (@: _ Config =), arch, CPU, board, vendor, and SOC parameters (six parameters in total but not

Must exist at the same time), to mkconfig.

2. After receiving the passed parameters, mkconfig links the corresponding header folder of the include header folder to generate config. h

3. Execute make to call the makefile files of each subdirectory to generate all OBJ files (including start. O) and OBJ library files *..

4. Finally, link all target files through the linker to generate a uboot image. The corresponding tools are called for images of different formats.

Generated indirectly or directly by an elf image.

5. Link script/u-boot-1.1.6/board/smdk2410/u-boot.lds and the explanation of config. mk please refer to the two articles I transferred here, very detailed and well understood

After a rough analysis, it took me nearly a day and I have read many articles. It is helpful to understand the U-boot architecture and compilation.

Step 001 is here, and step 002 is to analyze start. S.

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.