UBOOT编译--- UBOOT的顶层config.mk(五)
1. 前言
UBOOT版本:uboot2018.03,开发板myimx8mmek240。
2. 概述
此文件包含在 ./Makefile 和 spl/Makefile 中。 清理状态以避免添加两次相同的标志。有些平台需要不同的 SPL 标志,这就是为什么这个文件也必须包含在 spl/Makefile 中的原因。如果我们没有SPL,构建系统会简单得多。我使用的平台有使用SPL。
3. 顶层config.mk解析
由于内容较少,直接在源代码中批注:
# # (C) Copyright 2000-2013 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. # # SPDX-License-Identifier: GPL-2.0+ # ######################################################################### # This file is included from ./Makefile and spl/Makefile. # Clean the state to avoid the same flags added twice. # # (Tegra needs different flags for SPL. # That's the reason why this file must be included from spl/Makefile too. # If we did not have Tegra SoCs, build system would be much simpler...) PLATFORM_RELFLAGS := PLATFORM_CPPFLAGS := PLATFORM_LDFLAGS := LDFLAGS := LDFLAGS_FINAL := OBJCOPYFLAGS := # clear VENDOR for tcsh VENDOR := ######################################################################### ARCH := $(CONFIG_SYS_ARCH:"%"=%) //架构 arm CPU := $(CONFIG_SYS_CPU:"%"=%) //CPU armv8 ifdef CONFIG_SPL_BUILD //我使用的平台有定义 -DCONFIG_SPL_BUILD ifdef CONFIG_TEGRA CPU := arm720t endif endif BOARD := $(CONFIG_SYS_BOARD:"%"=%) //板 myimx8mm ifneq ($(CONFIG_SYS_VENDOR),) VENDOR := $(CONFIG_SYS_VENDOR:"%"=%) //厂商 myzr endif ifneq ($(CONFIG_SYS_SOC),) SOC := $(CONFIG_SYS_SOC:"%"=%) //SOC imx8m endif # Some architecture config.mk files need to know what CPUDIR is set to, # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files. # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains # CPU-specific code. CPUDIR=arch/$(ARCH)/cpu$(if $(CPU),/$(CPU),) // arch/arm/cpu/armv8 sinclude $(srctree)/arch/$(ARCH)/config.mk # include architecture dependend rules // arch/arm/config.mk sinclude $(srctree)/$(CPUDIR)/config.mk # include CPU specific rules //arch/arm/cpu/armv8/config.mk ifdef SOC sinclude $(srctree)/$(CPUDIR)/$(SOC)/config.mk # include SoC specific rules //arch/arm/cpu/armv8/imx8m/config.mk endif ifneq ($(BOARD),) ifdef VENDOR BOARDDIR = $(VENDOR)/$(BOARD) // myzr/myimx8mm else BOARDDIR = $(BOARD) endif endif ifdef BOARD sinclude $(srctree)/board/$(BOARDDIR)/config.mk # include board specific rules //board/myzr/myimx8mm/config.mk endif ifdef FTRACE PLATFORM_CPPFLAGS += -finstrument-functions -DFTRACE //进行函数跟踪,一般不开,调试时可以打开 endif # Allow use of stdint.h if available //如果您的工具链可以使用 stdint.h,您可以定义它启用它的选项。 您可以在以下情况下提供选项“USE_STDINT=1”构建 U-Boot 来实现这一点。 ifneq ($(USE_STDINT),) PLATFORM_CPPFLAGS += -DCONFIG_USE_STDINT endif ######################################################################### RELFLAGS := $(PLATFORM_RELFLAGS) PLATFORM_CPPFLAGS += $(RELFLAGS) PLATFORM_CPPFLAGS += -pipe //使用管道代替临时文件。 LDFLAGS += $(PLATFORM_LDFLAGS) LDFLAGS_FINAL += -Bstatic export PLATFORM_CPPFLAGS export RELFLAGS export LDFLAGS_FINAL export CONFIG_STANDALONE_LOAD_ADDR
3.1 架构(ARCH)特定规则
# arch/arm/config.mk # (C) Copyright 2000-2002 # Wolfgang Denk, DENX Software Engineering, wd@denx.de. # # SPDX-License-Identifier: GPL-2.0+ # ifndef CONFIG_STANDALONE_LOAD_ADDR ifneq ($(CONFIG_ARCH_OMAP2PLUS),) //未定义 CONFIG_STANDALONE_LOAD_ADDR = 0x80300000 else CONFIG_STANDALONE_LOAD_ADDR = 0xc100000 endif endif CFLAGS_NON_EFI := -fno-pic -ffixed-r9 -ffunction-sections -fdata-sections //-fno-pic : -fno-pic,-fno-PIC是同义的,生成position-dependent code //-ffixed-r9 :生成的代码不要用寄存器r9,uboot中用来指向global data //-ffunction-sections :把每个函数放入单独的section中,如果目标文件支持任意数量section //-fdata-sections :同上,只是对象是数据 CFLAGS_EFI := -fpic -fshort-wchar //-fpic :生成位置无关的代码,即代码无绝对跳转,都是相对跳转 //-fshort-wchar :强制将wchar_t指定成两个字节,使用这个字段常常是因为wchar_t类型在Windows和Linux平台下字节大小的不同,但这样做只会改变代码中实现的部分,而内部库或者是第三方库中用到的接口和函数都是没有变的,仍然采用的是4字节编码 LDFLAGS_FINAL += --gc-sections //--gc-sections :在链接生成最终可执行文件时,如果带有-Wl,--gc-sections参数,并且之前编译目标文件时带有-ffunction-sections、-fdata-sections参数,则链接器ld不会链接未使用的函数,从而减小可执行文件大小; PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections \ -fno-common -ffixed-r9 PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \ $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) //-fno-common :它指定编译器将未初始化的全局变量放在对象文件的BSS部分。 //-f-mshort-load-bytes、-malignment-traps :-mshort-load-bytes 在低版本gcc中使用,and -malignment-traps在高版本gcc中使用 # LLVM support LLVMS_RELFLAGS := $(call cc-option,-mllvm,) \ $(call cc-option,-target arm-none-eabi,) \ $(call cc-option,-arm-use-movt=0,) PLATFORM_RELFLAGS += $(LLVM_RELFLAGS) PLATFORM_CPPFLAGS += -D__ARM__ //定义宏ARM ifdef CONFIG_ARM64 PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64 else PLATFORM_ELFFLAGS += -B arm -O elf32-littlearm endif //-fno-common :放置未初始化的全局变量,这里不放到common block中,而是放到data section中 # Choose between ARM/Thumb instruction sets ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y) AFLAGS_IMPLICIT_IT := $(call as-option,-Wa$(comma)-mimplicit-it=always) PF_CPPFLAGS_ARM := $(AFLAGS_IMPLICIT_IT) \ $(call cc-option, -mthumb -mthumb-interwork,\ $(call cc-option,-marm,)\ $(call cc-option,-mno-thumb-interwork,)\ ) else PF_CPPFLAGS_ARM := $(call cc-option,-marm,) \ $(call cc-option,-mno-thumb-interwork,) endif //-marm :和-mthumb用来执行生成的代码在arm模式还是thumb模式执行 //-mno-thumb-interwork :没有ARM/Thumb之间的切换 # Only test once ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y) archprepare: checkthumb checkgcc6 checkthumb: @if test "$(call cc-name)" = "gcc" -a \ "$(call cc-version)" -lt "0404"; then \ echo -n '*** Your GCC does not produce working '; \ echo 'binaries in THUMB mode.'; \ echo '*** Your board is configured for THUMB mode.'; \ false; \ fi else //判断gcc的版本是否低于6.0 archprepare: checkgcc6 endif checkgcc6: @if test "$(call cc-name)" = "gcc" -a \ "$(call cc-version)" -lt "0600"; then \ echo '*** Your GCC is older than 6.0 and will not be supported'; \ fi # Try if EABI is supported, else fall back to old API, # i. e. for example: # - with ELDK 4.2 (EABI supported), use: # -mabi=aapcs-linux # - with ELDK 4.1 (gcc 4.x, no EABI), use: # -mabi=apcs-gnu # - with ELDK 3.1 (gcc 3.x), use: # -mapcs-32 PF_CPPFLAGS_ABI := $(call cc-option,\ -mabi=aapcs-linux,\ $(call cc-option,\ -mapcs-32,\ $(call cc-option,\ -mabi=apcs-gnu,\ )\ )\ ) PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARM) $(PF_CPPFLAGS_ABI) //-mabi=aapcs-linux : 针对不同系统的调用规则生成代码 # For EABI, make sure to provide raise() ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS))) # This file is parsed many times, so the string may get added multiple # times. Also, the prefix needs to be different based on whether # CONFIG_SPL_BUILD is defined or not. 'filter-out' the existing entry # before adding the correct one. PLATFORM_LIBS := arch/arm/lib/eabi_compat.o \ $(filter-out arch/arm/lib/eabi_compat.o, $(PLATFORM_LIBS)) endif # needed for relocation LDFLAGS_u-boot += -pie /*# FIXME: binutils versions < 2.22 have a bug in the assembler where # branches to weak symbols can be incorrectly optimized in thumb mode # to a short branch (b.n instruction) that won't reach when the symbol # gets preempted # # http://sourceware.org/bugzilla/show_bug.cgi?id=12532 #*/ ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y) ifeq ($(GAS_BUG_12532),) export GAS_BUG_12532:=$(shell if [ $(call binutils-version) -lt 0222 ] ; \ then echo y; else echo n; fi) endif ifeq ($(GAS_BUG_12532),y) PLATFORM_RELFLAGS += -fno-optimize-sibling-calls endif endif ifneq ($(CONFIG_SPL_BUILD),y) # Check that only R_ARM_RELATIVE relocations are generated. ALL-y += checkarmreloc # The movt / movw can hardcode 16 bit parts of the addresses in the # instruction. Relocation is not supported for that case, so disable # such usage by requiring word relocations. PLATFORM_CPPFLAGS += $(call cc-option, -mword-relocations) PLATFORM_CPPFLAGS += $(call cc-option, -fno-pic) endif //-mword-relocations : 由于使用pic时movt / movw指令会硬编码16bit的地址域,而uboot的relocation并不支持这个, 所以arm平台使用mword-relocations来生成位置无关代码 # limit ourselves to the sections we want in the .bin. ifdef CONFIG_ARM64 OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \ -j .u_boot_list -j .rela.dyn -j .got -j .got.plt \ -j .binman_sym_table else OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \ -j .data -j .got -j .got.plt -j .u_boot_list -j .rel.dyn \ -j .binman_sym_table endif # if a dtb section exists we always have to include it # there are only two cases where it is generated # 1) OF_EMBEDED is turned on # 2) unit tests include device tree blobs OBJCOPYFLAGS += -j .dtb.init.rodata ifdef CONFIG_EFI_LOADER OBJCOPYFLAGS += -j .efi_runtime -j .efi_runtime_rel endif ifdef CONFIG_IMX_M4_BIND OBJCOPYFLAGS += -j .firmware_image endif ifneq ($(CONFIG_IMX_CONFIG),) ifdef CONFIG_SPL ifndef CONFIG_SPL_BUILD ALL-y += SPL endif else ifeq ($(CONFIG_OF_SEPARATE),y) ALL-y += u-boot-dtb.imx else ALL-y += u-boot.imx endif endif ifneq ($(CONFIG_VF610),) ALL-y += u-boot.vyb endif endif EFI_LDS := elf_arm_efi.lds EFI_CRT0 := crt0_arm_efi.o EFI_RELOC := reloc_arm_efi.o
3.2 CPU特定规则
# arch/arm/cpu/armv8/config.mk # # (C) Copyright 2002 # Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> # # SPDX-License-Identifier: GPL-2.0+ # PLATFORM_RELFLAGS += -fno-common -ffixed-x18 PF_NO_UNALIGNED := $(call cc-option, -mstrict-align) PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED) //-mstrict-align : 避免非对齐内存访问 EFI_LDS := elf_aarch64_efi.lds EFI_CRT0 := crt0_aarch64_efi.o EFI_RELOC := reloc_aarch64_efi.o
3.3 SoC (SoC )特定规则
我使用的板子未定义,可根据自己的需要添加。
3.4 板级(BOARD)特定规则
我使用的板子未定义,可根据自己的需要添加。
4. 总结
顶层config.mk会被 ./Makefile 和 spl/Makefile 所包含,主要内容如下:
(1)定义架构、CPU、平台、板、厂商和SOC;
(2)包含架构(ARCH)特定规则(比如:arch/arm/config.mk);
(3)包含CPU(CPU)特定规则(比如:arch/arm/cpu/armv8/config.mk);
(4)包含SoC (SoC )特定规则(比如:arch/arm/cpu/armv8/imx8m/config.mk);
(5)包含板级(BOARD)特定规则(比如:board/myzr/myimx8mm/config.mk);
(6)特定的编译选项(比如:-pipe等);
作者:jianhua1992
本文来自博客园,作者:BSP-路人甲,转载请注明原文链接:https://www.cnblogs.com/jianhua1992/p/16852770.html,并保留此段声明,否则保留追究法律责任的权利。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步