build: download code from github using archive API
[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 include $(INCLUDE_DIR)/feeds.mk
22 include $(INCLUDE_DIR)/rootfs.mk
23
24 override MAKE:=$(_SINGLE)$(SUBMAKE)
25 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
26
27 target_params = $(subst +,$(space),$*)
28 param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
29 param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))
30 param_mangle = $(subst $(space),_,$(strip $(1)))
31 param_unmangle = $(subst _,$(space),$(1))
32
33 mkfs_packages_id = $(shell echo $(sort $(1)) | mkhash md5 | head -c 8)
34 mkfs_target_dir = $(if $(call param_get,pkg,$(1)),$(KDIR)/target-dir-$(call param_get,pkg,$(1)),$(TARGET_DIR))
35
36 KDIR=$(KERNEL_BUILD_DIR)
37 KDIR_TMP=$(KDIR)/tmp
38 DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
39
40 IMG_PREFIX_EXTRA:=$(if $(EXTRA_IMAGE_NAME),$(call sanitize,$(EXTRA_IMAGE_NAME))-)
41 IMG_PREFIX_VERNUM:=$(if $(CONFIG_VERSION_FILENAMES),$(call sanitize,$(VERSION_NUMBER))-)
42 IMG_PREFIX_VERCODE:=$(if $(CONFIG_VERSION_CODE_FILENAMES),$(call sanitize,$(VERSION_CODE))-)
43
44 IMG_PREFIX:=$(VERSION_DIST_SANITIZED)-$(IMG_PREFIX_VERNUM)$(IMG_PREFIX_VERCODE)$(IMG_PREFIX_EXTRA)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
45
46 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
47
48 ifneq ($(CONFIG_BIG_ENDIAN),)
49 JFFS2OPTS := --big-endian --squash-uids -v
50 else
51 JFFS2OPTS := --little-endian --squash-uids -v
52 endif
53
54 ifeq ($(CONFIG_JFFS2_RTIME),y)
55 JFFS2OPTS += -X rtime
56 endif
57 ifeq ($(CONFIG_JFFS2_ZLIB),y)
58 JFFS2OPTS += -X zlib
59 endif
60 ifeq ($(CONFIG_JFFS2_LZMA),y)
61 JFFS2OPTS += -X lzma --compression-mode=size
62 endif
63 ifneq ($(CONFIG_JFFS2_RTIME),y)
64 JFFS2OPTS += -x rtime
65 endif
66 ifneq ($(CONFIG_JFFS2_ZLIB),y)
67 JFFS2OPTS += -x zlib
68 endif
69 ifneq ($(CONFIG_JFFS2_LZMA),y)
70 JFFS2OPTS += -x lzma
71 endif
72
73 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
74
75 SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
76 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
77 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
78 SQUASHFSCOMP := gzip
79 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
80 ifeq ($(CONFIG_SQUASHFS_XZ),y)
81 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
82 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
83 endif
84 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
85 endif
86
87 JFFS2_BLOCKSIZE ?= 64k 128k
88
89 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
90 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
91 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
92 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
93 fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
94 fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
95 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
96
97 TARGET_FILESYSTEMS := $(fs-types-y)
98
99 FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
100 FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
101 FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
102
103 define add_jffs2_mark
104 echo -ne '\xde\xad\xc0\xde' >> $(1)
105 endef
106
107 PROFILE_SANITIZED := $(call sanitize,$(PROFILE))
108
109 define split_args
110 $(foreach data, \
111 $(subst |,$(space),\
112 $(subst $(space),^,$(1))), \
113 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
114 endef
115
116 define build_cmd
117 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
118 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
119
120 endef
121
122 define concat_cmd
123 $(call split_args,$(1),build_cmd)
124 endef
125
126 # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
127 define prepare_generic_squashfs
128 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
129 endef
130
131 define Image/BuildKernel/Initramfs
132 $(call Image/Build/Initramfs)
133 endef
134
135 define Image/BuildKernel/MkuImage
136 mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
137 -n '$(call toupper,$(ARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' -d $(4) $(5)
138 endef
139
140 define Image/BuildKernel/MkFIT
141 $(TOPDIR)/scripts/mkits.sh \
142 -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
143 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
144 -A $(LINUX_KARCH) -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 ifdef CONFIG_TARGET_IMAGES_GZIP
149 define Image/Gzip
150 rm -f $(1).gz
151 gzip -9n $(1)
152 endef
153 endif
154
155 # $(1) source dts file
156 # $(2) target dtb file
157 # $(3) extra CPP flags
158 # $(4) extra DTC flags
159 define Image/BuildDTB
160 $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
161 -I$(DTS_DIR) \
162 -I$(DTS_DIR)/include \
163 -I$(LINUX_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 # $(4): compat string
214 ifneq ($(CONFIG_NAND_SUPPORT),)
215 define Image/Build/SysupgradeNAND
216 mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
217 echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
218 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
219 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
220 (cd "$(KDIR_TMP)"; $(TAR) cvf \
221 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
222 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
223 )
224 endef
225
226 # $(1) board name
227 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
228 # $(3) rootfstype (e.g. squashfs or ubifs)
229 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
230 define Image/Build/UbinizeImage
231 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
232 "$(KDIR)/root.$(3)" \
233 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
234 $(4)
235 endef
236
237 endif
238
239 define Image/mkfs/ubifs
240 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
241 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
242 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
243 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
244 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
245 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
246 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
247 --squash-uids \
248 -o $@ -d $(call mkfs_target_dir,$(1))
249 endef
250
251 E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
252
253 define Image/mkfs/ext4
254 $(STAGING_DIR_HOST)/bin/make_ext4fs \
255 -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
256 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
257 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
258 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
259 $@ $(call mkfs_target_dir,$(1))/
260 endef
261
262 define Image/Manifest
263 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
264 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
265 endef
266
267 ifdef CONFIG_TARGET_ROOTFS_TARGZ
268 define Image/Build/targz
269 $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
270 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
271 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
272 endef
273 endif
274
275 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
276 define Image/Build/cpiogz
277 ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
278 endef
279 endif
280
281 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
282 mkfs_packages_add = $(filter-out -%,$(mkfs_packages))
283 mkfs_packages_remove = $(patsubst -%,%,$(filter -%,$(mkfs_packages)))
284 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
285
286 opkg_target = \
287 $(call opkg,$(mkfs_cur_target_dir)) \
288 -f $(mkfs_cur_target_dir).conf
289
290 target-dir-%: FORCE
291 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
292 $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
293 -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
294 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
295 $(if $(mkfs_packages_remove), \
296 -$(call opkg,$(mkfs_cur_target_dir)) remove \
297 $(mkfs_packages_remove))
298 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
299 $(opkg_target) update && \
300 $(opkg_target) install \
301 $(call opkg_package_files,$(mkfs_packages_add)))
302 -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
303 rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
304 $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
305
306 $(KDIR)/root.%: kernel_prepare
307 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
308
309 define Device/InitProfile
310 PROFILES := $(PROFILE)
311 DEVICE_TITLE :=
312 DEVICE_PACKAGES :=
313 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
314 endef
315
316 define Device/Init
317 DEVICE_NAME := $(1)
318 KERNEL:=
319 KERNEL_INITRAMFS = $$(KERNEL)
320 KERNEL_SIZE:=
321 CMDLINE:=
322
323 IMAGES :=
324 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
325 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
326 KERNEL_PREFIX = $$(IMAGE_PREFIX)
327 KERNEL_SUFFIX := -kernel.bin
328 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
329 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
330 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
331 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
332 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
333 KERNEL_INSTALL :=
334 KERNEL_NAME := vmlinux
335 KERNEL_DEPENDS :=
336 KERNEL_SIZE :=
337
338 UBOOTENV_IN_UBI :=
339 KERNEL_IN_UBI :=
340 BLOCKSIZE :=
341 PAGESIZE :=
342 SUBPAGESIZE :=
343 VID_HDR_OFFSET :=
344 UBINIZE_OPTS :=
345 UBINIZE_PARTS :=
346 MKUBIFS_OPTS :=
347
348 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
349
350 DEVICE_DTS :=
351 DEVICE_DTS_CONFIG :=
352 DEVICE_DTS_DIR :=
353
354 BOARD_NAME :=
355 UIMAGE_NAME :=
356 SUPPORTED_DEVICES :=
357 IMAGE_METADATA :=
358
359 FILESYSTEMS := $(TARGET_FILESYSTEMS)
360 endef
361
362 DEFAULT_DEVICE_VARS := \
363 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_SIZE KERNEL_INITRAMFS_IMAGE \
364 KERNEL_LOADADDR DEVICE_DTS DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME \
365 CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI \
366 BLOCKSIZE PAGESIZE SUBPAGESIZE VID_HDR_OFFSET \
367 UBINIZE_OPTS UIMAGE_NAME UBINIZE_PARTS \
368 SUPPORTED_DEVICES IMAGE_METADATA
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 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
386
387 define merge_packages
388 $(1) :=
389 $(foreach pkg,$(2),
390 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
391 )
392 endef
393
394 define Device/Check/Common
395 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
396 ifdef TARGET_PER_DEVICE_ROOTFS
397 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
398 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
399 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
400 endif
401 endef
402
403 define Device/Check
404 $(Device/Check/Common)
405 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
406 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
407 ifndef IB
408 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
409 endif
410 endef
411
412 ifndef IB
413 define Device/Build/initramfs
414 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
415 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
416
417 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
418 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
419 cp $$^ $$@
420
421 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
422 @rm -f $$@
423 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
424 endef
425 endif
426
427 define Device/Build/compile
428 $$(_COMPILE_TARGET): $(KDIR)/$(1)
429 $(eval $(call Device/Export,$(KDIR)/$(1)))
430 $(KDIR)/$(1):
431 $$(call concat_cmd,$(COMPILE/$(1)))
432
433 endef
434
435 ifndef IB
436 define Device/Build/dtb
437 ifndef BUILD_DTS_$(1)
438 BUILD_DTS_$(1) := 1
439 $(KDIR)/image-$(1).dtb: FORCE
440 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
441
442 image_prepare: $(KDIR)/image-$(1).dtb
443 endif
444
445 endef
446 endif
447
448 define Device/Build/kernel
449 $$(eval $$(foreach dts,$$(DEVICE_DTS), \
450 $$(call Device/Build/dtb,$$(notdir $$(dts)), \
451 $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
452 $$(dts) \
453 ) \
454 ))
455
456 $(KDIR)/$$(KERNEL_NAME):: image_prepare
457 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
458 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
459 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
460 cp $$^ $$@
461 ifndef IB
462 ifdef CONFIG_IB
463 install: $$(KDIR_KERNEL_IMAGE)
464 endif
465 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
466 @rm -f $$@
467 $$(call concat_cmd,$$(KERNEL))
468 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
469 endif
470 endef
471
472 define Device/Build/image
473 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
474 $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
475 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
476 ROOTFS/$(1)/$(3) := \
477 $(KDIR)/root.$(1)$$(strip \
478 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
479 )$$(strip \
480 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
481 )
482 ifndef IB
483 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
484 endif
485 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
486 @rm -f $$@
487 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
488 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
489
490 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
491
492 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
493 gzip -c -9n $$^ > $$@
494
495 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
496 cp $$^ $$@
497
498 endef
499
500 define Device/Build
501 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
502 $(call Device/Build/kernel,$(1))
503
504 $$(eval $$(foreach compile,$$(COMPILE), \
505 $$(call Device/Build/compile,$$(compile),$(1))))
506
507 $$(eval $$(foreach image,$$(IMAGES), \
508 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
509 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
510 endef
511
512 define Device/DumpInfo
513 Target-Profile: DEVICE_$(1)
514 Target-Profile-Name: $(DEVICE_TITLE)
515 Target-Profile-Packages: $(DEVICE_PACKAGES)
516 Target-Profile-Description:
517 $(DEVICE_DESCRIPTION)
518 @@
519
520 endef
521
522 define Device/Dump
523 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
524 endef
525
526 define Device
527 $(call Device/InitProfile,$(1))
528 $(call Device/Init,$(1))
529 $(call Device/Default,$(1))
530 $(call Device/$(1),$(1))
531 $(call Device/Check,$(1))
532 $(call Device/$(if $(DUMP),Dump,Build),$(1))
533
534 endef
535
536 define BuildImage
537
538 ifneq ($(DUMP),)
539 all: dumpinfo
540 dumpinfo: FORCE
541 @true
542 endif
543
544 download:
545 prepare:
546 compile:
547 clean:
548 legacy-images-prepare:
549 legacy-images:
550 image_prepare:
551
552 ifeq ($(IB),)
553 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
554 compile:
555 $(call Build/Compile)
556
557 clean:
558 $(call Build/Clean)
559
560 image_prepare: compile
561 mkdir -p $(BIN_DIR) $(KDIR)/tmp
562 $(call Image/Prepare)
563
564 legacy-images-prepare-make: image_prepare
565 $(MAKE) legacy-images-prepare
566
567 else
568 image_prepare:
569 mkdir -p $(BIN_DIR) $(KDIR)/tmp
570 endif
571
572 kernel_prepare: image_prepare
573 $(call Image/Build/targz)
574 $(call Image/Build/cpiogz)
575 $(call Image/BuildKernel)
576 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
577 $(call Image/InstallKernel)
578
579 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
580 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
581
582 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
583 $(foreach fs,$(TARGET_FILESYSTEMS),
584 $(call Image/Build,$(fs))
585 )
586
587 legacy-images-make: install-images
588 $(call Image/mkfs/ubifs/legacy)
589 $(MAKE) legacy-images
590
591 install: install-images
592 $(call Image/Manifest)
593
594 endef