build: allow overriding default selection state for devices
[openwrt/openwrt.git] / include / image.mk
1 #
2 # Copyright (C) 2006-2010 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 override TARGET_BUILD=
9 include $(INCLUDE_DIR)/prereq.mk
10 include $(INCLUDE_DIR)/kernel.mk
11 include $(INCLUDE_DIR)/version.mk
12 include $(INCLUDE_DIR)/image-commands.mk
13
14 ifndef IB
15 ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
16 TARGET_PER_DEVICE_ROOTFS := 1
17 endif
18 endif
19
20 include $(INCLUDE_DIR)/image-legacy.mk
21 include $(INCLUDE_DIR)/feeds.mk
22 include $(INCLUDE_DIR)/rootfs.mk
23
24 override MAKE:=$(_SINGLE)$(SUBMAKE)
25 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
26
27 target_params = $(subst +,$(space),$*)
28 param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
29 param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))
30 param_mangle = $(subst $(space),_,$(strip $(1)))
31 param_unmangle = $(subst _,$(space),$(1))
32
33 mkfs_packages_id = $(shell echo $(sort $(1)) | mkhash md5 | head -c 8)
34 mkfs_target_dir = $(if $(call param_get,pkg,$(1)),$(KDIR)/target-dir-$(call param_get,pkg,$(1)),$(TARGET_DIR))
35
36 KDIR=$(KERNEL_BUILD_DIR)
37 KDIR_TMP=$(KDIR)/tmp
38 DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
39
40 IMG_PREFIX_EXTRA:=$(if $(EXTRA_IMAGE_NAME),$(call sanitize,$(EXTRA_IMAGE_NAME))-)
41 IMG_PREFIX_VERNUM:=$(if $(CONFIG_VERSION_FILENAMES),$(call sanitize,$(VERSION_NUMBER))-)
42 IMG_PREFIX_VERCODE:=$(if $(CONFIG_VERSION_CODE_FILENAMES),$(call sanitize,$(VERSION_CODE))-)
43
44 IMG_PREFIX:=$(VERSION_DIST_SANITIZED)-$(IMG_PREFIX_VERNUM)$(IMG_PREFIX_VERCODE)$(IMG_PREFIX_EXTRA)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
45 IMG_ROOTFS:=$(IMG_PREFIX)-rootfs
46 IMG_COMBINED:=$(IMG_PREFIX)-combined
47
48 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
49
50 ifneq ($(CONFIG_BIG_ENDIAN),)
51 JFFS2OPTS := --big-endian --squash-uids -v
52 else
53 JFFS2OPTS := --little-endian --squash-uids -v
54 endif
55
56 ifeq ($(CONFIG_JFFS2_RTIME),y)
57 JFFS2OPTS += -X rtime
58 endif
59 ifeq ($(CONFIG_JFFS2_ZLIB),y)
60 JFFS2OPTS += -X zlib
61 endif
62 ifeq ($(CONFIG_JFFS2_LZMA),y)
63 JFFS2OPTS += -X lzma --compression-mode=size
64 endif
65 ifneq ($(CONFIG_JFFS2_RTIME),y)
66 JFFS2OPTS += -x rtime
67 endif
68 ifneq ($(CONFIG_JFFS2_ZLIB),y)
69 JFFS2OPTS += -x zlib
70 endif
71 ifneq ($(CONFIG_JFFS2_LZMA),y)
72 JFFS2OPTS += -x lzma
73 endif
74
75 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
76
77 SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
78 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
79 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
80 SQUASHFSCOMP := gzip
81 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
82 ifeq ($(CONFIG_SQUASHFS_XZ),y)
83 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
84 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
85 endif
86 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
87 endif
88
89 JFFS2_BLOCKSIZE ?= 64k 128k
90
91 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
92 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
93 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
94 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
95 fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
96 fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
97 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
98
99 TARGET_FILESYSTEMS := $(fs-types-y)
100
101 FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
102 FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
103 FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
104
105 define add_jffs2_mark
106 echo -ne '\xde\xad\xc0\xde' >> $(1)
107 endef
108
109 PROFILE_SANITIZED := $(call sanitize,$(subst DEVICE_,,$(PROFILE)))
110
111 define split_args
112 $(foreach data, \
113 $(subst |,$(space),\
114 $(subst $(space),^,$(1))), \
115 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
116 endef
117
118 define build_cmd
119 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
120 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
121
122 endef
123
124 define concat_cmd
125 $(call split_args,$(1),build_cmd)
126 endef
127
128 # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
129 define prepare_generic_squashfs
130 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
131 endef
132
133 define Image/BuildKernel/Initramfs
134 $(call Image/Build/Initramfs)
135 endef
136
137 define Image/BuildKernel/MkuImage
138 mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
139 -n '$(call toupper,$(ARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' -d $(4) $(5)
140 endef
141
142 define Image/BuildKernel/MkFIT
143 $(TOPDIR)/scripts/mkits.sh \
144 -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
145 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
146 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
147 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
148 endef
149
150 ifdef CONFIG_TARGET_IMAGES_GZIP
151 define Image/Gzip
152 rm -f $(1).gz
153 gzip -9n $(1)
154 endef
155 endif
156
157
158 # Disable noisy checks by default as in upstream
159 ifeq ($(strip $(call kernel_patchver_ge,4.7.0)),1)
160 DTC_FLAGS += -Wno-unit_address_vs_reg
161 endif
162 ifeq ($(strip $(call kernel_patchver_ge,4.12.0)),1)
163 DTC_FLAGS += \
164 -Wno-unit_address_vs_reg \
165 -Wno-simple_bus_reg \
166 -Wno-unit_address_format \
167 -Wno-pci_bridge \
168 -Wno-pci_device_bus_num \
169 -Wno-pci_device_reg
170 endif
171 ifeq ($(strip $(call kernel_patchver_ge,4.17.0)),1)
172 DTC_FLAGS += \
173 -Wno-avoid_unnecessary_addr_size \
174 -Wno-alias_paths
175 endif
176 ifeq ($(strip $(call kernel_patchver_ge,4.18.0)),1)
177 DTC_FLAGS += \
178 -Wno-graph_child_address \
179 -Wno-graph_port \
180 -Wno-unique_unit_address
181 endif
182
183 define Image/pad-to
184 dd if=$(1) of=$(1).new bs=$(2) conv=sync
185 mv $(1).new $(1)
186 endef
187
188 ROOTFS_PARTSIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
189
190 define Image/pad-root-squashfs
191 $(call Image/pad-to,$(KDIR)/root.squashfs,$(if $(1),$(1),$(ROOTFS_PARTSIZE)))
192 endef
193
194 # $(1) source dts file
195 # $(2) target dtb file
196 # $(3) extra CPP flags
197 # $(4) extra DTC flags
198 define Image/BuildDTB
199 $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
200 -I$(DTS_DIR) \
201 -I$(DTS_DIR)/include \
202 -I$(LINUX_DIR)/include/ \
203 -undef -D__DTS__ $(3) \
204 -o $(2).tmp $(1)
205 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
206 -i$(dir $(1)) $(DTC_FLAGS) $(4) \
207 -o $(2) $(2).tmp
208 $(RM) $(2).tmp
209 endef
210
211 define Image/mkfs/jffs2/sub-raw
212 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
213 $(2) \
214 -e $(patsubst %k,%KiB,$(1)) \
215 -o $@ -d $(call mkfs_target_dir,$(3)) \
216 -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
217 endef
218
219 define Image/mkfs/jffs2/sub
220 $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
221 $(call add_jffs2_mark,$@)
222 endef
223
224 define Image/mkfs/jffs2/template
225 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(JFFS2OPTS),$$(1))
226 Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(JFFS2OPTS),$$(1))
227
228 endef
229
230 define Image/mkfs/jffs2-nand/template
231 Image/mkfs/jffs2-nand-$(1) = \
232 $$(call Image/mkfs/jffs2/sub, \
233 $(word 2,$(subst -, ,$(1))), \
234 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))),$$(1))
235
236 endef
237
238 $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
239 $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
240
241 define Image/mkfs/squashfs
242 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
243 -nopad -noappend -root-owned \
244 -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) \
245 -processors 1
246 endef
247
248 # $(1): board name
249 # $(2): rootfs type
250 # $(3): kernel image
251 # $(4): compat string
252 ifneq ($(CONFIG_NAND_SUPPORT),)
253 define Image/Build/SysupgradeNAND
254 mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
255 echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
256 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
257 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
258 (cd "$(KDIR_TMP)"; $(TAR) cvf \
259 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
260 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
261 )
262 endef
263
264 # $(1) board name
265 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
266 # $(3) rootfstype (e.g. squashfs or ubifs)
267 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
268 define Image/Build/UbinizeImage
269 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
270 "$(KDIR)/root.$(3)" \
271 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
272 $(4)
273 endef
274
275 endif
276
277 define Image/mkfs/ubifs
278 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
279 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
280 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
281 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
282 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
283 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
284 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
285 --squash-uids \
286 -o $@ -d $(call mkfs_target_dir,$(1))
287 endef
288
289 define Image/mkfs/ext4
290 $(STAGING_DIR_HOST)/bin/make_ext4fs \
291 -l $(ROOTFS_PARTSIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
292 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
293 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
294 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
295 $@ $(call mkfs_target_dir,$(1))/
296 endef
297
298 define Image/Manifest
299 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
300 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
301 endef
302
303 define Image/gzip-ext4-padded-squashfs
304
305 define Image/Build/squashfs
306 $(call Image/pad-root-squashfs)
307 endef
308
309 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
310 define Image/Build/gzip/ext4
311 $(call Image/Build/gzip,ext4)
312 endef
313 define Image/Build/gzip/squashfs
314 $(call Image/Build/gzip,squashfs)
315 endef
316 endif
317
318 endef
319
320 ifdef CONFIG_TARGET_ROOTFS_TARGZ
321 define Image/Build/targz
322 $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
323 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
324 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
325 endef
326 endif
327
328 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
329 define Image/Build/cpiogz
330 ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_ROOTFS).cpio.gz )
331 endef
332 endif
333
334 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
335 mkfs_packages_add = $(foreach pkg,$(filter-out -%,$(mkfs_packages)),$(pkg)$(call GetABISuffix,$(pkg)))
336 mkfs_packages_remove = $(foreach pkg,$(patsubst -%,%,$(filter -%,$(mkfs_packages))),$(pkg)$(call GetABISuffix,$(pkg)))
337 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
338
339 opkg_target = \
340 $(call opkg,$(mkfs_cur_target_dir)) \
341 -f $(mkfs_cur_target_dir).conf
342
343 target-dir-%: FORCE
344 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
345 $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
346 -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
347 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
348 $(if $(mkfs_packages_remove), \
349 -$(call opkg,$(mkfs_cur_target_dir)) remove \
350 $(mkfs_packages_remove))
351 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
352 $(opkg_target) update && \
353 $(opkg_target) install \
354 $(call opkg_package_files,$(mkfs_packages_add)))
355 -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
356 rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
357 $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
358
359 $(KDIR)/root.%: kernel_prepare
360 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
361
362 define Device/InitProfile
363 PROFILES := $(PROFILE)
364 DEVICE_TITLE = $$(DEVICE_VENDOR) $$(DEVICE_MODEL)$$(if $$(DEVICE_VARIANT), $$(DEVICE_VARIANT))
365 DEVICE_VENDOR :=
366 DEVICE_MODEL :=
367 DEVICE_VARIANT :=
368 DEVICE_PACKAGES :=
369 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
370 endef
371
372 define Device/Init
373 DEVICE_NAME := $(1)
374 KERNEL:=
375 KERNEL_INITRAMFS = $$(KERNEL)
376 KERNEL_SIZE:=
377 CMDLINE:=
378
379 IMAGES :=
380 ARTIFACTS :=
381 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
382 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
383 KERNEL_PREFIX = $$(IMAGE_PREFIX)
384 KERNEL_SUFFIX := -kernel.bin
385 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
386 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
387 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
388 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
389 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
390 KERNEL_INSTALL :=
391 KERNEL_NAME := vmlinux
392 KERNEL_DEPENDS :=
393 KERNEL_SIZE :=
394
395 UBOOTENV_IN_UBI :=
396 KERNEL_IN_UBI :=
397 BLOCKSIZE :=
398 PAGESIZE :=
399 SUBPAGESIZE :=
400 VID_HDR_OFFSET :=
401 UBINIZE_OPTS :=
402 UBINIZE_PARTS :=
403 MKUBIFS_OPTS :=
404
405 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
406
407 DEVICE_DTS :=
408 DEVICE_DTS_CONFIG :=
409 DEVICE_DTS_DIR :=
410
411 BOARD_NAME :=
412 UIMAGE_NAME :=
413 SUPPORTED_DEVICES :=
414 IMAGE_METADATA :=
415
416 FILESYSTEMS := $(TARGET_FILESYSTEMS)
417
418 UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-$(1)
419
420 DEFAULT :=
421 endef
422
423 DEFAULT_DEVICE_VARS := \
424 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
425 CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
426 VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
427 DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME UIMAGE_NAME SUPPORTED_DEVICES \
428 IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR UBOOT_PATH DEVICE_VENDOR \
429 DEVICE_MODEL DEVICE_VARIANT
430
431 define Device/ExportVar
432 $(1) : $(2):=$$($(2))
433
434 endef
435 define Device/Export
436 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
437 $(1) : FILESYSTEM:=$(2)
438 endef
439
440 ifdef IB
441 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
442 else
443 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
444 endif
445
446 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
447
448 define merge_packages
449 $(1) :=
450 $(foreach pkg,$(2),
451 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
452 )
453 endef
454
455 define Device/Check/Common
456 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
457 DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
458 ifdef TARGET_PER_DEVICE_ROOTFS
459 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
460 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
461 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
462 endif
463 endef
464
465 define Device/Check
466 $(Device/Check/Common)
467 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
468 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
469 ifndef IB
470 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
471 endif
472 endef
473
474 ifndef IB
475 define Device/Build/initramfs
476 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
477 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
478
479 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
480 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
481 cp $$^ $$@
482
483 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
484 @rm -f $$@
485 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
486 endef
487 endif
488
489 define Device/Build/compile
490 $$(_COMPILE_TARGET): $(KDIR)/$(1)
491 $(eval $(call Device/Export,$(KDIR)/$(1)))
492 $(KDIR)/$(1):
493 $$(call concat_cmd,$(COMPILE/$(1)))
494
495 endef
496
497 ifndef IB
498 define Device/Build/dtb
499 ifndef BUILD_DTS_$(1)
500 BUILD_DTS_$(1) := 1
501 $(KDIR)/image-$(1).dtb: FORCE
502 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
503
504 image_prepare: $(KDIR)/image-$(1).dtb
505 endif
506
507 endef
508 endif
509
510 define Device/Build/kernel
511 $$(eval $$(foreach dts,$$(DEVICE_DTS), \
512 $$(call Device/Build/dtb,$$(notdir $$(dts)), \
513 $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
514 $$(dts) \
515 ) \
516 ))
517
518 $(KDIR)/$$(KERNEL_NAME):: image_prepare
519 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
520 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
521 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
522 cp $$^ $$@
523 ifndef IB
524 ifdef CONFIG_IB
525 install: $$(KDIR_KERNEL_IMAGE)
526 endif
527 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
528 @rm -f $$@
529 $$(call concat_cmd,$$(KERNEL))
530 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
531 endif
532 endef
533
534 define Device/Build/image
535 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
536 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
537 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
538 ROOTFS/$(1)/$(3) := \
539 $(KDIR)/root.$(1)$$(strip \
540 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
541 )$$(strip \
542 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
543 )
544 ifndef IB
545 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
546 endif
547 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
548 @rm -f $$@
549 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
550 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
551
552 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
553
554 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
555 gzip -c -9n $$^ > $$@
556
557 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
558 cp $$^ $$@
559
560 endef
561
562 define Device/Build/artifact
563 $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
564 $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
565 $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
566 @rm -f $$@
567 $$(call concat_cmd,$(ARTIFACT/$(1)))
568
569 .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
570
571 $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
572 cp $$^ $$@
573
574 endef
575
576 define Device/Build
577 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
578 $(call Device/Build/kernel,$(1))
579
580 $$(eval $$(foreach compile,$$(COMPILE), \
581 $$(call Device/Build/compile,$$(compile),$(1))))
582
583 $$(eval $$(foreach image,$$(IMAGES), \
584 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
585 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
586
587 $$(eval $$(foreach artifact,$$(ARTIFACTS), \
588 $$(call Device/Build/artifact,$$(artifact))))
589
590 endef
591
592 define Device/DumpInfo
593 Target-Profile: DEVICE_$(1)
594 Target-Profile-Name: $(DEVICE_TITLE)
595 Target-Profile-Packages: $(DEVICE_PACKAGES)
596 Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
597 Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
598 $(if $(DEFAULT),Target-Profile-Default: $(DEFAULT))
599 Target-Profile-Description:
600 $(DEVICE_DESCRIPTION)
601 @@
602
603 endef
604
605 define Device/Dump
606 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
607 endef
608
609 define Device
610 $(call Device/InitProfile,$(1))
611 $(call Device/Init,$(1))
612 $(call Device/Default,$(1))
613 $(call Device/$(1),$(1))
614 $(call Device/Check,$(1))
615 $(call Device/$(if $(DUMP),Dump,Build),$(1))
616
617 endef
618
619 define BuildImage
620
621 ifneq ($(DUMP),)
622 all: dumpinfo
623 dumpinfo: FORCE
624 @true
625 endif
626
627 download:
628 prepare:
629 compile:
630 clean:
631 legacy-images-prepare:
632 legacy-images:
633 image_prepare:
634
635 ifeq ($(IB),)
636 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
637 compile:
638 $(call Build/Compile)
639
640 clean:
641 $(call Build/Clean)
642
643 image_prepare: compile
644 mkdir -p $(BIN_DIR) $(KDIR)/tmp
645 $(call Image/Prepare)
646
647 legacy-images-prepare-make: image_prepare
648 $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
649
650 else
651 image_prepare:
652 mkdir -p $(BIN_DIR) $(KDIR)/tmp
653 endif
654
655 kernel_prepare: image_prepare
656 $(call Image/Build/targz)
657 $(call Image/Build/cpiogz)
658 $(call Image/BuildKernel)
659 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
660 $(call Image/InstallKernel)
661
662 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
663 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
664
665 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
666 $(foreach fs,$(TARGET_FILESYSTEMS),
667 $(call Image/Build,$(fs))
668 )
669
670 legacy-images-make: install-images
671 $(call Image/mkfs/ubifs/legacy)
672 $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
673
674 install: install-images
675 $(call Image/Manifest)
676
677 endef