1
0

image.mk 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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.6.0)),1)
  127. DTC_FLAGS += -Wno-unit_address_vs_reg
  128. endif
  129. ifeq ($(strip $(call kernel_patchver_ge,4.11.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.16.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.17.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 --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. endef
  326. DEFAULT_DEVICE_VARS := \
  327. DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_INITRAMFS_IMAGE KERNEL_SIZE \
  328. CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI BLOCKSIZE PAGESIZE SUBPAGESIZE \
  329. VID_HDR_OFFSET UBINIZE_OPTS UBINIZE_PARTS MKUBIFS_OPTS DEVICE_DTS \
  330. DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME UIMAGE_NAME SUPPORTED_DEVICES \
  331. IMAGE_METADATA KERNEL_ENTRY KERNEL_LOADADDR
  332. define Device/ExportVar
  333. $(1) : $(2):=$$($(2))
  334. endef
  335. define Device/Export
  336. $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
  337. $(1) : FILESYSTEM:=$(2)
  338. endef
  339. ifdef IB
  340. DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
  341. else
  342. DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
  343. endif
  344. DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
  345. define merge_packages
  346. $(1) :=
  347. $(foreach pkg,$(2),
  348. $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
  349. )
  350. endef
  351. define Device/Check/Common
  352. _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
  353. DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
  354. ifdef TARGET_PER_DEVICE_ROOTFS
  355. $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
  356. ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
  357. PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
  358. endif
  359. endef
  360. define Device/Check
  361. $(Device/Check/Common)
  362. KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
  363. _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
  364. ifndef IB
  365. _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
  366. endif
  367. endef
  368. ifndef IB
  369. define Device/Build/initramfs
  370. $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
  371. $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
  372. $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
  373. $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
  374. cp $$^ $$@
  375. $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  376. @rm -f $$@
  377. $$(call concat_cmd,$$(KERNEL_INITRAMFS))
  378. endef
  379. endif
  380. define Device/Build/compile
  381. $$(_COMPILE_TARGET): $(KDIR)/$(1)
  382. $(eval $(call Device/Export,$(KDIR)/$(1)))
  383. $(KDIR)/$(1):
  384. $$(call concat_cmd,$(COMPILE/$(1)))
  385. endef
  386. ifndef IB
  387. define Device/Build/dtb
  388. ifndef BUILD_DTS_$(1)
  389. BUILD_DTS_$(1) := 1
  390. $(KDIR)/image-$(1).dtb: FORCE
  391. $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
  392. image_prepare: $(KDIR)/image-$(1).dtb
  393. endif
  394. endef
  395. endif
  396. define Device/Build/kernel
  397. $$(eval $$(foreach dts,$$(DEVICE_DTS), \
  398. $$(call Device/Build/dtb,$$(notdir $$(dts)), \
  399. $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
  400. $$(dts) \
  401. ) \
  402. ))
  403. $(KDIR)/$$(KERNEL_NAME):: image_prepare
  404. $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
  405. $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
  406. $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
  407. cp $$^ $$@
  408. ifndef IB
  409. ifdef CONFIG_IB
  410. install: $$(KDIR_KERNEL_IMAGE)
  411. endif
  412. $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  413. @rm -f $$@
  414. $$(call concat_cmd,$$(KERNEL))
  415. $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
  416. endif
  417. endef
  418. define Device/Build/image
  419. GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  420. $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
  421. $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
  422. ROOTFS/$(1)/$(3) := \
  423. $(KDIR)/root.$(1)$$(strip \
  424. $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
  425. )$$(strip \
  426. $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
  427. )
  428. ifndef IB
  429. $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
  430. endif
  431. $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
  432. @rm -f $$@
  433. [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
  434. $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
  435. .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
  436. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  437. gzip -c -9n $$^ > $$@
  438. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  439. cp $$^ $$@
  440. endef
  441. define Device/Build/artifact
  442. $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
  443. $(eval $(call Device/Export,$(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)))
  444. $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
  445. @rm -f $$@
  446. $$(call concat_cmd,$(ARTIFACT/$(1)))
  447. .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
  448. $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
  449. cp $$^ $$@
  450. endef
  451. define Device/Build
  452. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
  453. $(call Device/Build/kernel,$(1))
  454. $$(eval $$(foreach compile,$$(COMPILE), \
  455. $$(call Device/Build/compile,$$(compile),$(1))))
  456. $$(eval $$(foreach image,$$(IMAGES), \
  457. $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
  458. $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
  459. $$(eval $$(foreach artifact,$$(ARTIFACTS), \
  460. $$(call Device/Build/artifact,$$(artifact))))
  461. endef
  462. define Device/DumpInfo
  463. Target-Profile: DEVICE_$(1)
  464. Target-Profile-Name: $(DEVICE_TITLE)
  465. Target-Profile-Packages: $(DEVICE_PACKAGES)
  466. Target-Profile-Description:
  467. $(DEVICE_DESCRIPTION)
  468. @@
  469. endef
  470. define Device/Dump
  471. $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
  472. endef
  473. define Device
  474. $(call Device/InitProfile,$(1))
  475. $(call Device/Init,$(1))
  476. $(call Device/Default,$(1))
  477. $(call Device/$(1),$(1))
  478. $(call Device/Check,$(1))
  479. $(call Device/$(if $(DUMP),Dump,Build),$(1))
  480. endef
  481. define BuildImage
  482. ifneq ($(DUMP),)
  483. all: dumpinfo
  484. dumpinfo: FORCE
  485. @true
  486. endif
  487. download:
  488. prepare:
  489. compile:
  490. clean:
  491. legacy-images-prepare:
  492. legacy-images:
  493. image_prepare:
  494. ifeq ($(IB),)
  495. .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
  496. compile:
  497. $(call Build/Compile)
  498. clean:
  499. $(call Build/Clean)
  500. image_prepare: compile
  501. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  502. $(call Image/Prepare)
  503. legacy-images-prepare-make: image_prepare
  504. $(MAKE) legacy-images-prepare BIN_DIR="$(BIN_DIR)"
  505. else
  506. image_prepare:
  507. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  508. endif
  509. kernel_prepare: image_prepare
  510. $(call Image/Build/targz)
  511. $(call Image/Build/cpiogz)
  512. $(call Image/BuildKernel)
  513. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
  514. $(call Image/InstallKernel)
  515. $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
  516. $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
  517. install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
  518. $(foreach fs,$(TARGET_FILESYSTEMS),
  519. $(call Image/Build,$(fs))
  520. )
  521. legacy-images-make: install-images
  522. $(call Image/mkfs/ubifs/legacy)
  523. $(MAKE) legacy-images BIN_DIR="$(BIN_DIR)"
  524. install: install-images
  525. $(call Image/Manifest)
  526. endef