Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. #
  2. # Copyright (C) 2006-2016 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. define Build/Clean
  10. $(MAKE) -C lzma-loader clean
  11. endef
  12. define Image/Prepare
  13. # Optimized LZMA compression (with dictionary), handled by lzma-loader.
  14. cat $(KDIR)/vmlinux | $(STAGING_DIR_HOST)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $(KDIR)/vmlinux.lzma
  15. # Less optimal LZMA compression (no dictionary), handled by CFE.
  16. $(STAGING_DIR_HOST)/bin/lzma e -so -d16 $(KDIR)/vmlinux > $(KDIR)/vmlinux-nodictionary.lzma
  17. gzip -nc9 $(KDIR)/vmlinux > $(KDIR)/vmlinux.gz
  18. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  19. cat $(KDIR)/vmlinux-initramfs | $(STAGING_DIR_HOST)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $(KDIR)/vmlinux-initramfs.lzma
  20. $(STAGING_DIR_HOST)/bin/lzma e -so -d16 $(KDIR)/vmlinux-initramfs > $(KDIR)/vmlinux-initramfs-nodictionary.lzma
  21. endif
  22. rm -f $(KDIR)/loader.gz
  23. $(MAKE) -C lzma-loader \
  24. BUILD_DIR="$(KDIR)" \
  25. TARGET="$(KDIR)" \
  26. clean install
  27. echo -ne "\\x00" >> $(KDIR)/loader.gz
  28. rm -f $(KDIR)/fs_mark
  29. echo -ne '\xde\xad\xc0\xde' > $(KDIR)/fs_mark
  30. $(call prepare_generic_squashfs,$(KDIR)/fs_mark)
  31. endef
  32. define trxalign/jffs2-128k
  33. -a 0x20000 -f $(KDIR)/root.$(1)
  34. endef
  35. define trxalign/jffs2-64k
  36. -a 0x10000 -f $(KDIR)/root.$(1)
  37. endef
  38. define trxalign/squashfs
  39. -a 1024 -f $(KDIR)/root.$(1) $(if $(2),-f $(2)) -a 0x10000 -A $(KDIR)/fs_mark
  40. endef
  41. #################################################
  42. # Images
  43. #################################################
  44. define Build/trx-with-loader
  45. $(STAGING_DIR_HOST)/bin/trx \
  46. -m 33554432 \
  47. -o $@ \
  48. -f $(KDIR)/loader.gz \
  49. -f $(word 1,$^) \
  50. $(call trxalign/$(FILESYSTEM),$(FILESYSTEM))
  51. endef
  52. define Build/trx-v2-with-loader
  53. $(STAGING_DIR_HOST)/bin/trx \
  54. -2 \
  55. -m 33554432 \
  56. -o $@.new \
  57. -f $(KDIR)/loader.gz \
  58. -f $(KDIR)/vmlinux.lzma \
  59. $(call trxalign/$(FILESYSTEM),$(FILESYSTEM),$@)
  60. mv $@.new $@
  61. endef
  62. define Build/trx-without-loader
  63. $(STAGING_DIR_HOST)/bin/trx \
  64. -m 33554432 \
  65. -o $@ \
  66. -f $(word 1,$^) \
  67. $(call trxalign/$(FILESYSTEM),$(FILESYSTEM))
  68. endef
  69. define Build/asus-trx
  70. $(STAGING_DIR_HOST)/bin/asustrx -p "$(PRODUCTID)" -i $@ -o $@.new
  71. mv $@.new $@
  72. endef
  73. define Build/edimax-bin
  74. $(STAGING_DIR_HOST)/bin/trx2edips $@ $@.new
  75. mv $@.new $@
  76. endef
  77. define Build/huawei-bin
  78. dd if=/dev/zero of=$@.new bs=92 count=1
  79. echo -ne 'HDR0\x08\x00\x00\x00' >> $@.new
  80. cat $@ >> $@.new
  81. mv $@.new $@
  82. endef
  83. define Build/linksys-bin
  84. $(STAGING_DIR_HOST)/bin/addpattern -4 -p $(DEVICE_ID) -v v$(VERSION) $(if $(SERIAL),-s $(SERIAL)) -i $@ -o $@.new
  85. mv $@.new $@
  86. endef
  87. define Build/linksys-pattern-partition
  88. $(STAGING_DIR_HOST)/bin/addpattern -5 -p $(DEVICE_ID) -v v$(VERSION) $(if $(SERIAL),-s $(SERIAL)) -i /dev/null -o $@
  89. endef
  90. define Build/motorola-bin
  91. $(STAGING_DIR_HOST)/bin/motorola-bin -$(MOTOROLA_DEVICE) $@ $@.new
  92. mv $@.new $@
  93. endef
  94. define Build/prepend-with-elf
  95. mv $@ $@.old
  96. dd if=$(KDIR)/loader.elf of=$@ bs=131072 conv=sync
  97. cat $@.old >> $@
  98. endef
  99. define Build/tailed-bin
  100. echo $(BIN_TAIL) >> $@
  101. endef
  102. define Build/usrobotics-bin
  103. $(STAGING_DIR_HOST)/bin/trx2usr $@ $@.new
  104. mv $@.new $@
  105. endef
  106. #################################################
  107. # Devices
  108. #################################################
  109. DEVICE_VARS += PRODUCTID
  110. DEVICE_VARS += DEVICE_ID VERSION SERIAL
  111. DEVICE_VARS += NETGEAR_BOARD_ID NETGEAR_REGION
  112. DEVICE_VARS += MOTOROLA_DEVICE
  113. DEVICE_VARS += BIN_TAIL
  114. define Device/Default
  115. KERNEL := kernel-bin
  116. IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1).$$(2)
  117. KERNEL_NAME = vmlinux.lzma
  118. FILESYSTEMS := $(FS_64K)
  119. IMAGES := trx
  120. IMAGE/trx := trx-with-loader
  121. endef
  122. define Device/standard
  123. endef
  124. define Device/standard-noloader-gz
  125. KERNEL_NAME = vmlinux.gz
  126. IMAGE/trx := trx-without-loader
  127. endef
  128. define Device/standard-noloader-nodictionarylzma
  129. KERNEL_NAME = vmlinux-nodictionary.lzma
  130. IMAGE/trx := trx-without-loader
  131. endef
  132. define Device/asus
  133. IMAGES := trx
  134. IMAGE/trx := trx-with-loader | asus-trx
  135. endef
  136. define AsusDevice
  137. define Device/asus-$(1)
  138. $$(Device/asus)
  139. PRODUCTID := $(2)
  140. endef
  141. TARGET_DEVICES += asus-$(1)
  142. endef
  143. define Device/linksys
  144. IMAGES := bin
  145. IMAGE/bin := trx-with-loader | linksys-bin
  146. endef
  147. define LinksysDevice
  148. define Device/linksys-$(1)
  149. $$(Device/linksys)
  150. DEVICE_ID := $(2)
  151. VERSION := $(3)
  152. endef
  153. TARGET_DEVICES += linksys-$(1)
  154. endef
  155. define Device/motorola
  156. IMAGES := bin
  157. IMAGE/bin := trx-with-loader | motorola-bin
  158. endef
  159. define MotorolaDevice
  160. define Device/motorola-$(1)
  161. $$(Device/motorola)
  162. MOTOROLA_DEVICE := $(2)
  163. endef
  164. TARGET_DEVICES += motorola-$(1)
  165. endef
  166. define Device/netgear
  167. IMAGES := chk
  168. IMAGE/chk := trx-with-loader | netgear-chk
  169. endef
  170. define NetgearDevice
  171. define Device/netgear-$(1)
  172. $$(Device/netgear)
  173. NETGEAR_BOARD_ID := $(2)
  174. NETGEAR_REGION := $(3)
  175. endef
  176. TARGET_DEVICES += netgear-$(1)
  177. endef
  178. #################################################
  179. # Subtarget generic
  180. #################################################
  181. ifeq ($(SUBTARGET),generic)
  182. # BCM4705 with tg3
  183. $(eval $(call LinksysDevice,wrt300n-v1.1,EWC2,1.51.2))
  184. $(eval $(call LinksysDevice,wrt310n-v1,310N,1.0.10))
  185. $(eval $(call LinksysDevice,wrt350n-v1,EWCG,1.04.1))
  186. $(eval $(call LinksysDevice,wrt610n-v1,610N,1.0.1))
  187. # BCMA SoC with SSB WiFi
  188. $(eval $(call LinksysDevice,wrt610n-v2,610N,2.0.0))
  189. $(eval $(call LinksysDevice,e3000-v1,61XN,1.0.3))
  190. TARGET_DEVICES += standard
  191. endif
  192. #################################################
  193. # Subtarget legacy
  194. #################################################
  195. define Device/dlink-dwl-3150
  196. IMAGES := bin
  197. IMAGE/bin := trx-with-loader | tailed-bin
  198. BIN_TAIL := BCM-5352-2050-0000000-01
  199. endef
  200. define Device/edimax-ps1208-mfg
  201. IMAGES := bin
  202. IMAGE/bin := trx-with-loader | edimax-bin
  203. endef
  204. define Device/huawei-e970
  205. KERNEL_NAME = vmlinux.gz
  206. IMAGES := bin
  207. IMAGE/bin := trx-without-loader | huawei-bin
  208. endef
  209. define Device/linksys-wrt54g3gv2-vf
  210. FILESYSTEMS := $(FS_128K)
  211. IMAGES := noheader.bin bin
  212. IMAGE/noheader.bin := linksys-pattern-partition | trx-v2-with-loader
  213. IMAGE/bin := linksys-pattern-partition | trx-v2-with-loader | linksys-bin
  214. DEVICE_ID := 3G2V
  215. VERSION := 3.00.24
  216. SERIAL := 6
  217. endef
  218. define Device/linksys-wrt54gs
  219. $(Device/linksys)
  220. FILESYSTEMS := $(FS_128K)
  221. DEVICE_ID := W54S
  222. VERSION := 4.80.1
  223. endef
  224. define Device/linksys-wrtsl54gs
  225. $(Device/linksys)
  226. FILESYSTEMS := $(FS_128K)
  227. DEVICE_ID := W54U
  228. VERSION := 2.08.1
  229. endef
  230. define Device/netgear-wgt634u
  231. FILESYSTEMS := $(FS_128K)
  232. IMAGES := bin
  233. IMAGE/bin := trx-with-loader | prepend-with-elf
  234. endef
  235. define Device/usrobotics-usr5461
  236. IMAGES := bin
  237. IMAGE/bin := trx-with-loader | usrobotics-bin
  238. endef
  239. ifeq ($(SUBTARGET),legacy)
  240. TARGET_DEVICES += \
  241. dlink-dwl-3150 \
  242. edimax-ps1208-mfg \
  243. huawei-e970 \
  244. linksys-wrt54g3gv2-vf \
  245. linksys-wrt54gs \
  246. linksys-wrtsl54gs \
  247. netgear-wgt634u \
  248. usrobotics-usr5461
  249. $(eval $(call AsusDevice,wl-300g,WL300g ))
  250. $(eval $(call AsusDevice,wl-320gp,WL320gP ))
  251. $(eval $(call AsusDevice,wl-330ge,WL-330gE ))
  252. $(eval $(call AsusDevice,wl-500gp-v1,WL500gp ))
  253. $(eval $(call AsusDevice,wl-500gp-v2,WL500gpv2 ))
  254. $(eval $(call AsusDevice,wl-500w,WL500W ))
  255. $(eval $(call AsusDevice,wl-520gu,WL520gu ))
  256. $(eval $(call AsusDevice,wl-550ge,WL550gE ))
  257. $(eval $(call AsusDevice,wl-hdd25,WLHDD ))
  258. $(eval $(call LinksysDevice,wrt54g3g,W54F,2.20.1))
  259. $(eval $(call LinksysDevice,wrt54g3g-em,W3GN,2.20.1))
  260. $(eval $(call LinksysDevice,wrt54g,W54G,4.71.1))
  261. $(eval $(call LinksysDevice,wrt54gs-v4,W54s,1.09.1))
  262. $(eval $(call LinksysDevice,wrt150n,N150,1.51.3))
  263. $(eval $(call LinksysDevice,wrt160n-v1,N150,1.50.1))
  264. $(eval $(call LinksysDevice,wrt300n-v1,EWCB,1.03.6))
  265. $(eval $(call MotorolaDevice,wa840g,2))
  266. $(eval $(call MotorolaDevice,we800g,3))
  267. $(eval $(call MotorolaDevice,wr850g,1))
  268. $(eval $(call NetgearDevice,wgr614-v8,U12H072T00_NETGEAR,2))
  269. $(eval $(call NetgearDevice,wndr3300-v1,U12H093T00_NETGEAR,2))
  270. $(eval $(call NetgearDevice,wnr834b-v2,U12H081T00_NETGEAR,2))
  271. TARGET_DEVICES += standard standard-noloader-gz
  272. endif
  273. #################################################
  274. # Subtarget mips74k
  275. #################################################
  276. ifeq ($(SUBTARGET),mips74k)
  277. $(eval $(call AsusDevice,rt-ac53u,RT-AC53U))
  278. # $(eval $(call AsusDevice,rt-ac66u,RT-AC66U))
  279. $(eval $(call AsusDevice,rt-n10,RT-N10 ))
  280. $(eval $(call AsusDevice,rt-n10p,RT-N10P))
  281. $(eval $(call AsusDevice,rt-n10p-v2,RT-N10PV2))
  282. $(eval $(call AsusDevice,rt-n10u,RT-N10U))
  283. $(eval $(call AsusDevice,rt-n10u-b,RT-N10U))
  284. $(eval $(call AsusDevice,rt-n12,RT-N12 ))
  285. $(eval $(call AsusDevice,rt-n12-b1,RT-N12B1))
  286. $(eval $(call AsusDevice,rt-n12-c1,RT-N12C1))
  287. $(eval $(call AsusDevice,rt-n12-d1,RT-N12D1))
  288. $(eval $(call AsusDevice,rt-n12hp,RT-N12HP))
  289. $(eval $(call AsusDevice,rt-n14uhp,RT-N14UHP))
  290. $(eval $(call AsusDevice,rt-n15u,RT-N15U))
  291. $(eval $(call AsusDevice,rt-n16,RT-N16))
  292. $(eval $(call AsusDevice,rt-n53,RT-N53))
  293. $(eval $(call AsusDevice,rt-n66u,RT-N66U))
  294. $(eval $(call AsusDevice,rt-n66w,RT-N66U))
  295. $(eval $(call LinksysDevice,wrt160n-v3,N150,3.0.3))
  296. $(eval $(call LinksysDevice,wrt310n-v2,310N,2.0.1))
  297. $(eval $(call LinksysDevice,wrt320n-v1,320N,1.0.5))
  298. $(eval $(call LinksysDevice,e900-v1,E900,1.0.4))
  299. $(eval $(call LinksysDevice,e1000-v1-v2-v2.1,E100,1.1.3))
  300. $(eval $(call LinksysDevice,e1200-v1,E120,1.0.3))
  301. $(eval $(call LinksysDevice,e1200-v2,E122,1.0.4))
  302. $(eval $(call LinksysDevice,e1500-v1,E150,1.0.5))
  303. $(eval $(call LinksysDevice,e1550-v1,1550,1.0.3))
  304. $(eval $(call LinksysDevice,e2000-v1,32XN,1.0.4))
  305. $(eval $(call LinksysDevice,e2500-v1,E25X,1.0.7))
  306. $(eval $(call LinksysDevice,e2500-v2,E25X,2.0.0))
  307. $(eval $(call LinksysDevice,e2500-v2.1,25RU,2.1.0))
  308. $(eval $(call LinksysDevice,e2500-v3,25V3,3.0.0))
  309. $(eval $(call LinksysDevice,e3200-v1,3200,1.0.1))
  310. $(eval $(call LinksysDevice,e4200-v1,4200,1.0.5))
  311. $(eval $(call NetgearDevice,wgr614-v10_north-america,U12H139T01_NETGEAR,2))
  312. $(eval $(call NetgearDevice,wgr614-v10_other-regions,U12H139T01_NETGEAR,1))
  313. $(eval $(call NetgearDevice,wn2500rp-v1,U12H197T00_NETGEAR,1))
  314. $(eval $(call NetgearDevice,wndr3400-v1,U12H155T00_NETGEAR,2))
  315. $(eval $(call NetgearDevice,wndr3400-v2,U12H187T00_NETGEAR,2))
  316. $(eval $(call NetgearDevice,wndr3400-v3,U12H208T00_NETGEAR,1))
  317. $(eval $(call NetgearDevice,wndr3700-v3,U12H194T00_NETGEAR,2))
  318. # $(eval $(call NetgearDevice,wndr3400-vcna,U12H155T01_NETGEAR,2))
  319. $(eval $(call NetgearDevice,wndr4000,U12H181T00_NETGEAR,2))
  320. $(eval $(call NetgearDevice,wnr1000-v3,U12H139T00_NETGEAR,2))
  321. $(eval $(call NetgearDevice,wnr2000v2,U12H114T00_NETGEAR,2))
  322. $(eval $(call NetgearDevice,wnr3000rp,U12H163T01_NETGEAR,1))
  323. $(eval $(call NetgearDevice,wnr3500l-v1-north-america,U12H136T99_NETGEAR,2))
  324. $(eval $(call NetgearDevice,wnr3500l-v1-other-regions,U12H136T99_NETGEAR,1))
  325. $(eval $(call NetgearDevice,wnr3500l-v2,U12H172T00_NETGEAR,1))
  326. # $(eval $(call NetgearDevice,wnr3500u,U12H136T00_NETGEAR,2))
  327. $(eval $(call NetgearDevice,wnr3500-v2,U12H127T00_NETGEAR,2))
  328. # $(eval $(call NetgearDevice,wnr3500-v2-vc,U12H127T70_NETGEAR,2))
  329. TARGET_DEVICES += standard standard-noloader-nodictionarylzma
  330. endif
  331. #################################################
  332. # Shared BuildImage defines
  333. #################################################
  334. define Image/Build/Initramfs
  335. $(STAGING_DIR_HOST)/bin/trx \
  336. -m 33554432 \
  337. -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs.trx \
  338. -f $(KDIR)/loader.gz \
  339. -f $(KDIR)/vmlinux-initramfs.lzma
  340. $(STAGING_DIR_HOST)/bin/trx \
  341. -m 33554432 \
  342. -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs-noloader-nodictionary.trx \
  343. -f $(KDIR)/vmlinux-initramfs-nodictionary.lzma
  344. endef
  345. # $(1): filesystem type.
  346. define Image/Build
  347. # TODO: Move it to Device/*
  348. ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
  349. $(call Image/Build/Initramfs)
  350. endif
  351. endef
  352. $(eval $(call BuildImage))