f01e160a9d8d7a13eeca58b0864305afdb3b69c9
[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 | cut -b1-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 IMG_ROOTFS:=$(IMG_PREFIX)-rootfs
46 IMG_COMBINED:=$(IMG_PREFIX)-combined
47 IMG_PART_SIGNATURE:=$(shell echo $(SOURCE_DATE_EPOCH)$(LINUX_VERMAGIC) | mkhash md5 | cut -b1-8)
48 IMG_PART_DISKGUID:=$(shell echo $(SOURCE_DATE_EPOCH)$(LINUX_VERMAGIC) | mkhash md5 | sed -E 's/(.{8})(.{4})(.{4})(.{4})(.{10})../\1-\2-\3-\4-\500/')
49
50 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
51
52 ifneq ($(CONFIG_BIG_ENDIAN),)
53 JFFS2OPTS := --big-endian --squash-uids -v
54 else
55 JFFS2OPTS := --little-endian --squash-uids -v
56 endif
57
58 ifeq ($(CONFIG_JFFS2_RTIME),y)
59 JFFS2OPTS += -X rtime
60 endif
61 ifeq ($(CONFIG_JFFS2_ZLIB),y)
62 JFFS2OPTS += -X zlib
63 endif
64 ifeq ($(CONFIG_JFFS2_LZMA),y)
65 JFFS2OPTS += -X lzma --compression-mode=size
66 endif
67 ifneq ($(CONFIG_JFFS2_RTIME),y)
68 JFFS2OPTS += -x rtime
69 endif
70 ifneq ($(CONFIG_JFFS2_ZLIB),y)
71 JFFS2OPTS += -x zlib
72 endif
73 ifneq ($(CONFIG_JFFS2_LZMA),y)
74 JFFS2OPTS += -x lzma
75 endif
76
77 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
78
79 SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
80 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
81 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
82 SQUASHFSCOMP := gzip
83 LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
84 ifeq ($(CONFIG_SQUASHFS_XZ),y)
85 ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
86 BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
87 endif
88 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
89 endif
90
91 JFFS2_BLOCKSIZE ?= 64k 128k
92
93 fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
94 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
95 fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
96 fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
97 fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
98 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
99
100 TARGET_FILESYSTEMS := $(fs-types-y)
101
102 FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
103 FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
104 FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
105
106 define add_jffs2_mark
107 echo -ne '\xde\xad\xc0\xde' >> $(1)
108 endef
109
110 PROFILE_SANITIZED := $(call tolower,$(subst DEVICE_,,$(subst $(space),-,$(PROFILE))))
111
112 define split_args
113 $(foreach data, \
114 $(subst |,$(space),\
115 $(subst $(space),^,$(1))), \
116 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
117 endef
118
119 define build_cmd
120 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
121 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
122
123 endef
124
125 define concat_cmd
126 $(call split_args,$(1),build_cmd)
127 endef
128
129 # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
130 define prepare_generic_squashfs
131 $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
132 endef
133
134 define Image/BuildKernel/Initramfs
135 $(call Image/Build/Initramfs)
136 endef
137
138 define Image/BuildKernel/MkuImage
139 mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
140 -n '$(call toupper,$(ARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' -d $(4) $(5)
141 endef
142
143 define Image/BuildKernel/MkFIT
144 $(TOPDIR)/scripts/mkits.sh \
145 -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
146 -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
147 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
148 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
149 endef
150
151 ifdef CONFIG_TARGET_IMAGES_GZIP
152 define Image/Gzip
153 rm -f $(1).gz
154 gzip -9n $(1)
155 endef
156 endif
157
158
159 # Disable noisy checks by default as in upstream
160 DTC_FLAGS += \
161 -Wno-unit_address_vs_reg \
162 -Wno-simple_bus_reg \
163 -Wno-unit_address_format \
164 -Wno-pci_bridge \
165 -Wno-pci_device_bus_num \
166 -Wno-pci_device_reg
167 ifeq ($(strip $(call kernel_patchver_ge,4.17.0)),1)
168 DTC_FLAGS += \
169 -Wno-avoid_unnecessary_addr_size \
170 -Wno-alias_paths
171 endif
172 ifeq ($(strip $(call kernel_patchver_ge,4.18.0)),1)
173 DTC_FLAGS += \
174 -Wno-graph_child_address \
175 -Wno-graph_port \
176 -Wno-unique_unit_address
177 endif
178
179 define Image/pad-to
180 dd if=$(1) of=$(1).new bs=$(2) conv=sync
181 mv $(1).new $(1)
182 endef
183
184 ROOTFS_PARTSIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
185
186 define Image/pad-root-squashfs
187 $(call Image/pad-to,$(KDIR)/root.squashfs,$(if $(1),$(1),$(ROOTFS_PARTSIZE)))
188 endef
189
190 # $(1) source dts file
191 # $(2) target dtb file
192 # $(3) extra CPP flags
193 # $(4) extra DTC flags
194 define Image/BuildDTB
195 $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
196 -I$(DTS_DIR) \
197 -I$(DTS_DIR)/include \
198 -I$(LINUX_DIR)/include/ \
199 -undef -D__DTS__ $(3) \
200 -o $(2).tmp $(1)
201 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
202 -i$(dir $(1)) $(DTC_FLAGS) $(4) \
203 -o $(2) $(2).tmp
204 $(RM) $(2).tmp
205 endef
206
207 define Image/mkfs/jffs2/sub-raw
208 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
209 $(2) \
210 -e $(patsubst %k,%KiB,$(1)) \
211 -o $@ -d $(call mkfs_target_dir,$(3)) \
212 -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
213 endef
214
215 define Image/mkfs/jffs2/sub
216 $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
217 $(call add_jffs2_mark,$@)
218 endef
219
220 define Image/mkfs/jffs2/template
221 Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(JFFS2OPTS),$$(1))
222 Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(JFFS2OPTS),$$(1))
223
224 endef
225
226 define Image/mkfs/jffs2-nand/template
227 Image/mkfs/jffs2-nand-$(1) = \
228 $$(call Image/mkfs/jffs2/sub, \
229 $(word 2,$(subst -, ,$(1))), \
230 $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))),$$(1))
231
232 endef
233
234 $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
235 $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
236
237 define Image/mkfs/squashfs-common
238 $(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
239 -nopad -noappend -root-owned \
240 -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) \
241 -processors 1
242 endef
243
244 ifeq ($(CONFIG_TARGET_ROOTFS_SECURITY_LABELS),y)
245 define Image/mkfs/squashfs
246 echo ". $(call mkfs_target_dir,$(1))/etc/selinux/config" > $@.fakeroot-script
247 echo "$(STAGING_DIR_HOST)/bin/setfiles -r" \
248 "$(call mkfs_target_dir,$(1))" \
249 "$(call mkfs_target_dir,$(1))/etc/selinux/\$${SELINUXTYPE}/contexts/files/file_contexts " \
250 "$(call mkfs_target_dir,$(1))" >> $@.fakeroot-script
251 echo "$(Image/mkfs/squashfs-common)" >> $@.fakeroot-script
252 chmod +x $@.fakeroot-script
253 $(FAKEROOT) "$@.fakeroot-script"
254 endef
255 else
256 define Image/mkfs/squashfs
257 $(call Image/mkfs/squashfs-common,$(1))
258 endef
259 endif
260
261 define Image/mkfs/ubifs
262 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
263 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
264 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
265 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
266 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
267 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
268 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
269 --squash-uids \
270 -o $@ -d $(call mkfs_target_dir,$(1))
271 endef
272
273 define Image/mkfs/ext4
274 $(STAGING_DIR_HOST)/bin/make_ext4fs -L rootfs \
275 -l $(ROOTFS_PARTSIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
276 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
277 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
278 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
279 $@ $(call mkfs_target_dir,$(1))/
280 endef
281
282 define Image/Manifest
283 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
284 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
285 endef
286
287 define Image/gzip-ext4-padded-squashfs
288
289 define Image/Build/squashfs
290 $(call Image/pad-root-squashfs)
291 endef
292
293 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
294 define Image/Build/gzip/ext4
295 $(call Image/Build/gzip,ext4)
296 endef
297 define Image/Build/gzip/squashfs
298 $(call Image/Build/gzip,squashfs)
299 endef
300 endif
301
302 endef
303
304 ifdef CONFIG_TARGET_ROOTFS_TARGZ
305 define Image/Build/targz
306 $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
307 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
308 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
309 endef
310 endif
311
312 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
313 define Image/Build/cpiogz
314 ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_ROOTFS).cpio.gz )
315 endef
316 endif
317
318 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
319 mkfs_packages_add = $(foreach pkg,$(filter-out -%,$(mkfs_packages)),$(pkg)$(call GetABISuffix,$(pkg)))
320 mkfs_packages_remove = $(foreach pkg,$(patsubst -%,%,$(filter -%,$(mkfs_packages))),$(pkg)$(call GetABISuffix,$(pkg)))
321 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
322
323 opkg_target = \
324 $(call opkg,$(mkfs_cur_target_dir)) \
325 -f $(mkfs_cur_target_dir).conf
326
327 target-dir-%: FORCE
328 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
329 $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
330 -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
331 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
332 $(if $(mkfs_packages_remove), \
333 -$(call opkg,$(mkfs_cur_target_dir)) remove \
334 $(mkfs_packages_remove))
335 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
336 $(opkg_target) update && \
337 $(opkg_target) install \
338 $(call opkg_package_files,$(mkfs_packages_add)))
339 -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
340 rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
341 $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
342
343 $(KDIR)/root.%: kernel_prepare
344 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
345
346 define Device/InitProfile
347 PROFILES := $(PROFILE)
348 DEVICE_TITLE = $$(DEVICE_VENDOR) $$(DEVICE_MODEL)$$(if $$(DEVICE_VARIANT), $$(DEVICE_VARIANT))
349 DEVICE_ALT0_TITLE = $$(DEVICE_ALT0_VENDOR) $$(DEVICE_ALT0_MODEL)$$(if $$(DEVICE_ALT0_VARIANT), $$(DEVICE_ALT0_VARIANT))
350 DEVICE_ALT1_TITLE = $$(DEVICE_ALT1_VENDOR) $$(DEVICE_ALT1_MODEL)$$(if $$(DEVICE_ALT1_VARIANT), $$(DEVICE_ALT1_VARIANT))
351 DEVICE_ALT2_TITLE = $$(DEVICE_ALT2_VENDOR) $$(DEVICE_ALT2_MODEL)$$(if $$(DEVICE_ALT2_VARIANT), $$(DEVICE_ALT2_VARIANT))
352 DEVICE_VENDOR :=
353 DEVICE_MODEL :=
354 DEVICE_VARIANT :=
355 DEVICE_ALT0_VENDOR :=
356 DEVICE_ALT0_MODEL :=
357 DEVICE_ALT0_VARIANT :=
358 DEVICE_ALT1_VENDOR :=
359 DEVICE_ALT1_MODEL :=
360 DEVICE_ALT1_VARIANT :=
361 DEVICE_ALT2_VENDOR :=
362 DEVICE_ALT2_MODEL :=
363 DEVICE_ALT2_VARIANT :=
364 DEVICE_PACKAGES :=
365 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
366 endef
367
368 define Device/Init
369 DEVICE_NAME := $(1)
370 KERNEL:=
371 KERNEL_INITRAMFS = $$(KERNEL)
372 CMDLINE:=
373
374 IMAGES :=
375 ARTIFACTS :=
376 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
377 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
378 IMAGE_SIZE :=
379 KERNEL_PREFIX = $$(IMAGE_PREFIX)
380 KERNEL_SUFFIX := -kernel.bin
381 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
382 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
383 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
384 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
385 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
386 KERNEL_INSTALL :=
387 KERNEL_NAME := vmlinux
388 KERNEL_DEPENDS :=
389 KERNEL_SIZE :=
390
391 UBOOTENV_IN_UBI :=
392 KERNEL_IN_UBI :=
393 BLOCKSIZE :=
394 PAGESIZE :=
395 SUBPAGESIZE :=
396 VID_HDR_OFFSET :=
397 UBINIZE_OPTS :=
398 UBINIZE_PARTS :=
399 MKUBIFS_OPTS :=
400
401 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
402
403 DEVICE_DTS :=
404 DEVICE_DTS_CONFIG :=
405 DEVICE_DTS_DIR :=
406 DEVICE_FDT_NUM :=
407 SOC :=
408
409 BOARD_NAME :=
410 UIMAGE_NAME :=
411 DEVICE_COMPAT_VERSION := 1.0
412 DEVICE_COMPAT_MESSAGE :=
413 SUPPORTED_DEVICES :=
414 IMAGE_METADATA :=
415
416 FILESYSTEMS := $(TARGET_FILESYSTEMS)
417
418 UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-$(1)
419
420 BROKEN :=
421 DEFAULT :=
422 endef
423
424 DEFAULT_DEVICE_VARS := \
425 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
426 CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
427 VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
428 DEVICE_DTS_CONFIG DEVICE_DTS_DIR DEVICE_FDT_NUM SOC BOARD_NAME \
429 UIMAGE_NAME SUPPORTED_DEVICES IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR \
430 UBOOT_PATH IMAGE_SIZE \
431 DEVICE_COMPAT_VERSION DEVICE_COMPAT_MESSAGE \
432 DEVICE_VENDOR DEVICE_MODEL DEVICE_VARIANT \
433 DEVICE_ALT0_VENDOR DEVICE_ALT0_MODEL DEVICE_ALT0_VARIANT \
434 DEVICE_ALT1_VENDOR DEVICE_ALT1_MODEL DEVICE_ALT1_VARIANT \
435 DEVICE_ALT2_VENDOR DEVICE_ALT2_MODEL DEVICE_ALT2_VARIANT
436
437 define Device/ExportVar
438 $(1) : $(2):=$$($(2))
439
440 endef
441 define Device/Export
442 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
443 $(1) : FILESYSTEM:=$(2)
444 endef
445
446 ifdef IB
447 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
448 else
449 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
450 endif
451
452 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
453
454 define merge_packages
455 $(1) :=
456 $(foreach pkg,$(2),
457 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
458 )
459 endef
460
461 define Device/Check/Common
462 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
463 DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
464 ifdef TARGET_PER_DEVICE_ROOTFS
465 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
466 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
467 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
468 endif
469 endef
470
471 define Device/Check
472 $(Device/Check/Common)
473 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
474 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
475 ifndef IB
476 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
477 endif
478 endef
479
480 ifndef IB
481 define Device/Build/initramfs
482 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
483 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
484
485 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
486 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
487 cp $$^ $$@
488
489 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
490 @rm -f $$@
491 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
492 endef
493 endif
494
495 define Device/Build/compile
496 $$(_COMPILE_TARGET): $(KDIR)/$(1)
497 $(eval $(call Device/Export,$(KDIR)/$(1)))
498 $(KDIR)/$(1):
499 $$(call concat_cmd,$(COMPILE/$(1)))
500
501 endef
502
503 ifndef IB
504 define Device/Build/dtb
505 ifndef BUILD_DTS_$(1)
506 BUILD_DTS_$(1) := 1
507 $(KDIR)/image-$(1).dtb: FORCE
508 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
509
510 image_prepare: $(KDIR)/image-$(1).dtb
511 endif
512
513 endef
514 endif
515
516 define Device/Build/kernel
517 $$(eval $$(foreach dts,$$(DEVICE_DTS), \
518 $$(call Device/Build/dtb,$$(notdir $$(dts)), \
519 $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
520 $$(dts) \
521 ) \
522 ))
523
524 $(KDIR)/$$(KERNEL_NAME):: image_prepare
525 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
526 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
527 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
528 cp $$^ $$@
529 ifndef IB
530 ifdef CONFIG_IB
531 install: $$(KDIR_KERNEL_IMAGE)
532 endif
533 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
534 @rm -f $$@
535 $$(call concat_cmd,$$(KERNEL))
536 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
537 endif
538 endef
539
540 define Device/Build/image
541 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
542 $$(_TARGET): $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
543 $(BUILD_DIR)/json_info_files/$(call IMAGE_NAME,$(1),$(2)).json, \
544 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX))
545 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
546
547 ROOTFS/$(1)/$(3) := \
548 $(KDIR)/root.$(1)$$(strip \
549 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
550 )$$(strip \
551 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
552 )
553 ifndef IB
554 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
555 endif
556 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
557 @rm -f $$@
558 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
559 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
560
561 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
562
563 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
564 gzip -c -9n $$^ > $$@
565
566 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
567 cp $$^ $$@
568
569 $(BUILD_DIR)/json_info_files/$(call IMAGE_NAME,$(1),$(2)).json: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
570 @mkdir -p $$(shell dirname $$@)
571 DEVICE_ID="$(DEVICE_NAME)" \
572 BIN_DIR="$(BIN_DIR)" \
573 IMAGE_NAME="$(IMAGE_NAME)" \
574 IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
575 IMAGE_PREFIX="$(IMAGE_PREFIX)" \
576 DEVICE_VENDOR="$(DEVICE_VENDOR)" \
577 DEVICE_MODEL="$(DEVICE_MODEL)" \
578 DEVICE_VARIANT="$(DEVICE_VARIANT)" \
579 DEVICE_ALT0_VENDOR="$(DEVICE_ALT0_VENDOR)" \
580 DEVICE_ALT0_MODEL="$(DEVICE_ALT0_MODEL)" \
581 DEVICE_ALT0_VARIANT="$(DEVICE_ALT0_VARIANT)" \
582 DEVICE_ALT1_VENDOR="$(DEVICE_ALT1_VENDOR)" \
583 DEVICE_ALT1_MODEL="$(DEVICE_ALT1_MODEL)" \
584 DEVICE_ALT1_VARIANT="$(DEVICE_ALT1_VARIANT)" \
585 DEVICE_ALT2_VENDOR="$(DEVICE_ALT2_VENDOR)" \
586 DEVICE_ALT2_MODEL="$(DEVICE_ALT2_MODEL)" \
587 DEVICE_ALT2_VARIANT="$(DEVICE_ALT2_VARIANT)" \
588 DEVICE_TITLE="$(DEVICE_TITLE)" \
589 DEVICE_PACKAGES="$(DEVICE_PACKAGES)" \
590 TARGET="$(BOARD)" \
591 SUBTARGET="$(if $(SUBTARGET),$(SUBTARGET),generic)" \
592 VERSION_NUMBER="$(VERSION_NUMBER)" \
593 VERSION_CODE="$(VERSION_CODE)" \
594 SUPPORTED_DEVICES="$(SUPPORTED_DEVICES)" \
595 $(TOPDIR)/scripts/json_add_image_info.py $$@
596
597 endef
598
599 define Device/Build/artifact
600 $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
601 $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
602 $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
603 @rm -f $$@
604 $$(call concat_cmd,$(ARTIFACT/$(1)))
605
606 .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
607
608 $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
609 cp $$^ $$@
610
611 endef
612
613 define Device/Build
614 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
615 $(call Device/Build/kernel,$(1))
616
617 $$(eval $$(foreach compile,$$(COMPILE), \
618 $$(call Device/Build/compile,$$(compile),$(1))))
619
620 $$(eval $$(foreach image,$$(IMAGES), \
621 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
622 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
623
624 $$(eval $$(foreach artifact,$$(ARTIFACTS), \
625 $$(call Device/Build/artifact,$$(artifact))))
626
627 endef
628
629 define Device/DumpInfo
630 Target-Profile: DEVICE_$(1)
631 Target-Profile-Name: $(DEVICE_DISPLAY)
632 Target-Profile-Packages: $(DEVICE_PACKAGES)
633 Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
634 Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
635 $(if $(BROKEN),Target-Profile-Broken: $(BROKEN))
636 $(if $(DEFAULT),Target-Profile-Default: $(DEFAULT))
637 Target-Profile-Description:
638 $(DEVICE_DESCRIPTION)
639 $(if $(strip $(DEVICE_ALT0_TITLE)),Alternative device titles:
640 - $(DEVICE_ALT0_TITLE))
641 $(if $(strip $(DEVICE_ALT1_TITLE)),- $(DEVICE_ALT1_TITLE))
642 $(if $(strip $(DEVICE_ALT2_TITLE)),- $(DEVICE_ALT2_TITLE))
643 @@
644
645 endef
646
647 define Device/Dump
648 ifneq ($$(strip $$(DEVICE_ALT0_TITLE)),)
649 DEVICE_DISPLAY = $$(DEVICE_ALT0_TITLE) ($$(DEVICE_TITLE))
650 $$(info $$(call Device/DumpInfo,$(1)))
651 endif
652 ifneq ($$(strip $$(DEVICE_ALT1_TITLE)),)
653 DEVICE_DISPLAY = $$(DEVICE_ALT1_TITLE) ($$(DEVICE_TITLE))
654 $$(info $$(call Device/DumpInfo,$(1)))
655 endif
656 ifneq ($$(strip $$(DEVICE_ALT2_TITLE)),)
657 DEVICE_DISPLAY = $$(DEVICE_ALT2_TITLE) ($$(DEVICE_TITLE))
658 $$(info $$(call Device/DumpInfo,$(1)))
659 endif
660 DEVICE_DISPLAY = $$(DEVICE_TITLE)
661 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
662 endef
663
664 define Device
665 $(call Device/InitProfile,$(1))
666 $(call Device/Init,$(1))
667 $(call Device/Default,$(1))
668 $(call Device/$(1),$(1))
669 $(call Device/Check,$(1))
670 $(call Device/$(if $(DUMP),Dump,Build),$(1))
671
672 endef
673
674 define BuildImage
675
676 ifneq ($(DUMP),)
677 all: dumpinfo
678 dumpinfo: FORCE
679 @true
680 endif
681
682 download:
683 prepare:
684 compile:
685 clean:
686 legacy-images-prepare:
687 legacy-images:
688 image_prepare:
689
690 ifeq ($(IB),)
691 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
692 compile:
693 $(call Build/Compile)
694
695 clean:
696 $(call Build/Clean)
697
698 image_prepare: compile
699 mkdir -p $(BIN_DIR) $(KDIR)/tmp
700 rm -rf $(BUILD_DIR)/json_info_files
701 $(call Image/Prepare)
702
703 legacy-images-prepare-make: image_prepare
704 $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
705
706 else
707 image_prepare:
708 mkdir -p $(BIN_DIR) $(KDIR)/tmp
709 endif
710
711 kernel_prepare: image_prepare
712 $(call Image/Build/targz)
713 $(call Image/Build/cpiogz)
714 $(call Image/BuildKernel)
715 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
716 $(call Image/InstallKernel)
717
718 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
719 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
720
721 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
722 $(foreach fs,$(TARGET_FILESYSTEMS),
723 $(call Image/Build,$(fs))
724 )
725
726 legacy-images-make: install-images
727 $(call Image/mkfs/ubifs/legacy)
728 $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
729
730 install: install-images
731 $(call Image/Manifest)
732
733 endef