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