Makefile 6.1 KB

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