1 # SPDX-License-Identifier: GPL-2.0-or-later
3 include $(TOPDIR
)/rules.mk
4 include $(INCLUDE_DIR
)/image.mk
6 KERNEL_LOADADDR
:= 0x80010000 # RAM start + 64K
7 LOADER_ENTRY
:= 0x80a00000 # RAM start + 10M, for relocate
8 LZMA_TEXT_START
:= 0x81800000 # RAM start + 24M
10 DEVICE_VARS
+= CFE_BOARD_ID CFE_EXTRAS
11 DEVICE_VARS
+= CFE_PART_FLAGS CFE_PART_ID
12 DEVICE_VARS
+= CFE_RAM_FILE
13 DEVICE_VARS
+= CFE_RAM_JFFS2_NAME CFE_RAM_JFFS2_PAD
14 DEVICE_VARS
+= CFE_WFI_CHIP_ID CFE_WFI_FLASH_TYPE
15 DEVICE_VARS
+= CFE_WFI_FLAGS CFE_WFI_VERSION
16 DEVICE_VARS
+= CHIP_ID DEVICE_LOADADDR
17 DEVICE_VARS
+= FLASH_MB IMAGE_OFFSET
18 DEVICE_VARS
+= SERCOMM_FSVER SERCOMM_HWVER SERCOMM_SWVER
21 rm -rf
$(KDIR
)/relocate
22 $(CP
) ..
/..
/generic
/image
/relocate
$(KDIR
)
23 $(MAKE
) -C
$(KDIR
)/relocate \
25 CROSS_COMPILE
=$(TARGET_CROSS
) \
26 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
27 LZMA_TEXT_START
=$(LOADER_ENTRY
)
30 ### Kernel scripts ###
31 define Build
/loader-lzma
33 $(MAKE
) -C lzma-loader \
35 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
37 LOADER_ADDR
=$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
39 LOADER_NAME
="$(notdir $@)" \
40 LZMA_TEXT_START
=$(LZMA_TEXT_START
) \
41 PKG_BUILD_DIR
="$@.src" \
42 TARGET_DIR
="$(dir $@)" \
49 # CFE is a LZMA nazi! It took me hours to find out the parameters!
50 # Also I think lzma has a bug cause it generates different output depending on
51 # if you use stdin / stdout or not. Use files instead of stdio here, cause
52 # otherwise CFE will complain and not boot the image.
53 $(call Build
/lzma-no-dict
,-d22
-fb64
-a1
)
54 # Strip out the length, CFE doesn't like this
55 dd if
=$@ of
=$@.new bs
=5 count
=1
56 dd if
=$@ of
=$@.new ibs
=13 obs
=5 skip
=1 seek
=1 conv
=notrunc
60 define Build
/relocate-kernel
61 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
62 # kernel might get larger than that, so let CFE unpack and load at a
63 # higher address and make the kernel relocate itself to the expected
66 dd if
=$(KDIR
)/relocate
/loader.bin bs
=32 conv
=sync
&& \
67 perl
-e
'@s = stat("$@"); print pack("N", @s[7])' && \
74 define rootfspad
/jffs2-128k
77 define rootfspad
/jffs2-64k
80 define rootfspad
/squashfs
83 define Image
/FileSystemStrip
84 $(firstword $(subst +,$(space
),$(subst root.
,,$(notdir $(1)))))
88 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
89 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
90 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
91 --info1
"$(call ModelNameLimit16,$(DEVICE_NAME))" \
92 --info2
"$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
93 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
97 define Build
/cfe-jffs2
98 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2 \
102 --eraseblock
=$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
105 --compression-mode
=none
107 $(call Build
/pad-to
,$(BLOCKSIZE
))
110 define Build
/cfe-jffs2-cferam
116 # CFE ROM checks JFFS2 dirent version of cferam.
117 # If version is not > 0 it will ignore the fs entry.
118 # JFFS2 sets version 0 to the first fs entry and increments
119 # it on the following ones, so let's create a dummy file that
120 # will have version 0 and let cferam be the second (version 1).
121 touch
$@
-cferam
/1-openwrt
122 # Add cferam as the last file in the JFFS2 partition
123 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-cferam
/$(CFE_RAM_JFFS2_NAME
)
125 # The JFFS2 partition creation should result in the following
127 # 1) 1-openwrt (version 0, ino 2)
128 # 2) cferam.000 (version 1, ino 3)
129 $(call Build
/cfe-jffs2
,$@
-cferam
)
131 # Some devices need padding between CFE RAM and kernel
132 $(if
$(CFE_RAM_JFFS2_PAD
),$(call Build
/pad-to
,$(CFE_RAM_JFFS2_PAD
)))
134 # Add CFE partition tag
135 $(if
$(CFE_PART_ID
),$(call Build
/cfe-part-tag
))
138 dd if
=$@.kernel
>> $@
142 define Build
/cfe-jffs2-kernel
146 # CFE RAM checks JFFS2 dirent version of vmlinux.
147 # If version is not > 0 it will ignore the fs entry.
148 # JFFS2 sets version 0 to the first fs entry and increments
149 # it on the following ones, so let's create a dummy file that
150 # will have version 0 and let cferam be the second (version 1).
151 touch
$@
-kernel
/1-openwrt
152 # vmlinux is located on a different JFFS2 partition, but CFE RAM
153 # ignores it, so let's create another dummy file that will match
154 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
155 # CFE RAM won't be able to find vmlinux if cferam has the same
157 touch
$@
-kernel
/2-openwrt
158 # Add vmlinux as the last file in the JFFS2 partition
159 $(TOPDIR
)/scripts
/cfe-bin-header.py \
161 --output-file
$@
-kernel
/vmlinux.lz \
162 --load-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
163 --entry-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
))
165 # The JFFS2 partition creation should result in the following
167 # 1) 1-openwrt (version 0, ino 2)
168 # 2) 2-openwrt (version 1, ino 3)
169 # 3) vmlinux.lz (version 2, ino 4)
170 $(call Build
/cfe-jffs2
,$@
-kernel
)
173 define Build
/cfe-part-tag
176 $(TOPDIR
)/scripts
/cfe-partition-tag.py \
177 --input-file
$@.part \
179 --flags
$(CFE_PART_FLAGS
) \
180 --id
$(CFE_PART_ID
) \
181 --name
$(VERSION_CODE
) \
182 --version
$(DEVICE_NAME
)
184 $(call Build
/pad-to
,$(BLOCKSIZE
))
189 define Build
/cfe-sercomm-crypto
190 $(TOPDIR
)/scripts
/sercomm-crypto.py \
193 --output-file
$@.ser \
195 $(STAGING_DIR_HOST
)/bin
/openssl enc
-md md5
-aes-256-cbc \
198 -iv
00000000000000000000000000000000
199 dd if
=$@.enc
>> $@.ser
204 define Build
/cfe-sercomm-load
205 $(TOPDIR
)/scripts
/sercomm-pid.py \
206 --hw-version
$(SERCOMM_HWVER
) \
207 --sw-version
$(SERCOMM_SWVER
) \
208 --extra-padding-size
0x10 \
210 $(TOPDIR
)/scripts
/sercomm-payload.py \
212 --output-file
$@.new \
219 define Build
/cfe-sercomm-part
220 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
222 --output-file
$@.kernel_rootfs \
223 --part-name kernel_rootfs \
224 --part-version OpenWrt \
225 --rootfs-version
$(SERCOMM_FSVER
)
228 mkdir
-p
$@
-rootfs_lib
229 echo
$(SERCOMM_FSVER
) > $@
-rootfs_lib
/lib_ver
230 $(call Build
/cfe-jffs2
,$@
-rootfs_lib
)
231 $(call Build
/pad-to
,$(BLOCKSIZE
))
232 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
234 --output-file
$@.rootfs_lib \
235 --part-name rootfs_lib \
236 --part-version
$(SERCOMM_FSVER
)
238 mv
$@.kernel_rootfs
$@
239 dd if
=$@.rootfs_lib
>> $@
242 define Build
/cfe-wfi-tag
243 $(TOPDIR
)/scripts
/cfe-wfi-tag.py \
245 --output-file
$@.new \
246 --version
$(if
$(1),$(1),$(CFE_WFI_VERSION
)) \
247 --chip-id
$(CFE_WFI_CHIP_ID
) \
248 --flash-type
$(CFE_WFI_FLASH_TYPE
) \
249 $(if
$(CFE_WFI_FLAGS
),--flags
$(CFE_WFI_FLAGS
))
253 ### Device scripts ###
254 define Device
/Default
255 PROFILES
= Default
$$(DEVICE_NAME
)
256 KERNEL_DEPENDS
= $$(wildcard ..
/dts
/$$(DEVICE_DTS
).dts
)
257 DEVICE_DTS_DIR
:= ..
/dts
260 DEVICE_DTS
= $$(SOC
)-$(subst _
,-,$(1))
264 define Device
/bcm63xx-cfe
265 FILESYSTEMS
:= squashfs jffs2-64k jffs2-128k
266 KERNEL
:= kernel-bin | append-dtb | relocate-kernel | lzma
267 KERNEL_INITRAMFS
:= kernel-bin | append-dtb | lzma | loader-lzma elf
268 KERNEL_INITRAMFS_SUFFIX
:= .elf
269 IMAGES
:= cfe.bin sysupgrade.bin
271 cfe-bin
$$$$(if
$$$$(FLASH_MB
),--pad
$$$$(shell expr
$$$$(FLASH_MB
) / 2))
272 IMAGE
/sysupgrade.bin
:= cfe-bin | append-metadata
277 CFE_EXTRAS
= --block-size
$$(BLOCKSIZE
) \
278 --image-offset
$$(if
$$(IMAGE_OFFSET
),$$(IMAGE_OFFSET
),$$(BLOCKSIZE
))
281 # Legacy CFEs with specific LZMA parameters and no length
282 define Device
/bcm63xx-cfe-legacy
283 $(Device
/bcm63xx-cfe
)
284 KERNEL
:= kernel-bin | append-dtb | relocate-kernel | lzma-cfe
287 # CFE expects a single JFFS2 partition with cferam and kernel. However,
288 # it's possible to fool CFE into properly loading both cferam and kernel
289 # from two different JFFS2 partitions by adding dummy files (see
290 # cfe-jffs2-cferam and cfe-jffs2-kernel).
291 # Separate JFFS2 partitions allow upgrading openwrt without reflashing cferam
292 # JFFS2 partition, which is much safer in case anything goes wrong.
293 define Device
/bcm63xx-nand
294 FILESYSTEMS
:= squashfs ubifs
295 KERNEL
:= kernel-bin | append-dtb | relocate-kernel | lzma | cfe-jffs2-kernel
296 KERNEL_INITRAMFS
:= kernel-bin | append-dtb | lzma | loader-lzma elf
297 KERNEL_INITRAMFS_SUFFIX
:= .elf
298 IMAGES
:= cfe.bin sysupgrade.bin
299 IMAGE
/cfe.bin
:= append-kernel | pad-to
$$$$(KERNEL_SIZE
) |\
300 cfe-jffs2-cferam | append-ubi | cfe-wfi-tag
301 IMAGE
/sysupgrade.bin
:= sysupgrade-tar | append-metadata
306 CFE_RAM_JFFS2_NAME
:=
309 CFE_WFI_CHIP_ID
= 0x
$$(CHIP_ID
)
310 CFE_WFI_FLASH_TYPE
:=
313 DEVICE_PACKAGES
+= nand-utils
316 define Device
/sercomm-nand
317 $(Device
/bcm63xx-nand
)
318 IMAGES
:= factory.img sysupgrade.bin
319 IMAGE
/factory.img
:= append-kernel | pad-to
$$$$(KERNEL_SIZE
) | append-ubi |\
320 cfe-sercomm-part | gzip | cfe-sercomm-load | cfe-sercomm-crypto
326 ### Package helpers ###
327 ATH9K_PACKAGES
:= kmod-ath9k kmod-owl-loader wpad-basic-mbedtls
328 B43_PACKAGES
:= kmod-b43 wpad-basic-mbedtls
329 USB1_PACKAGES
:= kmod-usb-ohci kmod-usb-ledtrig-usbport
330 USB2_PACKAGES
:= $(USB1_PACKAGES
) kmod-usb2
332 include $(SUBTARGET
).mk
334 $(eval
$(call BuildImage
))