Makefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. DEVICE_VARS += LOADER_TYPE
  10. DEVICE_VARS += NETGEAR_BOARD_ID NETGEAR_HW_ID
  11. DEVICE_VARS += BUFFALO_TAG_PLATFORM BUFFALO_TAG_VERSION BUFFALO_TAG_MINOR
  12. DEVICE_VARS += SEAMA_SIGNATURE SEAMA_MTDBLOCK
  13. DEVICE_VARS += SERCOMM_HWID SERCOMM_HWVER SERCOMM_SWVER
  14. DEVICE_VARS += JCG_MAXSIZE
  15. loadaddr-y := 0x80000000
  16. loadaddr-$(CONFIG_TARGET_ramips_rt288x) := 0x88000000
  17. loadaddr-$(CONFIG_TARGET_ramips_mt7621) := 0x80001000
  18. ldrplatform-y := ralink
  19. ldrplatform-$(CONFIG_TARGET_ramips_mt7621) := mt7621
  20. KERNEL_LOADADDR := $(loadaddr-y)
  21. LOADER_PLATFORM := $(ldrplatform-y)
  22. KERNEL_DTB = kernel-bin | append-dtb | lzma
  23. define Device/Default
  24. PROFILES = Default
  25. KERNEL := $(KERNEL_DTB) | uImage lzma
  26. SOC := $(DEFAULT_SOC)
  27. DEVICE_DTS_DIR := ../dts
  28. DEVICE_DTS = $$(SOC)_$(1)
  29. IMAGES := sysupgrade.bin
  30. SUPPORTED_DEVICES := $(subst _,$(comma),$(1))
  31. sysupgrade_bin := append-kernel | append-rootfs | pad-rootfs
  32. IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size
  33. endef
  34. define Device/uimage-lzma-loader
  35. LOADER_TYPE := bin
  36. KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | uImage none
  37. endef
  38. define Device/seama
  39. SEAMA_MTDBLOCK := 2
  40. IMAGES += factory.bin
  41. # 64 bytes offset:
  42. # - 28 bytes seama_header
  43. # - 36 bytes of META data (4-bytes aligned)
  44. IMAGE/default := append-kernel | pad-offset $$$$(BLOCKSIZE) 64 | append-rootfs
  45. IMAGE/sysupgrade.bin := \
  46. $$(IMAGE/default) | seama | pad-rootfs | append-metadata | check-size
  47. IMAGE/factory.bin := \
  48. $$(IMAGE/default) | pad-rootfs -x 64 | seama | seama-seal | check-size
  49. SEAMA_SIGNATURE :=
  50. endef
  51. define Build/jcg-header
  52. $(STAGING_DIR_HOST)/bin/jcgimage -v $(1) \
  53. $(if $(JCG_MAXSIZE), -m $$(($(subst k, * 1024,$(JCG_MAXSIZE)))),) \
  54. -u $@ -o [email protected]
  55. mv [email protected] $@
  56. endef
  57. define Build/trx
  58. $(STAGING_DIR_HOST)/bin/trx $(1) \
  59. -o $@ \
  60. -m $$(($(subst k, * 1024,$(IMAGE_SIZE)))) \
  61. -f $(IMAGE_KERNEL) \
  62. -a 4 -f $(IMAGE_ROOTFS)
  63. endef
  64. define Build/loader-common
  65. rm -rf [email protected]
  66. $(MAKE) -C lzma-loader \
  67. PKG_BUILD_DIR="[email protected]" \
  68. TARGET_DIR="$(dir $@)" LOADER_NAME="$(notdir $@)" \
  69. BOARD="$(BOARDNAME)" PLATFORM="$(LOADER_PLATFORM)" \
  70. LZMA_TEXT_START=0x82000000 LOADADDR=$(KERNEL_LOADADDR) \
  71. $(1) compile loader.$(LOADER_TYPE)
  72. mv "$@.$(LOADER_TYPE)" "$@"
  73. rm -rf [email protected]
  74. endef
  75. define Build/loader-kernel
  76. $(call Build/loader-common,LOADER_DATA="$@")
  77. endef
  78. define Build/relocate-kernel
  79. rm -rf [email protected]
  80. $(CP) ../../generic/image/relocate [email protected]
  81. $(MAKE) -C [email protected] KERNEL_ADDR=$(KERNEL_LOADADDR) CROSS_COMPILE=$(TARGET_CROSS)
  82. ( \
  83. dd [email protected]/loader.bin bs=32 conv=sync && \
  84. perl -e '@s = stat("$@"); print pack("V", @s[7])' && \
  85. cat $@ \
  86. ) > [email protected]
  87. mv [email protected] $@
  88. rm -rf [email protected]
  89. endef
  90. define Build/elx-header
  91. $(eval hw_id=$(word 1,$(1)))
  92. $(eval xor_pattern=$(word 2,$(1)))
  93. ( \
  94. echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
  95. dd bs=42 count=1 conv=sync; \
  96. hw_id="$(hw_id)"; \
  97. echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
  98. dd bs=20 count=1 conv=sync; \
  99. echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  100. dd bs=8 count=1 conv=sync; \
  101. echo -ne "$$($(STAGING_DIR_HOST)/bin/mkhash md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  102. dd bs=58 count=1 conv=sync; \
  103. ) > $(KDIR)/tmp/$(DEVICE_NAME).header
  104. $(call Build/xor-image,-p $(xor_pattern) -x)
  105. cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > [email protected]
  106. mv [email protected] $@
  107. rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
  108. endef
  109. define Build/umedia-header
  110. fix-u-media-header -T 0x46 -B $(1) -i $@ -o [email protected] && mv [email protected] $@
  111. endef
  112. define Build/edimax-header
  113. $(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o [email protected] $(1)
  114. @mv [email protected] $@
  115. endef
  116. define Build/poray-header
  117. $(STAGING_DIR_HOST)/bin/mkporayfw $(1) -f $@ -o [email protected]
  118. mv [email protected] $@
  119. endef
  120. define Build/wrg-header
  121. mkwrgimg -i $@ -d "/dev/mtdblock/2" -s $(1) -o [email protected]
  122. mv [email protected] $@
  123. endef
  124. # combine kernel and rootfs into one image
  125. # mkdlinkfw <type> <optional extra arguments to mkdlinkfw binary>
  126. define Build/mkdlinkfw
  127. -$(STAGING_DIR_HOST)/bin/mkdlinkfw \
  128. -k $(IMAGE_KERNEL) \
  129. -r $(IMAGE_ROOTFS) \
  130. -o $@ \
  131. $(if $(DLINK_IMAGE_OFFSET), -O $(DLINK_IMAGE_OFFSET)) \
  132. -s $(DLINK_FIRMWARE_SIZE)
  133. endef
  134. define Build/mkdlinkfw-factory
  135. -$(STAGING_DIR_HOST)/bin/mkdlinkfw \
  136. -m $(DLINK_ROM_ID) -f $(DLINK_FAMILY_MEMBER) \
  137. -F $@ \
  138. -o [email protected] \
  139. $(if $(DLINK_IMAGE_OFFSET), -O $(DLINK_IMAGE_OFFSET)) \
  140. -s $(DLINK_FIRMWARE_SIZE)
  141. mv [email protected] $@
  142. endef
  143. define Build/zyimage
  144. $(STAGING_DIR_HOST)/bin/zyimage $(1) $@
  145. endef
  146. define Build/sercom-seal
  147. $(STAGING_DIR_HOST)/bin/mksercommfw \
  148. -i $@ \
  149. -b $(SERCOMM_HWID) \
  150. -r $(SERCOMM_HWVER) \
  151. -v $(SERCOMM_SWVER) \
  152. $(1)
  153. endef
  154. define Build/sercom-footer
  155. $(call Build/sercom-seal,-f)
  156. endef
  157. define Build/fonfxcimage
  158. uimage_padhdr -i $@ -o [email protected]
  159. mv [email protected] $@
  160. endef
  161. ifeq ($(SUBTARGET),rt288x)
  162. include rt288x.mk
  163. endif
  164. ifeq ($(SUBTARGET),rt305x)
  165. include rt305x.mk
  166. endif
  167. ifeq ($(SUBTARGET),rt3883)
  168. include rt3883.mk
  169. endif
  170. ifeq ($(SUBTARGET),mt7620)
  171. include mt7620.mk
  172. endif
  173. ifeq ($(SUBTARGET),mt7621)
  174. include mt7621.mk
  175. endif
  176. ifeq ($(SUBTARGET),mt76x8)
  177. include mt76x8.mk
  178. endif
  179. $(eval $(call BuildImage))