]> git.ipfire.org Git - thirdparty/openwrt.git/blob - target/linux/bmips/image/Makefile
qualcommax: ipq807x: add support for Linksys MX8500
[thirdparty/openwrt.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 UBOOT_ENTRY := 0x81c00000
8 LOADER_ENTRY := 0x81000000 # RAM start + 16M, for relocate
9 LZMA_TEXT_START := 0x82000000 # RAM start + 32M
10
11 DEVICE_VARS += CFE_BOARD_ID CFE_EXTRAS
12 DEVICE_VARS += CFE_PART_FLAGS CFE_PART_ID
13 DEVICE_VARS += CFE_RAM_FILE
14 DEVICE_VARS += CFE_RAM_JFFS2_NAME CFE_RAM_JFFS2_PAD
15 DEVICE_VARS += CFE_WFI_CHIP_ID CFE_WFI_FLASH_TYPE
16 DEVICE_VARS += CFE_WFI_FLAGS CFE_WFI_VERSION
17 DEVICE_VARS += CHIP_ID DEVICE_LOADADDR
18 DEVICE_VARS += FLASH_MB IMAGE_OFFSET
19 DEVICE_VARS += SERCOMM_FSVER SERCOMM_HWVER SERCOMM_SWVER
20
21 define Build/Compile
22 rm -rf $(KDIR)/relocate
23 $(CP) ../../generic/image/relocate $(KDIR)
24 $(MAKE) -C $(KDIR)/relocate \
25 CACHELINE_SIZE=16 \
26 CROSS_COMPILE=$(TARGET_CROSS) \
27 KERNEL_ADDR=$(KERNEL_LOADADDR) \
28 LZMA_TEXT_START=$(LOADER_ENTRY)
29 endef
30
31 ### Kernel scripts ###
32 define Build/loader-lzma
33 @rm -rf $@.src
34 $(MAKE) -C lzma-loader \
35 CHIP_ID=$(CHIP_ID) \
36 KERNEL_ADDR=$(KERNEL_LOADADDR) \
37 KDIR=$(KDIR) \
38 LOADER_ADDR=$(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
39 LOADER_DATA="$@" \
40 LOADER_NAME="$(notdir $@)" \
41 LZMA_TEXT_START=$(LZMA_TEXT_START) \
42 PKG_BUILD_DIR="$@.src" \
43 TARGET_DIR="$(dir $@)" \
44 compile loader.$(1)
45 @mv "$@.$(1)" "$@"
46 @rm -rf $@.src
47 endef
48
49 define Build/lzma-cfe
50 # CFE is a LZMA nazi! It took me hours to find out the parameters!
51 # Also I think lzma has a bug cause it generates different output depending on
52 # if you use stdin / stdout or not. Use files instead of stdio here, cause
53 # otherwise CFE will complain and not boot the image.
54 $(call Build/lzma-no-dict,-d22 -fb64 -a1)
55 # Strip out the length, CFE doesn't like this
56 dd if=$@ of=$@.new bs=5 count=1
57 dd if=$@ of=$@.new ibs=13 obs=5 skip=1 seek=1 conv=notrunc
58 @mv $@.new $@
59 endef
60
61 define Build/relocate-kernel
62 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
63 # kernel might get larger than that, so let CFE unpack and load at a
64 # higher address and make the kernel relocate itself to the expected
65 # location.
66 ( \
67 dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
68 perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
69 cat $@ \
70 ) > $@.relocate
71 @mv $@.relocate $@
72 endef
73
74 ### Image scripts ###
75 define rootfspad/jffs2-128k
76 --align-rootfs
77 endef
78 define rootfspad/jffs2-64k
79 --align-rootfs
80 endef
81 define rootfspad/squashfs
82 endef
83
84 define Image/FileSystemStrip
85 $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
86 endef
87
88 define Build/cfe-bin
89 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
90 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
91 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
92 --info1 "$(call ModelNameLimit16,$(DEVICE_NAME))" \
93 --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
94 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
95 $(CFE_EXTRAS) $(1)
96 endef
97
98 # Build a CFE image with just U-Boot
99 define Build/cfe-bin-uboot
100 cp $(STAGING_DIR_IMAGE)/$(DEVICE_NAME)-u-boot.bin $@
101 $(call Build/lzma)
102 mv $@ $@.uboot.lzma
103 echo "dummy" > $@.dummyfs
104 $(STAGING_DIR_HOST)/bin/imagetag -i $@.uboot.lzma -f $@.dummyfs \
105 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
106 --entry $(UBOOT_ENTRY) --load-addr $(UBOOT_ENTRY) \
107 --info1 "$(call ModelNameLimit16,$(DEVICE_NAME))" \
108 $(CFE_EXTRAS) $(1)
109 rm $@.uboot.lzma
110 rm $@.dummyfs
111 endef
112
113 define Build/cfe-jffs2
114 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
115 --big-endian \
116 --pad \
117 --no-cleanmarkers \
118 --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
119 --root=$(1) \
120 --output=$@ \
121 --compression-mode=none
122
123 $(call Build/pad-to,$(BLOCKSIZE))
124 endef
125
126 define Build/cfe-jffs2-cferam
127 mv $@ $@.kernel
128
129 rm -rf $@-cferam
130 mkdir -p $@-cferam
131
132 # CFE ROM checks JFFS2 dirent version of cferam.
133 # If version is not > 0 it will ignore the fs entry.
134 # JFFS2 sets version 0 to the first fs entry and increments
135 # it on the following ones, so let's create a dummy file that
136 # will have version 0 and let cferam be the second (version 1).
137 touch $@-cferam/1-openwrt
138 # Add cferam as the last file in the JFFS2 partition
139 cp $(KDIR)/bcm63xx-cfe/$(CFE_RAM_FILE) $@-cferam/$(CFE_RAM_JFFS2_NAME)
140
141 # The JFFS2 partition creation should result in the following
142 # layout:
143 # 1) 1-openwrt (version 0, ino 2)
144 # 2) cferam.000 (version 1, ino 3)
145 $(call Build/cfe-jffs2,$@-cferam)
146
147 # Some devices need padding between CFE RAM and kernel
148 $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
149
150 # Add CFE partition tag
151 $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
152
153 # Append kernel
154 dd if=$@.kernel >> $@
155 rm -f $@.kernel
156 endef
157
158 define Build/cfe-jffs2-kernel
159 rm -rf $@-kernel
160 mkdir -p $@-kernel
161
162 # CFE RAM checks JFFS2 dirent version of vmlinux.
163 # If version is not > 0 it will ignore the fs entry.
164 # JFFS2 sets version 0 to the first fs entry and increments
165 # it on the following ones, so let's create a dummy file that
166 # will have version 0 and let cferam be the second (version 1).
167 touch $@-kernel/1-openwrt
168 # vmlinux is located on a different JFFS2 partition, but CFE RAM
169 # ignores it, so let's create another dummy file that will match
170 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
171 # CFE RAM won't be able to find vmlinux if cferam has the same
172 # ino as vmlinux.
173 touch $@-kernel/2-openwrt
174 # Add vmlinux as the last file in the JFFS2 partition
175 $(TOPDIR)/scripts/cfe-bin-header.py \
176 --input-file $@ \
177 --output-file $@-kernel/vmlinux.lz \
178 --load-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
179 --entry-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY))
180
181 # The JFFS2 partition creation should result in the following
182 # layout:
183 # 1) 1-openwrt (version 0, ino 2)
184 # 2) 2-openwrt (version 1, ino 3)
185 # 3) vmlinux.lz (version 2, ino 4)
186 $(call Build/cfe-jffs2,$@-kernel)
187 endef
188
189 define Build/cfe-part-tag
190 mv $@ $@.part
191
192 $(TOPDIR)/scripts/cfe-partition-tag.py \
193 --input-file $@.part \
194 --output-file $@ \
195 --flags $(CFE_PART_FLAGS) \
196 --id $(CFE_PART_ID) \
197 --name $(VERSION_CODE) \
198 --version $(DEVICE_NAME)
199
200 $(call Build/pad-to,$(BLOCKSIZE))
201
202 dd if=$@.part >> $@
203 endef
204
205 define Build/cfe-sercomm-crypto
206 $(TOPDIR)/scripts/sercomm-crypto.py \
207 --input-file $@ \
208 --key-file $@.key \
209 --output-file $@.ser \
210 --version OpenWrt
211 $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
212 -in $@ -out $@.enc \
213 -K `cat $@.key` \
214 -iv 00000000000000000000000000000000
215 dd if=$@.enc >> $@.ser
216 mv $@.ser $@
217 rm -f $@.enc $@.key
218 endef
219
220 define Build/cfe-sercomm-load
221 $(TOPDIR)/scripts/sercomm-pid.py \
222 --hw-version $(SERCOMM_HWVER) \
223 --sw-version $(SERCOMM_SWVER) \
224 --extra-padding-size 0x10 \
225 --pid-file $@.pid
226 $(TOPDIR)/scripts/sercomm-payload.py \
227 --input-file $@ \
228 --output-file $@.new \
229 --pid-file $@.pid
230
231 mv $@.new $@
232 rm -f $@.pid
233 endef
234
235 define Build/cfe-sercomm-part
236 $(TOPDIR)/scripts/sercomm-partition-tag.py \
237 --input-file $@ \
238 --output-file $@.kernel_rootfs \
239 --part-name kernel_rootfs \
240 --part-version OpenWrt \
241 --rootfs-version $(SERCOMM_FSVER)
242
243 rm -rf $@-rootfs_lib
244 mkdir -p $@-rootfs_lib
245 echo $(SERCOMM_FSVER) > $@-rootfs_lib/lib_ver
246 $(call Build/cfe-jffs2,$@-rootfs_lib)
247 $(call Build/pad-to,$(BLOCKSIZE))
248 $(TOPDIR)/scripts/sercomm-partition-tag.py \
249 --input-file $@ \
250 --output-file $@.rootfs_lib \
251 --part-name rootfs_lib \
252 --part-version $(SERCOMM_FSVER)
253
254 mv $@.kernel_rootfs $@
255 dd if=$@.rootfs_lib >> $@
256 endef
257
258 define Build/cfe-wfi-tag
259 $(TOPDIR)/scripts/cfe-wfi-tag.py \
260 --input-file $@ \
261 --output-file $@.new \
262 --version $(if $(1),$(1),$(CFE_WFI_VERSION)) \
263 --chip-id $(CFE_WFI_CHIP_ID) \
264 --flash-type $(CFE_WFI_FLASH_TYPE) \
265 $(if $(CFE_WFI_FLAGS),--flags $(CFE_WFI_FLAGS))
266 mv $@.new $@
267 endef
268
269 ### Device scripts ###
270 define Device/Default
271 PROFILES = Default $$(DEVICE_NAME)
272 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
273 DEVICE_DTS_DIR := ../dts
274 CHIP_ID :=
275 SOC = bcm$$(CHIP_ID)
276 DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
277 DEVICE_LOADADDR :=
278 endef
279
280 define Device/bcm63xx-cfe
281 FILESYSTEMS := squashfs jffs2-64k jffs2-128k
282 KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma
283 KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-lzma elf
284 KERNEL_INITRAMFS_SUFFIX := .elf
285 IMAGES := cfe.bin sysupgrade.bin
286 IMAGE/cfe.bin := \
287 cfe-bin $$$$(if $$$$(FLASH_MB),--pad $$$$(shell expr $$$$(FLASH_MB) / 2))
288 IMAGE/sysupgrade.bin := cfe-bin | append-metadata
289 BLOCKSIZE := 0x10000
290 IMAGE_OFFSET :=
291 FLASH_MB :=
292 CFE_BOARD_ID :=
293 CFE_EXTRAS = --block-size $$(BLOCKSIZE) \
294 --image-offset $$(if $$(IMAGE_OFFSET),$$(IMAGE_OFFSET),$$(BLOCKSIZE))
295 endef
296
297 # Legacy CFEs with specific LZMA parameters and no length
298 define Device/bcm63xx-cfe-legacy
299 $(Device/bcm63xx-cfe)
300 KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma-cfe
301 endef
302
303 # CFE images with U-Boot in front of the kernel, these will execute
304 # U-Boot instead of the kernel and U-Boot will then proceed to load
305 # the kernel. The reason to do this is that CFE is sometimes unable to
306 # load big kernels even with the lzma loader tricks.
307 define Device/bcm63xx-cfe-uboot
308 $(Device/bcm63xx-cfe)
309 KERNEL := kernel-bin | append-dtb | lzma | uImage lzma
310 IMAGE/cfe.bin := cfe-bin-uboot | pad-to $$$$$$$$(($$(BLOCKSIZE))) | \
311 append-kernel | pad-to $$$$$$$$(($$(BLOCKSIZE))) | \
312 append-rootfs $$$$(if $$$$(FLASH_MB),--pad $$$$(shell expr $$$$(FLASH_MB) / 2))
313 IMAGE/sysupgrade.bin := cfe-bin-uboot | pad-to $$$$$$$$(($$(BLOCKSIZE))) | \
314 append-kernel | pad-to $$$$$$$$(($$(BLOCKSIZE))) | \
315 append-rootfs | append-metadata
316 endef
317
318 # CFE expects a single JFFS2 partition with cferam and kernel. However,
319 # it's possible to fool CFE into properly loading both cferam and kernel
320 # from two different JFFS2 partitions by adding dummy files (see
321 # cfe-jffs2-cferam and cfe-jffs2-kernel).
322 # Separate JFFS2 partitions allow upgrading openwrt without reflashing cferam
323 # JFFS2 partition, which is much safer in case anything goes wrong.
324 define Device/bcm63xx-nand
325 FILESYSTEMS := squashfs ubifs
326 KERNEL := kernel-bin | append-dtb | relocate-kernel | lzma | cfe-jffs2-kernel
327 KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-lzma elf
328 KERNEL_INITRAMFS_SUFFIX := .elf
329 IMAGES := cfe.bin sysupgrade.bin
330 IMAGE/cfe.bin := append-kernel | pad-to $$$$(KERNEL_SIZE) |\
331 cfe-jffs2-cferam | append-ubi | cfe-wfi-tag
332 IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
333 KERNEL_SIZE := 5120k
334 CFE_PART_FLAGS :=
335 CFE_PART_ID :=
336 CFE_RAM_FILE :=
337 CFE_RAM_JFFS2_NAME :=
338 CFE_RAM_JFFS2_PAD :=
339 CFE_WFI_VERSION :=
340 CFE_WFI_CHIP_ID = 0x$$(CHIP_ID)
341 CFE_WFI_FLASH_TYPE :=
342 CFE_WFI_FLAGS :=
343 UBINIZE_OPTS := -E 5
344 DEVICE_PACKAGES += nand-utils
345 endef
346
347 define Device/bcm63xx-netgear
348 $(Device/bcm63xx-cfe)
349 DEVICE_VENDOR := NETGEAR
350 IMAGES := factory.chk sysupgrade.bin
351 IMAGE/factory.chk := cfe-bin | netgear-chk
352 NETGEAR_BOARD_ID :=
353 NETGEAR_REGION :=
354 endef
355
356 define Device/sercomm-nand
357 $(Device/bcm63xx-nand)
358 IMAGES := factory.img sysupgrade.bin
359 IMAGE/factory.img := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi |\
360 cfe-sercomm-part | gzip | cfe-sercomm-load | cfe-sercomm-crypto
361 SERCOMM_FSVER :=
362 SERCOMM_HWVER :=
363 SERCOMM_SWVER :=
364 endef
365
366 ### Package helpers ###
367 ATH9K_PACKAGES := kmod-ath9k kmod-owl-loader wpad-basic-mbedtls
368 B43_PACKAGES := kmod-b43 wpad-basic-mbedtls
369 USB1_PACKAGES := kmod-usb-ohci kmod-usb-ledtrig-usbport
370 USB2_PACKAGES := $(USB1_PACKAGES) kmod-usb2
371
372 include $(SUBTARGET).mk
373
374 $(eval $(call BuildImage))