brcm47xx: build image for Asus RT-N66U
[openwrt/openwrt.git] / target / linux / brcm47xx / image / Makefile
1 #
2 # Copyright (C) 2006-2012 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 Image/Build/wgt634u
38 dd if=$(KDIR)/loader.elf of=$(BIN_DIR)/openwrt-wgt634u-$(2).bin bs=131072 conv=sync
39 cat $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx >> $(BIN_DIR)/openwrt-wgt634u-$(2).bin
40 endef
41
42 define Image/Build/dwl3150
43 cp $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx $(BIN_DIR)/openwrt-dwl3150-$(2).bin
44 echo "BCM-5352-2050-0000000-01" >> $(BIN_DIR)/openwrt-dwl3150-$(2).bin
45 endef
46
47 # $(1): filesystem type.
48 # $(2): device model (used for output file).
49 # $(3): pattern (device specific magic).
50 # $(4): version.
51 # $(5): simplified filesystem type (without block size).
52 define Image/Build/CyberTAN
53 $(STAGING_DIR_HOST)/bin/addpattern -4 -p $(3) -v v$(4) -i $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx -o $(BIN_DIR)/openwrt-$(2)-$(5).bin $(if $(6),-s $(6))
54 endef
55 define Image/Build/CyberTAN2
56 $(STAGING_DIR_HOST)/bin/addpattern -4 -p $(3) -v v$(4) -i $(BIN_DIR)/openwrt-$(2)-$(5).noheader.bin -o $(BIN_DIR)/openwrt-$(2)-$(5).bin $(if $(6),-s $(6))
57 endef
58 define Image/Build/CyberTANHead
59 $(STAGING_DIR_HOST)/bin/addpattern -5 -p $(3) -v v$(4) -i /dev/null -o $(KDIR)/openwrt-$(2)-header.bin $(if $(6),-s $(6))
60 endef
61
62 define Image/Build/Motorola
63 $(STAGING_DIR_HOST)/bin/motorola-bin -$(3) $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx $(BIN_DIR)/openwrt-$(2)-$(4).bin
64 endef
65
66 define Image/Build/USR
67 $(STAGING_DIR_HOST)/bin/trx2usr $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx $(BIN_DIR)/openwrt-$(2)-$(3).bin
68 endef
69
70 define Image/Build/Edi
71 $(STAGING_DIR_HOST)/bin/trx2edips $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx $(BIN_DIR)/openwrt-$(2)-$(3).bin
72 endef
73
74 define Image/Build/Huawei
75 dd if=/dev/zero of=$(BIN_DIR)/openwrt-$(2)-$(3)-gz.bin bs=92 count=1
76 echo -ne 'HDR0\x08\x00\x00\x00' >> $(BIN_DIR)/openwrt-$(2)-$(3)-gz.bin
77 cat $(BIN_DIR)/$(IMG_PREFIX)-$(1)-gz.trx >> $(BIN_DIR)/openwrt-$(2)-$(3)-gz.bin
78 endef
79
80 # $(1): filesystem type.
81 # $(2): device model (used for output file).
82 # $(3): board_id (device specific magic).
83 # $(4): region.
84 # $(5): simplified filesystem type (without block size).
85 define Image/Build/Chk
86 $(STAGING_DIR_HOST)/bin/mkchkimg -o $(BIN_DIR)/openwrt-$(2)-$(5).chk -k $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx -b $(3) -r $(4)
87 endef
88
89 define trxalign/jffs2-128k
90 -a 0x20000 -f $(KDIR)/root.$(1)
91 endef
92 define trxalign/jffs2-64k
93 -a 0x10000 -f $(KDIR)/root.$(1)
94 endef
95 define trxalign/squashfs
96 -a 1024 -f $(KDIR)/root.$(1) $(if $(2),-f $(2)) -a 0x10000 -A $(KDIR)/fs_mark
97 endef
98
99 define Image/Build/trxV2
100 $(call Image/Build/CyberTANHead,$(1),$(2),$(3),$(4),$(5),$(if $(6),$(6)))
101 $(STAGING_DIR_HOST)/bin/trx -2 -o $(BIN_DIR)/openwrt-$(2)-$(5).noheader.bin \
102 -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux.lzma \
103 $(call trxalign/$(1),$(1),$(KDIR)/openwrt-$(2)-header.bin)
104 $(call Image/Build/CyberTAN2,$(1),$(2),$(3),$(4),$(5),$(if $(6),$(6)))
105 endef
106
107 #################################################
108 # Images
109 #################################################
110
111 define Build/trx-with-loader
112 $(STAGING_DIR_HOST)/bin/trx \
113 -o $@ \
114 -f $(KDIR)/loader.gz \
115 -f $(word 1,$^) \
116 $(call trxalign/$(FILESYSTEM),$(FILESYSTEM))
117 endef
118
119 define Build/asus-trx
120 $(STAGING_DIR_HOST)/bin/asustrx -p $(PRODUCTID) -i $@ -o $@.new
121 mv $@.new $@
122 endef
123
124 define Build/linksys-bin
125 $(STAGING_DIR_HOST)/bin/addpattern -4 -p $(DEVICE_ID) -v v$(VERSION) -i $@ -o $@.new
126 mv $@.new $@
127 endef
128
129 define Build/netgear-chk
130 $(STAGING_DIR_HOST)/bin/mkchkimg \
131 -o $@.new \
132 -k $@ \
133 -b $(BOARD_ID) \
134 -r $(REGION)
135 mv $@.new $@
136 endef
137
138 #################################################
139 # Devices
140 #################################################
141
142 DEVICE_VARS += PRODUCTID
143 DEVICE_VARS += DEVICE_ID VERSION
144 DEVICE_VARS += BOARD_ID REGION
145
146 define Device/Default
147 KERNEL := kernel-bin
148 IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1).$$(2)
149 KERNEL_NAME = vmlinux.lzma
150 FILESYSTEMS := $(FS_64K)
151 IMAGES := trx
152 IMAGE/trx := trx-with-loader
153 endef
154
155 define Device/asus
156 IMAGES := trx
157 IMAGE/trx := trx-with-loader | asus-trx
158 endef
159
160 define AsusDevice
161 define Device/asus-$(1)
162 $$(Device/asus)
163 PRODUCTID := $(2)
164 endef
165 TARGET_DEVICES += asus-$(1)
166 endef
167
168 define Device/linksys
169 IMAGES := bin
170 IMAGE/bin := trx-with-loader | linksys-bin
171 endef
172
173 define LinksysDevice
174 define Device/linksys-$(1)
175 $$(Device/linksys)
176 DEVICE_ID := $(2)
177 VERSION := $(3)
178 endef
179 TARGET_DEVICES += linksys-$(1)
180 endef
181
182 define Device/netgear
183 IMAGES := chk
184 IMAGE/chk := trx-with-loader | netgear-chk
185 endef
186
187 define NetgearDevice
188 define Device/netgear-$(1)
189 $$(Device/netgear)
190 BOARD_ID := $(2)
191 REGION := $(3)
192 endef
193 TARGET_DEVICES += netgear-$(1)
194 endef
195
196 #################################################
197 # Subtarget generic
198 #################################################
199
200 ifeq ($(SUBTARGET),generic)
201 # BCM4705 with tg3
202 $(eval $(call LinksysDevice,wrt300n-v1.1,EWC2,1.51.2))
203 $(eval $(call LinksysDevice,wrt310n-v1,310N,1.0.10))
204 $(eval $(call LinksysDevice,wrt350n-v1,EWCG,1.04.1))
205 $(eval $(call LinksysDevice,wrt610n-v1,610N,1.0.1))
206
207 # BCMA SoC with SSB WiFi
208 $(eval $(call LinksysDevice,wrt610n-v2,610N,2.0.0))
209 $(eval $(call LinksysDevice,e3000-v1,61XN,1.0.3))
210 endif
211
212 #################################################
213 # Subtarget legacy
214 #################################################
215
216 # $(1): filesystem type.
217 define Image/Build/legacy/devices-with-128k-blocks
218 $(call Image/Build/trxV2,$(1),wrt54g3gv2-vf,3G2V,3.00.24,$(patsubst jffs2-%,jffs2,$(1)),6)
219 $(call Image/Build/wgt634u,$(1),$(patsubst jffs2-%,jffs2,$(1)))
220 endef
221
222 # $(1): filesystem type.
223 define Image/Build/legacy/devices-with-64k-blocks
224 $(call Image/Build/dwl3150,$(1),$(patsubst jffs2-%,jffs2,$(1)))
225 $(call Image/Build/Edi,$(1),ps1208mfg,$(patsubst jffs2-%,jffs2,$(1)))
226 $(call Image/Build/Huawei,$(1),e970,$(1))
227 $(call Image/Build/Motorola,$(1),wa840g,2,$(patsubst jffs2-%,jffs2,$(1)))
228 $(call Image/Build/Motorola,$(1),we800g,3,$(patsubst jffs2-%,jffs2,$(1)))
229 $(call Image/Build/Motorola,$(1),wr850g,1,$(1))
230 $(call Image/Build/USR,$(1),usr5461,$(1))
231 endef
232
233 # $(1): filesystem type.
234 define Image/Build/legacy/jffs2-64k
235 $(call Image/Build/legacy/devices-with-64k-blocks,$(1))
236 endef
237
238 # $(1): filesystem type.
239 define Image/Build/legacy/jffs2-128k
240 $(call Image/Build/legacy/devices-with-128k-blocks,$(1))
241 endef
242
243 # $(1): filesystem type.
244 define Image/Build/legacy/squashfs
245 $(call Image/Build/legacy/devices-with-64k-blocks,$(1))
246 $(call Image/Build/legacy/devices-with-128k-blocks,$(1))
247 endef
248
249 define Device/linksys-wrt54gs
250 $(Device/linksys)
251 FILESYSTEMS := $(FS_128K)
252 DEVICE_ID := W54S
253 VERSION := 4.80.1
254 endef
255
256 define Device/linksys-wrtsl54gs
257 $(Device/linksys)
258 FILESYSTEMS := $(FS_128K)
259 DEVICE_ID := W54U
260 VERSION := 2.08.1
261 endef
262
263 ifeq ($(SUBTARGET),legacy)
264 TARGET_DEVICES += \
265 linksys-wrt54gs \
266 linksys-wrtsl54gs
267
268 $(eval $(call LinksysDevice,wrt54g3g,W54F,2.20.1))
269 $(eval $(call LinksysDevice,wrt54g3g-em,W3GN,2.20.1))
270 $(eval $(call LinksysDevice,wrt54g,W54G,4.71.1))
271 $(eval $(call LinksysDevice,wrt54gs-v4,W54s,1.09.1))
272 $(eval $(call LinksysDevice,wrt150n,N150,1.51.3))
273 $(eval $(call LinksysDevice,wrt160n-v1,N150,1.50.1))
274 $(eval $(call LinksysDevice,wrt300n-v1,EWCB,1.03.6))
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 endif
279
280 #################################################
281 # Subtarget mips74k
282 #################################################
283
284 ifeq ($(SUBTARGET),mips74k)
285 $(eval $(call AsusDevice,rt-n66u,RT-N66U))
286 $(eval $(call LinksysDevice,wrt160n-v3,N150,3.0.3))
287 $(eval $(call LinksysDevice,wrt310n-v2,310N,2.0.1))
288 $(eval $(call LinksysDevice,wrt320n-v1,320N,1.0.5))
289 $(eval $(call LinksysDevice,e900-v1,E900,1.0.4))
290 $(eval $(call LinksysDevice,e1000-v1-v2-v2.1,E100,1.1.3))
291 $(eval $(call LinksysDevice,e1200-v1,E120,1.0.3))
292 $(eval $(call LinksysDevice,e1200-v2-new,E122,1.0.4))
293 $(eval $(call LinksysDevice,e1500-v1,E150,1.0.5))
294 $(eval $(call LinksysDevice,e1550-v1,1550,1.0.3))
295 $(eval $(call LinksysDevice,e2000-v1,32XN,1.0.4))
296 $(eval $(call LinksysDevice,e2500-v1,E25X,1.0.7))
297 $(eval $(call LinksysDevice,e2500-v2,E25X,2.0.0))
298 $(eval $(call LinksysDevice,e2500-v2.1,25RU,2.1.0))
299 $(eval $(call LinksysDevice,e2500-v3,25V3,3.0.0))
300 $(eval $(call LinksysDevice,e3200-v1,3200,1.0.1))
301 $(eval $(call LinksysDevice,e4200-v1,4200,1.0.5))
302 $(eval $(call NetgearDevice,wgr614-v10_north-america,U12H139T01_NETGEAR,2))
303 $(eval $(call NetgearDevice,wgr614-v10_other-regions,U12H139T01_NETGEAR,1))
304 $(eval $(call NetgearDevice,wndr3400-v1,U12H155T00_NETGEAR,2))
305 $(eval $(call NetgearDevice,wndr3400-v2,U12H187T00_NETGEAR,2))
306 $(eval $(call NetgearDevice,wndr3400-v3,U12H208T00_NETGEAR,1))
307 $(eval $(call NetgearDevice,wndr3700-v3,U12H194T00_NETGEAR,2))
308 $(eval $(call NetgearDevice,wndr4000,U12H181T00_NETGEAR,2))
309 $(eval $(call NetgearDevice,wnr1000-v3,U12H139T00_NETGEAR,2))
310 $(eval $(call NetgearDevice,wnr2000v2,U12H114T00_NETGEAR,2))
311 $(eval $(call NetgearDevice,wnr3000rp,U12H163T01_NETGEAR,1))
312 $(eval $(call NetgearDevice,wnr3500l-v1-north-america,U12H136T99_NETGEAR,2))
313 $(eval $(call NetgearDevice,wnr3500l-v1-other-regions,U12H136T99_NETGEAR,1))
314 $(eval $(call NetgearDevice,wnr3500l-v2,U12H172T00_NETGEAR,1))
315 $(eval $(call NetgearDevice,wnr3500-v2,U12H127T00_NETGEAR,2))
316 endif
317
318 #################################################
319 # Shared BuildImage defines
320 #################################################
321
322 define Image/Build/Initramfs
323 $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs.trx -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux-initramfs.lzma
324 $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs-noloader-nodictionary.trx -f $(KDIR)/vmlinux-initramfs-nodictionary.lzma
325 endef
326
327 # $(1): filesystem type.
328 define Image/Build
329 $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx \
330 -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux.lzma \
331 $(call trxalign/$(1),$(1))
332 $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-$(1)-noloader-nodictionary.trx \
333 -f $(KDIR)/vmlinux-nodictionary.lzma \
334 $(call trxalign/$(1),$(1))
335 $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-$(1)-gz.trx \
336 -f $(KDIR)/vmlinux.gz \
337 $(call trxalign/$(1),$(1))
338 $(call Image/Build/$(SUBTARGET)/$(1),$(1))
339 # $(call Image/Build/Chk,$(1),wgr614_v9,U12H094T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
340 # $(call Image/Build/Chk,$(1),wndr3400_vcna,U12H155T01_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
341 # $(call Image/Build/Chk,$(1),wnr3500U,U12H136T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
342 # $(call Image/Build/Chk,$(1),wnr3500v2_VC,U12H127T70_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
343 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
344 $(call Image/Build/Initramfs)
345 endif
346 endef
347
348 $(eval $(call BuildImage))