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