Makefile 5.1 KB

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