ar71xx: add nbg460n image generation
[openwrt.git] / target / linux / ar71xx / image / Makefile
1 #
2 # Copyright (C) 2008-2010 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 imgname
11 $(BIN_DIR)/$(IMG_PREFIX)-$(2)-$(patsubst jffs2-%,jffs2,$(patsubst squashfs-%,squashfs,$(1)))
12 endef
13
14 VMLINUX:=$(BIN_DIR)/$(IMG_PREFIX)-vmlinux
15 UIMAGE:=$(BIN_DIR)/$(IMG_PREFIX)-uImage
16 fs_squash:=squashfs-only
17 fs_all:=all
18 fs_4k:=4k
19 fs_64k:=64k
20 fs_128k:=128k
21 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
22         fs_squash:=initramfs
23         fs_all:=initramfs
24         fs_4k:=initramfs
25         fs_64k:=initramfs
26         fs_128k:=initramfs
27         VMLINUX:=$(BIN_DIR)/$(IMG_PREFIX)-vmlinux-initramfs
28         UIMAGE:=$(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs
29 endif
30
31 define CompressLzma
32   $(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
33 endef
34
35 define PatchKernelLzma
36         cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(1)
37         $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(1) '$(strip $(2))'
38         $(call CompressLzma,$(KDIR)/vmlinux-$(1),$(KDIR)/vmlinux-$(1).bin.lzma)
39 endef
40
41 define PatchKernelGzip
42         cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(1)
43         $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(1) '$(strip $(2))'
44         gzip -9 -c $(KDIR)/vmlinux-$(1) > $(KDIR)/vmlinux-$(1).bin.gz
45 endef
46
47 define MkImageLzma
48         mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma \
49                 -e 0x80060000 -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
50                 -d $(1) $(2)
51 endef
52
53 define MkImageGzip
54         mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip \
55                 -e 0x80060000 -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
56                 -d $(1) $(2)
57 endef
58
59 define Image/BuildKernel
60         cp $(KDIR)/vmlinux.elf $(VMLINUX).elf
61         cp $(KDIR)/vmlinux $(VMLINUX).bin
62         gzip -9 -c $(KDIR)/vmlinux > $(KDIR)/vmlinux.bin.gz
63         $(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
64         dd if=$(KDIR)/vmlinux.bin.lzma of=$(VMLINUX).lzma bs=65536 conv=sync
65         dd if=$(KDIR)/vmlinux.bin.gz of=$(VMLINUX).gz bs=65536 conv=sync
66         $(call MkImageGzip,$(KDIR)/vmlinux.bin.gz,$(UIMAGE)-gzip.bin)
67         $(call MkImageLzma,$(KDIR)/vmlinux.bin.lzma,$(UIMAGE)-lzma.bin)
68         $(call Image/Build/Initramfs)
69 endef
70
71 define Image/Build/WRT400N
72         $(call PatchKernelLzma,$(2),$(3))
73         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 1310720 ]; then \
74                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
75         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6488064 ]; then \
76                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
77         else \
78                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
79                         0x80060000 \
80                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
81                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
82                 ( \
83                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1280k conv=sync; \
84                         dd if=$(KDIR)/root.$(1) \
85                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
86                 wrt400n $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) $(call imgname,$(1),$(2))-factory.bin; \
87         fi; fi
88 endef
89
90 dir825b1_mtdlayout=mtdparts=spi0.0:256k(uboot)ro,64k(config)ro,1024k(kernel),5184k(rootfs),64k(caldata)ro,1600k(unknown)ro,6208k@0x50000(firmware)
91 define Image/Build/DIR825B1
92         $(call PatchKernelLzma,$(2),$(3) $(dir825b1_mtdlayout))
93         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 1048576 ]; then \
94                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
95         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 5308416 ]; then \
96                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
97         else \
98                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
99                         0x80060000 \
100                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
101                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
102                 ( \
103                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1024k conv=sync; \
104                         dd if=$(KDIR)/root.$(1) \
105                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
106                 ( \
107                         dd if=$(call imgname,$(1),$(2))-sysupgrade.bin; \
108                         echo -n "01AP94-AR7161-RT-080619-00"; \
109                 ) > $(call imgname,$(1),$(2))-backup-loader.bin; \
110                 if [ `stat -c%s $(call imgname,$(1),$(2))-sysupgrade.bin` -gt 4194304 ]; then \
111                         echo "Warning: $(call imgname,$(1),$(2))-sysupgrade.bin is too big"; \
112                 else \
113                         ( \
114                                 dd if=$(call imgname,$(1),$(2))-sysupgrade.bin bs=4096k conv=sync; \
115                                 echo -n "00AP94-AR7161-RT-080619-00"; \
116                         ) > $(call imgname,$(1),$(2))-factory.bin; \
117                 fi; \
118         fi; fi
119 endef
120
121 define Image/Build/WZRHPG300NH
122         $(call PatchKernelLzma,$(2),$(3))
123         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 1048576 ]; then \
124                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
125         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 31850496 ]; then \
126                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
127         else \
128                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
129                         0x80060000 \
130                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
131                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
132                 ( \
133                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1024k conv=sync; \
134                         dd if=$(KDIR)/root.$(1) bs=128k conv=sync; \
135                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
136                 ( \
137                         echo -n -e "# Airstation Public Fmt1\x00\x00\x00\x00\x00\x00\x00\x00"; \
138                         dd if=$(call imgname,$(1),$(2))-sysupgrade.bin; \
139                 ) > $(call imgname,$(1),$(2))-tftp.bin; \
140         fi; fi
141 endef
142
143 cameo_mtdlayout=mtdparts=spi0.0:128k(u-boot)ro,64k(config)ro,896k(kernel),2944k(rootfs),64k(art)ro,3840k@0x30000(firmware)
144 define Image/Build/Cameo
145         $(call PatchKernelLzma,$(2),$(3) $(cameo_mtdlayout))
146         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 917504 ]; then \
147                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
148         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 2949120 ]; then \
149                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
150         else \
151                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
152                         0x80060000 \
153                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
154                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
155                 ( \
156                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=896k conv=sync; \
157                         dd if=$(KDIR)/root.$(1) \
158                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
159                 ( \
160                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=896k conv=sync; \
161                         dd if=$(KDIR)/root.$(1) bs=2880k conv=sync; \
162                         echo -n $(4); \
163                 ) > $(call imgname,$(1),$(2))-factory.bin; \
164         fi; fi
165 endef
166
167 cameo7240_mtdlayout=mtdparts=spi0.0:192k(u-boot)ro,64k(nvram)ro,896k(kernel),2816k(rootfs),64k(mac)ro,64k(art)ro,3712k@0x40000(firmware)
168 define Image/Build/Cameo7240
169         $(call PatchKernelLzma,$(2),$(3) $(cameo7240_mtdlayout))
170         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 917504 ]; then \
171                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
172         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 2818048 ]; then \
173                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
174         else \
175                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
176                         0x80060000 \
177                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
178                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
179                 ( \
180                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=896k conv=sync; \
181                         dd if=$(KDIR)/root.$(1) \
182                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
183                 ( \
184                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=896k conv=sync; \
185                         dd if=$(KDIR)/root.$(1) bs=2752k conv=sync; \
186                         echo -n $(4); \
187                 ) > $(call imgname,$(1),$(2))-factory.bin; \
188         fi; fi
189 endef
190
191 define Image/Build/AP83
192         $(call PatchKernelGzip,$(2),$(3))
193         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.gz"` -gt 1310720 ]; then \
194                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.gz is too big"; \
195         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6619136 ]; then \
196                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
197         else \
198                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
199                         0x80060000 \
200                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
201                         -d $(KDIR)/vmlinux-$(2).bin.gz \
202                         $(KDIR)/vmlinux-$(2).uImage; \
203                 dd if=$(KDIR)/vmlinux-$(2).uImage \
204                         of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync; \
205                 dd if=$(KDIR)/root.$(1) \
206                         of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync; \
207                 ( \
208                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1280k conv=sync; \
209                         dd if=$(KDIR)/root.$(1); \
210                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
211         fi; fi
212 endef
213
214 define Image/Build/PB92
215         $(call PatchKernelLzma,$(2),$(3))
216         if [ `stat -c%s $(KDIR)/vmlinux-$(2).bin.lzma` -gt 917504 ]; then \
217                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
218         elif [ `stat -c%s $(KDIR)/root.$(1)` -gt 2818048 ]; then \
219                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
220         else \
221                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
222                         0x80060000 \
223                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
224                         -d $(KDIR)/vmlinux-$(2).bin.lzma \
225                         $(KDIR)/vmlinux-$(2).uImage; \
226                 dd if=$(KDIR)/vmlinux-$(2).uImage \
227                         of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync; \
228                 dd if=$(KDIR)/root.$(1) \
229                         of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync; \
230                 ( \
231                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=896k conv=sync; \
232                         dd if=$(KDIR)/root.$(1); \
233                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
234         fi
235 endef
236
237 define Image/Build/PB4X
238         $(call PatchKernelLzma,$(2),$(3))
239         dd if=$(KDIR)/vmlinux-$(2).bin.lzma \
240            of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync
241         dd if=$(KDIR)/root.$(1) \
242            of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync
243         -sh $(TOPDIR)/scripts/combined-image.sh \
244                 "$(call imgname,kernel,$(2)).bin" \
245                 "$(call imgname,$(1),$(2)-rootfs).bin" \
246                 $(call imgname,$(1),$(2))-sysupgrade.bin
247 endef
248
249 define Image/Build/MyLoader
250         -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) -s $(3) \
251                 -p0x030000:0xe0000:al:0x80060000:kernel:$(KDIR)/vmlinux.bin.lzma \
252                 -p0x110000:0:::rootfs:$(KDIR)/root.$(1) \
253                 $(call imgname,$(1),$(2))-$(4)-factory.img
254 endef
255
256 ubntxm_mtdlayout=mtdparts=spi0.0:256k(u-boot)ro,64k(u-boot-env)ro,1024k(kernel),6528k(rootfs),256k(cfg)ro,64k(EEPROM)ro,7552k@0x50000(firmware)
257 define Image/Build/UBNTXM
258         $(call PatchKernelLzma,$(2),$(3) $(ubntxm_mtdlayout))
259         $(call MkImageLzma,$(KDIR)/vmlinux-$(2).bin.lzma,$(KDIR)/vmlinux-$(2).uImage.bin)
260         dd if=$(KDIR)/vmlinux-$(2).uImage.bin of=$(KDIR)/vmlinux-$(2).uImage bs=1024k conv=sync
261         -$(STAGING_DIR_HOST)/bin/mkfwimage \
262                 -B $(4) -v $(5).$(6).OpenWrt.$(REVISION) \
263                 -k $(KDIR)/vmlinux-$(2).uImage \
264                 -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
265                 -o $(call imgname,$(1),$(2))-factory.bin
266         ( \
267                 dd if=$(KDIR)/vmlinux-$(2).uImage; \
268                 dd if=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1); \
269         ) > $(call imgname,$(1),$(2))-sysupgrade.bin
270 endef
271
272 define Image/Build/UBNT
273         $(call PatchKernelLzma,$(2),$(3))
274         dd if=$(KDIR)/vmlinux-$(2).bin.lzma of=$(KDIR)/vmlinux-$(2).lzma bs=64k conv=sync
275         -$(STAGING_DIR_HOST)/bin/mkfwimage \
276                 -B $(4) -v $(5).$(6).OpenWrt.$(REVISION) \
277                 -k $(KDIR)/vmlinux-$(2).lzma \
278                 -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
279                 -o $(call imgname,$(1),$(2))-factory.bin
280         -sh $(TOPDIR)/scripts/combined-image.sh \
281                 "$(KDIR)/vmlinux-$(2).lzma" \
282                 "$(BIN_DIR)/$(IMG_PREFIX)-root.$(1)" \
283                 $(call imgname,$(1),$(2))-sysupgrade.bin
284 endef
285
286 define Image/Build/Planex
287         $(call PatchKernelGzip,$(2),$(3))
288         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.gz"` -gt 1441792 ]; then \
289                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.gz is too big"; \
290         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6356992 ]; then \
291                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
292         else \
293                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
294                         0x80060000 \
295                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
296                         -d $(KDIR)/vmlinux-$(2).bin.gz $(KDIR)/vmlinux-$(2).uImage; \
297                 ( \
298                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1408k conv=sync; \
299                         dd if=$(KDIR)/root.$(1); \
300                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
301                 $(STAGING_DIR_HOST)/bin/mkplanexfw \
302                         -B $(2) \
303                         -v 2.00.00 \
304                         -i $(call imgname,$(1),$(2))-sysupgrade.bin \
305                         -o $(call imgname,$(1),$(2))-factory.bin; \
306         fi; fi
307 endef
308
309 define Image/Build/TPLINK
310         $(call PatchKernelGzip,$(2),$(3))
311         -$(STAGING_DIR_HOST)/bin/mktplinkfw \
312                 -B $(4) -N OpenWrt -V $(REVISION)\
313                 -k $(KDIR)/vmlinux-$(2).bin.gz \
314                 -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
315                 -o $(call imgname,$(1),$(2))-factory.bin
316         -$(STAGING_DIR_HOST)/bin/mktplinkfw \
317                 -B $(4) -N OpenWrt -V $(REVISION) -s \
318                 -k $(KDIR)/vmlinux-$(2).bin.gz \
319                 -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
320                 -o $(call imgname,$(1),$(2))-sysupgrade.bin
321 endef
322
323 define Image/Build/TPLINK/initramfs
324         $(call PatchKernelGzip,$(2),$(3))
325         -$(STAGING_DIR_HOST)/bin/mktplinkfw -c \
326                 -B $(4) -N OpenWrt -V $(REVISION) -s \
327                 -k $(KDIR)/vmlinux-$(2).bin.gz \
328                 -o $(call imgname,$(1),$(2))-uImage.bin
329 endef
330
331 define Image/Build/CyberTAN
332         $(call PatchKernelGzip,$(2),$(3))
333         $(call MkImageGzip,$(KDIR)/vmlinux-$(2).bin.gz,$(KDIR)/vmlinux-$(2).uImage)
334         $(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/image.tmp -f $(KDIR)/vmlinux-$(2).uImage \
335                 -x 32 -a 0x10000 -x -32 -f $(KDIR)/root.$(1)
336         -$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) \
337                 -i $(KDIR)/image.tmp \
338                 -o $(call imgname,$(1),$(2))-sysupgrade.bin
339         -$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) -g \
340                 -i $(KDIR)/image.tmp \
341                 -o $(call imgname,$(1),$(2))-factory.bin
342         rm $(KDIR)/image.tmp
343 endef
344
345 wndr3700_mtdlayout=mtdparts=spi0.0:320k(u-boot)ro,128k(u-boot-env)ro,1024k(kernel),6656k(rootfs),64k(art)ro,7680k@0x70000(firmware)
346 define Image/Build/WNDR3700
347         $(call PatchKernelLzma,$(2),$(3) $(wndr3700_mtdlayout))
348         $(call MkImageLzma,$(KDIR)/vmlinux-$(2).bin.lzma,$(KDIR)/vmlinux-$(2).uImage)
349         mkdir -p $(KDIR)/wndr3700/image
350         $(STAGING_DIR_HOST)/bin/wndr3700 \
351                 $(KDIR)/vmlinux-$(2).uImage \
352                 $(KDIR)/wndr3700/image/uImage
353         $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
354                 $(KDIR)/wndr3700 $(KDIR)/vmlinux-$(2).uImage.squashfs.tmp \
355                 -nopad -noappend -root-owned -be
356         -rm -rf $(KDIR)/wndr3700
357         mkimage -A mips -O linux -T filesystem -C none \
358                 -a 0xbf070000 -e 0xbf070000 \
359                 -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
360                 -d $(KDIR)/vmlinux-$(2).uImage.squashfs.tmp \
361                 $(KDIR)/vmlinux-$(2).uImage.squashfs.tmp2
362         $(STAGING_DIR_HOST)/bin/wndr3700 \
363                 $(KDIR)/vmlinux-$(2).uImage.squashfs.tmp2 \
364                 $(KDIR)/vmlinux-$(2).uImage.squashfs
365         -rm -f $(KDIR)/vmlinux-$(2).uImage.squashfs.tmp*
366         ( \
367                 dd if=$(KDIR)/vmlinux-$(2).uImage.squashfs bs=1024k conv=sync; \
368                 dd if=$(KDIR)/root.$(1) bs=64k; \
369         ) > $(call imgname,$(1),$(2))-sysupgrade.bin
370         $(STAGING_DIR_HOST)/bin/mkdniimg \
371                 -B WNDR3700 -v OpenWrt.$(REVISION) \
372                 -i $(call imgname,$(1),$(2))-sysupgrade.bin \
373                 -o $(call imgname,$(1),$(2))-factory.img
374 endef
375
376 define Image/Build/ZyXEL
377         $(call PatchKernelLzma,$(2),$(3))
378         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 917504 ]; then \
379                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
380         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 2752512 ]; then \
381                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
382         else \
383                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
384                         0x80060000 \
385                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
386                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
387                 ( \
388                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=896k conv=sync; \
389                         dd if=$(KDIR)/root.$(1); \
390                 ) > $(call imgname,$(1),$(2))-sysupgrade.bin; \
391                 $(STAGING_DIR_HOST)/bin/mkzynfw \
392                         -B $(4) \
393                         -b $(BIN_DIR)/$(IMG_PREFIX)-$(2)-u-boot.bin \
394                         -r $(call imgname,$(1),$(2))-sysupgrade.bin:0x10000 \
395                         -o $(call imgname,$(1),$(2))-factory.bin; \
396         fi; fi
397 endef
398
399 define Image/Build/WNDR3700/initramfs
400         $(call PatchKernelLzma,$(2),$(3) $(wndr3700_mtdlayout))
401         $(call MkImageLzma,$(KDIR)/vmlinux-$(2).bin.lzma,$(KDIR)/vmlinux-$(2).uImage)
402         $(STAGING_DIR_HOST)/bin/wndr3700 \
403                 $(KDIR)/vmlinux-$(2).uImage \
404                 $(call imgname,$(1),$(2))-uImage.bin
405 endef
406
407 define Image/Build/Zcomax
408         $(call PatchKernelLzma,$(2),$(3))
409         $(call MkImageLzma,$(KDIR)/vmlinux-$(2).bin.lzma,$(KDIR)/vmlinux-$(2).uImage.bin)
410         -$(STAGING_DIR_HOST)/bin/mkzcfw \
411                 -B $(2) \
412                 -k $(KDIR)/vmlinux-$(2).uImage.bin \
413                 -r $(BIN_DIR)/$(IMG_PREFIX)-root.$(1) \
414                 -o $(call imgname,$(1),$(2))-factory.img
415         ( \
416                 dd if=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=6208k count=1 conv=sync; \
417                 dd if=$(KDIR)/vmlinux-$(2).uImage.bin bs=1472k count=1; \
418         ) > $(call imgname,$(1),$(2))-sysupgrade.bin
419 endef
420
421 define Image/Build/Template/initramfs/initramfs
422         $(call Image/Build/$(1)/initramfs,initramfs,$(2),$(3),$(4),$(5),$(6),$(7))
423 endef
424
425 define Image/Build/Template/all/squashfs
426         $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7))
427 endef
428
429 define Image/Build/Template/all/jffs2-64k
430         $(call Image/Build/$(1),jffs2-64k,$(2),$(3),$(4),$(5),$(6),$(7))
431 endef
432
433 define Image/Build/Template/all/jffs2-128k
434         $(call Image/Build/$(1),jffs2-128k,$(2),$(3),$(4),$(5),$(6),$(7))
435 endef
436
437 define Image/Build/Template/squashfs-only/squashfs
438         $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7))
439 endef
440
441 define Image/Build/Template/4k/squashfs
442         $(call Image/Build/$(1),squashfs-4k,$(2),$(3),$(4),$(5),$(6),$(7))
443 endef
444
445 define Image/Build/Template/64k/squashfs
446         $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7))
447 endef
448
449 define Image/Build/Template/64k/jffs2-64k
450         $(call Image/Build/$(1),jffs2-64k,$(2),$(3),$(4),$(5),$(6),$(7))
451 endef
452
453 define Image/Build/Template/128k/squashfs
454         $(call Image/Build/$(1),squashfs,$(2),$(3),$(4),$(5),$(6),$(7))
455 endef
456
457 define Image/Build/Template/128k/jffs2-128k
458         $(call Image/Build/$(1),jffs2-128k,$(2),$(3),$(4),$(5),$(6),$(7))
459 endef
460
461 define Image/Build/Profile/AP81
462         $(call Image/Build/Template/$(fs_64k)/$(1),AP83,ap81,board=AP81)
463 endef
464
465 define Image/Build/Profile/AP83
466         $(call Image/Build/Template/$(fs_64k)/$(1),AP83,ap83,board=AP83)
467 endef
468
469 define Image/Build/Profile/PB42
470         $(call Image/Build/Template/$(fs_64k)/$(1),PB4X,pb42,board=PB42)
471 endef
472
473 define Image/Build/Profile/PB44
474         $(call Image/Build/Template/$(fs_64k)/$(1),PB4X,pb44,board=PB44)
475 endef
476
477 define Image/Build/Profile/PB92
478         $(call Image/Build/Template/$(fs_64k)/$(1),PB92,pb92,board=PB92)
479 endef
480
481 define Image/Build/Profile/WP543
482         $(call Image/Build/Template/$(fs_64k)/$(1),MyLoader,wp543,0x200000,2M)
483         $(call Image/Build/Template/$(fs_64k)/$(1),MyLoader,wp543,0x400000,4M)
484         $(call Image/Build/Template/$(fs_64k)/$(1),MyLoader,wp543,0x800000,8M)
485         $(call Image/Build/Template/$(fs_64k)/$(1),MyLoader,wp543,0x1000000,16M)
486 endef
487
488 define Image/Build/Profile/DIR600A1
489         $(call Image/Build/Template/$(fs_64k)/$(1),Cameo7240,dir-600-a1,board=DIR-600-A1,"AP91-AR7240-RT-090223-00")
490 endef
491
492 define Image/Build/Profile/EAP7660D
493         $(call Image/Build/Template/$(fs_128k)/$(1),PB4X,eap7660d,board=EAP7660D)
494 endef
495
496 define Image/Build/Profile/JWAP003
497         $(call Image/Build/Template/$(fs_64k)/$(1),PB4X,jwap003,board=JWAP003)
498 endef
499
500 define Image/Build/Profile/FR54RTR
501         $(call Image/Build/Template/$(fs_64k)/$(1),Cameo7240,fr-54rtr,board=DIR-600-A1,"AP91-AR7240-RT-090223-01")
502 endef
503
504 define Image/Build/Profile/DIR615C1
505         $(call Image/Build/Template/$(fs_squash)/$(1),Cameo,dir-615-c1,board=DIR-615-C1,"AP81-AR9130-RT-070614-02")
506 endef
507
508 define Image/Build/Profile/TEW632BRP
509         $(call Image/Build/Template/$(fs_squash)/$(1),Cameo,tew-632brp,board=TEW-632BRP,"AP81-AR9130-RT-070614-00")
510 endef
511
512 define Image/Build/Profile/TEW652BRP
513         $(call Image/Build/Template/$(fs_squash)/$(1),Cameo,tew-652brp,board=TEW-632BRP,"AP81-AR9130-RT-080609-05")
514         $(call Image/Build/Template/$(fs_squash)/$(1),Cameo,tew-652brp-recovery,board=TEW-632BRP,"AP81-AR9130-RT-070614-02")
515 endef
516
517 define Image/Build/Profile/A02RBW300N
518         $(call Image/Build/Template/$(fs_squash)/$(1),Cameo,a02-rb-w300n,board=TEW-632BRP,"AP81-AR9130-RT-070614-03")
519 endef
520
521 define Image/Build/Profile/UBNTRS
522         $(call Image/Build/Template/$(fs_64k)/$(1),UBNT,ubnt-rs,board=UBNT-RS,RS,RSx,ar7100)
523 endef
524
525 define Image/Build/Profile/UBNTRSPRO
526         $(call Image/Build/Template/$(fs_64k)/$(1),UBNT,ubnt-rspro,board=UBNT-RSPRO,RSPRO,RSPRO,ar7100pro)
527 endef
528
529 define Image/Build/Profile/UBNTLSSR71
530         $(call Image/Build/Template/$(fs_64k)/$(1),UBNT,ubnt-ls-sr71,board=UBNT-LS-SR71,LS-SR71,LS-SR71,ar7100)
531 endef
532
533 define Image/Build/Profile/UBNTBULLETM
534         $(call Image/Build/Template/$(fs_64k)/$(1),UBNTXM,ubnt-bullet-m,board=UBNT-BM,XM,UBNTXM,ar7240)
535 endef
536
537 define Image/Build/Profile/UBNTROCKETM
538         $(call Image/Build/Template/$(fs_64k)/$(1),UBNTXM,ubnt-rocket-m,board=UBNT-RM,XM,UBNTXM,ar7240)
539 endef
540
541 define Image/Build/Profile/UBNTNANOM
542         $(call Image/Build/Template/$(fs_64k)/$(1),UBNTXM,ubnt-nano-m,board=UBNT-NM,XM,UBNTXM,ar7240)
543 endef
544
545 define Image/Build/Profile/UBNTUNIFI
546         $(call Image/Build/Template/$(fs_64k)/$(1),UBNTXM,ubnt-unifi,board=UBNT-XM,XM,UBNTXM,ar7240)
547 endef
548
549 define Image/Build/Profile/UBNT
550         $(call Image/Build/Profile/UBNTRS,$(1))
551         $(call Image/Build/Profile/UBNTRSPRO,$(1))
552         $(call Image/Build/Profile/UBNTLSSR71,$(1))
553         $(call Image/Build/Profile/UBNTBULLETM,$(1))
554         $(call Image/Build/Profile/UBNTROCKETM,$(1))
555         $(call Image/Build/Profile/UBNTNANOM,$(1))
556         $(call Image/Build/Profile/UBNTUNIFI,$(1))
557 endef
558
559 define Image/Build/Profile/MZKW04NU
560         $(call Image/Build/Template/$(fs_64k)/$(1),Planex,mzk-w04nu,board=MZK-W04NU)
561 endef
562
563 define Image/Build/Profile/MZKW300NH
564         $(call Image/Build/Template/$(fs_64k)/$(1),Planex,mzk-w300nh,board=MZK-W300NH)
565 endef
566
567 define Image/Build/Profile/NBG_460N_550N_550NH
568         $(call Image/Build/Template/$(fs_64k)/$(1),ZyXEL,nbg460n_550n_550nh,board=NBG460N,NBG-460N)
569 endef
570
571 define Image/Build/Profile/TLMR3420V1
572         $(call Image/Build/Template/$(fs_4k)/$(1),TPLINK,tl-mr3420-v1,board=TL-MR3420,TL-MR3420v1)
573 endef
574
575 define Image/Build/Profile/TLWA901NDV1
576         $(call Image/Build/Template/$(fs_4k)/$(1),TPLINK,tl-wa901nd-v1,board=TL-WA901ND,TL-WA901NDv1)
577 endef
578
579 define Image/Build/Profile/TLWR741NDV1
580         $(call Image/Build/Template/$(fs_4k)/$(1),TPLINK,tl-wr741nd-v1,board=TL-WR741ND,TL-WR741NDv1)
581 endef
582
583 define Image/Build/Profile/TLWR841NV15
584         $(call Image/Build/Template/$(fs_squash)/$(1),TPLINK,tl-wr841n-v1.5,board=TL-WR841N-v1.5,TL-WR841Nv1.5)
585 endef
586
587 define Image/Build/Profile/TLWR841NDV3
588         $(call Image/Build/Template/$(fs_squash)/$(1),TPLINK,tl-wr841nd-v3,board=TL-WR941ND,TL-WR841NDv3)
589 endef
590
591 define Image/Build/Profile/TLWR841NDV5
592         $(call Image/Build/Template/$(fs_4k)/$(1),TPLINK,tl-wr841nd-v5,board=TL-WR741ND,TL-WR841NDv5)
593 endef
594
595 define Image/Build/Profile/TLWR841NDV7
596         $(call Image/Build/Template/$(fs_4k)/$(1),TPLINK,tl-wr841nd-v7,board=TL-WR741ND,TL-WR841NDv7)
597 endef
598
599 define Image/Build/Profile/TLWR941NDV2
600         $(call Image/Build/Template/$(fs_squash)/$(1),TPLINK,tl-wr941nd-v2,board=TL-WR941ND,TL-WR941NDv2)
601 endef
602
603 define Image/Build/Profile/TLWR941NDV3
604         $(call Image/Build/Template/$(fs_squash)/$(1),TPLINK,tl-wr941nd-v3,board=TL-WR941ND,TL-WR941NDv2)
605 endef
606
607 define Image/Build/Profile/TLWR941NDV4
608         $(call Image/Build/Template/$(fs_4k)/$(1),TPLINK,tl-wr941nd-v4,board=TL-WR741ND,TL-WR941NDv4)
609 endef
610
611 define Image/Build/Profile/TLWR1043NDV1
612         $(call Image/Build/Template/$(fs_squash)/$(1),TPLINK,tl-wr1043nd-v1,board=TL-WR1043ND,TL-WR1043NDv1)
613 endef
614
615 define Image/Build/Profile/WNDR3700
616         $(call Image/Build/Template/$(fs_64k)/$(1),WNDR3700,wndr3700,board=WNDR3700)
617 endef
618
619 define Image/Build/Profile/AP96
620         $(call Image/Build/Template/$(fs_64k)/$(1),AP83,ap96,board=AP96)
621 endef
622
623 define Image/Build/Profile/WRT400N
624         $(call Image/Build/Template/$(fs_64k)/$(1),WRT400N,wrt400n,board=WRT400N)
625 endef
626
627 define Image/Build/Profile/DIR825B1
628         $(call Image/Build/Template/$(fs_64k)/$(1),DIR825B1,dir-825-b1,board=DIR-825-B1)
629 endef
630
631 define Image/Build/Profile/WRT160NL
632         $(call Image/Build/Template/$(fs_64k)/$(1),CyberTAN,wrt160nl,board=WRT160NL,1.00.01)
633 endef
634
635 define Image/Build/Profile/WZRHPG300NH
636         $(call Image/Build/Template/$(fs_128k)/$(1),WZRHPG300NH,wzr-hp-g300nh,board=WZR-HP-G300NH)
637 endef
638
639 define Image/Build/Profile/ZCN1523H28
640         $(call Image/Build/Template/$(fs_64k)/$(1),Zcomax,zcn-1523h-2-8,board=ZCN-1523H-2)
641 endef
642
643 define Image/Build/Profile/ZCN1523H516
644         $(call Image/Build/Template/$(fs_64k)/$(1),Zcomax,zcn-1523h-5-16,board=ZCN-1523H-5)
645 endef
646
647 define Image/Build/Profile/Default
648         $(call Image/Build/Profile/AP81,$(1))
649         $(call Image/Build/Profile/AP83,$(1))
650         $(call Image/Build/Profile/A02RBW300N,$(1))
651         $(call Image/Build/Profile/DIR600A1,$(1))
652         $(call Image/Build/Profile/DIR615C1,$(1))
653         $(call Image/Build/Profile/DIR825B1,$(1))
654         $(call Image/Build/Profile/EAP7660D,$(1))
655         $(call Image/Build/Profile/FR54RTR,$(1))
656         $(call Image/Build/Profile/JWAP003,$(1))
657         $(call Image/Build/Profile/MZKW04NU,$(1))
658         $(call Image/Build/Profile/MZKW300NH,$(1))
659         $(call Image/Build/Profile/NBG_460N_550N_550NH,$(1))
660         $(call Image/Build/Profile/PB42,$(1))
661         $(call Image/Build/Profile/PB44,$(1))
662         $(call Image/Build/Profile/PB92,$(1))
663         $(call Image/Build/Profile/TEW632BRP,$(1))
664         $(call Image/Build/Profile/TEW652BRP,$(1))
665         $(call Image/Build/Profile/TLMR3420V1,$(1))
666         $(call Image/Build/Profile/TLWA901NDV1,$(1))
667         $(call Image/Build/Profile/TLWR741NDV1,$(1))
668         $(call Image/Build/Profile/TLWR841NV15,$(1))
669         $(call Image/Build/Profile/TLWR841NDV3,$(1))
670         $(call Image/Build/Profile/TLWR841NDV5,$(1))
671         $(call Image/Build/Profile/TLWR841NDV7,$(1))
672         $(call Image/Build/Profile/TLWR941NDV2,$(1))
673         $(call Image/Build/Profile/TLWR941NDV3,$(1))
674         $(call Image/Build/Profile/TLWR941NDV4,$(1))
675         $(call Image/Build/Profile/TLWR1043NDV1,$(1))
676         $(call Image/Build/Profile/UBNT,$(1))
677         $(call Image/Build/Profile/WP543,$(1))
678         $(call Image/Build/Profile/WNDR3700,$(1))
679         $(call Image/Build/Profile/AP96,$(1))
680         $(call Image/Build/Profile/WRT400N,$(1))
681         $(call Image/Build/Profile/WRT160NL,$(1))
682         $(call Image/Build/Profile/WZRHPG300NH,$(1))
683         $(call Image/Build/Profile/ZCN1523H28,$(1))
684         $(call Image/Build/Profile/ZCN1523H516,$(1))
685 endef
686
687 define Image/Build/Profile/Minimal
688         $(call Image/Build/Profile/Default,$(1))
689 endef
690
691 define Image/Build/Profile/Madwifi
692         $(call Image/Build/Profile/EAP7660D,$(1))
693         $(call Image/Build/Profile/UBNTRS,$(1))
694         $(call Image/Build/Profile/UBNTRSPRO,$(1))
695         $(call Image/Build/Profile/UBNTLSSR71,$(1))
696         $(call Image/Build/Profile/WP543,$(1))
697 endef
698
699 define Image/Build/squashfs
700         $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
701         dd if=$(KDIR)/root.squashfs of=$(KDIR)/root.squashfs-4k.tmp0 bs=4k conv=sync
702         $(call add_jffs2_mark,$(KDIR)/root.squashfs-4k.tmp0)
703         dd if=$(KDIR)/root.squashfs-4k.tmp0 of=$(BIN_DIR)/$(IMG_PREFIX)-root.squashfs-4k bs=4k conv=sync
704         $(call add_jffs2_mark,$(BIN_DIR)/$(IMG_PREFIX)-root.squashfs-4k)
705         rm -f $(KDIR)/root.squashfs-4k.tmp0
706 endef
707
708 define Image/Build/Initramfs
709         $(call Image/Build/Profile/$(PROFILE),initramfs)
710 endef
711
712 define Image/Build
713         $(call Image/Build/$(1))
714         dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
715
716         $(call Image/Build/Profile/$(PROFILE),$(1))
717 endef
718
719 $(eval $(call BuildImage))