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