image-commands.mk 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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/zyxel-ras-image
  45. let \
  46. newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
  47. $(STAGING_DIR_HOST)/bin/mkrasimage \
  48. -b $(RAS_BOARD) \
  49. -v $(RAS_VERSION) \
  50. -r $@ \
  51. -s $$newsize \
  52. -o [email protected] \
  53. $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
  54. && mv [email protected] $@
  55. endef
  56. define Build/netgear-chk
  57. $(STAGING_DIR_HOST)/bin/mkchkimg \
  58. -o [email protected] \
  59. -k $@ \
  60. -b $(NETGEAR_BOARD_ID) \
  61. $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
  62. mv [email protected] $@
  63. endef
  64. define Build/netgear-dni
  65. $(STAGING_DIR_HOST)/bin/mkdniimg \
  66. -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
  67. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  68. -r "$(1)" \
  69. -i $@ -o [email protected]
  70. mv [email protected] $@
  71. endef
  72. define Build/append-squashfs-fakeroot-be
  73. rm -rf [email protected] [email protected]
  74. mkdir [email protected]
  75. $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
  76. [email protected] [email protected] \
  77. -noappend -root-owned -be -nopad -b 65536 \
  78. $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
  79. cat [email protected] >> $@
  80. endef
  81. # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
  82. # for example
  83. define Build/append-uImage-fakehdr
  84. touch [email protected]
  85. $(STAGING_DIR_HOST)/bin/mkimage \
  86. -A $(LINUX_KARCH) -O linux -T $(1) -C none \
  87. -n '$(VERSION_DIST) fake $(1)' \
  88. -d [email protected] \
  89. -s \
  90. [email protected]
  91. cat [email protected] >> $@
  92. endef
  93. define Build/tplink-safeloader
  94. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  95. -B $(TPLINK_BOARD_ID) \
  96. -V $(REVISION) \
  97. -k $(IMAGE_KERNEL) \
  98. -r $@ \
  99. -o [email protected] \
  100. -j \
  101. $(wordlist 2,$(words $(1)),$(1)) \
  102. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  103. endef
  104. define Build/mksercommfw
  105. -$(STAGING_DIR_HOST)/bin/mksercommfw \
  106. $@ \
  107. $(KERNEL_OFFSET) \
  108. $(HWID) \
  109. $(HWVER) \
  110. $(SWVER)
  111. endef
  112. define Build/append-dtb
  113. cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
  114. endef
  115. define Build/install-dtb
  116. $(foreach dts,$(DEVICE_DTS), \
  117. $(CP) \
  118. $(DTS_DIR)/$(dts).dtb \
  119. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  120. )
  121. endef
  122. define Build/fit
  123. $(TOPDIR)/scripts/mkits.sh \
  124. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  125. $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
  126. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  127. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
  128. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  129. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  130. @mv [email protected] $@
  131. endef
  132. define Build/lzma
  133. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  134. endef
  135. define Build/lzma-no-dict
  136. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  137. @mv [email protected] $@
  138. endef
  139. define Build/gzip
  140. gzip -f -9n -c $@ $(1) > [email protected]
  141. @mv [email protected] $@
  142. endef
  143. define Build/jffs2
  144. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  145. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  146. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  147. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  148. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  149. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  150. -o [email protected] \
  151. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  152. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  153. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  154. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  155. @mv [email protected] $@
  156. endef
  157. define Build/kernel-bin
  158. rm -f $@
  159. cp $< $@
  160. endef
  161. define Build/patch-cmdline
  162. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  163. endef
  164. define Build/append-kernel
  165. dd if=$(IMAGE_KERNEL) >> $@
  166. endef
  167. define Build/append-rootfs
  168. dd if=$(IMAGE_ROOTFS) >> $@
  169. endef
  170. define Build/append-ubi
  171. sh $(TOPDIR)/scripts/ubinize-image.sh \
  172. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  173. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  174. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  175. $(IMAGE_ROOTFS) \
  176. [email protected] \
  177. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  178. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  179. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  180. $(UBINIZE_OPTS)
  181. cat [email protected] >> $@
  182. rm [email protected]
  183. endef
  184. define Build/append-uboot
  185. dd if=$(UBOOT_PATH) >> $@
  186. endef
  187. define Build/pad-to
  188. dd if=$@ [email protected] bs=$(1) conv=sync
  189. mv [email protected] $@
  190. endef
  191. define Build/pad-extra
  192. dd if=/dev/zero bs=$(1) count=1 >> $@
  193. endef
  194. define Build/pad-rootfs
  195. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  196. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  197. endef
  198. define Build/pad-offset
  199. let \
  200. size="$$(stat -c%s $@)" \
  201. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  202. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  203. pad="(pad - ((size + offset) % pad)) % pad" \
  204. newsize='size + pad'; \
  205. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  206. mv [email protected] $@
  207. endef
  208. define Build/check-size
  209. @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
  210. echo "WARNING: Image file $@ is too big" >&2; \
  211. rm -f $@; \
  212. }
  213. endef
  214. define Build/combined-image
  215. -sh $(TOPDIR)/scripts/combined-image.sh \
  216. "$(IMAGE_KERNEL)" \
  217. "$@" \
  218. "[email protected]"
  219. @mv [email protected] $@
  220. endef
  221. define Build/openmesh-image
  222. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  223. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  224. "[email protected]" \
  225. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  226. "$(call param_get_default,rootfs,$(1),$@)"
  227. $(TOPDIR)/scripts/combined-ext-image.sh \
  228. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  229. "[email protected]" "fwupgrade.cfg" \
  230. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  231. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  232. endef
  233. define Build/senao-header
  234. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  235. mv [email protected] $@
  236. endef
  237. define Build/sysupgrade-tar
  238. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  239. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  240. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  241. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  242. $@
  243. endef
  244. define Build/tplink-v1-header
  245. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  246. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  247. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  248. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  249. -k $@ -o [email protected] $(1)
  250. @mv [email protected] $@
  251. endef
  252. define Build/tplink-v2-header
  253. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  254. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  255. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  256. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  257. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  258. -k $@ -o [email protected] $(1)
  259. @mv [email protected] $@
  260. endef
  261. define Build/tplink-v2-image
  262. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  263. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  264. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  265. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  266. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  267. cat [email protected] >> $@
  268. rm -rf [email protected]
  269. endef
  270. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  271. #")')
  272. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  273. metadata_json = \
  274. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  275. "supported_devices":[$(call metadata_devices,$(1))], \
  276. "version": { \
  277. "dist": "$(call json_quote,$(VERSION_DIST))", \
  278. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  279. "revision": "$(call json_quote,$(REVISION))", \
  280. "board": "$(call json_quote,$(BOARD))" \
  281. } \
  282. }'
  283. define Build/append-metadata
  284. $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
  285. [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
  286. cp "$(BUILD_KEY).ucert" "[email protected]" ;\
  287. usign -S -m "$@" -s "$(BUILD_KEY)" -x "[email protected]" ;\
  288. ucert -A -c "[email protected]" -x "[email protected]" ;\
  289. fwtool -S "[email protected]" "$@" ;\
  290. }
  291. endef
  292. define Build/kernel2minor
  293. kernel2minor -k $@ -r [email protected] $(1)
  294. mv [email protected] $@
  295. endef