2 # Copyright (C) 2008-2011 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
7 include $(TOPDIR
)/rules.mk
8 include $(INCLUDE_DIR
)/image.mk
11 $(BIN_DIR
)/$(IMG_PREFIX
)-$(2)-$(1)
15 $(call imgname
,$(1),$(2))-sysupgrade.bin
18 VMLINUX
:=$(IMG_PREFIX
)-vmlinux
19 UIMAGE
:=$(IMG_PREFIX
)-uImage
21 define Image
/Build
/Initramfs
22 $(call Image
/Build
/Profile
/$(PROFILE
),initramfs
)
25 DEVICE_VARS
+= DTS IMAGE_SIZE KERNEL_SIZE
27 loadaddr-y
:= 0x80000000
28 loadaddr-
$(CONFIG_TARGET_ramips_rt288x
) := 0x88000000
29 loadaddr-
$(CONFIG_TARGET_ramips_mt7621
) := 0x80001000
31 KERNEL_LOADADDR
:= $(loadaddr-y
)
33 KERNEL_DTB
= kernel-bin | patch-dtb | lzma
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
)
43 define Build
/patch-dtb
44 $(call Image
/BuildDTB
,..
/dts
/$(DTS
).dts
,$@.dtb
)
45 $(STAGING_DIR_HOST
)/bin
/patch-dtb
$@
$@.dtb
49 $(STAGING_DIR_HOST
)/bin
/trx \
53 -a
4 -f
$(IMAGE_ROOTFS
)
56 define Build
/relocate-kernel
58 dd if
=$(KDIR
)/loader.bin bs
=32 conv
=sync
&& \
59 perl
-e
'@s = stat("$@"); print pack("V", @s[7])' && \
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; \
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
; \
74 $(call MkImage
,lzma
,$(KDIR
)/vmlinux-
$(2).bin.lzma.combined
,$(call sysupname
,$(1),$(2)),$(6))
77 define Build
/umedia-header
78 fix-u-media-header
-T
0x46 -B
$(1) -i
$@
-o
$@.new
&& mv
$@.new
$@
81 define Build
/senao-header
82 $(STAGING_DIR_HOST
)/bin
/mksenaofw
$(1) -e
$@
-o
$@.new
87 # The real magic happens inside these templates
89 # $(1), compression method
90 # $(2), filename of image data
91 # $(3), output filename
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
) \
100 $(STAGING_DIR_HOST
)/bin
/lzma e
$(1) -lc1
-lp2
-pb2
$(2)
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; \
110 $(CP
) $(KDIR
)/$(output_name
) $(BIN_DIR
)/$(output_name
); \
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
)
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))
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))
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
152 # Build images for default ralink layout for 4MB flash
153 # kernel + roots = 0x3b0000
154 # $(1) = squashfs/initramfs
155 # $(2) = lowercase board name
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))
161 # Build images for default ralink layout for 8MB flash
162 # kernel + roots = 0x7b0000
163 # $(1) = squashfs/initramfs
164 # $(2) = lowercase board name
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))
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))
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))
179 # Build images for a custom sized flash layout
180 # $(1) = squashfs/initramfs
181 # $(2) = lowercase board name
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))
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))
192 BuildFirmware
/CustomFlashFactory
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3))
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
)
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
)
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; \
212 dd if
=$(KDIR
)/vmlinux-
$(2).bin.lzma of
=$(KDIR
)/vmlinux-
$(2).bin.lzma.padded bs
=64k conv
=sync
; \
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"; \
229 dd if
=$(KDIR
)/vmlinux-
$(2)-sysupgrade.tmp.seama
; \
230 dd if
=$(KDIR
)/root.
$(1) bs
=64k conv
=sync
; \
231 ) > $(BIN_DIR
)/$(output_name
); \
234 BuildFirmware
/Seama
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3))
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
; \
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
; \
249 BuildFirmware
/PorayDualSize
/initramfs
=$(call BuildFirmware
/DefaultDualSize
/initramfs
,$(1),$(2),$(3))
252 ifeq ($(SUBTARGET
),rt288x
)
256 ifeq ($(SUBTARGET
),rt305x
)
258 include rt305x-legacy.mk
261 ifeq ($(SUBTARGET
),rt3883
)
265 ifeq ($(SUBTARGET
),mt7620
)
269 ifeq ($(SUBTARGET
),mt7621
)
273 ifeq ($(SUBTARGET
),mt7628
)
277 ifeq ($(SUBTARGET
),mt7688
)
283 # Generic Targets - only needed for legacy image building code
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
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
)
303 $(call Image
/Build
/$(1))
304 dd if
=$(KDIR
)/root.
$(1) of
=$(BIN_DIR
)/$(IMG_PREFIX
)-root.
$(1) bs
=128k conv
=sync
307 define Image
/Build
/Profile
308 $(if
$(CONFIG_TARGET_ROOTFS_INITRAMFS
),$(call Image
/Build
/Profile
/$(1),initramfs
))
309 $(call Image
/Build
/Profile
/$(1),$(2))
314 $(eval
$(call BuildImage
))