2
0

image-commands.mk 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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 printf %.16s "$(word 2, $(subst _, ,$(1)))")
  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)-$(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. mkdir -p "$(STAGING_DIR_IMAGE)"
  47. dd if="[email protected]" of="$(STAGING_DIR_IMAGE)/$(BOARD)-$(SUBTARGET)-$(DEVICE_NAME)-$(1)"
  48. dd if="[email protected]" >> "$@"
  49. rm "[email protected]"
  50. endef
  51. endif
  52. compat_version=$(if $(DEVICE_COMPAT_VERSION),$(DEVICE_COMPAT_VERSION),1.0)
  53. json_quote=$(subst ','\'',$(subst ",\",$(1)))
  54. #")')
  55. legacy_supported_message=$(SUPPORTED_DEVICES) - Image version mismatch: image $(compat_version), \
  56. device 1.0. Please wipe config during upgrade (force required) or reinstall. \
  57. $(if $(DEVICE_COMPAT_MESSAGE),Reason: $(DEVICE_COMPAT_MESSAGE),Please check documentation ...)
  58. metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
  59. metadata_json = \
  60. '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
  61. "metadata_version": "1.1", \
  62. "compat_version": "$(call json_quote,$(compat_version))", \
  63. $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \
  64. $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices": \
  65. [$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma) \
  66. "supported_devices": ["$(call json_quote,$(legacy_supported_message))"]$(comma)) \
  67. $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \
  68. "version": { \
  69. "dist": "$(call json_quote,$(VERSION_DIST))", \
  70. "version": "$(call json_quote,$(VERSION_NUMBER))", \
  71. "revision": "$(call json_quote,$(REVISION))", \
  72. "target": "$(call json_quote,$(TARGETID))", \
  73. "board": "$(call json_quote,$(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)))" \
  74. } \
  75. }'
  76. define Build/append-metadata
  77. $(if $(SUPPORTED_DEVICES),-echo $(call metadata_json) | fwtool -I - $@)
  78. sha256sum "$@" | cut -d" " -f1 > "[email protected]"
  79. [ ! -s "$(BUILD_KEY)" -o ! -s "$(BUILD_KEY).ucert" -o ! -s "$@" ] || { \
  80. cp "$(BUILD_KEY).ucert" "[email protected]" ;\
  81. usign -S -m "$@" -s "$(BUILD_KEY)" -x "[email protected]" ;\
  82. ucert -A -c "[email protected]" -x "[email protected]" ;\
  83. fwtool -S "[email protected]" "$@" ;\
  84. }
  85. endef
  86. define Build/append-rootfs
  87. dd if=$(IMAGE_ROOTFS) >> $@
  88. endef
  89. define Build/append-squashfs-fakeroot-be
  90. rm -rf [email protected] [email protected]
  91. mkdir [email protected]
  92. $(STAGING_DIR_HOST)/bin/mksquashfs3-lzma \
  93. [email protected] [email protected] \
  94. -noappend -root-owned -be -nopad -b 65536 \
  95. $(if $(SOURCE_DATE_EPOCH),-fixed-time $(SOURCE_DATE_EPOCH))
  96. cat [email protected] >> $@
  97. endef
  98. define Build/append-squashfs4-fakeroot
  99. rm -rf [email protected] [email protected]
  100. mkdir [email protected]
  101. $(STAGING_DIR_HOST)/bin/mksquashfs4 \
  102. [email protected] [email protected] \
  103. -nopad -noappend -root-owned
  104. cat [email protected] >> $@
  105. endef
  106. define Build/append-string
  107. echo -n $(1) >> $@
  108. endef
  109. define Build/append-md5sum-ascii-salted
  110. cp $@ [email protected]
  111. echo -ne $(1) >> [email protected]
  112. $(STAGING_DIR_HOST)/bin/mkhash md5 [email protected] | head -c32 >> $@
  113. rm [email protected]
  114. endef
  115. UBI_NAND_SIZE_LIMIT = $(IMAGE_SIZE) - ($(NAND_SIZE)*20/1024 + 4*$(BLOCKSIZE))
  116. define Build/append-ubi
  117. sh $(TOPDIR)/scripts/ubinize-image.sh \
  118. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  119. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  120. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  121. --rootfs $(IMAGE_ROOTFS) \
  122. [email protected] \
  123. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  124. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  125. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  126. $(UBINIZE_OPTS)
  127. cat [email protected] >> $@
  128. rm [email protected]
  129. $(if $(and $(IMAGE_SIZE),$(NAND_SIZE)),\
  130. $(call Build/check-size,$(UBI_NAND_SIZE_LIMIT)))
  131. endef
  132. define Build/ubinize-image
  133. sh $(TOPDIR)/scripts/ubinize-image.sh \
  134. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  135. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  136. --part $(word 1,$(1))="$(BIN_DIR)/$(DEVICE_IMG_PREFIX)-$(word 2,$(1))" \
  137. [email protected] \
  138. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  139. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  140. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  141. $(UBINIZE_OPTS)
  142. cat [email protected] >> $@
  143. rm [email protected]
  144. endef
  145. define Build/ubinize-kernel
  146. cp $@ [email protected]
  147. sh $(TOPDIR)/scripts/ubinize-image.sh \
  148. --kernel [email protected] \
  149. $@ \
  150. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  151. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  152. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  153. $(UBINIZE_OPTS)
  154. rm [email protected]
  155. endef
  156. define Build/append-uboot
  157. dd if=$(UBOOT_PATH) >> $@
  158. endef
  159. # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
  160. # for example
  161. define Build/append-uImage-fakehdr
  162. $(eval type=$(word 1,$(1)))
  163. $(eval magic=$(word 2,$(1)))
  164. touch [email protected]
  165. $(STAGING_DIR_HOST)/bin/mkimage \
  166. -A $(LINUX_KARCH) -O linux -T $(type) -C none \
  167. -n '$(VERSION_DIST) fake $(type)' \
  168. $(if $(magic),-M $(magic)) \
  169. -d [email protected] \
  170. -s \
  171. [email protected]
  172. cat [email protected] >> $@
  173. endef
  174. define Build/buffalo-dhp-image
  175. $(STAGING_DIR_HOST)/bin/mkdhpimg $@ [email protected]
  176. mv [email protected] $@
  177. endef
  178. define Build/buffalo-enc
  179. $(eval product=$(word 1,$(1)))
  180. $(eval version=$(word 2,$(1)))
  181. $(eval args=$(wordlist 3,$(words $(1)),$(1)))
  182. $(STAGING_DIR_HOST)/bin/buffalo-enc \
  183. -p $(product) -v $(version) $(args) \
  184. -i $@ -o [email protected]
  185. mv [email protected] $@
  186. endef
  187. define Build/buffalo-enc-tag
  188. $(call Build/buffalo-enc,'' '' -S 152 $(1))
  189. endef
  190. define Build/buffalo-tag-dhp
  191. $(eval product=$(word 1,$(1)))
  192. $(eval region=$(word 2,$(1)))
  193. $(eval language=$(word 3,$(1)))
  194. $(STAGING_DIR_HOST)/bin/buffalo-tag \
  195. -d 0x01000000 -w 1 \
  196. -a $(BUFFALO_TAG_PLATFORM) \
  197. -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
  198. -b $(product) -p $(product) \
  199. -r $(region) -r $(region) -l $(language) \
  200. -I $@ -o [email protected]
  201. mv [email protected] $@
  202. endef
  203. define Build/buffalo-trx
  204. $(eval magic=$(word 1,$(1)))
  205. $(eval kern_bin=$(if $(1),$(IMAGE_KERNEL),$@))
  206. $(eval rtfs_bin=$(word 2,$(1)))
  207. $(eval apnd_bin=$(word 3,$(1)))
  208. $(eval kern_size=$(if $(KERNEL_SIZE),$(KERNEL_SIZE),0x400000))
  209. $(if $(rtfs_bin),touch $(rtfs_bin))
  210. $(STAGING_DIR_HOST)/bin/otrx create [email protected] \
  211. $(if $(magic),-M $(magic),) \
  212. -f $(kern_bin) \
  213. $(if $(rtfs_bin),\
  214. -a 0x20000 \
  215. -b $$(( $(call exp_units,$(kern_size)) )) \
  216. -f $(rtfs_bin),) \
  217. $(if $(apnd_bin),\
  218. -A $(apnd_bin) \
  219. -a 0x20000)
  220. mv [email protected] $@
  221. endef
  222. define Build/check-size
  223. @imagesize="$$(stat -c%s $@)"; \
  224. limitsize="$$(($(call exp_units,$(if $(1),$(1),$(IMAGE_SIZE)))))"; \
  225. [ $$limitsize -ge $$imagesize ] || { \
  226. $(call ERROR_MESSAGE, WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
  227. rm -f $@; \
  228. }
  229. endef
  230. define Build/copy-file
  231. cat "$(1)" > "$@"
  232. endef
  233. # Create a header for a D-Link AI series recovery image and add it at the beginning of the image
  234. # Currently supported: AQUILA M30, EAGLE M32 and R32
  235. # Arguments:
  236. # 1: Start string of the header
  237. # 2: Firmware version
  238. # 3: Block start address
  239. # 4: Block length
  240. # 5: Device FMID
  241. define Build/dlink-ai-recovery-header
  242. $(eval header_start=$(word 1,$(1)))
  243. $(eval firmware_version=$(word 2,$(1)))
  244. $(eval block_start=$(word 3,$(1)))
  245. $(eval block_length=$(word 4,$(1)))
  246. $(eval device_fmid=$(word 5,$(1)))
  247. # create [email protected] without the checksum
  248. echo -en "$(header_start)\x00\x00" > "[email protected]"
  249. # Calculate checksum over data area ($@) and append it to the header.
  250. # The checksum is the 2byte-sum over the whole data area.
  251. # Every overflow during the checksum calculation must increment the current checksum value by 1.
  252. od -v -w2 -tu2 -An --endian little "$@" | awk '{ s+=$$1; } END { s%=65535; printf "%c%c",s%256,s/256; }' >> "[email protected]"
  253. echo -en "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00" >> "[email protected]"
  254. echo -en "$(firmware_version)" >> "[email protected]"
  255. # Only one block supported: Erase start/length is identical to data start/length
  256. echo -en "$(block_start)$(block_length)$(block_start)$(block_length)" >> "[email protected]"
  257. # Only zeros
  258. echo -en "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" >> "[email protected]"
  259. # Last 16 bytes, but without checksum
  260. echo -en "\x42\x48\x02\x00\x00\x00\x08\x00\x00\x00\x00\x00" >> "[email protected]"
  261. echo -en "$(device_fmid)" >> "[email protected]"
  262. # Calculate and append checksum: The checksum must be set so that the 2byte-sum of the whole header is 0.
  263. # Every overflow during the checksum calculation must increment the current checksum value by 1.
  264. od -v -w2 -tu2 -An --endian little "[email protected]" | awk '{s+=65535-$$1;}END{s%=65535;printf "%c%c",s%256,s/256;}' >> "[email protected]"
  265. cat "[email protected]" "$@" > "[email protected]"
  266. mv "[email protected]" "$@"
  267. rm "[email protected]"
  268. endef
  269. define Build/dlink-sge-image
  270. $(STAGING_DIR_HOST)/bin/dlink-sge-image $(1) $@ [email protected]
  271. mv [email protected] $@
  272. endef
  273. define Build/edimax-header
  274. $(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o [email protected] $(1)
  275. @mv [email protected] $@
  276. endef
  277. define Build/elecom-product-header
  278. $(eval product=$(word 1,$(1)))
  279. $(eval fw=$(if $(word 2,$(1)),$(word 2,$(1)),$@))
  280. ( \
  281. echo -n -e "ELECOM\x00\x00$(product)" | dd bs=40 count=1 conv=sync; \
  282. echo -n "0.00" | dd bs=16 count=1 conv=sync; \
  283. dd if=$(fw); \
  284. ) > $(fw).new
  285. mv $(fw).new $(fw)
  286. endef
  287. define Build/elecom-wrc-gs-factory
  288. $(eval product=$(word 1,$(1)))
  289. $(eval version=$(word 2,$(1)))
  290. $(eval hash_opt=$(word 3,$(1)))
  291. $(MKHASH) md5 $(hash_opt) $@ >> $@
  292. ( \
  293. echo -n "ELECOM $(product) v$(version)" | \
  294. dd bs=32 count=1 conv=sync; \
  295. dd if=$@; \
  296. ) > [email protected]
  297. mv [email protected] $@
  298. endef
  299. define Build/elx-header
  300. $(eval hw_id=$(word 1,$(1)))
  301. $(eval xor_pattern=$(word 2,$(1)))
  302. ( \
  303. echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
  304. dd bs=42 count=1 conv=sync; \
  305. hw_id="$(hw_id)"; \
  306. echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
  307. dd bs=20 count=1 conv=sync; \
  308. echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  309. dd bs=8 count=1 conv=sync; \
  310. echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  311. dd bs=58 count=1 conv=sync; \
  312. ) > $(KDIR)/tmp/$(DEVICE_NAME).header
  313. $(call Build/xor-image,-p $(xor_pattern) -x)
  314. cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > [email protected]
  315. mv [email protected] $@
  316. rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
  317. endef
  318. define Build/eva-image
  319. $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ [email protected]
  320. mv [email protected] $@
  321. endef
  322. define Build/initrd_compression
  323. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
  324. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
  325. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),.lz4) \
  326. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
  327. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),.lzo) \
  328. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
  329. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
  330. endef
  331. define Build/fit
  332. $(TOPDIR)/scripts/mkits.sh \
  333. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  334. -C $(word 1,$(1)) \
  335. $(if $(word 2,$(1)),\
  336. $(if $(findstring 11,$(if $(DEVICE_DTS_OVERLAY),1)$(if $(findstring $(KERNEL_BUILD_DIR)/image-,$(word 2,$(1))),,1)), \
  337. -d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))), \
  338. -d $(word 2,$(1)))) \
  339. $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
  340. $(if $(findstring with-initrd,$(word 3,$(1))), \
  341. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
  342. -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
  343. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  344. $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
  345. $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \
  346. $(if $(DEVICE_DTS_LOADADDR),-s $(DEVICE_DTS_LOADADDR)) \
  347. $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtbo)) \
  348. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
  349. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  350. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
  351. -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f [email protected] [email protected]
  352. @mv [email protected] $@
  353. endef
  354. define Build/libdeflate-gzip
  355. $(STAGING_DIR_HOST)/bin/libdeflate-gzip -f -12 -c $@ $(1) > [email protected]
  356. @mv [email protected] $@
  357. endef
  358. define Build/gzip
  359. $(STAGING_DIR_HOST)/bin/gzip -f -9n -c $@ $(1) > [email protected]
  360. @mv [email protected] $@
  361. endef
  362. define Build/gzip-filename
  363. @mkdir -p [email protected]
  364. @cp $@ [email protected]/$(word 1,$(1))
  365. $(if $(SOURCE_DATE_EPOCH),touch -hcd "@$(SOURCE_DATE_EPOCH)" [email protected]/$(word 1,$(1)) $(word 2,$(1)))
  366. $(STAGING_DIR_HOST)/bin/gzip -f -9 -N -c [email protected]/$(word 1,$(1)) $(word 2,$(1)) > [email protected]
  367. @mv [email protected] $@
  368. @rm -rf [email protected]
  369. endef
  370. define Build/install-dtb
  371. $(call locked, \
  372. $(foreach dts,$(DEVICE_DTS), \
  373. $(CP) \
  374. $(DTS_DIR)/$(dts).dtb \
  375. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  376. ), \
  377. install-dtb-$(IMG_PREFIX) \
  378. )
  379. endef
  380. define Build/iptime-crc32
  381. $(STAGING_DIR_HOST)/bin/iptime-crc32 $(1) $@ [email protected]
  382. mv [email protected] $@
  383. endef
  384. define Build/iptime-naspkg
  385. $(STAGING_DIR_HOST)/bin/iptime-naspkg $(1) $@ [email protected]
  386. mv [email protected] $@
  387. endef
  388. define Build/jffs2
  389. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  390. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  391. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  392. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  393. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  394. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  395. -o [email protected] \
  396. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  397. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  398. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  399. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  400. @mv [email protected] $@
  401. endef
  402. define Build/yaffs-filesystem
  403. let \
  404. kernel_size="$$(stat -c%s $@)" \
  405. kernel_chunks="(kernel_size / 1024) + 1" \
  406. filesystem_chunks="kernel_chunks + 3" \
  407. filesystem_blocks="(filesystem_chunks / 63) + 1" \
  408. filesystem_size="filesystem_blocks * 64 * 1024" \
  409. filesystem_size_with_reserve="(filesystem_blocks + 2) * 64 * 1024"; \
  410. head -c $$filesystem_size_with_reserve /dev/zero | tr "\000" "\377" > [email protected] \
  411. && yafut -d [email protected] -w -i $@ -o kernel -C 1040 -B 64k -E -P -S $(1) \
  412. && truncate -s $$filesystem_size [email protected] \
  413. && mv [email protected] $@
  414. endef
  415. define Build/kernel-bin
  416. rm -f $@
  417. cp $< $@
  418. endef
  419. define Build/linksys-image
  420. let \
  421. size="$$(stat -c%s $@)" \
  422. pad="$(call exp_units,$(PAGESIZE))" \
  423. offset="256" \
  424. pad="(pad - ((size + offset) % pad)) % pad"; \
  425. dd if=/dev/zero bs=$$pad count=1 | tr '\000' '\377' >> $@
  426. printf ".LINKSYS.01000409%-15s%08X%-8s%-16s" \
  427. "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
  428. "$$(cksum $@ | cut -d ' ' -f1)" \
  429. "0" "K0000000F0246434" >> $@
  430. dd if=/dev/zero bs=192 count=1 >> $@
  431. endef
  432. define Build/lzma
  433. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  434. endef
  435. define Build/lzma-no-dict
  436. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  437. @mv [email protected] $@
  438. endef
  439. define Build/moxa-encode-fw
  440. $(TOPDIR)/scripts/moxa-encode-fw.py \
  441. --input $@ \
  442. --output $@ \
  443. --magic $(MOXA_MAGIC) \
  444. --hwid $(MOXA_HWID) \
  445. --buildid 00000000
  446. endef
  447. define Build/netgear-chk
  448. $(STAGING_DIR_HOST)/bin/mkchkimg \
  449. -o [email protected] \
  450. -k $@ \
  451. -b $(NETGEAR_BOARD_ID) \
  452. $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
  453. mv [email protected] $@
  454. endef
  455. define Build/netgear-dni
  456. $(STAGING_DIR_HOST)/bin/mkdniimg \
  457. -B $(NETGEAR_BOARD_ID) -v $(shell cat $(VERSION_DIST)| sed -e 's/[[:space:]]/-/g').$(firstword $(subst -, ,$(REVISION))) \
  458. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  459. -r "$(1)" \
  460. -i $@ -o [email protected]
  461. mv [email protected] $@
  462. endef
  463. define Build/netgear-encrypted-factory
  464. $(TOPDIR)/scripts/netgear-encrypted-factory.py \
  465. --input-file $@ \
  466. --output-file $@ \
  467. --model $(NETGEAR_ENC_MODEL) \
  468. --region $(NETGEAR_ENC_REGION) \
  469. $(if $(NETGEAR_ENC_HW_ID_LIST),--hw-id-list "$(NETGEAR_ENC_HW_ID_LIST)") \
  470. $(if $(NETGEAR_ENC_MODEL_LIST),--model-list "$(NETGEAR_ENC_MODEL_LIST)") \
  471. --version V1.0.0.0.$(shell cat $(VERSION_DIST)| sed -e 's/[[:space:]]/-/g').$(firstword $(subst -, ,$(REVISION))) \
  472. --encryption-block-size 0x20000 \
  473. --openssl-bin "$(STAGING_DIR_HOST)/bin/openssl" \
  474. --key 6865392d342b4d212964363d6d7e7765312c7132613364316e26322a5a5e2538 \
  475. --iv 4a253169516c38243d6c6d2d3b384145
  476. endef
  477. define Build/openmesh-image
  478. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  479. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  480. "[email protected]" \
  481. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  482. "$(call param_get_default,rootfs,$(1),$@)"
  483. $(TOPDIR)/scripts/combined-ext-image.sh \
  484. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  485. "[email protected]" "fwupgrade.cfg" \
  486. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  487. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  488. endef
  489. define Build/pad-extra
  490. dd if=/dev/zero bs=$(1) count=1 >> $@
  491. endef
  492. define Build/pad-offset
  493. let \
  494. size="$$(stat -c%s $@)" \
  495. pad="$(call exp_units,$(word 1, $(1)))" \
  496. offset="$(call exp_units,$(word 2, $(1)))" \
  497. pad="(pad - ((size + offset) % pad)) % pad" \
  498. newsize='size + pad'; \
  499. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  500. mv [email protected] $@
  501. endef
  502. define Build/pad-rootfs
  503. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  504. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  505. endef
  506. define Build/pad-to
  507. $(call Image/pad-to,$@,$(1))
  508. endef
  509. define Build/patch-cmdline
  510. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  511. endef
  512. # Convert a raw image into a $1 type image.
  513. # E.g. | qemu-image vdi <optional extra arguments to qemu-img binary>
  514. define Build/qemu-image
  515. if command -v qemu-img; then \
  516. qemu-img convert -f raw -O $1 $@ [email protected]; \
  517. mv [email protected] $@; \
  518. else \
  519. echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
  520. fi
  521. endef
  522. define Build/qsdk-ipq-factory-nand
  523. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  524. [email protected] ubi $@
  525. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  526. @mv [email protected] $@
  527. endef
  528. define Build/qsdk-ipq-factory-nor
  529. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  530. [email protected] hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
  531. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  532. @mv [email protected] $@
  533. endef
  534. define Build/seama
  535. $(STAGING_DIR_HOST)/bin/seama -i $@ \
  536. -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
  537. mv [email protected] $@
  538. endef
  539. define Build/seama-seal
  540. $(STAGING_DIR_HOST)/bin/seama -i $@ -s [email protected] \
  541. -m "signature=$(SEAMA_SIGNATURE)"
  542. mv [email protected] $@
  543. endef
  544. define Build/senao-header
  545. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  546. mv [email protected] $@
  547. endef
  548. define Build/sysupgrade-tar
  549. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  550. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  551. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  552. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  553. $@
  554. endef
  555. define Build/tplink-safeloader
  556. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  557. -B $(TPLINK_BOARD_ID) \
  558. -V $(REVISION) \
  559. -k $(IMAGE_KERNEL) \
  560. -r $@ \
  561. -o [email protected] \
  562. -j \
  563. $(wordlist 2,$(words $(1)),$(1)) \
  564. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  565. endef
  566. define Build/tplink-v1-header
  567. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  568. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  569. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  570. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  571. -k $@ -o [email protected] $(1)
  572. @mv [email protected] $@
  573. endef
  574. # combine kernel and rootfs into one image
  575. # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
  576. # <type> is "sysupgrade" or "factory"
  577. #
  578. # -a align the rootfs start on an <align> bytes boundary
  579. # -j add jffs2 end-of-filesystem markers
  580. # -s strip padding from end of the image
  581. # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
  582. define Build/tplink-v1-image
  583. -$(STAGING_DIR_HOST)/bin/mktplinkfw \
  584. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
  585. -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
  586. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] -j -X 0x40000 \
  587. -a $(call rootfs_align,$(FILESYSTEM)) \
  588. $(wordlist 2,$(words $(1)),$(1)) \
  589. $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv [email protected] $@ || rm -f $@
  590. endef
  591. define Build/tplink-v2-header
  592. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  593. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  594. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  595. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  596. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  597. -k $@ -o [email protected] $(1)
  598. @mv [email protected] $@
  599. endef
  600. define Build/tplink-v2-image
  601. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  602. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  603. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  604. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  605. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  606. cat [email protected] >> $@
  607. rm -rf [email protected]
  608. endef
  609. define Build/uImage
  610. $(if $(UIMAGE_TIME),SOURCE_DATE_EPOCH="$(UIMAGE_TIME)") \
  611. mkimage \
  612. -A $(LINUX_KARCH) \
  613. -O linux \
  614. -T kernel \
  615. -C $(word 1,$(1)) \
  616. -a $(KERNEL_LOADADDR) \
  617. -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  618. -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
  619. $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
  620. $(wordlist 2,$(words $(1)),$(1)) \
  621. -d $@ [email protected]
  622. mv [email protected] $@
  623. endef
  624. define Build/xor-image
  625. $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o [email protected] $(1)
  626. mv [email protected] $@
  627. endef
  628. define Build/zip
  629. rm -rf [email protected]
  630. mkdir [email protected]
  631. mv $@ [email protected]/$(word 1,$(1))
  632. TZ=UTC $(STAGING_DIR_HOST)/bin/zip -j -X \
  633. $(wordlist 2,$(words $(1)),$(1)) \
  634. $@ [email protected]/$(if $(word 1,$(1)),$(word 1,$(1)),$$(basename $@))
  635. rm -rf [email protected]
  636. endef
  637. define Build/zyxel-ras-image
  638. let \
  639. newsize="$(call exp_units,$(RAS_ROOTFS_SIZE))"; \
  640. $(STAGING_DIR_HOST)/bin/mkrasimage \
  641. -b $(RAS_BOARD) \
  642. -v $(RAS_VERSION) \
  643. -r $@ \
  644. -s $$newsize \
  645. -o [email protected] \
  646. $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
  647. && mv [email protected] $@
  648. endef