image-commands.mk 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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)$(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. mkdir -p "$(STAGING_DIR_IMAGE)"
  47. dd if="[email protected]" of="$(STAGING_DIR_IMAGE)/$(BOARD)$(if $(SUBTARGET),-$(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. define Build/append-ubi
  116. sh $(TOPDIR)/scripts/ubinize-image.sh \
  117. $(if $(UBOOTENV_IN_UBI),--uboot-env) \
  118. $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
  119. $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
  120. --rootfs $(IMAGE_ROOTFS) \
  121. [email protected] \
  122. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  123. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  124. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  125. $(UBINIZE_OPTS)
  126. cat [email protected] >> $@
  127. rm [email protected]
  128. endef
  129. define Build/ubinize-kernel
  130. cp $@ [email protected]
  131. sh $(TOPDIR)/scripts/ubinize-image.sh \
  132. --kernel [email protected] \
  133. $@ \
  134. -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
  135. $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
  136. $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
  137. $(UBINIZE_OPTS)
  138. rm [email protected]
  139. endef
  140. define Build/append-uboot
  141. dd if=$(UBOOT_PATH) >> $@
  142. endef
  143. # append a fake/empty uImage header, to fool bootloaders rootfs integrity check
  144. # for example
  145. define Build/append-uImage-fakehdr
  146. $(eval type=$(word 1,$(1)))
  147. $(eval magic=$(word 2,$(1)))
  148. touch [email protected]
  149. $(STAGING_DIR_HOST)/bin/mkimage \
  150. -A $(LINUX_KARCH) -O linux -T $(type) -C none \
  151. -n '$(VERSION_DIST) fake $(type)' \
  152. $(if $(magic),-M $(magic)) \
  153. -d [email protected] \
  154. -s \
  155. [email protected]
  156. cat [email protected] >> $@
  157. endef
  158. define Build/buffalo-dhp-image
  159. $(STAGING_DIR_HOST)/bin/mkdhpimg $@ [email protected]
  160. mv [email protected] $@
  161. endef
  162. define Build/buffalo-enc
  163. $(eval product=$(word 1,$(1)))
  164. $(eval version=$(word 2,$(1)))
  165. $(eval args=$(wordlist 3,$(words $(1)),$(1)))
  166. $(STAGING_DIR_HOST)/bin/buffalo-enc \
  167. -p $(product) -v $(version) $(args) \
  168. -i $@ -o [email protected]
  169. mv [email protected] $@
  170. endef
  171. define Build/buffalo-enc-tag
  172. $(call Build/buffalo-enc,'' '' -S 152 $(1))
  173. endef
  174. define Build/buffalo-tag-dhp
  175. $(eval product=$(word 1,$(1)))
  176. $(eval region=$(word 2,$(1)))
  177. $(eval language=$(word 3,$(1)))
  178. $(STAGING_DIR_HOST)/bin/buffalo-tag \
  179. -d 0x01000000 -w 1 \
  180. -a $(BUFFALO_TAG_PLATFORM) \
  181. -v $(BUFFALO_TAG_VERSION) -m $(BUFFALO_TAG_MINOR) \
  182. -b $(product) -p $(product) \
  183. -r $(region) -r $(region) -l $(language) \
  184. -I $@ -o [email protected]
  185. mv [email protected] $@
  186. endef
  187. define Build/check-size
  188. @imagesize="$$(stat -c%s $@)"; \
  189. limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
  190. [ $$limitsize -ge $$imagesize ] || { \
  191. $(call ERROR_MESSAGE, WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
  192. rm -f $@; \
  193. }
  194. endef
  195. define Build/copy-file
  196. cat "$(1)" > "$@"
  197. endef
  198. define Build/edimax-header
  199. $(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o [email protected] $(1)
  200. @mv [email protected] $@
  201. endef
  202. define Build/elecom-product-header
  203. $(eval product=$(word 1,$(1)))
  204. $(eval fw=$(if $(word 2,$(1)),$(word 2,$(1)),$@))
  205. ( \
  206. echo -n -e "ELECOM\x00\x00$(product)" | dd bs=40 count=1 conv=sync; \
  207. echo -n "0.00" | dd bs=16 count=1 conv=sync; \
  208. dd if=$(fw); \
  209. ) > $(fw).new
  210. mv $(fw).new $(fw)
  211. endef
  212. define Build/elecom-wrc-gs-factory
  213. $(eval product=$(word 1,$(1)))
  214. $(eval version=$(word 2,$(1)))
  215. $(eval hash_opt=$(word 3,$(1)))
  216. $(MKHASH) md5 $(hash_opt) $@ >> $@
  217. ( \
  218. echo -n "ELECOM $(product) v$(version)" | \
  219. dd bs=32 count=1 conv=sync; \
  220. dd if=$@; \
  221. ) > [email protected]
  222. mv [email protected] $@
  223. endef
  224. define Build/elx-header
  225. $(eval hw_id=$(word 1,$(1)))
  226. $(eval xor_pattern=$(word 2,$(1)))
  227. ( \
  228. echo -ne "\x00\x00\x00\x00\x00\x00\x00\x03" | \
  229. dd bs=42 count=1 conv=sync; \
  230. hw_id="$(hw_id)"; \
  231. echo -ne "\x$${hw_id:0:2}\x$${hw_id:2:2}\x$${hw_id:4:2}\x$${hw_id:6:2}" | \
  232. dd bs=20 count=1 conv=sync; \
  233. echo -ne "$$(printf '%08x' $$(stat -c%s $@) | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  234. dd bs=8 count=1 conv=sync; \
  235. echo -ne "$$($(MKHASH) md5 $@ | fold -s2 | xargs -I {} echo \\x{} | tr -d '\n')" | \
  236. dd bs=58 count=1 conv=sync; \
  237. ) > $(KDIR)/tmp/$(DEVICE_NAME).header
  238. $(call Build/xor-image,-p $(xor_pattern) -x)
  239. cat $(KDIR)/tmp/$(DEVICE_NAME).header $@ > [email protected]
  240. mv [email protected] $@
  241. rm -rf $(KDIR)/tmp/$(DEVICE_NAME).header
  242. endef
  243. define Build/eva-image
  244. $(STAGING_DIR_HOST)/bin/lzma2eva $(KERNEL_LOADADDR) $(KERNEL_LOADADDR) $@ [email protected]
  245. mv [email protected] $@
  246. endef
  247. define Build/initrd_compression
  248. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2),.bzip2) \
  249. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP),.gzip) \
  250. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4),.lz4) \
  251. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA),.lzma) \
  252. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO),.lzo) \
  253. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ),.xz) \
  254. $(if $(CONFIG_TARGET_INITRAMFS_COMPRESSION_ZSTD),.zstd)
  255. endef
  256. define Build/fit
  257. $(TOPDIR)/scripts/mkits.sh \
  258. -D $(DEVICE_NAME) -o [email protected] -k $@ \
  259. -C $(word 1,$(1)) \
  260. $(if $(word 2,$(1)),\
  261. $(if $(findstring 11,$(if $(DEVICE_DTS_OVERLAY),1)$(if $(findstring $(KERNEL_BUILD_DIR)/image-,$(word 2,$(1))),,1)), \
  262. -d $(KERNEL_BUILD_DIR)/image-$$(basename $(word 2,$(1))), \
  263. -d $(word 2,$(1)))) \
  264. $(if $(findstring with-rootfs,$(word 3,$(1))),-r $(IMAGE_ROOTFS)) \
  265. $(if $(findstring with-initrd,$(word 3,$(1))), \
  266. $(if $(CONFIG_TARGET_ROOTFS_INITRAMFS_SEPARATE), \
  267. -i $(KERNEL_BUILD_DIR)/initrd.cpio$(strip $(call Build/initrd_compression)))) \
  268. -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  269. $(if $(DEVICE_FDT_NUM),-n $(DEVICE_FDT_NUM)) \
  270. $(if $(DEVICE_DTS_DELIMITER),-l $(DEVICE_DTS_DELIMITER)) \
  271. $(if $(DEVICE_DTS_LOADADDR),-s $(DEVICE_DTS_LOADADDR)) \
  272. $(if $(DEVICE_DTS_OVERLAY),$(foreach dtso,$(DEVICE_DTS_OVERLAY), -O $(dtso):$(KERNEL_BUILD_DIR)/image-$(dtso).dtbo)) \
  273. -c $(if $(DEVICE_DTS_CONFIG),$(DEVICE_DTS_CONFIG),"config-1") \
  274. -A $(LINUX_KARCH) -v $(LINUX_VERSION)
  275. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage $(if $(findstring external,$(word 3,$(1))),\
  276. -E -B 0x1000 $(if $(findstring static,$(word 3,$(1))),-p 0x1000)) -f [email protected] [email protected]
  277. @mv [email protected] $@
  278. endef
  279. define Build/libdeflate-gzip
  280. $(STAGING_DIR_HOST)/bin/libdeflate-gzip -f -12 -c $@ $(1) > [email protected]
  281. @mv [email protected] $@
  282. endef
  283. define Build/gzip
  284. $(STAGING_DIR_HOST)/bin/gzip -f -9n -c $@ $(1) > [email protected]
  285. @mv [email protected] $@
  286. endef
  287. define Build/gzip-filename
  288. @mkdir -p [email protected]
  289. @cp $@ [email protected]/$(word 1,$(1))
  290. $(if $(SOURCE_DATE_EPOCH),touch -hcd "@$(SOURCE_DATE_EPOCH)" [email protected]/$(word 1,$(1)) $(word 2,$(1)))
  291. $(STAGING_DIR_HOST)/bin/gzip -f -9 -N -c [email protected]/$(word 1,$(1)) $(word 2,$(1)) > [email protected]
  292. @mv [email protected] $@
  293. @rm -rf [email protected]
  294. endef
  295. define Build/install-dtb
  296. $(call locked, \
  297. $(foreach dts,$(DEVICE_DTS), \
  298. $(CP) \
  299. $(DTS_DIR)/$(dts).dtb \
  300. $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
  301. ), \
  302. install-dtb-$(IMG_PREFIX) \
  303. )
  304. endef
  305. define Build/iptime-crc32
  306. $(STAGING_DIR_HOST)/bin/iptime-crc32 $(1) $@ [email protected]
  307. mv [email protected] $@
  308. endef
  309. define Build/iptime-naspkg
  310. $(STAGING_DIR_HOST)/bin/iptime-naspkg $(1) $@ [email protected]
  311. mv [email protected] $@
  312. endef
  313. define Build/jffs2
  314. rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
  315. mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
  316. cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
  317. $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
  318. $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
  319. --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
  320. -o [email protected] \
  321. -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
  322. 2>&1 1>/dev/null | awk '/^.+$$$$/' && \
  323. $(STAGING_DIR_HOST)/bin/padjffs2 [email protected] -J $(patsubst %k,,$(BLOCKSIZE))
  324. -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
  325. @mv [email protected] $@
  326. endef
  327. define Build/kernel2minor
  328. $(eval temp_file := $(shell mktemp))
  329. cp $@ $(temp_file)
  330. kernel2minor -k $(temp_file) -r $(temp_file).new $(1)
  331. mv $(temp_file).new $@
  332. rm -f $(temp_file)
  333. endef
  334. define Build/kernel-bin
  335. rm -f $@
  336. cp $< $@
  337. endef
  338. define Build/linksys-image
  339. $(TOPDIR)/scripts/linksys-image.sh \
  340. "$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
  341. $@ [email protected]
  342. mv [email protected] $@
  343. endef
  344. define Build/lzma
  345. $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
  346. endef
  347. define Build/lzma-no-dict
  348. $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) [email protected]
  349. @mv [email protected] $@
  350. endef
  351. define Build/moxa-encode-fw
  352. $(TOPDIR)/scripts/moxa-encode-fw.py \
  353. --input $@ \
  354. --output $@ \
  355. --magic $(MOXA_MAGIC) \
  356. --hwid $(MOXA_HWID) \
  357. --buildid 00000000
  358. endef
  359. define Build/netgear-chk
  360. $(STAGING_DIR_HOST)/bin/mkchkimg \
  361. -o [email protected] \
  362. -k $@ \
  363. -b $(NETGEAR_BOARD_ID) \
  364. $(if $(NETGEAR_REGION),-r $(NETGEAR_REGION),)
  365. mv [email protected] $@
  366. endef
  367. define Build/netgear-dni
  368. $(STAGING_DIR_HOST)/bin/mkdniimg \
  369. -B $(NETGEAR_BOARD_ID) -v $(shell cat $(VERSION_DIST)| sed -e 's/[[:space:]]/-/g').$(firstword $(subst -, ,$(REVISION))) \
  370. $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
  371. -r "$(1)" \
  372. -i $@ -o [email protected]
  373. mv [email protected] $@
  374. endef
  375. define Build/netgear-encrypted-factory
  376. $(TOPDIR)/scripts/netgear-encrypted-factory.py \
  377. --input-file $@ \
  378. --output-file $@ \
  379. --model $(NETGEAR_ENC_MODEL) \
  380. --region $(NETGEAR_ENC_REGION) \
  381. --version V1.0.0.0.$(shell cat $(VERSION_DIST)| sed -e 's/[[:space:]]/-/g').$(firstword $(subst -, ,$(REVISION))) \
  382. --encryption-block-size 0x20000 \
  383. --openssl-bin "$(STAGING_DIR_HOST)/bin/openssl" \
  384. --key 6865392d342b4d212964363d6d7e7765312c7132613364316e26322a5a5e2538 \
  385. --iv 4a253169516c38243d6c6d2d3b384145
  386. endef
  387. define Build/openmesh-image
  388. $(TOPDIR)/scripts/om-fwupgradecfg-gen.sh \
  389. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" \
  390. "[email protected]" \
  391. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" \
  392. "$(call param_get_default,rootfs,$(1),$@)"
  393. $(TOPDIR)/scripts/combined-ext-image.sh \
  394. "$(call param_get_default,ce_type,$(1),$(DEVICE_NAME))" "$@" \
  395. "[email protected]" "fwupgrade.cfg" \
  396. "$(call param_get_default,kernel,$(1),$(IMAGE_KERNEL))" "kernel" \
  397. "$(call param_get_default,rootfs,$(1),$@)" "rootfs"
  398. endef
  399. define Build/pad-extra
  400. dd if=/dev/zero bs=$(1) count=1 >> $@
  401. endef
  402. define Build/pad-offset
  403. let \
  404. size="$$(stat -c%s $@)" \
  405. pad="$(subst k,* 1024,$(word 1, $(1)))" \
  406. offset="$(subst k,* 1024,$(word 2, $(1)))" \
  407. pad="(pad - ((size + offset) % pad)) % pad" \
  408. newsize='size + pad'; \
  409. dd if=$@ [email protected] bs=$$newsize count=1 conv=sync
  410. mv [email protected] $@
  411. endef
  412. define Build/pad-rootfs
  413. $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
  414. $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
  415. endef
  416. define Build/pad-to
  417. $(call Image/pad-to,$@,$(1))
  418. endef
  419. define Build/patch-cmdline
  420. $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
  421. endef
  422. # Convert a raw image into a $1 type image.
  423. # E.g. | qemu-image vdi <optional extra arguments to qemu-img binary>
  424. define Build/qemu-image
  425. if command -v qemu-img; then \
  426. qemu-img convert -f raw -O $1 $@ [email protected]; \
  427. mv [email protected] $@; \
  428. else \
  429. echo "WARNING: Install qemu-img to create VDI/VMDK images" >&2; exit 1; \
  430. fi
  431. endef
  432. define Build/qsdk-ipq-factory-nand
  433. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  434. [email protected] ubi $@
  435. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  436. @mv [email protected] $@
  437. endef
  438. define Build/qsdk-ipq-factory-nor
  439. $(TOPDIR)/scripts/mkits-qsdk-ipq-image.sh \
  440. [email protected] hlos $(IMAGE_KERNEL) rootfs $(IMAGE_ROOTFS)
  441. PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f [email protected] [email protected]
  442. @mv [email protected] $@
  443. endef
  444. define Build/seama
  445. $(STAGING_DIR_HOST)/bin/seama -i $@ \
  446. -m "dev=/dev/mtdblock/$(SEAMA_MTDBLOCK)" -m "type=firmware"
  447. mv [email protected] $@
  448. endef
  449. define Build/seama-seal
  450. $(STAGING_DIR_HOST)/bin/seama -i $@ -s [email protected] \
  451. -m "signature=$(SEAMA_SIGNATURE)"
  452. mv [email protected] $@
  453. endef
  454. define Build/senao-header
  455. $(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o [email protected]
  456. mv [email protected] $@
  457. endef
  458. define Build/sysupgrade-tar
  459. sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
  460. --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
  461. --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
  462. --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
  463. $@
  464. endef
  465. define Build/tplink-safeloader
  466. -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
  467. -B $(TPLINK_BOARD_ID) \
  468. -V $(REVISION) \
  469. -k $(IMAGE_KERNEL) \
  470. -r $@ \
  471. -o [email protected] \
  472. -j \
  473. $(wordlist 2,$(words $(1)),$(1)) \
  474. $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv [email protected] $@ || rm -f $@
  475. endef
  476. define Build/tplink-v1-header
  477. $(STAGING_DIR_HOST)/bin/mktplinkfw \
  478. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  479. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  480. -m $(TPLINK_HEADER_VERSION) -N "$(VERSION_DIST)" -V $(REVISION) \
  481. -k $@ -o [email protected] $(1)
  482. @mv [email protected] $@
  483. endef
  484. # combine kernel and rootfs into one image
  485. # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
  486. # <type> is "sysupgrade" or "factory"
  487. #
  488. # -a align the rootfs start on an <align> bytes boundary
  489. # -j add jffs2 end-of-filesystem markers
  490. # -s strip padding from end of the image
  491. # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
  492. define Build/tplink-v1-image
  493. -$(STAGING_DIR_HOST)/bin/mktplinkfw \
  494. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) \
  495. -N "$(VERSION_DIST)" -V $(REVISION) -m $(TPLINK_HEADER_VERSION) \
  496. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] -j -X 0x40000 \
  497. -a $(call rootfs_align,$(FILESYSTEM)) \
  498. $(wordlist 2,$(words $(1)),$(1)) \
  499. $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv [email protected] $@ || rm -f $@
  500. endef
  501. define Build/tplink-v2-header
  502. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  503. -c -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -L $(KERNEL_LOADADDR) \
  504. -E $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  505. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  506. -T $(TPLINK_HVERSION) -V "ver. 2.0" \
  507. -k $@ -o [email protected] $(1)
  508. @mv [email protected] $@
  509. endef
  510. define Build/tplink-v2-image
  511. $(STAGING_DIR_HOST)/bin/mktplinkfw2 \
  512. -H $(TPLINK_HWID) -W $(TPLINK_HWREV) \
  513. -w $(TPLINK_HWREVADD) -F "$(TPLINK_FLASHLAYOUT)" \
  514. -T $(TPLINK_HVERSION) -V "ver. 2.0" -a 0x4 -j \
  515. -k $(IMAGE_KERNEL) -r $(IMAGE_ROOTFS) -o [email protected] $(1)
  516. cat [email protected] >> $@
  517. rm -rf [email protected]
  518. endef
  519. define Build/uImage
  520. $(if $(UIMAGE_TIME),SOURCE_DATE_EPOCH="$(UIMAGE_TIME)") \
  521. mkimage \
  522. -A $(LINUX_KARCH) \
  523. -O linux \
  524. -T kernel \
  525. -C $(word 1,$(1)) \
  526. -a $(KERNEL_LOADADDR) \
  527. -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
  528. -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION))' \
  529. $(if $(UIMAGE_MAGIC),-M $(UIMAGE_MAGIC)) \
  530. $(wordlist 2,$(words $(1)),$(1)) \
  531. -d $@ [email protected]
  532. mv [email protected] $@
  533. endef
  534. define Build/xor-image
  535. $(STAGING_DIR_HOST)/bin/xorimage -i $@ -o [email protected] $(1)
  536. mv [email protected] $@
  537. endef
  538. define Build/zip
  539. rm -rf [email protected]
  540. mkdir [email protected]
  541. mv $@ [email protected]/$(word 1,$(1))
  542. TZ=UTC $(STAGING_DIR_HOST)/bin/zip -j -X \
  543. $(wordlist 2,$(words $(1)),$(1)) \
  544. $@ [email protected]/$(if $(word 1,$(1)),$(word 1,$(1)),$$(basename $@))
  545. rm -rf [email protected]
  546. endef
  547. define Build/zyxel-ras-image
  548. let \
  549. newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
  550. $(STAGING_DIR_HOST)/bin/mkrasimage \
  551. -b $(RAS_BOARD) \
  552. -v $(RAS_VERSION) \
  553. -r $@ \
  554. -s $$newsize \
  555. -o [email protected] \
  556. $(if $(findstring separate-kernel,$(word 1,$(1))),-k $(IMAGE_KERNEL)) \
  557. && mv [email protected] $@
  558. endef