ramips: add build recipe for senao header
[openwrt/openwrt.git] / target / linux / ramips / image / Makefile
1 #
2 # Copyright (C) 2008-2011 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)-$(1)
12 endef
13
14 define sysupname
15 $(call imgname,$(1),$(2))-sysupgrade.bin
16 endef
17
18 VMLINUX:=$(IMG_PREFIX)-vmlinux
19 UIMAGE:=$(IMG_PREFIX)-uImage
20
21 define Image/Build/Initramfs
22 $(call Image/Build/Profile/$(PROFILE),initramfs)
23 endef
24
25 DEVICE_VARS += DTS IMAGE_SIZE KERNEL_SIZE
26
27 loadaddr-y := 0x80000000
28 loadaddr-$(CONFIG_TARGET_ramips_rt288x) := 0x88000000
29 loadaddr-$(CONFIG_TARGET_ramips_mt7621) := 0x80001000
30
31 KERNEL_LOADADDR := $(loadaddr-y)
32
33 KERNEL_DTB = kernel-bin | patch-dtb | lzma
34 define Device/Default
35 PROFILES = Default $$(DTS)
36 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DTS).dts)
37 KERNEL := $(KERNEL_DTB) | uImage lzma
38 IMAGES := sysupgrade.bin
39 IMAGE_SIZE := $(ralink_default_fw_size_8M)
40 IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | check-size $$$$(IMAGE_SIZE)
41 endef
42
43 define Build/patch-dtb
44 $(call Image/BuildDTB,../dts/$(DTS).dts,$@.dtb)
45 $(STAGING_DIR_HOST)/bin/patch-dtb $@ $@.dtb
46 endef
47
48 define Build/trx
49 $(STAGING_DIR_HOST)/bin/trx \
50 -o $@ \
51 -m $(IMAGE_SIZE) \
52 -f $(IMAGE_KERNEL) \
53 -a 4 -f $(IMAGE_ROOTFS)
54 endef
55
56 define Build/relocate-kernel
57 ( \
58 dd if=$(KDIR)/loader.bin bs=32 conv=sync && \
59 perl -e '@s = stat("$@"); print pack("V", @s[7])' && \
60 cat $@ \
61 ) > $@.new
62 mv $@.new $@
63 endef
64
65 define MkCombineduImage
66 $(call PatchKernelLzma,$(2),$(3))
67 if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt `expr $(4) - 64` ]; then \
68 echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big" >&2; \
69 else if [ `stat -c%s "$(KDIR)/root.$(1)"` -gt $(5) ]; then \
70 echo "Warning: $(KDIR)/root.$(1) is too big" >&2; \
71 else \
72 ( dd if=$(KDIR)/vmlinux-$(2).bin.lzma bs=`expr $(4) - 64` conv=sync ; dd if=$(KDIR)/root.$(1) ) > $(KDIR)/vmlinux-$(2).bin.lzma.combined ; \
73 fi ; fi
74 $(call MkImage,lzma,$(KDIR)/vmlinux-$(2).bin.lzma.combined,$(call sysupname,$(1),$(2)),$(6))
75 endef
76
77 define Build/umedia-header
78 fix-u-media-header -T 0x46 -B $(1) -i $@ -o $@.new && mv $@.new $@
79 endef
80
81 define Build/senao-header
82 $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
83 mv $@.new $@
84 endef
85
86 #
87 # The real magic happens inside these templates
88 #
89 # $(1), compression method
90 # $(2), filename of image data
91 # $(3), output filename
92 define MkImage
93 $(eval imagename=$(if $(4),$(4),MIPS OpenWrt Linux-$(LINUX_VERSION)))
94 -mkimage -A mips -O linux -T kernel -C $(1) -a $(loadaddr-y) -e $(loadaddr-y) \
95 -n "$(imagename)" \
96 -d $(2) $(3)
97 endef
98
99 define CompressLzma
100 $(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
101 endef
102
103 define MkImageSysupgrade/squashfs
104 $(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-$(if $(4),$(4),sysupgrade).bin)
105 cat $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) > $(KDIR)/$(output_name)
106 $(call prepare_generic_squashfs,$(KDIR)/$(output_name))
107 if [ `stat -c%s "$(KDIR)/$(output_name)"` -gt $(3) ]; then \
108 echo "Warning: $(KDIR)/$(output_name) is too big" >&2; \
109 else \
110 $(CP) $(KDIR)/$(output_name) $(BIN_DIR)/$(output_name); \
111 fi
112 endef
113
114 # $(1), lowercase board name like "mt7620a_v22sg"
115 # $(2), DTS filename without .dts extension
116 # $(3), optional filename suffix, e.g. "-initramfs"
117 define PatchKernelLzmaDtb
118 cp $(KDIR)/vmlinux$(3) $(KDIR)/vmlinux-$(1)$(3)
119 $(call Image/BuildDTB,../dts/$(2).dts,$(KDIR)/$(2).dtb)
120 $(STAGING_DIR_HOST)/bin/patch-dtb $(KDIR)/vmlinux-$(1)$(3) $(KDIR)/$(2).dtb
121 $(call CompressLzma,$(KDIR)/vmlinux-$(1)$(3),$(KDIR)/vmlinux-$(1)$(3).bin.lzma)
122 endef
123
124 # $(1), lowercase board name
125 # $(2), DTS filename without .dts extension
126 # $(3), ih_name field of uImage header
127 # $(4), optional filename suffix, e.g. "-initramfs"
128 define MkImageLzmaDtb
129 $(call PatchKernelLzmaDtb,$(1),$(2),$(4))
130 $(call MkImage,lzma,$(KDIR)/vmlinux-$(1)$(4).bin.lzma,$(KDIR)/vmlinux-$(1)$(4).uImage,$(3))
131 endef
132
133 # $(1), Rootfs type, e.g. squashfs
134 # $(2), lowercase board name
135 # $(3), DTS filename without .dts extension
136 # $(4), maximum size of sysupgrade image
137 # $(5), uImage header's ih_name field
138 define BuildFirmware/OF
139 $(call MkImageLzmaDtb,$(2),$(3),$(5))
140 $(call MkImageSysupgrade/$(1),$(1),$(2),$(4),$(6))
141 endef
142
143 # $(1), squashfs/initramfs
144 # $(2), lowercase board name
145 # $(3), DTS filename without .dts extension
146 # $(4), ih_name field of uImage header
147 define BuildFirmware/OF/initramfs
148 $(call MkImageLzmaDtb,$(2),$(3),$(4),-initramfs)
149 $(CP) $(KDIR)/vmlinux-$(2)-initramfs.uImage $(call imgname,$(1),$(2))-uImage.bin
150 endef
151
152 # Build images for default ralink layout for 4MB flash
153 # kernel + roots = 0x3b0000
154 # $(1) = squashfs/initramfs
155 # $(2) = lowercase board name
156 # $(3) = dts file
157 ralink_default_fw_size_4M=3866624
158 BuildFirmware/Default4M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_4M),$(4))
159 BuildFirmware/Default4M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
160
161 # Build images for default ralink layout for 8MB flash
162 # kernel + roots = 0x7b0000
163 # $(1) = squashfs/initramfs
164 # $(2) = lowercase board name
165 # $(3) = dts file
166 # $(4) = uImage header name field
167 ralink_default_fw_size_8M=8060928
168 BuildFirmware/Default8M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_8M),$(4))
169 BuildFirmware/Default8M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
170
171 ralink_default_fw_size_16M=16121856
172 BuildFirmware/Default16M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_16M),$(4))
173 BuildFirmware/Default16M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
174
175 ralink_default_fw_size_32M=33226752
176 BuildFirmware/Default32M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_32M),$(4))
177 BuildFirmware/Default32M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
178
179 # Build images for a custom sized flash layout
180 # $(1) = squashfs/initramfs
181 # $(2) = lowercase board name
182 # $(3) = dts file
183 # $(4) = kernel + rootfs size
184 BuildFirmware/CustomFlash/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(4),$(5),$(6))
185 BuildFirmware/CustomFlash/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3))
186
187 # Some boards need a special header inside the uImage to make them bootable
188 define BuildFirmware/CustomFlashFactory/squashfs
189 $(call BuildFirmware/CustomFlash/$(1),$(1),$(2),$(3),$(4))
190 $(call BuildFirmware/CustomFlash/$(1),$(1),$(2),$(3),$(4),$(5),$(6))
191 endef
192 BuildFirmware/CustomFlashFactory/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3))
193
194 # wrappers for boards that have 4MB and 8MB versions
195 define BuildFirmware/DefaultDualSize/squashfs
196 $(call BuildFirmware/Default4M/$(1),$(1),$(2)-4M,$(3)-4M)
197 $(call BuildFirmware/Default8M/$(1),$(1),$(2)-8M,$(3)-8M)
198 endef
199 define BuildFirmware/DefaultDualSize/initramfs
200 $(call BuildFirmware/OF/initramfs,$(1),$(2)-4M,$(3)-4M)
201 $(call BuildFirmware/OF/initramfs,$(1),$(2)-8M,$(3)-8M)
202 endef
203
204 # build Seama header images
205 define BuildFirmware/Seama/squashfs
206 $(call MkImageLzmaDtb,$(2),$(3),$(5))
207 $(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-sysupgrade.bin)
208 cat $(KDIR)/vmlinux-$(2).bin.lzma $(KDIR)/root.$(1) > $(KDIR)/img_$(2).$(1).tmp
209 if [ `stat -c%s "$(KDIR)/img_$(2).$(1).tmp"` -gt $(5) ]; then \
210 echo "Warning: $(KDIR)/img_$(2).$(1).tmp is too big" >&2; \
211 else \
212 dd if=$(KDIR)/vmlinux-$(2).bin.lzma of=$(KDIR)/vmlinux-$(2).bin.lzma.padded bs=64k conv=sync; \
213 ( \
214 dd if=$(KDIR)/vmlinux-$(2).bin.lzma.padded bs=1 count=`expr \`stat -c%s $(KDIR)/vmlinux-$(2).bin.lzma.padded\` - 64`; \
215 dd if=$(KDIR)/root.$(1) bs=64k conv=sync; \
216 ) > $(KDIR)/vmlinux-$(2).tmp; \
217 $(STAGING_DIR_HOST)/bin/seama \
218 -i $(KDIR)/vmlinux-$(2).tmp \
219 -m "dev=/dev/mtdblock/2" -m "type=firmware"; \
220 $(STAGING_DIR_HOST)/bin/seama \
221 -s $(call imgname,$(1),$(2))-factory.bin \
222 -m "signature=$(4)" \
223 -i $(KDIR)/vmlinux-$(2).tmp.seama; \
224 dd if=$(KDIR)/vmlinux-$(2).bin.lzma.padded bs=1 count=`expr \`stat -c%s $(KDIR)/vmlinux-$(2).bin.lzma.padded\` - 64` of=$(KDIR)/vmlinux-$(2)-sysupgrade.tmp; \
225 $(STAGING_DIR_HOST)/bin/seama \
226 -i $(KDIR)/vmlinux-$(2)-sysupgrade.tmp \
227 -m "dev=/dev/mtdblock/2" -m "type=firmware"; \
228 ( \
229 dd if=$(KDIR)/vmlinux-$(2)-sysupgrade.tmp.seama; \
230 dd if=$(KDIR)/root.$(1) bs=64k conv=sync; \
231 ) > $(BIN_DIR)/$(output_name); \
232 fi
233 endef
234 BuildFirmware/Seama/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3))
235
236 define BuildFirmware/PorayDualSize/squashfs
237 $(call BuildFirmware/DefaultDualSize/$(1),$(1),$(2),$(3))
238 if [ -e "$(call sysupname,$(1),$(2)-4M)" ]; then \
239 mkporayfw -B $(3) -F 4M \
240 -f $(call sysupname,$(1),$(2)-4M) \
241 -o $(call imgname,$(1),$(2)-4M)-factory.bin; \
242 fi
243 if [ -e "$(call sysupname,$(1),$(2)-8M)" ]; then \
244 mkporayfw -B $(3) -F 8M \
245 -f $(call sysupname,$(1),$(2)-8M) \
246 -o $(call imgname,$(1),$(2)-8M)-factory.bin; \
247 fi
248 endef
249 BuildFirmware/PorayDualSize/initramfs=$(call BuildFirmware/DefaultDualSize/initramfs,$(1),$(2),$(3))
250
251
252 ifeq ($(SUBTARGET),rt288x)
253 include rt288x.mk
254 endif
255
256 ifeq ($(SUBTARGET),rt305x)
257 include rt305x.mk
258 include rt305x-legacy.mk
259 endif
260
261 ifeq ($(SUBTARGET),rt3883)
262 include rt3883.mk
263 endif
264
265 ifeq ($(SUBTARGET),mt7620)
266 include mt7620.mk
267 endif
268
269 ifeq ($(SUBTARGET),mt7621)
270 include mt7621.mk
271 endif
272
273 ifeq ($(SUBTARGET),mt7628)
274 include mt7628.mk
275 endif
276
277 ifeq ($(SUBTARGET),mt7688)
278 include mt7688.mk
279 endif
280
281 ifdef LEGACY_DEVICES
282 #
283 # Generic Targets - only needed for legacy image building code
284 #
285 define Image/BuildKernel
286 cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(VMLINUX).elf
287 cp $(KDIR)/vmlinux $(BIN_DIR)/$(VMLINUX).bin
288 $(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
289 $(call MkImage,lzma,$(KDIR)/vmlinux.bin.lzma,$(KDIR)/uImage.lzma)
290 cp $(KDIR)/uImage.lzma $(BIN_DIR)/$(UIMAGE).bin
291 endef
292
293 define Image/BuildKernel/Initramfs
294 cp $(KDIR)/vmlinux-initramfs.elf $(BIN_DIR)/$(VMLINUX)-initramfs.elf
295 cp $(KDIR)/vmlinux-initramfs $(BIN_DIR)/$(VMLINUX)-initramfs.bin
296 $(call CompressLzma,$(KDIR)/vmlinux-initramfs,$(KDIR)/vmlinux-initramfs.bin.lzma)
297 $(call MkImage,lzma,$(KDIR)/vmlinux-initramfs.bin.lzma,$(KDIR)/uImage-initramfs.lzma)
298 cp $(KDIR)/uImage-initramfs.lzma $(BIN_DIR)/$(UIMAGE)-initramfs.bin
299 $(call Image/Build/Initramfs)
300 endef
301
302 define Image/Build
303 $(call Image/Build/$(1))
304 dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
305 endef
306
307 define Image/Build/Profile
308 $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/Build/Profile/$(1),initramfs))
309 $(call Image/Build/Profile/$(1),$(2))
310 endef
311
312 endif
313
314 $(eval $(call BuildImage))