当前位置:网站首页>Top level makefile analysis of u-boot (3)
Top level makefile analysis of u-boot (3)
2022-07-18 04:39:00 【Cheap sword】
stay u-boot Top layer of Makefile analysis ( Two ) Analysis of config.mk Generation process of , Then continue to analyze the top level Makefile
export config.mk For environment variables
# load ARCH, BOARD, and CPU configuration
include $(obj)include/config.mk
export ARCH CPU BOARD VENDOR SOC
- take
include/config.mkThe file is loaded in and the five internal variables are exported as environment variables
Set the cross compilation tool chain
ifndef CROSS_COMPILE
ifeq ($(HOSTARCH),$(ARCH))
CROSS_COMPILE =
else
ifeq ($(ARCH),ppc)
CROSS_COMPILE = ppc_8xx-
endif
ifeq ($(ARCH),arm)
CROSS_COMPILE = arm-none-linux-gnueabi-
endif
…………
endif # HOSTARCH,ARCH
endif # CROSS_COMPILE
export CROSS_COMPILE
include $(TOPDIR)/config.mk
- This is one of the important jobs --------- Set the cross compilation tool chain
- The above code only lists the first few lines , Ellipsis is used to judge other platforms that cannot be used
- Because of what we set up earlier
ARCHThe value of the variable is arm, So here we find arm And modifyCROSS_COMPILEA variable's value - In actual use, it can also be modified here , But through
make CROSS_COMPILE=xxxTo set up the cross compilation tool chain - export
CROSS_COMPILEVariables are environment variables - The next analysis config.mk The key part of the document
config.mk Analysis of key parts of the document
Compiler settings
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
#########################################################################
# Load generated board configuration
sinclude $(OBJTREE)/include/autoconf.mk
- the
AS,LDAnd other variables , These values are combined with the variables of the cross compilation tool chain configured above to form a compiler file to compile the source file - Import include/autoconf.mk file , This file is now empty , however Makefile Use sinclude To introduce , This results in no error even if the file does not exist
- include/autoconf.mk Files are generated during configuration , It is full of
CONFIG_XXThe macro definition at the beginning ( It can be understood as a switch ), Used to specify uboot The trend in the compilation process , At the end of this article, there is the generation process of this file !
Compilation options configuration
ifdef ARCH
sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
endif
ifdef CPU
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
endif
ifdef SOC
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
endif
ifdef VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
endif
- According to ARCH,CPU,SOC Wait to add different compilation options , Here is arm_config.mk The content in
PLATFORM_CPPFLAGS += -DCONFIG_ARM -D__ARM, Others are similar - Be careful
BOARDUnder the config.mk(board/samsung/x210/config.mk) The contents of the document TEXT_BASE = 0xc3e00000, This is different from the top floor Makefile Mediumx210_sd_configThe link address written by the task is the same
Link script
ifeq ($(CONFIG_NAND_U_BOOT),y)
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
else
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
endif
- Here we have no definition
CONFIG_NAND_U_BOOTVariable , thereforeLDSCRIPTThe value of is u-boot.lds, This is a linked script file , analysis uboot The link script file should be considered when compiling - First put the file below , For detailed instructions, please refer to u-boot Link script post , It just says
.textSection defines the running sequence of the program , thereforecpu/s5pc11x/start.oIs the first file to run
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
/*OUTPUT_FORMAT("elf32-arm", "elf32-arm", "elf32-arm")*/
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
. = 0x00000000;
. = ALIGN(4);
.text :
{
cpu/s5pc11x/start.o (.text)
cpu/s5pc11x/s5pc110/cpu_init.o (.text)
board/samsung/x210/lowlevel_init.o (.text)
cpu/s5pc11x/onenand_cp.o (.text)
cpu/s5pc11x/nand_cp.o (.text)
cpu/s5pc11x/movi.o (.text)
common/secure_boot.o (.text)
common/ace_sha1.o (.text)
cpu/s5pc11x/pmic.o (.text)
*(.text)
}
. = ALIGN(4);
.rodata : {
*(.rodata) }
. = ALIGN(4);
.data : {
*(.data) }
. = ALIGN(4);
.got : {
*(.got) }
__u_boot_cmd_start = .;
.u_boot_cmd : {
*(.u_boot_cmd) }
__u_boot_cmd_end = .;
. = ALIGN(4);
.mmudata : {
*(.mmudata) }
. = ALIGN(4);
__bss_start = .;
.bss : {
*(.bss) }
_end = .;
}
Specify the link address
ifneq ($(TEXT_BASE),)
CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
endif
ifneq ($(TEXT_BASE),)
LDFLAGS += -Ttext $(TEXT_BASE)
endif
- I've set it up here u-boot The link address specified when linking
TEXT_BASEVariable values are in the Compilation options configuration The source is analyzed in section
Compile the file
ifndef REMOTE_BUILD
%.s: %.S
$(CPP) $(AFLAGS) -o [email protected] $<
%.o: %.S
$(CC) $(AFLAGS) -c -o [email protected] $<
%.o: %.c
$(CC) $(CFLAGS) -c -o [email protected] $<
else
$(obj)%.s: %.S
$(CPP) $(AFLAGS) -o [email protected] $<
$(obj)%.o: %.S
$(CC) $(AFLAGS) -c -o [email protected] $<
$(obj)%.o: %.c
$(CC) $(CFLAGS) -c -o [email protected] $<
endif
- Through here Makefile Automatic derivation planning compilation target file
Continue to analyze the main Makefile
#########################################################################
# U-Boot objects....order is important (i.e. start must be first)
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
……
LIBS += drivers/mtd/nand_legacy/libnand_legacy.a
LIBS += drivers/mtd/onenand/libonenand.a
LIBS += drivers/mtd/ubi/libubi.a
LIBS += drivers/mtd/spi/libspi_flash.a
LIBS += drivers/net/libnet.a
LIBS += drivers/net/sk98lin/libsk98lin.a
LIBS += drivers/pci/libpci.a
LIBS += drivers/pcmcia/libpcmcia.a
LIBS += drivers/spi/libspi.a
- Next, continue to analyze the main Makefile
- Pay attention to the notes ,
order is important (i.e. start must be first), Order is important and start It must be the first file to run . This is similar to the link script we mentioned earlier.textThe first run file defined in the section is the same . - Next, add various runtime files
The first goal all
all: $(ALL)
$(obj)u-boot.srec: $(obj)u-boot
$(OBJCOPY) ${OBJCFLAGS} -O srec $< [email protected]
$(obj)u-boot: depend $(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT)
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
$(SUBDIRS): depend $(obj)include/autoconf.mk
#$(error SUBDIRS)
$(MAKE) -C [email protected] all
- all yes Makefile The first goal of , So execute
makeThe function of is equal to the executionmake all - $(ALL) The value of the variable is printed u-boot.srec u-boot.bin System.map u-boot.dis, Therefore, compiling and completing these four tasks respectively is considered to be completed
- u-boot.srec Depend on u-boot, and u-boot And depend on
$(SUBDIRS) $(OBJS) $(LIBBOARD) $(LIBS) $(LDSCRIPT),SUBDIRS And depend on include/autoconf.mk file . - Rely on it all the way , Then compile backwards
- Let's analyze
include/autoconf.mkHow are files generated , One is that many goals depend on this , Second, it is control u-boot Compile the switch file of the trend
autoconf.mk File generation
#
# 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 $(HOST_CFLAGS) $(CPPFLAGS) \
-MQ $(obj)include/autoconf.mk include/common.h > [email protected]
$(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]
- The above rules are used to generate autoconf.mk file
(obj)include/autoconf.mk.depRules don't work(obj)include/autoconf.mkRules are used to generate autoconf.mk file- Open this chapter
The first goal allIn the paragraph$(SUBDIRS)The effect can be seen by the comments in the goal ( Delete first. include/autoconf.mk file )

- here
include/autoconf.mkThe file has been generated , To know its complete command , You can use ( Delete first include/autoconf.mk file )make --tracecommand , Press... After two seconds of operation Ctrl+z interrupt , Then look back , The content in the red box below is the complete command .
- The following figure is an example of the contents of this file .

thus , Lord Makefile Analysis completed !
边栏推荐
猜你喜欢
随机推荐
DAY_4作业——判断数组内是否有某一个数据————实现数组映射(放大 10 倍)—— 实现按序插入数组(修改bug)——实现数组去重
Pat grade a a1043 is it a binary search tree
PAT 甲级 A1086 Tree Traversals Again
VirtualBox:SSH连接
笔记-树的遍历
BLOOM模型背后的技术实践:1760亿参数模型如何炼成?
MySQL时区问题
Pat grade a a1064 complete binary search tree
Pat a 1099 build a binary search tree
The nature and usage of binary search tree
Is it safe to open Huatai Securities account by mobile phone?
知识干货:基础存储服务新手体验营
Cyclic multi-Variate Function for Self-Supervised Image Denoising by Disentangling Noise from Image
常见保持请求幂等的方式
一种新的UI测试方法:视觉感知测试
CodeBlocks download installation tutorial (complete and detailed)
云计算SLA思考
Create a list, add the strings "a", "B", "C", "d" and "d" in turn, and print the contents of the set, then remove all the strings "d" in the list, and print its contents again
VirtualBox:设置共享文件夹
Rename file with command line









