2 # Copyright (C) 2006-2010 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
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
15 ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
16 TARGET_PER_DEVICE_ROOTFS := 1
20 include $(INCLUDE_DIR)/image-legacy.mk
21 include $(INCLUDE_DIR)/feeds.mk
22 include $(INCLUDE_DIR)/rootfs.mk
24 override MAKE:=$(_SINGLE)$(SUBMAKE)
25 override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
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))
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))
36 KDIR=$(KERNEL_BUILD_DIR)
38 DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
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))-)
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)
49 MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
51 ifneq ($(CONFIG_BIG_ENDIAN),)
52 JFFS2OPTS := --big-endian --squash-uids -v
54 JFFS2OPTS := --little-endian --squash-uids -v
57 ifeq ($(CONFIG_JFFS2_RTIME),y)
60 ifeq ($(CONFIG_JFFS2_ZLIB),y)
63 ifeq ($(CONFIG_JFFS2_LZMA),y)
64 JFFS2OPTS += -X lzma --compression-mode=size
66 ifneq ($(CONFIG_JFFS2_RTIME),y)
69 ifneq ($(CONFIG_JFFS2_ZLIB),y)
72 ifneq ($(CONFIG_JFFS2_LZMA),y)
76 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
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'
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)
87 SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
90 JFFS2_BLOCKSIZE ?= 64k 128k
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_ISO) += iso
97 fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
98 fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
100 TARGET_FILESYSTEMS := $(fs-types-y)
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
106 define add_jffs2_mark
107 echo -ne '\xde\xad\xc0\xde' >> $(1)
110 PROFILE_SANITIZED := $(call tolower,$(subst DEVICE_,,$(subst $(space),-,$(PROFILE))))
115 $(subst $(space),^,$(1))), \
116 $(call $(2),$(strip $(subst ^,$(space),$(data)))))
120 $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
121 $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
126 $(call split_args,$(1),build_cmd)
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
134 define Image/BuildKernel/Initramfs
135 $(call Image/Build/Initramfs)
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)
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
151 ifdef CONFIG_TARGET_IMAGES_GZIP
159 # Disable noisy checks by default as in upstream
161 -Wno-unit_address_vs_reg \
162 -Wno-simple_bus_reg \
163 -Wno-unit_address_format \
165 -Wno-pci_device_bus_num \
167 ifeq ($(strip $(call kernel_patchver_ge,4.17.0)),1)
169 -Wno-avoid_unnecessary_addr_size \
172 ifeq ($(strip $(call kernel_patchver_ge,4.18.0)),1)
174 -Wno-graph_child_address \
176 -Wno-unique_unit_address
180 dd if=$(1) of=$(1).new bs=$(2) conv=sync
184 ROOTFS_PARTSIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
186 define Image/pad-root-squashfs
187 $(call Image/pad-to,$(KDIR)/root.squashfs,$(if $(1),$(1),$(ROOTFS_PARTSIZE)))
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 \
197 -I$(DTS_DIR)/include \
198 -I$(LINUX_DIR)/include/ \
199 -undef -D__DTS__ $(3) \
201 $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
202 -i$(dir $(1)) $(DTC_FLAGS) $(4) \
207 define Image/mkfs/jffs2/sub-raw
208 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
210 -e $(patsubst %k,%KiB,$(1)) \
211 -o $@ -d $(call mkfs_target_dir,$(3)) \
212 -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
215 define Image/mkfs/jffs2/sub
216 $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
217 $(call add_jffs2_mark,$@)
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))
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))
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))))
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) \
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)") \
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" \
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)) \
282 -o $@ -d $(call mkfs_target_dir,$(1))
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))/
294 define Image/Manifest
295 $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
296 $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
299 define Image/gzip-ext4-padded-squashfs
301 define Image/Build/squashfs
302 $(call Image/pad-root-squashfs)
305 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
306 define Image/Build/gzip/ext4
307 $(call Image/Build/gzip,ext4)
309 define Image/Build/gzip/squashfs
310 $(call Image/Build/gzip,squashfs)
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
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 )
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))
336 $(call opkg,$(mkfs_cur_target_dir)) \
337 -f $(mkfs_cur_target_dir).conf
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)
355 $(KDIR)/root.%: kernel_prepare
356 $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
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))
367 DEVICE_ALT0_VENDOR :=
369 DEVICE_ALT0_VARIANT :=
370 DEVICE_ALT1_VENDOR :=
372 DEVICE_ALT1_VARIANT :=
373 DEVICE_ALT2_VENDOR :=
375 DEVICE_ALT2_VARIANT :=
377 DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
383 KERNEL_INITRAMFS = $$(KERNEL)
389 IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
390 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
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
399 KERNEL_NAME := vmlinux
413 FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
425 FILESYSTEMS := $(TARGET_FILESYSTEMS)
427 UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-$(1)
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 DEVICE_VENDOR \
438 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
443 define Device/ExportVar
444 $(1) : $(2):=$$($(2))
448 $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
449 $(1) : FILESYSTEM:=$(2)
453 DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
455 DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
458 DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
460 define merge_packages
463 $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
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)
478 $(Device/Check/Common)
479 KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
480 _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
482 _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
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))
491 $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
492 $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
495 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
497 $$(call concat_cmd,$$(KERNEL_INITRAMFS))
501 define Device/Build/compile
502 $$(_COMPILE_TARGET): $(KDIR)/$(1)
503 $(eval $(call Device/Export,$(KDIR)/$(1)))
505 $$(call concat_cmd,$(COMPILE/$(1)))
510 define Device/Build/dtb
511 ifndef BUILD_DTS_$(1)
513 $(KDIR)/image-$(1).dtb: FORCE
514 $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
516 image_prepare: $(KDIR)/image-$(1).dtb
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)), \
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)
537 install: $$(KDIR_KERNEL_IMAGE)
539 $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
541 $$(call concat_cmd,$$(KERNEL))
542 $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
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): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
549 $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
550 ROOTFS/$(1)/$(3) := \
551 $(KDIR)/root.$(1)$$(strip \
552 $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
554 $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
557 $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
559 $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
561 [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
562 $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
564 .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
566 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
567 gzip -c -9n $$^ > $$@
569 $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
571 $(if $(CONFIG_JSON_ADD_IMAGE_INFO), \
572 DEVICE_ID="$(DEVICE_NAME)" \
573 BIN_DIR="$(BIN_DIR)" \
574 IMAGE_NAME="$(IMAGE_NAME)" \
575 IMAGE_TYPE=$(word 1,$(subst ., ,$(2))) \
576 IMAGE_PREFIX="$(IMAGE_PREFIX)" \
577 DEVICE_VENDOR="$(DEVICE_VENDOR)" \
578 DEVICE_MODEL="$(DEVICE_MODEL)" \
579 DEVICE_VARIANT="$(DEVICE_VARIANT)" \
580 DEVICE_ALT0_VENDOR="$(DEVICE_ALT0_VENDOR)" \
581 DEVICE_ALT0_MODEL="$(DEVICE_ALT0_MODEL)" \
582 DEVICE_ALT0_VARIANT="$(DEVICE_ALT0_VARIANT)" \
583 DEVICE_ALT1_VENDOR="$(DEVICE_ALT1_VENDOR)" \
584 DEVICE_ALT1_MODEL="$(DEVICE_ALT1_MODEL)" \
585 DEVICE_ALT1_VARIANT="$(DEVICE_ALT1_VARIANT)" \
586 DEVICE_ALT2_VENDOR="$(DEVICE_ALT2_VENDOR)" \
587 DEVICE_ALT2_MODEL="$(DEVICE_ALT2_MODEL)" \
588 DEVICE_ALT2_VARIANT="$(DEVICE_ALT2_VARIANT)" \
589 DEVICE_TITLE="$(DEVICE_TITLE)" \
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 \
600 define Device/Build/artifact
601 $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
602 $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
603 $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
605 $$(call concat_cmd,$(ARTIFACT/$(1)))
607 .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
609 $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
615 $(shell rm -f $(BIN_DIR)/$(IMG_PREFIX)-$(1).json)
617 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
618 $(call Device/Build/kernel,$(1))
620 $$(eval $$(foreach compile,$$(COMPILE), \
621 $$(call Device/Build/compile,$$(compile),$(1))))
623 $$(eval $$(foreach image,$$(IMAGES), \
624 $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
625 $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
627 $$(eval $$(foreach artifact,$$(ARTIFACTS), \
628 $$(call Device/Build/artifact,$$(artifact))))
632 define Device/DumpInfo
633 Target-Profile: DEVICE_$(1)
634 Target-Profile-Name: $(DEVICE_DISPLAY)
635 Target-Profile-Packages: $(DEVICE_PACKAGES)
636 Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
637 Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
638 $(if $(DEFAULT),Target-Profile-Default: $(DEFAULT))
639 Target-Profile-Description:
640 $(DEVICE_DESCRIPTION)
641 $(if $(strip $(DEVICE_ALT0_TITLE)),Alternative device titles:
642 - $(DEVICE_ALT0_TITLE))
643 $(if $(strip $(DEVICE_ALT1_TITLE)),- $(DEVICE_ALT1_TITLE))
644 $(if $(strip $(DEVICE_ALT2_TITLE)),- $(DEVICE_ALT2_TITLE))
650 ifneq ($$(strip $$(DEVICE_ALT0_TITLE)),)
651 DEVICE_DISPLAY = $$(DEVICE_ALT0_TITLE) ($$(DEVICE_TITLE))
652 $$(info $$(call Device/DumpInfo,$(1)))
654 ifneq ($$(strip $$(DEVICE_ALT1_TITLE)),)
655 DEVICE_DISPLAY = $$(DEVICE_ALT1_TITLE) ($$(DEVICE_TITLE))
656 $$(info $$(call Device/DumpInfo,$(1)))
658 ifneq ($$(strip $$(DEVICE_ALT2_TITLE)),)
659 DEVICE_DISPLAY = $$(DEVICE_ALT2_TITLE) ($$(DEVICE_TITLE))
660 $$(info $$(call Device/DumpInfo,$(1)))
662 DEVICE_DISPLAY = $$(DEVICE_TITLE)
663 $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
667 $(call Device/InitProfile,$(1))
668 $(call Device/Init,$(1))
669 $(call Device/Default,$(1))
670 $(call Device/$(1),$(1))
671 $(call Device/Check,$(1))
672 $(call Device/$(if $(DUMP),Dump,Build),$(1))
688 legacy-images-prepare:
693 .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
695 $(call Build/Compile)
700 image_prepare: compile
701 mkdir -p $(BIN_DIR) $(KDIR)/tmp
702 $(call Image/Prepare)
704 legacy-images-prepare-make: image_prepare
705 $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
709 mkdir -p $(BIN_DIR) $(KDIR)/tmp
712 kernel_prepare: image_prepare
713 $(call Image/Build/targz)
714 $(call Image/Build/cpiogz)
715 $(call Image/BuildKernel)
716 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
717 $(call Image/InstallKernel)
719 $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
720 $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
722 install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
723 $(foreach fs,$(TARGET_FILESYSTEMS),
724 $(call Image/Build,$(fs))
727 legacy-images-make: install-images
728 $(call Image/mkfs/ubifs/legacy)
729 $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
731 install: install-images
732 $(call Image/Manifest)