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