diff python/ppci/buildtasks.py @ 385:d056b552d3f4

Made better use of layout
author Windel Bouwman
date Thu, 01 May 2014 14:03:12 +0200
parents 173e20a47fda
children 6ae782a085e0
line wrap: on
line diff
--- a/python/ppci/buildtasks.py	Sun Apr 27 17:50:25 2014 +0200
+++ b/python/ppci/buildtasks.py	Thu May 01 14:03:12 2014 +0200
@@ -7,7 +7,7 @@
 import logging
 
 from .tasks import Task, TaskError, register_task
-from .buildfunctions import c3compile, link, assemble
+from .buildfunctions import c3compile, link, assemble, fix_object
 from pyyacc import ParserException
 from . import CompilerError
 
@@ -82,20 +82,29 @@
     """ Link together a collection of object files """
     def run(self):
         layout = self.relpath(self.get_argument('layout'))
+        target = self.get_argument('target')
         objects = self.open_file_set(self.get_argument('objects'))
-        output_file = self.relpath(self.get_argument('output'))
+        output_filename = self.relpath(self.get_argument('output'))
 
         try:
-            output_obj = link(objects, layout)
+            output_obj = link(objects, layout, target)
         except CompilerError as e:
             raise TaskError(e.msg)
-        # TODO: use layout here:
-        code = output_obj.get_section('code').data
-        with open(output_file, 'wb') as f:
-            f.write(code)
+
+        # Store output:
+        with open(output_filename, 'w') as f:
+            output_obj.save(f)
 
 
+@register_task("objcopy")
 class ObjCopyTask(Task):
     def run(self):
-        pass
+        image_name = self.get_argument('imagename')
+        output_filename = self.relpath(self.get_argument('output'))
+        object_filename = self.relpath(self.get_argument('objectfile'))
 
+        obj = fix_object(object_filename)
+        image = obj.get_image(image_name)
+        with open(output_filename, 'wb') as f:
+            f.write(image)
+