MEDIA_TYPE = netboot image

TARGET = $(INITRD) $(KERNEL) nslu2_swap $(SOME_DEST)/$(EXTRANAME)di-nslu2.bin
EXTRANAME = $(MEDIUM)/
TYPE = netboot/network-console
INITRD_FS = initramfs

MANIFEST-INITRD = "netboot initrd"
MANIFEST-KERNEL = "kernel image to netboot"

# byteswap boot loader, initrd and kernel for NSLU2
nslu2_swap: $(INITRD) $(KERNEL)
	cp /boot/apex.flash $(TEMP)/apex.flash
	util/pad $(TEMP)/apex.flash 131040 # < 1 block, multiple of 4
	devio "<<"$(TEMP)/apex.flash > $(TEMP)/apex.flash.swapped \
	    'xp $$,4'
	cp $(TEMP)/initrd.gz $(TEMP)/initrd.gz.nslu2
	util/pad $(TEMP)/initrd.gz.nslu2 5636080 # size of partition - 16 for header
	devio "<<"$(TEMP)/initrd.gz.nslu2 > $(TEMP)/initrd.gz.nslu2.swapped \
	    'xp $$,4'
	cp $(TEMP)/$(KERNELNAME) $(TEMP)/$(KERNELNAME).nslu2
	# Let's pad the kernel to 131072 * 16 - 32 so slugimage will pad the
	# kernel area to 131072 * 16, i.e. 16 blocks.
	util/pad $(TEMP)/$(KERNELNAME).nslu2 2097120
	devio "<<"$(TEMP)/$(KERNELNAME).nslu2 > $(TEMP)/$(KERNELNAME).nslu2.swapped \
	    'xp $$,4'

# Generate an image for Linksys NSLU2 which can be flashed
$(SOME_DEST)/$(EXTRANAME)di-nslu2.bin:
	slugimage -p -L $(TEMP)/apex.flash.swapped -r $(TEMP)/initrd.gz.nslu2.swapped \
	    -k $(TEMP)/$(KERNELNAME).nslu2.swapped -o $@
	update-manifest $@ "Flashable firmware image of debian-installer for NSLU2"

