1# SPDX-License-Identifier: GPL-2.0+
2#
3# (C) Copyright 2000-2002
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5
6ifeq ($(CONFIG_ARM64),y)
7FIXED_REG := -ffixed-x18
8else
9FIXED_REG := -ffixed-r9
10endif
11
12CFLAGS_NON_EFI := -fno-pic $(FIXED_REG) -ffunction-sections -fdata-sections \
13		  -fstack-protector-strong
14CFLAGS_EFI := -fpic -fshort-wchar
15
16ifneq ($(LTO_ENABLE)$(CONFIG_USE_PRIVATE_LIBGCC),yy)
17LDFLAGS_FINAL += --gc-sections
18endif
19
20ifneq ($(LTO_ENABLE),y)
21PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
22endif
23
24PLATFORM_RELFLAGS += -fno-common $(FIXED_REG)
25PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \
26		     $(call cc-option,-mgeneral-regs-only) \
27      $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
28
29# LLVM support
30LLVM_RELFLAGS		:= $(call cc-option,-mllvm,) \
31			$(call cc-option,-mno-movt,)
32PLATFORM_RELFLAGS	+= $(LLVM_RELFLAGS)
33
34PLATFORM_CPPFLAGS += -D__ARM__
35
36ifdef CONFIG_ARM64
37PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64
38else
39PLATFORM_ELFFLAGS += -B arm -O elf32-littlearm
40endif
41
42# Choose between ARM/Thumb instruction sets
43ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y)
44AFLAGS_IMPLICIT_IT	:= $(call as-option,-Wa$(comma)-mimplicit-it=always)
45PF_CPPFLAGS_ARM		:= $(AFLAGS_IMPLICIT_IT) \
46			$(call cc-option, -mthumb -mthumb-interwork,\
47			$(call cc-option,-marm,)\
48			$(call cc-option,-mno-thumb-interwork,)\
49		)
50else
51PF_CPPFLAGS_ARM := $(call cc-option,-marm,) \
52		$(call cc-option,-mno-thumb-interwork,)
53endif
54
55# Only test once
56ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y)
57archprepare: checkthumb checkgcc6
58
59checkthumb:
60	@if test "$(call cc-name)" = "gcc" -a \
61			"$(call cc-version)" -lt "0404"; then \
62		echo -n '*** Your GCC does not produce working '; \
63		echo 'binaries in THUMB mode.'; \
64		echo '*** Your board is configured for THUMB mode.'; \
65		false; \
66	fi
67else
68archprepare: checkgcc6
69endif
70
71checkgcc6:
72	@if test "$(call cc-name)" = "gcc" -a \
73			"$(call cc-version)" -lt "0600"; then \
74		echo '*** Your GCC is older than 6.0 and is not supported'; \
75		false; \
76	fi
77
78
79# Try if EABI is supported, else fall back to old API,
80# i. e. for example:
81# - with ELDK 4.2 (EABI supported), use:
82#	-mabi=aapcs-linux
83# - with ELDK 4.1 (gcc 4.x, no EABI), use:
84#	-mabi=apcs-gnu
85# - with ELDK 3.1 (gcc 3.x), use:
86#	-mapcs-32
87PF_CPPFLAGS_ABI := $(call cc-option,\
88			-mabi=aapcs-linux,\
89			$(call cc-option,\
90				-mapcs-32,\
91				$(call cc-option,\
92					-mabi=apcs-gnu,\
93				)\
94			)\
95		)
96PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARM) $(PF_CPPFLAGS_ABI)
97
98# For EABI, make sure to provide raise()
99ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
100# This file is parsed many times, so the string may get added multiple
101# times. Also, the prefix needs to be different based on whether
102# CONFIG_SPL_BUILD is defined or not. 'filter-out' the existing entry
103# before adding the correct one.
104PLATFORM_LIBS := arch/arm/lib/eabi_compat.o \
105	$(filter-out arch/arm/lib/eabi_compat.o, $(PLATFORM_LIBS))
106endif
107
108# needed for relocation
109LDFLAGS_u-boot += -pie
110
111#
112# FIXME: binutils versions < 2.22 have a bug in the assembler where
113# branches to weak symbols can be incorrectly optimized in thumb mode
114# to a short branch (b.n instruction) that won't reach when the symbol
115# gets preempted
116#
117# http://sourceware.org/bugzilla/show_bug.cgi?id=12532
118#
119ifeq ($(CONFIG_$(SPL_)SYS_THUMB_BUILD),y)
120ifeq ($(GAS_BUG_12532),)
121export GAS_BUG_12532:=$(shell if [ $(call binutils-version) -lt 0222 ] ; \
122	then echo y; else echo n; fi)
123endif
124ifeq ($(GAS_BUG_12532),y)
125PLATFORM_RELFLAGS += -fno-optimize-sibling-calls
126endif
127endif
128
129ifneq ($(CONFIG_SPL_BUILD),y)
130# Check that only R_ARM_RELATIVE relocations are generated.
131INPUTS-y += checkarmreloc
132# The movt / movw can hardcode 16 bit parts of the addresses in the
133# instruction. Relocation is not supported for that case, so disable
134# such usage by requiring word relocations.
135PLATFORM_CPPFLAGS += $(call cc-option, -mword-relocations)
136PLATFORM_CPPFLAGS += $(call cc-option, -fno-pic)
137endif
138
139# limit ourselves to the sections we want in the .bin.
140ifdef CONFIG_ARM64
141OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \
142		-j __u_boot_list -j .rela.dyn -j .got -j .got.plt \
143		-j .binman_sym_table -j .text_rest
144else
145OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
146		-j .data -j .got -j .got.plt -j __u_boot_list -j .rel.dyn \
147		-j .binman_sym_table -j .text_rest
148endif
149
150# if a dtb section exists we always have to include it
151# there are only two cases where it is generated
152# 1) OF_EMBEDED is turned on
153# 2) unit tests include device tree blobs
154OBJCOPYFLAGS += -j .dtb.init.rodata
155
156ifdef CONFIG_EFI_LOADER
157OBJCOPYFLAGS += -j .efi_runtime -j .efi_runtime_rel
158endif
159
160ifdef CONFIG_MACH_IMX
161ifneq ($(CONFIG_IMX_CONFIG),"")
162ifdef CONFIG_SPL
163ifndef CONFIG_SPL_BUILD
164INPUTS-y += SPL
165endif
166else
167ifeq ($(CONFIG_OF_SEPARATE),y)
168INPUTS-y += u-boot-dtb.imx
169else
170INPUTS-y += u-boot.imx
171endif
172endif
173ifneq ($(CONFIG_VF610),)
174INPUTS-y += u-boot.vyb
175endif
176endif
177endif
178
179EFI_LDS := elf_arm_efi.lds
180EFI_CRT0 := crt0_arm_efi.o
181EFI_RELOC := reloc_arm_efi.o
182