include: remove 34k distinction
[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
268 ifdef CONFIG_TARGET_ROOTFS_TARGZ
269 define Image/Build/targz
270 $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
271 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
272 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
273 endef
274 endif
275
276 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
277 define Image/Build/cpiogz
278 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
279 endef
280 endif
281
282 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
283 mkfs_packages_add = $(filter-out -%,$(mkfs_packages))
284 mkfs_packages_remove = $(patsubst -%,%,$(filter -%,$(mkfs_packages)))
285 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
286
287 opkg_target = \
288 $(call opkg,$(mkfs_cur_target_dir)) \
289 -f $(mkfs_cur_target_dir).conf \
290 -l $(mkfs_cur_target_dir).tmp
291
292 target-dir-%: FORCE
293 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
294 $(CP) $(TARGET_DIR) $(mkfs_cur_target_dir)
295 mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
296 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
297 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
298 $(opkg_target) update && \
299 $(opkg_target) install \
300 $(call opkg_package_files,$(mkfs_packages_add)))
301 $(if $(mkfs_packages_remove), \
302 $(call opkg,$(mkfs_cur_target_dir)) remove \
303 $(mkfs_packages_remove))
304 $(call Image/mkfs/prepare,$(mkfs_cur_target_dir))
305 $(call prepare_rootfs,$(mkfs_cur_target_dir))
306 mv $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir)/etc/opkg
307 rm -rf \
308 $(mkfs_cur_target_dir).conf \
309 $(mkfs_cur_target_dir).tmp
310
311 $(KDIR)/root.%: kernel_prepare
312 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
313
314 define Device/InitProfile
315 PROFILES := $(PROFILE)
316 DEVICE_TITLE :=
317 DEVICE_PACKAGES :=
318 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
319 endef
320
321 define Device/Init
322 DEVICE_NAME := $(1)
323 KERNEL:=
324 KERNEL_INITRAMFS = $$(KERNEL)
325 KERNEL_SIZE:=
326 CMDLINE:=
327
328 IMAGES :=
329 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
330 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
331 KERNEL_PREFIX = $$(IMAGE_PREFIX)
332 KERNEL_SUFFIX := -kernel.bin
333 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
334 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
335 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
336 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
337 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
338 KERNEL_INSTALL :=
339 KERNEL_NAME := vmlinux
340 KERNEL_DEPENDS :=
341 KERNEL_SIZE :=
342
343 UBOOTENV_IN_UBI :=
344 KERNEL_IN_UBI :=
345 BLOCKSIZE :=
346 PAGESIZE :=
347 SUBPAGESIZE :=
348 VID_HDR_OFFSET :=
349 UBINIZE_OPTS := -E 5
350 MKUBIFS_OPTS :=
351
352 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
353
354 DEVICE_DTS :=
355 DEVICE_DTS_DIR :=
356
357 BOARD_NAME :=
358 UIMAGE_NAME :=
359
360 FILESYSTEMS := $(TARGET_FILESYSTEMS)
361 endef
362
363 DEFAULT_DEVICE_VARS := \
364 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE \
365 DEVICE_DTS DEVICE_DTS_DIR BOARD_NAME CMDLINE \
366 UBOOTENV_IN_UBI KERNEL_IN_UBI \
367 BLOCKSIZE PAGESIZE SUBPAGESIZE VID_HDR_OFFSET \
368 UBINIZE_OPTS UIMAGE_NAME
369
370 define Device/ExportVar
371 $(1) : $(2):=$$($(2))
372
373 endef
374 define Device/Export
375 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
376 $(1) : FILESYSTEM:=$(2)
377 endef
378
379 ifdef IB
380 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
381 else
382 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
383 endif
384
385 define Device/Check/Common
386 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
387 ifdef TARGET_PER_DEVICE_ROOTFS
388 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(DEVICE_PACKAGES)))
389 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(DEVICE_PACKAGES)
390 endif
391 endef
392
393 define Device/Check
394 $(Device/Check/Common)
395 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
396 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
397 ifndef IB
398 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
399 endif
400 endef
401
402 ifndef IB
403 define Device/Build/initramfs
404 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
405 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
406
407 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
408 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
409 cp $$^ $$@
410
411 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
412 @rm -f $$@
413 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
414 endef
415 endif
416
417 define Device/Build/check_size
418 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
419 echo "WARNING: Image file $@ is too big" >&2; \
420 rm -f $@; \
421 }
422 endef
423
424 define Device/Build/compile
425 $$(_COMPILE_TARGET): $(KDIR)/$(1)
426 $(eval $(call Device/Export,$(KDIR)/$(1)))
427 $(KDIR)/$(1):
428 $$(call concat_cmd,$(COMPILE/$(1)))
429
430 endef
431
432 define Device/Build/kernel
433 $(KDIR)/$$(KERNEL_NAME):: image_prepare
434 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
435 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
436 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
437 cp $$^ $$@
438 ifndef IB
439 ifdef CONFIG_IB
440 install: $$(KDIR_KERNEL_IMAGE)
441 endif
442 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
443 @rm -f $$@
444 $$(call concat_cmd,$$(KERNEL))
445 $$(if $$(KERNEL_SIZE),$$(call Device/Build/check_size,$$(KERNEL_SIZE)))
446 endif
447 endef
448
449 define Device/Build/image
450 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
451 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
452 ROOTFS/$(1)/$(3) := \
453 $(KDIR)/root.$(1)$$(strip \
454 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
455 )$$(strip \
456 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
457 )
458 ifndef IB
459 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
460 endif
461 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
462 @rm -f $$@
463 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
464 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
465
466 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
467 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
468 cp $$^ $$@
469
470 endef
471
472 define Device/Build
473 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
474 $(call Device/Build/kernel,$(1))
475
476 $$(eval $$(foreach compile,$$(COMPILE), \
477 $$(call Device/Build/compile,$$(compile),$(1))))
478
479 $$(eval $$(foreach image,$$(IMAGES), \
480 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
481 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
482 endef
483
484 define Device/DumpInfo
485 Target-Profile: DEVICE_$(1)
486 Target-Profile-Name: $(DEVICE_TITLE)
487 Target-Profile-Packages: $(DEVICE_PACKAGES)
488 Target-Profile-Description:
489 $(DEVICE_DESCRIPTION)
490 @@
491
492 endef
493
494 define Device/Dump
495 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
496 endef
497
498 define Device
499 $(call Device/InitProfile,$(1))
500 $(call Device/Init,$(1))
501 $(call Device/Default,$(1))
502 $(call Device/$(1),$(1))
503 $(call Device/Check,$(1))
504 $(call Device/$(if $(DUMP),Dump,Build),$(1))
505
506 endef
507
508 define BuildImage
509
510 ifneq ($(DUMP),)
511 all: dumpinfo
512 dumpinfo: FORCE
513 @true
514 endif
515
516 download:
517 prepare:
518 compile:
519 clean:
520 legacy-images-prepare:
521 legacy-images:
522 image_prepare:
523
524 ifeq ($(IB),)
525 .PHONY: download prepare compile clean image_prepare mkfs_prepare kernel_prepare install install-images
526 compile:
527 $(call Build/Compile)
528
529 clean:
530 $(call Build/Clean)
531
532 image_prepare: compile
533 mkdir -p $(BIN_DIR) $(KDIR)/tmp
534 $(call Image/Prepare)
535
536 legacy-images-prepare-make: image_prepare
537 $(MAKE) legacy-images-prepare
538
539 else
540 image_prepare:
541 mkdir -p $(BIN_DIR) $(KDIR)/tmp
542 endif
543
544 mkfs_prepare: image_prepare
545 $(call Image/mkfs/prepare,$(TARGET_DIR))
546
547 kernel_prepare: mkfs_prepare
548 $(call Image/Build/targz)
549 $(call Image/Build/cpiogz)
550 $(call Image/BuildKernel)
551 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
552 $(call Image/InstallKernel)
553
554 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
555 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
556
557 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
558 $(foreach fs,$(TARGET_FILESYSTEMS),
559 $(call Image/Build,$(fs))
560 )
561
562 legacy-images-make: install-images
563 $(call Image/mkfs/ubifs/legacy)
564 $(MAKE) legacy-images
565
566 install: install-images
567
568 endef