blob: 589f2aed2bc25746c8e75ae4025f79a88cf9b39a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
wdenk591dda52002-11-18 00:14:45 +00002#
3# (C) Copyright 2000-2002
4# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk591dda52002-11-18 00:14:45 +00005
Wolfgang Denk33a57342011-02-04 14:25:17 +01006CONFIG_STANDALONE_LOAD_ADDR ?= 0x40000
Mike Frysinger5b660442009-09-03 23:12:47 -04007
Graeme Russbed10fa2010-10-07 20:03:23 +11008PLATFORM_CPPFLAGS += -fomit-frame-pointer
Masahiro Yamada4fad1492014-02-26 14:51:01 +09009PF_CPPFLAGS_X86 := $(call cc-option, -fno-toplevel-reorder, \
Bin Meng20358f62017-07-27 06:12:34 -070010 $(call cc-option, -fno-unit-at-a-time))
Ben Stoltzc24aae52015-08-04 12:33:42 -060011
Wolfgang Denk9209ed52011-11-01 20:54:02 +000012PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_X86)
Graeme Russ9381c8a2011-02-12 15:11:21 +110013PLATFORM_CPPFLAGS += -fno-dwarf2-cfi-asm
Simon Glass5aa58752017-01-16 07:04:26 -070014
15ifdef CONFIG_SPL_BUILD
16IS_32BIT := y
17else
18ifndef CONFIG_X86_64
19IS_32BIT := y
20endif
21endif
22
23ifeq ($(IS_32BIT),y)
Vasili Galka37215b72014-06-10 16:14:56 +030024PLATFORM_CPPFLAGS += -march=i386 -m32
Simon Glass5aa58752017-01-16 07:04:26 -070025else
Bin Mengf50b17c2018-10-13 20:52:01 -070026PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -march=core2 -m64
Bin Meng58d4bc62018-10-13 20:52:02 -070027PLATFORM_CPPFLAGS += -mno-mmx -mno-sse
Simon Glass5aa58752017-01-16 07:04:26 -070028endif
Graeme Russ9381c8a2011-02-12 15:11:21 +110029
Alexander Graf86642972018-08-20 14:20:51 +020030PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
Graeme Russ9381c8a2011-02-12 15:11:21 +110031
Tom Rini5d4ecf22020-03-27 11:46:27 -040032KBUILD_LDFLAGS += -Bsymbolic -Bsymbolic-functions
33KBUILD_LDFLAGS += -m $(if $(IS_32BIT),elf_i386,elf_x86_64)
Graeme Russ9381c8a2011-02-12 15:11:21 +110034
Simon Glass63f581f2015-08-04 12:33:52 -060035# This is used in the top-level Makefile which does not include
Tom Rini5d4ecf22020-03-27 11:46:27 -040036# KBUILD_LDFLAGS
Bin Meng1aad48b2018-10-02 07:39:30 -070037LDFLAGS_EFI_PAYLOAD := -Bsymbolic -Bsymbolic-functions -shared --no-undefined -s
Simon Glass63f581f2015-08-04 12:33:52 -060038
Ben Stoltzc24aae52015-08-04 12:33:42 -060039OBJCOPYFLAGS_EFI := -j .text -j .sdata -j .data -j .dynamic -j .dynsym \
Simon Glass408cf262021-09-24 18:30:19 -060040 -j .rel -j .rela -j .reloc --strip-all
Ben Stoltzc24aae52015-08-04 12:33:42 -060041
Heinrich Schuchardteccd86f2021-04-11 11:21:57 +020042# Compiler flags to be added when building UEFI applications
Ben Stoltzc24aae52015-08-04 12:33:42 -060043CFLAGS_EFI := -fpic -fshort-wchar
Heinrich Schuchardteccd86f2021-04-11 11:21:57 +020044# Compiler flags to be removed when building UEFI applications
Joel Peshkin369d87a2021-04-11 11:21:58 +020045CFLAGS_NON_EFI := -mregparm=3 -fstack-protector-strong
Ben Stoltzc24aae52015-08-04 12:33:42 -060046
Simon Glassce62a252015-08-04 12:33:56 -060047ifeq ($(CONFIG_EFI_STUB_64BIT),)
48CFLAGS_EFI += $(call cc-option, -mno-red-zone)
Ben Stoltzc24aae52015-08-04 12:33:42 -060049EFIARCH = ia32
Simon Glass63f581f2015-08-04 12:33:52 -060050EFIPAYLOAD_BFDTARGET = elf32-i386
Simon Glassce62a252015-08-04 12:33:56 -060051else
52EFIARCH = x86_64
53EFIPAYLOAD_BFDTARGET = elf64-x86-64
54endif
Simon Glass63f581f2015-08-04 12:33:52 -060055
56EFIPAYLOAD_BFDARCH = i386
Ben Stoltzc24aae52015-08-04 12:33:42 -060057
Simon Glassb776fc02016-11-07 08:47:13 -070058LDSCRIPT_EFI := $(srctree)/arch/x86/lib/elf_$(EFIARCH)_efi.lds
Simon Glass6f4b08a2016-11-07 08:47:14 -070059EFISTUB := crt0_$(EFIARCH)_efi.o reloc_$(EFIARCH)_efi.o
Ben Stoltzc24aae52015-08-04 12:33:42 -060060OBJCOPYFLAGS_EFI += --target=efi-app-$(EFIARCH)
61
Simon Glassce62a252015-08-04 12:33:56 -060062CPPFLAGS_REMOVE_crt0-efi-$(EFIARCH).o += $(CFLAGS_NON_EFI)
63CPPFLAGS_crt0-efi-$(EFIARCH).o += $(CFLAGS_EFI)
64
Ben Stoltzc24aae52015-08-04 12:33:42 -060065ifeq ($(CONFIG_EFI_APP),y)
66
67PLATFORM_CPPFLAGS += $(CFLAGS_EFI)
Simon Glass408cf262021-09-24 18:30:19 -060068LDFLAGS_FINAL += -znocombreloc -shared
Ben Stoltzc24aae52015-08-04 12:33:42 -060069LDSCRIPT := $(LDSCRIPT_EFI)
70
71else
72
Heinrich Schuchardteccd86f2021-04-11 11:21:57 +020073ifeq ($(IS_32BIT),y)
74PLATFORM_CPPFLAGS += -mregparm=3
75endif
Tom Rini5d4ecf22020-03-27 11:46:27 -040076KBUILD_LDFLAGS += --emit-relocs
Simon Glass5aa58752017-01-16 07:04:26 -070077LDFLAGS_FINAL += --gc-sections $(if $(CONFIG_SPL_BUILD),,-pie)
78
79endif
Ben Stoltzc24aae52015-08-04 12:33:42 -060080
Simon Glass5aa58752017-01-16 07:04:26 -070081ifdef CONFIG_X86_64
82ifndef CONFIG_SPL_BUILD
83PLATFORM_CPPFLAGS += -D__x86_64__
84else
85PLATFORM_CPPFLAGS += -D__I386__
86endif
87else
88PLATFORM_CPPFLAGS += -D__I386__
Ben Stoltzc24aae52015-08-04 12:33:42 -060089endif
Simon Glass105c9362016-11-07 08:47:15 -070090
Heinrich Schuchardte2425b62018-05-18 19:12:19 +020091ifdef CONFIG_EFI_STUB
Simon Glass105c9362016-11-07 08:47:15 -070092
Heinrich Schuchardte2425b62018-05-18 19:12:19 +020093ifdef CONFIG_EFI_STUB_64BIT
Simon Glass105c9362016-11-07 08:47:15 -070094EFI_LDS := elf_x86_64_efi.lds
95EFI_CRT0 := crt0_x86_64_efi.o
96EFI_RELOC := reloc_x86_64_efi.o
Simon Glass105c9362016-11-07 08:47:15 -070097else
98EFI_LDS := elf_ia32_efi.lds
99EFI_CRT0 := crt0_ia32_efi.o
100EFI_RELOC := reloc_ia32_efi.o
Heinrich Schuchardt82182892018-04-06 15:36:31 +0200101endif
102
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200103else
104
Heinrich Schuchardt82182892018-04-06 15:36:31 +0200105ifdef CONFIG_X86_64
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200106EFI_LDS := elf_x86_64_efi.lds
107EFI_CRT0 := crt0_x86_64_efi.o
108EFI_RELOC := reloc_x86_64_efi.o
Heinrich Schuchardt82182892018-04-06 15:36:31 +0200109else
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200110EFI_LDS := elf_ia32_efi.lds
111EFI_CRT0 := crt0_ia32_efi.o
112EFI_RELOC := reloc_ia32_efi.o
113endif
114
Simon Glass105c9362016-11-07 08:47:15 -0700115endif
116
Heinrich Schuchardte2425b62018-05-18 19:12:19 +0200117ifdef CONFIG_X86_64
118EFI_TARGET := --target=efi-app-x86_64
119else
120EFI_TARGET := --target=efi-app-ia32
Simon Glass105c9362016-11-07 08:47:15 -0700121endif