+# $(1): (empty)
+# $(2): Board name (small caps)
+# $(3): Kernel board specific cmdline
+# $(4): Kernel mtdparts definition
+# $(5): U-Boot magic
+define Image/Build/NetgearNAND/buildkernel
+ $(eval kernelsize=$(call mtdpartsize,kernel,$(4)))
+ $(call PatchKernelLzma,$(2),$(3) $(4),-d20)
+ dd if=$(KDIR_TMP)/vmlinux-$(2).bin.lzma \
+ of=$(KDIR_TMP)/vmlinux-$(2).bin.tmp \
+ bs=$$$$(($(kernelsize)-131072-2*64-1)) \
+ count=1 conv=sync
+ $(call MkuImage,lzma,-M $(5),$(KDIR_TMP)/vmlinux-$(2).bin.tmp,$(KDIR_TMP)/vmlinux-$(2).uImage)
+ echo -ne '\xff' >> $(KDIR_TMP)/vmlinux-$(2).uImage
+ # create a fake rootfs image
+ dd if=/dev/zero of=$(KDIR_TMP)/fakeroot-$(2) bs=131072 count=1
+ mkimage -A mips -O linux -T filesystem -C none \
+ -a 0xbf070000 -e 0xbf070000 \
+ -n 'MIPS OpenWrt fakeroot' \
+ -d $(KDIR_TMP)/fakeroot-$(2) \
+ -M $(5) \
+ $(KDIR_TMP)/fakeroot-$(2).uImage
+ # append the fake rootfs image to the kernel, it will reside in the last
+ # erase block of the kernel partition
+ cat $(KDIR_TMP)/fakeroot-$(2).uImage >> $(KDIR_TMP)/vmlinux-$(2).uImage
+endef
+
+
+# $(1): rootfs image suffix
+# $(2): Board name (small caps)
+# $(3): Kernel board specific cmdline
+# $(4): Kernel mtdparts definition
+# $(5): U-Boot magic
+# $(6): Board name (upper caps)
+# $(7): firmware region code (not used yet)
+# $(8): DNI Hardware version
+define Image/Build/NetgearNAND
+ $(eval firmwaresize=$(call mtdpartsize,firmware,$(4)))
+ $(eval kernelsize=$(call mtdpartsize,kernel,$(4)))
+ $(eval imageraw=$(KDIR_TMP)/$(2)-raw.img)
+ $(CP) $(KDIR)/root.squashfs-raw $(KDIR_TMP)/root.squashfs
+ echo -ne '\xde\xad\xc0\xde' > $(KDIR_TMP)/jffs2.eof
+ $(call ubinize,ubinize-$(2).ini,$(KDIR_TMP),$(KDIR_TMP)/$(2)-root.ubi,128KiB,2048)
+ # Create firmware image full of 0xff to use the UBIFS auto-resize function
+ firmwareblocks=$$$$(($(firmwaresize) / 131072)); \
+ dd if=/dev/zero bs=128k count=$$$${firmwareblocks} conv=sync | tr '\000' '\377' > $(imageraw)
+ # Insert Kernel and UBI image to rootfs and generate DNI image
+ dd if=$(KDIR_TMP)/vmlinux-$(2).uImage of=$(imageraw) conv=notrunc
+ kernelblocks=$$$$(($(kernelsize) / 131072)); \
+ dd if=$(KDIR_TMP)/$(2)-root.ubi of=$(imageraw) bs=128k seek=$$$${kernelblocks} conv=notrunc
+ $(STAGING_DIR_HOST)/bin/mkdniimg \
+ -B $(6) -v OpenWrt.$(REVISION) -r "$$$$r" $(8) \
+ -i $(imageraw) \
+ -o $(call imgname,ubi,$(2))-recovery.img
+endef
+
+