Enable p8-pore-binutils as an external toolchain

Create the infrastructure necessary to bundle the p8-pore-binutils as
part of the sdk build, allowing it to be re-inserted as part of an
external sdk.

Signed-off-by: Klaus Heinrich Kiwi <klaus@linux.vnet.ibm.com>
diff --git a/openpower/configs/firenze_defconfig b/openpower/configs/firenze_defconfig
index 18d5d4e..7223ce2 100644
--- a/openpower/configs/firenze_defconfig
+++ b/openpower/configs/firenze_defconfig
@@ -45,6 +45,7 @@
 BR2_TARGET_ROOTFS_CPIO_XZ=y
 BR2_OPENPOWER_PLATFORM=y
 BR2_OPENPOWER_POWER8=y
+# BR2_PACKAGE_P8_PORE_TOOLCHAIN is not set
 # BR2_PACKAGE_HOSTBOOT_P8 is not set
 # BR2_PACKAGE_HOSTBOOT_BINARIES is not set
 # BR2_PACKAGE_MACHINE_XML is not set
@@ -52,7 +53,6 @@
 BR2_OPENPOWER_CONFIG_NAME="openpower-firenze"
 BR2_PACKAGE_PETITBOOT=y
 BR2_PACKAGE_PETITBOOT_MTD=y
-# BR2_PACKAGE_HOST_P8_PORE_BINUTILS is not set
 # BR2_PACKAGE_CAPP_UCODE is not set
 BR2_PACKAGE_LOADKEYS=y
 # BR2_PACKAGE_IMA_CATALOG is not set
diff --git a/openpower/configs/opal_defconfig b/openpower/configs/opal_defconfig
index 791214d..804e47c 100644
--- a/openpower/configs/opal_defconfig
+++ b/openpower/configs/opal_defconfig
@@ -43,6 +43,7 @@
 BR2_TARGET_ROOTFS_INITRAMFS=y
 BR2_OPENPOWER_PLATFORM=y
 BR2_OPENPOWER_POWER8=y
+# BR2_PACKAGE_P8_PORE_TOOLCHAIN is not set
 # BR2_PACKAGE_HOST_OPENPOWER_FFS is not set
 # BR2_PACKAGE_HOSTBOOT_P8 is not set
 # BR2_PACKAGE_HOSTBOOT_BINARIES is not set
@@ -51,7 +52,6 @@
 BR2_OPENPOWER_CONFIG_NAME="opal"
 BR2_PACKAGE_PETITBOOT=y
 BR2_PACKAGE_PETITBOOT_MTD=y
-# BR2_PACKAGE_HOST_P8_PORE_BINUTILS is not set
 # BR2_PACKAGE_CAPP_UCODE is not set
 BR2_SKIBOOT_DEVICETREE=y
 # BR2_PACKAGE_IMA_CATALOG is not set
diff --git a/openpower/configs/pseries_defconfig b/openpower/configs/pseries_defconfig
index 8f8c167..5a3b39f 100644
--- a/openpower/configs/pseries_defconfig
+++ b/openpower/configs/pseries_defconfig
@@ -47,6 +47,7 @@
 BR2_TARGET_ROOTFS_CPIO_XZ=y
 BR2_OPENPOWER_PLATFORM=y
 BR2_OPENPOWER_POWER8=y
+# BR2_PACKAGE_P8_PORE_TOOLCHAIN is not set
 # BR2_PACKAGE_HOSTBOOT_P8 is not set
 # BR2_PACKAGE_HOSTBOOT_BINARIES is not set
 # BR2_PACKAGE_MACHINE_XML is not set
@@ -54,7 +55,6 @@
 BR2_OPENPOWER_CONFIG_NAME="openpower-firenze"
 BR2_PACKAGE_PETITBOOT=y
 BR2_PACKAGE_PETITBOOT_MTD=y
-# BR2_PACKAGE_HOST_P8_PORE_BINUTILS is not set
 # BR2_PACKAGE_CAPP_UCODE is not set
 BR2_PACKAGE_LOADKEYS=y
 # BR2_PACKAGE_IMA_CATALOG is not set
diff --git a/openpower/package/Config.in b/openpower/package/Config.in
index 903e6cb..52662e6 100755
--- a/openpower/package/Config.in
+++ b/openpower/package/Config.in
@@ -7,7 +7,6 @@
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/machine-xml/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/openpower-pnor/Config.in"
 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/hcode/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/occ/Config.in"
 source "$BR2_EXTERNAL_OP_BUILD_PATH/package/occ-p8/Config.in"
diff --git a/openpower/package/p8-pore-binutils/Config.in b/openpower/package/p8-pore-binutils/Config.in
index 3d69782..db06064 100644
--- a/openpower/package/p8-pore-binutils/Config.in
+++ b/openpower/package/p8-pore-binutils/Config.in
@@ -1,6 +1,5 @@
 config BR2_PACKAGE_HOST_P8_PORE_BINUTILS
         bool "p8-pore-binutils"
-        default y if (BR2_OPENPOWER_POWER8)
         select BR2_PACKAGE_HAS_P8_PORE_TOOLCHAIN
         select BR2_CPP
         help
diff --git a/openpower/package/p8-pore-binutils/p8-pore-binutils.mk b/openpower/package/p8-pore-binutils/p8-pore-binutils.mk
index 7cd9807..00477a6 100644
--- a/openpower/package/p8-pore-binutils/p8-pore-binutils.mk
+++ b/openpower/package/p8-pore-binutils/p8-pore-binutils.mk
@@ -11,8 +11,8 @@
 P8_PORE_BINUTILS_PROVIDES = p8-pore-toolchain
 HOST_P8_PORE_BINUTILS_DEPENDENCIES = host-binutils
 
-P8_PORE_BINUTILS_DIR = $(STAGING_DIR)/p8-pore-binutils
-P8_PORE_BINUTILS_BIN = $(STAGING_DIR)/p8-pore-binutils/linux
+P8_PORE_BINUTILS_DIR = $(HOST_DIR)/$(P8_PORE_TOOLCHAIN_DIR)
+P8_PORE_BINUTILS_BIN = $(HOST_DIR)/$(P8_PORE_TOOLCHAIN_BIN)
 
 define HOST_P8_PORE_BINUTILS_BUILD_CMDS
         cd $(@D) && \
diff --git a/openpower/package/p8-pore-toolchain-external/Config.in b/openpower/package/p8-pore-toolchain-external/Config.in
new file mode 100644
index 0000000..cad96c0
--- /dev/null
+++ b/openpower/package/p8-pore-toolchain-external/Config.in
@@ -0,0 +1,19 @@
+config BR2_PACKAGE_P8_PORE_TOOLCHAIN_EXTERNAL
+	bool "p8-pore-toolchain-external"
+	select BR2_PACKAGE_HAS_P8_PORE_TOOLCHAIN
+	help
+	  Use an external P8 PORE toolchain
+
+if BR2_PACKAGE_P8_PORE_TOOLCHAIN_EXTERNAL
+config BR2_PACKAGE_PROVIDES_P8_PORE_TOOLCHAIN
+	default "p8-pore-toolchain-external"
+
+config BR2_P8_PORE_TOOLCHAIN_EXTERNAL_PATH
+	string "External P8 PORE toolchain path"
+	help
+	  Pathname to where the external P8 PORE toolchain
+	  is installed. The binutils are expected to be
+	  fully contained within the
+	  "sysroot/p8-pore-toolchain" directory
+endif
+
diff --git a/openpower/package/p8-pore-toolchain-external/p8-pore-toolchain-external.mk b/openpower/package/p8-pore-toolchain-external/p8-pore-toolchain-external.mk
new file mode 100644
index 0000000..c88864a
--- /dev/null
+++ b/openpower/package/p8-pore-toolchain-external/p8-pore-toolchain-external.mk
@@ -0,0 +1,22 @@
+################################################################################
+#
+# p8-pore-toolchain-external
+#
+################################################################################
+P8_PORE_TOOLCHAIN_EXTERNAL_REDISTRIBUTE = NO
+P8_PORE_TOOLCHAIN_EXTERNAL_SITE =
+P8_PORE_TOOLCHAIN_EXTERNAL_SOURCE =
+P8_PORE_TOOLCHAIN_EXTERNAL_PROVIDES = p8-pore-toolchain
+P8_PORE_TOOLCHAIN_EXTERNAL_PATH = \
+	$(call qstrip,$(BR2_P8_PORE_TOOLCHAIN_EXTERNAL_PATH))/$(P8_PORE_TOOLCHAIN_DIR)
+
+define HOST_P8_PORE_TOOLCHAIN_EXTERNAL_CONFIGURE_CMDS
+	test -e $(P8_PORE_TOOLCHAIN_EXTERNAL_PATH)
+endef
+
+define HOST_P8_PORE_TOOLCHAIN_EXTERNAL_INSTALL_CMDS
+	ln -snf $(P8_PORE_TOOLCHAIN_EXTERNAL_PATH) $(HOST_DIR)/$(P8_PORE_TOOLCHAIN_DIR)
+
+endef
+
+$(eval $(host-generic-package))
diff --git a/openpower/toolchain/p8-pore-toolchain/Config.in b/openpower/toolchain/p8-pore-toolchain/Config.in
index 40dd48d..c03422b 100644
--- a/openpower/toolchain/p8-pore-toolchain/Config.in
+++ b/openpower/toolchain/p8-pore-toolchain/Config.in
@@ -1,6 +1,27 @@
+menuconfig BR2_PACKAGE_P8_PORE_TOOLCHAIN
+	bool "p8-pore-toolchain"
+	default y if (BR2_OPENPOWER_POWER8)
+	help
+	  Build the PORE toolchain required to build the
+	  POWER8 OCC firmware
+
+if BR2_PACKAGE_P8_PORE_TOOLCHAIN
+choice
+	prompt "P8 PORE Toolchain Type"
+	help
+	  Select whether to build the P8 PORE toolchain or
+	  provide an external one
+
+source "$BR2_EXTERNAL_OP_BUILD_PATH/package/p8-pore-binutils/Config.in"
+source "$BR2_EXTERNAL_OP_BUILD_PATH/package/p8-pore-toolchain-external/Config.in"
+
+endchoice
+
 config BR2_PACKAGE_HAS_P8_PORE_TOOLCHAIN
 	bool
 
 config BR2_PACKAGE_PROVIDES_P8_PORE_TOOLCHAIN
 	depends on BR2_PACKAGE_HAS_P8_PORE_TOOLCHAIN
 	string
+
+endif
diff --git a/openpower/toolchain/p8-pore-toolchain/p8-pore-toolchain.mk b/openpower/toolchain/p8-pore-toolchain/p8-pore-toolchain.mk
index b618004..7936be5 100644
--- a/openpower/toolchain/p8-pore-toolchain/p8-pore-toolchain.mk
+++ b/openpower/toolchain/p8-pore-toolchain/p8-pore-toolchain.mk
@@ -3,5 +3,7 @@
 # p8-pore-toolchain
 #
 ################################################################################
+P8_PORE_TOOLCHAIN_DIR = $(STAGING_SUBDIR)/p8-pore-toolchain
+P8_PORE_TOOLCHAIN_BIN = $(STAGING_SUBDIR)/p8-pore-toolchain/linux
 
 $(eval $(host-virtual-package))