MEDIA_TYPE = netboot image

NETBOOT_DIR_TARGETS = $(TEMP_INITRD) $(TEMP_KERNEL)
TARGET = $(NETBOOT_DIR) $(NETBOOT_TAR) $(MINIISO) netboot_images_concatenateable
EXTRANAME = $(MEDIUM)/

MANIFEST-NETBOOT_DIR = "PXE boot directory for tftp server"
MANIFEST-NETBOOT_TAR = "tarball of PXE boot directory"
MANIFEST-MINIISO = "tiny CD image that boots the netboot installer"

IMAGE_SIZE = 150000

.PHONY: netboot_images_concatenateable
netboot_images_concatenateable: $(TEMP_KERNEL) $(TEMP_INITRD) $(TEMP_DTBS)
	-rm -rf $(TEMP)/netboot_images_concatenateable
	mkdir $(TEMP)/netboot_images_concatenateable
	cp $(TEMP_KERNEL) $(TEMP)/netboot_images_concatenateable/vmlinuz
	cp $(TEMP_INITRD) $(TEMP)/netboot_images_concatenateable/initrd.gz
	mkdir $(TEMP)/netboot_images_concatenateable/extlinux
	cp boot/arm64/extlinux/extlinux.conf $(TEMP)/netboot_images_concatenateable/extlinux/
	cp -r $(TEMP_DTBS) $(TEMP)/netboot_images_concatenateable/dtbs/
	cp boot/README.device-tree $(TEMP)/netboot_images_concatenateable/dtbs/README
	mkdir -p $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)
	for target in a64-olinuxino nanopi_neo2 orangepi_zero_plus2 pine64_plus pinebook teres_i ; do \
		echo "Providing u-boot binaries for $$target ..." ; \
		gen-hd-image -v -s "$(IMAGE_SIZE)" -p 32768 -b firmware -o $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
		TARGET=/usr/lib/u-boot/$${target} u-boot-install-sunxi $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
		gzip -9nf $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
	done
	for target in firefly-rk3399 pinebook-pro-rk3399 rockpro64-rk3399 rock64-rk3328 rock-pi-4-rk3399; do \
		echo "Providing u-boot binaries for $$target ..." ; \
		gen-hd-image -v -p 32768 -s "$(IMAGE_SIZE)" -b firmware -o $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
		TARGET=/usr/lib/u-boot/$${target} u-boot-install-rockchip $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
		gzip -9nf $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
	done
	for target in puma-rk3399 ; do \
		echo "Providing u-boot binaries for $$target ..." ; \
		gen-hd-image -v -p 32768 -s "$(IMAGE_SIZE)" -b firmware -o $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
		TARGET=/usr/lib/u-boot/$${target} UBOOT_OFFSET=512 u-boot-install-rockchip $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
		gzip -9nf $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.$${target}.img ; \
	done
	gen-hd-image -v -z -p 32768 -b firmware -s "$(IMAGE_SIZE)" -o "$(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/firmware.none.img"
	gen-hd-image -v -z -p 32768 -b partition -s "$(IMAGE_SIZE)" -i "$(TEMP)/netboot_images_concatenateable" -o "$(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/partition.img"
	cp boot/README.concatenateable_images "$(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)/"
