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