build: add e5500 CPU_TYPE
[openwrt/staging/stintel.git] / include / target.mk
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2007-2008 OpenWrt.org
4 # Copyright (C) 2016 LEDE Project
5
6 ifneq ($(__target_inc),1)
7 __target_inc=1
8
9 # default device type
10 DEVICE_TYPE?=router
11
12 # Default packages - the really basic set
13 DEFAULT_PACKAGES:=\
14 base-files \
15 ca-bundle \
16 dropbear \
17 fstools \
18 libc \
19 libgcc \
20 libustream-wolfssl \
21 logd \
22 mtd \
23 netifd \
24 opkg \
25 uci \
26 uclient-fetch \
27 urandom-seed \
28 urngd
29
30 ifneq ($(CONFIG_SELINUX),)
31 DEFAULT_PACKAGES+=busybox-selinux procd-selinux
32 else
33 DEFAULT_PACKAGES+=busybox procd
34 endif
35
36 # include ujail on systems with enough storage
37 ifeq ($(CONFIG_SMALL_FLASH),)
38 DEFAULT_PACKAGES+=procd-ujail
39 endif
40
41 # include seccomp ld-preload hooks if kernel supports it
42 ifneq ($(CONFIG_SECCOMP),)
43 DEFAULT_PACKAGES+=procd-seccomp
44 endif
45
46 # For the basic set
47 DEFAULT_PACKAGES.basic:=
48 # For nas targets
49 DEFAULT_PACKAGES.nas:=\
50 block-mount \
51 fdisk \
52 lsblk \
53 mdadm
54 # For router targets
55 DEFAULT_PACKAGES.router:=\
56 dnsmasq \
57 firewall \
58 ip6tables \
59 iptables \
60 kmod-ipt-offload \
61 odhcp6c \
62 odhcpd-ipv6only \
63 ppp \
64 ppp-mod-pppoe
65
66 ifneq ($(DUMP),)
67 all: dumpinfo
68 endif
69
70 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
71 ifeq ($(DUMP),)
72 PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
73 SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
74 else
75 PLATFORM_DIR:=${CURDIR}
76 ifeq ($(SUBTARGETS),)
77 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
78 endif
79 endif
80
81 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
82 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
83
84 ifneq ($(TARGET_BUILD),1)
85 ifndef DUMP
86 include $(PLATFORM_DIR)/Makefile
87 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
88 include $(PLATFORM_SUBDIR)/target.mk
89 endif
90 endif
91 else
92 ifneq ($(SUBTARGET),)
93 -include ./$(SUBTARGET)/target.mk
94 endif
95 endif
96
97 # Add device specific packages (here below to allow device type set from subtarget)
98 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
99
100 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
101 extra_packages = $(if $(filter wpad wpad-% nas,$(1)),iwinfo)
102
103 define ProfileDefault
104 NAME:=
105 PRIORITY:=
106 PACKAGES:=
107 endef
108
109 ifndef Profile
110 define Profile
111 $(eval $(call ProfileDefault))
112 $(eval $(call Profile/$(1)))
113 dumpinfo : $(call shexport,Profile/$(1)/Description)
114 PACKAGES := $(filter-out -%,$(PACKAGES))
115 DUMPINFO += \
116 echo "Target-Profile: $(1)"; \
117 $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
118 echo "Target-Profile-Name: $(NAME)"; \
119 echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
120 echo "Target-Profile-Description:"; \
121 echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
122 echo "@@"; \
123 echo;
124 endef
125 endif
126
127 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
128 define IncludeProfiles
129 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
130 -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
131 endef
132 else
133 define IncludeProfiles
134 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
135 endef
136 endif
137
138 PROFILE?=$(call qstrip,$(CONFIG_TARGET_PROFILE))
139
140 ifeq ($(TARGET_BUILD),1)
141 ifneq ($(DUMP),)
142 $(eval $(call IncludeProfiles))
143 endif
144 endif
145
146 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
147 include $(INCLUDE_DIR)/kernel-version.mk
148 endif
149
150 GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
151 GENERIC_BACKPORT_DIR := $(GENERIC_PLATFORM_DIR)/backport$(if $(wildcard $(GENERIC_PLATFORM_DIR)/backport-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
152 GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/pending$(if $(wildcard $(GENERIC_PLATFORM_DIR)/pending-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
153 GENERIC_HACK_DIR := $(GENERIC_PLATFORM_DIR)/hack$(if $(wildcard $(GENERIC_PLATFORM_DIR)/hack-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
154 GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
155
156 __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
157 __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
158 find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
159
160 GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
161 LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
162 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
163 LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
164 endif
165
166 # config file list used for compiling
167 LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
168
169 # default config list for reconfiguring
170 # defaults to subtarget if subtarget exists and target does not
171 # defaults to target otherwise
172 USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
173
174 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
175 LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
176
177 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
178 ifeq ($(CONFIG_TARGET),platform)
179 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
180 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
181 endif
182 ifeq ($(CONFIG_TARGET),subtarget)
183 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
184 LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
185 endif
186 ifeq ($(CONFIG_TARGET),subtarget_platform)
187 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
188 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
189 endif
190 ifeq ($(CONFIG_TARGET),env)
191 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
192 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
193 endif
194
195 __linux_confcmd = $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
196
197 LINUX_CONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_KCONFIG_LIST))
198 LINUX_RECONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_RECONFIG_LIST))
199 LINUX_RECONF_DIFF = $(SCRIPT_DIR)/kconfig.pl - '>' $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST))) $(1) $(GENERIC_PLATFORM_DIR)/config-filter
200
201 ifeq ($(DUMP),1)
202 BuildTarget=$(BuildTargets/DumpCurrent)
203
204 CPU_CFLAGS = -Os -pipe
205 ifneq ($(findstring mips,$(ARCH)),)
206 ifneq ($(findstring mips64,$(ARCH)),)
207 CPU_TYPE ?= mips64
208 else
209 CPU_TYPE ?= mips32
210 endif
211 CPU_CFLAGS += -mno-branch-likely
212 CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
213 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
214 CPU_CFLAGS_mips64r2 = -mips64r2 -mtune=mips64r2 -mabi=64
215 CPU_CFLAGS_4kec = -mips32r2 -mtune=4kec
216 CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
217 CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
218 CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64
219 endif
220 ifeq ($(ARCH),i386)
221 CPU_TYPE ?= pentium-mmx
222 CPU_CFLAGS_pentium-mmx = -march=pentium-mmx
223 CPU_CFLAGS_pentium4 = -march=pentium4
224 endif
225 ifneq ($(findstring arm,$(ARCH)),)
226 CPU_TYPE ?= xscale
227 endif
228 ifeq ($(ARCH),powerpc)
229 CPU_CFLAGS_603e:=-mcpu=603e
230 CPU_CFLAGS_8540:=-mcpu=8540
231 CPU_CFLAGS_405:=-mcpu=405
232 CPU_CFLAGS_440:=-mcpu=440
233 CPU_CFLAGS_464fp:=-mcpu=464fp
234 endif
235 ifeq ($(ARCH),powerpc64)
236 CPU_TYPE ?= powerpc64
237 CPU_CFLAGS_e5500:=-mcpu=e5500
238 CPU_CFLAGS_powerpc64:=-mcpu=powerpc64
239 endif
240 ifeq ($(ARCH),sparc)
241 CPU_TYPE = sparc
242 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
243 endif
244 ifeq ($(ARCH),aarch64)
245 CPU_TYPE ?= generic
246 CPU_CFLAGS_generic = -mcpu=generic
247 CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53
248 endif
249 ifeq ($(ARCH),arc)
250 CPU_TYPE ?= arc700
251 CPU_CFLAGS += -matomic
252 CPU_CFLAGS_arc700 = -mcpu=arc700
253 CPU_CFLAGS_archs = -mcpu=archs
254 endif
255 ifneq ($(CPU_TYPE),)
256 ifndef CPU_CFLAGS_$(CPU_TYPE)
257 $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type)
258 endif
259 endif
260 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
261
262 ifneq ($(BOARD),)
263 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
264 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
265 $(LINUX_CONF_CMD) > $@ || rm -f $@
266 -include $(TMP_CONFIG)
267 .SILENT: $(TMP_CONFIG)
268 .PRECIOUS: $(TMP_CONFIG)
269
270 ifdef KERNEL_TESTING_PATCHVER
271 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
272 FEATURES += testing-kernel
273 endif
274 endif
275 ifneq ($(CONFIG_OF),)
276 FEATURES += dt
277 endif
278 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
279 FEATURES += gpio
280 endif
281 ifneq ($(CONFIG_PCI),)
282 FEATURES += pci
283 endif
284 ifneq ($(CONFIG_PCIEPORTBUS),)
285 FEATURES += pcie
286 endif
287 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
288 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
289 FEATURES += usb
290 endif
291 endif
292 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
293 FEATURES += pcmcia
294 endif
295 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
296 FEATURES += display
297 endif
298 ifneq ($(CONFIG_RTC_CLASS),)
299 FEATURES += rtc
300 endif
301 ifneq ($(CONFIG_VIRTIO),)
302 FEATURES += virtio
303 endif
304 ifneq ($(CONFIG_CPU_MIPS32_R2),)
305 FEATURES += mips16
306 endif
307 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
308
309 # remove duplicates
310 FEATURES:=$(sort $(FEATURES))
311 endif
312 endif
313
314 CUR_SUBTARGET:=$(SUBTARGET)
315 ifeq ($(SUBTARGETS),)
316 CUR_SUBTARGET := default
317 endif
318
319 define BuildTargets/DumpCurrent
320 .PHONY: dumpinfo
321 dumpinfo : export DESCRIPTION=$$(Target/Description)
322 dumpinfo:
323 @echo 'Target: $(TARGETID)'; \
324 echo 'Target-Board: $(BOARD)'; \
325 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
326 echo 'Target-Arch: $(ARCH)'; \
327 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
328 echo 'Target-Features: $(FEATURES)'; \
329 echo 'Target-Depends: $(DEPENDS)'; \
330 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
331 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
332 echo 'Linux-Version: $(LINUX_VERSION)'; \
333 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \
334 echo 'Linux-Release: $(LINUX_RELEASE)'; \
335 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
336 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
337 echo 'Target-Description:'; \
338 echo "$$$$DESCRIPTION"; \
339 echo '@@'; \
340 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
341 $(DUMPINFO)
342 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
343 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
344 endef
345
346 include $(INCLUDE_DIR)/kernel.mk
347 ifeq ($(TARGET_BUILD),1)
348 include $(INCLUDE_DIR)/kernel-build.mk
349 BuildTarget?=$(BuildKernel)
350 endif
351
352 endif #__target_inc