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