2 # Copyright (C) 2006-2015 OpenWrt.org
3 # Copyright (C) 2016 LEDE project
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
8 include $(TOPDIR
)/rules.mk
9 include $(INCLUDE_DIR
)/image.mk
11 KERNEL_LOADADDR
= 0x80010000 # RAM start + 64K
12 LOADER_ENTRY
= 0x80a00000 # RAM start + 10M, for relocate
13 RAMSIZE
= 0x02000000 # 32MB
14 LZMA_TEXT_START
= 0x81800000 # 32MB - 8MB
18 LOADADDR
=$(KERNEL_LOADADDR
) \
20 LZMA_TEXT_START
=$(LZMA_TEXT_START
) \
25 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
26 CROSS_COMPILE
=$(TARGET_CROSS
) \
27 LZMA_TEXT_START
=$(LOADER_ENTRY
)
30 rm -rf
$(KDIR
)/relocate
31 $(CP
) ..
/..
/generic
/image
/relocate
$(KDIR
)
32 $(MAKE
) -C
$(KDIR
)/relocate
$(RELOCATE_MAKEOPTS
)
35 ### Kernel scripts ###
36 define Build
/hcs-initramfs
37 $(STAGING_DIR_HOST
)/bin
/hcsmakeimage
--magic_bytes
=$(HCS_MAGIC_BYTES
) \
38 --rev_maj
=$(HCS_REV_MAJ
) --rev_min
=$(HCS_REV_MIN
) --input_file
=$@ \
39 --output_file
=$@.hcs
--ldaddress
=$(KERNEL_LOADADDR
)
43 define Build
/loader-lzma
45 $(MAKE
) -C lzma-loader \
47 PKG_BUILD_DIR
="$@.src" \
48 TARGET_DIR
="$(dir $@)" \
50 LOADER_NAME
="$(notdir $@)" \
57 # CFE is a LZMA nazi! It took me hours to find out the parameters!
58 # Also I think lzma has a bug cause it generates different output depending on
59 # if you use stdin / stdout or not. Use files instead of stdio here, cause
60 # otherwise CFE will complain and not boot the image.
61 $(call Build
/lzma-no-dict
,-d22
-fb64
-a1
)
62 # Strip out the length, CFE doesn't like this
63 dd if
=$@ of
=$@.new bs
=5 count
=1
64 dd if
=$@ of
=$@.new ibs
=13 obs
=5 skip
=1 seek
=1 conv
=notrunc
68 define Build
/relocate-kernel
69 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
70 # kernel might get larger than that, so let CFE unpack and load at a
71 # higher address and make the kernel relocate itself to the expected
74 dd if
=$(KDIR
)/relocate
/loader.bin bs
=32 conv
=sync
&& \
75 perl
-e
'@s = stat("$@"); print pack("N", @s[7])' && \
82 define rootfspad
/jffs2-128k
85 define rootfspad
/jffs2-64k
88 define rootfspad
/squashfs
91 define Image
/LimitName16
92 $(shell expr substr
"$(1)" 1 16)
95 define Image
/FileSystemStrip
96 $(firstword $(subst +,$(space
),$(subst root.
,,$(notdir $(1)))))
100 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
101 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
102 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
103 --info1
"$(call Image/LimitName16,$(DEVICE_NAME))" \
104 --info2
"$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
105 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
109 define Build
/cfe-jffs2
110 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2 \
114 --eraseblock
=$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
117 --compression-mode
=none
119 $(call Build
/pad-to
,$(BLOCKSIZE
))
122 define Build
/cfe-jffs2-cferam
128 # CFE ROM checks JFFS2 dirent version of cferam.
129 # If version is not > 0 it will ignore the fs entry.
130 # JFFS2 sets version 0 to the first fs entry and increments
131 # it on the following ones, so let's create a dummy file that
132 # will have version 0 and let cferam be the second (version 1).
133 touch
$@
-cferam
/1-openwrt
134 # Add cferam as the last file in the JFFS2 partition
135 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-cferam
/$(CFE_RAM_JFFS2_NAME
)
137 # The JFFS2 partition creation should result in the following
139 # 1) 1-openwrt (version 0, ino 2)
140 # 2) cferam.000 (version 1, ino 3)
141 $(call Build
/cfe-jffs2
,$@
-cferam
)
143 # Some devices need padding between CFE RAM and kernel
144 $(if
$(CFE_RAM_JFFS2_PAD
),$(call Build
/pad-to
,$(CFE_RAM_JFFS2_PAD
)))
146 # Add CFE partition tag
147 $(if
$(CFE_PART_ID
),$(call Build
/cfe-part-tag
))
150 dd if
=$@.kernel
>> $@
154 define Build
/cfe-jffs2-kernel
158 # CFE RAM checks JFFS2 dirent version of vmlinux.
159 # If version is not > 0 it will ignore the fs entry.
160 # JFFS2 sets version 0 to the first fs entry and increments
161 # it on the following ones, so let's create a dummy file that
162 # will have version 0 and let cferam be the second (version 1).
163 touch
$@
-kernel
/1-openwrt
164 # vmlinux is located on a different JFFS2 partition, but CFE RAM
165 # ignores it, so let's create another dummy file that will match
166 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
167 # CFE RAM won't be able to find vmlinux if cferam has the same
169 touch
$@
-kernel
/2-openwrt
170 # Add vmlinux as the last file in the JFFS2 partition
171 $(TOPDIR
)/scripts
/cfe-bin-header.py \
173 --output-file
$@
-kernel
/vmlinux.lz \
174 --load-addr
$(LOADER_ENTRY
) \
175 --entry-addr
$(LOADER_ENTRY
)
177 # The JFFS2 partition creation should result in the following
179 # 1) 1-openwrt (version 0, ino 2)
180 # 2) 2-openwrt (version 1, ino 3)
181 # 3) vmlinux.lz (version 2, ino 4)
182 $(call Build
/cfe-jffs2
,$@
-kernel
)
185 define Build
/cfe-part-tag
188 $(TOPDIR
)/scripts
/cfe-partition-tag.py \
189 --input-file
$@.part \
191 --flags
$(CFE_PART_FLAGS
) \
192 --id
$(CFE_PART_ID
) \
193 --name
$(VERSION_CODE
) \
194 --version
$(DEVICE_NAME
)
196 $(call Build
/pad-to
,$(BLOCKSIZE
))
201 define Build
/cfe-sercomm-part
202 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
204 --output-file
$@.kernel_rootfs \
205 --part-name kernel_rootfs \
206 --part-version OpenWrt \
207 --rootfs-version
$(SERCOMM_VERSION
)
210 mkdir
-p
$@
-rootfs_lib
211 echo
$(SERCOMM_VERSION
) > $@
-rootfs_lib
/lib_ver
212 $(call Build
/cfe-jffs2
,$@
-rootfs_lib
)
213 $(call Build
/pad-to
,$(BLOCKSIZE
))
214 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
216 --output-file
$@.rootfs_lib \
217 --part-name rootfs_lib \
218 --part-version
$(SERCOMM_VERSION
)
221 mkdir
-p
$@
-bootloader
222 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-bootloader
/$(CFE_RAM_JFFS2_NAME
)
223 $(call Build
/cfe-jffs2
,$@
-bootloader
)
224 $(call Build
/pad-to
,$(BLOCKSIZE
))
225 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
227 --output-file
$@.bootloader \
228 --part-name bootloader \
229 --part-version
$(SERCOMM_VERSION
)
231 mv
$@.kernel_rootfs
$@
232 dd if
=$@.rootfs_lib
>> $@
233 dd if
=$@.bootloader
>> $@
236 define Build
/cfe-sercomm-load
237 $(TOPDIR
)/scripts
/sercomm-payload.py \
239 --output-file
$@.new \
240 --pid
"$(SERCOMM_PID)"
245 define Build
/cfe-sercomm-crypto
246 $(TOPDIR
)/scripts
/sercomm-crypto.py \
249 --output-file
$@.ser \
251 $(STAGING_DIR_HOST
)/bin
/openssl enc
-md md5
-aes-256-cbc \
254 -iv
00000000000000000000000000000000
255 dd if
=$@.enc
>> $@.ser
260 define Build
/cfe-old-bin
261 $(TOPDIR
)/scripts
/brcmImage.pl
-t
-p \
262 -o
$@
-b
$(CFE_BOARD_ID
) -c
$(CHIP_ID
) \
263 -e
$(LOADER_ENTRY
) -a
$(LOADER_ENTRY
) \
264 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) \
268 define Build
/cfe-spw303v-bin
269 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
270 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
271 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
272 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
276 define Build
/cfe-wfi-tag
277 $(TOPDIR
)/scripts
/cfe-wfi-tag.py \
279 --output-file
$@.new \
280 --version
$(if
$(1),$(1),$(CFE_WFI_VERSION
)) \
281 --chip-id
$(CFE_WFI_CHIP_ID
) \
282 --flash-type
$(CFE_WFI_FLASH_TYPE
) \
283 $(if
$(CFE_WFI_FLAGS
),--flags
$(CFE_WFI_FLAGS
))
287 define Build
/spw303v-bin
288 $(STAGING_DIR_HOST
)/bin
/spw303v
-i
$@
-o
$@.spw303v
292 define Build
/zyxel-bin
293 $(STAGING_DIR_HOST
)/bin
/zyxbcm
-i
$@
-o
$@.zyxel
297 define Build
/redboot-bin
298 # Prepare kernel and rootfs
299 dd if
=$(IMAGE_KERNEL
) of
=$(BIN_DIR
)/$(REDBOOT_PREFIX
)-vmlinux.gz bs
=65536 conv
=sync
300 dd if
=$(IMAGE_ROOTFS
) of
=$(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
)) bs
=64k conv
=sync
301 echo
-ne
\\xDE
\\xAD
\\xC0
\\xDE
>> $(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
))
302 # Generate the scripted image
303 $(TOPDIR
)/scripts
/redboot-script.pl \
304 -k
$(BIN_DIR
)/$(REDBOOT_PREFIX
)-vmlinux.gz \
305 -r
$(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
)) \
306 -a
$(strip $(LOADER_ENTRY
)) -f
0xbe430000 -l
0x7c0000 \
307 -s
0x1000 -t
20 -o
$@.redbootscript
308 dd if
="$@.redbootscript" of
="$@.redbootscript.padded" bs
=4096 conv
=sync
310 "$@.redbootscript.padded" \
311 "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
312 "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
316 define Device
/Default
317 PROFILES
= Default
$$(DEVICE_NAME
)
318 KERNEL_DEPENDS
= $$(wildcard ..
/dts
/$$(DEVICE_DTS
).dts
)
319 KERNEL_INITRAMFS_SUFFIX
:= .elf
320 DEVICE_DTS_DIR
:= ..
/dts
323 DEVICE_DTS
= $$(SOC
)-$(subst _
,-,$(1))
325 DEVICE_VARS
+= CHIP_ID
327 ATH5K_PACKAGES
:= kmod-ath5k wpad-basic
328 ATH9K_PACKAGES
:= kmod-ath9k wpad-basic
329 B43_PACKAGES
:= kmod-b43 wpad-basic
330 BRCMWL_PACKAGES
:= kmod-brcm-wl nas wlc
331 RT28_PACKAGES
:= kmod-rt2800-pci wpad-basic
332 RT61_PACKAGES
:= kmod-rt61-pci wpad-basic
333 USB1_PACKAGES
:= kmod-usb-ohci kmod-usb-ledtrig-usbport
334 USB2_PACKAGES
:= kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
338 ifeq ($(SUBTARGET
),smp
)
339 include bcm63xx_nand.mk
342 $(eval
$(call BuildImage
))