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