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