[brcm63xx] rework imagetag firmware generator and MTD partition parser to accomodate...
[15.05/openwrt.git] / target / linux / brcm63xx / image / Makefile
1
2 # Copyright (C) 2006 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 LOADADDR = 0x80010000           # RAM start + 16M 
11 KERNEL_ENTRY = $(LOADADDR)      # Newer kernels add a jmp to the kernel_entry at the start of the binary
12 RAMSIZE = 0x01000000            # 64MB
13
14 LOADER_MAKEOPTS= \
15                 KDIR=$(KDIR) \
16                 LOADADDR=$(LOADADDR) \
17                 KERNEL_ENTRY=$(KERNEL_ENTRY) \
18                 RAMSIZE=$(RAMSIZE)
19
20 SVN_REVISION=r$(shell svn info|grep Revision|cut -f1 -d\ )
21
22 define trxalign/jffs2-128k
23 -a 0x20000
24 endef
25 define trxalign/jffs2-64k
26 -a 0x10000
27 endef
28 define trxalign/squashfs
29 -a 1024
30 endef
31
32 define Image/Build/CFE
33         # Generate the tagged image
34         $(STAGING_DIR_HOST)/bin/imagetag -i $(KDIR)/vmlinux.lzma.cfe -f $(KDIR)/root.$(1) \
35                 -o $(BIN_DIR)/openwrt-$(2)-$(1)-$(6)-cfe.bin \
36                 -b $(2) -c $(3) -e $(LOADADDR) -l $(LOADADDR) \
37                 -t $(4) -d "$(5)"
38 #               -b $(2) -c $(3) -e $(KERNEL_ENTRY) -l $(LOADADDR)
39
40 endef
41
42 define Image/Build/CFEAGPF
43         # Generate the tagged image
44         $(STAGING_DIR_HOST)/bin/imagetag -i $(KDIR)/vmlinux.lzma.cfe -f $(KDIR)/root.$(1) \
45                 -o $(BIN_DIR)/openwrt-$(2)-$(1)-$(7)-cfe.bin \
46                 -b $(2) -c $(3) -e $(LOADADDR) -l $(LOADADDR) \
47                 -v 8 -m IMAGE -k 0x20000 -n $(4) -t $(5)
48 endef
49
50 define Image/Build/RedBoot
51         cp $(KDIR)/vmlinux.elf $(BIN_DIR)/openwrt-$(1)-vmlinux.elf
52         gzip -9 -c $(KDIR)/vmlinux > $(KDIR)/vmlinux.bin.gz
53         $(STAGING_DIR_HOST)/bin/lzma e $(KDIR)/vmlinux $(KDIR)/vmlinux.bin.l7
54         dd if=$(KDIR)/vmlinux.bin.l7 of=$(BIN_DIR)/openwrt-$(1)-vmlinux.lzma bs=65536 conv=sync
55         dd if=$(KDIR)/vmlinux.bin.gz of=$(BIN_DIR)/openwrt-$(1)-vmlinux.gz bs=65536 conv=sync
56 endef
57
58 define Image/Build/CFEOLD
59         $(TOPDIR)/scripts/brcmImage.pl -t -p    \
60                 -b $(2) -c $(3)                 \
61                 -k $(KDIR)/vmlinux.lzma.cfe     \
62                 -r $(KDIR)/root.$(1)            \
63                 -o $(BIN_DIR)/openwrt-$(2)-$(1)-cfe.bin
64 endef
65
66 define Build/Clean
67         $(MAKE) -C lzma-loader clean
68 endef
69
70 define Image/Prepare
71         # Standard LZMA kernel
72         cat $(KDIR)/vmlinux | $(STAGING_DIR_HOST)/bin/lzma e -si -so -eos -lc1 -lp2 -pb2 > $(KDIR)/vmlinux.lzma
73
74         # CFE is a LZMA nazi! It took me hours to find out the parameters!
75         # Also I think lzma has a bug cause it generates different output depending on
76         # if you use stdin / stdout or not. Use files instead of stdio here, cause
77         # otherwise CFE will complain and not boot the image.
78         $(STAGING_DIR_HOST)/bin/lzma e -d22 -fb64 -a1 $(KDIR)/vmlinux $(KDIR)/vmlinux.lzma.tmp
79
80         # Strip out the length, CFE doesn't like this
81         dd if=$(KDIR)/vmlinux.lzma.tmp of=$(KDIR)/vmlinux.lzma.cfe bs=5 count=1
82         dd if=$(KDIR)/vmlinux.lzma.tmp of=$(KDIR)/vmlinux.lzma.cfe ibs=13 obs=5 skip=1 seek=1 conv=notrunc
83         rm -f $(KDIR)/vmlinux.lzma.tmp
84
85         # Build the LZMA loader
86         rm -f $(KDIR)/loader.gz
87         $(MAKE) -C lzma-loader \
88                 BUILD_DIR="$(KDIR)" \
89                 TARGET="$(KDIR)" \
90                 clean install
91
92         echo -ne "\\x00" >> $(KDIR)/loader.gz
93         rm -f $(KDIR)/fs_mark
94         touch $(KDIR)/fs_mark
95         $(call prepare_generic_squashfs,$(KDIR)/fs_mark)
96 endef
97
98 define Image/Build
99         $(STAGING_DIR_HOST)/bin/trx -o $(BIN_DIR)/openwrt-$(BOARD)-$(1).trx -f $(KDIR)/loader.gz -f $(KDIR)/vmlinux.lzma $(call trxalign/$(1)) -f $(KDIR)/root.$(1)
100         dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/openwrt-$(BOARD)-root.$(1) bs=128k conv=sync
101         # Various routers
102         $(call Image/Build/CFE,$(1),96345GW2,6345,bccfe,,bccfe)
103         $(call Image/Build/CFE,$(1),96345GW2,6345,bc300,,bc300)
104         $(call Image/Build/CFE,$(1),96345GW2,6345,bc310,OpenWRT-$(SVN_REVISION),bc310)
105         $(call Image/Build/CFE,$(1),96348GW,6348,bccfe,,bcfe)
106         # BT Voyager V2500V
107         $(call Image/Build/CFE,$(1),V2500V_BB,6348,bc308,,btvgr)
108         # Tecom GW6000
109         $(call Image/Build/CFE,$(1),96348GW,6348,bc300,,bc300)
110         # Tecom GW6200
111         $(call Image/Build/CFE,$(1),96348GW,6348,bc310,$(shell printf '\x99'),gw6200)
112         # Neufbox4
113         $(call Image/Build/CFE,$(1),96358VW,6358,bccfe,,bccfe)
114         $(call Image/Build/CFE,$(1),96358VW,6358,bc310,OpenWRT-$(SVN_REVISION),nb4)
115         # Comtrend 536, 5621
116         $(call Image/Build/CFE,$(1),96348GW-11,6348,bccfe,,bccfe)
117         $(call Image/Build/CFE,$(1),96348GW-11,6348,bc300,,bc300)
118         # Davolink DV201AMR
119         $(call Image/Build/CFEOLD,$(1),DV201AMR,6348)
120         # USR 9108
121         $(call Image/Build/CFE,$(1),96348GW-A,6348,bccfe,,bccfe)
122         $(call Image/Build/CFE,$(1),96348GW-A,6348,bc300,,bc300)
123         $(call Image/Build/CFE,$(1),96348GW-A,6348,bc310,OpenWRT-$(SVN_REVISION),bc310)
124         # NetGear DG834GT
125         $(call Image/Build/CFE,$(1),96348GW-10,6348,bccfe,,bccfe)
126         $(call Image/Build/CFE,$(1),96348GW-10,6348,bc300,,bc300)
127
128         # Sagem F@ST2404
129         $(call Image/Build/CFE,$(1),F@ST2404,6348,bccfe,,bccfe)
130         $(call Image/Build/CFE,$(1),F@ST2404,6348,bc300,,bc300)
131         $(call Image/Build/CFE,$(1),F@ST2404,6348,bc310,OpenWRT-$(SVN_REVISION),bc310)
132         # Inventel Livebox
133         $(call Image/Build/RedBoot,livebox)
134         # Pirelli Alice Gate VoIP 2 Plus Wi-Fi AGPF-S0
135         $(call Image/Build/CFEAGPF,$(1),AGPF-S0,6358,0x20000,bccfe,,bccfe)
136         $(call Image/Build/CFEAGPF,$(1),AGPF-S0,6358,0x20000,ag306,,agv2+w)
137 endef
138
139 $(eval $(call BuildImage))