image-commands.mk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. # Build commands that can be called from Device/* templates
  2. IMAGE_KERNEL = $(word 1,$^)
  3. IMAGE_ROOTFS = $(word 2,$^)
  4. define ModelNameLimit16
  5. $(shell expr substr "$(word 2, $(subst _, ,$(1)))" 1 16)
  6. endef
  7. define rootfs_align
  8. $(patsubst %-256k,0x40000,$(patsubst %-128k,0x20000,$(patsubst %-64k,0x10000,$(patsubst squashfs%,0x4,$(patsubst root.%,%,$(1))))))
  9. endef
  10. define Build/append-dtb
  11. cat $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb >> $@
  12. endef
  13. define Build/append-dtb-elf
  14. $(TARGET_CROSS)objcopy \
  15. --set-section-flags=.appended_dtb=alloc,contents \
  16. --update-section \
  17. .appended_dtb=$(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb $@
  18. endef
  19. define Build/append-kernel
  20. dd if=$(IMAGE_KERNEL) >> $@
  21. endef
  22. define Build/package-kernel-ubifs
  23. mkdir [email protected]
  24. cp $@ [email protected]/kernel
  25. $(STAGING_DIR_HOST)/bin/mkfs.ubifs \
  26. $(KERNEL_UBIFS_OPTS) \
  27. -r [email protected] $@
  28. rm -r [email protected]
  29. endef
  30. define Build/append-image
  31. cp "$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1)" "[email protected]"
  32. fwtool -s /dev/null -t "[email protected]" || :
  33. fwtool -i /dev/null -t "[email protected]" || :
  34. dd if="[email protected]" >> "$@"
  35. rm "[email protected]"
  36. endef
  37. ifdef IB
  38. define Build/append-image-stage
  39. dd if=$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))-$(DEVICE_NAME)-$(1) >> $@
  40. endef
  41. else
  42. define Build/append-image-stage
  43. cp "$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(1)" "[email protected]"
  44. fwtool -s /dev/null -t "[email protected]" || :
  45. fwtool -i /dev/null -t "[email protected]" || :
  46. dd if="[email protected]" of="$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))-$(DEVICE_NAME)-$(1)"
  47. dd if="[email protected]" >> "$@"
  48. rm "[email protected]"
  49. endef
  50. endif
  51. compat_version=$(if $(DEVICE_COMPAT_VERSION),$(DEVICE_COMPAT_VERSION),1.0)
  52. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  53. #")')
  54. legacy_supported_message=$(SUPPORTED_DEVICES) - Image version mismatch: image $(compat_version), \
  55. device 1.0. Please wipe config during upgrade (force required) or reinstall. \
  56. $(if $(DEVICE_COMPAT_MESSAGE),Reason: $(DEVICE_COMPAT_MESSAGE),Please check documentation ...)
  57. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  58. metadata_json = \
  59. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  60. "metadata_version": "1.1", \
  61. "compat_version": "$(call json_quote,$(compat_version))", \
  62. $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
  63. $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
  64. [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
  65. "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
  66. $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
  67. "version": { \
  68. "dist": "$(call json_quote,$(VERSION_DIST))", \
  69. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  70. "revision": "$(call json_quote,$(REVISION))", \
  71. "target": "$(call json_quote,$(TARGETID))", \
  72. "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
  73. } \
  74. }'
  75. define Build/append-metadata
  76. $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json) | fwtool -I - $@)
  77. sha256sum "$@" | cut -d" " -f1 > "[email protected]"
  78. [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
  79. cp "$(BUILD_KEY).ucert" "[email protected]" ;\
  80. usign -S -m "$@" -s "$(BUILD_KEY)" -x "[email protected]" ;\
  81. ucert -A -c "[email protected]" -x "[email protected]" ;\
  82. fwtool -S "[email protected]" "$@" ;\
  83. }
  84. endef
  85. define Build/append-rootfs
  86. dd if=$(IMAGE_ROOTFS) >> $@
  87. endef
  88. define Build/append-squashfs-fakeroot-be
  89. rm -rf [email protected] [email protected]
  90. mkdir [email protected]
  91. $(STAGING_DIR_HOST)/bin/mksquashfs-lzma \
  92. [email protected] [email protected] \
  93. -noappend -root-owned -be -nopad -b 65536 \
  94. $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
  95. cat [email protected] >> $@
  96. endef
  97. define Build/append-squashfs4-fakeroot
  98. rm -rf [email protected] [email protected]
  99. mkdir [email protected]
  100. $(STAGING_DIR_HOST)/bin/mksquashfs4 \
  101. [email protected] [email protected] \
  102. -nopad -noappend -root-owned
  103. cat [email protected] >> $@
  104. endef
  105. define Build/append-string
  106. echo -n $(1) >> $@
  107. endef
  108. define Build/append-ubi
  109. sh $(TOPDIR)/scripts/ubinize-image.sh \
  110. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  111. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  112. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  113. --rootfs $(IMAGE_ROOTFS) \
  114. [email protected] \
  115. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  116. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  117. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  118. $(UBINIZE_OPTS)
  119. cat [email protected] >> $@
  120. rm [email protected]
  121. endef
  122. define Build/ubinize-kernel
  123. cp $@ [email protected]
  124. sh $(TOPDIR)/scripts/ubinize-image.sh \
  125. --kernel [email protected] \
  126. $@ \
  127. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  128. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  129. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  130. $(UBINIZE_OPTS)
  131. rm [email protected]
  132. endef
  133. define Build/append-uboot
  134. dd if=$(UBOOT_PATH) >> $@
  135. endef
  136. # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
  137. # for example
  138. define Build/append-uImage-fakehdr
  139. $(eval type=$(word 1,$(1)))
  140. $(eval magic=$(word 2,$(1)))
  141. touch [email protected]
  142. $(STAGING_DIR_HOST)/bin/mkimage \
  143. -A $(LINUX_KARCH) -O linux -T $(type) -C none \
  144. -n '$(VERSION_DIST) fake $(type)' \
  145. $(if $(magic),-M $(magic)) \
  146. -d [email protected] \
  147. -s \
  148. [email protected]
  149. cat [email protected] >> $@
  150. endef
  151. define Build/buffalo-dhp-image
  152. $(STAGING_DIR_HOST)/bin/mkdhpimg $@ [email protected]
  153. mv [email protected] $@
  154. endef
  155. define Build/buffalo-enc
  156. $(eval product=$(word 1,$(1)))
  157. $(eval version=$(word 2,$(1)))
  158. $(eval args=$(wordlist 3,$(words $(1)),$(1)))
  159. $(STAGING_DIR_HOST)/bin/buffalo-enc \
  160. -p $(product) -v $(version) $(args) \
  161. -i $@ -o [email protected]
  162. mv [email protected] $@
  163. endef
  164. define Build/buffalo-enc-tag
  165. $(call Build/buffalo-enc,'' '' -S 152 $(1))
  166. endef
  167. define Build/buffalo-tag-dhp
  168. $(eval product=$(word 1,$(1)))
  169. $(eval region=$(word 2,$(1)))
  170. $(eval language=$(word 3,$(1)))
  171. $(STAGING_DIR_HOST)/bin/buffalo-tag \
  172. -d 0x01000000 -w 1 \
  173. -a $(BUFFALO_TAG_PLATFORM) \
  174. -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
  175. -b $(product) -p $(product) \
  176. -r $(region) -r $(region) -l $(language) \
  177. -I $@ -o [email protected]
  178. mv [email protected] $@
  179. endef
  180. define Build/check-size
  181. @imagesize="$$(stat -c%s $@)"; \
  182. limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
  183. [ $$limitsize -ge $$imagesize ] || { \
  184. $(call ERROR_MESSAGE, WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
  185. rm -f $@; \
  186. }
  187. endef
  188. define Build/copy-file
  189. cat "$(1)" > "$@"
  190. endef
  191. define Build/elecom-product-header
  192. $(eval product=$(word 1,$(1)))
  193. $(eval fw=$(if $(word 2,$(1)),$(word 2,$(1)),$@))
  194. ( \
  195. echo -n -e "ELECOM\x00\x00$(product)" | dd bs=40 count=1 conv=sync; \
  196. echo -n "0.00" | dd bs=16 count=1 conv=sync; \
  197. dd if=$(fw); \
  198. ) > $(fw).new
  199. mv $(fw).new $(fw)
  200. endef
  201. define Build/elecom-wrc-gs-factory
  202. $(eval product=$(word 1,$(1)))
  203. $(eval version=$(word 2,$(1)))
  204. $(eval hash_opt=$(word 3,$(1)))
  205. $(MKHASH) md5 $(hash_opt) $@ >> $@
  206. ( \
  207. echo -n "ELECOM $(product) v$(version)" | \
  208. dd bs=32 count=1 conv=sync; \
  209. dd if=$@; \
  210. ) > [email protected]
  211. mv [email protected] $@
  212. endef
  213. define Build/elx-header
  214. $(eval hw_id=$(word 1,$(1)))
  215. $(eval xor_pattern=$(word 2,$(1)))
  216. ( \
  217. echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
  218. dd bs=42 count=1 conv=sync; \
  219. hw_id="$(hw_id)"; \
  220. echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
  221. dd bs=20 count=1 conv=sync; \
  222. echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  223. dd bs=8 count=1 conv=sync; \
  224. echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  225. dd bs=58 count=1 conv=sync; \
  226. ) > $(KDIR)/tmp/$(DEVICE_NAME).header
  227. $(call Build/xor-image,-p $(xor_pattern) -x)
  228. cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > [email protected]
  229. mv [email protected] $@
  230. rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
  231. endef
  232. define Build/eva-image
  233. $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ [email protected]
  234. mv [email protected] $@
  235. endef
  236. define Build/initrd_compression
  237. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
  238. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
  239. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
  240. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
  241. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
  242. endef
  243. define Build/fit
  244. $(TOPDIR)/scripts/mkits.sh \
  245. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  246. -C $(word 1,$(1)) $(if $(word 2,$(1)),\
  247. $(if $(DEVICE_DTS_OVERLAY),-d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))),\
  248. -d $(word 2,$(1)))) \
  249. $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
  250. $(if $(findstring with-initrd,$(word 3,$(1))), \
  251. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
  252. -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
  253. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  254. $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
  255. $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \
  256. $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtb)) \
  257. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
  258. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  259. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
  260. -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f [email protected] [email protected]
  261. @mv [email protected] $@
  262. endef
  263. define Build/gzip
  264. gzip -f -9n -c $@ $(1) > [email protected]
  265. @mv [email protected] $@
  266. endef
  267. define Build/install-dtb
  268. $(call locked, \
  269. $(foreach dts,$(DEVICE_DTS), \
  270. $(CP) \
  271. $(DTS_DIR)/$(dts).dtb \
  272. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  273. ), \
  274. install-dtb-$(IMG_PREFIX) \
  275. )
  276. endef
  277. define Build/iptime-crc32
  278. $(STAGING_DIR_HOST)/bin/iptime-crc32 $(1) $@ [email protected]
  279. mv [email protected] $@
  280. endef
  281. define Build/iptime-naspkg
  282. $(STAGING_DIR_HOST)/bin/iptime-naspkg $(1) $@ [email protected]
  283. mv [email protected] $@
  284. endef
  285. define Build/jffs2
  286. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  287. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  288. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  289. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  290. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  291. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  292. -o [email protected] \
  293. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  294. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  295. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  296. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  297. @mv [email protected] $@
  298. endef
  299. define Build/kernel2minor
  300. $(eval temp_file := $(shell mktemp))
  301. cp $@ $(temp_file)
  302. kernel2minor -k $(temp_file) -r $(temp_file).new $(1)
  303. mv $(temp_file).new $@
  304. rm -f $(temp_file)
  305. endef
  306. define Build/kernel-bin
  307. rm -f $@
  308. cp $< $@
  309. endef
  310. define Build/linksys-image
  311. $(TOPDIR)/scripts/linksys-image.sh \
  312. "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
  313. $@ [email protected]
  314. mv [email protected] $@
  315. endef
  316. define Build/lzma
  317. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  318. endef
  319. define Build/lzma-no-dict
  320. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  321. @mv [email protected] $@
  322. endef
  323. define Build/netgear-chk
  324. $(STAGING_DIR_HOST)/bin/mkchkimg \
  325. -o [email protected] \
  326. -k $@ \
  327. -b $(NETGEAR_BOARD_ID) \
  328. $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
  329. mv [email protected] $@
  330. endef
  331. define Build/netgear-dni
  332. $(STAGING_DIR_HOST)/bin/mkdniimg \
  333. -B $(NETGEAR_BOARD_ID) -v $(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
  334. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  335. -r "$(1)" \
  336. -i $@ -o [email protected]
  337. mv [email protected] $@
  338. endef
  339. define Build/netgear-encrypted-factory
  340. $(TOPDIR)/scripts/netgear-encrypted-factory.py \
  341. --input-file $@ \
  342. --output-file $@ \
  343. --model $(NETGEAR_ENC_MODEL) \
  344. --region $(NETGEAR_ENC_REGION) \
  345. --version V1.0.0.0.$(VERSION_DIST).$(firstword $(subst -, ,$(REVISION))) \
  346. --encryption-block-size 0x20000 \
  347. --openssl-bin "$(STAGING_DIR_HOST)/bin/openssl" \
  348. --key 6865392d342b4d212964363d6d7e7765312c7132613364316e26322a5a5e2538 \
  349. --iv 4a253169516c38243d6c6d2d3b384145
  350. endef
  351. define Build/openmesh-image
  352. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  353. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  354. "[email protected]" \
  355. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  356. "$(call param_get_default,rootfs,$(1),$@)"
  357. $(TOPDIR)/scripts/combined-ext-image.sh \
  358. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  359. "[email protected]" "fwupgrade.cfg" \
  360. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  361. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  362. endef
  363. define Build/pad-extra
  364. dd if=/dev/zero bs=$(1) count=1 >> $@
  365. endef
  366. define Build/pad-offset
  367. let \
  368. size="$$(stat -c%s $@)" \
  369. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  370. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  371. pad="(pad - ((size + offset) % pad)) % pad" \
  372. newsize='size + pad'; \
  373. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  374. mv [email protected] $@
  375. endef
  376. define Build/pad-rootfs
  377. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  378. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  379. endef
  380. define Build/pad-to
  381. $(call Image/pad-to,$@,$(1))
  382. endef
  383. define Build/patch-cmdline
  384. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  385. endef
  386. # Convert a raw image into a $1 type image.
  387. # E.g. | qemu-image vdi <optional extra arguments to qemu-img binary>
  388. define Build/qemu-image
  389. if command -v qemu-img; then \
  390. qemu-img convert -f raw -O $1 $@ [email protected]; \
  391. mv [email protected] $@; \
  392. else \
  393. echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
  394. fi
  395. endef
  396. define Build/qsdk-ipq-factory-nand
  397. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  398. [email protected] ubi $@
  399. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  400. @mv [email protected] $@
  401. endef
  402. define Build/qsdk-ipq-factory-nor
  403. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  404. [email protected] hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
  405. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  406. @mv [email protected] $@
  407. endef
  408. define Build/seama
  409. $(STAGING_DIR_HOST)/bin/seama -i $@ \
  410. -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
  411. mv [email protected] $@
  412. endef
  413. define Build/seama-seal
  414. $(STAGING_DIR_HOST)/bin/seama -i $@ -s [email protected] \
  415. -m "signature=$(SEAMA_SIGNATURE)"
  416. mv [email protected] $@
  417. endef
  418. define Build/senao-header
  419. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  420. mv [email protected] $@
  421. endef
  422. define Build/sysupgrade-tar
  423. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  424. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  425. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  426. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  427. $@
  428. endef
  429. define Build/tplink-safeloader
  430. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  431. -B $(TPLINK_BOARD_ID) \
  432. -V $(REVISION) \
  433. -k $(IMAGE_KERNEL) \
  434. -r $@ \
  435. -o [email protected] \
  436. -j \
  437. $(wordlist 2,$(words $(1)),$(1)) \
  438. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  439. endef
  440. define Build/tplink-v1-header
  441. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  442. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  443. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  444. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  445. -k $@ -o [email protected] $(1)
  446. @mv [email protected] $@
  447. endef
  448. # combine kernel and rootfs into one image
  449. # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
  450. # <type> is "sysupgrade" or "factory"
  451. #
  452. # -a align the rootfs start on an <align> bytes boundary
  453. # -j add jffs2 end-of-filesystem markers
  454. # -s strip padding from end of the image
  455. # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
  456. define Build/tplink-v1-image
  457. -$(STAGING_DIR_HOST)/bin/mktplinkfw \
  458. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
  459. -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
  460. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] -j -X 0x40000 \
  461. -a $(call rootfs_align,$(FILESYSTEM)) \
  462. $(wordlist 2,$(words $(1)),$(1)) \
  463. $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv [email protected] $@ || rm -f $@
  464. endef
  465. define Build/tplink-v2-header
  466. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  467. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  468. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  469. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  470. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  471. -k $@ -o [email protected] $(1)
  472. @mv [email protected] $@
  473. endef
  474. define Build/tplink-v2-image
  475. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  476. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  477. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  478. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  479. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  480. cat [email protected] >> $@
  481. rm -rf [email protected]
  482. endef
  483. define Build/uImage
  484. mkimage \
  485. -A $(LINUX_KARCH) \
  486. -O linux \
  487. -T kernel \
  488. -C $(word 1,$(1)) \
  489. -a $(KERNEL_LOADADDR) \
  490. -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  491. -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
  492. $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
  493. $(wordlist 2,$(words $(1)),$(1)) \
  494. -d $@ [email protected]
  495. mv [email protected] $@
  496. endef
  497. define Build/xor-image
  498. $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o [email protected] $(1)
  499. mv [email protected] $@
  500. endef
  501. define Build/zip
  502. rm -rf [email protected]
  503. mkdir [email protected]
  504. mv $@ [email protected]/$(word 1,$(1))
  505. TZ=UTC $(STAGING_DIR_HOST)/bin/zip -j -X \
  506. $(wordlist 2,$(words $(1)),$(1)) \
  507. $@ [email protected]/$(if $(word 1,$(1)),$(word 1,$(1)),$$(basename $@))
  508. rm -rf [email protected]
  509. endef
  510. define Build/zyxel-ras-image
  511. let \
  512. newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
  513. $(STAGING_DIR_HOST)/bin/mkrasimage \
  514. -b $(RAS_BOARD) \
  515. -v $(RAS_VERSION) \
  516. -r $@ \
  517. -s $$newsize \
  518. -o [email protected] \
  519. $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
  520. && mv [email protected] $@
  521. endef