image.mk 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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. # $(1) source dts file
  126. # $(2) target dtb file
  127. # $(3) extra CPP flags
  128. # $(4) extra DTC flags
  129. define Image/BuildDTB
  130. $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
  131. -I$(DTS_DIR) \
  132. -I$(DTS_DIR)/include \
  133. -I$(LINUX_DIR)/include/ \
  134. -undef -D__DTS__ $(3) \
  135. -o $(2).tmp $(1)
  136. $(LINUX_DIR)/scripts/dtc/dtc -O dtb \
  137. -i$(dir $(1)) $(4) \
  138. -o $(2) $(2).tmp
  139. $(RM) $(2).tmp
  140. endef
  141. define Image/mkfs/jffs2/sub-raw
  142. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
  143. $(2) \
  144. -e $(patsubst %k,%KiB,$(1)) \
  145. -o $@ -d $(call mkfs_target_dir,$(3)) \
  146. -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
  147. endef
  148. define Image/mkfs/jffs2/sub
  149. $(call Image/mkfs/jffs2/sub-raw,$(1),--pad $(2),$(3))
  150. $(call add_jffs2_mark,$@)
  151. endef
  152. define Image/mkfs/jffs2/template
  153. Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(JFFS2OPTS),$$(1))
  154. Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(JFFS2OPTS),$$(1))
  155. endef
  156. define Image/mkfs/jffs2-nand/template
  157. Image/mkfs/jffs2-nand-$(1) = \
  158. $$(call Image/mkfs/jffs2/sub, \
  159. $(word 2,$(subst -, ,$(1))), \
  160. $(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))),$$(1))
  161. endef
  162. $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
  163. $(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
  164. define Image/mkfs/squashfs
  165. $(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
  166. -nopad -noappend -root-owned \
  167. -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) \
  168. -processors 1 \
  169. $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
  170. endef
  171. # $(1): board name
  172. # $(2): rootfs type
  173. # $(3): kernel image
  174. # $(4): compat string
  175. ifneq ($(CONFIG_NAND_SUPPORT),)
  176. define Image/Build/SysupgradeNAND
  177. mkdir -p "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/"
  178. echo "BOARD=$(if $(4),$(4),$(1))" > "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/CONTROL"
  179. [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/root"
  180. [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(if $(4),$(4),$(1))/kernel"
  181. (cd "$(KDIR_TMP)"; $(TAR) cvf \
  182. "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(if $(4),$(4),$(1)) \
  183. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  184. )
  185. endef
  186. # $(1) board name
  187. # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
  188. # $(3) rootfstype (e.g. squashfs or ubifs)
  189. # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
  190. define Image/Build/UbinizeImage
  191. sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
  192. "$(KDIR)/root.$(3)" \
  193. "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
  194. $(4)
  195. endef
  196. endif
  197. define Image/mkfs/ubifs
  198. $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
  199. $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
  200. $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
  201. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
  202. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
  203. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
  204. $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
  205. --squash-uids \
  206. -o $@ -d $(call mkfs_target_dir,$(1))
  207. endef
  208. E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
  209. define Image/mkfs/ext4
  210. $(STAGING_DIR_HOST)/bin/make_ext4fs \
  211. -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
  212. $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
  213. $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
  214. $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
  215. $@ $(call mkfs_target_dir,$(1))/
  216. endef
  217. define Image/Manifest
  218. $(call opkg,$(TARGET_DIR_ORIG)) list-installed > \
  219. $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
  220. endef
  221. ifdef CONFIG_TARGET_ROOTFS_TARGZ
  222. define Image/Build/targz
  223. $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
  224. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  225. -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
  226. endef
  227. endif
  228. ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
  229. define Image/Build/cpiogz
  230. ( cd $(TARGET_DIR); find . | cpio -o -H newc -R root:root | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
  231. endef
  232. endif
  233. mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
  234. mkfs_packages_add = $(filter-out -%,$(mkfs_packages))
  235. mkfs_packages_remove = $(patsubst -%,%,$(filter -%,$(mkfs_packages)))
  236. mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
  237. opkg_target = \
  238. $(call opkg,$(mkfs_cur_target_dir)) \
  239. -f $(mkfs_cur_target_dir).conf
  240. target-dir-%: FORCE
  241. rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
  242. $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
  243. -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
  244. echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
  245. $(if $(mkfs_packages_remove), \
  246. -$(call opkg,$(mkfs_cur_target_dir)) remove \
  247. $(mkfs_packages_remove))
  248. $(if $(call opkg_package_files,$(mkfs_packages_add)), \
  249. $(opkg_target) update && \
  250. $(opkg_target) install \
  251. $(call opkg_package_files,$(mkfs_packages_add)))
  252. -$(CP) -T $(mkfs_cur_target_dir).opkg/ $(mkfs_cur_target_dir)/etc/opkg/
  253. rm -rf $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir).conf
  254. $(call prepare_rootfs,$(mkfs_cur_target_dir),$(TOPDIR)/files)
  255. $(KDIR)/root.%: kernel_prepare
  256. $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
  257. define Device/InitProfile
  258. PROFILES := $(PROFILE)
  259. DEVICE_TITLE :=
  260. DEVICE_PACKAGES :=
  261. DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
  262. endef
  263. define Device/Init
  264. DEVICE_NAME := $(1)
  265. KERNEL:=
  266. KERNEL_INITRAMFS = $$(KERNEL)
  267. KERNEL_SIZE:=
  268. CMDLINE:=
  269. IMAGES :=
  270. ARTIFACTS :=
  271. IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
  272. IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
  273. KERNEL_PREFIX = $$(IMAGE_PREFIX)
  274. KERNEL_SUFFIX := -kernel.bin
  275. KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
  276. KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
  277. KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
  278. KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
  279. KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
  280. KERNEL_INSTALL :=
  281. KERNEL_NAME := vmlinux
  282. KERNEL_DEPENDS :=
  283. KERNEL_SIZE :=
  284. UBOOTENV_IN_UBI :=
  285. KERNEL_IN_UBI :=
  286. BLOCKSIZE :=
  287. PAGESIZE :=
  288. SUBPAGESIZE :=
  289. VID_HDR_OFFSET :=
  290. UBINIZE_OPTS :=
  291. UBINIZE_PARTS :=
  292. MKUBIFS_OPTS :=
  293. FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
  294. DEVICE_DTS :=
  295. DEVICE_DTS_CONFIG :=
  296. DEVICE_DTS_DIR :=
  297. BOARD_NAME :=
  298. UIMAGE_NAME :=
  299. SUPPORTED_DEVICES :=
  300. IMAGE_METADATA :=
  301. FILESYSTEMS := $(TARGET_FILESYSTEMS)
  302. endef
  303. DEFAULT_DEVICE_VARS := \
  304. DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_SIZE KERNEL_INITRAMFS_IMAGE \
  305. KERNEL_LOADADDR DEVICE_DTS DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME \
  306. CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI \
  307. BLOCKSIZE PAGESIZE SUBPAGESIZE VID_HDR_OFFSET \
  308. UBINIZE_OPTS UIMAGE_NAME UBINIZE_PARTS \
  309. SUPPORTED_DEVICES IMAGE_METADATA
  310. define Device/ExportVar
  311. $(1) : $(2):=$$($(2))
  312. endef
  313. define Device/Export
  314. $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
  315. $(1) : FILESYSTEM:=$(2)
  316. endef
  317. ifdef IB
  318. DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
  319. else
  320. DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
  321. endif
  322. DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
  323. define merge_packages
  324. $(1) :=
  325. $(foreach pkg,$(2),
  326. $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
  327. )
  328. endef
  329. define Device/Check/Common
  330. _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
  331. DEVICE_PACKAGES += $$(call extra_packages,$$(DEVICE_PACKAGES))
  332. ifdef TARGET_PER_DEVICE_ROOTFS
  333. $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
  334. ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
  335. PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
  336. endif
  337. endef
  338. define Device/Check
  339. $(Device/Check/Common)
  340. KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
  341. _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
  342. ifndef IB
  343. _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
  344. endif
  345. endef
  346. ifndef IB
  347. define Device/Build/initramfs
  348. $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
  349. $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
  350. $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
  351. $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
  352. cp $$^ $$@
  353. $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  354. @rm -f $$@
  355. $$(call concat_cmd,$$(KERNEL_INITRAMFS))
  356. endef
  357. endif
  358. define Device/Build/compile
  359. $$(_COMPILE_TARGET): $(KDIR)/$(1)
  360. $(eval $(call Device/Export,$(KDIR)/$(1)))
  361. $(KDIR)/$(1):
  362. $$(call concat_cmd,$(COMPILE/$(1)))
  363. endef
  364. ifndef IB
  365. define Device/Build/dtb
  366. ifndef BUILD_DTS_$(1)
  367. BUILD_DTS_$(1) := 1
  368. $(KDIR)/image-$(1).dtb: FORCE
  369. $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
  370. image_prepare: $(KDIR)/image-$(1).dtb
  371. endif
  372. endef
  373. endif
  374. define Device/Build/kernel
  375. $$(eval $$(foreach dts,$$(DEVICE_DTS), \
  376. $$(call Device/Build/dtb,$$(notdir $$(dts)), \
  377. $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
  378. $$(dts) \
  379. ) \
  380. ))
  381. $(KDIR)/$$(KERNEL_NAME):: image_prepare
  382. $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
  383. $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
  384. $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
  385. cp $$^ $$@
  386. ifndef IB
  387. ifdef CONFIG_IB
  388. install: $$(KDIR_KERNEL_IMAGE)
  389. endif
  390. $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  391. @rm -f $$@
  392. $$(call concat_cmd,$$(KERNEL))
  393. $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
  394. endif
  395. endef
  396. define Device/Build/image
  397. GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  398. $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
  399. $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
  400. ROOTFS/$(1)/$(3) := \
  401. $(KDIR)/root.$(1)$$(strip \
  402. $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
  403. )$$(strip \
  404. $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
  405. )
  406. ifndef IB
  407. $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
  408. endif
  409. $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
  410. @rm -f $$@
  411. [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
  412. $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
  413. .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
  414. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  415. gzip -c -9n $$^ > $$@
  416. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  417. cp $$^ $$@
  418. endef
  419. define Device/Build/artifact
  420. $$(_TARGET): $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
  421. $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1): $$(KDIR_KERNEL_IMAGE)
  422. @rm -f $$@
  423. $$(call concat_cmd,$(ARTIFACT/$(1)))
  424. .IGNORE: $(BIN_DIR)/$(IMAGE_PREFIX)-$(1)
  425. $(BIN_DIR)/$(IMAGE_PREFIX)-$(1): $(KDIR)/tmp/$(IMAGE_PREFIX)-$(1)
  426. cp $$^ $$@
  427. endef
  428. define Device/Build
  429. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
  430. $(call Device/Build/kernel,$(1))
  431. $$(eval $$(foreach compile,$$(COMPILE), \
  432. $$(call Device/Build/compile,$$(compile),$(1))))
  433. $$(eval $$(foreach image,$$(IMAGES), \
  434. $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
  435. $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
  436. $$(eval $$(foreach artifact,$$(ARTIFACTS), \
  437. $$(call Device/Build/artifact,$$(artifact))))
  438. endef
  439. define Device/DumpInfo
  440. Target-Profile: DEVICE_$(1)
  441. Target-Profile-Name: $(DEVICE_TITLE)
  442. Target-Profile-Packages: $(DEVICE_PACKAGES)
  443. Target-Profile-Description:
  444. $(DEVICE_DESCRIPTION)
  445. @@
  446. endef
  447. define Device/Dump
  448. $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
  449. endef
  450. define Device
  451. $(call Device/InitProfile,$(1))
  452. $(call Device/Init,$(1))
  453. $(call Device/Default,$(1))
  454. $(call Device/$(1),$(1))
  455. $(call Device/Check,$(1))
  456. $(call Device/$(if $(DUMP),Dump,Build),$(1))
  457. endef
  458. define BuildImage
  459. ifneq ($(DUMP),)
  460. all: dumpinfo
  461. dumpinfo: FORCE
  462. @true
  463. endif
  464. download:
  465. prepare:
  466. compile:
  467. clean:
  468. legacy-images-prepare:
  469. legacy-images:
  470. image_prepare:
  471. ifeq ($(IB),)
  472. .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
  473. compile:
  474. $(call Build/Compile)
  475. clean:
  476. $(call Build/Clean)
  477. image_prepare: compile
  478. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  479. $(call Image/Prepare)
  480. legacy-images-prepare-make: image_prepare
  481. $(MAKE) legacy-images-prepare
  482. else
  483. image_prepare:
  484. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  485. endif
  486. kernel_prepare: image_prepare
  487. $(call Image/Build/targz)
  488. $(call Image/Build/cpiogz)
  489. $(call Image/BuildKernel)
  490. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
  491. $(call Image/InstallKernel)
  492. $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
  493. $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
  494. install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
  495. $(foreach fs,$(TARGET_FILESYSTEMS),
  496. $(call Image/Build,$(fs))
  497. )
  498. legacy-images-make: install-images
  499. $(call Image/mkfs/ubifs/legacy)
  500. $(MAKE) legacy-images
  501. install: install-images
  502. $(call Image/Manifest)
  503. endef