mac80211: brcmfmac: update Raspberry Pi patches for linux 4.9
[openwrt/openwrt.git] / include / image-commands.mk
1 # Build commands that can be called from Device/* templates
2
3 IMAGE_KERNEL = $(word 1,$^)
4 IMAGE_ROOTFS = $(word 2,$^)
5
6 define Build/uImage
7 mkimage -A $(LINUX_KARCH) \
8 -O linux -T kernel \
9 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
10 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION))' -d $@ $@.new
11 @mv $@.new $@
12 endef
13
14 define Build/buffalo-enc
15 $(eval product=$(word 1,$(1)))
16 $(eval version=$(word 2,$(1)))
17 $(eval args=$(wordlist 3,$(words $(1)),$(1)))
18 $(STAGING_DIR_HOST)/bin/buffalo-enc \
19 -p $(product) -v $(version) $(args) \
20 -i $@ -o $@.new
21 mv $@.new $@
22 endef
23
24 define Build/buffalo-enc-tag
25 $(call Build/buffalo-enc,'' '' -S 152 $(1))
26 endef
27
28 define Build/buffalo-tag-dhp
29 $(eval product=$(word 1,$(1)))
30 $(eval region=$(word 2,$(1)))
31 $(eval language=$(word 3,$(1)))
32 $(STAGING_DIR_HOST)/bin/buffalo-tag \
33 -d 0x01000000 -w 1 \
34 -a $(BUFFALO_TAG_PLATFORM) \
35 -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
36 -b $(product) -p $(product) \
37 -r $(region) -r $(region) -l $(language) \
38 -I $@ -o $@.new
39 mv $@.new $@
40 endef
41
42 define Build/buffalo-dhp-image
43 $(STAGING_DIR_HOST)/bin/mkdhpimg $@ $@.new
44 mv $@.new $@
45 endef
46
47 define Build/netgear-chk
48 $(STAGING_DIR_HOST)/bin/mkchkimg \
49 -o $@.new \
50 -k $@ \
51 -b $(NETGEAR_BOARD_ID) \
52 -r $(NETGEAR_REGION)
53 mv $@.new $@
54 endef
55
56 define Build/netgear-dni
57 $(STAGING_DIR_HOST)/bin/mkdniimg \
58 -B $(NETGEAR_BOARD_ID) -v LEDE.$(REVISION) \
59 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
60 -r "$(1)" \
61 -i $@ -o $@.new
62 mv $@.new $@
63 endef
64
65 # append a fake/empty rootfs uImage header, to fool the bootloaders
66 # rootfs integrity check
67 define Build/append-uImage-fakeroot-hdr
68 rm -f $@.fakeroot
69 $(STAGING_DIR_HOST)/bin/mkimage \
70 -A $(LINUX_KARCH) -O linux -T filesystem -C none \
71 -n '$(call toupper,$(LINUX_KARCH)) LEDE fakeroot' \
72 -s \
73 $@.fakeroot
74 cat $@.fakeroot >> $@
75 endef
76
77 define Build/tplink-safeloader
78 -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
79 -B $(TPLINK_BOARD_NAME) \
80 -V $(REVISION) \
81 -k $(IMAGE_KERNEL) \
82 -r $@ \
83 -o $@.new \
84 -j \
85 $(wordlist 2,$(words $(1)),$(1)) \
86 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
87 endef
88
89 define Build/append-dtb
90 $(call Image/BuildDTB,$(if $(DEVICE_DTS_DIR),$(DEVICE_DTS_DIR),$(DTS_DIR))/$(DEVICE_DTS).dts,$@.dtb)
91 cat $@.dtb >> $@
92 endef
93
94 define Build/install-dtb
95 $(foreach dts,$(DEVICE_DTS), \
96 $(CP) \
97 $(DTS_DIR)/$(dts).dtb \
98 $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
99 )
100 endef
101
102 define Build/fit
103 $(TOPDIR)/scripts/mkits.sh \
104 -D $(DEVICE_NAME) -o $@.its -k $@ \
105 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
106 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
107 -A $(LINUX_KARCH) -v $(LINUX_VERSION)
108 PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
109 @mv $@.new $@
110 endef
111
112 define Build/lzma
113 $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
114 endef
115
116 define Build/lzma-no-dict
117 $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
118 @mv $@.new $@
119 endef
120
121 define Build/gzip
122 gzip -9n -c $@ $(1) > $@.new
123 @mv $@.new $@
124 endef
125
126 define Build/jffs2
127 rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
128 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
129 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
130 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
131 $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
132 --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
133 -o $@.new \
134 -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
135 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
136 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
137 -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
138 @mv $@.new $@
139 endef
140
141 define Build/kernel-bin
142 rm -f $@
143 cp $< $@
144 endef
145
146 define Build/patch-cmdline
147 $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
148 endef
149
150 define Build/append-kernel
151 dd if=$(IMAGE_KERNEL) >> $@
152 endef
153
154 define Build/append-rootfs
155 dd if=$(IMAGE_ROOTFS) >> $@
156 endef
157
158 define Build/append-ubi
159 sh $(TOPDIR)/scripts/ubinize-image.sh \
160 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
161 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
162 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
163 $(IMAGE_ROOTFS) \
164 $@.tmp \
165 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
166 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
167 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
168 $(UBINIZE_OPTS)
169 cat $@.tmp >> $@
170 rm $@.tmp
171 endef
172
173 define Build/pad-to
174 dd if=$@ of=$@.new bs=$(1) conv=sync
175 mv $@.new $@
176 endef
177
178 define Build/pad-extra
179 dd if=/dev/zero bs=$(1) count=1 >> $@
180 endef
181
182 define Build/pad-rootfs
183 $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
184 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
185 endef
186
187 define Build/pad-offset
188 let \
189 size="$$(stat -c%s $@)" \
190 pad="$(subst k,* 1024,$(word 1, $(1)))" \
191 offset="$(subst k,* 1024,$(word 2, $(1)))" \
192 pad="(pad - ((size + offset) % pad)) % pad" \
193 newsize='size + pad'; \
194 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
195 mv $@.new $@
196 endef
197
198 define Build/check-size
199 @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
200 echo "WARNING: Image file $@ is too big" >&2; \
201 rm -f $@; \
202 }
203 endef
204
205 define Build/combined-image
206 -sh $(TOPDIR)/scripts/combined-image.sh \
207 "$(IMAGE_KERNEL)" \
208 "$@" \
209 "$@.new"
210 @mv $@.new $@
211 endef
212
213 define Build/sysupgrade-tar
214 sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
215 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
216 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
217 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
218 $@
219 endef
220
221 json_quote=$(subst ','\'',$(subst ",\",$(1)))
222 #")')
223 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
224 metadata_json = \
225 '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
226 "supported_devices":[$(call metadata_devices,$(1))], \
227 "version": { \
228 "dist": "$(call json_quote,$(VERSION_DIST))", \
229 "version": "$(call json_quote,$(VERSION_NUMBER))", \
230 "revision": "$(call json_quote,$(REVISION))", \
231 "board": "$(call json_quote,$(BOARD))" \
232 } \
233 }'
234
235 define Build/append-metadata
236 $(if $(SUPPORTED_DEVICES),echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
237 endef
238
239 define Build/kernel2minor
240 kernel2minor -k $@ -r $@.new $(1)
241 mv $@.new $@
242 endef