image-commands.mk 19 KB

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