image.mk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  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)/host.mk
  11. include $(INCLUDE_DIR)/version.mk
  12. include $(INCLUDE_DIR)/image-commands.mk
  13. ifndef IB
  14. ifdef CONFIG_TARGET_PER_DEVICE_ROOTFS
  15. TARGET_PER_DEVICE_ROOTFS := 1
  16. endif
  17. endif
  18. include $(INCLUDE_DIR)/image-legacy.mk
  19. ifdef TARGET_PER_DEVICE_ROOTFS
  20. include $(INCLUDE_DIR)/rootfs.mk
  21. endif
  22. override MAKE:=$(_SINGLE)$(SUBMAKE)
  23. override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
  24. target_params = $(subst +,$(space),$*)
  25. param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
  26. param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))
  27. param_mangle = $(subst $(space),_,$(strip $(1)))
  28. param_unmangle = $(subst _,$(space),$(1))
  29. mkfs_packages_id = $(shell echo $(sort $(1)) | mkhash md5 | head -c 8)
  30. mkfs_target_dir = $(if $(call param_get,pkg,$(1)),$(KDIR)/target-dir-$(call param_get,pkg,$(1)),$(TARGET_DIR))
  31. KDIR=$(KERNEL_BUILD_DIR)
  32. KDIR_TMP=$(KDIR)/tmp
  33. DTS_DIR:=$(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts
  34. IMG_PREFIX_EXTRA:=$(if $(EXTRA_IMAGE_NAME),$(call sanitize,$(EXTRA_IMAGE_NAME))-)
  35. IMG_PREFIX_VERNUM:=$(if $(CONFIG_VERSION_FILENAMES),$(call sanitize,$(VERSION_NUMBER))-)
  36. IMG_PREFIX_VERCODE:=$(if $(CONFIG_VERSION_CODE_FILENAMES),$(call sanitize,$(VERSION_CODE))-)
  37. IMG_PREFIX:=$(VERSION_DIST_SANITIZED)-$(IMG_PREFIX_VERNUM)$(IMG_PREFIX_VERCODE)$(IMG_PREFIX_EXTRA)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
  38. MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt
  39. ifneq ($(CONFIG_BIG_ENDIAN),)
  40. JFFS2OPTS := --big-endian --squash-uids -v
  41. else
  42. JFFS2OPTS := --little-endian --squash-uids -v
  43. endif
  44. ifeq ($(CONFIG_JFFS2_RTIME),y)
  45. JFFS2OPTS += -X rtime
  46. endif
  47. ifeq ($(CONFIG_JFFS2_ZLIB),y)
  48. JFFS2OPTS += -X zlib
  49. endif
  50. ifeq ($(CONFIG_JFFS2_LZMA),y)
  51. JFFS2OPTS += -X lzma --compression-mode=size
  52. endif
  53. ifneq ($(CONFIG_JFFS2_RTIME),y)
  54. JFFS2OPTS += -x rtime
  55. endif
  56. ifneq ($(CONFIG_JFFS2_ZLIB),y)
  57. JFFS2OPTS += -x zlib
  58. endif
  59. ifneq ($(CONFIG_JFFS2_LZMA),y)
  60. JFFS2OPTS += -x lzma
  61. endif
  62. JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
  63. SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
  64. SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
  65. SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
  66. SQUASHFSCOMP := gzip
  67. LZMA_XZ_OPTIONS := -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2
  68. ifeq ($(CONFIG_SQUASHFS_XZ),y)
  69. ifneq ($(filter arm x86 powerpc sparc,$(LINUX_KARCH)),)
  70. BCJ_FILTER:=-Xbcj $(LINUX_KARCH)
  71. endif
  72. SQUASHFSCOMP := xz $(LZMA_XZ_OPTIONS) $(BCJ_FILTER)
  73. endif
  74. JFFS2_BLOCKSIZE ?= 64k 128k
  75. fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
  76. fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
  77. fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
  78. fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
  79. fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
  80. fs-types-$(CONFIG_TARGET_ROOTFS_UBIFS) += ubifs
  81. fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
  82. TARGET_FILESYSTEMS := $(fs-types-y)
  83. FS_64K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-64k
  84. FS_128K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-128k
  85. FS_256K := $(filter-out jffs2-%,$(TARGET_FILESYSTEMS)) jffs2-256k
  86. define add_jffs2_mark
  87. echo -ne '\xde\xad\xc0\xde' >> $(1)
  88. endef
  89. PROFILE_SANITIZED := $(call sanitize,$(PROFILE))
  90. define split_args
  91. $(foreach data, \
  92. $(subst |,$(space),\
  93. $(subst $(space),^,$(1))), \
  94. $(call $(2),$(strip $(subst ^,$(space),$(data)))))
  95. endef
  96. define build_cmd
  97. $(if $(Build/$(word 1,$(1))),,$(error Missing Build/$(word 1,$(1))))
  98. $(call Build/$(word 1,$(1)),$(wordlist 2,$(words $(1)),$(1)))
  99. endef
  100. define concat_cmd
  101. $(call split_args,$(1),build_cmd)
  102. endef
  103. # pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
  104. define prepare_generic_squashfs
  105. $(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
  106. endef
  107. define Image/BuildKernel/Initramfs
  108. $(call Image/Build/Initramfs)
  109. endef
  110. define Image/BuildKernel/MkuImage
  111. mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
  112. -n '$(call toupper,$(ARCH)) LEDE Linux-$(LINUX_VERSION)' -d $(4) $(5)
  113. endef
  114. define Image/BuildKernel/MkFIT
  115. $(TOPDIR)/scripts/mkits.sh \
  116. -D $(1) -o $(KDIR)/fit-$(1).its -k $(2) $(if $(3),-d $(3)) -C $(4) -a $(5) -e $(6) \
  117. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  118. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $(KDIR)/fit-$(1).its $(KDIR)/fit-$(1)$(7).itb
  119. endef
  120. ifdef CONFIG_TARGET_IMAGES_GZIP
  121. define Image/Gzip
  122. rm -f $(1).gz
  123. gzip -9n $(1)
  124. endef
  125. endif
  126. # $(1) source dts file
  127. # $(2) target dtb file
  128. # $(3) extra CPP flags
  129. # $(4) extra DTC flags
  130. define Image/BuildDTB
  131. $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \
  132. -I$(DTS_DIR) \
  133. -I$(DTS_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. ifneq ($(CONFIG_NAND_SUPPORT),)
  175. define Image/Build/SysupgradeNAND
  176. mkdir -p "$(KDIR_TMP)/sysupgrade-$(1)/"
  177. echo "BOARD=$(1)" > "$(KDIR_TMP)/sysupgrade-$(1)/CONTROL"
  178. [ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(1)/root"
  179. [ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(1)/kernel"
  180. (cd "$(KDIR_TMP)"; $(TAR) cvf \
  181. "$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(1) \
  182. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  183. )
  184. endef
  185. # $(1) board name
  186. # $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
  187. # $(3) rootfstype (e.g. squashfs or ubifs)
  188. # $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
  189. define Image/Build/UbinizeImage
  190. sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
  191. "$(KDIR)/root.$(3)" \
  192. "$(KDIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
  193. $(4)
  194. endef
  195. endif
  196. define Image/mkfs/ubifs
  197. $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
  198. $(UBIFS_OPTS) $(call param_unmangle,$(call param_get,fs,$(1))) \
  199. $(if $(CONFIG_TARGET_UBIFS_FREE_SPACE_FIXUP),--space-fixup) \
  200. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_NONE),--compr=none) \
  201. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_LZO),--compr=lzo) \
  202. $(if $(CONFIG_TARGET_UBIFS_COMPRESSION_ZLIB),--compr=zlib) \
  203. $(if $(shell echo $(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)),--jrn-size=$(CONFIG_TARGET_UBIFS_JOURNAL_SIZE)) \
  204. --squash-uids \
  205. -o $@ -d $(call mkfs_target_dir,$(1))
  206. endef
  207. E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
  208. define Image/mkfs/ext4
  209. $(STAGING_DIR_HOST)/bin/make_ext4fs \
  210. -l $(E2SIZE) -b $(CONFIG_TARGET_EXT4_BLOCKSIZE) \
  211. $(if $(CONFIG_TARGET_EXT4_RESERVED_PCT),-m $(CONFIG_TARGET_EXT4_RESERVED_PCT)) \
  212. $(if $(CONFIG_TARGET_EXT4_JOURNAL),,-J) \
  213. $(if $(SOURCE_DATE_EPOCH),-T $(SOURCE_DATE_EPOCH)) \
  214. $@ $(call mkfs_target_dir,$(1))/
  215. endef
  216. define Image/Manifest
  217. $(STAGING_DIR_HOST)/bin/opkg \
  218. --offline-root $(TARGET_DIR) \
  219. --add-arch all:100 \
  220. --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200 list-installed > \
  221. $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED)).manifest
  222. endef
  223. ifdef CONFIG_TARGET_ROOTFS_TARGZ
  224. define Image/Build/targz
  225. $(TAR) -cp --numeric-owner --owner=0 --group=0 --sort=name \
  226. $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
  227. -C $(TARGET_DIR)/ . | gzip -9n > $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz
  228. endef
  229. endif
  230. ifdef CONFIG_TARGET_ROOTFS_CPIOGZ
  231. define Image/Build/cpiogz
  232. ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
  233. endef
  234. endif
  235. mkfs_packages = $(filter-out @%,$(PACKAGES_$(call param_get,pkg,pkg=$(target_params))))
  236. mkfs_packages_add = $(filter-out -%,$(mkfs_packages))
  237. mkfs_packages_remove = $(patsubst -%,%,$(filter -%,$(mkfs_packages)))
  238. mkfs_cur_target_dir = $(call mkfs_target_dir,pkg=$(target_params))
  239. opkg_target = \
  240. $(call opkg,$(mkfs_cur_target_dir)) \
  241. -f $(mkfs_cur_target_dir).conf
  242. target-dir-%: FORCE
  243. rm -rf $(mkfs_cur_target_dir) $(mkfs_cur_target_dir).opkg
  244. $(CP) $(TARGET_DIR_ORIG) $(mkfs_cur_target_dir)
  245. -mv $(mkfs_cur_target_dir)/etc/opkg $(mkfs_cur_target_dir).opkg
  246. echo 'src default file://$(PACKAGE_DIR_ALL)' > $(mkfs_cur_target_dir).conf
  247. $(if $(mkfs_packages_remove), \
  248. -$(call opkg,$(mkfs_cur_target_dir)) remove \
  249. $(mkfs_packages_remove))
  250. $(if $(call opkg_package_files,$(mkfs_packages_add)), \
  251. $(opkg_target) update && \
  252. $(opkg_target) install \
  253. $(call opkg_package_files,$(mkfs_packages_add)))
  254. $(call prepare_rootfs,$(mkfs_cur_target_dir))
  255. -mv $(mkfs_cur_target_dir).opkg $(mkfs_cur_target_dir)/etc/opkg
  256. rm -f $(mkfs_cur_target_dir).conf
  257. $(KDIR)/root.%: kernel_prepare
  258. $(call Image/mkfs/$(word 1,$(target_params)),$(target_params))
  259. define Device/InitProfile
  260. PROFILES := $(PROFILE)
  261. DEVICE_TITLE :=
  262. DEVICE_PACKAGES :=
  263. DEVICE_DESCRIPTION = Build firmware images for $$(DEVICE_TITLE)
  264. endef
  265. define Device/Init
  266. DEVICE_NAME := $(1)
  267. KERNEL:=
  268. KERNEL_INITRAMFS = $$(KERNEL)
  269. KERNEL_SIZE:=
  270. CMDLINE:=
  271. IMAGES :=
  272. IMAGE_PREFIX := $(IMG_PREFIX)-$(1)
  273. IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1)-$$(2)
  274. KERNEL_PREFIX = $$(IMAGE_PREFIX)
  275. KERNEL_SUFFIX := -kernel.bin
  276. KERNEL_INITRAMFS_SUFFIX = $$(KERNEL_SUFFIX)
  277. KERNEL_IMAGE = $$(KERNEL_PREFIX)$$(KERNEL_SUFFIX)
  278. KERNEL_INITRAMFS_PREFIX = $$(IMAGE_PREFIX)-initramfs
  279. KERNEL_INITRAMFS_IMAGE = $$(KERNEL_INITRAMFS_PREFIX)$$(KERNEL_INITRAMFS_SUFFIX)
  280. KERNEL_INITRAMFS_NAME = $$(KERNEL_NAME)-initramfs
  281. KERNEL_INSTALL :=
  282. KERNEL_NAME := vmlinux
  283. KERNEL_DEPENDS :=
  284. KERNEL_SIZE :=
  285. UBOOTENV_IN_UBI :=
  286. KERNEL_IN_UBI :=
  287. BLOCKSIZE :=
  288. PAGESIZE :=
  289. SUBPAGESIZE :=
  290. VID_HDR_OFFSET :=
  291. UBINIZE_OPTS :=
  292. UBINIZE_PARTS :=
  293. MKUBIFS_OPTS :=
  294. FS_OPTIONS/ubifs = $$(MKUBIFS_OPTS)
  295. DEVICE_DTS :=
  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. DEVICE_DTS DEVICE_DTS_DIR BOARD_NAME CMDLINE \
  306. 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. ifdef TARGET_PER_DEVICE_ROOTFS
  332. $$(eval $$(call merge_packages,_PACKAGES,$$(DEVICE_PACKAGES) $$(call DEVICE_EXTRA_PACKAGES,$(1))))
  333. ROOTFS_ID/$(1) := $$(if $$(_PROFILE_SET),$$(call mkfs_packages_id,$$(_PACKAGES)))
  334. PACKAGES_$$(ROOTFS_ID/$(1)) := $$(_PACKAGES)
  335. endif
  336. endef
  337. define Device/Check
  338. $(Device/Check/Common)
  339. KDIR_KERNEL_IMAGE := $(KDIR)/$(1)$$(KERNEL_SUFFIX)
  340. _TARGET := $$(if $$(_PROFILE_SET),install-images,install-disabled)
  341. ifndef IB
  342. _COMPILE_TARGET := $$(if $(CONFIG_IB)$$(_PROFILE_SET),compile,compile-disabled)
  343. endif
  344. endef
  345. ifndef IB
  346. define Device/Build/initramfs
  347. $(call Device/Export,$(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE),$(1))
  348. $$(_TARGET): $$(if $$(KERNEL_INITRAMFS),$(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE))
  349. $(KDIR)/$$(KERNEL_INITRAMFS_NAME):: image_prepare
  350. $(BIN_DIR)/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE)
  351. cp $$^ $$@
  352. $(KDIR)/tmp/$$(KERNEL_INITRAMFS_IMAGE): $(KDIR)/$$(KERNEL_INITRAMFS_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
  353. @rm -f $$@
  354. $$(call concat_cmd,$$(KERNEL_INITRAMFS))
  355. endef
  356. endif
  357. define Device/Build/compile
  358. $$(_COMPILE_TARGET): $(KDIR)/$(1)
  359. $(eval $(call Device/Export,$(KDIR)/$(1)))
  360. $(KDIR)/$(1):
  361. $$(call concat_cmd,$(COMPILE/$(1)))
  362. endef
  363. define Device/Build/kernel
  364. $(KDIR)/$$(KERNEL_NAME):: image_prepare
  365. $$(_TARGET): $$(if $$(KERNEL_INSTALL),$(BIN_DIR)/$$(KERNEL_IMAGE))
  366. $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1))
  367. $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE)
  368. cp $$^ $$@
  369. ifndef IB
  370. ifdef CONFIG_IB
  371. install: $$(KDIR_KERNEL_IMAGE)
  372. endif
  373. $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS)
  374. @rm -f $$@
  375. $$(call concat_cmd,$$(KERNEL))
  376. $$(if $$(KERNEL_SIZE),$$(call Build/check-size,$$(KERNEL_SIZE)))
  377. endif
  378. endef
  379. define Device/Build/image
  380. GZ_SUFFIX := $(if $(filter %dtb %gz,$(2)),,$(if $(and $(findstring ext4,$(1)),$(CONFIG_TARGET_IMAGES_GZIP)),.gz))
  381. $$(_TARGET): $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))$$(GZ_SUFFIX)
  382. $(eval $(call Device/Export,$(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)),$(1)))
  383. ROOTFS/$(1)/$(3) := \
  384. $(KDIR)/root.$(1)$$(strip \
  385. $$(if $$(FS_OPTIONS/$(1)),+fs=$$(call param_mangle,$$(FS_OPTIONS/$(1)))) \
  386. )$$(strip \
  387. $(if $(TARGET_PER_DEVICE_ROOTFS),+pkg=$$(ROOTFS_ID/$(3))) \
  388. )
  389. ifndef IB
  390. $$(ROOTFS/$(1)/$(3)): $(if $(TARGET_PER_DEVICE_ROOTFS),target-dir-$$(ROOTFS_ID/$(3)))
  391. endif
  392. $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2)): $$(KDIR_KERNEL_IMAGE) $$(ROOTFS/$(1)/$(3))
  393. @rm -f $$@
  394. [ -f $$(word 1,$$^) -a -f $$(word 2,$$^) ]
  395. $$(call concat_cmd,$(if $(IMAGE/$(2)/$(1)),$(IMAGE/$(2)/$(1)),$(IMAGE/$(2))))
  396. .IGNORE: $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2))
  397. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)).gz: $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  398. gzip -c -9n $$^ > $$@
  399. $(BIN_DIR)/$(call IMAGE_NAME,$(1),$(2)): $(KDIR)/tmp/$(call IMAGE_NAME,$(1),$(2))
  400. cp $$^ $$@
  401. endef
  402. define Device/Build
  403. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Device/Build/initramfs,$(1)))
  404. $(call Device/Build/kernel,$(1))
  405. $$(eval $$(foreach compile,$$(COMPILE), \
  406. $$(call Device/Build/compile,$$(compile),$(1))))
  407. $$(eval $$(foreach image,$$(IMAGES), \
  408. $$(foreach fs,$$(filter $(TARGET_FILESYSTEMS),$$(FILESYSTEMS)), \
  409. $$(call Device/Build/image,$$(fs),$$(image),$(1)))))
  410. endef
  411. define Device/DumpInfo
  412. Target-Profile: DEVICE_$(1)
  413. Target-Profile-Name: $(DEVICE_TITLE)
  414. Target-Profile-Packages: $(DEVICE_PACKAGES)
  415. Target-Profile-Description:
  416. $(DEVICE_DESCRIPTION)
  417. @@
  418. endef
  419. define Device/Dump
  420. $$(eval $$(if $$(DEVICE_TITLE),$$(info $$(call Device/DumpInfo,$(1)))))
  421. endef
  422. define Device
  423. $(call Device/InitProfile,$(1))
  424. $(call Device/Init,$(1))
  425. $(call Device/Default,$(1))
  426. $(call Device/$(1),$(1))
  427. $(call Device/Check,$(1))
  428. $(call Device/$(if $(DUMP),Dump,Build),$(1))
  429. endef
  430. define BuildImage
  431. ifneq ($(DUMP),)
  432. all: dumpinfo
  433. dumpinfo: FORCE
  434. @true
  435. endif
  436. download:
  437. prepare:
  438. compile:
  439. clean:
  440. legacy-images-prepare:
  441. legacy-images:
  442. image_prepare:
  443. ifeq ($(IB),)
  444. .PHONY: download prepare compile clean image_prepare kernel_prepare install install-images
  445. compile:
  446. $(call Build/Compile)
  447. clean:
  448. $(call Build/Clean)
  449. image_prepare: compile
  450. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  451. $(call Image/Prepare)
  452. legacy-images-prepare-make: image_prepare
  453. $(MAKE) legacy-images-prepare
  454. else
  455. image_prepare:
  456. mkdir -p $(BIN_DIR) $(KDIR)/tmp
  457. endif
  458. kernel_prepare: image_prepare
  459. $(call Image/Build/targz)
  460. $(call Image/Build/cpiogz)
  461. $(call Image/BuildKernel)
  462. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(if $(IB),,$(call Image/BuildKernel/Initramfs)))
  463. $(call Image/InstallKernel)
  464. $(foreach device,$(TARGET_DEVICES),$(call Device,$(device)))
  465. $(foreach device,$(LEGACY_DEVICES),$(call LegacyDevice,$(device)))
  466. install-images: kernel_prepare $(foreach fs,$(filter-out $(if $(UBIFS_OPTS),,ubifs),$(TARGET_FILESYSTEMS) $(fs-subtypes-y)),$(KDIR)/root.$(fs))
  467. $(foreach fs,$(TARGET_FILESYSTEMS),
  468. $(call Image/Build,$(fs))
  469. )
  470. legacy-images-make: install-images
  471. $(call Image/mkfs/ubifs/legacy)
  472. $(MAKE) legacy-images
  473. install: install-images
  474. $(call Image/Manifest)
  475. endef