image-commands.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. touch [email protected]
  98. $(STAGING_DIR_HOST)/bin/mkimage \
  99. -A $(LINUX_KARCH) -O linux -T $(1) -C none \
  100. -n '$(VERSION_DIST) fake $(1)' \
  101. -d [email protected] \
  102. -s \
  103. [email protected]
  104. cat [email protected] >> $@
  105. endef
  106. define Build/tplink-safeloader
  107. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  108. -B $(TPLINK_BOARD_ID) \
  109. -V $(REVISION) \
  110. -k $(IMAGE_KERNEL) \
  111. -r $@ \
  112. -o [email protected] \
  113. -j \
  114. $(wordlist 2,$(words $(1)),$(1)) \
  115. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  116. endef
  117. define Build/append-dtb
  118. cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
  119. endef
  120. define Build/install-dtb
  121. $(call locked, \
  122. $(foreach dts,$(DEVICE_DTS), \
  123. $(CP) \
  124. $(DTS_DIR)/$(dts).dtb \
  125. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  126. ), \
  127. install-dtb-$(IMG_PREFIX) \
  128. )
  129. endef
  130. define Build/fit
  131. $(TOPDIR)/scripts/mkits.sh \
  132. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  133. $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
  134. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  135. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
  136. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  137. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  138. @mv [email protected] $@
  139. endef
  140. define Build/lzma
  141. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  142. endef
  143. define Build/lzma-no-dict
  144. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  145. @mv [email protected] $@
  146. endef
  147. define Build/gzip
  148. gzip -f -9n -c $@ $(1) > [email protected]
  149. @mv [email protected] $@
  150. endef
  151. define Build/zip
  152. mkdir [email protected]
  153. mv $@ [email protected]/$(1)
  154. zip -j -X \
  155. $(if $(SOURCE_DATE_EPOCH),--mtime="$(SOURCE_DATE_EPOCH)") \
  156. $@ [email protected]/$(if $(1),$(1),$@)
  157. rm -rf [email protected]
  158. endef
  159. define Build/jffs2
  160. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  161. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  162. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  163. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  164. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  165. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  166. -o [email protected] \
  167. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  168. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  169. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  170. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  171. @mv [email protected] $@
  172. endef
  173. define Build/kernel-bin
  174. rm -f $@
  175. cp $< $@
  176. endef
  177. define Build/patch-cmdline
  178. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  179. endef
  180. define Build/append-kernel
  181. dd if=$(IMAGE_KERNEL) >> $@
  182. endef
  183. define Build/append-rootfs
  184. dd if=$(IMAGE_ROOTFS) >> $@
  185. endef
  186. define Build/append-ubi
  187. sh $(TOPDIR)/scripts/ubinize-image.sh \
  188. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  189. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  190. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  191. $(IMAGE_ROOTFS) \
  192. [email protected] \
  193. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  194. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  195. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  196. $(UBINIZE_OPTS)
  197. cat [email protected] >> $@
  198. rm [email protected]
  199. endef
  200. define Build/append-uboot
  201. dd if=$(UBOOT_PATH) >> $@
  202. endef
  203. define Build/pad-to
  204. $(call Image/pad-to,$@,$(1))
  205. endef
  206. define Build/pad-extra
  207. dd if=/dev/zero bs=$(1) count=1 >> $@
  208. endef
  209. define Build/pad-rootfs
  210. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  211. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  212. endef
  213. define Build/pad-offset
  214. let \
  215. size="$$(stat -c%s $@)" \
  216. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  217. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  218. pad="(pad - ((size + offset) % pad)) % pad" \
  219. newsize='size + pad'; \
  220. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  221. mv [email protected] $@
  222. endef
  223. define Build/xor-image
  224. $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o [email protected] $(1)
  225. mv [email protected] $@
  226. endef
  227. define Build/check-size
  228. @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
  229. echo "WARNING: Image file $@ is too big" >&2; \
  230. rm -f $@; \
  231. }
  232. endef
  233. define Build/combined-image
  234. -sh $(TOPDIR)/scripts/combined-image.sh \
  235. "$(IMAGE_KERNEL)" \
  236. "$@" \
  237. "[email protected]"
  238. @mv [email protected] $@
  239. endef
  240. define Build/linksys-image
  241. $(TOPDIR)/scripts/linksys-image.sh \
  242. "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
  243. $@ [email protected]
  244. mv [email protected] $@
  245. endef
  246. define Build/openmesh-image
  247. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  248. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  249. "[email protected]" \
  250. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  251. "$(call param_get_default,rootfs,$(1),$@)"
  252. $(TOPDIR)/scripts/combined-ext-image.sh \
  253. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  254. "[email protected]" "fwupgrade.cfg" \
  255. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  256. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  257. endef
  258. define Build/qsdk-ipq-factory-nand
  259. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  260. [email protected] ubi $@
  261. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  262. @mv [email protected] $@
  263. endef
  264. define Build/qsdk-ipq-factory-nor
  265. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  266. [email protected] hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
  267. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  268. @mv [email protected] $@
  269. endef
  270. define Build/senao-header
  271. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  272. mv [email protected] $@
  273. endef
  274. define Build/sysupgrade-tar
  275. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  276. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  277. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  278. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  279. $@
  280. endef
  281. define Build/tplink-v1-header
  282. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  283. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  284. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  285. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  286. -k $@ -o [email protected] $(1)
  287. @mv [email protected] $@
  288. endef
  289. define Build/tplink-v2-header
  290. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  291. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  292. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  293. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  294. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  295. -k $@ -o [email protected] $(1)
  296. @mv [email protected] $@
  297. endef
  298. define Build/tplink-v2-image
  299. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  300. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  301. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  302. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  303. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  304. cat [email protected] >> $@
  305. rm -rf [email protected]
  306. endef
  307. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  308. #")')
  309. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  310. metadata_json = \
  311. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  312. "metadata_version": "1.0", \
  313. "supported_devices":[$(call metadata_devices,$(1))], \
  314. "version": { \
  315. "dist": "$(call json_quote,$(VERSION_DIST))", \
  316. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  317. "revision": "$(call json_quote,$(REVISION))", \
  318. "target": "$(call json_quote,$(TARGETID))", \
  319. "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
  320. } \
  321. }'
  322. define Build/append-metadata
  323. $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
  324. [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
  325. cp "$(BUILD_KEY).ucert" "[email protected]" ;\
  326. usign -S -m "$@" -s "$(BUILD_KEY)" -x "[email protected]" ;\
  327. ucert -A -c "[email protected]" -x "[email protected]" ;\
  328. fwtool -S "[email protected]" "$@" ;\
  329. }
  330. endef
  331. define Build/kernel2minor
  332. kernel2minor -k $@ -r [email protected] $(1)
  333. mv [email protected] $@
  334. endef