Makefile 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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
  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/relocate-kernel
  50. ( \
  51. dd if=$(KDIR)/loader.bin bs=32 conv=sync && \
  52. perl -e '@s = stat("$@"); print pack("V", @s[7])' && \
  53. cat $@ \
  54. ) > [email protected]
  55. mv [email protected] $@
  56. endef
  57. define MkCombineduImage
  58. $(call PatchKernelLzma,$(2),$(3))
  59. if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt `expr $(4) - 64` ]; then \
  60. echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big" >&2; \
  61. else if [ `stat -c%s "$(KDIR)/root.$(1)"` -gt $(5) ]; then \
  62. echo "Warning: $(KDIR)/root.$(1) is too big" >&2; \
  63. else \
  64. ( dd if=$(KDIR)/vmlinux-$(2).bin.lzma bs=`expr $(4) - 64` conv=sync ; dd if=$(KDIR)/root.$(1) ) > $(KDIR)/vmlinux-$(2).bin.lzma.combined ; \
  65. fi ; fi
  66. $(call MkImage,lzma,$(KDIR)/vmlinux-$(2).bin.lzma.combined,$(call sysupname,$(1),$(2)),$(6))
  67. endef
  68. define Build/umedia-header
  69. fix-u-media-header -T 0x46 -B $(1) -i $@ -o [email protected] && mv [email protected] $@
  70. endef
  71. define Build/edimax-header
  72. $(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o [email protected] $(1)
  73. @mv [email protected] $@
  74. endef
  75. define Build/poray-header
  76. $(STAGING_DIR_HOST)/bin/mkporayfw $(1) -f $@ -o [email protected]
  77. mv [email protected] $@
  78. endef
  79. define Build/senao-header
  80. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  81. mv [email protected] $@
  82. endef
  83. define Build/seama
  84. $(STAGING_DIR_HOST)/bin/seama -i $@ $(1)
  85. mv [email protected] $@
  86. endef
  87. define Build/seama-seal
  88. $(call Build/seama,-s [email protected] $(1))
  89. endef
  90. define Build/wrg-header
  91. mkwrgimg -i $@ -d "/dev/mtdblock/2" -s $(1) -o [email protected]
  92. mv [email protected] $@
  93. endef
  94. # combine kernel and rootfs into one image
  95. # mkdlinkfw <type> <optional extra arguments to mkdlinkfw binary>
  96. define Build/mkdlinkfw
  97. -$(STAGING_DIR_HOST)/bin/mkdlinkfw \
  98. -k $(IMAGE_KERNEL) \
  99. -r $(IMAGE_ROOTFS) \
  100. -o $@ \
  101. -s $(DLINK_FIRMWARE_SIZE)
  102. endef
  103. define Build/mkdlinkfw-factory
  104. -$(STAGING_DIR_HOST)/bin/mkdlinkfw \
  105. -m $(DLINK_ROM_ID) -f $(DLINK_FAMILY_MEMBER) \
  106. -F $@ \
  107. -o [email protected] \
  108. -s $(DLINK_FIRMWARE_SIZE)
  109. mv [email protected] $@
  110. endef
  111. #
  112. # The real magic happens inside these templates
  113. #
  114. # $(1), compression method
  115. # $(2), filename of image data
  116. # $(3), output filename
  117. define MkImage
  118. $(eval imagename=$(if $(4),$(4),MIPS $(VERSION_DIST) Linux-$(LINUX_VERSION)))
  119. -mkimage -A mips -O linux -T kernel -C $(1) -a $(loadaddr-y) -e $(loadaddr-y) \
  120. -n "$(imagename)" \
  121. -d $(2) $(3)
  122. endef
  123. define CompressLzma
  124. $(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
  125. endef
  126. define MkImageSysupgrade/squashfs
  127. $(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-$(if $(4),$(4),sysupgrade).bin)
  128. cat $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) > $(KDIR)/$(output_name)
  129. $(call prepare_generic_squashfs,$(KDIR)/$(output_name))
  130. if [ `stat -c%s "$(KDIR)/$(output_name)"` -gt $(3) ]; then \
  131. echo "Warning: $(KDIR)/$(output_name) is too big" >&2; \
  132. else \
  133. $(CP) $(KDIR)/$(output_name) $(BIN_DIR)/$(output_name); \
  134. fi
  135. endef
  136. # $(1), lowercase board name like "mt7620a_v22sg"
  137. # $(2), DTS filename without .dts extension
  138. # $(3), optional filename suffix, e.g. "-initramfs"
  139. define PatchKernelLzmaDtb
  140. cp $(KDIR)/vmlinux$(3) $(KDIR)/vmlinux-$(1)$(3)
  141. $(call Image/BuildDTB,../dts/$(2).dts,$(KDIR)/$(2).dtb)
  142. $(STAGING_DIR_HOST)/bin/patch-dtb $(KDIR)/vmlinux-$(1)$(3) $(KDIR)/$(2).dtb
  143. $(call CompressLzma,$(KDIR)/vmlinux-$(1)$(3),$(KDIR)/vmlinux-$(1)$(3).bin.lzma)
  144. endef
  145. # $(1), lowercase board name
  146. # $(2), DTS filename without .dts extension
  147. # $(3), ih_name field of uImage header
  148. # $(4), optional filename suffix, e.g. "-initramfs"
  149. define MkImageLzmaDtb
  150. $(call PatchKernelLzmaDtb,$(1),$(2),$(4))
  151. $(call MkImage,lzma,$(KDIR)/vmlinux-$(1)$(4).bin.lzma,$(KDIR)/vmlinux-$(1)$(4).uImage,$(3))
  152. endef
  153. # $(1), Rootfs type, e.g. squashfs
  154. # $(2), lowercase board name
  155. # $(3), DTS filename without .dts extension
  156. # $(4), maximum size of sysupgrade image
  157. # $(5), uImage header's ih_name field
  158. define BuildFirmware/OF
  159. $(call MkImageLzmaDtb,$(2),$(3),$(5))
  160. $(call MkImageSysupgrade/$(1),$(1),$(2),$(4),$(6))
  161. endef
  162. # $(1), squashfs/initramfs
  163. # $(2), lowercase board name
  164. # $(3), DTS filename without .dts extension
  165. # $(4), ih_name field of uImage header
  166. define BuildFirmware/OF/initramfs
  167. $(call MkImageLzmaDtb,$(2),$(3),$(4),-initramfs)
  168. $(CP) $(KDIR)/vmlinux-$(2)-initramfs.uImage $(call imgname,$(1),$(2))-uImage.bin
  169. endef
  170. # Build images for default ralink layout for 4MB flash
  171. # kernel + roots = 0x3b0000
  172. # $(1) = squashfs/initramfs
  173. # $(2) = lowercase board name
  174. # $(3) = dts file
  175. ralink_default_fw_size_4M=3866624
  176. BuildFirmware/Default4M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_4M),$(4))
  177. BuildFirmware/Default4M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
  178. ralink_default_fw_size_8M=8060928
  179. ralink_default_fw_size_16M=16121856
  180. ralink_default_fw_size_32M=33226752
  181. ifeq ($(SUBTARGET),rt288x)
  182. include rt288x.mk
  183. endif
  184. ifeq ($(SUBTARGET),rt305x)
  185. include rt305x.mk
  186. include rt305x-legacy.mk
  187. endif
  188. ifeq ($(SUBTARGET),rt3883)
  189. include rt3883.mk
  190. endif
  191. ifeq ($(SUBTARGET),mt7620)
  192. include mt7620.mk
  193. endif
  194. ifeq ($(SUBTARGET),mt7621)
  195. include mt7621.mk
  196. endif
  197. ifeq ($(SUBTARGET),mt76x8)
  198. include mt76x8.mk
  199. endif
  200. ifdef LEGACY_DEVICES
  201. #
  202. # Generic Targets - only needed for legacy image building code
  203. #
  204. define Image/BuildKernel
  205. cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(VMLINUX).elf
  206. cp $(KDIR)/vmlinux $(BIN_DIR)/$(VMLINUX).bin
  207. $(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
  208. $(call MkImage,lzma,$(KDIR)/vmlinux.bin.lzma,$(KDIR)/uImage.lzma)
  209. cp $(KDIR)/uImage.lzma $(BIN_DIR)/$(UIMAGE).bin
  210. endef
  211. define Image/BuildKernel/Initramfs
  212. cp $(KDIR)/vmlinux-initramfs.elf $(BIN_DIR)/$(VMLINUX)-initramfs.elf
  213. cp $(KDIR)/vmlinux-initramfs $(BIN_DIR)/$(VMLINUX)-initramfs.bin
  214. $(call CompressLzma,$(KDIR)/vmlinux-initramfs,$(KDIR)/vmlinux-initramfs.bin.lzma)
  215. $(call MkImage,lzma,$(KDIR)/vmlinux-initramfs.bin.lzma,$(KDIR)/uImage-initramfs.lzma)
  216. cp $(KDIR)/uImage-initramfs.lzma $(BIN_DIR)/$(UIMAGE)-initramfs.bin
  217. $(call Image/Build/Initramfs)
  218. endef
  219. define Image/Build
  220. $(call Image/Build/$(1))
  221. dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
  222. endef
  223. define Image/Build/Profile
  224. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/Build/Profile/$(1),initramfs))
  225. $(call Image/Build/Profile/$(1),$(2))
  226. endef
  227. endif
  228. $(eval $(call BuildImage))