generic.mk 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #
  2. # Copyright (C) 2008-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ### DO NOT INDENT LINES CONTAINING $(call xyz) AS THIS MAY CHANGE THE CONTEXT
  8. ### OF THE FIRST LINE IN THE CALLED VARIABLE (NOTE: variable!)
  9. ### see http://www.gnu.org/software/make/manual/html_node/Call-Function.html#Call-Function
  10. ### ACTUALLY IT IS A SIMPLE MACRO EXPANSION
  11. ### use round brackets for make variables, and curly brackets for shell variables
  12. ## Kernel mtd partition size in KiB
  13. KERNEL_MTD_SIZE:=1280
  14. # Netgear WNR854T: erase size is 128KiB = 0x00020000 = 131072
  15. ERASE_SIZE_128K:=128
  16. # Linksys WRT350N v2: erase size is 64KiB = 0x00010000 = 65536
  17. ERASE_SIZE_64K:=64
  18. # define JFFS2 sizes for include/image.mk
  19. JFFS2_BLOCKSIZE:=64k 128k
  20. ###
  21. ### Image/BuildKernel
  22. ###
  23. define Image/BuildKernel
  24. ### Dummy comment for indented calls of Image/BuildKernel
  25. ## Netgear WN802T: mach id 3306 (0x0cea)
  26. $(call Image/BuildKernel/ARM/zImage,wn802t,"\x0c\x1c\xa0\xe3\xea\x10\x81\xe3")
  27. $(call Image/BuildKernel/ARM/uImage,wn802t)
  28. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  29. $(call Image/BuildKernel/ARM/zImage,wn802t,"\x0c\x1c\xa0\xe3\xea\x10\x81\xe3",-initramfs)
  30. $(call Image/BuildKernel/ARM/uImage,wn802t,-initramfs)
  31. endif
  32. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) # nothing more to do for a ramdisk build
  33. $(call Image/BuildKernel/JFFS2uImage,wn802t,$(ERASE_SIZE_64K),uImage)
  34. $(call Image/Default/FileSizeCheck,$(KDIR)/wn802t-uImage.jffs2,$(shell expr $(KERNEL_MTD_SIZE) \* 1024))
  35. endif
  36. ## Netgear WNR854T: mach id 1801 (0x0709)
  37. $(call Image/BuildKernel/ARM/zImage,wnr854t,"\x07\x1c\xa0\xe3\x09\x10\x81\xe3")
  38. $(call Image/BuildKernel/ARM/uImage,wnr854t)
  39. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  40. $(call Image/BuildKernel/ARM/zImage,wnr854t,"\x07\x1c\xa0\xe3\x09\x10\x81\xe3",-initramfs)
  41. $(call Image/BuildKernel/ARM/uImage,wnr854t,-initramfs)
  42. endif
  43. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) # nothing more to do for a ramdisk build
  44. $(call Image/BuildKernel/JFFS2uImage,wnr854t,$(ERASE_SIZE_128K),uImage)
  45. $(call Image/Default/FileSizeCheck,$(KDIR)/wnr854t-uImage.jffs2,$(shell expr $(KERNEL_MTD_SIZE) \* 1024))
  46. endif
  47. ## Linksys WRT350N v2: mach id 1633 (0x0661)
  48. $(call Image/BuildKernel/ARM/zImage,wrt350nv2,"\x06\x1c\xa0\xe3\x61\x10\x81\xe3")
  49. $(call Image/BuildKernel/ARM/uImage,wrt350nv2)
  50. ifeq ($($CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  51. $(call Image/BuildKernel/ARM/zImage,wrt350nv2,"\x06\x1c\xa0\xe3\x61\x10\x81\xe3",-initramfs)
  52. $(call Image/BuildKernel/ARM/uImage,wrt350nv2-initramfs)
  53. endif
  54. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y) # nothing more to do for a ramdisk build
  55. $(call Image/Default/FileSizeCheck,$(KDIR)/wrt350nv2-uImage,$(shell expr $(KERNEL_MTD_SIZE) \* 1024))
  56. endif
  57. ## Buffalo Terastation Pro II/Live: mach id 1584 (0x0630)
  58. $(call Image/BuildKernel/ARM/zImage,terastation-pro2,"\x06\x1c\xa0\xe3\x30\x10\x81\xe3")
  59. $(call Image/BuildKernel/ARM/uImage,terastation-pro2)
  60. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  61. $(call Image/BuildKernel/ARM/zImage,terastation-pro2,"\x06\x1c\xa0\xe3\x30\x10\x81\xe3",-initramfs)
  62. $(call Image/BuildKernel/ARM/uImage,terastation-pro2,-initramfs)
  63. endif
  64. endef
  65. define Image/BuildKernel/ARM/zImage
  66. # merge machine id and regular zImage into one file
  67. # parameters: 1 = machine name, 2 = machine id as string in quotes
  68. # $(BOARD) kernel zImage for $(1)
  69. echo -en $(2) > '$(KDIR)/$(1)-zImage$(3)'
  70. cat '$(KDIR)/zImage$(3)' >> '$(KDIR)/$(1)-zImage$(3)'
  71. endef
  72. define Image/BuildKernel/ARM/uImage
  73. # create uImage from zImage
  74. # parameters: 1 = machine name
  75. # $(BOARD) kernel uImage for $(1)
  76. '$(STAGING_DIR_HOST)/bin/mkimage' -A arm -O linux -T kernel \
  77. -C none -a 0x00008000 -e 0x00008000 -n 'Linux-$(LINUX_VERSION)' \
  78. -d '$(KDIR)/$(1)-zImage$(2)' '$(KDIR)/$(1)-uImage$(2)'
  79. ifeq ($(2),-initramfs) # only copy uImage for ramdisk build
  80. cp '$(KDIR)/$(1)-uImage-initramfs' '$(BIN_DIR)/openwrt-$(1)-uImage-initramfs'
  81. endif
  82. endef
  83. define Image/BuildKernel/JFFS2uImage
  84. # create JFFS2 partition with uImage file (result is already padded to erase size)
  85. # parameters: 1 = machine name, 2 = erase size in KiB, 3 = uImage file name
  86. # $(BOARD) kernel uImage for $(1) in JFFS2-$(2)k partition
  87. rm -rf '$(TMP_DIR)/$(1)_jffs2_uimage'
  88. mkdir '$(TMP_DIR)/$(1)_jffs2_uimage'
  89. cp '$(KDIR)/$(1)-uImage' '$(TMP_DIR)/$(1)_jffs2_uimage/$(3)'
  90. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --compression-mode=none --pad --little-endian --squash -e $(2)KiB -o '$(KDIR)/$(1)-uImage.jffs2' -d '$(TMP_DIR)/$(1)_jffs2_uimage'
  91. rm -rf '$(TMP_DIR)/$(1)_jffs2_uimage'
  92. endef
  93. define Image/Default/FileSizeCheck
  94. # parameters: 1 = file path, 2 = maximum size in bytes
  95. [ `stat -c %s '$(1)'` -le $(2) ] || { echo ' ERROR: $(1) too big (> $(2) bytes)'; rm -f $(1); }
  96. endef
  97. ###
  98. ### Image/Build
  99. ###
  100. define Image/Build
  101. ### Dummy comment for indented calls of Image/Build with $(1)
  102. ## Prepare rootfs
  103. $(call Image/Build/$(1),$(1))
  104. ## Netgear WN802T
  105. $(call Image/Build/Default,$(1),wn802t,$(ERASE_SIZE_64K),$(KERNEL_MTD_SIZE),.jffs2,NG_WN802T)
  106. ## Netgear WNR854T
  107. $(call Image/Build/Default,$(1),wnr854t,$(ERASE_SIZE_128K),$(KERNEL_MTD_SIZE),.jffs2,NG_WNR854T)
  108. ## Linksys WRT350N v2
  109. $(call Image/Build/Linksys/wrt350nv2,$(1),wrt350nv2,$(ERASE_SIZE_64K),$(KERNEL_MTD_SIZE),)
  110. ## Buffalo Terastation Pro II/Live
  111. $(call Image/Build/Default,$(1),terastation-pro2,$(ERASE_SIZE_128K),$(KERNEL_MTD_SIZE),.jffs2,TERASTATION_PRO2)
  112. endef
  113. define Image/Build/squashfs
  114. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  115. endef
  116. ## generate defines for all JFFS2 block sizes
  117. define Image/Build/jffs2/sub
  118. $(eval define Image/Build/jffs2-$(1)
  119. cp '$$(KDIR)/root.jffs2-$(1)' '$$(BIN_DIR)/$$(IMG_PREFIX)-root.jffs2-$(1)'
  120. endef)
  121. endef
  122. $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/Build/jffs2/sub,$(SZ)))
  123. define Image/Build/Default
  124. # parameters: 1 = rootfs type, 2 = machine name, 3 = erase size in KiB, 4 = kernel mtd size in KiB, 5 = kernel file suffix, 6 = header
  125. ifeq ($(findstring jffs2-,$(1)),jffs2-) # JFFS2: build only image fitting to erase size
  126. ifeq ($(1),jffs2-$(3)k)
  127. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  128. $(call Image/Build/Default/factory,$(1),$(2),$(6))
  129. endif
  130. else
  131. ifeq ($(1),ext4) # EXT4: ignore
  132. # do nothing
  133. else # do all other images
  134. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  135. $(call Image/Build/Default/factory,$(1),$(2),$(6))
  136. endif
  137. endif
  138. endef
  139. define Image/Build/Default/sysupgrade
  140. # parameters: 1 = rootfs type, 2 = machine name, 3 = pad size in KiB (kernel mtd size or erase size), 4 = kernel file suffix
  141. # $(BOARD) $(1) sysupgrade image for $(2)
  142. ( \
  143. dd if='$(KDIR)/$(2)-uImage$(4)' bs=$(3)k conv=sync; \
  144. dd if='$(KDIR)/root.$(1)'; \
  145. ) > '$(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img'
  146. endef
  147. define Image/Build/Default/factory
  148. # parameters: 1 = rootfs type, 2 = machine name, 3 = header
  149. # $(BOARD) $(1) factory upgrade image for $(2)
  150. '$(STAGING_DIR_HOST)/bin/add_header' $(3) '$(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img' '$(BIN_DIR)/openwrt-$(2)-$(1)-factory.img'
  151. endef
  152. ##
  153. ## Image/Build/Linksys
  154. ##
  155. define Image/Build/Linksys/wrt350nv2
  156. # parameters: 1 = rootfs type, 2 = machine name, 3 = erase size in KiB, 4 = kernel mtd size in KiB, 5 = kernel file suffix
  157. ifeq ($(findstring jffs2-,$(1)),jffs2-) # JFFS2: build only image fitting to erase size
  158. ifeq ($(1),jffs2-$(3)k)
  159. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  160. $(call Image/Build/Linksys/wrt350nv2-builder,$(1),$(2))
  161. endif
  162. else
  163. ifeq ($(1),ext4) # EXT4: ignore
  164. # do nothing
  165. else # do all other images
  166. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  167. $(call Image/Build/Linksys/wrt350nv2-builder,$(1),$(2))
  168. endif
  169. endif
  170. endef
  171. define Image/Build/Linksys/wrt350nv2-builder
  172. # parameters: 1 = rootfs type, 2 = machine name
  173. # $(BOARD) $(1) factory and recovery image for $(2) via wrt350nv2-builder
  174. rm -rf '$(TMP_DIR)/$(2)_factory'
  175. mkdir '$(TMP_DIR)/$(2)_factory'
  176. # create parameter file
  177. echo ':image 0 $(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img' > '$(TMP_DIR)/$(2)_factory/$(2).par'
  178. [ ! -f '$(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin' ] || ( \
  179. echo ':u-boot 0 $(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin' >> '$(TMP_DIR)/$(2)_factory/$(2).par'; \
  180. )
  181. echo '#version 0x2020' >> '$(TMP_DIR)/$(2)_factory/$(2).par'
  182. # create bin file for recovery and factory image
  183. -( \
  184. cd '$(TMP_DIR)/$(2)_factory'; \
  185. '$(STAGING_DIR_HOST)/bin/wrt350nv2-builder' -b '$(TMP_DIR)/$(2)_factory/$(2).par'; \
  186. ) && $(CP) '$(TMP_DIR)/$(2)_factory/wrt350n.bin' '$(BIN_DIR)/openwrt-$(2)-$(1)-recovery.bin' && \
  187. ( \
  188. cd '$(TMP_DIR)/$(2)_factory'; \
  189. zip 'wrt350n.zip' 'wrt350n.bin'; \
  190. ) && '$(STAGING_DIR_HOST)/bin/wrt350nv2-builder' -z '$(TMP_DIR)/$(2)_factory/wrt350n.zip' '$(BIN_DIR)/openwrt-$(2)-$(1)-factory.img'
  191. rm -rf '$(TMP_DIR)/$(2)_factory'
  192. endef
  193. ###
  194. ### Image/PreReq
  195. ###
  196. ## Dependency for WRT350N v2 factory image
  197. $(eval $(call RequireCommand,zip, \
  198. Please install zip. \
  199. ))