ramips: rename PSG1218 to match label
[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 ifneq ($(CONFIG_NAND_SUPPORT),)
214 define Image/Build/SysupgradeNAND
215 mkdir -p "$(KDIR_TMP)/sysupgrade-$(1)/"
216 echo "BOARD=$(1)" > "$(KDIR_TMP)/sysupgrade-$(1)/CONTROL"
217 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(1)/root"
218 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(1)/kernel"
219 (cd "$(KDIR_TMP)"; $(TAR) cvf \
220 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(1) \
221 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
222 )
223 endef
224
225 # $(1) board name
226 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
227 # $(3) rootfstype (e.g. squashfs or ubifs)
228 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
229 define Image/Build/UbinizeImage
230 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
231 "$(KDIR)/root.$(3)" \
232 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
233 $(4)
234 endef
235
236 endif
237
238 define Image/mkfs/ubifs
239 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
240 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
241 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
242 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
243 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
244 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
245 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
246 --squash-uids \
247 -o $@ -d $(call mkfs_target_dir,$(1))
248 endef
249
250 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
251
252 define Image/mkfs/ext4
253 $(STAGING_DIR_HOST)/bin/make_ext4fs \
254 -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
255 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
256 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
257 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
258 $@ $(call mkfs_target_dir,$(1))/
259 endef
260
261 define Image/Manifest
262 $(STAGING_DIR_HOST)/bin/opkg \
263 --offline-root $(TARGET_DIR) \
264 --add-arch all:100 \
265 --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200 list-installed > \
266 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
267 endef
268
269 ifdef CONFIG_TARGET_ROOTFS_TARGZ
270 define Image/Build/targz
271 $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
272 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
273 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
274 endef
275 endif
276
277 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
278 define Image/Build/cpiogz
279 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
280 endef
281 endif
282
283 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
284 mkfs_packages_add = $(filter-out -%,$(mkfs_packages))
285 mkfs_packages_remove = $(patsubst -%,%,$(filter -%,$(mkfs_packages)))
286 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
287
288 opkg_target = \
289 $(call opkg,$(mkfs_cur_target_dir)) \
290 -f $(mkfs_cur_target_dir).conf
291
292 target-dir-%: FORCE
293 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
294 $(CP) $(TARGET_DIR_ORIG) $(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 $(mkfs_packages_remove), \
298 -$(call opkg,$(mkfs_cur_target_dir)) remove \
299 $(mkfs_packages_remove))
300 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
301 $(opkg_target) update && \
302 $(opkg_target) install \
303 $(call opkg_package_files,$(mkfs_packages_add)))
304 $(call prepare_rootfs,$(mkfs_cur_target_dir))
305 -mv $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir)/etc/opkg
306 rm -f $(mkfs_cur_target_dir).conf
307
308 $(KDIR)/root.%: kernel_prepare
309 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
310
311 define Device/InitProfile
312 PROFILES := $(PROFILE)
313 DEVICE_TITLE :=
314 DEVICE_PACKAGES :=
315 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
316 endef
317
318 define Device/Init
319 DEVICE_NAME := $(1)
320 KERNEL:=
321 KERNEL_INITRAMFS = $$(KERNEL)
322 KERNEL_SIZE:=
323 CMDLINE:=
324
325 IMAGES :=
326 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
327 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
328 KERNEL_PREFIX = $$(IMAGE_PREFIX)
329 KERNEL_SUFFIX := -kernel.bin
330 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
331 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
332 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
333 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
334 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
335 KERNEL_INSTALL :=
336 KERNEL_NAME := vmlinux
337 KERNEL_DEPENDS :=
338 KERNEL_SIZE :=
339
340 UBOOTENV_IN_UBI :=
341 KERNEL_IN_UBI :=
342 BLOCKSIZE :=
343 PAGESIZE :=
344 SUBPAGESIZE :=
345 VID_HDR_OFFSET :=
346 UBINIZE_OPTS :=
347 UBINIZE_PARTS :=
348 MKUBIFS_OPTS :=
349
350 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
351
352 DEVICE_DTS :=
353 DEVICE_DTS_DIR :=
354
355 BOARD_NAME :=
356 UIMAGE_NAME :=
357 SUPPORTED_DEVICES :=
358 IMAGE_METADATA :=
359
360 FILESYSTEMS := $(TARGET_FILESYSTEMS)
361 endef
362
363 DEFAULT_DEVICE_VARS := \
364 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_SIZE KERNEL_INITRAMFS_IMAGE \
365 KERNEL_LOADADDR 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 UBINIZE_PARTS \
369 SUPPORTED_DEVICES IMAGE_METADATA
370
371 define Device/ExportVar
372 $(1) : $(2):=$$($(2))
373
374 endef
375 define Device/Export
376 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
377 $(1) : FILESYSTEM:=$(2)
378 endef
379
380 ifdef IB
381 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
382 else
383 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
384 endif
385
386 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
387
388 define merge_packages
389 $(1) :=
390 $(foreach pkg,$(2),
391 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
392 )
393 endef
394
395 define Device/Check/Common
396 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
397 ifdef TARGET_PER_DEVICE_ROOTFS
398 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
399 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
400 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
401 endif
402 endef
403
404 define Device/Check
405 $(Device/Check/Common)
406 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
407 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
408 ifndef IB
409 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
410 endif
411 endef
412
413 ifndef IB
414 define Device/Build/initramfs
415 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
416 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
417
418 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
419 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
420 cp $$^ $$@
421
422 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
423 @rm -f $$@
424 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
425 endef
426 endif
427
428 define Device/Build/compile
429 $$(_COMPILE_TARGET): $(KDIR)/$(1)
430 $(eval $(call Device/Export,$(KDIR)/$(1)))
431 $(KDIR)/$(1):
432 $$(call concat_cmd,$(COMPILE/$(1)))
433
434 endef
435
436 define Device/Build/kernel
437 $(KDIR)/$$(KERNEL_NAME):: image_prepare
438 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
439 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
440 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
441 cp $$^ $$@
442 ifndef IB
443 ifdef CONFIG_IB
444 install: $$(KDIR_KERNEL_IMAGE)
445 endif
446 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
447 @rm -f $$@
448 $$(call concat_cmd,$$(KERNEL))
449 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
450 endif
451 endef
452
453 define Device/Build/image
454 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
455 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
456 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
457 ROOTFS/$(1)/$(3) := \
458 $(KDIR)/root.$(1)$$(strip \
459 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
460 )$$(strip \
461 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
462 )
463 ifndef IB
464 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
465 endif
466 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
467 @rm -f $$@
468 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
469 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
470
471 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
472
473 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
474 gzip -c -9n $$^ > $$@
475
476 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
477 cp $$^ $$@
478
479 endef
480
481 define Device/Build
482 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
483 $(call Device/Build/kernel,$(1))
484
485 $$(eval $$(foreach compile,$$(COMPILE), \
486 $$(call Device/Build/compile,$$(compile),$(1))))
487
488 $$(eval $$(foreach image,$$(IMAGES), \
489 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
490 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
491 endef
492
493 define Device/DumpInfo
494 Target-Profile: DEVICE_$(1)
495 Target-Profile-Name: $(DEVICE_TITLE)
496 Target-Profile-Packages: $(DEVICE_PACKAGES)
497 Target-Profile-Description:
498 $(DEVICE_DESCRIPTION)
499 @@
500
501 endef
502
503 define Device/Dump
504 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
505 endef
506
507 define Device
508 $(call Device/InitProfile,$(1))
509 $(call Device/Init,$(1))
510 $(call Device/Default,$(1))
511 $(call Device/$(1),$(1))
512 $(call Device/Check,$(1))
513 $(call Device/$(if $(DUMP),Dump,Build),$(1))
514
515 endef
516
517 define BuildImage
518
519 ifneq ($(DUMP),)
520 all: dumpinfo
521 dumpinfo: FORCE
522 @true
523 endif
524
525 download:
526 prepare:
527 compile:
528 clean:
529 legacy-images-prepare:
530 legacy-images:
531 image_prepare:
532
533 ifeq ($(IB),)
534 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
535 compile:
536 $(call Build/Compile)
537
538 clean:
539 $(call Build/Clean)
540
541 image_prepare: compile
542 mkdir -p $(BIN_DIR) $(KDIR)/tmp
543 $(call Image/Prepare)
544
545 legacy-images-prepare-make: image_prepare
546 $(MAKE) legacy-images-prepare
547
548 else
549 image_prepare:
550 mkdir -p $(BIN_DIR) $(KDIR)/tmp
551 endif
552
553 kernel_prepare: image_prepare
554 $(call Image/Build/targz)
555 $(call Image/Build/cpiogz)
556 $(call Image/BuildKernel)
557 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
558 $(call Image/InstallKernel)
559
560 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
561 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
562
563 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
564 $(foreach fs,$(TARGET_FILESYSTEMS),
565 $(call Image/Build,$(fs))
566 )
567
568 legacy-images-make: install-images
569 $(call Image/mkfs/ubifs/legacy)
570 $(MAKE) legacy-images
571
572 install: install-images
573 $(call Image/Manifest)
574
575 endef