image-commands.mk 16 KB

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