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