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