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