Add support for creating a squashfs image

Signed-off-by: Jon Ringle <jon@ringle.org>

Index: rules/post/images.make
===================================================================
--- rules/post/images.make	(revision 9989)
+++ rules/post/images.make	(working copy)
@@ -78,6 +78,7 @@
 SEL_ROOTFS-$(PTXCONF_IMAGE_EXT2_GZIP)	+= $(IMAGEDIR)/root.ext2.gz
 SEL_ROOTFS-$(PTXCONF_IMAGE_UIMAGE)	+= $(IMAGEDIR)/uRamdisk
 SEL_ROOTFS-$(PTXCONF_IMAGE_CPIO)	+= $(IMAGEDIR)/initrd.gz
+SEL_ROOTFS-$(PTXCONF_IMAGE_SQUASHFS)	+= $(IMAGEDIR)/root.squashfs
 
 #
 # extract all current ipkgs into the working directory
@@ -118,6 +119,24 @@
 	@echo "done."
 
 #
+# create the squashfs image
+#
+$(IMAGEDIR)/root.squashfs: $(STATEDIR)/image_working_dir $(STATEDIR)/host-squashfs-tools.install
+	@echo -n "Creating root.squashfs from working dir..."
+	@cd $(WORKDIR);							\
+	(awk -F: $(DOPERMISSIONS) $(IMAGEDIR)/permissions &&		\
+	(								\
+		echo -n "$(PTXCONF_SYSROOT_HOST)/sbin/mksquashfs ";	\
+		echo -n "$(WORKDIR) ";					\
+		echo -n "$@ ";						\
+		echo -n "-noappend ";					\
+		echo -n "-b $(PTXCONF_IMAGE_SQUASHFS_BLOCK_SIZE) ";	\
+		echo -n "$(if $(subst "y",,$(PTXCONF_ENDIAN_BIG)),-be,-le) "; \
+		echo -n $(PTXCONF_IMAGE_SQUASHFS_EXTRA_ARGS) )	\
+	) | $(FAKEROOT) --
+	@echo "done."
+
+#
 # create the ext2 image
 #
 $(IMAGEDIR)/root.ext2: $(STATEDIR)/image_working_dir
Index: rules/host-squashfs-tools.make
===================================================================
--- rules/host-squashfs-tools.make	(revision 0)
+++ rules/host-squashfs-tools.make	(revision 0)
@@ -0,0 +1,71 @@
+# -*-makefile-*-
+
+#
+# We provide this package
+#
+HOST_PACKAGES-$(PTXCONF_HOST_SQUASHFS_TOOLS) += host-squashfs-tools
+
+#
+# Paths and names
+#
+HOST_SQUASHFS_TOOLS_VERSION	:= 3.4
+HOST_SQUASHFS_TOOLS		:= squashfs$(HOST_SQUASHFS_TOOLS_VERSION)
+HOST_SQUASHFS_TOOLS_SUFFIX	:= tar.gz
+HOST_SQUASHFS_TOOLS_URL		:= http://downloads.sourceforge.net/squashfs/$(HOST_SQUASHFS_TOOLS).$(HOST_SQUASHFS_TOOLS_SUFFIX)
+HOST_SQUASHFS_TOOLS_SOURCE	:= $(SRCDIR)/$(HOST_SQUASHFS_TOOLS).$(HOST_SQUASHFS_TOOLS_SUFFIX)
+HOST_SQUASHFS_TOOLS_DIR		:= $(HOST_BUILDDIR)/$(HOST_SQUASHFS_TOOLS)/squashfs-tools
+
+# ----------------------------------------------------------------------------
+# Get
+# ----------------------------------------------------------------------------
+
+$(HOST_SQUASHFS_TOOLS_SOURCE):
+	@$(call targetinfo)
+	@$(call get, HOST_SQUASHFS_TOOLS)
+
+# ----------------------------------------------------------------------------
+# Extract
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/host-squashfs-tools.extract:
+	@$(call targetinfo)
+	@$(call clean, $(HOST_SQUASHFS_TOOLS_DIR))
+	@$(call extract, HOST_SQUASHFS_TOOLS, $(HOST_BUILDDIR))
+	@$(call patchin, HOST_SQUASHFS_TOOLS, $(HOST_SQUASHFS_TOOLS_DIR))
+	@$(call touch)
+
+# ----------------------------------------------------------------------------
+# Prepare
+# ----------------------------------------------------------------------------
+
+HOST_SQUASHFS_TOOLS_COMPILE_ENV := \
+	$(HOST_ENV)
+
+HOST_SQUASHFS_TOOLS_MAKEVARS	:= \
+	INSTALL_DIR="$(PTXCONF_SYSROOT_HOST)/sbin"
+
+$(STATEDIR)/host-squashfs-tools.prepare:
+	@$(call targetinfo)
+	@$(call touch)
+
+# ----------------------------------------------------------------------------
+# Compile
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/host-squashfs-tools.compile:
+	@$(call targetinfo)
+	cd $(HOST_SQUASHFS_TOOLS_DIR) && \
+		$(HOST_SQUASHFS_TOOLS_PATH) \
+		$(HOST_SQUASHFS_TOOLS_COMPILE_ENV) \
+		$(MAKE) $(HOST_SQUASHFS_TOOLS_MAKEVARS) $(PARALLELMFLAGS_BROKEN)
+	@$(call touch)
+
+# ----------------------------------------------------------------------------
+# Clean
+# ----------------------------------------------------------------------------
+
+host-squashfs-tools_clean:
+	rm -rf $(STATEDIR)/host-squashfs-tools.*
+	rm -rf $(HOST_SQUASHFS_TOOLS_DIR)
+
+# vim: syntax=make
Index: rules/host-squashfs-tools.in
===================================================================
--- rules/host-squashfs-tools.in	(revision 0)
+++ rules/host-squashfs-tools.in	(revision 0)
@@ -0,0 +1,5 @@
+## SECTION=hosttools_noprompt
+
+config HOST_SQUASHFS_TOOLS
+	tristate
+	prompt "squashfs tools"
Index: platforms/Kconfig
===================================================================
--- platforms/Kconfig	(revision 9989)
+++ platforms/Kconfig	(working copy)
@@ -53,6 +53,7 @@
 source "platforms/image_uimage.in"
 source "platforms/image_cpio.in"
 source "platforms/image_ext2.in"
+source "platforms/image_squashfs.in"
 endmenu
 
 source "platforms/flash.in"
Index: platforms/image_squashfs.in
===================================================================
--- platforms/image_squashfs.in	(revision 0)
+++ platforms/image_squashfs.in	(revision 0)
@@ -0,0 +1,29 @@
+menuconfig IMAGE_SQUASHFS
+	bool
+	select HOST_SQUASHFS_TOOLS
+	prompt "Generate images/root.squashfs    "
+	help
+	  Build a squashfs image of the root filesystem. This image can be stored
+	  linearly into target's flash device at the start of the desired
+	  partition. You should erase the whole partition first if the image
+	  is smaller than partition's size. If not, garbage data in the remaining
+	  space could confuse the filesystem driver.
+
+if IMAGE_SQUASHFS
+
+config IMAGE_SQUASHFS_BLOCK_SIZE
+	string
+	default "128K"
+	prompt "Block size"
+	help
+	  This allows the block size to be selected, both "K" and "M" postfixes are
+	  supported, this can be either 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K or 1M bytes.
+
+config IMAGE_SQUASHFS_EXTRA_ARGS
+	string
+	default ""
+	prompt "extra arguments passed to mksquashfs"
+	help
+	  You can add extra arguments for mksquashfs here
+
+endif
