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
)
24 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
25 CROSS_COMPILE
=$(TARGET_CROSS
) \
26 LZMA_TEXT_START
=$(LOADER_ENTRY
)
29 rm -rf
$(KDIR
)/relocate
30 $(CP
) ..
/..
/generic
/image
/relocate
$(KDIR
)
31 $(MAKE
) -C
$(KDIR
)/relocate
$(RELOCATE_MAKEOPTS
)
34 ### Kernel scripts ###
35 define Build
/hcs-initramfs
36 $(STAGING_DIR_HOST
)/bin
/hcsmakeimage
--magic_bytes
=$(HCS_MAGIC_BYTES
) \
37 --rev_maj
=$(HCS_REV_MAJ
) --rev_min
=$(HCS_REV_MIN
) --input_file
=$@ \
38 --output_file
=$@.hcs
--ldaddress
=$(KERNEL_LOADADDR
)
42 define Build
/loader-lzma
44 $(MAKE
) -C lzma-loader \
46 PKG_BUILD_DIR
="$@.src" \
47 TARGET_DIR
="$(dir $@)" \
49 LOADER_NAME
="$(notdir $@)" \
56 # CFE is a LZMA nazi! It took me hours to find out the parameters!
57 # Also I think lzma has a bug cause it generates different output depending on
58 # if you use stdin / stdout or not. Use files instead of stdio here, cause
59 # otherwise CFE will complain and not boot the image.
60 $(call Build
/lzma-no-dict
,-d22
-fb64
-a1
)
61 # Strip out the length, CFE doesn't like this
62 dd if
=$@ of
=$@.new bs
=5 count
=1
63 dd if
=$@ of
=$@.new ibs
=13 obs
=5 skip
=1 seek
=1 conv
=notrunc
67 define Build
/relocate-kernel
68 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
69 # kernel might get larger than that, so let CFE unpack and load at a
70 # higher address and make the kernel relocate itself to the expected
73 dd if
=$(KDIR
)/relocate
/loader.bin bs
=32 conv
=sync
&& \
74 perl
-e
'@s = stat("$@"); print pack("N", @s[7])' && \
81 define rootfspad
/jffs2-128k
84 define rootfspad
/jffs2-64k
87 define rootfspad
/squashfs
90 define Image
/LimitName16
91 $(shell expr substr
"$(1)" 1 16)
94 define Image
/FileSystemStrip
95 $(firstword $(subst +,$(space
),$(subst root.
,,$(notdir $(1)))))
99 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
100 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CFE_CHIP_ID
) \
101 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
102 --info1
"$(call Image/LimitName16,$(DEVICE_NAME))" \
103 --info2
"$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
104 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
108 define Build
/cfe-jffs2
109 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2 \
113 --eraseblock
=$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
116 --compression-mode
=none
118 $(call Build
/pad-to
,$(BLOCKSIZE
))
121 define Build
/cfe-jffs2-cferam
127 # CFE ROM checks JFFS2 dirent version of cferam.
128 # If version is not > 0 it will ignore the fs entry.
129 # JFFS2 sets version 0 to the first fs entry and increments
130 # it on the following ones, so let's create a dummy file that
131 # will have version 0 and let cferam be the second (version 1).
132 touch
$@
-cferam
/1-openwrt
133 # Add cferam as the last file in the JFFS2 partition
134 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-cferam
/$(CFE_RAM_JFFS2_NAME
)
136 # The JFFS2 partition creation should result in the following
138 # 1) 1-openwrt (version 0, ino 2)
139 # 2) cferam.000 (version 1, ino 3)
140 $(call Build
/cfe-jffs2
,$@
-cferam
)
142 # Some devices need padding between CFE RAM and kernel
143 $(if
$(CFE_RAM_JFFS2_PAD
),$(call Build
/pad-to
,$(CFE_RAM_JFFS2_PAD
)))
146 dd if
=$@.kernel
>> $@
150 define Build
/cfe-jffs2-kernel
154 # CFE RAM checks JFFS2 dirent version of vmlinux.
155 # If version is not > 0 it will ignore the fs entry.
156 # JFFS2 sets version 0 to the first fs entry and increments
157 # it on the following ones, so let's create a dummy file that
158 # will have version 0 and let cferam be the second (version 1).
159 touch
$@
-kernel
/1-openwrt
160 # vmlinux is located on a different JFFS2 partition, but CFE RAM
161 # ignores it, so let's create another dummy file that will match
162 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
163 # CFE RAM won't be able to find vmlinux if cferam has the same
165 touch
$@
-kernel
/2-openwrt
166 # Add vmlinux as the last file in the JFFS2 partition
167 $(TOPDIR
)/scripts
/cfe-bin-header.py \
169 --output-file
$@
-kernel
/vmlinux.lz \
170 --load-addr
$(LOADER_ENTRY
) \
171 --entry-addr
$(LOADER_ENTRY
)
173 # The JFFS2 partition creation should result in the following
175 # 1) 1-openwrt (version 0, ino 2)
176 # 2) 2-openwrt (version 1, ino 3)
177 # 3) vmlinux.lz (version 2, ino 4)
178 $(call Build
/cfe-jffs2
,$@
-kernel
)
181 define Build
/cfe-old-bin
182 $(TOPDIR
)/scripts
/brcmImage.pl
-t
-p \
183 -o
$@
-b
$(CFE_BOARD_ID
) -c
$(CFE_CHIP_ID
) \
184 -e
$(LOADER_ENTRY
) -a
$(LOADER_ENTRY
) \
185 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) \
189 define Build
/cfe-spw303v-bin
190 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
191 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CFE_CHIP_ID
) \
192 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
193 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
197 define Build
/cfe-wfi-tag
198 $(TOPDIR
)/scripts
/cfe-wfi-tag.py \
200 --output-file
$@.new \
201 --version
$(if
$(1),$(1),$(CFE_WFI_VERSION
)) \
202 --chip-id
$(CFE_WFI_CHIP_ID
) \
203 --flash-type
$(CFE_WFI_FLASH_TYPE
) \
204 $(if
$(CFE_WFI_FLAGS
),--flags
$(CFE_WFI_FLAGS
))
208 define Build
/spw303v-bin
209 $(STAGING_DIR_HOST
)/bin
/spw303v
-i
$@
-o
$@.spw303v
213 define Build
/zyxel-bin
214 $(STAGING_DIR_HOST
)/bin
/zyxbcm
-i
$@
-o
$@.zyxel
218 define Build
/redboot-bin
219 # Prepare kernel and rootfs
220 dd if
=$(IMAGE_KERNEL
) of
=$(BIN_DIR
)/$(REDBOOT_PREFIX
)-vmlinux.gz bs
=65536 conv
=sync
221 dd if
=$(IMAGE_ROOTFS
) of
=$(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
)) bs
=64k conv
=sync
222 echo
-ne
\\xDE
\\xAD
\\xC0
\\xDE
>> $(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
))
223 # Generate the scripted image
224 $(TOPDIR
)/scripts
/redboot-script.pl \
225 -k
$(BIN_DIR
)/$(REDBOOT_PREFIX
)-vmlinux.gz \
226 -r
$(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
)) \
227 -a
$(strip $(LOADER_ENTRY
)) -f
0xbe430000 -l
0x7c0000 \
228 -s
0x1000 -t
20 -o
$@.redbootscript
229 dd if
="$@.redbootscript" of
="$@.redbootscript.padded" bs
=4096 conv
=sync
231 "$@.redbootscript.padded" \
232 "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
233 "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
237 define Device
/Default
238 PROFILES
= Default
$$(DEVICE_NAME
)
239 KERNEL_DEPENDS
= $$(wildcard ..
/dts
/$$(DEVICE_DTS
).dts
)
240 KERNEL_INITRAMFS_SUFFIX
:= .elf
241 DEVICE_DTS_DIR
:= ..
/dts
242 SOC
= bcm
$$(CFE_CHIP_ID
)
243 DEVICE_DTS
= $$(SOC
)-$(subst _
,-,$(1))
246 ATH5K_PACKAGES
:= kmod-ath5k wpad-basic
247 ATH9K_PACKAGES
:= kmod-ath9k wpad-basic
248 B43_PACKAGES
:= kmod-b43 wpad-basic
249 BRCMWL_PACKAGES
:= kmod-brcm-wl nas wlc
250 RT28_PACKAGES
:= kmod-rt2800-pci wpad-basic
251 RT61_PACKAGES
:= kmod-rt61-pci wpad-basic
252 USB1_PACKAGES
:= kmod-usb-ohci kmod-usb-ledtrig-usbport
253 USB2_PACKAGES
:= kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
257 ifeq ($(SUBTARGET
),smp
)
258 include bcm63xx_nand.mk
261 $(eval
$(call BuildImage
))