2
0

image.mk 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. override TARGET_BUILD=
  8. include $(INCLUDE_DIR)/prereq.mk
  9. include $(INCLUDE_DIR)/kernel.mk
  10. include $(INCLUDE_DIR)/version.mk
  11. include $(INCLUDE_DIR)/image-commands.mk
  12. ifndef IB
  13. ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
  14. TARGET_PER_DEVICE_ROOTFS := 1
  15. endif
  16. endif
  17. include $(INCLUDE_DIR)/image-legacy.mk
  18. include $(INCLUDE_DIR)/feeds.mk
  19. include $(INCLUDE_DIR)/rootfs.mk
  20. override MAKE:=$(_SINGLE)$(SUBMAKE)
  21. override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
  22. target_params = $(subst +,$(space),$*)
  23. param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
  24. param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))
  25. param_mangle = $(subst $(space),_,$(strip $(1)))
  26. param_unmangle = $(subst _,$(space),$(1))
  27. mkfs_packages_id = $(shell echo $(sort $(1)) | mkhash md5 | head -c 8)
  28. mkfs_target_dir = $(if $(call param_get,pkg,$(1)),$(KDIR)/target-dir-$(call param_get,pkg,$(1)),$(TARGET_DIR))
  29. KDIR=$(KERNEL_BUILD_DIR)
  30. KDIR_TMP=$(KDIR)/tmp
  31. DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
  32. IMG_PREFIX_EXTRA:=$(if $(EXTRA_IMAGE_NAME),$(call sanitize,$(EXTRA_IMAGE_NAME))-)
  33. IMG_PREFIX_VERNUM:=$(if $(CONFIG_VERSION_FILENAMES),$(call sanitize,$(VERSION_NUMBER))-)
  34. IMG_PREFIX_VERCODE:=$(if $(CONFIG_VERSION_CODE_FILENAMES),$(call sanitize,$(VERSION_CODE))-)
  35. IMG_PREFIX:=$(VERSION_DIST_SANITIZED)-$(IMG_PREFIX_VERNUM)$(IMG_PREFIX_VERCODE)$(IMG_PREFIX_EXTRA)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
  36. MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
  37. ifneq ($(CONFIG_BIG_ENDIAN),)
  38. JFFS2OPTS := --big-endian --squash-uids -v
  39. else
  40. JFFS2OPTS := --little-endian --squash-uids -v
  41. endif
  42. ifeq ($(CONFIG_JFFS2_RTIME),y)
  43. JFFS2OPTS += -X rtime
  44. endif
  45. ifeq ($(CONFIG_JFFS2_ZLIB),y)
  46. JFFS2OPTS += -X zlib
  47. endif
  48. ifeq ($(CONFIG_JFFS2_LZMA),y)
  49. JFFS2OPTS += -X lzma --compression-mode=size
  50. endif
  51. ifneq ($(CONFIG_JFFS2_RTIME),y)
  52. JFFS2OPTS += -x rtime
  53. endif
  54. ifneq ($(CONFIG_JFFS2_ZLIB),y)
  55. JFFS2OPTS += -x zlib
  56. endif
  57. ifneq ($(CONFIG_JFFS2_LZMA),y)
  58. JFFS2OPTS += -x lzma
  59. endif
  60. JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
  61. SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
  62. SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
  63. SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
  64. SQUASHFSCOMP := gzip
  65. LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
  66. ifeq ($(CONFIG_SQUASHFS_XZ),y)
  67. ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
  68. BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
  69. endif
  70. SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
  71. endif
  72. JFFS2_BLOCKSIZE ?= 64k 128k
  73. fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
  74. fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
  75. fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
  76. fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
  77. fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
  78. fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
  79. fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
  80. TARGET_FILESYSTEMS := $(fs-types-y)
  81. FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
  82. FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
  83. FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
  84. define add_jffs2_mark
  85. echo -ne '\xde\xad\xc0\xde' >> $(1)
  86. endef
  87. PROFILE_SANITIZED := $(call sanitize,$(PROFILE))
  88. define split_args
  89. $(foreach data, \
  90. $(subst |,$(space),\
  91. $(subst $(space),^,$(1))), \
  92. $(call $(2),$(strip $(subst ^,$(space),$(data)))))
  93. endef
  94. define build_cmd
  95. $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
  96. $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
  97. endef
  98. define concat_cmd
  99. $(call split_args,$(1),build_cmd)
  100. endef
  101. # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
  102. define prepare_generic_squashfs
  103. $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
  104. endef
  105. define Image/BuildKernel/Initramfs
  106. $(call Image/Build/Initramfs)
  107. endef
  108. define Image/BuildKernel/MkuImage
  109. mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
  110. -n '$(call toupper,$(ARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' -d $(4) $(5)
  111. endef
  112. define Image/BuildKernel/MkFIT
  113. $(TOPDIR)/scripts/mkits.sh \
  114. -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
  115. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
  116. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  117. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
  118. endef
  119. ifdef CONFIG_TARGET_IMAGES_GZIP
  120. define Image/Gzip
  121. rm -f $(1).gz
  122. gzip -9n $(1)
  123. endef
  124. endif
  125. # Disable noisy checks by default as in upstream
  126. ifeq ($(strip $(call kernel_patchver_ge,4.7.0)),1)
  127. DTC_FLAGS += -Wno-unit_address_vs_reg
  128. endif
  129. ifeq ($(strip $(call kernel_patchver_ge,4.12.0)),1)
  130. DTC_FLAGS += \
  131. -Wno-unit_address_vs_reg \
  132. -Wno-simple_bus_reg \
  133. -Wno-unit_address_format \
  134. -Wno-pci_bridge \
  135. -Wno-pci_device_bus_num \
  136. -Wno-pci_device_reg
  137. endif
  138. ifeq ($(strip $(call kernel_patchver_ge,4.17.0)),1)
  139. DTC_FLAGS += \
  140. -Wno-avoid_unnecessary_addr_size \
  141. -Wno-alias_paths
  142. endif
  143. ifeq ($(strip $(call kernel_patchver_ge,4.18.0)),1)
  144. DTC_FLAGS += \
  145. -Wno-graph_child_address \
  146. -Wno-graph_port \
  147. -Wno-unique_unit_address
  148. endif
  149. # $(1) source dts file
  150. # $(2) target dtb file
  151. # $(3) extra CPP flags
  152. # $(4) extra DTC flags
  153. define Image/BuildDTB
  154. $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
  155. -I$(DTS_DIR) \
  156. -I$(DTS_DIR)/include \
  157. -I$(LINUX_DIR)/include/ \
  158. -undef -D__DTS__ $(3) \
  159. -o $(2).tmp $(1)
  160. $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
  161. -i$(dir $(1)) $(DTC_FLAGS) $(4) \
  162. -o $(2) $(2).tmp
  163. $(RM) $(2).tmp
  164. endef
  165. define Image/mkfs/jffs2/sub-raw
  166. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
  167. $(2) \
  168. -e $(patsubst %k,%KiB,$(1)) \
  169. -o $@ -d $(call mkfs_target_dir,$(3)) \
  170. -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
  171. endef
  172. define Image/mkfs/jffs2/sub
  173. $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
  174. $(call add_jffs2_mark,$@)
  175. endef
  176. define Image/mkfs/jffs2/template
  177. Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(JFFS2OPTS),$$(1))
  178. Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(JFFS2OPTS),$$(1))
  179. endef
  180. define Image/mkfs/jffs2-nand/template
  181. Image/mkfs/jffs2-nand-$(1) = \
  182. $$(call Image/mkfs/jffs2/sub, \
  183. $(word 2,$(subst -, ,$(1))), \
  184. $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))),$$(1))
  185. endef
  186. $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
  187. $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
  188. define Image/mkfs/squashfs
  189. $(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
  190. -nopad -noappend -root-owned \
  191. -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) \
  192. -processors 1
  193. endef
  194. # $(1): board name
  195. # $(2): rootfs type
  196. # $(3): kernel image
  197. # $(4): compat string
  198. ifneq ($(CONFIG_NAND_SUPPORT),)
  199. define Image/Build/SysupgradeNAND
  200. mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
  201. echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
  202. [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
  203. [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
  204. (cd "$(KDIR_TMP)"; $(TAR) cvf \
  205. "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
  206. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  207. )
  208. endef
  209. # $(1) board name
  210. # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
  211. # $(3) rootfstype (e.g. squashfs or ubifs)
  212. # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
  213. define Image/Build/UbinizeImage
  214. sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
  215. "$(KDIR)/root.$(3)" \
  216. "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
  217. $(4)
  218. endef
  219. endif
  220. define Image/mkfs/ubifs
  221. $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
  222. $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
  223. $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
  224. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
  225. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
  226. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
  227. $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
  228. --squash-uids \
  229. -o $@ -d $(call mkfs_target_dir,$(1))
  230. endef
  231. E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
  232. define Image/mkfs/ext4
  233. $(STAGING_DIR_HOST)/bin/make_ext4fs \
  234. -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
  235. $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
  236. $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
  237. $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
  238. $@ $(call mkfs_target_dir,$(1))/
  239. endef
  240. define Image/Manifest
  241. $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
  242. $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
  243. endef
  244. ifdef CONFIG_TARGET_ROOTFS_TARGZ
  245. define Image/Build/targz
  246. $(TAR) -cp --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name \
  247. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  248. -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
  249. endef
  250. endif
  251. ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
  252. define Image/Build/cpiogz
  253. ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
  254. endef
  255. endif
  256. mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
  257. mkfs_packages_add = $(foreach pkg,$(filter-out -%,$(mkfs_packages)),$(pkg)$(call GetABISuffix,$(pkg)))
  258. mkfs_packages_remove = $(foreach pkg,$(patsubst -%,%,$(filter -%,$(mkfs_packages))),$(pkg)$(call GetABISuffix,$(pkg)))
  259. mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
  260. opkg_target = \
  261. $(call opkg,$(mkfs_cur_target_dir)) \
  262. -f $(mkfs_cur_target_dir).conf
  263. target-dir-%: FORCE
  264. rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
  265. $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
  266. -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
  267. echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
  268. $(if $(mkfs_packages_remove), \
  269. -$(call opkg,$(mkfs_cur_target_dir)) remove \
  270. $(mkfs_packages_remove))
  271. $(if $(call opkg_package_files,$(mkfs_packages_add)), \
  272. $(opkg_target) update && \
  273. $(opkg_target) install \
  274. $(call opkg_package_files,$(mkfs_packages_add)))
  275. -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
  276. rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
  277. $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
  278. $(KDIR)/root.%: kernel_prepare
  279. $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
  280. define Device/InitProfile
  281. PROFILES := $(PROFILE)
  282. DEVICE_TITLE :=
  283. DEVICE_PACKAGES :=
  284. DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
  285. endef
  286. define Device/Init
  287. DEVICE_NAME := $(1)
  288. KERNEL:=
  289. KERNEL_INITRAMFS = $$(KERNEL)
  290. KERNEL_SIZE:=
  291. CMDLINE:=
  292. IMAGES :=
  293. ARTIFACTS :=
  294. IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
  295. IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
  296. KERNEL_PREFIX = $$(IMAGE_PREFIX)
  297. KERNEL_SUFFIX := -kernel.bin
  298. KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
  299. KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
  300. KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
  301. KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
  302. KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
  303. KERNEL_INSTALL :=
  304. KERNEL_NAME := vmlinux
  305. KERNEL_DEPENDS :=
  306. KERNEL_SIZE :=
  307. UBOOTENV_IN_UBI :=
  308. KERNEL_IN_UBI :=
  309. BLOCKSIZE :=
  310. PAGESIZE :=
  311. SUBPAGESIZE :=
  312. VID_HDR_OFFSET :=
  313. UBINIZE_OPTS :=
  314. UBINIZE_PARTS :=
  315. MKUBIFS_OPTS :=
  316. FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
  317. DEVICE_DTS :=
  318. DEVICE_DTS_CONFIG :=
  319. DEVICE_DTS_DIR :=
  320. BOARD_NAME :=
  321. UIMAGE_NAME :=
  322. SUPPORTED_DEVICES :=
  323. IMAGE_METADATA :=
  324. FILESYSTEMS := $(TARGET_FILESYSTEMS)
  325. UBOOT_PATH := $(STAGING_DIR_IMAGE)/uboot-$(1)
  326. DEFAULT :=
  327. endef
  328. DEFAULT_DEVICE_VARS := \
  329. DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
  330. CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
  331. VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
  332. DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME UIMAGE_NAME SUPPORTED_DEVICES \
  333. IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR UBOOT_PATH
  334. define Device/ExportVar
  335. $(1) : $(2):=$$($(2))
  336. endef
  337. define Device/Export
  338. $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
  339. $(1) : FILESYSTEM:=$(2)
  340. endef
  341. ifdef IB
  342. DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
  343. else
  344. DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
  345. endif
  346. DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
  347. define merge_packages
  348. $(1) :=
  349. $(foreach pkg,$(2),
  350. $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
  351. )
  352. endef
  353. define Device/Check/Common
  354. _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
  355. DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
  356. ifdef TARGET_PER_DEVICE_ROOTFS
  357. $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
  358. ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
  359. PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
  360. endif
  361. endef
  362. define Device/Check
  363. $(Device/Check/Common)
  364. KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
  365. _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
  366. ifndef IB
  367. _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
  368. endif
  369. endef
  370. ifndef IB
  371. define Device/Build/initramfs
  372. $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
  373. $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
  374. $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
  375. $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
  376. cp $$^ $$@
  377. $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  378. @rm -f $$@
  379. $$(call concat_cmd,$$(KERNEL_INITRAMFS))
  380. endef
  381. endif
  382. define Device/Build/compile
  383. $$(_COMPILE_TARGET): $(KDIR)/$(1)
  384. $(eval $(call Device/Export,$(KDIR)/$(1)))
  385. $(KDIR)/$(1):
  386. $$(call concat_cmd,$(COMPILE/$(1)))
  387. endef
  388. ifndef IB
  389. define Device/Build/dtb
  390. ifndef BUILD_DTS_$(1)
  391. BUILD_DTS_$(1) := 1
  392. $(KDIR)/image-$(1).dtb: FORCE
  393. $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
  394. image_prepare: $(KDIR)/image-$(1).dtb
  395. endif
  396. endef
  397. endif
  398. define Device/Build/kernel
  399. $$(eval $$(foreach dts,$$(DEVICE_DTS), \
  400. $$(call Device/Build/dtb,$$(notdir $$(dts)), \
  401. $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
  402. $$(dts) \
  403. ) \
  404. ))
  405. $(KDIR)/$$(KERNEL_NAME):: image_prepare
  406. $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
  407. $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
  408. $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
  409. cp $$^ $$@
  410. ifndef IB
  411. ifdef CONFIG_IB
  412. install: $$(KDIR_KERNEL_IMAGE)
  413. endif
  414. $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  415. @rm -f $$@
  416. $$(call concat_cmd,$$(KERNEL))
  417. $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
  418. endif
  419. endef
  420. define Device/Build/image
  421. GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  422. $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
  423. $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
  424. ROOTFS/$(1)/$(3) := \
  425. $(KDIR)/root.$(1)$$(strip \
  426. $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
  427. )$$(strip \
  428. $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
  429. )
  430. ifndef IB
  431. $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
  432. endif
  433. $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
  434. @rm -f $$@
  435. [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
  436. $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
  437. .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
  438. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  439. gzip -c -9n $$^ > $$@
  440. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  441. cp $$^ $$@
  442. endef
  443. define Device/Build/artifact
  444. $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
  445. $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
  446. $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
  447. @rm -f $$@
  448. $$(call concat_cmd,$(ARTIFACT/$(1)))
  449. .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
  450. $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
  451. cp $$^ $$@
  452. endef
  453. define Device/Build
  454. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
  455. $(call Device/Build/kernel,$(1))
  456. $$(eval $$(foreach compile,$$(COMPILE), \
  457. $$(call Device/Build/compile,$$(compile),$(1))))
  458. $$(eval $$(foreach image,$$(IMAGES), \
  459. $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
  460. $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
  461. $$(eval $$(foreach artifact,$$(ARTIFACTS), \
  462. $$(call Device/Build/artifact,$$(artifact))))
  463. endef
  464. define Device/DumpInfo
  465. Target-Profile: DEVICE_$(1)
  466. Target-Profile-Name: $(DEVICE_TITLE)
  467. Target-Profile-Packages: $(DEVICE_PACKAGES)
  468. Target-Profile-hasImageMetadata: $(if $(foreach image,$(IMAGES),$(findstring append-metadata,$(IMAGE/$(image)))),1,0)
  469. Target-Profile-SupportedDevices: $(SUPPORTED_DEVICES)
  470. $(if $(DEFAULT),Target-Profile-Default: $(DEFAULT))
  471. Target-Profile-Description:
  472. $(DEVICE_DESCRIPTION)
  473. @@
  474. endef
  475. define Device/Dump
  476. $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
  477. endef
  478. define Device
  479. $(call Device/InitProfile,$(1))
  480. $(call Device/Init,$(1))
  481. $(call Device/Default,$(1))
  482. $(call Device/$(1),$(1))
  483. $(call Device/Check,$(1))
  484. $(call Device/$(if $(DUMP),Dump,Build),$(1))
  485. endef
  486. define BuildImage
  487. ifneq ($(DUMP),)
  488. all: dumpinfo
  489. dumpinfo: FORCE
  490. @true
  491. endif
  492. download:
  493. prepare:
  494. compile:
  495. clean:
  496. legacy-images-prepare:
  497. legacy-images:
  498. image_prepare:
  499. ifeq ($(IB),)
  500. .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
  501. compile:
  502. $(call Build/Compile)
  503. clean:
  504. $(call Build/Clean)
  505. image_prepare: compile
  506. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  507. $(call Image/Prepare)
  508. legacy-images-prepare-make: image_prepare
  509. $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
  510. else
  511. image_prepare:
  512. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  513. endif
  514. kernel_prepare: image_prepare
  515. $(call Image/Build/targz)
  516. $(call Image/Build/cpiogz)
  517. $(call Image/BuildKernel)
  518. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
  519. $(call Image/InstallKernel)
  520. $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
  521. $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
  522. install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
  523. $(foreach fs,$(TARGET_FILESYSTEMS),
  524. $(call Image/Build,$(fs))
  525. )
  526. legacy-images-make: install-images
  527. $(call Image/mkfs/ubifs/legacy)
  528. $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
  529. install: install-images
  530. $(call Image/Manifest)
  531. endef