MEDIA_TYPE = netboot image

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

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

# 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 6291440 # 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 * 11 - 32 so slugimage will pad the
	# kernel area to 131072 * 11, i.e. 11 blocks.
	util/pad $(TEMP)/$(KERNELNAME).nslu2 1441760
	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"

