image-commands.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. # Build commands that can be called from Device/* templates
  2. IMAGE_KERNEL = $(word 1,$^)
  3. IMAGE_ROOTFS = $(word 2,$^)
  4. define Build/uImage
  5. mkimage -A $(LINUX_KARCH) \
  6. -O linux -T kernel \
  7. -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  8. -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' -d $@ [email protected]
  9. mv [email protected] $@
  10. endef
  11. define Build/buffalo-enc
  12. $(eval product=$(word 1,$(1)))
  13. $(eval version=$(word 2,$(1)))
  14. $(eval args=$(wordlist 3,$(words $(1)),$(1)))
  15. $(STAGING_DIR_HOST)/bin/buffalo-enc \
  16. -p $(product) -v $(version) $(args) \
  17. -i $@ -o [email protected]
  18. mv [email protected] $@
  19. endef
  20. define Build/buffalo-enc-tag
  21. $(call Build/buffalo-enc,'' '' -S 152 $(1))
  22. endef
  23. define Build/buffalo-tag-dhp
  24. $(eval product=$(word 1,$(1)))
  25. $(eval region=$(word 2,$(1)))
  26. $(eval language=$(word 3,$(1)))
  27. $(STAGING_DIR_HOST)/bin/buffalo-tag \
  28. -d 0x01000000 -w 1 \
  29. -a $(BUFFALO_TAG_PLATFORM) \
  30. -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
  31. -b $(product) -p $(product) \
  32. -r $(region) -r $(region) -l $(language) \
  33. -I $@ -o [email protected]
  34. mv [email protected] $@
  35. endef
  36. define Build/buffalo-dhp-image
  37. $(STAGING_DIR_HOST)/bin/mkdhpimg $@ [email protected]
  38. mv [email protected] $@
  39. endef
  40. define Build/eva-image
  41. $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ [email protected]
  42. mv [email protected] $@
  43. endef
  44. define Build/seama
  45. $(STAGING_DIR_HOST)/bin/seama -i $@ \
  46. -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
  47. mv [email protected] $@
  48. endef
  49. define Build/seama-seal
  50. $(STAGING_DIR_HOST)/bin/seama -i $@ -s [email protected] \
  51. -m "signature=$(SEAMA_SIGNATURE)"
  52. mv [email protected] $@
  53. endef
  54. define Build/zyxel-ras-image
  55. let \
  56. newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
  57. $(STAGING_DIR_HOST)/bin/mkrasimage \
  58. -b $(RAS_BOARD) \
  59. -v $(RAS_VERSION) \
  60. -r $@ \
  61. -s $$newsize \
  62. -o [email protected] \
  63. $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
  64. && mv [email protected] $@
  65. endef
  66. define Build/netgear-chk
  67. $(STAGING_DIR_HOST)/bin/mkchkimg \
  68. -o [email protected] \
  69. -k $@ \
  70. -b $(NETGEAR_BOARD_ID) \
  71. $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
  72. mv [email protected] $@
  73. endef
  74. define Build/netgear-dni
  75. $(STAGING_DIR_HOST)/bin/mkdniimg \
  76. -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
  77. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  78. -r "$(1)" \
  79. -i $@ -o [email protected]
  80. mv [email protected] $@
  81. endef
  82. define Build/append-squashfs-fakeroot-be
  83. rm -rf [email protected] [email protected]
  84. mkdir [email protected]
  85. $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
  86. [email protected] [email protected] \
  87. -noappend -root-owned -be -nopad -b 65536 \
  88. $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
  89. cat [email protected] >> $@
  90. endef
  91. define Build/append-string
  92. echo -n $(1) >> $@
  93. endef
  94. # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
  95. # for example
  96. define Build/append-uImage-fakehdr
  97. $(eval type=$(word 1,$(1)))
  98. $(eval magic=$(word 2,$(1)))
  99. touch [email protected]
  100. $(STAGING_DIR_HOST)/bin/mkimage \
  101. -A $(LINUX_KARCH) -O linux -T $(type) -C none \
  102. -n '$(VERSION_DIST) fake $(type)' \
  103. $(if $(magic),-M $(magic)) \
  104. -d [email protected] \
  105. -s \
  106. [email protected]
  107. cat [email protected] >> $@
  108. endef
  109. define Build/tplink-safeloader
  110. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  111. -B $(TPLINK_BOARD_ID) \
  112. -V $(REVISION) \
  113. -k $(IMAGE_KERNEL) \
  114. -r $@ \
  115. -o [email protected] \
  116. -j \
  117. $(wordlist 2,$(words $(1)),$(1)) \
  118. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  119. endef
  120. define Build/append-dtb
  121. cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
  122. endef
  123. define Build/install-dtb
  124. $(call locked, \
  125. $(foreach dts,$(DEVICE_DTS), \
  126. $(CP) \
  127. $(DTS_DIR)/$(dts).dtb \
  128. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  129. ), \
  130. install-dtb-$(IMG_PREFIX) \
  131. )
  132. endef
  133. define Build/fit
  134. $(TOPDIR)/scripts/mkits.sh \
  135. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  136. $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
  137. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  138. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
  139. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  140. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  141. @mv [email protected] $@
  142. endef
  143. define Build/lzma
  144. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  145. endef
  146. define Build/lzma-no-dict
  147. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  148. @mv [email protected] $@
  149. endef
  150. define Build/gzip
  151. gzip -f -9n -c $@ $(1) > [email protected]
  152. @mv [email protected] $@
  153. endef
  154. define Build/zip
  155. mkdir [email protected]
  156. mv $@ [email protected]/$(1)
  157. zip -j -X \
  158. $(if $(SOURCE_DATE_EPOCH),--mtime="$(SOURCE_DATE_EPOCH)") \
  159. $@ [email protected]/$(if $(1),$(1),$@)
  160. rm -rf [email protected]
  161. endef
  162. define Build/jffs2
  163. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  164. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  165. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  166. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  167. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  168. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  169. -o [email protected] \
  170. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  171. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  172. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  173. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  174. @mv [email protected] $@
  175. endef
  176. define Build/kernel-bin
  177. rm -f $@
  178. cp $< $@
  179. endef
  180. define Build/patch-cmdline
  181. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  182. endef
  183. define Build/append-kernel
  184. dd if=$(IMAGE_KERNEL) >> $@
  185. endef
  186. define Build/append-rootfs
  187. dd if=$(IMAGE_ROOTFS) >> $@
  188. endef
  189. define Build/append-ubi
  190. sh $(TOPDIR)/scripts/ubinize-image.sh \
  191. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  192. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  193. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  194. $(IMAGE_ROOTFS) \
  195. [email protected] \
  196. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  197. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  198. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  199. $(UBINIZE_OPTS)
  200. cat [email protected] >> $@
  201. rm [email protected]
  202. endef
  203. define Build/append-uboot
  204. dd if=$(UBOOT_PATH) >> $@
  205. endef
  206. define Build/pad-to
  207. $(call Image/pad-to,$@,$(1))
  208. endef
  209. define Build/pad-extra
  210. dd if=/dev/zero bs=$(1) count=1 >> $@
  211. endef
  212. define Build/pad-rootfs
  213. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  214. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  215. endef
  216. define Build/pad-offset
  217. let \
  218. size="$$(stat -c%s $@)" \
  219. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  220. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  221. pad="(pad - ((size + offset) % pad)) % pad" \
  222. newsize='size + pad'; \
  223. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  224. mv [email protected] $@
  225. endef
  226. define Build/xor-image
  227. $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o [email protected] $(1)
  228. mv [email protected] $@
  229. endef
  230. define Build/check-size
  231. @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
  232. echo "WARNING: Image file $@ is too big" >&2; \
  233. rm -f $@; \
  234. }
  235. endef
  236. define Build/combined-image
  237. -sh $(TOPDIR)/scripts/combined-image.sh \
  238. "$(IMAGE_KERNEL)" \
  239. "$@" \
  240. "[email protected]"
  241. @mv [email protected] $@
  242. endef
  243. define Build/linksys-image
  244. $(TOPDIR)/scripts/linksys-image.sh \
  245. "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
  246. $@ [email protected]
  247. mv [email protected] $@
  248. endef
  249. define Build/openmesh-image
  250. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  251. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  252. "[email protected]" \
  253. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  254. "$(call param_get_default,rootfs,$(1),$@)"
  255. $(TOPDIR)/scripts/combined-ext-image.sh \
  256. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  257. "[email protected]" "fwupgrade.cfg" \
  258. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  259. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  260. endef
  261. define Build/qsdk-ipq-factory-nand
  262. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  263. [email protected] ubi $@
  264. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  265. @mv [email protected] $@
  266. endef
  267. define Build/qsdk-ipq-factory-nor
  268. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  269. [email protected] hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
  270. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  271. @mv [email protected] $@
  272. endef
  273. define Build/senao-header
  274. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  275. mv [email protected] $@
  276. endef
  277. define Build/sysupgrade-tar
  278. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  279. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  280. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  281. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  282. $@
  283. endef
  284. define Build/tplink-v1-header
  285. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  286. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  287. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  288. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  289. -k $@ -o [email protected] $(1)
  290. @mv [email protected] $@
  291. endef
  292. define Build/tplink-v2-header
  293. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  294. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  295. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  296. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  297. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  298. -k $@ -o [email protected] $(1)
  299. @mv [email protected] $@
  300. endef
  301. define Build/tplink-v2-image
  302. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  303. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  304. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  305. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  306. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  307. cat [email protected] >> $@
  308. rm -rf [email protected]
  309. endef
  310. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  311. #")')
  312. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  313. metadata_json = \
  314. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  315. "metadata_version": "1.0", \
  316. "supported_devices":[$(call metadata_devices,$(1))], \
  317. "version": { \
  318. "dist": "$(call json_quote,$(VERSION_DIST))", \
  319. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  320. "revision": "$(call json_quote,$(REVISION))", \
  321. "target": "$(call json_quote,$(TARGETID))", \
  322. "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
  323. } \
  324. }'
  325. define Build/append-metadata
  326. $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
  327. [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
  328. cp "$(BUILD_KEY).ucert" "[email protected]" ;\
  329. usign -S -m "$@" -s "$(BUILD_KEY)" -x "[email protected]" ;\
  330. ucert -A -c "[email protected]" -x "[email protected]" ;\
  331. fwtool -S "[email protected]" "$@" ;\
  332. }
  333. endef
  334. define Build/kernel2minor
  335. kernel2minor -k $@ -r [email protected] $(1)
  336. mv [email protected] $@
  337. endef