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, [email protected].
#
# 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, [email protected].
#
# 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, <[email protected]>
#
# 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等);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/534037.html
標籤:嵌入式
