Add support for using the hcode repo

    -Add hcode package to enable compiling hardware
     reference image
    -Modify pnor and sbe makefiles to include a dependency on
     the hcode repository
    -Modify config files so that p9 platfoms use the compiled
     version of the hardware reference image by default
    -Update hostboot-binaries.mk to install the ring images
     to the staging dir

[stewart: remove IBM Austin specific paths, update defconfigs]
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
diff --git a/openpower/configs/openpower_p9_mambo_defconfig b/openpower/configs/openpower_p9_mambo_defconfig
index be886df..cfdff54 100644
--- a/openpower/configs/openpower_p9_mambo_defconfig
+++ b/openpower/configs/openpower_p9_mambo_defconfig
@@ -44,8 +44,8 @@
 BR2_PACKAGE_PETITBOOT=y
 # BR2_PACKAGE_HOST_P8_PORE_BINUTILS is not set
 # BR2_PACKAGE_OCC is not set
+# BR2_PACKAGE_HCODE is not set
 # BR2_PACKAGE_CAPP_UCODE is not set
 # BR2_PACKAGE_HOST_PPE42_BINUTILS is not set
 # BR2_PACKAGE_HOST_PPE42_GCC is not set
 # BR2_PACKAGE_IMA_CATALOG is not set
-# BR2_PACKAGE_SBE is not set
diff --git a/openpower/configs/romulus_defconfig b/openpower/configs/romulus_defconfig
index 301e824..5f78349 100644
--- a/openpower/configs/romulus_defconfig
+++ b/openpower/configs/romulus_defconfig
@@ -58,6 +58,7 @@
 BR2_PACKAGE_PETITBOOT=y
 BR2_PACKAGE_PETITBOOT_MTD=y
 BR2_OCC_BIN_FILENAME="occ.bin"
+# BR2_HCODE_INCLUDE_IONV is not set
 BR2_CAPP_UCODE_BIN_FILENAME="cappucode.bin"
 BR2_PACKAGE_LOADKEYS=y
 BR2_IMA_CATALOG_DTS="POWER9"
diff --git a/openpower/configs/zz_defconfig b/openpower/configs/zz_defconfig
index 3691e65..1ccb704 100644
--- a/openpower/configs/zz_defconfig
+++ b/openpower/configs/zz_defconfig
@@ -50,10 +50,10 @@
 BR2_PACKAGE_PETITBOOT_MTD=y
 # BR2_PACKAGE_HOST_P8_PORE_BINUTILS is not set
 # BR2_PACKAGE_OCC is not set
+# BR2_PACKAGE_HCODE is not set
 # BR2_PACKAGE_CAPP_UCODE is not set
 BR2_PACKAGE_LOADKEYS=y
 # BR2_PACKAGE_HOST_PPE42_BINUTILS is not set
 # BR2_PACKAGE_HOST_PPE42_GCC is not set
 # BR2_PACKAGE_IMA_CATALOG is not set
-# BR2_PACKAGE_SBE is not set
 # BR2_PACKAGE_HOST_SB_SIGNING_UTILS is not set
diff --git a/openpower/package/Config.in b/openpower/package/Config.in
index aed88b6..eb685db 100755
--- a/openpower/package/Config.in
+++ b/openpower/package/Config.in
@@ -8,6 +8,7 @@
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/petitboot/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/p8-pore-binutils/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/occ/Config.in"
+source "$BR2_EXTERNAL_OP_BUILD_PATH/package/hcode/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/capp-ucode/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/skiboot/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/libflash/Config.in"
diff --git a/openpower/package/hcode/Config.in b/openpower/package/hcode/Config.in
new file mode 100644
index 0000000..c64e36d
--- /dev/null
+++ b/openpower/package/hcode/Config.in
@@ -0,0 +1,13 @@
+config BR2_PACKAGE_HCODE
+        bool "hcode"
+        default y if (BR2_OPENPOWER_PLATFORM && BR2_OPENPOWER_POWER9)
+        select BR2_CPP
+        help
+            Project to build the hcode firmware codebase
+
+config BR2_HCODE_INCLUDE_IONV
+        bool "Enables packaging of the NVIDIA GPU image into the final hw image"
+        default y
+        help
+            Boolean used to flag whether to include NVIDIA GPU binary
+
diff --git a/openpower/package/hcode/hcode.mk b/openpower/package/hcode/hcode.mk
new file mode 100644
index 0000000..45953e2
--- /dev/null
+++ b/openpower/package/hcode/hcode.mk
@@ -0,0 +1,42 @@
+################################################################################
+#
+# HCODE
+#
+################################################################################
+
+HCODE_VERSION ?= 270068cbfcb001fa5ccfbb6e8bc18eea22d68487
+HCODE_SITE = $(call github,open-power,hcode,$(HCODE_VERSION))
+
+HCODE_LICENSE = Apache-2.0
+
+HCODE_INSTALL_IMAGES = YES
+HCODE_INSTALL_TARGET = NO
+
+HCODE_DEPENDENCIES = host-binutils host-ppe42-gcc hostboot-binaries
+
+HW_IMAGE_BIN_PATH=output/images/hw_image
+HW_IMAGE_BIN=p9n.hw_image.bin
+HCODE_IMAGE_BIN = p9n.ref_image.bin
+
+CROSS_COMPILER_PATH=$(PPE42_GCC_BIN)
+PPE_TOOL_PATH ?= $(CROSS_COMPILER_PATH)
+PPE_PREFIX    ?= $(PPE_TOOL_PATH)/bin/powerpc-eabi-
+
+HCODE_ENV_VARS= CONFIG_FILE=$(BR2_EXTERNAL_OP_BUILD_PATH)/configs/hcode/$(BR2_HCODE_CONFIG_FILE) \
+	LD_LIBRARY_PATH=$(HOST_DIR)/usr/lib OPENPOWER_BUILD=1\
+	CROSS_COMPILER_PATH=$(PPE42_GCC_BIN) PPE_TOOL_PATH=$(CROSS_COMPILER_PATH) \
+	PPE_PREFIX=$(CROSS_COMPILER_PATH)/bin/powerpc-eabi- \
+	RINGFILEPATH=$(STAGING_DIR)/hostboot_binaries __EKB_PREFIX=$(CXXPATH) \
+	CONFIG_IONV_FILE_LOCATION=$(STAGING_DIR)/hostboot_binaries/$(BR2_HOSTBOOT_BINARY_IONV_FILENAME) \
+	CONFIG_INCLUDE_IONV=$(BR2_HCODE_INCLUDE_IONV)
+
+define HCODE_INSTALL_IMAGES_CMDS
+	mkdir -p $(STAGING_DIR)/hcode
+	$(INSTALL) $(@D)/$(HW_IMAGE_BIN_PATH)/$(HW_IMAGE_BIN) $(STAGING_DIR)/hcode/$(HCODE_IMAGE_BIN)
+endef
+
+define HCODE_BUILD_CMDS
+		$(HCODE_ENV_VARS) bash -c 'cd $(@D) && source ./env.bash && $(MAKE) '
+endef
+
+$(eval $(generic-package))
diff --git a/openpower/package/hostboot-binaries/hostboot_binaries.mk b/openpower/package/hostboot-binaries/hostboot_binaries.mk
index 5a97bd7..4e4b04e 100644
--- a/openpower/package/hostboot-binaries/hostboot_binaries.mk
+++ b/openpower/package/hostboot-binaries/hostboot_binaries.mk
@@ -14,6 +14,9 @@
 HOSTBOOT_BINARIES_INSTALL_IMAGES = YES
 HOSTBOOT_BINARIES_INSTALL_TARGET = NO
 
+NIMBUS_RING_FILE=p9n.hw.rings.bin
+NIMBUS_RING_OVERLAYS_FILE=p9n.hw.overlays.bin
+
 #for P9 the hw_ref image is changing to not be padded with ECC.  However
 #all the other op-build files use the end name result.  Thus replace ".hdr.bin.ecc"
 #with ".bin"
@@ -25,6 +28,9 @@
      $(INSTALL) -D $(@D)/$(BR2_HOSTBOOT_BINARY_SBEC_FILENAME) $(STAGING_DIR)/hostboot_binaries/
      $(INSTALL) -D $(@D)/$(BR2_HOSTBOOT_BINARY_SBE_FILENAME)  $(STAGING_DIR)/hostboot_binaries/
      $(INSTALL) -D $(@D)/gpu_gpe1.bin  $(STAGING_DIR)/hostboot_binaries/gpu_gpe1.bin
+     $(INSTALL) -D $(@D)/$(NIMBUS_RING_FILE)  $(STAGING_DIR)/hostboot_binaries/
+     $(INSTALL) -D $(@D)/$(NIMBUS_RING_OVERLAYS_FILE)  $(STAGING_DIR)/hostboot_binaries/
+     $(INSTALL) -D $(@D)/$(BR2_HOSTBOOT_BINARY_IONV_FILENAME)  $(STAGING_DIR)/hostboot_binaries/
 endef
 
 $(eval $(generic-package))
diff --git a/openpower/package/openpower-pnor/Config.in b/openpower/package/openpower-pnor/Config.in
index 37c4470..1c43735 100644
--- a/openpower/package/openpower-pnor/Config.in
+++ b/openpower/package/openpower-pnor/Config.in
@@ -9,7 +9,8 @@
         select BR2_PACKAGE_CAPP_UCODE
         select BR2_PACKAGE_IMA_CATALOG
         select BR2_PACKAGE_HOST_OPENPOWER_VPNOR
-	select BR2_PACKAGE_MACHINE_XML
+        select BR2_PACKAGE_MACHINE_XML
+        select BR2_PACKAGE_HCODE if BR2_OPENPOWER_POWER9
         help
             Utilites for building a targeting binary image
 
@@ -94,6 +95,12 @@
         help
             String used to define name of sbec hostboot binary file
 
+config BR2_HOSTBOOT_BINARY_IONV_FILENAME
+        string "Name of IONV binary"
+        default "ionv.bin"
+        help
+            String used to define name of ionv binary file
+
 config BR2_HOSTBOOT_BINARY_WINK_FILENAME
         string "Name of winkle hostboot binary"
         help
diff --git a/openpower/package/openpower-pnor/openpower-pnor.mk b/openpower/package/openpower-pnor/openpower-pnor.mk
index fb32397..3bf4d8a 100644
--- a/openpower/package/openpower-pnor/openpower-pnor.mk
+++ b/openpower/package/openpower-pnor/openpower-pnor.mk
@@ -11,6 +11,10 @@
 OPENPOWER_PNOR_LICENSE_FILES = LICENSE
 OPENPOWER_PNOR_DEPENDENCIES = hostboot hostboot-binaries machine-xml skiboot host-openpower-ffs occ capp-ucode
 
+ifeq ($(BR2_OPENPOWER_POWER9),y)
+OPENPOWER_PNOR_DEPENDENCIES += hcode
+endif
+
 ifeq ($(BR2_PACKAGE_IMA_CATALOG),y)
 OPENPOWER_PNOR_DEPENDENCIES += ima-catalog
 endif
@@ -56,7 +60,10 @@
 OPENPOWER_PNOR_INSTALL_TARGET = NO
 
 HOSTBOOT_IMAGE_DIR=$(STAGING_DIR)/hostboot_build_images/
-HOSTBOOT_BINARY_DIR = $(STAGING_DIR)/hostboot_binaries/
+HOSTBOOT_BINARY_DIR = $(STAGING_DIR)/hostboot_binaries
+
+HCODE_STAGING_DIR = $(STAGING_DIR)/hcode
+
 SBE_BINARY_DIR = $(STAGING_DIR)/sbe_binaries/
 OPENPOWER_PNOR_SCRATCH_DIR = $(STAGING_DIR)/openpower_pnor_scratch/
 OPENPOWER_VERSION_DIR = $(STAGING_DIR)/openpower_version
@@ -92,6 +99,7 @@
             -hb_image_dir $(HOSTBOOT_IMAGE_DIR) \
             -scratch_dir $(OPENPOWER_PNOR_SCRATCH_DIR) \
             -hb_binary_dir $(HOSTBOOT_BINARY_DIR) \
+            -hcode_dir $(HCODE_STAGING_DIR) \
             -targeting_binary_filename $(BR2_OPENPOWER_TARGETING_ECC_FILENAME) \
             -targeting_binary_source $(BR2_OPENPOWER_TARGETING_BIN_FILENAME) \
             -sbe_binary_filename $(BR2_HOSTBOOT_BINARY_SBE_FILENAME) \
diff --git a/openpower/package/sbe/Config.in b/openpower/package/sbe/Config.in
index cd9e84f..c512bbb 100644
--- a/openpower/package/sbe/Config.in
+++ b/openpower/package/sbe/Config.in
@@ -2,5 +2,6 @@
         bool "sbe"
         default y if (BR2_OPENPOWER_PLATFORM && BR2_OPENPOWER_POWER9)
         select BR2_CPP
+        depends on BR2_PACKAGE_HCODE
         help
             Project to build the sbe firmware codebase
diff --git a/openpower/package/sbe/sbe.mk b/openpower/package/sbe/sbe.mk
index 937a12c..04841ee 100644
--- a/openpower/package/sbe/sbe.mk
+++ b/openpower/package/sbe/sbe.mk
@@ -8,7 +8,7 @@
 SBE_SITE ?= $(call github,open-power,sbe,$(SBE_VERSION))
 
 SBE_LICENSE = Apache-2.0
-SBE_DEPENDENCIES = host-ppe42-gcc
+SBE_DEPENDENCIES = host-ppe42-gcc hcode
 
 SBE_INSTALL_IMAGES = YES
 SBE_INSTALL_TARGET = NO