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