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
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 \
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))
78 # The real magic happens inside these templates
80 # $(1), compression method
81 # $(2), filename of image data
82 # $(3), output filename
84 $(eval imagename
=$(if
$(4),$(4),MIPS OpenWrt Linux-
$(LINUX_VERSION
)))
85 -mkimage
-A mips
-O linux
-T kernel
-C
$(1) -a
$(loadaddr-y
) -e
$(loadaddr-y
) \
91 $(STAGING_DIR_HOST
)/bin
/lzma e
$(1) -lc1
-lp2
-pb2
$(2)
94 define MkImageSysupgrade
/squashfs
95 $(eval output_name
=$(IMG_PREFIX
)-$(2)-$(1)-$(if
$(4),$(4),sysupgrade
).bin
)
96 cat
$(KDIR
)/vmlinux-
$(2).uImage
$(KDIR
)/root.
$(1) > $(KDIR
)/$(output_name
)
97 $(call prepare_generic_squashfs
,$(KDIR
)/$(output_name
))
98 if
[ `stat -c%s "$(KDIR)/$(output_name)"` -gt
$(3) ]; then \
99 echo
"Warning: $(KDIR)/$(output_name) is too big" >&2; \
101 $(CP
) $(KDIR
)/$(output_name
) $(BIN_DIR
)/$(output_name
); \
105 # $(1), lowercase board name like "mt7620a_v22sg"
106 # $(2), DTS filename without .dts extension
107 # $(3), optional filename suffix, e.g. "-initramfs"
108 define PatchKernelLzmaDtb
109 cp
$(KDIR
)/vmlinux
$(3) $(KDIR
)/vmlinux-
$(1)$(3)
110 $(LINUX_DIR
)/scripts
/dtc
/dtc
-O dtb
-o
$(KDIR
)/$(2).dtb ..
/dts
/$(2).dts
111 $(STAGING_DIR_HOST
)/bin
/patch-dtb
$(KDIR
)/vmlinux-
$(1)$(3) $(KDIR
)/$(2).dtb
112 $(call CompressLzma
,$(KDIR
)/vmlinux-
$(1)$(3),$(KDIR
)/vmlinux-
$(1)$(3).bin.lzma
)
115 # $(1), lowercase board name
116 # $(2), DTS filename without .dts extension
117 # $(3), ih_name field of uImage header
118 # $(4), optional filename suffix, e.g. "-initramfs"
119 define MkImageLzmaDtb
120 $(call PatchKernelLzmaDtb
,$(1),$(2),$(4))
121 $(call MkImage
,lzma
,$(KDIR
)/vmlinux-
$(1)$(4).bin.lzma
,$(KDIR
)/vmlinux-
$(1)$(4).uImage
,$(3))
124 # $(1), Rootfs type, e.g. squashfs
125 # $(2), lowercase board name
126 # $(3), DTS filename without .dts extension
127 # $(4), maximum size of sysupgrade image
128 # $(5), uImage header's ih_name field
129 define BuildFirmware
/OF
130 $(call MkImageLzmaDtb
,$(2),$(3),$(5))
131 $(call MkImageSysupgrade
/$(1),$(1),$(2),$(4),$(6))
134 # $(1), squashfs/initramfs
135 # $(2), lowercase board name
136 # $(3), DTS filename without .dts extension
137 # $(4), ih_name field of uImage header
138 define BuildFirmware
/OF
/initramfs
139 $(call MkImageLzmaDtb
,$(2),$(3),$(4),-initramfs
)
140 $(CP
) $(KDIR
)/vmlinux-
$(2)-initramfs.uImage
$(call imgname
,$(1),$(2))-uImage.bin
143 # Build images for default ralink layout for 4MB flash
144 # kernel + roots = 0x3b0000
145 # $(1) = squashfs/initramfs
146 # $(2) = lowercase board name
148 ralink_default_fw_size_4M
=3866624
149 BuildFirmware
/Default4M
/squashfs
=$(call BuildFirmware
/OF
,$(1),$(2),$(3),$(ralink_default_fw_size_4M
),$(4))
150 BuildFirmware
/Default4M
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3),$(4))
152 # Build images for default ralink layout for 8MB flash
153 # kernel + roots = 0x7b0000
154 # $(1) = squashfs/initramfs
155 # $(2) = lowercase board name
157 # $(4) = uImage header name field
158 ralink_default_fw_size_8M
=8060928
159 BuildFirmware
/Default8M
/squashfs
=$(call BuildFirmware
/OF
,$(1),$(2),$(3),$(ralink_default_fw_size_8M
),$(4))
160 BuildFirmware
/Default8M
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3),$(4))
162 ralink_default_fw_size_16M
=16121856
163 BuildFirmware
/Default16M
/squashfs
=$(call BuildFirmware
/OF
,$(1),$(2),$(3),$(ralink_default_fw_size_16M
),$(4))
164 BuildFirmware
/Default16M
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3),$(4))
166 ralink_default_fw_size_32M
=33226752
167 BuildFirmware
/Default32M
/squashfs
=$(call BuildFirmware
/OF
,$(1),$(2),$(3),$(ralink_default_fw_size_32M
),$(4))
168 BuildFirmware
/Default32M
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3),$(4))
170 # Build images for a custom sized flash layout
171 # $(1) = squashfs/initramfs
172 # $(2) = lowercase board name
174 # $(4) = kernel + rootfs size
175 BuildFirmware
/CustomFlash
/squashfs
=$(call BuildFirmware
/OF
,$(1),$(2),$(3),$(4),$(5),$(6))
176 BuildFirmware
/CustomFlash
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3))
178 # Some boards need a special header inside the uImage to make them bootable
179 define BuildFirmware
/CustomFlashFactory
/squashfs
180 $(call BuildFirmware
/CustomFlash
/$(1),$(1),$(2),$(3),$(4))
181 $(call BuildFirmware
/CustomFlash
/$(1),$(1),$(2),$(3),$(4),$(5),$(6))
183 BuildFirmware
/CustomFlashFactory
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3))
185 # wrappers for boards that have 4MB and 8MB versions
186 define BuildFirmware
/DefaultDualSize
/squashfs
187 $(call BuildFirmware
/Default4M
/$(1),$(1),$(2)-4M
,$(3)-4M
)
188 $(call BuildFirmware
/Default8M
/$(1),$(1),$(2)-8M
,$(3)-8M
)
190 define BuildFirmware
/DefaultDualSize
/initramfs
191 $(call BuildFirmware
/OF
/initramfs
,$(1),$(2)-4M
,$(3)-4M
)
192 $(call BuildFirmware
/OF
/initramfs
,$(1),$(2)-8M
,$(3)-8M
)
195 # build Seama header images
196 define BuildFirmware
/Seama
/squashfs
197 $(call MkImageLzmaDtb
,$(2),$(3),$(5))
198 $(eval output_name
=$(IMG_PREFIX
)-$(2)-$(1)-sysupgrade.bin
)
199 cat
$(KDIR
)/vmlinux-
$(2).bin.lzma
$(KDIR
)/root.
$(1) > $(KDIR
)/img_
$(2).
$(1).tmp
200 if
[ `stat -c%s "$(KDIR)/img_$(2).$(1).tmp"` -gt
$$$$(($(5) - 64)) ]; then \
201 echo
"Warning: $(KDIR)/img_$(2).$(1).tmp is too big" >&2; \
203 dd if
=$(KDIR
)/vmlinux-
$(2).bin.lzma of
=$(KDIR
)/vmlinux-
$(2).bin.lzma.padded bs
=64k conv
=sync
; \
205 dd if
=$(KDIR
)/vmlinux-
$(2).bin.lzma.padded bs
=1 count
=`expr \`stat
-c
%s
$(KDIR
)/vmlinux-
$(2).bin.lzma.padded\
` - 64`; \
206 dd if
=$(KDIR
)/root.
$(1) bs
=64k conv
=sync
; \
207 ) > $(KDIR
)/vmlinux-
$(2).tmp
; \
208 $(STAGING_DIR_HOST
)/bin
/seama \
209 -i
$(KDIR
)/vmlinux-
$(2).tmp \
210 -m
"dev=/dev/mtdblock/2" -m
"type=firmware"; \
211 $(STAGING_DIR_HOST
)/bin
/seama \
212 -s
$(call imgname
,$(1),$(2))-factory.bin \
213 -m
"signature=$(4)" \
214 -i
$(KDIR
)/vmlinux-
$(2).tmp.seama
; \
215 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
; \
216 $(STAGING_DIR_HOST
)/bin
/seama \
217 -i
$(KDIR
)/vmlinux-
$(2)-sysupgrade.tmp \
218 -m
"dev=/dev/mtdblock/2" -m
"type=firmware"; \
220 dd if
=$(KDIR
)/vmlinux-
$(2)-sysupgrade.tmp.seama
; \
221 dd if
=$(KDIR
)/root.
$(1) bs
=64k conv
=sync
; \
222 ) > $(BIN_DIR
)/$(output_name
); \
225 BuildFirmware
/Seama
/initramfs
=$(call BuildFirmware
/OF
/initramfs
,$(1),$(2),$(3))
227 define BuildFirmware
/PorayDualSize
/squashfs
228 $(call BuildFirmware
/DefaultDualSize
/$(1),$(1),$(2),$(3))
229 if
[ -e
"$(call sysupname,$(1),$(2)-4M)" ]; then \
230 mkporayfw
-B
$(3) -F
4M \
231 -f
$(call sysupname
,$(1),$(2)-4M
) \
232 -o
$(call imgname
,$(1),$(2)-4M
)-factory.bin
; \
234 if
[ -e
"$(call sysupname,$(1),$(2)-8M)" ]; then \
235 mkporayfw
-B
$(3) -F
8M \
236 -f
$(call sysupname
,$(1),$(2)-8M
) \
237 -o
$(call imgname
,$(1),$(2)-8M
)-factory.bin
; \
240 BuildFirmware
/PorayDualSize
/initramfs
=$(call BuildFirmware
/DefaultDualSize
/initramfs
,$(1),$(2),$(3))
243 ifeq ($(SUBTARGET
),rt288x
)
247 ifeq ($(SUBTARGET
),rt305x
)
251 ifeq ($(SUBTARGET
),rt3883
)
255 ifeq ($(SUBTARGET
),mt7620
)
259 ifeq ($(SUBTARGET
),mt7621
)
263 ifeq ($(SUBTARGET
),mt7628
)
267 ifeq ($(SUBTARGET
),mt7688
)
272 ifndef TARGET_DEVICES
274 # Generic Targets - only needed for legacy image building code
276 define Image
/BuildKernel
277 cp
$(KDIR
)/vmlinux.elf
$(BIN_DIR
)/$(VMLINUX
).elf
278 cp
$(KDIR
)/vmlinux
$(BIN_DIR
)/$(VMLINUX
).bin
279 $(call CompressLzma
,$(KDIR
)/vmlinux
,$(KDIR
)/vmlinux.bin.lzma
)
280 $(call MkImage
,lzma
,$(KDIR
)/vmlinux.bin.lzma
,$(KDIR
)/uImage.lzma
)
281 cp
$(KDIR
)/uImage.lzma
$(BIN_DIR
)/$(UIMAGE
).bin
284 define Image
/BuildKernel
/Initramfs
285 cp
$(KDIR
)/vmlinux-initramfs.elf
$(BIN_DIR
)/$(VMLINUX
)-initramfs.elf
286 cp
$(KDIR
)/vmlinux-initramfs
$(BIN_DIR
)/$(VMLINUX
)-initramfs.bin
287 $(call CompressLzma
,$(KDIR
)/vmlinux-initramfs
,$(KDIR
)/vmlinux-initramfs.bin.lzma
)
288 $(call MkImage
,lzma
,$(KDIR
)/vmlinux-initramfs.bin.lzma
,$(KDIR
)/uImage-initramfs.lzma
)
289 cp
$(KDIR
)/uImage-initramfs.lzma
$(BIN_DIR
)/$(UIMAGE
)-initramfs.bin
290 $(call Image
/Build
/Initramfs
)
294 $(call Image
/Build
/$(1))
295 dd if
=$(KDIR
)/root.
$(1) of
=$(BIN_DIR
)/$(IMG_PREFIX
)-root.
$(1) bs
=128k conv
=sync
296 $(call Image
/Build
/Profile
/$(PROFILE
),$(1))
300 $(eval
$(call BuildImage
))