image-commands.mk 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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/make-ras
  45. let \
  46. newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
  47. $(TOPDIR)/scripts/make-ras.sh \
  48. --board $(RAS_BOARD) \
  49. --version $(RAS_VERSION) \
  50. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  51. --rootfs $@ \
  52. --rootfssize $$newsize \
  53. [email protected]
  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/append-dtb
  105. cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
  106. endef
  107. define Build/install-dtb
  108. $(foreach dts,$(DEVICE_DTS), \
  109. $(CP) \
  110. $(DTS_DIR)/$(dts).dtb \
  111. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  112. )
  113. endef
  114. define Build/fit
  115. $(TOPDIR)/scripts/mkits.sh \
  116. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  117. $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
  118. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  119. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config@1") \
  120. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  121. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  122. @mv [email protected] $@
  123. endef
  124. define Build/lzma
  125. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  126. endef
  127. define Build/lzma-no-dict
  128. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  129. @mv [email protected] $@
  130. endef
  131. define Build/gzip
  132. gzip -f -9n -c $@ $(1) > [email protected]
  133. @mv [email protected] $@
  134. endef
  135. define Build/jffs2
  136. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  137. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  138. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  139. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  140. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  141. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  142. -o [email protected] \
  143. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  144. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  145. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  146. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  147. @mv [email protected] $@
  148. endef
  149. define Build/kernel-bin
  150. rm -f $@
  151. cp $< $@
  152. endef
  153. define Build/patch-cmdline
  154. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  155. endef
  156. define Build/append-kernel
  157. dd if=$(IMAGE_KERNEL) >> $@
  158. endef
  159. define Build/append-rootfs
  160. dd if=$(IMAGE_ROOTFS) >> $@
  161. endef
  162. define Build/append-ubi
  163. sh $(TOPDIR)/scripts/ubinize-image.sh \
  164. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  165. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  166. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  167. $(IMAGE_ROOTFS) \
  168. [email protected] \
  169. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  170. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  171. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  172. $(UBINIZE_OPTS)
  173. cat [email protected] >> $@
  174. rm [email protected]
  175. endef
  176. define Build/append-uboot
  177. dd if=$(UBOOT_PATH) >> $@
  178. endef
  179. define Build/pad-to
  180. dd if=$@ [email protected] bs=$(1) conv=sync
  181. mv [email protected] $@
  182. endef
  183. define Build/pad-extra
  184. dd if=/dev/zero bs=$(1) count=1 >> $@
  185. endef
  186. define Build/pad-rootfs
  187. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  188. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  189. endef
  190. define Build/pad-offset
  191. let \
  192. size="$$(stat -c%s $@)" \
  193. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  194. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  195. pad="(pad - ((size + offset) % pad)) % pad" \
  196. newsize='size + pad'; \
  197. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  198. mv [email protected] $@
  199. endef
  200. define Build/check-size
  201. @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
  202. echo "WARNING: Image file $@ is too big" >&2; \
  203. rm -f $@; \
  204. }
  205. endef
  206. define Build/combined-image
  207. -sh $(TOPDIR)/scripts/combined-image.sh \
  208. "$(IMAGE_KERNEL)" \
  209. "$@" \
  210. "[email protected]"
  211. @mv [email protected] $@
  212. endef
  213. define Build/openmesh-image
  214. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  215. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  216. "[email protected]" \
  217. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  218. "$(call param_get_default,rootfs,$(1),$@)"
  219. $(TOPDIR)/scripts/combined-ext-image.sh \
  220. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  221. "[email protected]" "fwupgrade.cfg" \
  222. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  223. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  224. endef
  225. define Build/sysupgrade-tar
  226. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  227. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  228. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  229. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  230. $@
  231. endef
  232. define Build/tplink-v1-header
  233. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  234. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  235. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  236. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  237. -k $@ -o [email protected] $(1)
  238. @mv [email protected] $@
  239. endef
  240. define Build/tplink-v2-header
  241. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  242. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  243. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  244. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  245. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  246. -k $@ -o [email protected] $(1)
  247. @mv [email protected] $@
  248. endef
  249. define Build/tplink-v2-image
  250. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  251. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  252. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  253. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  254. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  255. cat [email protected] >> $@
  256. rm -rf [email protected]
  257. endef
  258. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  259. #")')
  260. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  261. metadata_json = \
  262. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  263. "supported_devices":[$(call metadata_devices,$(1))], \
  264. "version": { \
  265. "dist": "$(call json_quote,$(VERSION_DIST))", \
  266. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  267. "revision": "$(call json_quote,$(REVISION))", \
  268. "board": "$(call json_quote,$(BOARD))" \
  269. } \
  270. }'
  271. define Build/append-metadata
  272. $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
  273. endef
  274. define Build/kernel2minor
  275. kernel2minor -k $@ -r [email protected] $(1)
  276. mv [email protected] $@
  277. endef