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