image.mk 17 KB

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