image-commands.mk 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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)) LEDE 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/netgear-chk
  41. $(STAGING_DIR_HOST)/bin/mkchkimg \
  42. -o [email protected] \
  43. -k $@ \
  44. -b $(NETGEAR_BOARD_ID) \
  45. -r $(NETGEAR_REGION)
  46. mv [email protected] $@
  47. endef
  48. define Build/netgear-dni
  49. $(STAGING_DIR_HOST)/bin/mkdniimg \
  50. -B $(NETGEAR_BOARD_ID) -v LEDE.$(REVISION) \
  51. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  52. -r "$(1)" \
  53. -i $@ -o [email protected]
  54. mv [email protected] $@
  55. endef
  56. # append a fake/empty rootfs uImage header, to fool the bootloaders
  57. # rootfs integrity check
  58. define Build/append-uImage-fakeroot-hdr
  59. rm -f [email protected]
  60. $(STAGING_DIR_HOST)/bin/mkimage \
  61. -A $(LINUX_KARCH) -O linux -T filesystem -C none \
  62. -n '$(call toupper,$(LINUX_KARCH)) LEDE fakeroot' \
  63. -s \
  64. [email protected]
  65. cat [email protected] >> $@
  66. endef
  67. define Build/tplink-safeloader
  68. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  69. -B $(TPLINK_BOARD_NAME) \
  70. -V $(REVISION) \
  71. -k $(IMAGE_KERNEL) \
  72. -r $@ \
  73. -o [email protected] \
  74. -j \
  75. $(wordlist 2,$(words $(1)),$(1)) \
  76. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  77. endef
  78. define Build/append-dtb
  79. $(call Image/BuildDTB,$(if $(DEVICE_DTS_DIR),$(DEVICE_DTS_DIR),$(DTS_DIR))/$(DEVICE_DTS).dts,[email protected])
  80. cat [email protected] >> $@
  81. endef
  82. define Build/install-dtb
  83. $(foreach dts,$(DEVICE_DTS), \
  84. $(CP) \
  85. $(DTS_DIR)/$(dts).dtb \
  86. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  87. )
  88. endef
  89. define Build/fit
  90. $(TOPDIR)/scripts/mkits.sh \
  91. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  92. $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
  93. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  94. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  95. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  96. @mv [email protected] $@
  97. endef
  98. define Build/lzma
  99. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  100. endef
  101. define Build/lzma-no-dict
  102. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  103. @mv [email protected] $@
  104. endef
  105. define Build/gzip
  106. gzip -9n -c $@ $(1) > [email protected]
  107. @mv [email protected] $@
  108. endef
  109. define Build/jffs2
  110. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  111. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  112. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  113. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  114. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  115. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  116. -o [email protected] \
  117. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  118. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  119. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  120. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  121. @mv [email protected] $@
  122. endef
  123. define Build/kernel-bin
  124. rm -f $@
  125. cp $< $@
  126. endef
  127. define Build/patch-cmdline
  128. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  129. endef
  130. define Build/append-kernel
  131. dd if=$(IMAGE_KERNEL) >> $@
  132. endef
  133. define Build/append-rootfs
  134. dd if=$(IMAGE_ROOTFS) >> $@
  135. endef
  136. define Build/append-ubi
  137. sh $(TOPDIR)/scripts/ubinize-image.sh \
  138. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  139. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  140. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  141. $(IMAGE_ROOTFS) \
  142. [email protected] \
  143. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  144. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  145. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  146. $(UBINIZE_OPTS)
  147. cat [email protected] >> $@
  148. rm [email protected]
  149. endef
  150. define Build/pad-to
  151. dd if=$@ [email protected] bs=$(1) conv=sync
  152. mv [email protected] $@
  153. endef
  154. define Build/pad-extra
  155. dd if=/dev/zero bs=$(1) count=1 >> $@
  156. endef
  157. define Build/pad-rootfs
  158. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  159. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  160. endef
  161. define Build/pad-offset
  162. let \
  163. size="$$(stat -c%s $@)" \
  164. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  165. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  166. pad="(pad - ((size + offset) % pad)) % pad" \
  167. newsize='size + pad'; \
  168. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  169. mv [email protected] $@
  170. endef
  171. define Build/check-size
  172. @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
  173. echo "WARNING: Image file $@ is too big" >&2; \
  174. rm -f $@; \
  175. }
  176. endef
  177. define Build/combined-image
  178. -sh $(TOPDIR)/scripts/combined-image.sh \
  179. "$(IMAGE_KERNEL)" \
  180. "$@" \
  181. "[email protected]"
  182. @mv [email protected] $@
  183. endef
  184. define Build/sysupgrade-tar
  185. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  186. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  187. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  188. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  189. $@
  190. endef
  191. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  192. #")')
  193. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  194. metadata_json = \
  195. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  196. "supported_devices":[$(call metadata_devices,$(1))], \
  197. "version": { \
  198. "dist": "$(call json_quote,$(VERSION_DIST))", \
  199. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  200. "revision": "$(call json_quote,$(REVISION))", \
  201. "board": "$(call json_quote,$(BOARD))" \
  202. } \
  203. }'
  204. define Build/append-metadata
  205. $(if $(SUPPORTED_DEVICES),echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
  206. endef
  207. define Build/kernel2minor
  208. kernel2minor -k $@ -r [email protected] $(1)
  209. mv [email protected] $@
  210. endef