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
+= CHIP_ID DEVICE_LOADADDR
13 rm -rf
$(KDIR
)/relocate
14 $(CP
) ..
/..
/generic
/image
/relocate
$(KDIR
)
15 $(MAKE
) -C
$(KDIR
)/relocate \
17 CROSS_COMPILE
=$(TARGET_CROSS
) \
18 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
19 LZMA_TEXT_START
=$(LOADER_ENTRY
)
22 ### Kernel scripts ###
23 define Build
/loader-lzma
25 $(MAKE
) -C lzma-loader \
27 KERNEL_ADDR
=$(KERNEL_LOADADDR
) \
29 LOADER_ADDR
=$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
31 LOADER_NAME
="$(notdir $@)" \
32 LZMA_TEXT_START
=$(LZMA_TEXT_START
) \
33 PKG_BUILD_DIR
="$@.src" \
34 TARGET_DIR
="$(dir $@)" \
41 # CFE is a LZMA nazi! It took me hours to find out the parameters!
42 # Also I think lzma has a bug cause it generates different output depending on
43 # if you use stdin / stdout or not. Use files instead of stdio here, cause
44 # otherwise CFE will complain and not boot the image.
45 $(call Build
/lzma-no-dict
,-d22
-fb64
-a1
)
46 # Strip out the length, CFE doesn't like this
47 dd if
=$@ of
=$@.new bs
=5 count
=1
48 dd if
=$@ of
=$@.new ibs
=13 obs
=5 skip
=1 seek
=1 conv
=notrunc
52 define Build
/relocate-kernel
53 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
54 # kernel might get larger than that, so let CFE unpack and load at a
55 # higher address and make the kernel relocate itself to the expected
58 dd if
=$(KDIR
)/relocate
/loader.bin bs
=32 conv
=sync
&& \
59 perl
-e
'@s = stat("$@"); print pack("N", @s[7])' && \
66 define rootfspad
/jffs2-128k
69 define rootfspad
/jffs2-64k
72 define rootfspad
/squashfs
75 define Image
/FileSystemStrip
76 $(firstword $(subst +,$(space
),$(subst root.
,,$(notdir $(1)))))
80 $(STAGING_DIR_HOST
)/bin
/imagetag
-i
$(IMAGE_KERNEL
) -f
$(IMAGE_ROOTFS
) \
81 --output
$@
--boardid
$(CFE_BOARD_ID
) --chipid
$(CHIP_ID
) \
82 --entry
$(LOADER_ENTRY
) --load-addr
$(LOADER_ENTRY
) \
83 --info1
"$(call ModelNameLimit16,$(DEVICE_NAME))" \
84 --info2
"$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
85 $(call rootfspad
/$(call Image
/FileSystemStrip
,$(IMAGE_ROOTFS
))) \
89 define Build
/cfe-jffs2
90 $(STAGING_DIR_HOST
)/bin
/mkfs.jffs2 \
94 --eraseblock
=$(patsubst %k
,%KiB
,$(BLOCKSIZE
)) \
97 --compression-mode
=none
99 $(call Build
/pad-to
,$(BLOCKSIZE
))
102 define Build
/cfe-jffs2-cferam
108 # CFE ROM checks JFFS2 dirent version of cferam.
109 # If version is not > 0 it will ignore the fs entry.
110 # JFFS2 sets version 0 to the first fs entry and increments
111 # it on the following ones, so let's create a dummy file that
112 # will have version 0 and let cferam be the second (version 1).
113 touch
$@
-cferam
/1-openwrt
114 # Add cferam as the last file in the JFFS2 partition
115 cp
$(KDIR
)/bcm63xx-cfe
/$(CFE_RAM_FILE
) $@
-cferam
/$(CFE_RAM_JFFS2_NAME
)
117 # The JFFS2 partition creation should result in the following
119 # 1) 1-openwrt (version 0, ino 2)
120 # 2) cferam.000 (version 1, ino 3)
121 $(call Build
/cfe-jffs2
,$@
-cferam
)
123 # Some devices need padding between CFE RAM and kernel
124 $(if
$(CFE_RAM_JFFS2_PAD
),$(call Build
/pad-to
,$(CFE_RAM_JFFS2_PAD
)))
126 # Add CFE partition tag
127 $(if
$(CFE_PART_ID
),$(call Build
/cfe-part-tag
))
130 dd if
=$@.kernel
>> $@
134 define Build
/cfe-jffs2-kernel
138 # CFE RAM checks JFFS2 dirent version of vmlinux.
139 # If version is not > 0 it will ignore the fs entry.
140 # JFFS2 sets version 0 to the first fs entry and increments
141 # it on the following ones, so let's create a dummy file that
142 # will have version 0 and let cferam be the second (version 1).
143 touch
$@
-kernel
/1-openwrt
144 # vmlinux is located on a different JFFS2 partition, but CFE RAM
145 # ignores it, so let's create another dummy file that will match
146 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
147 # CFE RAM won't be able to find vmlinux if cferam has the same
149 touch
$@
-kernel
/2-openwrt
150 # Add vmlinux as the last file in the JFFS2 partition
151 $(TOPDIR
)/scripts
/cfe-bin-header.py \
153 --output-file
$@
-kernel
/vmlinux.lz \
154 --load-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
)) \
155 --entry-addr
$(if
$(DEVICE_LOADADDR
),$(DEVICE_LOADADDR
),$(LOADER_ENTRY
))
157 # The JFFS2 partition creation should result in the following
159 # 1) 1-openwrt (version 0, ino 2)
160 # 2) 2-openwrt (version 1, ino 3)
161 # 3) vmlinux.lz (version 2, ino 4)
162 $(call Build
/cfe-jffs2
,$@
-kernel
)
165 define Build
/cfe-part-tag
168 $(TOPDIR
)/scripts
/cfe-partition-tag.py \
169 --input-file
$@.part \
171 --flags
$(CFE_PART_FLAGS
) \
172 --id
$(CFE_PART_ID
) \
173 --name
$(VERSION_CODE
) \
174 --version
$(DEVICE_NAME
)
176 $(call Build
/pad-to
,$(BLOCKSIZE
))
181 define Build
/cfe-sercomm-crypto
182 $(TOPDIR
)/scripts
/sercomm-crypto.py \
185 --output-file
$@.ser \
187 $(STAGING_DIR_HOST
)/bin
/openssl enc
-md md5
-aes-256-cbc \
190 -iv
00000000000000000000000000000000
191 dd if
=$@.enc
>> $@.ser
196 define Build
/cfe-sercomm-load
197 $(TOPDIR
)/scripts
/sercomm-payload.py \
199 --output-file
$@.new \
200 --pid
"$(SERCOMM_PID)"
205 define Build
/cfe-sercomm-part
206 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
208 --output-file
$@.kernel_rootfs \
209 --part-name kernel_rootfs \
210 --part-version OpenWrt \
211 --rootfs-version
$(SERCOMM_FSVER
)
214 mkdir
-p
$@
-rootfs_lib
215 echo
$(SERCOMM_FSVER
) > $@
-rootfs_lib
/lib_ver
216 $(call Build
/cfe-jffs2
,$@
-rootfs_lib
)
217 $(call Build
/pad-to
,$(BLOCKSIZE
))
218 $(TOPDIR
)/scripts
/sercomm-partition-tag.py \
220 --output-file
$@.rootfs_lib \
221 --part-name rootfs_lib \
222 --part-version
$(SERCOMM_FSVER
)
224 mv
$@.kernel_rootfs
$@
225 dd if
=$@.rootfs_lib
>> $@
228 define Build
/cfe-wfi-tag
229 $(TOPDIR
)/scripts
/cfe-wfi-tag.py \
231 --output-file
$@.new \
232 --version
$(if
$(1),$(1),$(CFE_WFI_VERSION
)) \
233 --chip-id
$(CFE_WFI_CHIP_ID
) \
234 --flash-type
$(CFE_WFI_FLASH_TYPE
) \
235 $(if
$(CFE_WFI_FLAGS
),--flags
$(CFE_WFI_FLAGS
))
239 ### Device scripts ###
240 define Device
/Default
241 PROFILES
= Default
$$(DEVICE_NAME
)
242 KERNEL_DEPENDS
= $$(wildcard ..
/dts
/$$(DEVICE_DTS
).dts
)
243 DEVICE_DTS_DIR
:= ..
/dts
246 DEVICE_DTS
= $$(SOC
)-$(subst _
,-,$(1))
250 ATH9K_PACKAGES
:= kmod-ath9k wpad-basic-mbedtls
251 B43_PACKAGES
:= kmod-b43 wpad-basic-mbedtls
252 USB1_PACKAGES
:= kmod-usb-ohci kmod-ledtrig-usbdev
253 USB2_PACKAGES
:= $(USB1_PACKAGES
) kmod-usb2
255 include bcm63xx_
$(SUBTARGET
).mk
257 $(eval
$(call BuildImage
))