openpower-pnor: build a PNOR squashfs as consumed by OpenBMC

Recently, OpenBMC has started supporting a firmware update mechanism
that requires a specially formatted tarball to be passed to it.

Since we want op-build to produce images that are easily consumable,
this patch makes the openpower-pnor build produce one of these images.

There is currently no documentation of this format, although the code
that produces it from a PNOR is open source.

Signed-off-by: Charles P. Hofer <charles.hofer@ibm.com>
[stewart@linux.vnet.ibm.com: flattened commit history, rewrote commit message]
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
diff --git a/openpower/package/openpower-pnor/Config.in b/openpower/package/openpower-pnor/Config.in
index 9360628..644d281 100644
--- a/openpower/package/openpower-pnor/Config.in
+++ b/openpower/package/openpower-pnor/Config.in
@@ -8,6 +8,7 @@
         select BR2_PACKAGE_OCC
         select BR2_PACKAGE_CAPP_UCODE
         select BR2_PACKAGE_IMA_CATALOG
+        select BR2_PACKAGE_HOST_OPENPOWER_VPNOR
 	select BR2_PACKAGE_MACHINE_XML
         help
             Utilites for building a targeting binary image
@@ -144,3 +145,7 @@
 config BR2_OPENPOWER_PNOR_XZ_ENABLED
         bool "Enable xz compression in PNOR payloads"
         default n
+
+config BR2_BUILD_PNOR_SQUASHFS
+        bool "Create a virtual PNOR image along with the standard image"
+        default y
diff --git a/openpower/package/openpower-pnor/openpower-pnor.mk b/openpower/package/openpower-pnor/openpower-pnor.mk
index dd08018..b6c5cdf 100644
--- a/openpower/package/openpower-pnor/openpower-pnor.mk
+++ b/openpower/package/openpower-pnor/openpower-pnor.mk
@@ -48,6 +48,9 @@
     OPENPOWER_RELEASE=p8
 endif
 
+ifeq ($(BR2_BUILD_PNOR_SQUASHFS),y)
+    OPENPOWER_PNOR_DEPENDENCIES += host-openpower-vpnor
+endif
 
 OPENPOWER_PNOR_INSTALL_IMAGES = YES
 OPENPOWER_PNOR_INSTALL_TARGET = NO
@@ -123,6 +126,13 @@
             dd if=$(STAGING_DIR)/pnor/$(BR2_OPENPOWER_PNOR_FILENAME) of=$(STAGING_DIR)/pnor/$(BR2_OPENPOWER_PNOR_UPDATE_FILENAME) bs=32M count=1; \
             $(INSTALL) $(STAGING_DIR)/pnor/$(BR2_OPENPOWER_PNOR_UPDATE_FILENAME) $(BINARIES_DIR); \
         fi
+
+        # If this is a VPNOR system, run the generate-squashfs command and
+        # create a tarball
+        if [ "$(BR2_BUILD_PNOR_SQUASHFS)" == "y" ]; then \
+            PATH=$(PATH):$(HOST_DIR)/usr/bin $(HOST_DIR)/usr/bin/generate-squashfs -f $(STAGING_DIR)/pnor/$(BR2_OPENPOWER_PNOR_FILENAME).squashfs.tar $(STAGING_DIR)/pnor/$(BR2_OPENPOWER_PNOR_FILENAME); \
+            $(INSTALL) $(STAGING_DIR)/pnor/$(BR2_OPENPOWER_PNOR_FILENAME).squashfs.tar $(BINARIES_DIR); \
+        fi
 endef
 
 $(eval $(generic-package))