Makefile 5.1 KB

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