1
0

image-commands.mk 9.2 KB

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