image.mk 28 KB

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