FLAVOUR_SUPPORTED = "" gtk tiny

MEDIA_TYPE = bootable drive

GZIPPED = .gz
EXTRANAME = hd-media/

# Add the gtk images on to the bootable image.
EXTRATARGETS = build_hd-media_gtk
INITRD_GTK = dest/hd-media/gtk/initrd.gz
TARGET = $(KERNEL) $(INITRD) $(DEPTHCHARGE) hd-media_tarball hd-media_images_concatenateable

MANIFEST-KERNEL = "Kernel for use on USB memory sticks"
MANIFEST-INITRD = "Initrd for use on USB memory sticks"
MANIFEST-DEPTHCHARGE = "Disk/partition image for ChromeOS boards for use on USB memory sticks"

# This is a 953 MiB image, large enough to put a netinst iso in (being
# able to fit the full CD on it is just a bonus..), and small enough to
# fit on a low-end memory stick, such as those advertised as being 1
# gigabyte in size.
IMAGE_SIZE = 976560

.PHONY: hd-media_tarball
hd-media_tarball: $(TEMP_KERNEL) $(TEMP_INITRD) $(TEMP_DTBS)
	-rm -rf $(TEMP)/hd-media
	mkdir $(TEMP)/hd-media
	cp $(TEMP_KERNEL) $(TEMP)/hd-media/vmlinuz
	cp $(TEMP_INITRD) $(TEMP)/hd-media/initrd.gz
	mkdir $(TEMP)/hd-media/gtk
	cp $(INITRD_GTK) $(TEMP)/hd-media/gtk/initrd.gz
	mkdir $(TEMP)/hd-media/extlinux
	cp boot/arm64/extlinux/extlinux-gtk.conf $(TEMP)/hd-media/extlinux/extlinux.conf
	cp -r $(TEMP_DTBS) $(TEMP)/hd-media/dtbs/
	cp boot/README.device-tree $(TEMP)/hd-media/dtbs/README
	gen-tarball $(TEMP)/hd-media $(SOME_DEST)/$(EXTRANAME)/hd-media.tar.gz

.PHONY: hd-media_images_concatenateable
hd-media_images_concatenateable: $(TEMP_KERNEL) $(TEMP_INITRD) $(TEMP_DTBS)
	-rm -rf $(TEMP)/hd-media_images_concatenateable
	mkdir $(TEMP)/hd-media_images_concatenateable
	cp $(TEMP_KERNEL) $(TEMP)/hd-media_images_concatenateable/vmlinuz
	cp $(TEMP_INITRD) $(TEMP)/hd-media_images_concatenateable/initrd.gz
	mkdir $(TEMP)/hd-media_images_concatenateable/extlinux
	cp boot/arm64/extlinux/extlinux-gtk.conf $(TEMP)/hd-media_images_concatenateable/extlinux/extlinux.conf
	cp -r $(TEMP_DTBS) $(TEMP)/hd-media_images_concatenateable/dtbs/
	cp boot/README.device-tree $(TEMP)/hd-media_images_concatenateable/dtbs/README
	mkdir -p $(SOME_DEST)/$(EXTRANAME)/SD-card-images/$(CONCATENATEABLE_SUFFIX)
	for target in a64-olinuxino nanopi_neo2 orangepi_one_plus 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 ; \
		pigz -9nmf $(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 ; \
		pigz -9nmf $(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 ; \
		pigz -9nmf $(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)/hd-media_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)/"
