Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. #
  2. # Copyright (C) 2008-2009 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. IMGNAME:=$(BIN_DIR)/openwrt-$(BOARD)
  10. define imgname
  11. $(IMGNAME)-$(2)-$(patsubst jffs2-%,jffs2,$(patsubst squashfs-%,squashfs,$(1)))
  12. endef
  13. VMLINUX:=$(IMGNAME)-vmlinux
  14. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  15. VMLINUX:=$(IMGNAME)-vmlinux-initramfs
  16. endif
  17. define Image/BuildKernel
  18. cp $(KDIR)/vmlinux.elf $(VMLINUX).elf
  19. cp $(KDIR)/vmlinux $(VMLINUX).bin
  20. gzip -9 -c $(KDIR)/vmlinux > $(KDIR)/vmlinux.bin.gz
  21. $(STAGING_DIR_HOST)/bin/lzma e $(KDIR)/vmlinux $(KDIR)/vmlinux.bin.l7
  22. $(STAGING_DIR_HOST)/bin/lzma e $(KDIR)/vmlinux -lc1 -lp2 -pb2 $(KDIR)/vmlinux.bin.lzma
  23. dd if=$(KDIR)/vmlinux.bin.l7 of=$(VMLINUX).lzma bs=65536 conv=sync
  24. dd if=$(KDIR)/vmlinux.bin.gz of=$(VMLINUX).gz bs=65536 conv=sync
  25. mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
  26. 0x80060000 \
  27. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  28. -d $(KDIR)/vmlinux.bin.gz $(IMGNAME)-uImage-gzip.bin
  29. mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
  30. 0x80060000 \
  31. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  32. -d $(KDIR)/vmlinux.bin.lzma $(IMGNAME)-uImage-lzma.bin
  33. endef
  34. define Image/Build/WRT400N
  35. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  36. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  37. $(STAGING_DIR_HOST)/bin/lzma e $(KDIR)/vmlinux-$(2) $(KDIR)/vmlinux-$(2).bin.lzma
  38. if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 1310720 ]; then \
  39. echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
  40. else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6488064 ]; then \
  41. echo "Warning: $(KDIR)/root.$(1) is too big"; \
  42. else \
  43. mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
  44. 0x80060000 \
  45. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  46. -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
  47. ( \
  48. dd if=$(KDIR)/vmlinux-$(2).uImage bs=1280k conv=sync; \
  49. dd if=$(KDIR)/root.$(1) bs=6336k conv=sync; \
  50. echo -n $(4); \
  51. ) > $(call imgname,$(1),$(2)).bin; \
  52. wrt400n $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) $(call imgname,$(1),$(2)).webui; \
  53. fi; fi
  54. endef
  55. define Image/Build/AP81
  56. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  57. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  58. $(STAGING_DIR_HOST)/bin/lzma e $(KDIR)/vmlinux-$(2) $(KDIR)/vmlinux-$(2).bin.lzma
  59. if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 851968 ]; then \
  60. echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
  61. else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 3014656 ]; then \
  62. echo "Warning: $(KDIR)/root.$(1) is too big"; \
  63. else \
  64. mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
  65. 0x80060000 \
  66. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  67. -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
  68. ( \
  69. dd if=$(KDIR)/vmlinux-$(2).uImage bs=832k conv=sync; \
  70. dd if=$(KDIR)/root.$(1) bs=2944k conv=sync; \
  71. echo -n $(4); \
  72. ) > $(call imgname,$(1),$(2)).uni; \
  73. fi; fi
  74. endef
  75. define Image/Build/AP83
  76. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  77. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  78. gzip -9 -c $(KDIR)/vmlinux-$(2) > $(KDIR)/vmlinux-$(2).bin.gz
  79. if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.gz"` -gt 1310720 ]; then \
  80. echo "Warning: $(KDIR)/vmlinux-$(2).bin.gz is too big"; \
  81. else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6619136 ]; then \
  82. echo "Warning: $(KDIR)/root.$(1) is too big"; \
  83. else \
  84. mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
  85. 0x80060000 \
  86. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  87. -d $(KDIR)/vmlinux-$(2).bin.gz \
  88. $(KDIR)/vmlinux-$(2).uImage; \
  89. dd if=$(KDIR)/vmlinux-$(2).uImage \
  90. of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync; \
  91. dd if=$(KDIR)/root.$(1) \
  92. of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync; \
  93. ( \
  94. dd if=$(KDIR)/vmlinux-$(2).uImage bs=1280k conv=sync; \
  95. dd if=$(KDIR)/root.$(1); \
  96. ) > $(call imgname,$(1),$(2)-firmware).bin; \
  97. fi; fi
  98. endef
  99. define Image/Build/MyLoader
  100. -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) \
  101. -p0x30000:0xc0000:al:0x80060000:kernel:$(KDIR)/vmlinux.bin.lzma \
  102. -p0xf0000:0:::rootfs:$(KDIR)/root.$(1) \
  103. $(call imgname,$(1),$(2)).img
  104. endef
  105. define Image/Build/UBNT
  106. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  107. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  108. $(STAGING_DIR_HOST)/bin/lzma e $(KDIR)/vmlinux-$(2) $(KDIR)/vmlinux-$(2).lzma
  109. dd if=$(KDIR)/vmlinux-$(2).lzma of=$(KDIR)/vmlinux-$(2).bin.lzma bs=64k conv=sync
  110. -$(STAGING_DIR_HOST)/bin/mkfwimage \
  111. -B $(4) -v $(5).$(6).OpenWrt.$(REVISION) \
  112. -k $(KDIR)/vmlinux-$(2).bin.lzma \
  113. -r $(BIN_DIR)/openwrt-$(BOARD)-root.$(1) \
  114. -o $(call imgname,$(1),$(2)).bin
  115. endef
  116. define Image/Build/Planex
  117. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  118. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  119. gzip -9 -c $(KDIR)/vmlinux-$(2) > $(KDIR)/vmlinux-$(2).bin.gzip
  120. if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.gzip"` -gt 1441792 ]; then \
  121. echo "Warning: $(KDIR)/vmlinux-$(2).bin.gzip is too big"; \
  122. else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6356992 ]; then \
  123. echo "Warning: $(KDIR)/root.$(1) is too big"; \
  124. else \
  125. mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
  126. 0x80060000 \
  127. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  128. -d $(KDIR)/vmlinux-$(2).bin.gzip $(KDIR)/vmlinux-$(2).uImage; \
  129. ( \
  130. dd if=$(KDIR)/vmlinux-$(2).uImage bs=1408k conv=sync; \
  131. dd if=$(KDIR)/root.$(1) bs=6208k conv=sync; \
  132. ) > $(call imgname,$(1),$(2)).bin; \
  133. $(STAGING_DIR_HOST)/bin/mkplanexfw \
  134. -B $(2) \
  135. -v 2.00.00 \
  136. -i $(call imgname,$(1),$(2)).bin \
  137. -o $(call imgname,$(1),$(2)).webui; \
  138. fi; fi
  139. endef
  140. define Image/Build/TPLINK
  141. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  142. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  143. gzip -9 -c $(KDIR)/vmlinux-$(2) > $(KDIR)/vmlinux-$(2).bin.gzip
  144. -$(STAGING_DIR_HOST)/bin/mktplinkfw \
  145. -B $(4) -N OpenWrt -V $(REVISION)\
  146. -k $(KDIR)/vmlinux-$(2).bin.gzip \
  147. -r $(BIN_DIR)/openwrt-$(BOARD)-root.$(1) \
  148. -o $(call imgname,$(1),$(2)).uni
  149. endef
  150. define Image/Build/CyberTAN
  151. cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(2)
  152. $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(2) '$(strip $(3))'
  153. gzip -9 -c $(KDIR)/vmlinux-$(2) > $(KDIR)/vmlinux-$(2).bin.gzip
  154. mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
  155. 0x80060000 \
  156. -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
  157. -d $(KDIR)/vmlinux-$(2).bin.gzip $(KDIR)/vmlinux-$(2).uImage
  158. ( \
  159. dd if=$(KDIR)/vmlinux-$(2).uImage bs=64k conv=sync; \
  160. dd if=/dev/zero bs=1 count=65476; \
  161. dd if=$(KDIR)/root.$(1) bs=64k; \
  162. ) > $(KDIR)/vmlinux-$(2).image
  163. $(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/vmlinux-$(2).trx \
  164. -f $(KDIR)/vmlinux-$(2).image
  165. -$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) -g \
  166. -i $(KDIR)/vmlinux-$(2).trx \
  167. -o $(call imgname,$(1),$(2)).bin
  168. endef
  169. define Image/Build/Template/Compex
  170. $(call Image/Build/MyLoader,$(1),$(2))
  171. endef
  172. define Image/Build/Template/Compex/squashfs
  173. $(call Image/Build/Template/Compex,squashfs,$(1))
  174. endef
  175. define Image/Build/Template/WRT400N
  176. $(call Image/Build/WRT400N,$(1),$(2),$(3),$(4))
  177. endef
  178. define Image/Build/Template/WRT400N/squashfs
  179. $(call Image/Build/Template/WRT400N,squashfs,$(1),$(2),$(3))
  180. endef
  181. define Image/Build/Template/WRT400N/jffs2-64k
  182. $(call Image/Build/Template/WRT400N,jffs2-64k,$(1),$(2),$(3))
  183. endef
  184. define Image/Build/Template/CyberTAN
  185. $(call Image/Build/CyberTAN,$(1),$(2),$(3),$(4))
  186. endef
  187. define Image/Build/Template/CyberTAN/squashfs
  188. $(call Image/Build/Template/CyberTAN,squashfs,$(1),$(2),$(3))
  189. endef
  190. define Image/Build/Template/CyberTAN/jffs2-64k
  191. $(call Image/Build/Template/CyberTAN,jffs2-64k,$(1),$(2),$(3))
  192. endef
  193. define Image/Build/Template/AP81
  194. $(call Image/Build/AP81,$(1),$(2),$(3),$(4))
  195. endef
  196. define Image/Build/Template/AP81/squashfs
  197. $(call Image/Build/Template/AP81,squashfs,$(1),$(2),$(3))
  198. endef
  199. define Image/Build/Template/AP83
  200. $(call Image/Build/AP83,$(1),$(2),$(3))
  201. endef
  202. define Image/Build/Template/AP83/squashfs
  203. $(call Image/Build/Template/AP83,squashfs,$(1),$(2))
  204. endef
  205. define Image/Build/Template/AP83/jffs2-64k
  206. $(call Image/Build/Template/AP83,jffs2-64k,$(1),$(2))
  207. endef
  208. define Image/Build/Template/TPLINK
  209. $(call Image/Build/TPLINK,$(1),$(2),$(3),$(4))
  210. endef
  211. define Image/Build/Template/TPLINK/squashfs
  212. $(call Image/Build/Template/TPLINK,squashfs,$(1),$(2),$(3))
  213. endef
  214. define Image/Build/Template/TPLINK4K
  215. $(call Image/Build/TPLINK,$(1),$(2),$(3),$(4))
  216. endef
  217. define Image/Build/Template/TPLINK4K/squashfs
  218. $(call Image/Build/Template/TPLINK,squashfs-4k,$(1),$(2),$(3))
  219. endef
  220. define Image/Build/Template/UBNT
  221. $(call Image/Build/UBNT,$(1),$(2),$(3),$(4),$(5),$(6))
  222. endef
  223. define Image/Build/Template/UBNT/squashfs
  224. $(call Image/Build/Template/UBNT,squashfs,$(1),$(2),$(3),$(4),$(5))
  225. endef
  226. define Image/Build/Template/UBNT/jffs2-64k
  227. $(call Image/Build/Template/UBNT,jffs2-64k,$(1),$(2),$(3),$(4),$(5))
  228. endef
  229. define Image/Build/Template/Planex
  230. $(call Image/Build/Planex,$(1),$(2),$(3))
  231. endef
  232. define Image/Build/Template/Planex/squashfs
  233. $(call Image/Build/Template/Planex,squashfs,$(1),$(2))
  234. endef
  235. define Image/Build/Template/Planex/jffs2-64k
  236. $(call Image/Build/Template/Planex,jffs2-64k,$(1),$(2))
  237. endef
  238. define Image/Build/Profile/AP83
  239. $(call Image/Build/Template/AP83/$(1),ap83,board=AP83)
  240. endef
  241. define Image/Build/Profile/WP543
  242. $(call Image/Build/Template/Compex/$(1),wp543)
  243. endef
  244. define Image/Build/Profile/DIR615C1
  245. $(call Image/Build/Template/AP81/$(1),dir-615c1,board=TEW-632BRP,"AP81-AR9130-RT-070614-02")
  246. endef
  247. define Image/Build/Profile/TEW632BRP
  248. $(call Image/Build/Template/AP81/$(1),tew-632brp,board=TEW-632BRP,"AP81-AR9130-RT-070614-00")
  249. endef
  250. define Image/Build/Profile/TEW652BRP
  251. $(call Image/Build/Template/AP81/$(1),tew-652brp,board=TEW-632BRP,"AP81-AR9130-RT-080609-05")
  252. endef
  253. define Image/Build/Profile/A02RBW300N
  254. $(call Image/Build/Template/AP81/$(1),a02-rb-w300n,board=TEW-632BRP,"AP81-AR9130-RT-070614-03")
  255. endef
  256. define Image/Build/Profile/UBNTRS
  257. $(call Image/Build/Template/UBNT/$(1),ubnt-rs,board=UBNT-RS,RS,RSx,ar7100)
  258. endef
  259. define Image/Build/Profile/UBNTRSPRO
  260. $(call Image/Build/Template/UBNT/$(1),ubnt-rspro,board=UBNT-RSPRO,RSPRO,RSPRO,ar7100pro)
  261. endef
  262. define Image/Build/Profile/UBNTLSSR71
  263. $(call Image/Build/Template/UBNT/$(1),ubnt-ls-sr71,board=UBNT-LS-SR71,LS-SR71,LS-SR71,ar7100)
  264. endef
  265. define Image/Build/Profile/UBNT
  266. $(call Image/Build/Profile/UBNTRS,$(1))
  267. $(call Image/Build/Profile/UBNTRSPRO,$(1))
  268. $(call Image/Build/Profile/UBNTLSSR71,$(1))
  269. endef
  270. define Image/Build/Profile/MZKW04NU
  271. $(call Image/Build/Template/Planex/$(1),mzk-w04nu,board=MZK-W04NU)
  272. endef
  273. define Image/Build/Profile/MZKW300NH
  274. $(call Image/Build/Template/Planex/$(1),mzk-w300nh,board=MZK-W300NH)
  275. endef
  276. define Image/Build/Profile/TLWR741NDV1
  277. $(call Image/Build/Template/TPLINK4K/$(1),tl-wr741ndv1,board=TL-WR741ND,TL-WR741NDv1)
  278. endef
  279. define Image/Build/Profile/TLWR841NDV3
  280. $(call Image/Build/Template/TPLINK/$(1),tl-wr841ndv3,board=TL-WR941ND,TL-WR841NDv3)
  281. endef
  282. define Image/Build/Profile/TLWR941NDV2
  283. $(call Image/Build/Template/TPLINK/$(1),tl-wr941ndv2,board=TL-WR941ND,TL-WR941NDv2)
  284. endef
  285. define Image/Build/Profile/WRT400N
  286. $(call Image/Build/Template/WRT400N/$(1),wrt400n,board=WRT400N)
  287. endef
  288. define Image/Build/Profile/WRT160NL
  289. $(call Image/Build/Template/CyberTAN/$(1),wrt160nl,board=WRT160NL,1.00.01)
  290. endef
  291. define Image/Build/Profile/Default
  292. $(call Image/Build/Profile/AP83,$(1))
  293. $(call Image/Build/Profile/A02RBW300N,$(1))
  294. $(call Image/Build/Profile/DIR615C1,$(1))
  295. $(call Image/Build/Profile/MZKW04NU,$(1))
  296. $(call Image/Build/Profile/MZKW300NH,$(1))
  297. $(call Image/Build/Profile/TEW632BRP,$(1))
  298. $(call Image/Build/Profile/TEW652BRP,$(1))
  299. $(call Image/Build/Profile/TLWR741NDV1,$(1))
  300. $(call Image/Build/Profile/TLWR841NDV3,$(1))
  301. $(call Image/Build/Profile/TLWR941NDV2,$(1))
  302. $(call Image/Build/Profile/UBNT,$(1))
  303. $(call Image/Build/Profile/WP543,$(1))
  304. $(call Image/Build/Profile/WRT400N,$(1))
  305. $(call Image/Build/Profile/WRT160NL,$(1))
  306. endef
  307. define Image/Build/Profile/Madwifi
  308. $(call Image/Build/Profile/UBNT,$(1))
  309. $(call Image/Build/Profile/WP543,$(1))
  310. endef
  311. define Image/Build/squashfs
  312. dd if=$(KDIR)/root.squashfs of=$(IMGNAME)-root.squashfs-4k bs=4k conv=sync
  313. $(call add_jffs2_mark,$(IMGNAME)-root.squashfs-4k)
  314. $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
  315. endef
  316. define Image/Build
  317. $(call Image/Build/$(1))
  318. dd if=$(KDIR)/root.$(1) of=$(IMGNAME)-root.$(1) bs=128k conv=sync
  319. $(call Image/Build/Profile/$(PROFILE),$(1))
  320. endef
  321. $(eval $(call BuildImage))