image-commands.mk 8.2 KB

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