1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2006-2015 OpenWrt.org
4 # Copyright (C) 2016 LEDE project
6 include $(TOPDIR
)/rules.mk
7 include $(INCLUDE_DIR
)/image.mk
9 KERNEL_LOADADDR
= 0x80010000 # RAM start + 64K
10 LOADER_ENTRY
= 0x80a00000 # RAM start + 10M, for relocate
11 LZMA_TEXT_START
= 0x81800000 # RAM start + 24M
15 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
16 CROSS_COMPILE
=$(TARGET_CROSS
) \
17 LZMA_TEXT_START
=$(LOADER_ENTRY
)
20 rm -rf
$(KDIR
)/relocate
21 $(CP
) ..
/..
/generic
/image
/relocate
$(KDIR
)
22 $(MAKE
) -C
$(KDIR
)/relocate
$(RELOCATE_MAKEOPTS
)
25 ### Kernel scripts ###
26 define Build
/hcs-initramfs
27 $(STAGING_DIR_HOST
)/bin
/hcsmakeimage
--magic_bytes
=$(HCS_MAGIC_BYTES
) \
28 --rev_maj
=$(HCS_REV_MAJ
) --rev_min
=$(HCS_REV_MIN
) --input_file
=$@ \
29 --output_file
=$@.hcs
--ldaddress
=$(KERNEL_LOADADDR
)
33 define Build
/loader-lzma
35 $(MAKE
) -C lzma-loader \
37 LOADER_ADDR
=$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
38 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
39 LZMA_TEXT_START
=$(LZMA_TEXT_START
) \
41 PKG_BUILD_DIR
="$@.src" \
42 TARGET_DIR
="$(dir $@)" \
44 LOADER_NAME
="$(notdir $@)" \
51 # CFE is a LZMA nazi! It took me hours to find out the parameters!
52 # Also I think lzma has a bug cause it generates different output depending on
53 # if you use stdin / stdout or not. Use files instead of stdio here, cause
54 # otherwise CFE will complain and not boot the image.
55 $(call Build
/lzma-no-dict
,-d22
-fb64
-a1
)
56 # Strip out the length, CFE doesn't like this
57 dd if
=$@ of
=$@.new bs
=5 count
=1
58 dd if
=$@ of
=$@.new ibs
=13 obs
=5 skip
=1 seek
=1 conv
=notrunc
62 define Build
/relocate-kernel
63 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
64 # kernel might get larger than that, so let CFE unpack and load at a
65 # higher address and make the kernel relocate itself to the expected
68 dd if
=$(KDIR
)/relocate
/loader.bin bs
=32 conv
=sync
&& \
69 perl
-e
'@s = stat("$@"); print pack("N", @s[7])' && \
76 define rootfspad
/jffs2-128k
79 define rootfspad
/jffs2-64k
82 define rootfspad
/squashfs
85 define Image
/FileSystemStrip
86 $(firstword $(subst +,$(space
),$(subst root.
,,$(notdir $(1)))))
90 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
91 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
92 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
93 --info1
"$(call ModelNameLimit16,$(DEVICE_NAME))" \
94 --info2
"$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
95 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
99 define Build
/cfe-jffs2
100 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2 \
104 --eraseblock
=$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
107 --compression-mode
=none
109 $(call Build
/pad-to
,$(BLOCKSIZE
))
112 define Build
/cfe-jffs2-cferam
118 # CFE ROM checks JFFS2 dirent version of cferam.
119 # If version is not > 0 it will ignore the fs entry.
120 # JFFS2 sets version 0 to the first fs entry and increments
121 # it on the following ones, so let's create a dummy file that
122 # will have version 0 and let cferam be the second (version 1).
123 touch
$@
-cferam
/1-openwrt
124 # Add cferam as the last file in the JFFS2 partition
125 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-cferam
/$(CFE_RAM_JFFS2_NAME
)
127 # The JFFS2 partition creation should result in the following
129 # 1) 1-openwrt (version 0, ino 2)
130 # 2) cferam.000 (version 1, ino 3)
131 $(call Build
/cfe-jffs2
,$@
-cferam
)
133 # Some devices need padding between CFE RAM and kernel
134 $(if
$(CFE_RAM_JFFS2_PAD
),$(call Build
/pad-to
,$(CFE_RAM_JFFS2_PAD
)))
136 # Add CFE partition tag
137 $(if
$(CFE_PART_ID
),$(call Build
/cfe-part-tag
))
140 dd if
=$@.kernel
>> $@
144 define Build
/cfe-jffs2-kernel
148 # CFE RAM checks JFFS2 dirent version of vmlinux.
149 # If version is not > 0 it will ignore the fs entry.
150 # JFFS2 sets version 0 to the first fs entry and increments
151 # it on the following ones, so let's create a dummy file that
152 # will have version 0 and let cferam be the second (version 1).
153 touch
$@
-kernel
/1-openwrt
154 # vmlinux is located on a different JFFS2 partition, but CFE RAM
155 # ignores it, so let's create another dummy file that will match
156 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
157 # CFE RAM won't be able to find vmlinux if cferam has the same
159 touch
$@
-kernel
/2-openwrt
160 # Add vmlinux as the last file in the JFFS2 partition
161 $(TOPDIR
)/scripts
/cfe-bin-header.py \
163 --output-file
$@
-kernel
/vmlinux.lz \
164 --load-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
165 --entry-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
))
167 # The JFFS2 partition creation should result in the following
169 # 1) 1-openwrt (version 0, ino 2)
170 # 2) 2-openwrt (version 1, ino 3)
171 # 3) vmlinux.lz (version 2, ino 4)
172 $(call Build
/cfe-jffs2
,$@
-kernel
)
175 define Build
/cfe-part-tag
178 $(TOPDIR
)/scripts
/cfe-partition-tag.py \
179 --input-file
$@.part \
181 --flags
$(CFE_PART_FLAGS
) \
182 --id
$(CFE_PART_ID
) \
183 --name
$(VERSION_CODE
) \
184 --version
$(DEVICE_NAME
)
186 $(call Build
/pad-to
,$(BLOCKSIZE
))
191 define Build
/cfe-sercomm-part
192 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
194 --output-file
$@.kernel_rootfs \
195 --part-name kernel_rootfs \
196 --part-version OpenWrt \
197 --rootfs-version
$(SERCOMM_VERSION
)
200 mkdir
-p
$@
-rootfs_lib
201 echo
$(SERCOMM_VERSION
) > $@
-rootfs_lib
/lib_ver
202 $(call Build
/cfe-jffs2
,$@
-rootfs_lib
)
203 $(call Build
/pad-to
,$(BLOCKSIZE
))
204 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
206 --output-file
$@.rootfs_lib \
207 --part-name rootfs_lib \
208 --part-version
$(SERCOMM_VERSION
)
210 mv
$@.kernel_rootfs
$@
211 dd if
=$@.rootfs_lib
>> $@
214 define Build
/cfe-sercomm-load
215 $(TOPDIR
)/scripts
/sercomm-payload.py \
217 --output-file
$@.new \
218 --pid
"$(SERCOMM_PID)"
223 define Build
/cfe-sercomm-crypto
224 $(TOPDIR
)/scripts
/sercomm-crypto.py \
227 --output-file
$@.ser \
229 $(STAGING_DIR_HOST
)/bin
/openssl enc
-md md5
-aes-256-cbc \
232 -iv
00000000000000000000000000000000
233 dd if
=$@.enc
>> $@.ser
238 define Build
/cfe-old-bin
239 $(TOPDIR
)/scripts
/brcmImage.pl
-t
-p \
240 -o
$@
-b
$(CFE_BOARD_ID
) -c
$(CHIP_ID
) \
241 -e
$(LOADER_ENTRY
) -a
$(LOADER_ENTRY
) \
242 -k
$(IMAGE_KERNEL
) -r
$(IMAGE_ROOTFS
) \
246 define Build
/cfe-spw303v-bin
247 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
248 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
249 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
250 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
254 define Build
/cfe-wfi-tag
255 $(TOPDIR
)/scripts
/cfe-wfi-tag.py \
257 --output-file
$@.new \
258 --version
$(if
$(1),$(1),$(CFE_WFI_VERSION
)) \
259 --chip-id
$(CFE_WFI_CHIP_ID
) \
260 --flash-type
$(CFE_WFI_FLASH_TYPE
) \
261 $(if
$(CFE_WFI_FLAGS
),--flags
$(CFE_WFI_FLAGS
))
265 define Build
/spw303v-bin
266 $(STAGING_DIR_HOST
)/bin
/spw303v
-i
$@
-o
$@.spw303v
270 define Build
/zyxel-bin
271 $(STAGING_DIR_HOST
)/bin
/zyxbcm
-i
$@
-o
$@.zyxel
275 define Build
/redboot-bin
276 # Prepare kernel and rootfs
277 dd if
=$(IMAGE_KERNEL
) of
=$(BIN_DIR
)/$(REDBOOT_PREFIX
)-vmlinux.gz bs
=65536 conv
=sync
278 dd if
=$(IMAGE_ROOTFS
) of
=$(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
)) bs
=64k conv
=sync
279 echo
-ne
\\xDE
\\xAD
\\xC0
\\xDE
>> $(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
))
280 # Generate the scripted image
281 $(TOPDIR
)/scripts
/redboot-script.pl \
282 -k
$(BIN_DIR
)/$(REDBOOT_PREFIX
)-vmlinux.gz \
283 -r
$(BIN_DIR
)/$(REDBOOT_PREFIX
)-$(notdir $(IMAGE_ROOTFS
)) \
284 -a
$(strip $(LOADER_ENTRY
)) -f
0xbe430000 -l
0x7c0000 \
285 -s
0x1000 -t
20 -o
$@.redbootscript
286 dd if
="$@.redbootscript" of
="$@.redbootscript.padded" bs
=4096 conv
=sync
288 "$@.redbootscript.padded" \
289 "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
290 "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
294 define Device
/Default
295 PROFILES
= Default
$$(DEVICE_NAME
)
296 KERNEL_DEPENDS
= $$(wildcard ..
/dts
/$$(DEVICE_DTS
).dts
)
297 KERNEL_INITRAMFS_SUFFIX
:= .elf
298 DEVICE_DTS_DIR
:= ..
/dts
301 DEVICE_DTS
= $$(SOC
)-$(subst _
,-,$(1))
304 DEVICE_VARS
+= CHIP_ID DEVICE_LOADADDR
306 ATH5K_PACKAGES
:= kmod-ath5k wpad-basic-mbedtls
307 ATH9K_PACKAGES
:= kmod-ath9k wpad-basic-mbedtls
308 B43_PACKAGES
:= kmod-b43 wpad-basic-mbedtls
309 BRCMWL_PACKAGES
:= kmod-brcm-wl nas wlc
310 RT28_PACKAGES
:= kmod-rt2800-pci wpad-basic-mbedtls
311 RT61_PACKAGES
:= kmod-rt61-pci wpad-basic-mbedtls
312 USB1_PACKAGES
:= kmod-usb-ohci kmod-usb-ledtrig-usbport
313 USB2_PACKAGES
:= kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
317 ifeq ($(SUBTARGET
),smp
)
318 include bcm63xx_nand.mk
321 $(eval
$(call BuildImage
))