bmips: hg556a: switch to kmod-owl-loader
[openwrt/staging/hauke.git] / target / linux / bmips / image / Makefile
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 include $(TOPDIR)/rules.mk
4 include $(INCLUDE_DIR)/image.mk
5
6 KERNEL_LOADADDR := 0x80010000 # RAM start + 64K
7 LOADER_ENTRY := 0x80a00000 # RAM start + 10M, for relocate
8 LZMA_TEXT_START := 0x81800000 # RAM start + 24M
9
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
19
20 define Build/Compile
21 rm -rf $(KDIR)/relocate
22 $(CP) ../../generic/image/relocate $(KDIR)
23 $(MAKE) -C $(KDIR)/relocate \
24 CACHELINE_SIZE=16 \
25 CROSS_COMPILE=$(TARGET_CROSS) \
26 KERNEL_ADDR=$(KERNEL_LOADADDR) \
27 LZMA_TEXT_START=$(LOADER_ENTRY)
28 endef
29
30 ### Kernel scripts ###
31 define Build/loader-lzma
32 @rm -rf $@.src
33 $(MAKE) -C lzma-loader \
34 CHIP_ID=$(CHIP_ID) \
35 KERNEL_ADDR=$(KERNEL_LOADADDR) \
36 KDIR=$(KDIR) \
37 LOADER_ADDR=$(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
38 LOADER_DATA="$@" \
39 LOADER_NAME="$(notdir $@)" \
40 LZMA_TEXT_START=$(LZMA_TEXT_START) \
41 PKG_BUILD_DIR="$@.src" \
42 TARGET_DIR="$(dir $@)" \
43 compile loader.$(1)
44 @mv "$@.$(1)" "$@"
45 @rm -rf $@.src
46 endef
47
48 define Build/lzma-cfe
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
57 @mv $@.new $@
58 endef
59
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
64 # location.
65 ( \
66 dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
67 perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
68 cat $@ \
69 ) > $@.relocate
70 @mv $@.relocate $@
71 endef
72
73 ### Image scripts ###
74 define rootfspad/jffs2-128k
75 --align-rootfs
76 endef
77 define rootfspad/jffs2-64k
78 --align-rootfs
79 endef
80 define rootfspad/squashfs
81 endef
82
83 define Image/FileSystemStrip
84 $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
85 endef
86
87 define Build/cfe-bin
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))) \
94 $(CFE_EXTRAS) $(1)
95 endef
96
97 define Build/cfe-jffs2
98 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
99 --big-endian \
100 --pad \
101 --no-cleanmarkers \
102 --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
103 --root=$(1) \
104 --output=$@ \
105 --compression-mode=none
106
107 $(call Build/pad-to,$(BLOCKSIZE))
108 endef
109
110 define Build/cfe-jffs2-cferam
111 mv $@ $@.kernel
112
113 rm -rf $@-cferam
114 mkdir -p $@-cferam
115
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)
124
125 # The JFFS2 partition creation should result in the following
126 # layout:
127 # 1) 1-openwrt (version 0, ino 2)
128 # 2) cferam.000 (version 1, ino 3)
129 $(call Build/cfe-jffs2,$@-cferam)
130
131 # Some devices need padding between CFE RAM and kernel
132 $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
133
134 # Add CFE partition tag
135 $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
136
137 # Append kernel
138 dd if=$@.kernel >> $@
139 rm -f $@.kernel
140 endef
141
142 define Build/cfe-jffs2-kernel
143 rm -rf $@-kernel
144 mkdir -p $@-kernel
145
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
156 # ino as vmlinux.
157 touch $@-kernel/2-openwrt
158 # Add vmlinux as the last file in the JFFS2 partition
159 $(TOPDIR)/scripts/cfe-bin-header.py \
160 --input-file $@ \
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))
164
165 # The JFFS2 partition creation should result in the following
166 # layout:
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)
171 endef
172
173 define Build/cfe-part-tag
174 mv $@ $@.part
175
176 $(TOPDIR)/scripts/cfe-partition-tag.py \
177 --input-file $@.part \
178 --output-file $@ \
179 --flags $(CFE_PART_FLAGS) \
180 --id $(CFE_PART_ID) \
181 --name $(VERSION_CODE) \
182 --version $(DEVICE_NAME)
183
184 $(call Build/pad-to,$(BLOCKSIZE))
185
186 dd if=$@.part >> $@
187 endef
188
189 define Build/cfe-sercomm-crypto
190 $(TOPDIR)/scripts/sercomm-crypto.py \
191 --input-file $@ \
192 --key-file $@.key \
193 --output-file $@.ser \
194 --version OpenWrt
195 $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
196 -in $@ -out $@.enc \
197 -K `cat $@.key` \
198 -iv 00000000000000000000000000000000
199 dd if=$@.enc >> $@.ser
200 mv $@.ser $@
201 rm -f $@.enc $@.key
202 endef
203
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 \
209 --pid-file $@.pid
210 $(TOPDIR)/scripts/sercomm-payload.py \
211 --input-file $@ \
212 --output-file $@.new \
213 --pid-file $@.pid
214
215 mv $@.new $@
216 rm -f $@.pid
217 endef
218
219 define Build/cfe-sercomm-part
220 $(TOPDIR)/scripts/sercomm-partition-tag.py \
221 --input-file $@ \
222 --output-file $@.kernel_rootfs \
223 --part-name kernel_rootfs \
224 --part-version OpenWrt \
225 --rootfs-version $(SERCOMM_FSVER)
226
227 rm -rf $@-rootfs_lib
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 \
233 --input-file $@ \
234 --output-file $@.rootfs_lib \
235 --part-name rootfs_lib \
236 --part-version $(SERCOMM_FSVER)
237
238 mv $@.kernel_rootfs $@
239 dd if=$@.rootfs_lib >> $@
240 endef
241
242 define Build/cfe-wfi-tag
243 $(TOPDIR)/scripts/cfe-wfi-tag.py \
244 --input-file $@ \
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))
250 mv $@.new $@
251 endef
252
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
258 CHIP_ID :=
259 SOC = bcm$$(CHIP_ID)
260 DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
261 DEVICE_LOADADDR :=
262 endef
263
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
270 IMAGE/cfe.bin := \
271 cfe-bin $$$$(if $$$$(FLASH_MB),--pad $$$$(shell expr $$$$(FLASH_MB) / 2))
272 IMAGE/sysupgrade.bin := cfe-bin | append-metadata
273 BLOCKSIZE := 0x10000
274 IMAGE_OFFSET :=
275 FLASH_MB :=
276 CFE_BOARD_ID :=
277 CFE_EXTRAS = --block-size $$(BLOCKSIZE) \
278 --image-offset $$(if $$(IMAGE_OFFSET),$$(IMAGE_OFFSET),$$(BLOCKSIZE))
279 endef
280
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
285 endef
286
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
302 KERNEL_SIZE := 5120k
303 CFE_PART_FLAGS :=
304 CFE_PART_ID :=
305 CFE_RAM_FILE :=
306 CFE_RAM_JFFS2_NAME :=
307 CFE_RAM_JFFS2_PAD :=
308 CFE_WFI_VERSION :=
309 CFE_WFI_CHIP_ID = 0x$$(CHIP_ID)
310 CFE_WFI_FLASH_TYPE :=
311 CFE_WFI_FLAGS :=
312 UBINIZE_OPTS := -E 5
313 DEVICE_PACKAGES += nand-utils
314 endef
315
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
321 SERCOMM_FSVER :=
322 SERCOMM_HWVER :=
323 SERCOMM_SWVER :=
324 endef
325
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
331
332 include $(SUBTARGET).mk
333
334 $(eval $(call BuildImage))