treewide: replace wpad-basic-wolfssl default
[openwrt/staging/ldir.git] / target / linux / bcm63xx / image / Makefile
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2006-2015 OpenWrt.org
4 # Copyright (C) 2016 LEDE project
5
6 include $(TOPDIR)/rules.mk
7 include $(INCLUDE_DIR)/image.mk
8
9 KERNEL_LOADADDR = 0x80010000 # RAM start + 64K
10 LOADER_ENTRY = 0x80a00000 # RAM start + 10M, for relocate
11 RAMSIZE = 0x02000000 # 32MB
12 LZMA_TEXT_START = 0x81800000 # 32MB - 8MB
13
14 RELOCATE_MAKEOPTS= \
15 CACHELINE_SIZE=16 \
16 KERNEL_ADDR=$(KERNEL_LOADADDR) \
17 CROSS_COMPILE=$(TARGET_CROSS) \
18 LZMA_TEXT_START=$(LOADER_ENTRY)
19
20 define Build/Compile
21 rm -rf $(KDIR)/relocate
22 $(CP) ../../generic/image/relocate $(KDIR)
23 $(MAKE) -C $(KDIR)/relocate $(RELOCATE_MAKEOPTS)
24 endef
25
26 ### Kernel scripts ###
27 define Build/hcs-initramfs
28 $(STAGING_DIR_HOST)/bin/hcsmakeimage --magic_bytes=$(HCS_MAGIC_BYTES) \
29 --rev_maj=$(HCS_REV_MAJ) --rev_min=$(HCS_REV_MIN) --input_file=$@ \
30 --output_file=$@.hcs --ldaddress=$(KERNEL_LOADADDR)
31 mv $@.hcs $@
32 endef
33
34 define Build/loader-lzma
35 rm -rf $@.src
36 $(MAKE) -C lzma-loader \
37 KDIR=$(KDIR) \
38 LOADER_ADDR=$(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
39 KERNEL_ADDR=$(KERNEL_LOADADDR) \
40 RAMSIZE=$(RAMSIZE) \
41 LZMA_TEXT_START=$(LZMA_TEXT_START) \
42 CHIP_ID=$(CHIP_ID) \
43 PKG_BUILD_DIR="$@.src" \
44 TARGET_DIR="$(dir $@)" \
45 LOADER_DATA="$@" \
46 LOADER_NAME="$(notdir $@)" \
47 compile loader.$(1)
48 mv "$@.$(1)" "$@"
49 rm -rf $@.src
50 endef
51
52 define Build/lzma-cfe
53 # CFE is a LZMA nazi! It took me hours to find out the parameters!
54 # Also I think lzma has a bug cause it generates different output depending on
55 # if you use stdin / stdout or not. Use files instead of stdio here, cause
56 # otherwise CFE will complain and not boot the image.
57 $(call Build/lzma-no-dict,-d22 -fb64 -a1)
58 # Strip out the length, CFE doesn't like this
59 dd if=$@ of=$@.new bs=5 count=1
60 dd if=$@ of=$@.new ibs=13 obs=5 skip=1 seek=1 conv=notrunc
61 mv $@.new $@
62 endef
63
64 define Build/relocate-kernel
65 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
66 # kernel might get larger than that, so let CFE unpack and load at a
67 # higher address and make the kernel relocate itself to the expected
68 # location.
69 ( \
70 dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
71 perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
72 cat $@ \
73 ) > $@.relocate
74 mv $@.relocate $@
75 endef
76
77 ### Image scripts ###
78 define rootfspad/jffs2-128k
79 --align-rootfs
80 endef
81 define rootfspad/jffs2-64k
82 --align-rootfs
83 endef
84 define rootfspad/squashfs
85 endef
86
87 define Image/FileSystemStrip
88 $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
89 endef
90
91 define Build/cfe-bin
92 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
93 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
94 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
95 --info1 "$(call ModelNameLimit16,$(DEVICE_NAME))" \
96 --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
97 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
98 $(CFE_EXTRAS) $(1)
99 endef
100
101 define Build/cfe-jffs2
102 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
103 --big-endian \
104 --pad \
105 --no-cleanmarkers \
106 --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
107 --root=$(1) \
108 --output=$@ \
109 --compression-mode=none
110
111 $(call Build/pad-to,$(BLOCKSIZE))
112 endef
113
114 define Build/cfe-jffs2-cferam
115 mv $@ $@.kernel
116
117 rm -rf $@-cferam
118 mkdir -p $@-cferam
119
120 # CFE ROM checks JFFS2 dirent version of cferam.
121 # If version is not > 0 it will ignore the fs entry.
122 # JFFS2 sets version 0 to the first fs entry and increments
123 # it on the following ones, so let's create a dummy file that
124 # will have version 0 and let cferam be the second (version 1).
125 touch $@-cferam/1-openwrt
126 # Add cferam as the last file in the JFFS2 partition
127 cp $(KDIR)/bcm63xx-cfe/$(CFE_RAM_FILE) $@-cferam/$(CFE_RAM_JFFS2_NAME)
128
129 # The JFFS2 partition creation should result in the following
130 # layout:
131 # 1) 1-openwrt (version 0, ino 2)
132 # 2) cferam.000 (version 1, ino 3)
133 $(call Build/cfe-jffs2,$@-cferam)
134
135 # Some devices need padding between CFE RAM and kernel
136 $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
137
138 # Add CFE partition tag
139 $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
140
141 # Append kernel
142 dd if=$@.kernel >> $@
143 rm -f $@.kernel
144 endef
145
146 define Build/cfe-jffs2-kernel
147 rm -rf $@-kernel
148 mkdir -p $@-kernel
149
150 # CFE RAM checks JFFS2 dirent version of vmlinux.
151 # If version is not > 0 it will ignore the fs entry.
152 # JFFS2 sets version 0 to the first fs entry and increments
153 # it on the following ones, so let's create a dummy file that
154 # will have version 0 and let cferam be the second (version 1).
155 touch $@-kernel/1-openwrt
156 # vmlinux is located on a different JFFS2 partition, but CFE RAM
157 # ignores it, so let's create another dummy file that will match
158 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
159 # CFE RAM won't be able to find vmlinux if cferam has the same
160 # ino as vmlinux.
161 touch $@-kernel/2-openwrt
162 # Add vmlinux as the last file in the JFFS2 partition
163 $(TOPDIR)/scripts/cfe-bin-header.py \
164 --input-file $@ \
165 --output-file $@-kernel/vmlinux.lz \
166 --load-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
167 --entry-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY))
168
169 # The JFFS2 partition creation should result in the following
170 # layout:
171 # 1) 1-openwrt (version 0, ino 2)
172 # 2) 2-openwrt (version 1, ino 3)
173 # 3) vmlinux.lz (version 2, ino 4)
174 $(call Build/cfe-jffs2,$@-kernel)
175 endef
176
177 define Build/cfe-part-tag
178 mv $@ $@.part
179
180 $(TOPDIR)/scripts/cfe-partition-tag.py \
181 --input-file $@.part \
182 --output-file $@ \
183 --flags $(CFE_PART_FLAGS) \
184 --id $(CFE_PART_ID) \
185 --name $(VERSION_CODE) \
186 --version $(DEVICE_NAME)
187
188 $(call Build/pad-to,$(BLOCKSIZE))
189
190 dd if=$@.part >> $@
191 endef
192
193 define Build/cfe-sercomm-part
194 $(TOPDIR)/scripts/sercomm-partition-tag.py \
195 --input-file $@ \
196 --output-file $@.kernel_rootfs \
197 --part-name kernel_rootfs \
198 --part-version OpenWrt \
199 --rootfs-version $(SERCOMM_VERSION)
200
201 rm -rf $@-rootfs_lib
202 mkdir -p $@-rootfs_lib
203 echo $(SERCOMM_VERSION) > $@-rootfs_lib/lib_ver
204 $(call Build/cfe-jffs2,$@-rootfs_lib)
205 $(call Build/pad-to,$(BLOCKSIZE))
206 $(TOPDIR)/scripts/sercomm-partition-tag.py \
207 --input-file $@ \
208 --output-file $@.rootfs_lib \
209 --part-name rootfs_lib \
210 --part-version $(SERCOMM_VERSION)
211
212 mv $@.kernel_rootfs $@
213 dd if=$@.rootfs_lib >> $@
214 endef
215
216 define Build/cfe-sercomm-load
217 $(TOPDIR)/scripts/sercomm-payload.py \
218 --input-file $@ \
219 --output-file $@.new \
220 --pid "$(SERCOMM_PID)"
221
222 mv $@.new $@
223 endef
224
225 define Build/cfe-sercomm-crypto
226 $(TOPDIR)/scripts/sercomm-crypto.py \
227 --input-file $@ \
228 --key-file $@.key \
229 --output-file $@.ser \
230 --version OpenWrt
231 $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
232 -in $@ -out $@.enc \
233 -K `cat $@.key` \
234 -iv 00000000000000000000000000000000
235 dd if=$@.enc >> $@.ser
236 mv $@.ser $@
237 rm -f $@.enc $@.key
238 endef
239
240 define Build/cfe-old-bin
241 $(TOPDIR)/scripts/brcmImage.pl -t -p \
242 -o $@ -b $(CFE_BOARD_ID) -c $(CHIP_ID) \
243 -e $(LOADER_ENTRY) -a $(LOADER_ENTRY) \
244 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) \
245 $(CFE_EXTRAS)
246 endef
247
248 define Build/cfe-spw303v-bin
249 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
250 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
251 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
252 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
253 $(CFE_EXTRAS) $(1)
254 endef
255
256 define Build/cfe-wfi-tag
257 $(TOPDIR)/scripts/cfe-wfi-tag.py \
258 --input-file $@ \
259 --output-file $@.new \
260 --version $(if $(1),$(1),$(CFE_WFI_VERSION)) \
261 --chip-id $(CFE_WFI_CHIP_ID) \
262 --flash-type $(CFE_WFI_FLASH_TYPE) \
263 $(if $(CFE_WFI_FLAGS),--flags $(CFE_WFI_FLAGS))
264 mv $@.new $@
265 endef
266
267 define Build/spw303v-bin
268 $(STAGING_DIR_HOST)/bin/spw303v -i $@ -o $@.spw303v
269 mv $@.spw303v $@
270 endef
271
272 define Build/zyxel-bin
273 $(STAGING_DIR_HOST)/bin/zyxbcm -i $@ -o $@.zyxel
274 mv $@.zyxel $@
275 endef
276
277 define Build/redboot-bin
278 # Prepare kernel and rootfs
279 dd if=$(IMAGE_KERNEL) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz bs=65536 conv=sync
280 dd if=$(IMAGE_ROOTFS) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) bs=64k conv=sync
281 echo -ne \\xDE\\xAD\\xC0\\xDE >> $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))
282 # Generate the scripted image
283 $(TOPDIR)/scripts/redboot-script.pl \
284 -k $(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz \
285 -r $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) \
286 -a $(strip $(LOADER_ENTRY)) -f 0xbe430000 -l 0x7c0000 \
287 -s 0x1000 -t 20 -o $@.redbootscript
288 dd if="$@.redbootscript" of="$@.redbootscript.padded" bs=4096 conv=sync
289 cat \
290 "$@.redbootscript.padded" \
291 "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
292 "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
293 > "$@"
294 endef
295
296 define Device/Default
297 PROFILES = Default $$(DEVICE_NAME)
298 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
299 KERNEL_INITRAMFS_SUFFIX := .elf
300 DEVICE_DTS_DIR := ../dts
301 CHIP_ID :=
302 SOC = bcm$$(CHIP_ID)
303 DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
304 DEVICE_LOADADDR :=
305 endef
306 DEVICE_VARS += CHIP_ID DEVICE_LOADADDR
307
308 ATH5K_PACKAGES := kmod-ath5k wpad-basic-mbedtls
309 ATH9K_PACKAGES := kmod-ath9k wpad-basic-mbedtls
310 B43_PACKAGES := kmod-b43 wpad-basic-mbedtls
311 BRCMWL_PACKAGES := kmod-brcm-wl nas wlc
312 RT28_PACKAGES := kmod-rt2800-pci wpad-basic-mbedtls
313 RT61_PACKAGES := kmod-rt61-pci wpad-basic-mbedtls
314 USB1_PACKAGES := kmod-usb-ohci kmod-usb-ledtrig-usbport
315 USB2_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
316
317 include bcm63xx.mk
318
319 ifeq ($(SUBTARGET),smp)
320 include bcm63xx_nand.mk
321 endif
322
323 $(eval $(call BuildImage))