bmips: image: rename SERCOMM_VERSION to SERCOMM_FSVER
[openwrt/staging/dedeckeh.git] / target / linux / bmips / image / Makefile
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 include $(TOPDIR)/rules.mk
4 include $(INCLUDE_DIR)/image.mk
5
6 KERNEL_LOADADDR := 0x80010000 # RAM start + 64K
7 LOADER_ENTRY := 0x80a00000 # RAM start + 10M, for relocate
8 LZMA_TEXT_START := 0x81800000 # RAM start + 24M
9
10 DEVICE_VARS += CHIP_ID DEVICE_LOADADDR
11
12 define Build/Compile
13 rm -rf $(KDIR)/relocate
14 $(CP) ../../generic/image/relocate $(KDIR)
15 $(MAKE) -C $(KDIR)/relocate \
16 CACHELINE_SIZE=16 \
17 CROSS_COMPILE=$(TARGET_CROSS) \
18 KERNEL_ADDR=$(KERNEL_LOADADDR) \
19 LZMA_TEXT_START=$(LOADER_ENTRY)
20 endef
21
22 ### Kernel scripts ###
23 define Build/loader-lzma
24 @rm -rf $@.src
25 $(MAKE) -C lzma-loader \
26 CHIP_ID=$(CHIP_ID) \
27 KERNEL_ADDR=$(KERNEL_LOADADDR) \
28 KDIR=$(KDIR) \
29 LOADER_ADDR=$(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
30 LOADER_DATA="$@" \
31 LOADER_NAME="$(notdir $@)" \
32 LZMA_TEXT_START=$(LZMA_TEXT_START) \
33 PKG_BUILD_DIR="$@.src" \
34 TARGET_DIR="$(dir $@)" \
35 compile loader.$(1)
36 @mv "$@.$(1)" "$@"
37 @rm -rf $@.src
38 endef
39
40 define Build/lzma-cfe
41 # CFE is a LZMA nazi! It took me hours to find out the parameters!
42 # Also I think lzma has a bug cause it generates different output depending on
43 # if you use stdin / stdout or not. Use files instead of stdio here, cause
44 # otherwise CFE will complain and not boot the image.
45 $(call Build/lzma-no-dict,-d22 -fb64 -a1)
46 # Strip out the length, CFE doesn't like this
47 dd if=$@ of=$@.new bs=5 count=1
48 dd if=$@ of=$@.new ibs=13 obs=5 skip=1 seek=1 conv=notrunc
49 @mv $@.new $@
50 endef
51
52 define Build/relocate-kernel
53 # CFE only allows ~4 MiB for the uncompressed kernels, but uncompressed
54 # kernel might get larger than that, so let CFE unpack and load at a
55 # higher address and make the kernel relocate itself to the expected
56 # location.
57 ( \
58 dd if=$(KDIR)/relocate/loader.bin bs=32 conv=sync && \
59 perl -e '@s = stat("$@"); print pack("N", @s[7])' && \
60 cat $@ \
61 ) > $@.relocate
62 @mv $@.relocate $@
63 endef
64
65 ### Image scripts ###
66 define rootfspad/jffs2-128k
67 --align-rootfs
68 endef
69 define rootfspad/jffs2-64k
70 --align-rootfs
71 endef
72 define rootfspad/squashfs
73 endef
74
75 define Image/FileSystemStrip
76 $(firstword $(subst +,$(space),$(subst root.,,$(notdir $(1)))))
77 endef
78
79 define Build/cfe-bin
80 $(STAGING_DIR_HOST)/bin/imagetag -i $(IMAGE_KERNEL) -f $(IMAGE_ROOTFS) \
81 --output $@ --boardid $(CFE_BOARD_ID) --chipid $(CHIP_ID) \
82 --entry $(LOADER_ENTRY) --load-addr $(LOADER_ENTRY) \
83 --info1 "$(call ModelNameLimit16,$(DEVICE_NAME))" \
84 --info2 "$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))" \
85 $(call rootfspad/$(call Image/FileSystemStrip,$(IMAGE_ROOTFS))) \
86 $(CFE_EXTRAS) $(1)
87 endef
88
89 define Build/cfe-jffs2
90 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 \
91 --big-endian \
92 --pad \
93 --no-cleanmarkers \
94 --eraseblock=$(patsubst %k,%KiB,$(BLOCKSIZE)) \
95 --root=$(1) \
96 --output=$@ \
97 --compression-mode=none
98
99 $(call Build/pad-to,$(BLOCKSIZE))
100 endef
101
102 define Build/cfe-jffs2-cferam
103 mv $@ $@.kernel
104
105 rm -rf $@-cferam
106 mkdir -p $@-cferam
107
108 # CFE ROM checks JFFS2 dirent version of cferam.
109 # If version is not > 0 it will ignore the fs entry.
110 # JFFS2 sets version 0 to the first fs entry and increments
111 # it on the following ones, so let's create a dummy file that
112 # will have version 0 and let cferam be the second (version 1).
113 touch $@-cferam/1-openwrt
114 # Add cferam as the last file in the JFFS2 partition
115 cp $(KDIR)/bcm63xx-cfe/$(CFE_RAM_FILE) $@-cferam/$(CFE_RAM_JFFS2_NAME)
116
117 # The JFFS2 partition creation should result in the following
118 # layout:
119 # 1) 1-openwrt (version 0, ino 2)
120 # 2) cferam.000 (version 1, ino 3)
121 $(call Build/cfe-jffs2,$@-cferam)
122
123 # Some devices need padding between CFE RAM and kernel
124 $(if $(CFE_RAM_JFFS2_PAD),$(call Build/pad-to,$(CFE_RAM_JFFS2_PAD)))
125
126 # Add CFE partition tag
127 $(if $(CFE_PART_ID),$(call Build/cfe-part-tag))
128
129 # Append kernel
130 dd if=$@.kernel >> $@
131 rm -f $@.kernel
132 endef
133
134 define Build/cfe-jffs2-kernel
135 rm -rf $@-kernel
136 mkdir -p $@-kernel
137
138 # CFE RAM checks JFFS2 dirent version of vmlinux.
139 # If version is not > 0 it will ignore the fs entry.
140 # JFFS2 sets version 0 to the first fs entry and increments
141 # it on the following ones, so let's create a dummy file that
142 # will have version 0 and let cferam be the second (version 1).
143 touch $@-kernel/1-openwrt
144 # vmlinux is located on a different JFFS2 partition, but CFE RAM
145 # ignores it, so let's create another dummy file that will match
146 # the JFFS2 ino of cferam entry on the first JFFS2 partition.
147 # CFE RAM won't be able to find vmlinux if cferam has the same
148 # ino as vmlinux.
149 touch $@-kernel/2-openwrt
150 # Add vmlinux as the last file in the JFFS2 partition
151 $(TOPDIR)/scripts/cfe-bin-header.py \
152 --input-file $@ \
153 --output-file $@-kernel/vmlinux.lz \
154 --load-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY)) \
155 --entry-addr $(if $(DEVICE_LOADADDR),$(DEVICE_LOADADDR),$(LOADER_ENTRY))
156
157 # The JFFS2 partition creation should result in the following
158 # layout:
159 # 1) 1-openwrt (version 0, ino 2)
160 # 2) 2-openwrt (version 1, ino 3)
161 # 3) vmlinux.lz (version 2, ino 4)
162 $(call Build/cfe-jffs2,$@-kernel)
163 endef
164
165 define Build/cfe-part-tag
166 mv $@ $@.part
167
168 $(TOPDIR)/scripts/cfe-partition-tag.py \
169 --input-file $@.part \
170 --output-file $@ \
171 --flags $(CFE_PART_FLAGS) \
172 --id $(CFE_PART_ID) \
173 --name $(VERSION_CODE) \
174 --version $(DEVICE_NAME)
175
176 $(call Build/pad-to,$(BLOCKSIZE))
177
178 dd if=$@.part >> $@
179 endef
180
181 define Build/cfe-sercomm-crypto
182 $(TOPDIR)/scripts/sercomm-crypto.py \
183 --input-file $@ \
184 --key-file $@.key \
185 --output-file $@.ser \
186 --version OpenWrt
187 $(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
188 -in $@ -out $@.enc \
189 -K `cat $@.key` \
190 -iv 00000000000000000000000000000000
191 dd if=$@.enc >> $@.ser
192 mv $@.ser $@
193 rm -f $@.enc $@.key
194 endef
195
196 define Build/cfe-sercomm-load
197 $(TOPDIR)/scripts/sercomm-payload.py \
198 --input-file $@ \
199 --output-file $@.new \
200 --pid "$(SERCOMM_PID)"
201
202 mv $@.new $@
203 endef
204
205 define Build/cfe-sercomm-part
206 $(TOPDIR)/scripts/sercomm-partition-tag.py \
207 --input-file $@ \
208 --output-file $@.kernel_rootfs \
209 --part-name kernel_rootfs \
210 --part-version OpenWrt \
211 --rootfs-version $(SERCOMM_FSVER)
212
213 rm -rf $@-rootfs_lib
214 mkdir -p $@-rootfs_lib
215 echo $(SERCOMM_FSVER) > $@-rootfs_lib/lib_ver
216 $(call Build/cfe-jffs2,$@-rootfs_lib)
217 $(call Build/pad-to,$(BLOCKSIZE))
218 $(TOPDIR)/scripts/sercomm-partition-tag.py \
219 --input-file $@ \
220 --output-file $@.rootfs_lib \
221 --part-name rootfs_lib \
222 --part-version $(SERCOMM_FSVER)
223
224 mv $@.kernel_rootfs $@
225 dd if=$@.rootfs_lib >> $@
226 endef
227
228 define Build/cfe-wfi-tag
229 $(TOPDIR)/scripts/cfe-wfi-tag.py \
230 --input-file $@ \
231 --output-file $@.new \
232 --version $(if $(1),$(1),$(CFE_WFI_VERSION)) \
233 --chip-id $(CFE_WFI_CHIP_ID) \
234 --flash-type $(CFE_WFI_FLASH_TYPE) \
235 $(if $(CFE_WFI_FLAGS),--flags $(CFE_WFI_FLAGS))
236 mv $@.new $@
237 endef
238
239 ### Device scripts ###
240 define Device/Default
241 PROFILES = Default $$(DEVICE_NAME)
242 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
243 DEVICE_DTS_DIR := ../dts
244 CHIP_ID :=
245 SOC = bcm$$(CHIP_ID)
246 DEVICE_DTS = $$(SOC)-$(subst _,-,$(1))
247 DEVICE_LOADADDR :=
248 endef
249
250 ATH9K_PACKAGES := kmod-ath9k wpad-basic-mbedtls
251 B43_PACKAGES := kmod-b43 wpad-basic-mbedtls
252 USB1_PACKAGES := kmod-usb-ohci kmod-ledtrig-usbdev
253 USB2_PACKAGES := $(USB1_PACKAGES) kmod-usb2
254
255 include bcm63xx_$(SUBTARGET).mk
256
257 $(eval $(call BuildImage))