image.mk 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
  271. IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
  272. KERNEL_PREFIX = $$(IMAGE_PREFIX)
  273. KERNEL_SUFFIX := -kernel.bin
  274. KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
  275. KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
  276. KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
  277. KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
  278. KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
  279. KERNEL_INSTALL :=
  280. KERNEL_NAME := vmlinux
  281. KERNEL_DEPENDS :=
  282. KERNEL_SIZE :=
  283. UBOOTENV_IN_UBI :=
  284. KERNEL_IN_UBI :=
  285. BLOCKSIZE :=
  286. PAGESIZE :=
  287. SUBPAGESIZE :=
  288. VID_HDR_OFFSET :=
  289. UBINIZE_OPTS :=
  290. UBINIZE_PARTS :=
  291. MKUBIFS_OPTS :=
  292. FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
  293. DEVICE_DTS :=
  294. DEVICE_DTS_CONFIG :=
  295. DEVICE_DTS_DIR :=
  296. BOARD_NAME :=
  297. UIMAGE_NAME :=
  298. SUPPORTED_DEVICES :=
  299. IMAGE_METADATA :=
  300. FILESYSTEMS := $(TARGET_FILESYSTEMS)
  301. endef
  302. DEFAULT_DEVICE_VARS := \
  303. DEVICE_NAME KERNEL KERNEL_INITRAMFS KERNEL_SIZE KERNEL_INITRAMFS_IMAGE \
  304. KERNEL_LOADADDR DEVICE_DTS DEVICE_DTS_CONFIG DEVICE_DTS_DIR BOARD_NAME \
  305. CMDLINE UBOOTENV_IN_UBI KERNEL_IN_UBI \
  306. BLOCKSIZE PAGESIZE SUBPAGESIZE VID_HDR_OFFSET \
  307. UBINIZE_OPTS UIMAGE_NAME UBINIZE_PARTS \
  308. SUPPORTED_DEVICES IMAGE_METADATA
  309. define Device/ExportVar
  310. $(1) : $(2):=$$($(2))
  311. endef
  312. define Device/Export
  313. $(foreach var,$(DEVICE_VARS) $(DEFAULT_DEVICE_VARS),$(call Device/ExportVar,$(1),$(var)))
  314. $(1) : FILESYSTEM:=$(2)
  315. endef
  316. ifdef IB
  317. DEVICE_CHECK_PROFILE = $(filter $(1),DEVICE_$(PROFILE) $(PROFILE))
  318. else
  319. DEVICE_CHECK_PROFILE = $(CONFIG_TARGET_$(if $(CONFIG_TARGET_MULTI_PROFILE),DEVICE_)$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_$(1))
  320. endif
  321. DEVICE_EXTRA_PACKAGES = $(call qstrip,$(CONFIG_TARGET_DEVICE_PACKAGES_$(call target_conf,$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET)))_DEVICE_$(1)))
  322. define merge_packages
  323. $(1) :=
  324. $(foreach pkg,$(2),
  325. $(1) := $$(strip $$(filter-out -$$(patsubst -%,%,$(pkg)) $$(patsubst -%,%,$(pkg)),$$($(1))) $(pkg))
  326. )
  327. endef
  328. define Device/Check/Common
  329. _PROFILE_SET = $$(strip $$(foreach profile,$$(PROFILES) DEVICE_$(1),$$(call DEVICE_CHECK_PROFILE,$$(profile))))
  330. ifdef TARGET_PER_DEVICE_ROOTFS
  331. $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
  332. ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
  333. PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
  334. endif
  335. endef
  336. define Device/Check
  337. $(Device/Check/Common)
  338. KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
  339. _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
  340. ifndef IB
  341. _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
  342. endif
  343. endef
  344. ifndef IB
  345. define Device/Build/initramfs
  346. $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
  347. $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
  348. $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
  349. $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
  350. cp $$^ $$@
  351. $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  352. @rm -f $$@
  353. $$(call concat_cmd,$$(KERNEL_INITRAMFS))
  354. endef
  355. endif
  356. define Device/Build/compile
  357. $$(_COMPILE_TARGET): $(KDIR)/$(1)
  358. $(eval $(call Device/Export,$(KDIR)/$(1)))
  359. $(KDIR)/$(1):
  360. $$(call concat_cmd,$(COMPILE/$(1)))
  361. endef
  362. ifndef IB
  363. define Device/Build/dtb
  364. ifndef BUILD_DTS_$(1)
  365. BUILD_DTS_$(1) := 1
  366. $(KDIR)/image-$(1).dtb: FORCE
  367. $(call Image/BuildDTB,$(strip $(2))/$(strip $(3)).dts,$$@)
  368. image_prepare: $(KDIR)/image-$(1).dtb
  369. endif
  370. endef
  371. endif
  372. define Device/Build/kernel
  373. $$(eval $$(foreach dts,$$(DEVICE_DTS), \
  374. $$(call Device/Build/dtb,$$(notdir $$(dts)), \
  375. $$(if $$(DEVICE_DTS_DIR),$$(DEVICE_DTS_DIR),$$(DTS_DIR)), \
  376. $$(dts) \
  377. ) \
  378. ))
  379. $(KDIR)/$$(KERNEL_NAME):: image_prepare
  380. $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
  381. $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
  382. $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
  383. cp $$^ $$@
  384. ifndef IB
  385. ifdef CONFIG_IB
  386. install: $$(KDIR_KERNEL_IMAGE)
  387. endif
  388. $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare
  389. @rm -f $$@
  390. $$(call concat_cmd,$$(KERNEL))
  391. $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
  392. endif
  393. endef
  394. define Device/Build/image
  395. GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  396. $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
  397. $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
  398. ROOTFS/$(1)/$(3) := \
  399. $(KDIR)/root.$(1)$$(strip \
  400. $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
  401. )$$(strip \
  402. $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
  403. )
  404. ifndef IB
  405. $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
  406. endif
  407. $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
  408. @rm -f $$@
  409. [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
  410. $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
  411. .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
  412. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  413. gzip -c -9n $$^ > $$@
  414. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  415. cp $$^ $$@
  416. endef
  417. define Device/Build
  418. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
  419. $(call Device/Build/kernel,$(1))
  420. $$(eval $$(foreach compile,$$(COMPILE), \
  421. $$(call Device/Build/compile,$$(compile),$(1))))
  422. $$(eval $$(foreach image,$$(IMAGES), \
  423. $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
  424. $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
  425. endef
  426. define Device/DumpInfo
  427. Target-Profile: DEVICE_$(1)
  428. Target-Profile-Name: $(DEVICE_TITLE)
  429. Target-Profile-Packages: $(DEVICE_PACKAGES)
  430. Target-Profile-Description:
  431. $(DEVICE_DESCRIPTION)
  432. @@
  433. endef
  434. define Device/Dump
  435. $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
  436. endef
  437. define Device
  438. $(call Device/InitProfile,$(1))
  439. $(call Device/Init,$(1))
  440. $(call Device/Default,$(1))
  441. $(call Device/$(1),$(1))
  442. $(call Device/Check,$(1))
  443. $(call Device/$(if $(DUMP),Dump,Build),$(1))
  444. endef
  445. define BuildImage
  446. ifneq ($(DUMP),)
  447. all: dumpinfo
  448. dumpinfo: FORCE
  449. @true
  450. endif
  451. download:
  452. prepare:
  453. compile:
  454. clean:
  455. legacy-images-prepare:
  456. legacy-images:
  457. image_prepare:
  458. ifeq ($(IB),)
  459. .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
  460. compile:
  461. $(call Build/Compile)
  462. clean:
  463. $(call Build/Clean)
  464. image_prepare: compile
  465. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  466. $(call Image/Prepare)
  467. legacy-images-prepare-make: image_prepare
  468. $(MAKE) legacy-images-prepare
  469. else
  470. image_prepare:
  471. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  472. endif
  473. kernel_prepare: image_prepare
  474. $(call Image/Build/targz)
  475. $(call Image/Build/cpiogz)
  476. $(call Image/BuildKernel)
  477. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
  478. $(call Image/InstallKernel)
  479. $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
  480. $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
  481. install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
  482. $(foreach fs,$(TARGET_FILESYSTEMS),
  483. $(call Image/Build,$(fs))
  484. )
  485. legacy-images-make: install-images
  486. $(call Image/mkfs/ubifs/legacy)
  487. $(MAKE) legacy-images
  488. install: install-images
  489. $(call Image/Manifest)
  490. endef