Makefile Analysis of U-boot

Source: Internet
Author: User
Tags srec

By the top-level makefile file, comb the U-boot compilation process.

Tips:

in large makefile, it is often necessary to determine the value of a variable , and a small method is:

$ (Shell echo "Variable0_val = $ (variable0_val)" > V_file.txt) $ (shell echo "Variable1_val = $ (variable1_val)" >> V_file.txt)

1. First, determine the variables required in the make process (makefile's gaze is changed to/* */).

VERSION = 2010PATCHLEVEL = 06SUBLEVEL =extraversion =ifneq "$ (sublevel)" "" "U_boot_version = $ (version). $ (Patchlevel). $ ( Sublevel) $ (extraversion) else/* u_boot_version = 2010.06 */u_boot_version = $ (VERSION). $ (patchlevel) $ (extraversion) endif/* obj variable is null */timestamp_file = $ (obj) Include/timestamp_autogenerated.hversion_file = $ (obj) include/version_ autogenerated.h/* Hostarch: Get the hardware architecture of the host * "SED-E" means the command script followed, "s/xxx/yyy/" means to look for "xxx" from the printing information and then replace it with "yyy", "." As a wildcard character. * uname-m command to get host schema information * execution process: * uname-m result is "i686", conforms to "s/i.86/i386/" command script, "i686" is replaced with "i386" * Final result: Hostarch = i386 */hostarch : = $ (Shell uname-m | sed-e s/i.86/i386/-E s/sun4u/sparc64/-e s/arm.*/arm/-e s/sa110/arm/-E s/ppc64/p owerpc/-E s/ppc/powerpc/-e s/macppc/powerpc/)/*-S, print the kernel name * [: Upper:], all upper case letters * [: Lower:], all lower case letters * Execution Process: * Uname-s get the kernel name "Linux", tr convert uppercase of string to lowercase * end result: Hostos = Linux */hostos: = $ (Shell u Name-s |     TR ' [: Upper:] ' [: Lower:] ' | Sed-e ' S/\ (cygwin\). */cygwin/')/* Set Shell to bash if possible, otherwise fall back to sh * end result: Shell =/bin/bash */shell: = $ (Shell if [ -X "$ $BASH"]; then echo $ $BASH; else if [-x/bin/bash]; Then Echo/bin/bash; else echo sh; Fi  FI)/* Hostarch Hostos SHELL is the information that compiles u-boot hosts */exporthostarch Hostos shell/* Deal with colliding definitions from tcsh etc. */vendor=/* allow for silent builds */ifeq (, $ (findstring s,$ (makeflags))) Xecho = Echoelsexecho =: endif/* u-boot support in other directories Compile and process the target file so that you can keep the source code clean * The directory is specified in 2 ways: * 1) Add "-O dir" key when executing make command--' Make o=/tmp/build all ' * 2) Set environment variable Build_dir--' export Buil D_dir=/tmp/build '; The function of the ' make ' */ifdef o/* origin function is to tell a variable to come from there, and it does not change the variable. * The Origin function has the following conditions * 1) If the variable o,$ (Origin O) has never been defined to return ' undefined ' * 2) If the variable o is an environment variable, $ (Origin o) returns ' Environment ' * 3) If the variable o is the default definition, $ (Origi n O) returns ' Default ' * 4 if the variable o is defined in Makefile, $ (Origin o) returns ' file ' * 5) If the variable o from the command line, $ (Origin o) returns ' command lines ' * 6) If the variable o is redefined, $ (ori Gin o) returns ' override ' * 7 if the variable O is an automatic variable, such as "[Email protected]" "$<", etc., $ (Origin O) returns ' Automatic ' */ifeq ("$ (Origin O)", "Command line") Build_dir: = $ (O) endifendif/* if Build_dir is not empty, assign to variable Saved-output */ifneq ($ (build_dir),) Saved-output: = $ (build_dir)/* Attempt to create a output directory. *-D File:file exists and is a directory */$ (Shell [-D ${build_dir}] | | mkdir-p ${build_dir})/* Verify if it was succes Sful. */build_dir: = $ (Shell CD $ (build_dir) &&/bin/pwd) $ (if $ (build_dir), $ (Error output Directory "$ (saved-output)" does not exist)) ENDIF # IFNEQ ($ (build_dir),)/* CURDIR =. * Objtree =. * Srctree =. * Topdir =. * Lndir =. */objtree:= $ (if $ (build_dir), $ (Build_dir), $ (CURDIR)) srctree:= $ (CURDIR) topdir:= $ (srctree) lndir:= $ (objtree) Exporttopdir srctree objtree/* mkconfig =./mkconfig * Mkconfig Analysis in the previous: U-boot makefile Analysis mkconfig "*/http blog.csdn.net/u013686019/article/details/42295291 */mkconfig:= $ (srctree)/mkconfigexport MKCONFIGifneq ($ (OBJTREE) , $ (srctree)) remote_build:= 1export remote_buildendif/* $ (obj) and (SRC) is defined in CONFIG.MK but here in main makefilE * We also need them before CONFIG.MK is included which are the case for * some targets as unconfig, clean, clobber, dis  Tclean, etc. */IFNEQ ($ (Objtree), $ (srctree)) obj: = $ (objtree)/SRC: = $ (srctree)/elseobj: =src: =endifexport obj src/* make Sure Cdpath settings don ' t interfere */unexport cdpath############################################################## ###########/* the "Tools" is needed early, so put this first * Don ' t include stuff already do in $ (LIBS) */subdirs= too LS Examples/standalone examples/api/*. Phony is used to mark a pseudo-target * what is a pseudo-target? Is that we define a goal, but this goal does not depend on the specific document * What does "pseudo-target" do? Suppose that the directory in which the makefile is located has a file whose name is the same as a target in the makefile, and because the file is not dependent on any files, it is always up to date, and the target with the same name as the file will not be executed, depending on the build rule of make. Phony: $ (subdirs) ifeq ($ (obj) include/config.mk,$ (wildcard $ (obj) include/config.mk)/* include autoconf.mk before  Config.mk So, the config options is available * to all top level build files. We need the dummy all:target to prevent the * dependency target in AUTOCONF.MK.DEP from being the default. */all:sinClude $ (obj) Include/autoconf.mk.depsinclude $ (obj) Include/autoconf.mkinclude $ (obj) include/config.mk/* arm arm920t smdk2410 Samsung s3c24x0 */exportarch CPU BOARD VENDOR soc/* The ifeq will not be executed, cross_compile? = arm-linux-in File arch/arm/config.mk In Assignment */ifeq ($ (Hostarch), $ (ARCH)) Cross_compile =endif$ (Shell echo "hostarch     = $ (hostarch)" > V_file.txt) $ (Shell echo "ARCH         = $ (Arch)" >> v_file.txt) $ (Shell echo "cross_compile= $ (Cross_compil E) ">> v_file.txt)/* Load other configuration */include $ (topdir)/config.mk


2, second, according to the specified CPU, the first to compile start. S file.

/* U-boot Objects....order is important (i.e. start must be first)/* OBJS  = $ (cpudir)/START.O

3, for different CPU, development Board, call their respective directory makefile to generate the corresponding library.

/* Addprefix, add prefix function * Function: Add prefix to each word after * Example: $ (addprefix src/,foo bar) return value is "Src/foo src/bar" */OBJS: = $ (Addprefix $ (obj), $ (O BJS)) LIBS = Lib/libgeneric.alibs + = Lib/lzma/liblzma.alibs + = lib/lzo/liblzo.alibs + $ (shell if [-F board/$ (VENDOR)/com Mon/makefile]; Then echo "board/$ (VENDOR)/common/lib$ (VENDOR). a"; FI) LIBS + = $ (cpudir)/lib$ (CPU). aifdef Soclibs + = $ (cpudir)/$ (Soc)/lib$ (SOC). Aendiflibs + = arch/$ (arch)/lib/lib$ (arch) . alibs + = fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ EXT2/LIBEXT2FS.A fs/yaffs2/libyaffs2.a Fs/ubifs/libubifs.alibs + = net/libnet.alibs + Disk/libdisk.aLIBS + = drivers/ Bios_emulator/libatibiosemu.alibs + = drivers/block/libblock.alibs + drivers/dma/libdma.alibs + = drivers/fpga/ Libfpga.alibs + = drivers/gpio/libgpio.alibs + drivers/hwmon/libhwmon.alibs + drivers/i2c/libi2c.alibs + = drivers/ Input/libinput.alibs + = drivers/misc/libmisc.alibs + drivers/mmc/libmmc.alibs + drivers/mtd/libmtd.alibs + = DriverS/mtd/nand/libnand.alibs + = drivers/mtd/onenand/libonenand.alibs + drivers/mtd/ubi/libubi.alibs + = drivers/mtd/spi/ Libspi_flash.alibs + = drivers/net/libnet.alibs + drivers/net/phy/libphy.alibs + drivers/pci/libpci.alibs + = drivers/ Pcmcia/libpcmcia.alibs + = drivers/power/libpower.alibs + drivers/spi/libspi.alibs + drivers/rtc/librtc.alibs + = Drivers/serial/libserial.alibs + = drivers/twserial/libtws.alibs + drivers/usb/gadget/libusb_gadget.alibs + = drivers /usb/host/libusb_host.alibs + = drivers/usb/musb/libusb_musb.alibs + drivers/usb/phy/libusb_phy.alibs + = drivers/ Video/libvideo.alibs + = drivers/watchdog/libwatchdog.alibs + common/libcommon.alibs + Lib/libfdt/libfdt.aLIBS + API /libapi.alibs + = Post/libpost.alibs: = $ (Addprefix $ (obj), $ (LIBS)). Phony: $ (LIBS) $ (timestamp_file) $ (version_file)/* Boarddir = samsung/smdk2410 */libboard = board/$ (boarddir)/lib$ ( BOARD). Alibboard: = $ (Addprefix $ (obj), $ (Libboard))
$ (OBJS):d epend$ (make)-C $ (cpudir) $ (if $ (remote_build), [email protected],$ (Notdir [email protected])) $ ( LIBS):d Epend $ (subdirs) $ (make)-C $ (dir $ (subst $ (obj),, [email protected])) $ (libboard):d Epend $ (LIBS) $ (make)-C $ (Dir $ (subst $ (obj), [email protected]) $ (subdirs):d epend$ (make)-C [email protected] all$ (ldscript): depend$ (make)-C $ (dir [email protected]) $ (notdir [email protected]) $ (obj) U-boot.lds: $ (ldscript) $ (CPP) $ ( Cppflags) $ (ldppflags)-ansi-d__assembly__-P-<$^ >[email protected]$ (NAND_SPL): $ (TIMESTAMP_FILE) $ ( Version_file) $ (obj) include/autoconf.mk$ (make)-C nand_spl/board/$ (Boarddir) all$ (U_boot_nand): $ (NAND_SPL) $ (obj) U-boot.bincat $ (obj) Nand_spl/u-boot-spl-16k.bin $ (obj) u-boot.bin > $ (obj) u-boot-nand.bin$ (ONENAND_IPL): $ ( Timestamp_file) $ (version_file) $ (obj) include/autoconf.mk$ (make)-C onenand_ipl/board/$ (Boarddir) all$ (U_BOOT_ Onenand): $ (ONENAND_IPL) $ (obj) U-boot.bincat $ (onenand_bin) $ (obj) u-boot.bin > $ (obj) u-boot-onenand.bin$ (Version_file): @ (printf ' #define u_boot_version "U-boot%s%s" \ n ' "$ (u_boot_version)" ' $ (Shell $ (topdir)/ Tools/setlocalversion $ (topdir)) > [email protected] @cmp-S [email protected] [email protected] & amp;& rm-f [email protected] | | mv-f [email protected] [email protected]$ (timestamp_file): @LC_ALL =c date + ' #define U_boot_date "%b%d%c%y" ' > [email protected] @LC_ALL =c date + ' #define U_boot_time "%T" ' >> [email protected]gdbtools:$ (Make) -C Tools/gdb All | | Exit 1updater:$ (Make)-c Tools/updater All | | Exit 1env:$ (Make)-C tools/env all mtd_version=${mtd_version} | | Exit # explicitly make _depend in subdirs containing multiple targets to prevent# parallel sub-makes creating. Depend fil Es simultaneously.depend dep:$ (timestamp_file) $ (version_file) $ (obj) include/autoconf.mkfor dir in $ (subdirs) $ (CPUDIR ) $ (dir $ (ldscript)); Do $ (make)-C $ $dir _depend; Donetag_subdirs = $ (subdirs) Tag_subdirs + = $ (dir $ (__libs)) TAG_subdirs + = Includetags ctags:ctags-w-o $ (obj) ctags ' Find $ (tag_subdirs)-name ' *. [ChS] '-print ' Etags:etags-a-o $ (obj) etags ' Find $ (tag_subdirs)-name ' *. [ChS] '-print ' Cscope:find $ (tag_subdirs)-name ' *. [ChS] '-print > Cscope.filescscope-b-q-ksystem_map = $ (NM) $ | Grep-v ' \ (compiled\) \|\ (\.o$$\) \|\ ([Auw] \) \|\ (\.\.ng$$\) \|\ (lash[rl]di\) ' | Lc_all=c sort$ (obj) system.map:$ (obj) u-boot@$ (call system_map,$<) > $ (obj) system.map## auto-generate the Autoconf.mk file (which is included by all makefiles) # # This target actually generates 2 files;  Autoconf.mk and autoconf.mk.dep.# The DEP file is only include in this top level makefile to determine when# to regenerate The autoconf.mk file.$ (obj) INCLUDE/AUTOCONF.MK.DEP: $ (obj) include/config.h include/common.h@$ (Xecho) Generating [ Email protected]; SET-E; : Generate the Dependancies; $ (CC)-X c-ddo_deps_only-m $ (hostcflags) $ (cppflags)-mq $ (obj) include/autoconf.mk include/common.h > [EMAIL&NBSP;PR otected]$ (obj) inCLUDE/AUTOCONF.MK: $ (obj) include/config.h@$ (xecho) generating [email protected]; SET-E; : Extract the config macros; $ (CPP) $ (CFLAGS)-DDO_DEPS_ONLY-DM Include/common.h | Sed-n-F tools/scripts/define2mk.sed > [email protected] && mv [email protected] [email  protected]######################################################################## #else #!config.mkall $ (obj) U-boot.hex $ (obj) U-boot.srec $ (obj) U-boot.bin $ (obj) u-boot.img $ (obj) U-boot.dis $ (obj) U-boot $ (filter-out tools,$ (  Subdirs) $ (timestamp_file) $ (version_file) Gdbtools Updater env depend DEP tags ctags etags cscope $ (obj) System.map: @echo "System not Configured-see README" >&2@ exit 1tools:$ (make)-C toolstools-all:$ (make)-C tools Host_tools_all=ye ndif# config.mk.PHONY:CHANGELOGCHANGELOG:git log--no-merges u-boot-1_1_5. | unexpand-a | Sed-e ' s/\s\s*$$//' > [email protected]include/license.h:tools/bin2header COPYING cat COPYING | Gzip-9-C |./tools/bin2header LicenSe_gzip > include/license.h######################################################################## #unconfig: @rm-F $ (obj) include/config.h $ (obj) include/config.mk $ (obj) board/*/config.tmp $ (obj) board/*/*/config.tmp $ (obj) Include/autoconf.mk $ (obj) include/autoconf.mk.dep%:%_config$ (make) ############################################# ########################### #smdk2410_config: unconfig@$ (mkconfig) $ (@:_config=) arm arm920t smdk2410 Samsung S3c24x0

4, the above generated. O,. A file is linked by board/$ (Boarddir)/config.mk, U-boot.lds determined address, script.


5, and according to the need to convert to other formats of executable files, such as binary format, S_record format, etc.:

/* Add GCC lib */ifdef use_private_libgccifeq ("$ (USE_PRIVATE_LIBGCC)", "yes") PLATFORM_LIBGCC =-L $ (objtree)/arch/$ ( ARCH)/LIB-LGCCELSEPLATFORM_LIBGCC =-L $ (USE_PRIVATE_LIBGCC)-LGCCENDIFELSEPLATFORM_LIBGCC =-L $ (Shell dirname ' $ (CC) $ (CFLAGS)-print-libgcc-file-name ')-lgccendifplatform_libs + = $ (PLATFORM_LIBGCC) export platform_libs/* Special Flags For CPP when processing the linker script. * Pass The version down so we can handle backwards compatibility * on the fly.   */ldppflags + =-include $ (topdir)/include/u-boot/u-boot.lds.h $ (Shell $ (LD)--version | Sed-ne ' S/gnu ld version \ ([0-9][0-9]*\) \.\ ([0-9][0-9]*\]. */-dld_major=\1-dld_minor=\2/p ') ifeq ($ (config_nand_u_ BOOT), y) nand_spl = Nand_splu_boot_nand = $ (obj) u-boot-nand.binendif/* subst function: * $ (subst from, to, text), in text "text" with "to" Instead of each "from" */__OBJS: = $ (subst $ (obj), $ (OBJS)) __libs: = $ (subst $ (obj), $ (LIBS)) $ (subst $ (obj), $ (libboard)) ####### ##################################################################/* always AppEnd all So, Arch Config.mk's can add custom ones */all + = $ (obj) U-boot.srec $ (obj) U-boot.bin $ (obj) System.map $ (u_boot_ NAND) $ (U_boot_onenand) all:$ (All)/* on the top level of CONFIG.MK * as= $ (cross_compile) as * ld= $ (cross_compile) LD * cc= $ (cross_compile ) GCC * cpp= $ (CC)-E * ar= $ (cross_compile) AR * nm= $ (cross_compile) NM * ldr= $ (cross_compile) LDR * strip= $ (cross_compile ) Strip * Objcopy = $ (cross_compile) objcopy * OBJDUMP = $ (cross_compile) OBJDUMP * ranlib= $ (cross_compile) Ranlib *//* based on generated U-boot convert to other format executable */$ (obj) u-boot.hex:$ (obj) u-boot$ (objcopy) ${objcflags}-o ihex $< [email protected]$ (obj ) u-boot.srec:$ (obj) u-boot$ (objcopy)-O srec $< [email protected]$ (obj) u-boot.bin:$ (obj) u-boot$ (objcopy) ${ Objcflags}-o binary $< [email protected]$ (obj) u-boot.ldr:$ (obj) u-boot$ (create_ldr_env) $ (LDR)-T $ (config_ BFIN_CPU)-c [email protected] $< $ (ldr_flags) $ (obj) u-boot.ldr.hex:$ (obj) u-boot.ldr$ (objcopy) ${OBJCFLAGS}- O Ihex $< [email protected]-i binary$ (obj) U-boot.ldr.srec:$ (obj) u-boot.ldr$ (objcopy) ${objcflags}-o srec $< [email protected]-i binary$ (obj) u-boot.img: $ (obj) u-boot.bin$ (obj) tools/mkimage-a $ (ARCH)-T firmware-c none-a $ (text_base)-e 0-n $ (shell sed-n-E ' s/.*u_boot_v Ersion//p ' $ (version_file) | Sed-e ' s/"[]*$$/for $ (BOARD) BOARD"/')-D $< [email protected]$ (obj) u-boot.imx: $ (obj) u-boot.bin$ (obj) too Ls/mkimage-n $ (imx_config)-T imximage-e $ (text_base)-D $< [email protected]$ (obj) U-BOOT.KWB: $ (obj) U-boo t.bin$ (obj) tools/mkimage-n $ (kwd_config)-T kwbimage-a $ (text_base)-E $ (text_base)-D $< [email protected]$ (ob j) u-boot.sha1:$ (obj) u-boot.bin$ (obj) tools/ubsha1 $ (obj) u-boot.bin$ (obj) u-boot.dis:$ (obj) u-boot$ (OBJDUMP)-D $< > [email protected]gen_uboot = Undef_sym= ' $ (OBJDUMP)-X $ (Libboard) $ (LIBS) | Sed-n-E ' s/.*\ ($ (sym_prefix) __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$ (obj) u-boot:depend $ (subdirs) $ (OBJS) $ (libboard) $ (LIBS) $ (ldscript) $ (obj) u-boot.lds$ (Gen_uboot) ifeq ($ (config_kallsyms), y) smap= ' $ (call system_map,u-boot) | awk ' $$2 ~/[ttww]/{printf $$1 $$3 ' \\\\000 '} '; $ (CC) $ (CFLAGS)-dsystem_map= "\" $${smap}\ ""-C Common/system_map.c-o $ (obj) common/system_map.o$ (gen_uboot) $ (obj) Common/system_map.oendif

Makefile Analysis of U-boot

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.