bcm63xx: image: rename LOADADDR to KERNEL_LOADADDR
[openwrt/staging/stintel.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 KERNEL_ENTRY=$(KERNEL_LOADADDR) \
20 RAMSIZE=$(RAMSIZE) \
21 LZMA_TEXT_START=$(LZMA_TEXT_START) \
22
23 RELOCATE_MAKEOPTS= \
24 CACHELINE_SIZE=16 \
25 KERNEL_ADDR=$(KERNEL_LOADADDR) \
26 CROSS_COMPILE=$(TARGET_CROSS) \
27 LZMA_TEXT_START=$(LOADER_ENTRY)
28
29 define Build/Compile
30 rm -rf $(KDIR)/relocate
31 $(CP) ../../generic/image/relocate $(KDIR)
32 $(MAKE) -C $(KDIR)/relocate $(RELOCATE_MAKEOPTS)
33 endef
34
35 ### Kernel scripts ###
36 define Build/hcs-initramfs
37 $(STAGING_DIR_HOST)/bin/hcsmakeimage --magic_bytes=$(HCS_MAGIC_BYTES) \
38 --rev_maj=$(HCS_REV_MAJ) --rev_min=$(HCS_REV_MIN) --input_file=$@ \
39 --output_file=$@.hcs --ldaddress=$(KERNEL_LOADADDR)
40 mv $@.hcs $@
41 endef
42
43 define Build/loader-lzma
44 rm -rf $@.src
45 $(MAKE) -C lzma-loader \
46 $(LOADER_MAKEOPTS) \
47 PKG_BUILD_DIR="$@.src" \
48 TARGET_DIR="$(dir $@)" \
49 LOADER_DATA="$@" \
50 LOADER_NAME="$(notdir $@)" \
51 compile loader.$(1)
52 mv "$@.$(1)" "$@"
53 rm -rf $@.src
54 endef
55
56 define Build/lzma
57 # CFE is a LZMA nazi! It took me hours to find out the parameters!
58 # Also I think lzma has a bug cause it generates different output depending on
59 # if you use stdin / stdout or not. Use files instead of stdio here, cause
60 # otherwise CFE will complain and not boot the image.
61 $(STAGING_DIR_HOST)/bin/lzma e $@ -d22 -fb64 -a1 $@.lzma
62 mv $@.lzma $@
63 endef
64
65 define Build/lzma-cfe
66 # Strip out the length, CFE doesn't like this
67 dd if=$@ of=$@.lzma.cfe bs=5 count=1
68 dd if=$@ of=$@.lzma.cfe ibs=13 obs=5 skip=1 seek=1 conv=notrunc
69 mv $@.lzma.cfe $@
70 endef
71
72 define Build/relocate-kernel
73 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
74 # kernel might get larger than that, so let CFE unpack and load at a
75 # higher address and make the kernel relocate itself to the expected
76 # location.
77 ( \
78 dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
79 perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
80 cat $@ \
81 ) > $@.relocate
82 mv $@.relocate $@
83 endef
84
85 ### Image scripts ###
86 define rootfspad/jffs2-128k
87 --align-rootfs
88 endef
89 define rootfspad/jffs2-64k
90 --align-rootfs
91 endef
92 define rootfspad/squashfs
93 endef
94
95 define Image/LimitName16
96 $(shell expr substr "$(1)" 1 16)
97 endef
98
99 define Image/FileSystemStrip
100 $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
101 endef
102
103 define Build/cfe-bin
104 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
105 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CFE_CHIP_ID) \
106 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
107 --info1 "$(call Image/LimitName16,$(DEVICE_NAME))" \
108 --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
109 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
110 $(CFE_EXTRAS) $(1)
111 endef
112
113 define Build/cfe-old-bin
114 $(TOPDIR)/scripts/brcmImage.pl -t -p \
115 -o $@ -b $(CFE_BOARD_ID) -c $(CFE_CHIP_ID) \
116 -e $(LOADER_ENTRY) -a $(LOADER_ENTRY) \
117 -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) \
118 $(CFE_EXTRAS)
119 endef
120
121 define Build/cfe-spw303v-bin
122 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
123 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CFE_CHIP_ID) \
124 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
125 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
126 $(CFE_EXTRAS) $(1)
127 endef
128
129 define Build/spw303v-bin
130 $(STAGING_DIR_HOST)/bin/spw303v -i $@ -o $@.spw303v
131 mv $@.spw303v $@
132 endef
133
134 define Build/zyxel-bin
135 $(STAGING_DIR_HOST)/bin/zyxbcm -i $@ -o $@.zyxel
136 mv $@.zyxel $@
137 endef
138
139 define Build/redboot-bin
140 # Prepare kernel and rootfs
141 dd if=$(IMAGE_KERNEL) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz bs=65536 conv=sync
142 dd if=$(IMAGE_ROOTFS) of=$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) bs=64k conv=sync
143 echo -ne \\xDE\\xAD\\xC0\\xDE >> $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))
144 # Generate the scripted image
145 $(TOPDIR)/scripts/redboot-script.pl \
146 -k $(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz \
147 -r $(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS)) \
148 -a $(strip $(LOADER_ENTRY)) -f 0xbe430000 -l 0x7c0000 \
149 -s 0x1000 -t 20 -o $@.redbootscript
150 dd if="$@.redbootscript" of="$@.redbootscript.padded" bs=4096 conv=sync
151 cat \
152 "$@.redbootscript.padded" \
153 "$(BIN_DIR)/$(REDBOOT_PREFIX)-vmlinux.gz" \
154 "$(BIN_DIR)/$(REDBOOT_PREFIX)-$(notdir $(IMAGE_ROOTFS))" \
155 > "$@"
156 endef
157
158 define Device/Default
159 PROFILES = Default $$(DEVICE_NAME)
160 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
161 KERNEL_INITRAMFS_SUFFIX := .elf
162 DEVICE_DTS_DIR := ../dts
163 SOC = bcm$$(CFE_CHIP_ID)
164 DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
165 endef
166
167 ATH5K_PACKAGES := kmod-ath5k wpad-basic
168 ATH9K_PACKAGES := kmod-ath9k wpad-basic
169 B43_PACKAGES := kmod-b43 wpad-basic
170 BRCMWL_PACKAGES := kmod-brcm-wl nas wlc
171 RT28_PACKAGES := kmod-rt2800-pci wpad-basic
172 RT61_PACKAGES := kmod-rt61-pci wpad-basic
173 USB1_PACKAGES := kmod-usb-ohci kmod-usb-ledtrig-usbport
174 USB2_PACKAGES := kmod-usb2 kmod-usb-ohci kmod-usb-ledtrig-usbport
175
176 include bcm63xx.mk
177
178 $(eval $(call BuildImage))