822e26e9935a224a569c5ecd4fffa024997a8c41
[openwrt/staging/chunkeey.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/LimitName16
88 $(shell expr substr "$(1)" 1 16)
89 endef
90
91 define Image/FileSystemStrip
92 $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
93 endef
94
95 define Build/cfe-bin
96 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
97 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
98 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
99 --info1 "$(call Image/LimitName16,$(DEVICE_NAME))" \
100 --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
101 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
102 $(CFE_EXTRAS) $(1)
103 endef
104
105 define Build/cfe-jffs2
106 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
107 --big-endian \
108 --pad \
109 --no-cleanmarkers \
110 --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
111 --root=$(1) \
112 --output=$@ \
113 --compression-mode=none
114
115 $(call Build/pad-to,$(BLOCKSIZE))
116 endef
117
118 define Build/cfe-jffs2-cferam
119 mv $@ $@.kernel
120
121 rm -rf $@-cferam
122 mkdir -p $@-cferam
123
124 # CFE ROM checks JFFS2 dirent version of cferam.
125 # If version is not > 0 it will ignore the fs entry.
126 # JFFS2 sets version 0 to the first fs entry and increments
127 # it on the following ones, so let's create a dummy file that
128 # will have version 0 and let cferam be the second (version 1).
129 touch $@-cferam/1-openwrt
130 # Add cferam as the last file in the JFFS2 partition
131 cp $(KDIR)/bcm63xx-cfe/$(CFE_RAM_FILE) $@-cferam/$(CFE_RAM_JFFS2_NAME)
132
133 # The JFFS2 partition creation should result in the following
134 # layout:
135 # 1) 1-openwrt (version 0, ino 2)
136 # 2) cferam.000 (version 1, ino 3)
137 $(call Build/cfe-jffs2,$@-cferam)
138
139 # Some devices need padding between CFE RAM and kernel
140 $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
141
142 # Add CFE partition tag
143 $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
144
145 # Append kernel
146 dd if=$@.kernel >> $@
147 rm -f $@.kernel
148 endef
149
150 define Build/cfe-jffs2-kernel
151 rm -rf $@-kernel
152 mkdir -p $@-kernel
153
154 # CFE RAM checks JFFS2 dirent version of vmlinux.
155 # If version is not > 0 it will ignore the fs entry.
156 # JFFS2 sets version 0 to the first fs entry and increments
157 # it on the following ones, so let's create a dummy file that
158 # will have version 0 and let cferam be the second (version 1).
159 touch $@-kernel/1-openwrt
160 # vmlinux is located on a different JFFS2 partition, but CFE RAM
161 # ignores it, so let's create another dummy file that will match
162 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
163 # CFE RAM won't be able to find vmlinux if cferam has the same
164 # ino as vmlinux.
165 touch $@-kernel/2-openwrt
166 # Add vmlinux as the last file in the JFFS2 partition
167 $(TOPDIR)/scripts/cfe-bin-header.py \
168 --input-file $@ \
169 --output-file $@-kernel/vmlinux.lz \
170 --load-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
171 --entry-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY))
172
173 # The JFFS2 partition creation should result in the following
174 # layout:
175 # 1) 1-openwrt (version 0, ino 2)
176 # 2) 2-openwrt (version 1, ino 3)
177 # 3) vmlinux.lz (version 2, ino 4)
178 $(call Build/cfe-jffs2,$@-kernel)
179 endef
180
181 define Build/cfe-part-tag
182 mv $@ $@.part
183
184 $(TOPDIR)/scripts/cfe-partition-tag.py \
185 --input-file $@.part \
186 --output-file $@ \
187 --flags $(CFE_PART_FLAGS) \
188 --id $(CFE_PART_ID) \
189 --name $(VERSION_CODE) \
190 --version $(DEVICE_NAME)
191
192 $(call Build/pad-to,$(BLOCKSIZE))
193
194 dd if=$@.part >> $@
195 endef
196
197 define Build/cfe-sercomm-part
198 $(TOPDIR)/scripts/sercomm-partition-tag.py \
199 --input-file $@ \
200 --output-file $@.kernel_rootfs \
201 --part-name kernel_rootfs \
202 --part-version OpenWrt \
203 --rootfs-version $(SERCOMM_VERSION)
204
205 rm -rf $@-rootfs_lib
206 mkdir -p $@-rootfs_lib
207 echo $(SERCOMM_VERSION) > $@-rootfs_lib/lib_ver
208 $(call Build/cfe-jffs2,$@-rootfs_lib)
209 $(call Build/pad-to,$(BLOCKSIZE))
210 $(TOPDIR)/scripts/sercomm-partition-tag.py \
211 --input-file $@ \
212 --output-file $@.rootfs_lib \
213 --part-name rootfs_lib \
214 --part-version $(SERCOMM_VERSION)
215
216 mv $@.kernel_rootfs $@
217 dd if=$@.rootfs_lib >> $@
218 endef
219
220 define Build/cfe-sercomm-load
221 $(TOPDIR)/scripts/sercomm-payload.py \
222 --input-file $@ \
223 --output-file $@.new \
224 --pid "$(SERCOMM_PID)"
225
226 mv $@.new $@
227 endef
228
229 define Build/cfe-sercomm-crypto
230 $(TOPDIR)/scripts/sercomm-crypto.py \
231 --input-file $@ \
232 --key-file $@.key \
233 --output-file $@.ser \
234 --version OpenWrt
235 $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
236 -in $@ -out $@.enc \
237 -K `cat $@.key` \
238 -iv 00000000000000000000000000000000
239 dd if=$@.enc >> $@.ser
240 mv $@.ser $@
241 rm -f $@.enc $@.key
242 endef
243
244 define Build/cfe-old-bin
245 $(TOPDIR)/scripts/brcmImage.pl -t -p \
246 -o $@ -b $(CFE_BOARD_ID) -c $(CHIP_ID) \
247 -e $(LOADER_ENTRY) -a $(LOADER_ENTRY) \
248 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) \
249 $(CFE_EXTRAS)
250 endef
251
252 define Build/cfe-spw303v-bin
253 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
254 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
255 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
256 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
257 $(CFE_EXTRAS) $(1)
258 endef
259
260 define Build/cfe-wfi-tag
261 $(TOPDIR)/scripts/cfe-wfi-tag.py \
262 --input-file $@ \
263 --output-file $@.new \
264 --version $(if $(1),$(1),$(CFE_WFI_VERSION)) \
265 --chip-id $(CFE_WFI_CHIP_ID) \
266 --flash-type $(CFE_WFI_FLASH_TYPE) \
267 $(if $(CFE_WFI_FLAGS),--flags $(CFE_WFI_FLAGS))
268 mv $@.new $@
269 endef
270
271 define Build/spw303v-bin
272 $(STAGING_DIR_HOST)/bin/spw303v -i $@ -o $@.spw303v
273 mv $@.spw303v $@
274 endef
275
276 define Build/zyxel-bin
277 $(STAGING_DIR_HOST)/bin/zyxbcm -i $@ -o $@.zyxel
278 mv $@.zyxel $@
279 endef
280
281 define Build/redboot-bin
282 # Prepare kernel and rootfs
283 dd if=$(IMAGE_KERNEL) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz bs=65536 conv=sync
284 dd if=$(IMAGE_ROOTFS) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) bs=64k conv=sync
285 echo -ne \\xDE\\xAD\\xC0\\xDE >> $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))
286 # Generate the scripted image
287 $(TOPDIR)/scripts/redboot-script.pl \
288 -k $(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz \
289 -r $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) \
290 -a $(strip $(LOADER_ENTRY)) -f 0xbe430000 -l 0x7c0000 \
291 -s 0x1000 -t 20 -o $@.redbootscript
292 dd if="$@.redbootscript" of="$@.redbootscript.padded" bs=4096 conv=sync
293 cat \
294 "$@.redbootscript.padded" \
295 "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
296 "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
297 > "$@"
298 endef
299
300 define Device/Default
301 PROFILES = Default $$(DEVICE_NAME)
302 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
303 KERNEL_INITRAMFS_SUFFIX := .elf
304 DEVICE_DTS_DIR := ../dts
305 CHIP_ID :=
306 SOC = bcm$$(CHIP_ID)
307 DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
308 DEVICE_LOADADDR :=
309 endef
310 DEVICE_VARS += CHIP_ID DEVICE_LOADADDR
311
312 ATH5K_PACKAGES := kmod-ath5k wpad-basic-wolfssl
313 ATH9K_PACKAGES := kmod-ath9k wpad-basic-wolfssl
314 B43_PACKAGES := kmod-b43 wpad-basic-wolfssl
315 BRCMWL_PACKAGES := kmod-brcm-wl nas wlc
316 RT28_PACKAGES := kmod-rt2800-pci wpad-basic-wolfssl
317 RT61_PACKAGES := kmod-rt61-pci wpad-basic-wolfssl
318 USB1_PACKAGES := kmod-usb-ohci kmod-usb-ledtrig-usbport
319 USB2_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
320
321 include bcm63xx.mk
322
323 ifeq ($(SUBTARGET),smp)
324 include bcm63xx_nand.mk
325 endif
326
327 $(eval $(call BuildImage))