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