Makefile 5.4 KB

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