9c0fa2d7f1148c097509e0930e49ccb886cea202
[15.05/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/$(lastword $(subst ., ,$(word 2,$^))),$(lastword $(subst ., ,$(word 2,$^))))
117 endef
118
119 define Build/linksys-bin
120         $(STAGING_DIR_HOST)/bin/addpattern -4 -p $(DEVICE_ID) -v v$(VERSION) -i $@ -o $@.new
121         mv $@.new $@
122 endef
123
124 define Build/netgear-chk
125         $(STAGING_DIR_HOST)/bin/mkchkimg \
126                 -o $@.new \
127                 -k $@ \
128                 -b $(BOARD_ID) \
129                 -r $(REGION)
130         mv $@.new $@
131 endef
132
133 #################################################
134 # Devices
135 #################################################
136
137 DEVICE_VARS += DEVICE_ID VERSION
138 DEVICE_VARS += BOARD_ID REGION
139
140 define Device/Default
141         IMAGE_NAME = $$(IMAGE_PREFIX)-$$(1).$$(2)
142         KERNEL_IMAGE = vmlinux.lzma
143         FILESYSTEMS := $(FS_64K)
144         IMAGES := trx
145         IMAGE/trx := trx-with-loader
146 endef
147
148 define Device/linksys
149         IMAGES := bin
150         IMAGE/bin := trx-with-loader | linksys-bin
151 endef
152
153 define Device/netgear
154         IMAGES := chk
155         IMAGE/chk := trx-with-loader | netgear-chk
156 endef
157
158 #################################################
159 # Subtarget generic
160 #################################################
161
162 # $(1): filesystem type.
163 define Image/Build/generic/jffs2-64k
164         # BCM4705 with tg3
165         $(call Image/Build/CyberTAN,$(1),wrt300n_v11,EWC2,1.51.2,$(patsubst jffs2-%,jffs2,$(1)))
166         $(call Image/Build/CyberTAN,$(1),wrt310n_v1,310N,1.0.10,$(patsubst jffs2-%,jffs2,$(1)))
167         $(call Image/Build/CyberTAN,$(1),wrt350n_v1,EWCG,1.04.1,$(patsubst jffs2-%,jffs2,$(1)))
168         $(call Image/Build/CyberTAN,$(1),wrt610n_v1,610N,1.0.1,$(patsubst jffs2-%,jffs2,$(1)))
169
170         # BCMA SoC with SSB WiFi
171         $(call Image/Build/CyberTAN,$(1),wrt610n_v2,610N,2.0.0,$(patsubst jffs2-%,jffs2,$(1)))
172         $(call Image/Build/CyberTAN,$(1),e3000_v1,61XN,1.0.3,$(patsubst jffs2-%,jffs2,$(1)))
173 endef
174
175 # $(1): filesystem type.
176 define Image/Build/generic/squashfs
177         $(call Image/Build/generic/jffs2-64k,$(1))
178         $(call Image/Build/generic/jffs2-128k,$(1))
179 endef
180
181 #################################################
182 # Subtarget legacy
183 #################################################
184
185 # $(1): filesystem type.
186 define Image/Build/legacy/devices-with-128k-blocks
187         $(call Image/Build/CyberTAN,$(1),wrt54gs,W54S,4.80.1,$(patsubst jffs2-%,jffs2,$(1)))
188         $(call Image/Build/CyberTAN,$(1),wrtsl54gs,W54U,2.08.1,$(patsubst jffs2-%,jffs2,$(1)))
189         $(call Image/Build/trxV2,$(1),wrt54g3gv2-vf,3G2V,3.00.24,$(patsubst jffs2-%,jffs2,$(1)),6)
190         $(call Image/Build/wgt634u,$(1),$(patsubst jffs2-%,jffs2,$(1)))
191 endef
192
193 # $(1): filesystem type.
194 define Image/Build/legacy/devices-with-64k-blocks
195         $(call Image/Build/Chk,$(1),wgr614_v8,U12H072T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
196         $(call Image/Build/Chk,$(1),wndr3300_v1,U12H093T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
197         $(call Image/Build/Chk,$(1),wnr834b_v2,U12H081T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
198         $(call Image/Build/CyberTAN,$(1),wrt54g3g,W54F,2.20.1,$(patsubst jffs2-%,jffs2,$(1)))
199         $(call Image/Build/CyberTAN,$(1),wrt54g3g-em,W3GN,2.20.1,$(patsubst jffs2-%,jffs2,$(1)))
200         $(call Image/Build/CyberTAN,$(1),wrt54g,W54G,4.71.1,$(patsubst jffs2-%,jffs2,$(1)))
201         $(call Image/Build/CyberTAN,$(1),wrt54gs_v4,W54s,1.09.1,$(patsubst jffs2-%,jffs2,$(1)))
202         $(call Image/Build/CyberTAN,$(1),wrt150n,N150,1.51.3,$(patsubst jffs2-%,jffs2,$(1)))
203         $(call Image/Build/CyberTAN,$(1),wrt160n_v1,N150,1.50.1,$(patsubst jffs2-%,jffs2,$(1)))
204         $(call Image/Build/CyberTAN,$(1),wrt300n_v1,EWCB,1.03.6,$(patsubst jffs2-%,jffs2,$(1)))
205         $(call Image/Build/dwl3150,$(1),$(patsubst jffs2-%,jffs2,$(1)))
206         $(call Image/Build/Edi,$(1),ps1208mfg,$(patsubst jffs2-%,jffs2,$(1)))
207         $(call Image/Build/Huawei,$(1),e970,$(1))
208         $(call Image/Build/Motorola,$(1),wa840g,2,$(patsubst jffs2-%,jffs2,$(1)))
209         $(call Image/Build/Motorola,$(1),we800g,3,$(patsubst jffs2-%,jffs2,$(1)))
210         $(call Image/Build/Motorola,$(1),wr850g,1,$(1))
211         $(call Image/Build/USR,$(1),usr5461,$(1))
212 endef
213
214 # $(1): filesystem type.
215 define Image/Build/legacy/jffs2-64k
216         $(call Image/Build/legacy/devices-with-64k-blocks,$(1))
217 endef
218
219 # $(1): filesystem type.
220 define Image/Build/legacy/jffs2-128k
221         $(call Image/Build/legacy/devices-with-128k-blocks,$(1))
222 endef
223
224 # $(1): filesystem type.
225 define Image/Build/legacy/squashfs
226         $(call Image/Build/legacy/devices-with-64k-blocks,$(1))
227         $(call Image/Build/legacy/devices-with-128k-blocks,$(1))
228 endef
229
230 #################################################
231 # Subtarget mips74k
232 #################################################
233
234 define Image/Build/mips74k/devices-with-64k-blocks
235         $(call Image/Build/Chk,$(1),wgr614_v10_north_america,U12H139T01_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
236         $(call Image/Build/Chk,$(1),wgr614_v10_other_regions,U12H139T01_NETGEAR,1,$(patsubst jffs2-%,jffs2,$(1)))
237         $(call Image/Build/Chk,$(1),wndr3400_v1,U12H155T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
238         $(call Image/Build/Chk,$(1),wndr3400_v2,U12H187T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
239         $(call Image/Build/Chk,$(1),wndr3400_v3,U12H208T00_NETGEAR,1,$(patsubst jffs2-%,jffs2,$(1)))
240         $(call Image/Build/Chk,$(1),wndr4000,U12H181T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
241         $(call Image/Build/Chk,$(1),wnr1000_v3,U12H139T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
242         $(call Image/Build/Chk,$(1),wnr2000v2,U12H114T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
243         $(call Image/Build/Chk,$(1),wnr3000rp,U12H163T01_NETGEAR,1,$(patsubst jffs2-%,jffs2,$(1)))
244         $(call Image/Build/Chk,$(1),wnr3500l_v1_north_america,U12H136T99_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
245         $(call Image/Build/Chk,$(1),wnr3500l_v1_other_regions,U12H136T99_NETGEAR,1,$(patsubst jffs2-%,jffs2,$(1)))
246         $(call Image/Build/Chk,$(1),wnr3500l_v2,U12H172T00_NETGEAR,1,$(patsubst jffs2-%,jffs2,$(1)))
247         $(call Image/Build/Chk,$(1),wnr3500_v2,U12H127T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
248         $(call Image/Build/CyberTAN,$(1),wrt160n_v3,N150,3.0.3,$(patsubst jffs2-%,jffs2,$(1)))
249         $(call Image/Build/CyberTAN,$(1),wrt310n_v2,310N,2.0.1,$(patsubst jffs2-%,jffs2,$(1)))
250         $(call Image/Build/CyberTAN,$(1),wrt320n_v1,320N,1.0.5,$(patsubst jffs2-%,jffs2,$(1)))
251         $(call Image/Build/CyberTAN,$(1),e900_v1,E900,1.0.4,$(patsubst jffs2-%,jffs2,$(1)))
252         $(call Image/Build/CyberTAN,$(1),e1000_v1_v2_v2.1,E100,1.1.3,$(patsubst jffs2-%,jffs2,$(1)))
253         $(call Image/Build/CyberTAN,$(1),e1200_v1,E120,1.0.3,$(patsubst jffs2-%,jffs2,$(1)))
254         $(call Image/Build/CyberTAN,$(1),e1500_v1,E150,1.0.5,$(patsubst jffs2-%,jffs2,$(1)))
255         $(call Image/Build/CyberTAN,$(1),e1550_v1,1550,1.0.3,$(patsubst jffs2-%,jffs2,$(1)))
256         $(call Image/Build/CyberTAN,$(1),e2000_v1,32XN,1.0.4,$(patsubst jffs2-%,jffs2,$(1)))
257         $(call Image/Build/CyberTAN,$(1),e2500_v1,E25X,1.0.7,$(patsubst jffs2-%,jffs2,$(1)))
258         $(call Image/Build/CyberTAN,$(1),e2500_v2,E25X,2.0.0,$(patsubst jffs2-%,jffs2,$(1)))
259         $(call Image/Build/CyberTAN,$(1),e2500_v2.1,25RU,2.1.0,$(patsubst jffs2-%,jffs2,$(1)))
260         $(call Image/Build/CyberTAN,$(1),e2500_v3,25V3,3.0.0,$(patsubst jffs2-%,jffs2,$(1)))
261         $(call Image/Build/CyberTAN,$(1),e3200_v1,3200,1.0.1,$(patsubst jffs2-%,jffs2,$(1)))
262         $(call Image/Build/CyberTAN,$(1),e4200_v1,4200,1.0.5,$(patsubst jffs2-%,jffs2,$(1)))
263 endef
264
265 # $(1): filesystem type.
266 define Image/Build/mips74k/jffs2-64k
267         $(call Image/Build/mips74k/devices-with-64k-blocks,$(1))
268 endef
269
270 # $(1): filesystem type.
271 define Image/Build/mips74k/jffs2-128k
272         $(call Image/Build/mips74k/devices-with-128k-blocks,$(1))
273 endef
274
275 # $(1): filesystem type.
276 define Image/Build/mips74k/squashfs
277         $(call Image/Build/mips74k/devices-with-64k-blocks,$(1))
278         $(call Image/Build/mips74k/devices-with-128k-blocks,$(1))
279 endef
280
281 define Device/linksys-e1200-v2
282         $(Device/linksys)
283         DEVICE_ID := E122
284         VERSION := 1.0.4
285 endef
286
287 define Device/netgear-wndr3700-v3
288         $(Device/netgear)
289         BOARD_ID := U12H194T00_NETGEAR
290         REGION := 2
291 endef
292
293 ifeq ($(SUBTARGET),mips74k)
294         TARGET_DEVICES += \
295                 linksys-e1200-v2 \
296                 netgear-wndr3700-v3
297 endif
298
299 #################################################
300 # Shared BuildImage defines
301 #################################################
302
303 define Image/Build/Initramfs
304         $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs.trx -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux-initramfs.lzma
305         $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-initramfs-noloader-nodictionary.trx -f $(KDIR)/vmlinux-initramfs-nodictionary.lzma
306 endef
307
308 # $(1): filesystem type.
309 define Image/Build
310         $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-$(1).trx \
311                 -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux.lzma \
312                 $(call trxalign/$(1),$(1))
313         $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-$(1)-noloader-nodictionary.trx \
314                 -f $(KDIR)/vmlinux-nodictionary.lzma \
315                 $(call trxalign/$(1),$(1))
316         $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/$(IMG_PREFIX)-$(1)-gz.trx \
317                 -f $(KDIR)/vmlinux.gz \
318                 $(call trxalign/$(1),$(1))
319         $(call Image/Build/$(SUBTARGET)/$(1),$(1))
320 #       $(call Image/Build/Chk,$(1),wgr614_v9,U12H094T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
321 #       $(call Image/Build/Chk,$(1),wndr3400_vcna,U12H155T01_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
322 #       $(call Image/Build/Chk,$(1),wnr3500U,U12H136T00_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
323 #       $(call Image/Build/Chk,$(1),wnr3500v2_VC,U12H127T70_NETGEAR,2,$(patsubst jffs2-%,jffs2,$(1)))
324 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
325         $(call Image/Build/Initramfs)
326 endif
327 endef
328
329 $(eval $(call BuildImage))