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