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