dac7ded0167936230e8fcddc94fd79db14b9bd7f
[openwrt.git] / target / linux / ar71xx / image / Makefile
1 #
2 # Copyright (C) 2008-2009 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 IMGNAME:=$(BIN_DIR)/openwrt-$(BOARD)
11
12 define imgname
13 $(IMGNAME)-$(2)-$(patsubst jffs2-%,jffs2,$(patsubst squashfs-%,squashfs,$(1)))
14 endef
15
16 VMLINUX:=$(IMGNAME)-vmlinux
17 ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
18         VMLINUX:=$(IMGNAME)-vmlinux-initramfs
19 endif
20
21 define CompressLzma
22   $(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
23 endef
24
25 define PatchKernelLzma
26         cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(1)
27         $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(1) '$(strip $(2))'
28         $(call CompressLzma,$(KDIR)/vmlinux-$(1),$(KDIR)/vmlinux-$(1).bin.lzma)
29 endef
30
31 define PatchKernelGzip
32         cp $(KDIR)/vmlinux $(KDIR)/vmlinux-$(1)
33         $(STAGING_DIR_HOST)/bin/patch-cmdline $(KDIR)/vmlinux-$(1) '$(strip $(2))'
34         gzip -9 -c $(KDIR)/vmlinux-$(1) > $(KDIR)/vmlinux-$(1).bin.gz
35 endef
36
37 define MkImageLzma
38         mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma \
39                 -e 0x80060000 -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
40                 -d $(1) $(2)
41 endef
42
43 define MkImageGzip
44         mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip \
45                 -e 0x80060000 -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
46                 -d $(1) $(2)
47 endef
48
49 define Image/BuildKernel
50         cp $(KDIR)/vmlinux.elf $(VMLINUX).elf
51         cp $(KDIR)/vmlinux $(VMLINUX).bin
52         gzip -9 -c $(KDIR)/vmlinux > $(KDIR)/vmlinux.bin.gz
53         $(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
54         dd if=$(KDIR)/vmlinux.bin.lzma of=$(VMLINUX).lzma bs=65536 conv=sync
55         dd if=$(KDIR)/vmlinux.bin.gz of=$(VMLINUX).gz bs=65536 conv=sync
56         $(call MkImageGzip,$(KDIR)/vmlinux.bin.gz,$(IMGNAME)-uImage-gzip.bin)
57         $(call MkImageLzma,$(KDIR)/vmlinux.bin.lzma,$(IMGNAME)-uImage-lzma.bin)
58 endef
59
60 define Image/Build/WRT400N
61         $(call PatchKernelLzma,$(2),$(3))
62         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 1310720 ]; then \
63                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
64         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6488064 ]; then \
65                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
66         else \
67                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
68                         0x80060000 \
69                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
70                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
71                 ( \
72                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1280k conv=sync; \
73                         dd if=$(KDIR)/root.$(1) bs=6336k conv=sync; \
74                         echo -n $(4); \
75                 ) > $(call imgname,$(1),$(2)).bin; \
76                 wrt400n $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) $(call imgname,$(1),$(2)).webui; \
77         fi; fi
78 endef
79
80 define Image/Build/Cameo
81         $(call PatchKernelLzma,$(2),$(3))
82         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt 851968 ]; then \
83                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big"; \
84         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 3014656 ]; then \
85                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
86         else \
87                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C lzma -e \
88                         0x80060000 \
89                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
90                         -d $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/vmlinux-$(2).uImage; \
91                 ( \
92                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=832k conv=sync; \
93                         dd if=$(KDIR)/root.$(1) bs=2944k conv=sync; \
94                         echo -n $(4); \
95                 ) > $(call imgname,$(1),$(2)).uni; \
96         fi; fi
97 endef
98
99 define Image/Build/AP83
100         $(call PatchKernelGzip,$(2),$(3))
101         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.gz"` -gt 1310720 ]; then \
102                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.gz is too big"; \
103         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6619136 ]; then \
104                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
105         else \
106                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
107                         0x80060000 \
108                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
109                         -d $(KDIR)/vmlinux-$(2).bin.gz \
110                         $(KDIR)/vmlinux-$(2).uImage; \
111                 dd if=$(KDIR)/vmlinux-$(2).uImage \
112                         of=$(call imgname,kernel,$(2)).bin bs=64k conv=sync; \
113                 dd if=$(KDIR)/root.$(1) \
114                         of=$(call imgname,$(1),$(2)-rootfs).bin bs=128k conv=sync; \
115                 ( \
116                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1280k conv=sync; \
117                         dd if=$(KDIR)/root.$(1); \
118                 ) > $(call imgname,$(1),$(2)-firmware).bin; \
119         fi; fi
120 endef
121
122 define Image/Build/MyLoader
123         -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) \
124                 -p0x030000:0xd0000:al:0x80060000:kernel:$(KDIR)/vmlinux.bin.lzma \
125                 -p0x100000:0:::rootfs:$(KDIR)/root.$(1) \
126                 $(call imgname,$(1),$(2))-2M.img
127         -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) -s 0x400000 \
128                 -p0x030000:0xd0000:al:0x80060000:kernel:$(KDIR)/vmlinux.bin.lzma \
129                 -p0x100000:0:::rootfs:$(KDIR)/root.$(1) \
130                 $(call imgname,$(1),$(2))-4M.img
131         -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) -s 0x800000 \
132                 -p0x030000:0xd0000:al:0x80060000:kernel:$(KDIR)/vmlinux.bin.lzma \
133                 -p0x100000:0:::rootfs:$(KDIR)/root.$(1) \
134                 $(call imgname,$(1),$(2))-8M.img
135         -$(STAGING_DIR_HOST)/bin/mkmylofw -B $(2) -s 0x1000000 \
136                 -p0x030000:0xd0000:al:0x80060000:kernel:$(KDIR)/vmlinux.bin.lzma \
137                 -p0x100000:0:::rootfs:$(KDIR)/root.$(1) \
138                 $(call imgname,$(1),$(2))-16M.img
139 endef
140
141 define Image/Build/UBNT
142         $(call PatchKernelLzma,$(2),$(3))
143         dd if=$(KDIR)/vmlinux-$(2).bin.lzma of=$(KDIR)/vmlinux-$(2).lzma bs=64k conv=sync
144         -$(STAGING_DIR_HOST)/bin/mkfwimage \
145                 -B $(4) -v $(5).$(6).OpenWrt.$(REVISION) \
146                 -k $(KDIR)/vmlinux-$(2).lzma \
147                 -r $(BIN_DIR)/openwrt-$(BOARD)-root.$(1) \
148                 -o $(call imgname,$(1),$(2)).bin
149 endef
150
151 define Image/Build/Planex
152         $(call PatchKernelGzip,$(2),$(3))
153         if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.gz"` -gt 1441792 ]; then \
154                 echo "Warning: $(KDIR)/vmlinux-$(2).bin.gz is too big"; \
155         else if [ `stat -c%s $(KDIR)/root.$(1)` -gt 6356992 ]; then \
156                 echo "Warning: $(KDIR)/root.$(1) is too big"; \
157         else \
158                 mkimage -A mips -O linux -T kernel -a 0x80060000 -C gzip -e \
159                         0x80060000 \
160                         -n 'MIPS OpenWrt Linux-$(LINUX_VERSION)' \
161                         -d $(KDIR)/vmlinux-$(2).bin.gz $(KDIR)/vmlinux-$(2).uImage; \
162                 ( \
163                         dd if=$(KDIR)/vmlinux-$(2).uImage bs=1408k conv=sync; \
164                         dd if=$(KDIR)/root.$(1) bs=6208k conv=sync; \
165                 ) > $(call imgname,$(1),$(2)).bin; \
166                 $(STAGING_DIR_HOST)/bin/mkplanexfw \
167                         -B $(2) \
168                         -v 2.00.00 \
169                         -i $(call imgname,$(1),$(2)).bin \
170                         -o $(call imgname,$(1),$(2)).webui; \
171         fi; fi
172 endef
173
174 define Image/Build/TPLINK
175         $(call PatchKernelGzip,$(2),$(3))
176         -$(STAGING_DIR_HOST)/bin/mktplinkfw \
177                 -B $(4) -N OpenWrt -V $(REVISION)\
178                 -k $(KDIR)/vmlinux-$(2).bin.gz \
179                 -r $(BIN_DIR)/openwrt-$(BOARD)-root.$(1) \
180                 -o $(call imgname,$(1),$(2)).uni
181 endef
182
183 define Image/Build/CyberTAN
184         $(call PatchKernelGzip,$(2),$(3))
185         $(call MkImageGzip,$(KDIR)/vmlinux-$(2).bin.gz,$(KDIR)/vmlinux-$(2).uImage)
186         ( \
187                 dd if=$(KDIR)/vmlinux-$(2).uImage bs=64k conv=sync; \
188                 dd if=/dev/zero bs=1 count=65476; \
189                 dd if=$(KDIR)/root.$(1) bs=64k; \
190         ) > $(KDIR)/vmlinux-$(2).image
191         $(STAGING_DIR_HOST)/bin/trx -o $(KDIR)/vmlinux-$(2).trx \
192                 -f $(KDIR)/vmlinux-$(2).image
193         -$(STAGING_DIR_HOST)/bin/addpattern -B $(2) -v v$(4) -g \
194                 -i $(KDIR)/vmlinux-$(2).trx \
195                 -o $(call imgname,$(1),$(2)).bin
196 endef
197
198 define Image/Build/Template/Compex
199         $(call Image/Build/MyLoader,$(1),$(2))
200 endef
201
202 define Image/Build/Template/Compex/squashfs
203         $(call Image/Build/Template/Compex,squashfs,$(1))
204 endef
205
206 define Image/Build/Template/WRT400N
207         $(call Image/Build/WRT400N,$(1),$(2),$(3),$(4))
208 endef
209
210 define Image/Build/Template/WRT400N/squashfs
211         $(call Image/Build/Template/WRT400N,squashfs,$(1),$(2),$(3))
212 endef
213
214 define Image/Build/Template/WRT400N/jffs2-64k
215         $(call Image/Build/Template/WRT400N,jffs2-64k,$(1),$(2),$(3))
216 endef
217
218 define Image/Build/Template/CyberTAN
219         $(call Image/Build/CyberTAN,$(1),$(2),$(3),$(4))
220 endef
221
222 define Image/Build/Template/CyberTAN/squashfs
223         $(call Image/Build/Template/CyberTAN,squashfs,$(1),$(2),$(3))
224 endef
225
226 define Image/Build/Template/CyberTAN/jffs2-64k
227         $(call Image/Build/Template/CyberTAN,jffs2-64k,$(1),$(2),$(3))
228 endef
229
230 define Image/Build/Template/Cameo
231         $(call Image/Build/Cameo,$(1),$(2),$(3),$(4))
232 endef
233
234 define Image/Build/Template/Cameo/squashfs
235         $(call Image/Build/Template/Cameo,squashfs,$(1),$(2),$(3))
236 endef
237
238 define Image/Build/Template/AP83
239         $(call Image/Build/AP83,$(1),$(2),$(3))
240 endef
241
242 define Image/Build/Template/AP83/squashfs
243         $(call Image/Build/Template/AP83,squashfs,$(1),$(2))
244 endef
245
246 define Image/Build/Template/AP83/jffs2-64k
247         $(call Image/Build/Template/AP83,jffs2-64k,$(1),$(2))
248 endef
249
250 define Image/Build/Template/TPLINK
251         $(call Image/Build/TPLINK,$(1),$(2),$(3),$(4))
252 endef
253
254 define Image/Build/Template/TPLINK/squashfs
255         $(call Image/Build/Template/TPLINK,squashfs,$(1),$(2),$(3))
256 endef
257
258 define Image/Build/Template/TPLINK4K
259         $(call Image/Build/TPLINK,$(1),$(2),$(3),$(4))
260 endef
261
262 define Image/Build/Template/TPLINK4K/squashfs
263         $(call Image/Build/Template/TPLINK,squashfs-4k,$(1),$(2),$(3))
264 endef
265
266 define Image/Build/Template/UBNT
267         $(call Image/Build/UBNT,$(1),$(2),$(3),$(4),$(5),$(6))
268 endef
269
270 define Image/Build/Template/UBNT/squashfs
271         $(call Image/Build/Template/UBNT,squashfs,$(1),$(2),$(3),$(4),$(5))
272 endef
273
274 define Image/Build/Template/UBNT/jffs2-64k
275         $(call Image/Build/Template/UBNT,jffs2-64k,$(1),$(2),$(3),$(4),$(5))
276 endef
277
278 define Image/Build/Template/Planex
279         $(call Image/Build/Planex,$(1),$(2),$(3))
280 endef
281
282 define Image/Build/Template/Planex/squashfs
283         $(call Image/Build/Template/Planex,squashfs,$(1),$(2))
284 endef
285
286 define Image/Build/Template/Planex/jffs2-64k
287         $(call Image/Build/Template/Planex,jffs2-64k,$(1),$(2))
288 endef
289
290 define Image/Build/Profile/AP83
291         $(call Image/Build/Template/AP83/$(1),ap83,board=AP83)
292 endef
293
294 define Image/Build/Profile/WP543
295         $(call Image/Build/Template/Compex/$(1),wp543)
296 endef
297
298 define Image/Build/Profile/DIR615C1
299         $(call Image/Build/Template/Cameo/$(1),dir-615c1,board=TEW-632BRP,"AP81-AR9130-RT-070614-02")
300 endef
301
302 define Image/Build/Profile/TEW632BRP
303         $(call Image/Build/Template/Cameo/$(1),tew-632brp,board=TEW-632BRP,"AP81-AR9130-RT-070614-00")
304 endef
305
306 define Image/Build/Profile/TEW652BRP
307         $(call Image/Build/Template/Cameo/$(1),tew-652brp,board=TEW-632BRP,"AP81-AR9130-RT-080609-05")
308 endef
309
310 define Image/Build/Profile/A02RBW300N
311         $(call Image/Build/Template/Cameo/$(1),a02-rb-w300n,board=TEW-632BRP,"AP81-AR9130-RT-070614-03")
312 endef
313
314 define Image/Build/Profile/UBNTRS
315         $(call Image/Build/Template/UBNT/$(1),ubnt-rs,board=UBNT-RS,RS,RSx,ar7100)
316 endef
317
318 define Image/Build/Profile/UBNTRSPRO
319         $(call Image/Build/Template/UBNT/$(1),ubnt-rspro,board=UBNT-RSPRO,RSPRO,RSPRO,ar7100pro)
320 endef
321
322 define Image/Build/Profile/UBNTLSSR71
323         $(call Image/Build/Template/UBNT/$(1),ubnt-ls-sr71,board=UBNT-LS-SR71,LS-SR71,LS-SR71,ar7100)
324 endef
325
326 define Image/Build/Profile/UBNT
327         $(call Image/Build/Profile/UBNTRS,$(1))
328         $(call Image/Build/Profile/UBNTRSPRO,$(1))
329         $(call Image/Build/Profile/UBNTLSSR71,$(1))
330 endef
331
332 define Image/Build/Profile/MZKW04NU
333         $(call Image/Build/Template/Planex/$(1),mzk-w04nu,board=MZK-W04NU)
334 endef
335
336 define Image/Build/Profile/MZKW300NH
337         $(call Image/Build/Template/Planex/$(1),mzk-w300nh,board=MZK-W300NH)
338 endef
339
340 define Image/Build/Profile/TLWR741NDV1
341         $(call Image/Build/Template/TPLINK4K/$(1),tl-wr741ndv1,board=TL-WR741ND,TL-WR741NDv1)
342 endef
343
344 define Image/Build/Profile/TLWR841NDV3
345         $(call Image/Build/Template/TPLINK/$(1),tl-wr841ndv3,board=TL-WR941ND,TL-WR841NDv3)
346 endef
347
348 define Image/Build/Profile/TLWR841NDV5
349         $(call Image/Build/Template/TPLINK4K/$(1),tl-wr841ndv5,board=TL-WR741ND,TL-WR841NDv5)
350 endef
351
352 define Image/Build/Profile/TLWR941NDV2
353         $(call Image/Build/Template/TPLINK/$(1),tl-wr941ndv2,board=TL-WR941ND,TL-WR941NDv2)
354 endef
355
356 define Image/Build/Profile/WRT400N
357         $(call Image/Build/Template/WRT400N/$(1),wrt400n,board=WRT400N)
358 endef
359
360 define Image/Build/Profile/WRT160NL
361         $(call Image/Build/Template/CyberTAN/$(1),wrt160nl,board=WRT160NL,1.00.01)
362 endef
363
364 define Image/Build/Profile/Default
365         $(call Image/Build/Profile/AP83,$(1))
366         $(call Image/Build/Profile/A02RBW300N,$(1))
367         $(call Image/Build/Profile/DIR615C1,$(1))
368         $(call Image/Build/Profile/MZKW04NU,$(1))
369         $(call Image/Build/Profile/MZKW300NH,$(1))
370         $(call Image/Build/Profile/TEW632BRP,$(1))
371         $(call Image/Build/Profile/TEW652BRP,$(1))
372         $(call Image/Build/Profile/TLWR741NDV1,$(1))
373         $(call Image/Build/Profile/TLWR841NDV3,$(1))
374         $(call Image/Build/Profile/TLWR841NDV5,$(1))
375         $(call Image/Build/Profile/TLWR941NDV2,$(1))
376         $(call Image/Build/Profile/UBNT,$(1))
377         $(call Image/Build/Profile/WP543,$(1))
378         $(call Image/Build/Profile/WRT400N,$(1))
379         $(call Image/Build/Profile/WRT160NL,$(1))
380 endef
381
382 define Image/Build/Profile/Madwifi
383         $(call Image/Build/Profile/UBNT,$(1))
384         $(call Image/Build/Profile/WP543,$(1))
385 endef
386
387 define Image/Build/squashfs
388         dd if=$(KDIR)/root.squashfs of=$(IMGNAME)-root.squashfs-4k bs=4k conv=sync
389         $(call add_jffs2_mark,$(IMGNAME)-root.squashfs-4k)
390         $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
391 endef
392
393 define Image/Build
394         $(call Image/Build/$(1))
395         dd if=$(KDIR)/root.$(1) of=$(IMGNAME)-root.$(1) bs=128k conv=sync
396
397         $(call Image/Build/Profile/$(PROFILE),$(1))
398 endef
399
400 $(eval $(call BuildImage))