2
0

image-commands.mk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 $@ $@.new
  9. @mv $@.new $@
  10. endef
  11. define Build/netgear-chk
  12. $(STAGING_DIR_HOST)/bin/mkchkimg \
  13. -o $@.new \
  14. -k $@ \
  15. -b $(NETGEAR_BOARD_ID) \
  16. -r $(NETGEAR_REGION)
  17. mv $@.new $@
  18. endef
  19. define Build/netgear-dni
  20. $(STAGING_DIR_HOST)/bin/mkdniimg \
  21. -B $(NETGEAR_BOARD_ID) -v LEDE.$(REVISION) \
  22. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  23. -r "$(1)" \
  24. -i $@ -o $@.new
  25. mv $@.new $@
  26. endef
  27. define Build/tplink-safeloader
  28. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  29. -B $(TPLINK_BOARD_NAME) \
  30. -V $(REVISION) \
  31. -k $(IMAGE_KERNEL) \
  32. -r $@ \
  33. -o $@.new \
  34. -j \
  35. $(wordlist 2,$(words $(1)),$(1)) \
  36. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
  37. endef
  38. define Build/append-dtb
  39. $(call Image/BuildDTB,$(if $(DEVICE_DTS_DIR),$(DEVICE_DTS_DIR),$(DTS_DIR))/$(DEVICE_DTS).dts,$@.dtb)
  40. cat $@.dtb >> $@
  41. endef
  42. define Build/install-dtb
  43. $(foreach dts,$(DEVICE_DTS), \
  44. $(CP) \
  45. $(DTS_DIR)/$(dts).dtb \
  46. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  47. )
  48. endef
  49. define Build/fit
  50. $(TOPDIR)/scripts/mkits.sh \
  51. -D $(DEVICE_NAME) -o $@.its -k $@ \
  52. $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
  53. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  54. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  55. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
  56. @mv $@.new $@
  57. endef
  58. define Build/lzma
  59. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  60. endef
  61. define Build/lzma-no-dict
  62. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
  63. @mv $@.new $@
  64. endef
  65. define Build/gzip
  66. gzip -9n -c $@ $(1) > $@.new
  67. @mv $@.new $@
  68. endef
  69. define Build/jffs2
  70. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  71. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  72. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  73. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  74. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  75. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  76. -o $@.new \
  77. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  78. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  79. $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
  80. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  81. @mv $@.new $@
  82. endef
  83. define Build/kernel-bin
  84. rm -f $@
  85. cp $< $@
  86. endef
  87. define Build/patch-cmdline
  88. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  89. endef
  90. define Build/append-kernel
  91. dd if=$(IMAGE_KERNEL) >> $@
  92. endef
  93. define Build/append-rootfs
  94. dd if=$(IMAGE_ROOTFS) >> $@
  95. endef
  96. define Build/append-ubi
  97. sh $(TOPDIR)/scripts/ubinize-image.sh \
  98. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  99. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  100. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  101. $(IMAGE_ROOTFS) \
  102. $@.tmp \
  103. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  104. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  105. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  106. $(UBINIZE_OPTS)
  107. cat $@.tmp >> $@
  108. rm $@.tmp
  109. endef
  110. define Build/pad-to
  111. dd if=$@ of=$@.new bs=$(1) conv=sync
  112. mv $@.new $@
  113. endef
  114. define Build/pad-extra
  115. dd if=/dev/zero bs=$(1) count=1 >> $@
  116. endef
  117. define Build/pad-rootfs
  118. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  119. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  120. endef
  121. define Build/pad-offset
  122. let \
  123. size="$$(stat -c%s $@)" \
  124. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  125. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  126. pad="(pad - ((size + offset) % pad)) % pad" \
  127. newsize='size + pad'; \
  128. dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
  129. mv $@.new $@
  130. endef
  131. define Build/check-size
  132. @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
  133. echo "WARNING: Image file $@ is too big" >&2; \
  134. rm -f $@; \
  135. }
  136. endef
  137. define Build/combined-image
  138. -sh $(TOPDIR)/scripts/combined-image.sh \
  139. "$(IMAGE_KERNEL)" \
  140. "$@" \
  141. "$@.new"
  142. @mv $@.new $@
  143. endef
  144. define Build/sysupgrade-tar
  145. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  146. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  147. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  148. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  149. $@
  150. endef
  151. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  152. #")')
  153. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  154. metadata_json = \
  155. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  156. "supported_devices":[$(call metadata_devices,$(1))], \
  157. "version": { \
  158. "dist": "$(call json_quote,$(VERSION_DIST))", \
  159. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  160. "revision": "$(call json_quote,$(REVISION))", \
  161. "board": "$(call json_quote,$(BOARD))" \
  162. } \
  163. }'
  164. define Build/append-metadata
  165. $(if $(SUPPORTED_DEVICES),echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
  166. endef
  167. define Build/kernel2minor
  168. kernel2minor -k $@ -r $@.new $(1)
  169. mv $@.new $@
  170. endef