300f7a66195a30dffd5aa0718d69736578f49a8b
[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
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 # $(1): board name
245 # $(2): rootfs type
246 # $(3): kernel image
247 # $(4): compat string
248 ifneq ($(CONFIG_NAND_SUPPORT),)
249 define Image/Build/SysupgradeNAND
250 mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
251 echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
252 [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
253 [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
254 (cd "$(KDIR_TMP)"; $(TAR) cvf \
255 "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
256 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
257 )
258 endef
259
260 # $(1) board name
261 # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
262 # $(3) rootfstype (e.g. squashfs or ubifs)
263 # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
264 define Image/Build/UbinizeImage
265 sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
266 "$(KDIR)/root.$(3)" \
267 "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
268 $(4)
269 endef
270
271 endif
272
273 define Image/mkfs/ubifs
274 $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
275 $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
276 $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
277 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
278 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
279 $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
280 $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
281 --squash-uids \
282 -o $@ -d $(call mkfs_target_dir,$(1))
283 endef
284
285 define Image/mkfs/ext4
286 $(STAGING_DIR_HOST)/bin/make_ext4fs -L rootfs \
287 -l $(ROOTFS_PARTSIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
288 $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
289 $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
290 $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
291 $@ $(call mkfs_target_dir,$(1))/
292 endef
293
294 define Image/Manifest
295 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
296 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
297 endef
298
299 define Image/gzip-ext4-padded-squashfs
300
301 define Image/Build/squashfs
302 $(call Image/pad-root-squashfs)
303 endef
304
305 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
306 define Image/Build/gzip/ext4
307 $(call Image/Build/gzip,ext4)
308 endef
309 define Image/Build/gzip/squashfs
310 $(call Image/Build/gzip,squashfs)
311 endef
312 endif
313
314 endef
315
316 ifdef CONFIG_TARGET_ROOTFS_TARGZ
317 define Image/Build/targz
318 $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
319 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
320 -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
321 endef
322 endif
323
324 ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
325 define Image/Build/cpiogz
326 ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_ROOTFS).cpio.gz )
327 endef
328 endif
329
330 mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
331 mkfs_packages_add = $(foreach pkg,$(filter-out -%,$(mkfs_packages)),$(pkg)$(call GetABISuffix,$(pkg)))
332 mkfs_packages_remove = $(foreach pkg,$(patsubst -%,%,$(filter -%,$(mkfs_packages))),$(pkg)$(call GetABISuffix,$(pkg)))
333 mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
334
335 opkg_target = \
336 $(call opkg,$(mkfs_cur_target_dir)) \
337 -f $(mkfs_cur_target_dir).conf
338
339 target-dir-%: FORCE
340 rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
341 $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
342 -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
343 echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
344 $(if $(mkfs_packages_remove), \
345 -$(call opkg,$(mkfs_cur_target_dir)) remove \
346 $(mkfs_packages_remove))
347 $(if $(call opkg_package_files,$(mkfs_packages_add)), \
348 $(opkg_target) update && \
349 $(opkg_target) install \
350 $(call opkg_package_files,$(mkfs_packages_add)))
351 -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
352 rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
353 $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
354
355 $(KDIR)/root.%: kernel_prepare
356 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
357
358 define Device/InitProfile
359 PROFILES := $(PROFILE)
360 DEVICE_TITLE = $$(DEVICE_VENDOR) $$(DEVICE_MODEL)$$(if $$(DEVICE_VARIANT), $$(DEVICE_VARIANT))
361 DEVICE_ALT0_TITLE = $$(DEVICE_ALT0_VENDOR) $$(DEVICE_ALT0_MODEL)$$(if $$(DEVICE_ALT0_VARIANT), $$(DEVICE_ALT0_VARIANT))
362 DEVICE_ALT1_TITLE = $$(DEVICE_ALT1_VENDOR) $$(DEVICE_ALT1_MODEL)$$(if $$(DEVICE_ALT1_VARIANT), $$(DEVICE_ALT1_VARIANT))
363 DEVICE_ALT2_TITLE = $$(DEVICE_ALT2_VENDOR) $$(DEVICE_ALT2_MODEL)$$(if $$(DEVICE_ALT2_VARIANT), $$(DEVICE_ALT2_VARIANT))
364 DEVICE_VENDOR :=
365 DEVICE_MODEL :=
366 DEVICE_VARIANT :=
367 DEVICE_ALT0_VENDOR :=
368 DEVICE_ALT0_MODEL :=
369 DEVICE_ALT0_VARIANT :=
370 DEVICE_ALT1_VENDOR :=
371 DEVICE_ALT1_MODEL :=
372 DEVICE_ALT1_VARIANT :=
373 DEVICE_ALT2_VENDOR :=
374 DEVICE_ALT2_MODEL :=
375 DEVICE_ALT2_VARIANT :=
376 DEVICE_PACKAGES :=
377 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
378 endef
379
380 define Device/Init
381 DEVICE_NAME := $(1)
382 KERNEL:=
383 KERNEL_INITRAMFS = $$(KERNEL)
384 CMDLINE:=
385
386 IMAGES :=
387 ARTIFACTS :=
388 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
389 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
390 IMAGE_SIZE :=
391 KERNEL_PREFIX = $$(IMAGE_PREFIX)
392 KERNEL_SUFFIX := -kernel.bin
393 KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
394 KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
395 KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
396 KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
397 KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
398 KERNEL_INSTALL :=
399 KERNEL_NAME := vmlinux
400 KERNEL_DEPENDS :=
401 KERNEL_SIZE :=
402
403 UBOOTENV_IN_UBI :=
404 KERNEL_IN_UBI :=
405 BLOCKSIZE :=
406 PAGESIZE :=
407 SUBPAGESIZE :=
408 VID_HDR_OFFSET :=
409 UBINIZE_OPTS :=
410 UBINIZE_PARTS :=
411 MKUBIFS_OPTS :=
412
413 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
414
415 DEVICE_DTS :=
416 DEVICE_DTS_CONFIG :=
417 DEVICE_DTS_DIR :=
418 SOC :=
419
420 BOARD_NAME :=
421 UIMAGE_NAME :=
422 SUPPORTED_DEVICES :=
423 IMAGE_METADATA :=
424
425 FILESYSTEMS := $(TARGET_FILESYSTEMS)
426
427 UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-$(1)
428
429 DEFAULT :=
430 endef
431
432 DEFAULT_DEVICE_VARS := \
433 DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
434 CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
435 VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
436 DEVICE_DTS_CONFIG DEVICE_DTS_DIR SOC BOARD_NAME UIMAGE_NAME SUPPORTED_DEVICES \
437 IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR UBOOT_PATH IMAGE_SIZE \
438 DEVICE_VENDOR DEVICE_MODEL DEVICE_VARIANT \
439 DEVICE_ALT0_VENDOR DEVICE_ALT0_MODEL DEVICE_ALT0_VARIANT \
440 DEVICE_ALT1_VENDOR DEVICE_ALT1_MODEL DEVICE_ALT1_VARIANT \
441 DEVICE_ALT2_VENDOR DEVICE_ALT2_MODEL DEVICE_ALT2_VARIANT
442
443 define Device/ExportVar
444 $(1) : $(2):=$$($(2))
445
446 endef
447 define Device/Export
448 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
449 $(1) : FILESYSTEM:=$(2)
450 endef
451
452 ifdef IB
453 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
454 else
455 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
456 endif
457
458 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
459
460 define merge_packages
461 $(1) :=
462 $(foreach pkg,$(2),
463 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
464 )
465 endef
466
467 define Device/Check/Common
468 _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
469 DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
470 ifdef TARGET_PER_DEVICE_ROOTFS
471 $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
472 ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
473 PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
474 endif
475 endef
476
477 define Device/Check
478 $(Device/Check/Common)
479 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
480 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
481 ifndef IB
482 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
483 endif
484 endef
485
486 ifndef IB
487 define Device/Build/initramfs
488 $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
489 $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
490
491 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
492 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
493 cp $$^ $$@
494
495 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
496 @rm -f $$@
497 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
498 endef
499 endif
500
501 define Device/Build/compile
502 $$(_COMPILE_TARGET): $(KDIR)/$(1)
503 $(eval $(call Device/Export,$(KDIR)/$(1)))
504 $(KDIR)/$(1):
505 $$(call concat_cmd,$(COMPILE/$(1)))
506
507 endef
508
509 ifndef IB
510 define Device/Build/dtb
511 ifndef BUILD_DTS_$(1)
512 BUILD_DTS_$(1) := 1
513 $(KDIR)/image-$(1).dtb: FORCE
514 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
515
516 image_prepare: $(KDIR)/image-$(1).dtb
517 endif
518
519 endef
520 endif
521
522 define Device/Build/kernel
523 $$(eval $$(foreach dts,$$(DEVICE_DTS), \
524 $$(call Device/Build/dtb,$$(notdir $$(dts)), \
525 $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
526 $$(dts) \
527 ) \
528 ))
529
530 $(KDIR)/$$(KERNEL_NAME):: image_prepare
531 $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
532 $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
533 $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
534 cp $$^ $$@
535 ifndef IB
536 ifdef CONFIG_IB
537 install: $$(KDIR_KERNEL_IMAGE)
538 endif
539 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
540 @rm -f $$@
541 $$(call concat_cmd,$$(KERNEL))
542 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
543 endif
544 endef
545
546 define Device/Build/image
547 GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
548 $$(_TARGET): $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
549 $(BUILD_DIR)/json_info_files/$(call IMAGE_NAME,$(1),$(2)).json, \
550 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX))
551 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
552
553 ROOTFS/$(1)/$(3) := \
554 $(KDIR)/root.$(1)$$(strip \
555 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
556 )$$(strip \
557 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
558 )
559 ifndef IB
560 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
561 endif
562 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
563 @rm -f $$@
564 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
565 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
566
567 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
568
569 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
570 gzip -c -9n $$^ > $$@
571
572 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
573 cp $$^ $$@
574
575 $(BUILD_DIR)/json_info_files/$(call IMAGE_NAME,$(1),$(2)).json: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
576 @mkdir -p $$(shell dirname $$@)
577 DEVICE_ID="$(DEVICE_NAME)" \
578 BIN_DIR="$(BIN_DIR)" \
579 IMAGE_NAME="$(IMAGE_NAME)" \
580 IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
581 IMAGE_PREFIX="$(IMAGE_PREFIX)" \
582 DEVICE_VENDOR="$(DEVICE_VENDOR)" \
583 DEVICE_MODEL="$(DEVICE_MODEL)" \
584 DEVICE_VARIANT="$(DEVICE_VARIANT)" \
585 DEVICE_ALT0_VENDOR="$(DEVICE_ALT0_VENDOR)" \
586 DEVICE_ALT0_MODEL="$(DEVICE_ALT0_MODEL)" \
587 DEVICE_ALT0_VARIANT="$(DEVICE_ALT0_VARIANT)" \
588 DEVICE_ALT1_VENDOR="$(DEVICE_ALT1_VENDOR)" \
589 DEVICE_ALT1_MODEL="$(DEVICE_ALT1_MODEL)" \
590 DEVICE_ALT1_VARIANT="$(DEVICE_ALT1_VARIANT)" \
591 DEVICE_ALT2_VENDOR="$(DEVICE_ALT2_VENDOR)" \
592 DEVICE_ALT2_MODEL="$(DEVICE_ALT2_MODEL)" \
593 DEVICE_ALT2_VARIANT="$(DEVICE_ALT2_VARIANT)" \
594 DEVICE_TITLE="$(DEVICE_TITLE)" \
595 DEVICE_PACKAGES="$(DEVICE_PACKAGES)" \
596 TARGET="$(BOARD)" \
597 SUBTARGET="$(if $(SUBTARGET),$(SUBTARGET),generic)" \
598 VERSION_NUMBER="$(VERSION_NUMBER)" \
599 VERSION_CODE="$(VERSION_CODE)" \
600 SUPPORTED_DEVICES="$(SUPPORTED_DEVICES)" \
601 $(TOPDIR)/scripts/json_add_image_info.py $$@
602
603 endef
604
605 define Device/Build/artifact
606 $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
607 $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
608 $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
609 @rm -f $$@
610 $$(call concat_cmd,$(ARTIFACT/$(1)))
611
612 .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
613
614 $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
615 cp $$^ $$@
616
617 endef
618
619 define Device/Build
620 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
621 $(call Device/Build/kernel,$(1))
622
623 $$(eval $$(foreach compile,$$(COMPILE), \
624 $$(call Device/Build/compile,$$(compile),$(1))))
625
626 $$(eval $$(foreach image,$$(IMAGES), \
627 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
628 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
629
630 $$(eval $$(foreach artifact,$$(ARTIFACTS), \
631 $$(call Device/Build/artifact,$$(artifact))))
632
633 endef
634
635 define Device/DumpInfo
636 Target-Profile: DEVICE_$(1)
637 Target-Profile-Name: $(DEVICE_DISPLAY)
638 Target-Profile-Packages: $(DEVICE_PACKAGES)
639 Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
640 Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
641 $(if $(DEFAULT),Target-Profile-Default: $(DEFAULT))
642 Target-Profile-Description:
643 $(DEVICE_DESCRIPTION)
644 $(if $(strip $(DEVICE_ALT0_TITLE)),Alternative device titles:
645 - $(DEVICE_ALT0_TITLE))
646 $(if $(strip $(DEVICE_ALT1_TITLE)),- $(DEVICE_ALT1_TITLE))
647 $(if $(strip $(DEVICE_ALT2_TITLE)),- $(DEVICE_ALT2_TITLE))
648 @@
649
650 endef
651
652 define Device/Dump
653 ifneq ($$(strip $$(DEVICE_ALT0_TITLE)),)
654 DEVICE_DISPLAY = $$(DEVICE_ALT0_TITLE) ($$(DEVICE_TITLE))
655 $$(info $$(call Device/DumpInfo,$(1)))
656 endif
657 ifneq ($$(strip $$(DEVICE_ALT1_TITLE)),)
658 DEVICE_DISPLAY = $$(DEVICE_ALT1_TITLE) ($$(DEVICE_TITLE))
659 $$(info $$(call Device/DumpInfo,$(1)))
660 endif
661 ifneq ($$(strip $$(DEVICE_ALT2_TITLE)),)
662 DEVICE_DISPLAY = $$(DEVICE_ALT2_TITLE) ($$(DEVICE_TITLE))
663 $$(info $$(call Device/DumpInfo,$(1)))
664 endif
665 DEVICE_DISPLAY = $$(DEVICE_TITLE)
666 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
667 endef
668
669 define Device
670 $(call Device/InitProfile,$(1))
671 $(call Device/Init,$(1))
672 $(call Device/Default,$(1))
673 $(call Device/$(1),$(1))
674 $(call Device/Check,$(1))
675 $(call Device/$(if $(DUMP),Dump,Build),$(1))
676
677 endef
678
679 define BuildImage
680
681 ifneq ($(DUMP),)
682 all: dumpinfo
683 dumpinfo: FORCE
684 @true
685 endif
686
687 download:
688 prepare:
689 compile:
690 clean:
691 legacy-images-prepare:
692 legacy-images:
693 image_prepare:
694
695 ifeq ($(IB),)
696 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
697 compile:
698 $(call Build/Compile)
699
700 clean:
701 $(call Build/Clean)
702
703 image_prepare: compile
704 mkdir -p $(BIN_DIR) $(KDIR)/tmp
705 rm -rf $(BUILD_DIR)/json_info_files
706 $(call Image/Prepare)
707
708 legacy-images-prepare-make: image_prepare
709 $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
710
711 else
712 image_prepare:
713 mkdir -p $(BIN_DIR) $(KDIR)/tmp
714 endif
715
716 kernel_prepare: image_prepare
717 $(call Image/Build/targz)
718 $(call Image/Build/cpiogz)
719 $(call Image/BuildKernel)
720 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
721 $(call Image/InstallKernel)
722
723 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
724 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
725
726 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
727 $(foreach fs,$(TARGET_FILESYSTEMS),
728 $(call Image/Build,$(fs))
729 )
730
731 legacy-images-make: install-images
732 $(call Image/mkfs/ubifs/legacy)
733 $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
734
735 install: install-images
736 $(call Image/Manifest)
737
738 endef