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