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