From c89e24973295279422f9f5adb316f02bea322b35 Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Thu, 5 Oct 2017 15:17:58 +0100
Subject: [PATCH] framework/target: add ability to pass additional platform
 params.

Gem5Platform requires a host output directory as one if it's
instantiation parameters. This is not something we want to expose a
configuration parameter to the user, as for WA, the standard output
directory ought to be used.

Up to this point, WA's target instatiation process assumed that all
parameters came from the user, and there was no way for WA itself to set
them. This commit adds extra_platform_parms argument to
instantiate_target, to remedi this.

extra_platform_parms is then used to set the host output directory for
gem5 appropriately.
---
 wa/framework/execution.py      |  3 ++-
 wa/framework/target/manager.py | 13 +++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/wa/framework/execution.py b/wa/framework/execution.py
index d665389c..f2b302c6 100644
--- a/wa/framework/execution.py
+++ b/wa/framework/execution.py
@@ -269,7 +269,8 @@ class Executor(object):
 
         self.logger.info('Connecting to target')
         self.target_manager = TargetManager(config.run_config.device,
-                                       config.run_config.device_config)
+                                       config.run_config.device_config,
+                                       output.basepath)
         output.write_target_info(self.target_manager.get_target_info())
 
         self.logger.info('Initializing execution context')
diff --git a/wa/framework/target/manager.py b/wa/framework/target/manager.py
index 1b5022bf..98b1cb38 100644
--- a/wa/framework/target/manager.py
+++ b/wa/framework/target/manager.py
@@ -1,4 +1,5 @@
 import logging
+import os
 
 from wa.framework import signal
 from wa.framework.plugin import Parameter
@@ -8,6 +9,7 @@ from wa.framework.target.descriptor import (get_target_descriptions,
 from wa.framework.target.info import TargetInfo
 from wa.framework.target.runtime_parameter_manager import RuntimeParameterManager
 
+from devlib import Gem5SimulationPlatform
 from devlib.utils.misc import memoized
 from devlib.exception import TargetError
 
@@ -25,7 +27,8 @@ class TargetManager(object):
                   """),
     ]
 
-    def __init__(self, name, parameters):
+    def __init__(self, name, parameters, outdir):
+        self.outdir = outdir
         self.logger = logging.getLogger('tm')
         self.target_name = name
         self.target = None
@@ -85,8 +88,14 @@ class TargetManager(object):
         if self.target_name not in target_map:
             raise ValueError('Unknown Target: {}'.format(self.target_name))
         tdesc = target_map[self.target_name]
+
+        extra_plat_params={}
+        if tdesc.platform is Gem5SimulationPlatform:
+            extra_plat_params['host_output_dir'] = self.outdir
+
         self.logger.debug('Creating {} target'.format(self.target_name))
-        self.target = instantiate_target(tdesc, self.parameters, connect=False)
+        self.target = instantiate_target(tdesc, self.parameters, connect=False,
+                                         extra_platform_params=extra_plat_params)
 
         with signal.wrap('TARGET_CONNECT'):
             self.target.connect()