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