MEDIA_TYPE = netboot image

TARGET = $(TEMP_INITRD) $(TEMP_KERNEL) kuroboxpro lschl lsgl lswsgl lswtgl
EXTRANAME = $(MEDIUM)/
TYPE = netboot/network-console

TEMP_INITRD_XZ = $(TEMP)/initrd.xz

$(TEMP_INITRD_XZ): $(TEMP_INITRD)
	zcat $(TEMP_INITRD) | xz --check=crc32 -9 > $(TEMP_INITRD_XZ)

# Buffalo Kurobox Pro
kuroboxpro: $(TEMP_INITRD_XZ)
	mkdir -p $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro
	cat $(TEMP_KERNEL) $(TEMP_DTBS)/orion5x-kuroboxpro.dtb > $(TEMP)/vmlinuz-kuroboxpro
	mkimage -A arm -O linux -T kernel -C none -a 0x01a00000 -e 0x01a00000 -n "Debian kernel" -d $(TEMP)/vmlinuz-kuroboxpro $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro/uImage.buffalo
	mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n "debian-installer ramdisk" -d $(TEMP_INITRD_XZ) $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro/initrd.buffalo
	install -m 744 boot/arm/kuroboxpro-config-debian $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro/config-debian
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro/config-debian "Script to run debian-installer"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro/uImage.buffalo "Linux kernel for Kurobox Pro"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/kuroboxpro/initrd.buffalo "initrd for Kurobox Pro"

# Buffalo Linkstation Live V3 (LS-CHL)
lschl: kuroboxpro
	mkdir -p $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl
	cat $(TEMP_KERNEL) $(TEMP_DTBS)/orion5x-linkstation-lschl.dtb > $(TEMP)/vmlinuz-lschl
	mkimage -A arm -O linux -T kernel -C none -a 0x01a00000 -e 0x01a00000 -n "Debian kernel" -d $(TEMP)/vmlinuz-lschl $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl/uImage.buffalo
	ln -nfs ../kuroboxpro/initrd.buffalo $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl/
	install -m 744 boot/arm/linkstation-config-debian $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl/config-debian
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl/config-debian "Script to run debian-installer"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl/uImage.buffalo "Linux kernel for Linkstation Live V3"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-chl/initrd.buffalo "initrd for Linkstation Live V3"

# Buffalo Linkstation LS-WTGL
lswtgl: lschl
	mkdir -p $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl
	cat $(TEMP_KERNEL) $(TEMP_DTBS)/orion5x-linkstation-lswtgl.dtb > $(TEMP)/vmlinuz-lswtgl
	mkimage -A arm -O linux -T kernel -C none -a 0x01a00000 -e 0x01a00000 -n "Debian kernel" -d $(TEMP)/vmlinuz-lswtgl $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl/uImage.buffalo
	ln -nfs ../kuroboxpro/initrd.buffalo $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl/
	ln -nfs ../ls-chl/config-debian $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl/
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl/config-debian "Script to run debian-installer"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl/uImage.buffalo "Linux kernel for Linkstation LS-WTGL"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wtgl/initrd.buffalo "initrd for Linkstation LS-WTGL"

# Buffalo Linkstation Mini (LS-WSGL)
lswsgl: lschl
	mkdir -p $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl
	cat $(TEMP_KERNEL) $(TEMP_DTBS)/orion5x-lswsgl.dtb > $(TEMP)/vmlinuz-lswsgl
	mkimage -A arm -O linux -T kernel -C none -a 0x01a00000 -e 0x01a00000 -n "Debian kernel" -d $(TEMP)/vmlinuz-lswsgl $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl/uImage.buffalo
	ln -nfs ../kuroboxpro/initrd.buffalo $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl/
	ln -nfs ../ls-chl/config-debian $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl/
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl/config-debian "Script to run debian-installer"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl/uImage.buffalo "Linux kernel for Linkstation Mini (LS-WSGL)"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/ls-wsgl/initrd.buffalo "initrd for Linkstation Mini (LS-WSGL)"

# Buffalo Linkstation Pro/Live (LS-GL)
lsgl: lschl
	mkdir -p $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl
	cat $(TEMP_KERNEL) $(TEMP_DTBS)/orion5x-linkstation-lsgl.dtb > $(TEMP)/vmlinuz-lsgl
	mkimage -A arm -O linux -T kernel -C none -a 0x01a00000 -e 0x01a00000 -n "Debian kernel" -d $(TEMP)/vmlinuz-lsgl $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl/uImage.buffalo
	ln -nfs ../kuroboxpro/initrd.buffalo $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl/
	ln -nfs ../ls-chl/config-debian $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl/
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl/config-debian "Script to run debian-installer"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl/uImage.buffalo "Linux kernel for Linkstation Pro/Live (LS-GL)"
	update-manifest $(SOME_DEST)/$(EXTRANAME)buffalo/lspro_ls-gl/initrd.buffalo "initrd for Linkstation Pro/Live (LS-GL)"
