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