Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. #
  2. # Copyright (C) 2008-2011 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. include $(INCLUDE_DIR)/image.mk
  9. define imgname
  10. $(BIN_DIR)/$(IMG_PREFIX)-$(2)-$(1)
  11. endef
  12. define sysupname
  13. $(call imgname,$(1),$(2))-sysupgrade.bin
  14. endef
  15. VMLINUX:=$(IMG_PREFIX)-vmlinux
  16. UIMAGE:=$(IMG_PREFIX)-uImage
  17. define Image/Build/Initramfs
  18. $(call Image/Build/Profile/$(PROFILE),initramfs)
  19. endef
  20. DEVICE_VARS += DTS IMAGE_SIZE NETGEAR_BOARD_ID NETGEAR_HW_ID
  21. DEVICE_VARS += BUFFALO_TAG_PLATFORM BUFFALO_TAG_VERSION BUFFALO_TAG_MINOR
  22. loadaddr-y := 0x80000000
  23. loadaddr-$(CONFIG_TARGET_ramips_rt288x) := 0x88000000
  24. loadaddr-$(CONFIG_TARGET_ramips_mt7621) := 0x80001000
  25. KERNEL_LOADADDR := $(loadaddr-y)
  26. KERNEL_DTB = kernel-bin | patch-dtb | lzma -d21
  27. define Device/Default
  28. PROFILES = Default $$(DTS)
  29. KERNEL_DEPENDS = $$(wildcard ../dts/$$(DTS).dts)
  30. KERNEL := $(KERNEL_DTB) | uImage lzma
  31. DEVICE_DTS_DIR := ../dts
  32. IMAGES := sysupgrade.bin
  33. IMAGE_SIZE := $(ralink_default_fw_size_8M)
  34. SUPPORTED_DEVICES := $(subst _,$(comma),$(1))
  35. sysupgrade_bin := append-kernel | append-rootfs | pad-rootfs
  36. IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size $$$$(IMAGE_SIZE)
  37. endef
  38. define Build/patch-dtb
  39. $(call Image/BuildDTB,../dts/$(DTS).dts,[email protected])
  40. $(STAGING_DIR_HOST)/bin/patch-dtb $@ [email protected]
  41. endef
  42. define Build/trx
  43. $(STAGING_DIR_HOST)/bin/trx $(1) \
  44. -o $@ \
  45. -m $(IMAGE_SIZE) \
  46. -f $(IMAGE_KERNEL) \
  47. -a 4 -f $(IMAGE_ROOTFS)
  48. endef
  49. define Build/loader-common
  50. rm -rf [email protected]
  51. $(MAKE) -C lzma-loader \
  52. PKG_BUILD_DIR="[email protected]" \
  53. TARGET_DIR="$(dir $@)" LOADER_NAME="$(notdir $@)" \
  54. BOARD="$(BOARDNAME)" PLATFORM="$(PLATFORM)" \
  55. LZMA_TEXT_START=0x82000000 LOADADDR=$(KERNEL_LOADADDR) \
  56. $(1) compile loader.$(LOADER_TYPE)
  57. mv "$@.$(LOADER_TYPE)" "$@"
  58. rm -rf [email protected]
  59. endef
  60. define Build/loader-kernel
  61. $(call Build/loader-common,LOADER_DATA="$@")
  62. endef
  63. define Build/relocate-kernel
  64. ( \
  65. dd if=$(KDIR)/loader.bin bs=32 conv=sync && \
  66. perl -e '@s = stat("$@"); print pack("V", @s[7])' && \
  67. cat $@ \
  68. ) > [email protected]
  69. mv [email protected] $@
  70. endef
  71. define MkCombineduImage
  72. $(call PatchKernelLzma,$(2),$(3))
  73. if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt `expr $(4) - 64` ]; then \
  74. echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big" >&2; \
  75. else if [ `stat -c%s "$(KDIR)/root.$(1)"` -gt $(5) ]; then \
  76. echo "Warning: $(KDIR)/root.$(1) is too big" >&2; \
  77. else \
  78. ( dd if=$(KDIR)/vmlinux-$(2).bin.lzma bs=`expr $(4) - 64` conv=sync ; dd if=$(KDIR)/root.$(1) ) > $(KDIR)/vmlinux-$(2).bin.lzma.combined ; \
  79. fi ; fi
  80. $(call MkImage,lzma,$(KDIR)/vmlinux-$(2).bin.lzma.combined,$(call sysupname,$(1),$(2)),$(6))
  81. endef
  82. define Build/umedia-header
  83. fix-u-media-header -T 0x46 -B $(1) -i $@ -o [email protected] && mv [email protected] $@
  84. endef
  85. define Build/edimax-header
  86. $(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o [email protected] $(1)
  87. @mv [email protected] $@
  88. endef
  89. define Build/poray-header
  90. $(STAGING_DIR_HOST)/bin/mkporayfw $(1) -f $@ -o [email protected]
  91. mv [email protected] $@
  92. endef
  93. define Build/senao-header
  94. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  95. mv [email protected] $@
  96. endef
  97. define Build/seama
  98. $(STAGING_DIR_HOST)/bin/seama -i $@ $(1)
  99. mv [email protected] $@
  100. endef
  101. define Build/seama-seal
  102. $(call Build/seama,-s [email protected] $(1))
  103. endef
  104. define Build/wrg-header
  105. mkwrgimg -i $@ -d "/dev/mtdblock/2" -s $(1) -o [email protected]
  106. mv [email protected] $@
  107. endef
  108. # combine kernel and rootfs into one image
  109. # mkdlinkfw <type> <optional extra arguments to mkdlinkfw binary>
  110. define Build/mkdlinkfw
  111. -$(STAGING_DIR_HOST)/bin/mkdlinkfw \
  112. -k $(IMAGE_KERNEL) \
  113. -r $(IMAGE_ROOTFS) \
  114. -o $@ \
  115. -s $(DLINK_FIRMWARE_SIZE)
  116. endef
  117. define Build/mkdlinkfw-factory
  118. -$(STAGING_DIR_HOST)/bin/mkdlinkfw \
  119. -m $(DLINK_ROM_ID) -f $(DLINK_FAMILY_MEMBER) \
  120. -F $@ \
  121. -o [email protected] \
  122. -s $(DLINK_FIRMWARE_SIZE)
  123. mv [email protected] $@
  124. endef
  125. define Build/zyimage
  126. $(STAGING_DIR_HOST)/bin/zyimage $(1) $@
  127. endef
  128. #
  129. # The real magic happens inside these templates
  130. #
  131. # $(1), compression method
  132. # $(2), filename of image data
  133. # $(3), output filename
  134. define MkImage
  135. $(eval imagename=$(if $(4),$(4),MIPS $(VERSION_DIST) Linux-$(LINUX_VERSION)))
  136. -mkimage -A mips -O linux -T kernel -C $(1) -a $(loadaddr-y) -e $(loadaddr-y) \
  137. -n "$(imagename)" \
  138. -d $(2) $(3)
  139. endef
  140. define CompressLzma
  141. $(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
  142. endef
  143. define MkImageSysupgrade/squashfs
  144. $(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-$(if $(4),$(4),sysupgrade).bin)
  145. cat $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) > $(KDIR)/$(output_name)
  146. $(call prepare_generic_squashfs,$(KDIR)/$(output_name))
  147. if [ `stat -c%s "$(KDIR)/$(output_name)"` -gt $(3) ]; then \
  148. echo "Warning: $(KDIR)/$(output_name) is too big" >&2; \
  149. else \
  150. $(CP) $(KDIR)/$(output_name) $(BIN_DIR)/$(output_name); \
  151. fi
  152. endef
  153. # $(1), lowercase board name like "mt7620a_v22sg"
  154. # $(2), DTS filename without .dts extension
  155. # $(3), optional filename suffix, e.g. "-initramfs"
  156. define PatchKernelLzmaDtb
  157. cp $(KDIR)/vmlinux$(3) $(KDIR)/vmlinux-$(1)$(3)
  158. $(call Image/BuildDTB,../dts/$(2).dts,$(KDIR)/$(2).dtb)
  159. $(STAGING_DIR_HOST)/bin/patch-dtb $(KDIR)/vmlinux-$(1)$(3) $(KDIR)/$(2).dtb
  160. $(call CompressLzma,$(KDIR)/vmlinux-$(1)$(3),$(KDIR)/vmlinux-$(1)$(3).bin.lzma)
  161. endef
  162. # $(1), lowercase board name
  163. # $(2), DTS filename without .dts extension
  164. # $(3), ih_name field of uImage header
  165. # $(4), optional filename suffix, e.g. "-initramfs"
  166. define MkImageLzmaDtb
  167. $(call PatchKernelLzmaDtb,$(1),$(2),$(4))
  168. $(call MkImage,lzma,$(KDIR)/vmlinux-$(1)$(4).bin.lzma,$(KDIR)/vmlinux-$(1)$(4).uImage,$(3))
  169. endef
  170. # $(1), Rootfs type, e.g. squashfs
  171. # $(2), lowercase board name
  172. # $(3), DTS filename without .dts extension
  173. # $(4), maximum size of sysupgrade image
  174. # $(5), uImage header's ih_name field
  175. define BuildFirmware/OF
  176. $(call MkImageLzmaDtb,$(2),$(3),$(5))
  177. $(call MkImageSysupgrade/$(1),$(1),$(2),$(4),$(6))
  178. endef
  179. # $(1), squashfs/initramfs
  180. # $(2), lowercase board name
  181. # $(3), DTS filename without .dts extension
  182. # $(4), ih_name field of uImage header
  183. define BuildFirmware/OF/initramfs
  184. $(call MkImageLzmaDtb,$(2),$(3),$(4),-initramfs)
  185. $(CP) $(KDIR)/vmlinux-$(2)-initramfs.uImage $(call imgname,$(1),$(2))-uImage.bin
  186. endef
  187. # Build images for default ralink layout for 4MB flash
  188. # kernel + roots = 0x3b0000
  189. # $(1) = squashfs/initramfs
  190. # $(2) = lowercase board name
  191. # $(3) = dts file
  192. ralink_default_fw_size_4M=3866624
  193. BuildFirmware/Default4M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_4M),$(4))
  194. BuildFirmware/Default4M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
  195. ralink_default_fw_size_8M=8060928
  196. ralink_default_fw_size_16M=16121856
  197. ralink_default_fw_size_32M=33226752
  198. ifeq ($(SUBTARGET),rt288x)
  199. include rt288x.mk
  200. endif
  201. ifeq ($(SUBTARGET),rt305x)
  202. include rt305x.mk
  203. include rt305x-legacy.mk
  204. endif
  205. ifeq ($(SUBTARGET),rt3883)
  206. include rt3883.mk
  207. endif
  208. ifeq ($(SUBTARGET),mt7620)
  209. include mt7620.mk
  210. endif
  211. ifeq ($(SUBTARGET),mt7621)
  212. include mt7621.mk
  213. endif
  214. ifeq ($(SUBTARGET),mt76x8)
  215. include mt76x8.mk
  216. endif
  217. ifdef LEGACY_DEVICES
  218. #
  219. # Generic Targets - only needed for legacy image building code
  220. #
  221. define Image/BuildKernel
  222. cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(VMLINUX).elf
  223. cp $(KDIR)/vmlinux $(BIN_DIR)/$(VMLINUX).bin
  224. $(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
  225. $(call MkImage,lzma,$(KDIR)/vmlinux.bin.lzma,$(KDIR)/uImage.lzma)
  226. cp $(KDIR)/uImage.lzma $(BIN_DIR)/$(UIMAGE).bin
  227. endef
  228. define Image/BuildKernel/Initramfs
  229. cp $(KDIR)/vmlinux-initramfs.elf $(BIN_DIR)/$(VMLINUX)-initramfs.elf
  230. cp $(KDIR)/vmlinux-initramfs $(BIN_DIR)/$(VMLINUX)-initramfs.bin
  231. $(call CompressLzma,$(KDIR)/vmlinux-initramfs,$(KDIR)/vmlinux-initramfs.bin.lzma)
  232. $(call MkImage,lzma,$(KDIR)/vmlinux-initramfs.bin.lzma,$(KDIR)/uImage-initramfs.lzma)
  233. cp $(KDIR)/uImage-initramfs.lzma $(BIN_DIR)/$(UIMAGE)-initramfs.bin
  234. $(call Image/Build/Initramfs)
  235. endef
  236. define Image/Build
  237. $(call Image/Build/$(1))
  238. dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
  239. endef
  240. define Image/Build/Profile
  241. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/Build/Profile/$(1),initramfs))
  242. $(call Image/Build/Profile/$(1),$(2))
  243. endef
  244. endif
  245. $(eval $(call BuildImage))