3680be2155d361b898b78df62547eb457caa5457
[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
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
156 # Disable noisy checks by default as in upstream
157 ifeq ($(strip $(call kernel_patchver_ge,4.7.0)),1)
158 DTC_FLAGS += -Wno-unit_address_vs_reg
159 endif
160 ifeq ($(strip $(call kernel_patchver_ge,4.12.0)),1)
161 DTC_FLAGS += \
162 -Wno-unit_address_vs_reg \
163 -Wno-simple_bus_reg \
164 -Wno-unit_address_format \
165 -Wno-pci_bridge \
166 -Wno-pci_device_bus_num \
167 -Wno-pci_device_reg
168 endif
169 ifeq ($(strip $(call kernel_patchver_ge,4.17.0)),1)
170 DTC_FLAGS += \
171 -Wno-avoid_unnecessary_addr_size \
172 -Wno-alias_paths
173 endif
174 ifeq ($(strip $(call kernel_patchver_ge,4.18.0)),1)
175 DTC_FLAGS += \
176 -Wno-graph_child_address \
177 -Wno-graph_port \
178 -Wno-unique_unit_address
179 endif
180
181 define Image/pad-to
182 dd if=$(1) of=$(1).new bs=$(2) conv=sync
183 mv $(1).new $(1)
184 endef
185
186 define Image/pad-root-squashfs
187 $(call Image/pad-to,$(KDIR)/root.squashfs,$(if $(1),$(1),$(CONFIG_TARGET_ROOTFS_PARTSIZE)M))
188 endef
189
190 # $(1) source dts file
191 # $(2) target dtb file
192 # $(3) extra CPP flags
193 # $(4) extra DTC flags
194 define Image/BuildDTB
195 $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
196 -I$(DTS_DIR) \
197 -I$(DTS_DIR)/include \
198 -I$(LINUX_DIR)/include/ \
199 -undef -D__DTS__ $(3) \
200 -o $(2).tmp $(1)
201 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
202 -i$(dir $(1)) $(DTC_FLAGS) $(4) \
203 -o $(2) $(2).tmp
204 $(RM) $(2).tmp
205 endef
206
207 define Image/mkfs/jffs2/sub-raw
208 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
209 $(2) \
210 -e $(patsubst %k,%KiB,$(1)) \
211 -o $@ -d $(call mkfs_target_dir,$(3)) \
212 -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
213 endef
214
215 define Image/mkfs/jffs2/sub
216 $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
217 $(call add_jffs2_mark,$@)
218 endef
219
220 define Image/mkfs/jffs2/template
221 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(JFFS2OPTS),$$(1))
222 Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(JFFS2OPTS),$$(1))
223
224 endef
225
226 define Image/mkfs/jffs2-nand/template
227 Image/mkfs/jffs2-nand-$(1) = \
228 $$(call Image/mkfs/jffs2/sub, \
229 $(word 2,$(subst -, ,$(1))), \
230 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))),$$(1))
231
232 endef
233
234 $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
235 $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
236
237 define Image/mkfs/squashfs
238 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
239 -nopad -noappend -root-owned \
240 -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) \
241 -processors 1
242 endef
243
244 # $(1): board name
245 # $(2): rootfs type
246 # $(3): kernel image
247 # $(4): compat string
248 ifneq ($(CONFIG_NAND_SUPPORT),)
249 define Image/Build/SysupgradeNAND
250 mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
251 echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
252 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
253 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
254 (cd "$(KDIR_TMP)"; $(TAR) cvf \
255 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
256 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
257 )
258 endef
259
260 # $(1) board name
261 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
262 # $(3) rootfstype (e.g. squashfs or ubifs)
263 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
264 define Image/Build/UbinizeImage
265 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
266 "$(KDIR)/root.$(3)" \
267 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
268 $(4)
269 endef
270
271 endif
272
273 define Image/mkfs/ubifs
274 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
275 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
276 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
277 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
278 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
279 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
280 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
281 --squash-uids \
282 -o $@ -d $(call mkfs_target_dir,$(1))
283 endef
284
285 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
286
287 define Image/mkfs/ext4
288 $(STAGING_DIR_HOST)/bin/make_ext4fs \
289 -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
290 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
291 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
292 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
293 $@ $(call mkfs_target_dir,$(1))/
294 endef
295
296 define Image/Manifest
297 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
298 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
299 endef
300
301 ifdef CONFIG_TARGET_ROOTFS_TARGZ
302 define Image/Build/targz
303 $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
304 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
305 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
306 endef
307 endif
308
309 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
310 define Image/Build/cpiogz
311 ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
312 endef
313 endif
314
315 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
316 mkfs_packages_add = $(foreach pkg,$(filter-out -%,$(mkfs_packages)),$(pkg)$(call GetABISuffix,$(pkg)))
317 mkfs_packages_remove = $(foreach pkg,$(patsubst -%,%,$(filter -%,$(mkfs_packages))),$(pkg)$(call GetABISuffix,$(pkg)))
318 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
319
320 opkg_target = \
321 $(call opkg,$(mkfs_cur_target_dir)) \
322 -f $(mkfs_cur_target_dir).conf
323
324 target-dir-%: FORCE
325 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
326 $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
327 -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
328 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
329 $(if $(mkfs_packages_remove), \
330 -$(call opkg,$(mkfs_cur_target_dir)) remove \
331 $(mkfs_packages_remove))
332 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
333 $(opkg_target) update && \
334 $(opkg_target) install \
335 $(call opkg_package_files,$(mkfs_packages_add)))
336 -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
337 rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
338 $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
339
340 $(KDIR)/root.%: kernel_prepare
341 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
342
343 define Device/InitProfile
344 PROFILES := $(PROFILE)
345 DEVICE_TITLE :=
346 DEVICE_PACKAGES :=
347 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
348 endef
349
350 define Device/Init
351 DEVICE_NAME := $(1)
352 KERNEL:=
353 KERNEL_INITRAMFS = $$(KERNEL)
354 KERNEL_SIZE:=
355 CMDLINE:=
356
357 IMAGES :=
358 ARTIFACTS :=
359 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
360 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
361 KERNEL_PREFIX = $$(IMAGE_PREFIX)
362 KERNEL_SUFFIX := -kernel.bin
363 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
364 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
365 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
366 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
367 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
368 KERNEL_INSTALL :=
369 KERNEL_NAME := vmlinux
370 KERNEL_DEPENDS :=
371 KERNEL_SIZE :=
372
373 UBOOTENV_IN_UBI :=
374 KERNEL_IN_UBI :=
375 BLOCKSIZE :=
376 PAGESIZE :=
377 SUBPAGESIZE :=
378 VID_HDR_OFFSET :=
379 UBINIZE_OPTS :=
380 UBINIZE_PARTS :=
381 MKUBIFS_OPTS :=
382
383 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
384
385 DEVICE_DTS :=
386 DEVICE_DTS_CONFIG :=
387 DEVICE_DTS_DIR :=
388
389 BOARD_NAME :=
390 UIMAGE_NAME :=
391 SUPPORTED_DEVICES :=
392 IMAGE_METADATA :=
393
394 FILESYSTEMS := $(TARGET_FILESYSTEMS)
395
396 UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-$(1)
397 endef
398
399 DEFAULT_DEVICE_VARS := \
400 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
401 CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
402 VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
403 DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME UIMAGE_NAME SUPPORTED_DEVICES \
404 IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR UBOOT_PATH
405
406 define Device/ExportVar
407 $(1) : $(2):=$$($(2))
408
409 endef
410 define Device/Export
411 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
412 $(1) : FILESYSTEM:=$(2)
413 endef
414
415 ifdef IB
416 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
417 else
418 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
419 endif
420
421 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
422
423 define merge_packages
424 $(1) :=
425 $(foreach pkg,$(2),
426 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
427 )
428 endef
429
430 define Device/Check/Common
431 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
432 DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
433 ifdef TARGET_PER_DEVICE_ROOTFS
434 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
435 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
436 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
437 endif
438 endef
439
440 define Device/Check
441 $(Device/Check/Common)
442 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
443 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
444 ifndef IB
445 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
446 endif
447 endef
448
449 ifndef IB
450 define Device/Build/initramfs
451 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
452 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
453
454 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
455 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
456 cp $$^ $$@
457
458 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
459 @rm -f $$@
460 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
461 endef
462 endif
463
464 define Device/Build/compile
465 $$(_COMPILE_TARGET): $(KDIR)/$(1)
466 $(eval $(call Device/Export,$(KDIR)/$(1)))
467 $(KDIR)/$(1):
468 $$(call concat_cmd,$(COMPILE/$(1)))
469
470 endef
471
472 ifndef IB
473 define Device/Build/dtb
474 ifndef BUILD_DTS_$(1)
475 BUILD_DTS_$(1) := 1
476 $(KDIR)/image-$(1).dtb: FORCE
477 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
478
479 image_prepare: $(KDIR)/image-$(1).dtb
480 endif
481
482 endef
483 endif
484
485 define Device/Build/kernel
486 $$(eval $$(foreach dts,$$(DEVICE_DTS), \
487 $$(call Device/Build/dtb,$$(notdir $$(dts)), \
488 $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
489 $$(dts) \
490 ) \
491 ))
492
493 $(KDIR)/$$(KERNEL_NAME):: image_prepare
494 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
495 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
496 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
497 cp $$^ $$@
498 ifndef IB
499 ifdef CONFIG_IB
500 install: $$(KDIR_KERNEL_IMAGE)
501 endif
502 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
503 @rm -f $$@
504 $$(call concat_cmd,$$(KERNEL))
505 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
506 endif
507 endef
508
509 define Device/Build/image
510 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
511 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
512 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
513 ROOTFS/$(1)/$(3) := \
514 $(KDIR)/root.$(1)$$(strip \
515 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
516 )$$(strip \
517 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
518 )
519 ifndef IB
520 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
521 endif
522 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
523 @rm -f $$@
524 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
525 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
526
527 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
528
529 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
530 gzip -c -9n $$^ > $$@
531
532 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
533 cp $$^ $$@
534
535 endef
536
537 define Device/Build/artifact
538 $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
539 $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
540 $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
541 @rm -f $$@
542 $$(call concat_cmd,$(ARTIFACT/$(1)))
543
544 .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
545
546 $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
547 cp $$^ $$@
548
549 endef
550
551 define Device/Build
552 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
553 $(call Device/Build/kernel,$(1))
554
555 $$(eval $$(foreach compile,$$(COMPILE), \
556 $$(call Device/Build/compile,$$(compile),$(1))))
557
558 $$(eval $$(foreach image,$$(IMAGES), \
559 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
560 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
561
562 $$(eval $$(foreach artifact,$$(ARTIFACTS), \
563 $$(call Device/Build/artifact,$$(artifact))))
564
565 endef
566
567 define Device/DumpInfo
568 Target-Profile: DEVICE_$(1)
569 Target-Profile-Name: $(DEVICE_TITLE)
570 Target-Profile-Packages: $(DEVICE_PACKAGES)
571 Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
572 Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
573 Target-Profile-Description:
574 $(DEVICE_DESCRIPTION)
575 @@
576
577 endef
578
579 define Device/Dump
580 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
581 endef
582
583 define Device
584 $(call Device/InitProfile,$(1))
585 $(call Device/Init,$(1))
586 $(call Device/Default,$(1))
587 $(call Device/$(1),$(1))
588 $(call Device/Check,$(1))
589 $(call Device/$(if $(DUMP),Dump,Build),$(1))
590
591 endef
592
593 define BuildImage
594
595 ifneq ($(DUMP),)
596 all: dumpinfo
597 dumpinfo: FORCE
598 @true
599 endif
600
601 download:
602 prepare:
603 compile:
604 clean:
605 legacy-images-prepare:
606 legacy-images:
607 image_prepare:
608
609 ifeq ($(IB),)
610 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
611 compile:
612 $(call Build/Compile)
613
614 clean:
615 $(call Build/Clean)
616
617 image_prepare: compile
618 mkdir -p $(BIN_DIR) $(KDIR)/tmp
619 $(call Image/Prepare)
620
621 legacy-images-prepare-make: image_prepare
622 $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
623
624 else
625 image_prepare:
626 mkdir -p $(BIN_DIR) $(KDIR)/tmp
627 endif
628
629 kernel_prepare: image_prepare
630 $(call Image/Build/targz)
631 $(call Image/Build/cpiogz)
632 $(call Image/BuildKernel)
633 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
634 $(call Image/InstallKernel)
635
636 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
637 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
638
639 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
640 $(foreach fs,$(TARGET_FILESYSTEMS),
641 $(call Image/Build,$(fs))
642 )
643
644 legacy-images-make: install-images
645 $(call Image/mkfs/ubifs/legacy)
646 $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
647
648 install: install-images
649 $(call Image/Manifest)
650
651 endef