261f0f8aeaa1e88d8e5c9aad6a8f673ff1d6a79f
[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)/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 -l $(mkfs_cur_target_dir).tmp
298
299 target-dir-%: FORCE
300 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
301 $(CP) $(TARGET_DIR) $(mkfs_cur_target_dir)
302 mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
303 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
304 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
305 $(opkg_target) update && \
306 $(opkg_target) install \
307 $(call opkg_package_files,$(mkfs_packages_add)))
308 $(if $(mkfs_packages_remove), \
309 $(call opkg,$(mkfs_cur_target_dir)) remove \
310 $(mkfs_packages_remove))
311 $(call Image/mkfs/prepare,$(mkfs_cur_target_dir))
312 $(call prepare_rootfs,$(mkfs_cur_target_dir))
313 mv $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir)/etc/opkg
314 rm -rf \
315 $(mkfs_cur_target_dir).conf \
316 $(mkfs_cur_target_dir).tmp
317
318 $(KDIR)/root.%: kernel_prepare
319 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
320
321 define Device/InitProfile
322 PROFILES := $(PROFILE)
323 DEVICE_TITLE :=
324 DEVICE_PACKAGES :=
325 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
326 endef
327
328 define Device/Init
329 DEVICE_NAME := $(1)
330 KERNEL:=
331 KERNEL_INITRAMFS = $$(KERNEL)
332 KERNEL_SIZE:=
333 CMDLINE:=
334
335 IMAGES :=
336 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
337 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
338 KERNEL_PREFIX = $$(IMAGE_PREFIX)
339 KERNEL_SUFFIX := -kernel.bin
340 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
341 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
342 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
343 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
344 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
345 KERNEL_INSTALL :=
346 KERNEL_NAME := vmlinux
347 KERNEL_DEPENDS :=
348 KERNEL_SIZE :=
349
350 UBOOTENV_IN_UBI :=
351 KERNEL_IN_UBI :=
352 BLOCKSIZE :=
353 PAGESIZE :=
354 SUBPAGESIZE :=
355 VID_HDR_OFFSET :=
356 UBINIZE_OPTS :=
357 UBINIZE_PARTS :=
358 MKUBIFS_OPTS :=
359
360 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
361
362 DEVICE_DTS :=
363 DEVICE_DTS_DIR :=
364
365 BOARD_NAME :=
366 UIMAGE_NAME :=
367
368 FILESYSTEMS := $(TARGET_FILESYSTEMS)
369 endef
370
371 DEFAULT_DEVICE_VARS := \
372 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_SIZE KERNEL_INITRAMFS_IMAGE \
373 DEVICE_DTS DEVICE_DTS_DIR BOARD_NAME CMDLINE \
374 UBOOTENV_IN_UBI KERNEL_IN_UBI \
375 BLOCKSIZE PAGESIZE SUBPAGESIZE VID_HDR_OFFSET \
376 UBINIZE_OPTS UIMAGE_NAME UBINIZE_PARTS
377
378 define Device/ExportVar
379 $(1) : $(2):=$$($(2))
380
381 endef
382 define Device/Export
383 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
384 $(1) : FILESYSTEM:=$(2)
385 endef
386
387 ifdef IB
388 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
389 else
390 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
391 endif
392
393 define Device/Check/Common
394 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
395 ifdef TARGET_PER_DEVICE_ROOTFS
396 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(DEVICE_PACKAGES)))
397 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(DEVICE_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)
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 define Device/Build/kernel
434 $(KDIR)/$$(KERNEL_NAME):: image_prepare
435 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
436 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
437 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
438 cp $$^ $$@
439 ifndef IB
440 ifdef CONFIG_IB
441 install: $$(KDIR_KERNEL_IMAGE)
442 endif
443 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
444 @rm -f $$@
445 $$(call concat_cmd,$$(KERNEL))
446 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
447 endif
448 endef
449
450 define Device/Build/image
451 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
452 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
453 ROOTFS/$(1)/$(3) := \
454 $(KDIR)/root.$(1)$$(strip \
455 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
456 )$$(strip \
457 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
458 )
459 ifndef IB
460 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
461 endif
462 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
463 @rm -f $$@
464 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
465 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
466
467 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
468 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
469 cp $$^ $$@
470
471 endef
472
473 define Device/Build
474 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
475 $(call Device/Build/kernel,$(1))
476
477 $$(eval $$(foreach compile,$$(COMPILE), \
478 $$(call Device/Build/compile,$$(compile),$(1))))
479
480 $$(eval $$(foreach image,$$(IMAGES), \
481 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
482 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
483 endef
484
485 define Device/DumpInfo
486 Target-Profile: DEVICE_$(1)
487 Target-Profile-Name: $(DEVICE_TITLE)
488 Target-Profile-Packages: $(DEVICE_PACKAGES)
489 Target-Profile-Description:
490 $(DEVICE_DESCRIPTION)
491 @@
492
493 endef
494
495 define Device/Dump
496 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
497 endef
498
499 define Device
500 $(call Device/InitProfile,$(1))
501 $(call Device/Init,$(1))
502 $(call Device/Default,$(1))
503 $(call Device/$(1),$(1))
504 $(call Device/Check,$(1))
505 $(call Device/$(if $(DUMP),Dump,Build),$(1))
506
507 endef
508
509 define BuildImage
510
511 ifneq ($(DUMP),)
512 all: dumpinfo
513 dumpinfo: FORCE
514 @true
515 endif
516
517 download:
518 prepare:
519 compile:
520 clean:
521 legacy-images-prepare:
522 legacy-images:
523 image_prepare:
524
525 ifeq ($(IB),)
526 .PHONY: download prepare compile clean image_prepare mkfs_prepare kernel_prepare install install-images
527 compile:
528 $(call Build/Compile)
529
530 clean:
531 $(call Build/Clean)
532
533 image_prepare: compile
534 mkdir -p $(BIN_DIR) $(KDIR)/tmp
535 $(call Image/Prepare)
536
537 legacy-images-prepare-make: image_prepare
538 $(MAKE) legacy-images-prepare
539
540 else
541 image_prepare:
542 mkdir -p $(BIN_DIR) $(KDIR)/tmp
543 endif
544
545 mkfs_prepare: image_prepare
546 $(call Image/mkfs/prepare,$(TARGET_DIR))
547
548 kernel_prepare: mkfs_prepare
549 $(call Image/Build/targz)
550 $(call Image/Build/cpiogz)
551 $(call Image/BuildKernel)
552 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
553 $(call Image/InstallKernel)
554
555 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
556 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
557
558 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
559 $(foreach fs,$(TARGET_FILESYSTEMS),
560 $(call Image/Build,$(fs))
561 )
562
563 legacy-images-make: install-images
564 $(call Image/mkfs/ubifs/legacy)
565 $(MAKE) legacy-images
566
567 install: install-images
568 $(call Image/Manifest)
569
570 endef