xref: /openbmc/linux/arch/loongarch/Makefile (revision adacfc6d)
1fa96b57cSHuacai Chen# SPDX-License-Identifier: GPL-2.0
2fa96b57cSHuacai Chen#
3fa96b57cSHuacai Chen# Author: Huacai Chen <chenhuacai@loongson.cn>
4fa96b57cSHuacai Chen# Copyright (C) 2020-2022 Loongson Technology Corporation Limited
5fa96b57cSHuacai Chen
6fa96b57cSHuacai Chenboot	:= arch/loongarch/boot
7fa96b57cSHuacai Chen
89e8536e2SHuacai ChenKBUILD_DEFCONFIG := loongson3_defconfig
99e8536e2SHuacai Chen
10c5d5cba7SArd Biesheuvelimage-name-y			:= vmlinux
11c5d5cba7SArd Biesheuvelimage-name-$(CONFIG_EFI_ZBOOT)	:= vmlinuz
12c5d5cba7SArd Biesheuvel
13ead384d9SHuacai Chenifndef CONFIG_EFI_STUB
14ead384d9SHuacai ChenKBUILD_IMAGE	:= $(boot)/vmlinux.elf
15ead384d9SHuacai Chenelse
16c5d5cba7SArd BiesheuvelKBUILD_IMAGE	:= $(boot)/$(image-name-y).efi
17ead384d9SHuacai Chenendif
18fa96b57cSHuacai Chen
19fa96b57cSHuacai Chen#
20fa96b57cSHuacai Chen# Select the object file format to substitute into the linker script.
21fa96b57cSHuacai Chen#
22fa96b57cSHuacai Chen64bit-tool-archpref	= loongarch64
23fa96b57cSHuacai Chen32bit-bfd		= elf32-loongarch
24fa96b57cSHuacai Chen64bit-bfd		= elf64-loongarch
25fa96b57cSHuacai Chen32bit-emul		= elf32loongarch
26fa96b57cSHuacai Chen64bit-emul		= elf64loongarch
27fa96b57cSHuacai Chen
284733f09dSQing Zhangifdef CONFIG_DYNAMIC_FTRACE
294733f09dSQing ZhangKBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY
304733f09dSQing ZhangCC_FLAGS_FTRACE := -fpatchable-function-entry=2
314733f09dSQing Zhangendif
324733f09dSQing Zhang
33fa96b57cSHuacai Chenifdef CONFIG_64BIT
34fa96b57cSHuacai Chentool-archpref		= $(64bit-tool-archpref)
35fa96b57cSHuacai ChenUTS_MACHINE		:= loongarch64
36fa96b57cSHuacai Chenendif
37fa96b57cSHuacai Chen
38fa96b57cSHuacai Chenifneq ($(SUBARCH),$(ARCH))
39fa96b57cSHuacai Chen  ifeq ($(CROSS_COMPILE),)
40fa96b57cSHuacai Chen    CROSS_COMPILE := $(call cc-cross-prefix, $(tool-archpref)-linux-  $(tool-archpref)-linux-gnu-  $(tool-archpref)-unknown-linux-gnu-)
41fa96b57cSHuacai Chen  endif
42fa96b57cSHuacai Chenendif
43fa96b57cSHuacai Chen
44fa96b57cSHuacai Chenifdef CONFIG_64BIT
45fa96b57cSHuacai Chenld-emul			= $(64bit-emul)
46fa96b57cSHuacai Chencflags-y		+= -mabi=lp64s
47fa96b57cSHuacai Chenendif
48fa96b57cSHuacai Chen
4938b10b26SWANG Xueruicflags-y			+= -pipe -msoft-float
5038b10b26SWANG XueruiLDFLAGS_vmlinux			+= -static -n -nostdlib
5111cd8a64SXi Ruoyao
5211cd8a64SXi Ruoyao# When the assembler supports explicit relocation hint, we must use it.
5311cd8a64SXi Ruoyao# GCC may have -mexplicit-relocs off by default if it was built with an old
5411cd8a64SXi Ruoyao# assembler, so we force it via an option.
5511cd8a64SXi Ruoyao#
5611cd8a64SXi Ruoyao# When the assembler does not supports explicit relocation hint, we can't use
5711cd8a64SXi Ruoyao# it.  Disable it if the compiler supports it.
5811cd8a64SXi Ruoyao#
5938b10b26SWANG Xuerui# The combination of a "new" assembler and "old" GCC is not supported, given
6038b10b26SWANG Xuerui# the rarity of this combo and the extra complexity needed to make it work.
6138b10b26SWANG Xuerui# Either upgrade the compiler or downgrade the assembler; the build will error
6238b10b26SWANG Xuerui# out if it is the case (by probing for the model attribute; all supported
6338b10b26SWANG Xuerui# compilers in this case would have support).
6438b10b26SWANG Xuerui#
6538b10b26SWANG Xuerui# Also, -mdirect-extern-access is useful in case of building with explicit
6638b10b26SWANG Xuerui# relocs, for avoiding unnecessary GOT accesses. It is harmless to not have
6738b10b26SWANG Xuerui# support though.
6811cd8a64SXi Ruoyaoifdef CONFIG_AS_HAS_EXPLICIT_RELOCS
6938b10b26SWANG Xueruicflags-y			+= $(call cc-option,-mexplicit-relocs)
7038b10b26SWANG XueruiKBUILD_CFLAGS_KERNEL		+= $(call cc-option,-mdirect-extern-access)
7103c53eb9SHuacai ChenKBUILD_AFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
7203c53eb9SHuacai ChenKBUILD_CFLAGS_MODULE		+= $(call cc-option,-mno-relax) $(call cc-option,-Wa$(comma)-mno-relax)
7311cd8a64SXi Ruoyaoelse
7411cd8a64SXi Ruoyaocflags-y			+= $(call cc-option,-mno-explicit-relocs)
75fa96b57cSHuacai ChenKBUILD_AFLAGS_KERNEL		+= -Wa,-mla-global-with-pcrel
76fa96b57cSHuacai ChenKBUILD_CFLAGS_KERNEL		+= -Wa,-mla-global-with-pcrel
77fa96b57cSHuacai ChenKBUILD_AFLAGS_MODULE		+= -Wa,-mla-global-with-abs
78fa96b57cSHuacai ChenKBUILD_CFLAGS_MODULE		+= -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
7911cd8a64SXi Ruoyaoendif
80fa96b57cSHuacai Chen
81d8da19fbSYouling Tangifeq ($(CONFIG_RELOCATABLE),y)
82d8da19fbSYouling TangKBUILD_CFLAGS_KERNEL		+= -fPIE
8310d9f8edSWANG RuiLDFLAGS_vmlinux			+= -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
84d8da19fbSYouling Tangendif
85d8da19fbSYouling Tang
86fa96b57cSHuacai Chencflags-y += $(call cc-option, -mno-check-zero-division)
875aa4ac64SQing Zhang
885aa4ac64SQing Zhangifndef CONFIG_KASAN
893f301dc2SWANG Xueruicflags-y += -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset
905aa4ac64SQing Zhangendif
91fa96b57cSHuacai Chen
92fa96b57cSHuacai Chenload-y		= 0x9000000000200000
93fa96b57cSHuacai Chenbootvars-y	= VMLINUX_LOAD_ADDRESS=$(load-y)
94fa96b57cSHuacai Chen
9557fc7323SHuacai Chendrivers-$(CONFIG_PCI)		+= arch/loongarch/pci/
9657fc7323SHuacai Chen
97fa96b57cSHuacai ChenKBUILD_AFLAGS	+= $(cflags-y)
98fa96b57cSHuacai ChenKBUILD_CFLAGS	+= $(cflags-y)
99fa96b57cSHuacai ChenKBUILD_CPPFLAGS += -DVMLINUX_LOAD_ADDRESS=$(load-y)
100fa96b57cSHuacai Chen
101fa96b57cSHuacai Chen# This is required to get dwarf unwinding tables into .debug_frame
102fa96b57cSHuacai Chen# instead of .eh_frame so we don't discard them.
103fa96b57cSHuacai ChenKBUILD_CFLAGS += -fno-asynchronous-unwind-tables
104fa96b57cSHuacai Chen
10541596803SHuacai Chenifdef CONFIG_ARCH_STRICT_ALIGN
106fa96b57cSHuacai Chen# Don't emit unaligned accesses.
107fa96b57cSHuacai Chen# Not all LoongArch cores support unaligned access, and as kernel we can't
108fa96b57cSHuacai Chen# rely on others to provide emulation for these accesses.
109fa96b57cSHuacai ChenKBUILD_CFLAGS += $(call cc-option,-mstrict-align)
11041596803SHuacai Chenelse
11141596803SHuacai Chen# Optimise for performance on hardware supports unaligned access.
11241596803SHuacai ChenKBUILD_CFLAGS += $(call cc-option,-mno-strict-align)
11341596803SHuacai Chenendif
114fa96b57cSHuacai Chen
115fa96b57cSHuacai ChenKBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)
116fa96b57cSHuacai Chen
117fa96b57cSHuacai ChenKBUILD_LDFLAGS	+= -m $(ld-emul)
118fa96b57cSHuacai Chen
11954c2c9dfSHuacai Chenifdef need-compiler
1205ddc7a37SWANG XueruiCHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \
12183f638bcSTiezhu Yang	grep -E -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \
122fa96b57cSHuacai Chen	sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g')
123fa96b57cSHuacai Chenendif
124fa96b57cSHuacai Chen
125fa96b57cSHuacai Chenlibs-y += arch/loongarch/lib/
126ead384d9SHuacai Chenlibs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
127fa96b57cSHuacai Chen
1282f164822SMin Zhoudrivers-y		+= arch/loongarch/crypto/
1292f164822SMin Zhou
130366bb35aSHuacai Chen# suspend and hibernation support
131366bb35aSHuacai Chendrivers-$(CONFIG_PM)	+= arch/loongarch/power/
132366bb35aSHuacai Chen
133fa96b57cSHuacai Chenifeq ($(KBUILD_EXTMOD),)
134fa96b57cSHuacai Chenprepare: vdso_prepare
135fa96b57cSHuacai Chenvdso_prepare: prepare0
136fa96b57cSHuacai Chen	$(Q)$(MAKE) $(build)=arch/loongarch/vdso include/generated/vdso-offsets.h
137fa96b57cSHuacai Chenendif
138fa96b57cSHuacai Chen
139adacfc6dSMasahiro Yamadavdso-install-y += arch/loongarch/vdso/vdso.so.dbg
140fa96b57cSHuacai Chen
141ead384d9SHuacai Chenall:	$(notdir $(KBUILD_IMAGE))
142fa96b57cSHuacai Chen
14303372601SMasahiro Yamadavmlinuz.efi: vmlinux.efi
14403372601SMasahiro Yamada
145c5d5cba7SArd Biesheuvelvmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux
146ead384d9SHuacai Chen	$(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@
147fa96b57cSHuacai Chen
148fa96b57cSHuacai Cheninstall:
149c5d5cba7SArd Biesheuvel	$(Q)install -D -m 755 $(KBUILD_IMAGE) $(INSTALL_PATH)/$(image-name-y)-$(KERNELRELEASE)
150fa96b57cSHuacai Chen	$(Q)install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE)
151fa96b57cSHuacai Chen	$(Q)install -D -m 644 System.map $(INSTALL_PATH)/System.map-$(KERNELRELEASE)
152fa96b57cSHuacai Chen
153fa96b57cSHuacai Chendefine archhelp
154fa96b57cSHuacai Chen	echo '  install              - install kernel into $(INSTALL_PATH)'
155fa96b57cSHuacai Chen	echo
156fa96b57cSHuacai Chenendef
157