Add MRW tools and xml
diff --git a/openpower/configs/habanero_defconfig b/openpower/configs/habanero_defconfig
index cad44ef..b16df59 100644
--- a/openpower/configs/habanero_defconfig
+++ b/openpower/configs/habanero_defconfig
@@ -3,6 +3,7 @@
 BR2_OPENPOWER_PLATFORM=y
 
 BR2_OPENPOWER_CONFIG_NAME="habanero"
+BR2_OPENPOWER_XML_PACKAGE="habanero-xml"
 BR2_HOSTBOOT_CONFIG_FILE="habanero.config"
 
 BR2_HOSTBOOT_BINARY_SBE_FILENAME="venice_sbe.img.ecc"
@@ -10,8 +11,9 @@
 
 BR2_OCC_BIN_FILENAME="occ.bin"
 
-BR2_OPENPOWER_TARGETING_SYSTEM_XML_FILENAME="HABANERO_hb.system.xml"
-BR2_OPENPOWER_TARGETING_MRW_XML_FILENAME="HABANERO_hb.mrw.xml"
+BR2_HABANERO_SYSTEM_XML_FILENAME="HABANERO_hb.system.xml"
+BR2_HABANERO_MRW_XML_FILENAME="HABANERO_hb.mrw.xml"
+
 BR2_OPENPOWER_TARGETING_BIN_FILENAME="HABANERO_HB.targeting.bin"
 BR2_OPENPOWER_TARGETING_ECC_FILENAME="HABANERO_HB.targeting.bin.ecc"
 
diff --git a/openpower/configs/palmetto_defconfig b/openpower/configs/palmetto_defconfig
index 86da41c..6de6c4c 100644
--- a/openpower/configs/palmetto_defconfig
+++ b/openpower/configs/palmetto_defconfig
@@ -3,6 +3,7 @@
 BR2_OPENPOWER_PLATFORM=y
 
 BR2_OPENPOWER_CONFIG_NAME="palmetto"
+BR2_OPENPOWER_XML_PACKAGE="palmetto-xml"
 BR2_HOSTBOOT_CONFIG_FILE="palmetto.config"
 
 BR2_HOSTBOOT_BINARY_SBE_FILENAME="venice_sbe.img.ecc"
@@ -10,8 +11,8 @@
 
 BR2_OCC_BIN_FILENAME="occ.bin"
 
-BR2_OPENPOWER_TARGETING_SYSTEM_XML_FILENAME="PALMETTO_hb.system.xml"
-BR2_OPENPOWER_TARGETING_MRW_XML_FILENAME="PALMETTO_hb.mrw.xml"
+BR2_PALMETTO_SYSTEM_XML_FILENAME="PALMETTO_hb.system.xml"
+BR2_PALMETTO_MRW_XML_FILENAME="PALMETTO_hb.mrw.xml"
 BR2_OPENPOWER_TARGETING_BIN_FILENAME="PALMETTO_HB.targeting.bin"
 BR2_OPENPOWER_TARGETING_ECC_FILENAME="PALMETTO_HB.targeting.bin.ecc"
 
diff --git a/openpower/package/Config.in b/openpower/package/Config.in
index ca858d6..3271f80 100644
--- a/openpower/package/Config.in
+++ b/openpower/package/Config.in
@@ -1,7 +1,8 @@
 source "$BR2_EXTERNAL/package/openpower-ffs/Config.in"
 source "$BR2_EXTERNAL/package/hostboot/Config.in"
 source "$BR2_EXTERNAL/package/hostboot-binaries/Config.in"
-source "$BR2_EXTERNAL/package/openpower-targeting/Config.in"
+source "$BR2_EXTERNAL/package/palmetto-xml/Config.in"
+source "$BR2_EXTERNAL/package/habanero-xml/Config.in"
 source "$BR2_EXTERNAL/package/openpower-pnor/Config.in"
 source "$BR2_EXTERNAL/package/p8-pore-binutils/Config.in"
 source "$BR2_EXTERNAL/package/occ/Config.in"
diff --git a/openpower/package/common-p8-xml/Config.in b/openpower/package/common-p8-xml/Config.in
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/openpower/package/common-p8-xml/Config.in
diff --git a/openpower/package/common-p8-xml/common-p8-xml.mk b/openpower/package/common-p8-xml/common-p8-xml.mk
new file mode 100644
index 0000000..f7a3aa2
--- /dev/null
+++ b/openpower/package/common-p8-xml/common-p8-xml.mk
@@ -0,0 +1,22 @@
+################################################################################
+#
+# common-p8-xml
+#
+################################################################################
+
+COMMON_P8_XML_VERSION ?= 1afe70931836abbe896220e3824cbbeb730ee5d7
+COMMON_P8_XML_SITE ?= $(call github,open-power,common-p8-xml,$(COMMON_P8_XML_VERSION))
+
+COMMON_P8_XML_LICENSE = Apache-2.0
+COMMON_P8_XML_DEPENDENCIES =
+
+COMMON_P8_XML_INSTALL_IMAGES = YES
+COMMON_P8_XML_INSTALL_TARGET = NO
+
+XML_INSTALL_DIRECTORY=$(STAGING_DIR)/openpower_mrw_scratch/
+
+define COMMON_P8_XML_INSTALL_IMAGES_CMDS
+        bash -c 'mkdir -p $(XML_INSTALL_DIRECTORY) && cp -r $(@D)/* $(XML_INSTALL_DIRECTORY)'
+endef
+
+$(eval $(generic-package))
diff --git a/openpower/package/habanero-xml/Config.in b/openpower/package/habanero-xml/Config.in
new file mode 100755
index 0000000..c6d945e
--- /dev/null
+++ b/openpower/package/habanero-xml/Config.in
@@ -0,0 +1,17 @@
+config BR2_PACKAGE_HABANERO_XML
+        bool "habanero_xml"
+        default y if (BR2_OPENPOWER_CONFIG_NAME = "habanero")
+        help
+            Utilites for building xml and the targeting binary image
+
+config BR2_HABANERO_SYSTEM_XML_FILENAME
+        string "Habanero targeting system xml filename"
+        default ""
+        help
+            Defines the name of the system XML filename to be used when creating targeting binary image
+
+config BR2_HABANERO_MRW_XML_FILENAME
+        string "Habanero targeting mrw xml filename"
+        default ""
+        help
+            Defines the name of the mrw XML filename to be used when creating targeting binary image
diff --git a/openpower/package/habanero-xml/habanero-xml.mk b/openpower/package/habanero-xml/habanero-xml.mk
new file mode 100644
index 0000000..7e0980e
--- /dev/null
+++ b/openpower/package/habanero-xml/habanero-xml.mk
@@ -0,0 +1,62 @@
+################################################################################
+#
+# habanero_xml
+#
+################################################################################
+
+HABANERO_XML_VERSION ?= 7156de2d91ec5195148b7dc941aa4b786e9281d8
+HABANERO_XML_SITE ?= $(call github,open-power,habanero-xml,$(HABANERO_XML_VERSION))
+
+HABANERO_XML_LICENSE = Apache-2.0
+HABANERO_XML_DEPENDENCIES = hostboot-install-images openpower-mrw-install-images common-p8-xml-install-images
+
+HABANERO_XML_INSTALL_IMAGES = YES
+HABANERO_XML_INSTALL_TARGET = NO
+
+MRW_SCRATCH=$(STAGING_DIR)/openpower_mrw_scratch
+MRW_INSTALL_DIRECTORY=$(STAGING_DIR)/preprocessed_mrw
+MRW_HB_TOOLS=$(STAGING_DIR)/hostboot_build_images
+
+HABANERO_XML_ENV_VARS= \
+    SCHEMA_FILE=$(MRW_SCRATCH)/schema/mrw.xsd \
+    PARSER_PATH=$(STAGING_DIR)/usr/bin \
+    XSL_PATH=$(MRW_SCRATCH)/xslt \
+    OUTPUT_PATH=$(MRW_INSTALL_DIRECTORY)
+
+define HABANERO_XML_BUILD_CMDS
+        # copy the habanero xml where the common lives
+        bash -c 'mkdir -p $(MRW_SCRATCH) && cp -r $(@D)/* $(MRW_SCRATCH)'
+        mkdir -p $(MRW_INSTALL_DIRECTORY)
+
+        # run the mrw parsers
+        $(HABANERO_XML_ENV_VARS) bash -c 'cd $(MRW_SCRATCH) && $(MAKE) habanero'
+
+        # generate the system mrm xml
+        $(MRW_HB_TOOLS)/genHwsvMrwXml.pl \
+            --system=$(BR2_OPENPOWER_CONFIG_NAME) \
+            --mrwdir=$(MRW_INSTALL_DIRECTORY) \
+            --build=hb > $(MRW_INSTALL_DIRECTORY)/$(BR2_HABANERO_MRW_XML_FILENAME)
+endef
+
+define HABANERO_XML_INSTALL_IMAGES_CMDS
+
+        # merge in any system specific attributes, hostboot attributes
+        $(MRW_HB_TOOLS)/mergexml.sh $(@D)/$(BR2_HABANERO_SYSTEM_XML_FILENAME) \
+            $(MRW_HB_TOOLS)/attribute_types.xml \
+            $(MRW_HB_TOOLS)/attribute_types_hb.xml \
+            $(MRW_HB_TOOLS)/target_types_merged.xml \
+            $(MRW_HB_TOOLS)/target_types_hb.xml \
+            $(MRW_INSTALL_DIRECTORY)/$(BR2_HABANERO_MRW_XML_FILENAME) > $(MRW_HB_TOOLS)/temporary_hb.hb.xml;
+
+        # creating the targeting binary
+        $(MRW_HB_TOOLS)/xmltohb.pl  \
+            --hb-xml-file=$(MRW_HB_TOOLS)/temporary_hb.hb.xml \
+            --fapi-attributes-xml-file=$(MRW_HB_TOOLS)/fapiattrs.xml \
+            --src-output-dir=none \
+            --img-output-dir=$(MRW_HB_TOOLS)/ \
+            --vmm-consts-file=$(MRW_HB_TOOLS)/vmmconst.h --noshort-enums
+
+        mv $(MRW_HB_TOOLS)/targeting.bin $(MRW_HB_TOOLS)/$(BR2_OPENPOWER_TARGETING_BIN_FILENAME)
+endef
+
+$(eval $(generic-package))
diff --git a/openpower/package/hostboot/hostboot.mk b/openpower/package/hostboot/hostboot.mk
index 5bc18cb..3e7c6f1 100644
--- a/openpower/package/hostboot/hostboot.mk
+++ b/openpower/package/hostboot/hostboot.mk
@@ -6,6 +6,7 @@
 
 HOSTBOOT_VERSION ?= 6c5f08212c150d69a931fa4fa1354b6a3aac61e8
 HOSTBOOT_SITE ?= $(call github,open-power,hostboot,$(HOSTBOOT_VERSION))
+
 HOSTBOOT_LICENSE = Apache-2.0
 HOSTBOOT_DEPENDENCIES = host-binutils
 
diff --git a/openpower/package/openpower-mrw/Config.in b/openpower/package/openpower-mrw/Config.in
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/openpower/package/openpower-mrw/Config.in
diff --git a/openpower/package/openpower-mrw/openpower-mrw.mk b/openpower/package/openpower-mrw/openpower-mrw.mk
new file mode 100644
index 0000000..ccd059f
--- /dev/null
+++ b/openpower/package/openpower-mrw/openpower-mrw.mk
@@ -0,0 +1,26 @@
+################################################################################
+#
+# openpower-mrw
+#
+################################################################################
+
+OPENPOWER_MRW_VERSION = 0729a4a68c0e731a8d3720f1a5aee190d165400b
+OPENPOWER_MRW_SITE = $(call github,open-power,openpower-mrw,$(OPENPOWER_MRW_VERSION))
+
+OPENPOWER_MRW_LICENSE = Apache-2.0
+OPENPOWER_MRW_DEPENDENCIES =
+
+OPENPOWER_MRW_INSTALL_IMAGES = YES
+OPENPOWER_MRW_INSTALL_TARGET = NO
+
+OPENPOWER_MRW_ENV_VARS=INSTALL_DIRECTORY=$(STAGING_DIR)/usr/bin/
+
+define OPENPOWER_MRW_BUILD_CMDS
+        $(OPENPOWER_MRW_ENV_VARS) bash -c 'cd $(@D) && $(MAKE)'
+endef
+
+define OPENPOWER_MRW_INSTALL_IMAGES_CMDS
+        $(OPENPOWER_MRW_ENV_VARS) bash -c 'cd $(@D) && $(MAKE) install'
+endef
+
+$(eval $(generic-package))
diff --git a/openpower/package/openpower-pnor/Config.in b/openpower/package/openpower-pnor/Config.in
index 5078824..8815490 100644
--- a/openpower/package/openpower-pnor/Config.in
+++ b/openpower/package/openpower-pnor/Config.in
@@ -14,6 +14,11 @@
         help
             String used to define configuration name
 
+config BR2_OPENPOWER_XML_PACKAGE
+        string "Name of xml/targeting package"
+        help
+            String defines the xml/targeting package used
+
 config BR2_OPENPOWER_PNOR_FILENAME
         string "Name of pnor file to be created"
         help
@@ -40,3 +45,8 @@
         string "Name of openpower binary targeting file"
         help
             String used to define name of openpower targeting binary file
+
+config BR2_OPENPOWER_TARGETING_ECC_FILENAME
+        string "Name of openpower binary targeting file"
+        help
+            String used to define name of openpower targeting binary file, ecc protected
diff --git a/openpower/package/openpower-pnor/openpower-pnor.mk b/openpower/package/openpower-pnor/openpower-pnor.mk
index db427fc..c49c36c 100644
--- a/openpower/package/openpower-pnor/openpower-pnor.mk
+++ b/openpower/package/openpower-pnor/openpower-pnor.mk
@@ -4,25 +4,28 @@
 #
 ################################################################################
 
+# remove the quotes from the XML/Targeting package as
+# make doesn't care for quotes in the dependencies.
+XML_PACKAGE=$(subst $\",,$(BR2_OPENPOWER_XML_PACKAGE))
 
 OPENPOWER_PNOR_VERSION ?= e0e46ec7327edd6b24947706f074cd04d239cc86
 OPENPOWER_PNOR_SITE ?= $(call github,open-power,pnor,$(OPENPOWER_PNOR_VERSION))
 
 OPENPOWER_PNOR_LICENSE = Apache-2.0
-OPENPOWER_PNOR_DEPENDENCIES = hostboot hostboot-binaries openpower-targeting skiboot host-openpower-ffs occ
+OPENPOWER_PNOR_DEPENDENCIES = hostboot hostboot-binaries $(XML_PACKAGE) skiboot host-openpower-ffs occ
 
 OPENPOWER_PNOR_INSTALL_IMAGES = YES
 OPENPOWER_PNOR_INSTALL_TARGET = NO
 
-OPENPOWER_TARGETING_DIR=$(STAGING_DIR)/openpower_targeting/
 HOSTBOOT_IMAGE_DIR=$(STAGING_DIR)/hostboot_build_images/
 HOSTBOOT_BINARY_DIR = $(STAGING_DIR)/hostboot_binaries/
 OPENPOWER_PNOR_SCRATCH_DIR = $(STAGING_DIR)/openpower_pnor_scratch/
 
 define OPENPOWER_PNOR_INSTALL_IMAGES_CMDS
         mkdir -p $(OPENPOWER_PNOR_SCRATCH_DIR)
+
         $(TARGET_MAKE_ENV) $(@D)/update_image.pl \
-            -op_target_dir $(STAGING_DIR)/openpower_targeting/ \
+            -op_target_dir $(HOSTBOOT_IMAGE_DIR) \
             -hb_image_dir $(HOSTBOOT_IMAGE_DIR) \
             -scratch_dir $(OPENPOWER_PNOR_SCRATCH_DIR) \
             -hb_binary_dir $(HOSTBOOT_BINARY_DIR) \
diff --git a/openpower/package/openpower-targeting/Config.in b/openpower/package/openpower-targeting/Config.in
deleted file mode 100755
index af70355..0000000
--- a/openpower/package/openpower-targeting/Config.in
+++ /dev/null
@@ -1,29 +0,0 @@
-config BR2_PACKAGE_OPENPOWER_TARGETING
-        bool "openpower_targeting"
-        default y if (BR2_OPENPOWER_PLATFORM && BR2_powerpc_power8)
-        help
-            Utilites for building a targeting binary image
-
-config BR2_OPENPOWER_TARGETING_BIN_FILENAME
-        string "openpower targeting binary file name"
-        default ""
-        help
-            Defines targeting binary file name created
-
-config BR2_OPENPOWER_TARGETING_ECC_FILENAME
-        string "openpower targeting binary file name - ecc injected"
-        default ""
-        help
-            Defines targeting binary ecc file name created
-
-config BR2_OPENPOWER_TARGETING_SYSTEM_XML_FILENAME
-        string "openpower targeting system xml filename"
-        default ""
-        help
-            Defines the name of the system XML filename to be used when creating targeting binary image
-
-config BR2_OPENPOWER_TARGETING_MRW_XML_FILENAME
-        string "openpower targeting mrw xml filename"
-        default ""
-        help
-            Defines the name of the mrw XML filename to be used when creating targeting binary image
diff --git a/openpower/package/openpower-targeting/openpower-targeting.mk b/openpower/package/openpower-targeting/openpower-targeting.mk
deleted file mode 100644
index 42aadc5..0000000
--- a/openpower/package/openpower-targeting/openpower-targeting.mk
+++ /dev/null
@@ -1,38 +0,0 @@
-################################################################################
-#
-# openpower_targeting
-#
-################################################################################
-
-OPENPOWER_TARGETING_VERSION ?= 9ce8c2454580037cf2f5572379536408152d19f0
-OPENPOWER_TARGETING_SITE ?= $(call github,open-power,hostboot-targeting,$(OPENPOWER_TARGETING_VERSION))
-
-OPENPOWER_TARGETING_LICENSE = Apache-2.0
-OPENPOWER_TARGETING_DEPENDENCIES = hostboot-install-images
-
-OPENPOWER_TARGETING_INSTALL_IMAGES = YES
-OPENPOWER_TARGETING_INSTALL_TARGET = NO
-
-define OPENPOWER_TARGETING_INSTALL_IMAGES_CMDS
-        mkdir -p $(STAGING_DIR)/openpower_targeting/;
-
-        $(STAGING_DIR)/hostboot_build_images/mergexml.sh \
-            $(@D)/$(BR2_OPENPOWER_TARGETING_SYSTEM_XML_FILENAME) \
-            $(STAGING_DIR)/hostboot_build_images/attribute_types.xml \
-            $(STAGING_DIR)/hostboot_build_images/attribute_types_hb.xml \
-            $(STAGING_DIR)/hostboot_build_images/target_types_merged.xml \
-            $(STAGING_DIR)/hostboot_build_images/target_types_hb.xml \
-            $(@D)/$(BR2_OPENPOWER_TARGETING_MRW_XML_FILENAME) > $(STAGING_DIR)/openpower_targeting/temporary_hb.hb.xml;
-
-        $(STAGING_DIR)/hostboot_build_images/xmltohb.pl \
-            --hb-xml-file=$(STAGING_DIR)/openpower_targeting/temporary_hb.hb.xml \
-            --fapi-attributes-xml-file=$(STAGING_DIR)/hostboot_build_images/fapiattrs.xml \
-            --src-output-dir=none \
-            --img-output-dir=$(STAGING_DIR)/openpower_targeting/ \
-            --vmm-consts-file=$(STAGING_DIR)/hostboot_build_images/vmmconst.h \
-            --noshort-enums
-
-        mv $(STAGING_DIR)/openpower_targeting/targeting.bin $(STAGING_DIR)/openpower_targeting/$(BR2_OPENPOWER_TARGETING_BIN_FILENAME)
-endef
-
-$(eval $(generic-package))
diff --git a/openpower/package/palmetto-xml/Config.in b/openpower/package/palmetto-xml/Config.in
new file mode 100755
index 0000000..6c5fd3c
--- /dev/null
+++ b/openpower/package/palmetto-xml/Config.in
@@ -0,0 +1,17 @@
+config BR2_PACKAGE_PALMETTO_XML
+        bool "palmetto_xml"
+        default y if (BR2_OPENPOWER_CONFIG_NAME = "palmetto")
+        help
+            Utilites for building xml and the targeting binary image
+
+config BR2_PALMETTO_SYSTEM_XML_FILENAME
+        string "Palmetto targeting system xml filename"
+        default ""
+        help
+            Defines the name of the system XML filename to be used when creating targeting binary image
+
+config BR2_PALMETTO_MRW_XML_FILENAME
+        string "Palmetto targeting mrw xml filename"
+        default ""
+        help
+            Defines the name of the mrw XML filename to be used when creating targeting binary image
diff --git a/openpower/package/palmetto-xml/palmetto-xml.mk b/openpower/package/palmetto-xml/palmetto-xml.mk
new file mode 100644
index 0000000..01c81d0
--- /dev/null
+++ b/openpower/package/palmetto-xml/palmetto-xml.mk
@@ -0,0 +1,63 @@
+################################################################################
+#
+# palmetto_xml
+#
+################################################################################
+
+PALMETTO_XML_VERSION = 7667c42a1a6097030564dcf06879b7ae66656e9a
+PALMETTO_XML_SITE = $(call github,open-power,palmetto-xml,$(PALMETTO_XML_VERSION))
+
+PALMETTO_XML_LICENSE = Apache-2.0
+PALMETTO_XML_DEPENDENCIES = hostboot-install-images openpower-mrw-install-images common-p8-xml-install-images
+
+PALMETTO_XML_INSTALL_IMAGES = YES
+PALMETTO_XML_INSTALL_TARGET = NO
+
+MRW_SCRATCH=$(STAGING_DIR)/openpower_mrw_scratch
+MRW_INSTALL_DIRECTORY=$(STAGING_DIR)/preprocessed_mrw
+MRW_HB_TOOLS=$(STAGING_DIR)/hostboot_build_images
+
+PALMETTO_XML_ENV_VARS= \
+    SCHEMA_FILE=$(MRW_SCRATCH)/schema/mrw.xsd \
+    PARSER_PATH=$(STAGING_DIR)/usr/bin \
+    XSL_PATH=$(MRW_SCRATCH)/xslt \
+    OUTPUT_PATH=$(MRW_INSTALL_DIRECTORY)
+
+define PALMETTO_XML_BUILD_CMDS
+        # copy the palmetto xml where the common lives
+        bash -c 'mkdir -p $(MRW_SCRATCH) && cp -r $(@D)/* $(MRW_SCRATCH)'
+        mkdir -p $(MRW_INSTALL_DIRECTORY)
+
+        # run the mrw parsers
+        $(PALMETTO_XML_ENV_VARS) bash -c 'cd $(MRW_SCRATCH) && $(MAKE) palmetto'
+
+        # generate the system mrm xml
+        $(MRW_HB_TOOLS)/genHwsvMrwXml.pl \
+            --system=$(BR2_OPENPOWER_CONFIG_NAME) \
+            --mrwdir=$(MRW_INSTALL_DIRECTORY) \
+            --build=hb > $(MRW_INSTALL_DIRECTORY)/$(BR2_PALMETTO_MRW_XML_FILENAME)
+
+endef
+
+define PALMETTO_XML_INSTALL_IMAGES_CMDS
+
+        # merge in any system specific attributes, hostboot attributes
+        $(MRW_HB_TOOLS)/mergexml.sh $(@D)/$(BR2_PALMETTO_SYSTEM_XML_FILENAME) \
+            $(MRW_HB_TOOLS)/attribute_types.xml \
+            $(MRW_HB_TOOLS)/attribute_types_hb.xml \
+            $(MRW_HB_TOOLS)/target_types_merged.xml \
+            $(MRW_HB_TOOLS)/target_types_hb.xml \
+            $(MRW_INSTALL_DIRECTORY)/$(BR2_PALMETTO_MRW_XML_FILENAME) > $(MRW_HB_TOOLS)/temporary_hb.hb.xml;
+
+        # creating the targeting binary
+        $(MRW_HB_TOOLS)/xmltohb.pl  \
+            --hb-xml-file=$(MRW_HB_TOOLS)/temporary_hb.hb.xml \
+            --fapi-attributes-xml-file=$(MRW_HB_TOOLS)/fapiattrs.xml \
+            --src-output-dir=none \
+            --img-output-dir=$(MRW_HB_TOOLS)/ \
+            --vmm-consts-file=$(MRW_HB_TOOLS)/vmmconst.h --noshort-enums
+
+        mv $(MRW_HB_TOOLS)/targeting.bin $(MRW_HB_TOOLS)/$(BR2_OPENPOWER_TARGETING_BIN_FILENAME)
+endef
+
+$(eval $(generic-package))