MEDIUM_SUPPORTED = cdrom netboot device-tree

KERNELMAJOR = 2.6
BASEVERSION = 5.4.0-26
KERNELVERSION = $(BASEVERSION)-generic
KERNEL_FLAVOUR = di
KERNELIMAGEVERSION = $(KERNELVERSION)
KERNELNAME = vmlinuz
KERNELNAME_ALT_SUFFIX = -$(KERNELVERSION)

GRUB_EFI=y
GRUB_PLATFORM=arm64-efi
GRUB_EFI_NAME=aa64
GRUB_FONT = /usr/share/grub/ascii.pf2

arch_boot_screens:
arch_tree:

# Extract GRUB EFI files.
.PHONY: arm64_grub_efi
arm64_grub_efi:
ifeq ($(GRUB_EFI),y)
	SIGNED_IMAGE="$(KERNELNAME_ALT_SUFFIX)" efi-image $(TEMP_GRUB_EFI) arm64-efi aa64 $(NETBOOT_PATH)
endif


# Supply GRUB EFI configuration.
.PHONY: arch_cd_info_dir
arch_cd_info_dir: arm64_grub_efi
	-rm -f $(TEMP_CD_INFO_DIR)/*
	mkdir -p $(TEMP_CD_INFO_DIR)

	if [ "$(GRUB_EFI)" = y ]; then \
		set -e; \
		mkdir -p $(TEMP_CD_INFO_DIR)/grub/arm64-efi; \
		cp -a $(TEMP_GRUB_EFI)/efi.img $(TEMP_CD_INFO_DIR)/grub/; \
		grub-gencfg \
			KERNEL /%install%/vmlinuz \
			INITRD /%install%/initrd.gz \
			HEADER boot/arm64/grub/grub-efi.cfg \
		> $(TEMP_CD_INFO_DIR)/grub/grub.cfg; \
		cp -a $(GRUB_FONT) $(TEMP_CD_INFO_DIR)/grub/font.pf2; \
		cp -a $(TEMP_GRUB_EFI)/boot/grub/arm64-efi/* \
			$(TEMP_CD_INFO_DIR)/grub/arm64-efi/; \
	fi

.PHONY: arch_miniiso
arch_miniiso: arm64_grub_efi
	-rm -f $(TEMP_CD_TREE)/*
	mkdir -p $(TEMP_CD_TREE)

	ln -f $(TEMP_KERNEL) $(TEMP_CD_TREE)/linux
	ln -f $(TEMP_INITRD) $(TEMP_CD_TREE)/initrd.gz

	mkdir -p $(TEMP_CD_TREE)/.disk
	echo "$(DISTRIBUTION_NAME) $(DEBIAN_VERSION) $(ARCH) - netboot mini.iso $(BUILD_DATE)"\
	> $(TEMP_CD_TREE)/.disk/info

	if [ "$(GRUB_EFI)" = y ]; then \
		set -e; \
		mkdir -p $(TEMP_CD_TREE)/boot/grub/arm64-efi; \
		cp -a $(TEMP_GRUB_EFI)/efi.img $(TEMP_CD_TREE)/boot/grub/; \
		grub-gencfg \
			KERNEL /linux \
			INITRD /initrd.gz \
			HEADER boot/arm64/grub/grub-efi.cfg \
		> $(TEMP_CD_TREE)/boot/grub/grub.cfg; \
		cp -a $(GRUB_FONT) $(TEMP_CD_TREE)/boot/grub/font.pf2; \
		cp -a $(TEMP_GRUB_EFI)/boot/grub/arm64-efi/* \
			$(TEMP_CD_TREE)/boot/grub/arm64-efi/; \
	fi

	if [ "$(GRUB_EFI)" = y ]; then \
		xorriso -as mkisofs -r -J -c boot.cat \
			-partition_offset 16 \
			-append_partition 2 0xef $(TEMP_GRUB_EFI)/efi.img \
			-e --interval:appended_partition_2:all:: \
			-no-emul-boot \
			-o $(TEMP_MINIISO) $(TEMP_CD_TREE); \
	fi

.PHONY: arch_netboot_dir
arch_netboot_dir: arm64_grub_efi
	-rm -f $(TEMP_NETBOOT_DIR)
	mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
	cp $(TEMP_KERNEL) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/linux
	cp $(TEMP_INITRD) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/initrd.gz

	if [ "$(GRUB_EFI)" = y ]; then \
		set -e; \
		mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/arm64-efi; \
		cp -a $(TEMP_GRUB_EFI)/bootnetaa64.efi $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH); \
		cp -a $(GRUB_FONT) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/font.pf2; \
		cp -a $(TEMP_GRUB_EFI)/boot/grub/arm64-efi/* \
			$(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/arm64-efi/; \
		grub-gencfg \
			KERNEL /$(NETBOOT_PATH)/linux \
			INITRD /$(NETBOOT_PATH)/initrd.gz \
			HEADER boot/arm64/grub/grub-efi.cfg \
		> $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/grub.cfg; \
	fi
