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