blob: e0045e2227133ae682f83871af03662b087c6554 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
wdenk39f0e5f2002-08-14 20:30:46 +00002#
3# (C) Copyright 2000-2002
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk39f0e5f2002-08-14 20:30:46 +00005
Tom Rini8267f162023-04-05 19:48:54 -04006ifeq ($(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 \
Joel Peshkin369d87a2021-04-11 11:21:58 +020013 -fstack-protector-strong
Simon Glassfc03fb92016-11-07 08:47:10 -070014CFLAGS_EFI := -fpic -fshort-wchar
15
Simon Glass6c8ec912022-08-03 12:13:08 -060016ifneq ($(LTO_ENABLE)$(CONFIG_USE_PRIVATE_LIBGCC),yy)
Tom Riniefc90722013-04-25 07:40:22 +000017LDFLAGS_FINAL += --gc-sections
Marek Behún701bc2e2021-05-20 13:24:24 +020018endif
Marek Behún2a9079e2021-05-20 13:24:23 +020019
Simon Glass6c8ec912022-08-03 12:13:08 -060020ifneq ($(LTO_ENABLE),y)
Marek Behún2a9079e2021-05-20 13:24:23 +020021PLATFORM_RELFLAGS += -ffunction-sections -fdata-sections
22endif
23
Tom Rini8267f162023-04-05 19:48:54 -040024PLATFORM_RELFLAGS += -fno-common $(FIXED_REG)
Masahiro Yamadab8a26252014-01-15 11:00:45 +090025PLATFORM_RELFLAGS += $(call cc-option, -msoft-float) \
Samuel Hollanda871d862021-08-21 19:54:02 -050026 $(call cc-option,-mgeneral-regs-only) \
Masahiro Yamadab8a26252014-01-15 11:00:45 +090027 $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,))
Tom Riniefc90722013-04-25 07:40:22 +000028
Tom Rini1088ec12016-03-16 19:55:55 -040029# LLVM support
Tom Rinida62bb92018-04-22 19:15:03 -040030LLVM_RELFLAGS := $(call cc-option,-mllvm,) \
31 $(call cc-option,-mno-movt,)
Tom Rini1088ec12016-03-16 19:55:55 -040032PLATFORM_RELFLAGS += $(LLVM_RELFLAGS)
33
Masahiro Yamada4869aee2014-07-30 14:08:23 +090034PLATFORM_CPPFLAGS += -D__ARM__
Jean-Christophe PLAGNIOL-VILLARD7580b862009-05-08 20:24:12 +020035
Álvaro Fernández Rojas1f86ebd2017-04-20 20:36:25 +020036ifdef CONFIG_ARM64
37PLATFORM_ELFFLAGS += -B aarch64 -O elf64-littleaarch64
38else
39PLATFORM_ELFFLAGS += -B arm -O elf32-littlearm
40endif
41
Aneesh Vb8e40802012-03-08 07:20:19 +000042# Choose between ARM/Thumb instruction sets
Simon Glass86adc2e2024-09-29 19:49:53 -060043ifeq ($(CONFIG_$(XPL_)SYS_THUMB_BUILD),y)
Stefan Agnera257f2e2014-12-18 18:10:33 +010044AFLAGS_IMPLICIT_IT := $(call as-option,-Wa$(comma)-mimplicit-it=always)
45PF_CPPFLAGS_ARM := $(AFLAGS_IMPLICIT_IT) \
46 $(call cc-option, -mthumb -mthumb-interwork,\
Aneesh Vb8e40802012-03-08 07:20:19 +000047 $(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
Wolfgang Denkd47f4862009-08-17 13:17:29 +020054
Tom Rini20eef6c2012-03-16 06:34:35 +000055# Only test once
Simon Glass86adc2e2024-09-29 19:49:53 -060056ifeq ($(CONFIG_$(XPL_)SYS_THUMB_BUILD),y)
Tom Rinie1250132017-04-17 09:18:00 -040057archprepare: checkthumb checkgcc6
Masahiro Yamada54ead2c2014-03-05 17:49:22 +090058
59checkthumb:
Tom Rini7aaf2772016-01-19 20:39:02 -050060 @if test "$(call cc-name)" = "gcc" -a \
61 "$(call cc-version)" -lt "0404"; then \
Masahiro Yamada54ead2c2014-03-05 17:49:22 +090062 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
Tom Rinie1250132017-04-17 09:18:00 -040067else
68archprepare: checkgcc6
Masahiro Yamada54ead2c2014-03-05 17:49:22 +090069endif
Tom Rini20eef6c2012-03-16 06:34:35 +000070
Tom Rinie1250132017-04-17 09:18:00 -040071checkgcc6:
72 @if test "$(call cc-name)" = "gcc" -a \
73 "$(call cc-version)" -lt "0600"; then \
Tom Rinicfa4c712017-12-02 20:11:31 -050074 echo '*** Your GCC is older than 6.0 and is not supported'; \
75 false; \
Tom Rinie1250132017-04-17 09:18:00 -040076 fi
77
78
Wolfgang Denkd47f4862009-08-17 13:17:29 +020079# Try if EABI is supported, else fall back to old API,
80# i. e. for example:
81# - with ELDK 4.2 (EABI supported), use:
Aneesh Vb8e40802012-03-08 07:20:19 +000082# -mabi=aapcs-linux
Wolfgang Denkd47f4862009-08-17 13:17:29 +020083# - with ELDK 4.1 (gcc 4.x, no EABI), use:
Aneesh Vb8e40802012-03-08 07:20:19 +000084# -mabi=apcs-gnu
Wolfgang Denkd47f4862009-08-17 13:17:29 +020085# - with ELDK 3.1 (gcc 3.x), use:
Aneesh Vb8e40802012-03-08 07:20:19 +000086# -mapcs-32
Wolfgang Denk9209ed52011-11-01 20:54:02 +000087PF_CPPFLAGS_ABI := $(call cc-option,\
Aneesh Vb8e40802012-03-08 07:20:19 +000088 -mabi=aapcs-linux,\
Wolfgang Denk9209ed52011-11-01 20:54:02 +000089 $(call cc-option,\
90 -mapcs-32,\
Wolfgang Denkd47f4862009-08-17 13:17:29 +020091 $(call cc-option,\
Wolfgang Denk9209ed52011-11-01 20:54:02 +000092 -mabi=apcs-gnu,\
93 )\
Aneesh Vb8e40802012-03-08 07:20:19 +000094 )\
Wolfgang Denk9209ed52011-11-01 20:54:02 +000095 )
96PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARM) $(PF_CPPFLAGS_ABI)
Wolfgang Denkd47f4862009-08-17 13:17:29 +020097
98# For EABI, make sure to provide raise()
99ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))
Aneesh Vad356282011-07-19 05:51:41 +0000100# 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
Simon Glass85ed77d2024-09-29 19:49:46 -0600102# CONFIG_XPL_BUILD is defined or not. 'filter-out' the existing entry
Aneesh Vad356282011-07-19 05:51:41 +0000103# before adding the correct one.
Masahiro Yamada933c7e02014-02-27 22:40:34 +0900104PLATFORM_LIBS := arch/arm/lib/eabi_compat.o \
105 $(filter-out arch/arm/lib/eabi_compat.o, $(PLATFORM_LIBS))
Wolfgang Denkd47f4862009-08-17 13:17:29 +0200106endif
Albert Aribaud6d1fcb12010-10-11 13:13:28 +0200107
Albert Aribaud6d1fcb12010-10-11 13:13:28 +0200108# needed for relocation
Stefano Babic8b378e12011-01-27 06:03:49 +0000109LDFLAGS_u-boot += -pie
Allen Martina8c7aea2012-07-18 13:45:53 +0000110
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#
Simon Glass86adc2e2024-09-29 19:49:53 -0600119ifeq ($(CONFIG_$(XPL_)SYS_THUMB_BUILD),y)
Allen Martina8c7aea2012-07-18 13:45:53 +0000120ifeq ($(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
Albert ARIBAUD446dd122013-06-11 14:17:30 +0200128
Simon Glass85ed77d2024-09-29 19:49:46 -0600129ifneq ($(CONFIG_XPL_BUILD),y)
Jeroen Hofsteea2f61ca2013-08-24 13:55:38 +0200130# Check that only R_ARM_RELATIVE relocations are generated.
Simon Glassc46090d2020-07-19 13:56:01 -0600131INPUTS-y += checkarmreloc
Jeroen Hofsteea2f61ca2013-08-24 13:55:38 +0200132# 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)
Peng Fan18ad9292016-01-30 12:10:49 +0800136PLATFORM_CPPFLAGS += $(call cc-option, -fno-pic)
Albert ARIBAUD446dd122013-06-11 14:17:30 +0200137endif
Albert ARIBAUD95fc6d62013-11-07 14:21:46 +0100138
139# limit ourselves to the sections we want in the .bin.
David Feng85fd5f12013-12-14 11:47:35 +0800140ifdef CONFIG_ARM64
macro.wave.z@gmail.com01bd3342016-12-08 11:58:22 +0800141OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .data \
Andrew Scull5a9095c2022-05-30 10:00:04 +0000142 -j __u_boot_list -j .rela.dyn -j .got -j .got.plt \
Alexander Graf94a10f22018-06-12 07:48:37 +0200143 -j .binman_sym_table -j .text_rest
David Feng85fd5f12013-12-14 11:47:35 +0800144else
Chen-Yu Tsai5ed03872016-07-05 21:45:06 +0800145OBJCOPYFLAGS += -j .text -j .secure_text -j .secure_data -j .rodata -j .hash \
Andrew Scull5a9095c2022-05-30 10:00:04 +0000146 -j .data -j .got -j .got.plt -j __u_boot_list -j .rel.dyn \
Alexander Graf94a10f22018-06-12 07:48:37 +0200147 -j .binman_sym_table -j .text_rest
David Feng85fd5f12013-12-14 11:47:35 +0800148endif
Masahiro Yamadad36a7492014-02-24 11:12:21 +0900149
Pantelis Antoniou76482732017-05-25 19:23:58 +0300150# 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
Alexey Ignatov576a8d52014-07-07 03:21:44 +0400154OBJCOPYFLAGS += -j .dtb.init.rodata
Alexey Ignatov576a8d52014-07-07 03:21:44 +0400155
Alexander Graf0bd425a2016-03-04 01:10:01 +0100156ifdef CONFIG_EFI_LOADER
157OBJCOPYFLAGS += -j .efi_runtime -j .efi_runtime_rel
158endif
159
Tom Rini57b93812021-08-24 20:41:00 -0400160ifdef CONFIG_MACH_IMX
161ifneq ($(CONFIG_IMX_CONFIG),"")
Masahiro Yamadad36a7492014-02-24 11:12:21 +0900162ifdef CONFIG_SPL
Simon Glass85ed77d2024-09-29 19:49:46 -0600163ifndef CONFIG_XPL_BUILD
Simon Glassc46090d2020-07-19 13:56:01 -0600164INPUTS-y += SPL
Masahiro Yamadad36a7492014-02-24 11:12:21 +0900165endif
166else
Stefano Babicc183a6e2014-03-31 09:50:35 +0200167ifeq ($(CONFIG_OF_SEPARATE),y)
Simon Glassc46090d2020-07-19 13:56:01 -0600168INPUTS-y += u-boot-dtb.imx
Stefano Babicc183a6e2014-03-31 09:50:35 +0200169else
Simon Glassc46090d2020-07-19 13:56:01 -0600170INPUTS-y += u-boot.imx
Masahiro Yamadad36a7492014-02-24 11:12:21 +0900171endif
172endif
Albert ARIBAUD \(3ADEV\)2e9f4942016-09-26 09:08:06 +0200173ifneq ($(CONFIG_VF610),)
Simon Glassc46090d2020-07-19 13:56:01 -0600174INPUTS-y += u-boot.vyb
Albert ARIBAUD \(3ADEV\)2e9f4942016-09-26 09:08:06 +0200175endif
Stefano Babicc183a6e2014-03-31 09:50:35 +0200176endif
Tom Rini57b93812021-08-24 20:41:00 -0400177endif
Simon Glassfc03fb92016-11-07 08:47:10 -0700178
179EFI_LDS := elf_arm_efi.lds
180EFI_CRT0 := crt0_arm_efi.o
181EFI_RELOC := reloc_arm_efi.o