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 RAMSIZE
:= 0x02000000 # 32MB
9 LZMA_TEXT_START
:= 0x81800000 # 32MB - 8MB
11 DEVICE_VARS
+= CHIP_ID DEVICE_LOADADDR
14 rm -rf
$(KDIR
)/relocate
15 $(CP
) ..
/..
/generic
/image
/relocate
$(KDIR
)
16 $(MAKE
) -C
$(KDIR
)/relocate \
18 CROSS_COMPILE
=$(TARGET_CROSS
) \
19 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
20 LZMA_TEXT_START
=$(LOADER_ENTRY
)
23 ### Kernel scripts ###
24 define Build
/loader-lzma
26 $(MAKE
) -C lzma-loader \
28 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
30 LOADER_ADDR
=$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
32 LOADER_NAME
="$(notdir $@)" \
33 LZMA_TEXT_START
=$(LZMA_TEXT_START
) \
34 PKG_BUILD_DIR
="$@.src" \
36 TARGET_DIR
="$(dir $@)" \
43 # CFE is a LZMA nazi! It took me hours to find out the parameters!
44 # Also I think lzma has a bug cause it generates different output depending on
45 # if you use stdin / stdout or not. Use files instead of stdio here, cause
46 # otherwise CFE will complain and not boot the image.
47 $(call Build
/lzma-no-dict
,-d22
-fb64
-a1
)
48 # Strip out the length, CFE doesn't like this
49 dd if
=$@ of
=$@.new bs
=5 count
=1
50 dd if
=$@ of
=$@.new ibs
=13 obs
=5 skip
=1 seek
=1 conv
=notrunc
54 define Build
/relocate-kernel
55 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
56 # kernel might get larger than that, so let CFE unpack and load at a
57 # higher address and make the kernel relocate itself to the expected
60 dd if
=$(KDIR
)/relocate
/loader.bin bs
=32 conv
=sync
&& \
61 perl
-e
'@s = stat("$@"); print pack("N", @s[7])' && \
68 define rootfspad
/jffs2-128k
71 define rootfspad
/jffs2-64k
74 define rootfspad
/squashfs
77 define Image
/FileSystemStrip
78 $(firstword $(subst +,$(space
),$(subst root.
,,$(notdir $(1)))))
82 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
83 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
84 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
85 --info1
"$(call ModelNameLimit16,$(DEVICE_NAME))" \
86 --info2
"$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
87 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
91 define Build
/cfe-jffs2
92 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2 \
96 --eraseblock
=$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
99 --compression-mode
=none
101 $(call Build
/pad-to
,$(BLOCKSIZE
))
104 define Build
/cfe-jffs2-cferam
110 # CFE ROM checks JFFS2 dirent version of cferam.
111 # If version is not > 0 it will ignore the fs entry.
112 # JFFS2 sets version 0 to the first fs entry and increments
113 # it on the following ones, so let's create a dummy file that
114 # will have version 0 and let cferam be the second (version 1).
115 touch
$@
-cferam
/1-openwrt
116 # Add cferam as the last file in the JFFS2 partition
117 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-cferam
/$(CFE_RAM_JFFS2_NAME
)
119 # The JFFS2 partition creation should result in the following
121 # 1) 1-openwrt (version 0, ino 2)
122 # 2) cferam.000 (version 1, ino 3)
123 $(call Build
/cfe-jffs2
,$@
-cferam
)
125 # Some devices need padding between CFE RAM and kernel
126 $(if
$(CFE_RAM_JFFS2_PAD
),$(call Build
/pad-to
,$(CFE_RAM_JFFS2_PAD
)))
128 # Add CFE partition tag
129 $(if
$(CFE_PART_ID
),$(call Build
/cfe-part-tag
))
132 dd if
=$@.kernel
>> $@
136 define Build
/cfe-jffs2-kernel
140 # CFE RAM checks JFFS2 dirent version of vmlinux.
141 # If version is not > 0 it will ignore the fs entry.
142 # JFFS2 sets version 0 to the first fs entry and increments
143 # it on the following ones, so let's create a dummy file that
144 # will have version 0 and let cferam be the second (version 1).
145 touch
$@
-kernel
/1-openwrt
146 # vmlinux is located on a different JFFS2 partition, but CFE RAM
147 # ignores it, so let's create another dummy file that will match
148 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
149 # CFE RAM won't be able to find vmlinux if cferam has the same
151 touch
$@
-kernel
/2-openwrt
152 # Add vmlinux as the last file in the JFFS2 partition
153 $(TOPDIR
)/scripts
/cfe-bin-header.py \
155 --output-file
$@
-kernel
/vmlinux.lz \
156 --load-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
157 --entry-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
))
159 # The JFFS2 partition creation should result in the following
161 # 1) 1-openwrt (version 0, ino 2)
162 # 2) 2-openwrt (version 1, ino 3)
163 # 3) vmlinux.lz (version 2, ino 4)
164 $(call Build
/cfe-jffs2
,$@
-kernel
)
167 define Build
/cfe-part-tag
170 $(TOPDIR
)/scripts
/cfe-partition-tag.py \
171 --input-file
$@.part \
173 --flags
$(CFE_PART_FLAGS
) \
174 --id
$(CFE_PART_ID
) \
175 --name
$(VERSION_CODE
) \
176 --version
$(DEVICE_NAME
)
178 $(call Build
/pad-to
,$(BLOCKSIZE
))
183 define Build
/cfe-sercomm-crypto
184 $(TOPDIR
)/scripts
/sercomm-crypto.py \
187 --output-file
$@.ser \
189 $(STAGING_DIR_HOST
)/bin
/openssl enc
-md md5
-aes-256-cbc \
192 -iv
00000000000000000000000000000000
193 dd if
=$@.enc
>> $@.ser
198 define Build
/cfe-sercomm-load
199 $(TOPDIR
)/scripts
/sercomm-payload.py \
201 --output-file
$@.new \
202 --pid
"$(SERCOMM_PID)"
207 define Build
/cfe-sercomm-part
208 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
210 --output-file
$@.kernel_rootfs \
211 --part-name kernel_rootfs \
212 --part-version OpenWrt \
213 --rootfs-version
$(SERCOMM_VERSION
)
216 mkdir
-p
$@
-rootfs_lib
217 echo
$(SERCOMM_VERSION
) > $@
-rootfs_lib
/lib_ver
218 $(call Build
/cfe-jffs2
,$@
-rootfs_lib
)
219 $(call Build
/pad-to
,$(BLOCKSIZE
))
220 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
222 --output-file
$@.rootfs_lib \
223 --part-name rootfs_lib \
224 --part-version
$(SERCOMM_VERSION
)
226 mv
$@.kernel_rootfs
$@
227 dd if
=$@.rootfs_lib
>> $@
230 define Build
/cfe-wfi-tag
231 $(TOPDIR
)/scripts
/cfe-wfi-tag.py \
233 --output-file
$@.new \
234 --version
$(if
$(1),$(1),$(CFE_WFI_VERSION
)) \
235 --chip-id
$(CFE_WFI_CHIP_ID
) \
236 --flash-type
$(CFE_WFI_FLASH_TYPE
) \
237 $(if
$(CFE_WFI_FLAGS
),--flags
$(CFE_WFI_FLAGS
))
241 ### Device scripts ###
242 define Device
/Default
243 PROFILES
= Default
$$(DEVICE_NAME
)
244 KERNEL_DEPENDS
= $$(wildcard ..
/dts
/$$(DEVICE_DTS
).dts
)
245 DEVICE_DTS_DIR
:= ..
/dts
248 DEVICE_DTS
= $$(SOC
)-$(subst _
,-,$(1))
252 ATH9K_PACKAGES
:= kmod-ath9k wpad-basic-wolfssl
253 B43_PACKAGES
:= kmod-b43 wpad-basic-wolfssl
254 USB1_PACKAGES
:= kmod-usb-ohci kmod-ledtrig-usbdev
255 USB2_PACKAGES
:= $(USB1_PACKAGES
) kmod-usb2
257 include bcm63xx_
$(SUBTARGET
).mk
259 $(eval
$(call BuildImage
))