generic.mk 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. endef
  58. define Image/BuildKernel/ARM/zImage
  59. # merge machine id and regular zImage into one file
  60. # parameters: 1 = machine name, 2 = machine id as string in quotes
  61. # $(BOARD) kernel zImage for $(1)
  62. echo -en $(2) > '$(KDIR)/$(1)-zImage$(3)'
  63. cat '$(KDIR)/zImage$(3)' >> '$(KDIR)/$(1)-zImage$(3)'
  64. endef
  65. define Image/BuildKernel/ARM/uImage
  66. # create uImage from zImage
  67. # parameters: 1 = machine name
  68. # $(BOARD) kernel uImage for $(1)
  69. '$(STAGING_DIR_HOST)/bin/mkimage' -A arm -O linux -T kernel \
  70. -C none -a 0x00008000 -e 0x00008000 -n 'Linux-$(LINUX_VERSION)' \
  71. -d '$(KDIR)/$(1)-zImage$(2)' '$(KDIR)/$(1)-uImage$(2)'
  72. ifeq ($(2),-initramfs) # only copy uImage for ramdisk build
  73. cp '$(KDIR)/$(1)-uImage-initramfs' '$(BIN_DIR)/openwrt-$(1)-uImage-initramfs'
  74. endif
  75. endef
  76. define Image/BuildKernel/JFFS2uImage
  77. # create JFFS2 partition with uImage file (result is already padded to erase size)
  78. # parameters: 1 = machine name, 2 = erase size in KiB, 3 = uImage file name
  79. # $(BOARD) kernel uImage for $(1) in JFFS2-$(2)k partition
  80. rm -rf '$(TMP_DIR)/$(1)_jffs2_uimage'
  81. mkdir '$(TMP_DIR)/$(1)_jffs2_uimage'
  82. cp '$(KDIR)/$(1)-uImage' '$(TMP_DIR)/$(1)_jffs2_uimage/$(3)'
  83. $(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'
  84. rm -rf '$(TMP_DIR)/$(1)_jffs2_uimage'
  85. endef
  86. define Image/Default/FileSizeCheck
  87. # parameters: 1 = file path, 2 = maximum size in bytes
  88. [ `stat -c %s '$(1)'` -le $(2) ] || { echo ' ERROR: $(1) too big (> $(2) bytes)'; exit 1; }
  89. endef
  90. ###
  91. ### Image/Build
  92. ###
  93. define Image/Build
  94. ### Dummy comment for indented calls of Image/Build with $(1)
  95. ## Prepare rootfs
  96. $(call Image/Build/$(1),$(1))
  97. ## Netgear WN802T
  98. $(call Image/Build/Default,$(1),wn802t,$(ERASE_SIZE_64K),$(KERNEL_MTD_SIZE),.jffs2,NG_WN802T)
  99. ## Netgear WNR854T
  100. $(call Image/Build/Default,$(1),wnr854t,$(ERASE_SIZE_128K),$(KERNEL_MTD_SIZE),.jffs2,NG_WNR854T)
  101. ## Linksys WRT350N v2
  102. $(call Image/Build/Linksys/wrt350nv2,$(1),wrt350nv2,$(ERASE_SIZE_64K),$(KERNEL_MTD_SIZE),)
  103. endef
  104. define Image/Build/squashfs
  105. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  106. endef
  107. ## generate defines for all JFFS2 block sizes
  108. define Image/Build/jffs2/sub
  109. $(eval define Image/Build/jffs2-$(1)
  110. cp '$$(KDIR)/root.jffs2-$(1)' '$$(BIN_DIR)/$$(IMG_PREFIX)-root.jffs2-$(1)'
  111. endef)
  112. endef
  113. $(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/Build/jffs2/sub,$(SZ)))
  114. define Image/Build/Default
  115. # parameters: 1 = rootfs type, 2 = machine name, 3 = erase size in KiB, 4 = kernel mtd size in KiB, 5 = kernel file suffix, 6 = header
  116. ifeq ($(findstring jffs2-,$(1)),jffs2-) # JFFS2: build only image fitting to erase size
  117. ifeq ($(1),jffs2-$(3)k)
  118. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  119. $(call Image/Build/Default/factory,$(1),$(2),$(6))
  120. endif
  121. else
  122. ifeq ($(1),ext4) # EXT4: ignore
  123. # do nothing
  124. else # do all other images
  125. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  126. $(call Image/Build/Default/factory,$(1),$(2),$(6))
  127. endif
  128. endif
  129. endef
  130. define Image/Build/Default/sysupgrade
  131. # parameters: 1 = rootfs type, 2 = machine name, 3 = pad size in KiB (kernel mtd size or erase size), 4 = kernel file suffix
  132. # $(BOARD) $(1) sysupgrade image for $(2)
  133. ( \
  134. dd if='$(KDIR)/$(2)-uImage$(4)' bs=$(3)k conv=sync; \
  135. dd if='$(KDIR)/root.$(1)'; \
  136. ) > '$(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img'
  137. endef
  138. define Image/Build/Default/factory
  139. # parameters: 1 = rootfs type, 2 = machine name, 3 = header
  140. # $(BOARD) $(1) factory upgrade image for $(2)
  141. '$(STAGING_DIR_HOST)/bin/add_header' $(3) '$(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img' '$(BIN_DIR)/openwrt-$(2)-$(1)-factory.img'
  142. endef
  143. ##
  144. ## Image/Build/Linksys
  145. ##
  146. define Image/Build/Linksys/wrt350nv2
  147. # parameters: 1 = rootfs type, 2 = machine name, 3 = erase size in KiB, 4 = kernel mtd size in KiB, 5 = kernel file suffix
  148. ifeq ($(findstring jffs2-,$(1)),jffs2-) # JFFS2: build only image fitting to erase size
  149. ifeq ($(1),jffs2-$(3)k)
  150. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  151. $(call Image/Build/Linksys/wrt350nv2-builder,$(1),$(2))
  152. endif
  153. else
  154. ifeq ($(1),ext4) # EXT4: ignore
  155. # do nothing
  156. else # do all other images
  157. $(call Image/Build/Default/sysupgrade,$(1),$(2),$(4),$(5))
  158. $(call Image/Build/Linksys/wrt350nv2-builder,$(1),$(2))
  159. endif
  160. endif
  161. endef
  162. define Image/Build/Linksys/wrt350nv2-builder
  163. # parameters: 1 = rootfs type, 2 = machine name
  164. # $(BOARD) $(1) factory and recovery image for $(2) via wrt350nv2-builder
  165. rm -rf '$(TMP_DIR)/$(2)_factory'
  166. mkdir '$(TMP_DIR)/$(2)_factory'
  167. # create parameter file
  168. echo ':image 0 $(BIN_DIR)/openwrt-$(2)-$(1)-sysupgrade.img' > '$(TMP_DIR)/$(2)_factory/$(2).par'
  169. [ ! -f '$(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin' ] || ( \
  170. echo ':u-boot 0 $(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin' >> '$(TMP_DIR)/$(2)_factory/$(2).par'; \
  171. )
  172. echo '#version 0x2020' >> '$(TMP_DIR)/$(2)_factory/$(2).par'
  173. # create bin file for recovery and factory image
  174. ( \
  175. cd '$(TMP_DIR)/$(2)_factory'; \
  176. '$(STAGING_DIR_HOST)/bin/wrt350nv2-builder' -b '$(TMP_DIR)/$(2)_factory/$(2).par'; \
  177. )
  178. # copy bin file as recovery image
  179. $(CP) '$(TMP_DIR)/$(2)_factory/wrt350n.bin' '$(BIN_DIR)/openwrt-$(2)-$(1)-recovery.bin'
  180. # create factory image for stock firmware update mechanism
  181. ( \
  182. cd '$(TMP_DIR)/$(2)_factory'; \
  183. zip 'wrt350n.zip' 'wrt350n.bin'; \
  184. )
  185. '$(STAGING_DIR_HOST)/bin/wrt350nv2-builder' -z '$(TMP_DIR)/$(2)_factory/wrt350n.zip' '$(BIN_DIR)/openwrt-$(2)-$(1)-factory.img'
  186. rm -rf '$(TMP_DIR)/$(2)_factory'
  187. endef
  188. ###
  189. ### Image/PreReq
  190. ###
  191. ## Dependency for WRT350N v2 factory image
  192. $(eval $(call RequireCommand,zip, \
  193. Please install zip. \
  194. ))