objcopy.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/python
  2. # Grygoriy Fuchedzhy 2010
  3. """
  4. Support for converting linked targets to ihex, srec or binary files using
  5. objcopy. Use the 'objcopy' feature in conjunction with the 'cc' or 'cxx'
  6. feature. The 'objcopy' feature uses the following attributes:
  7. objcopy_bfdname Target object format name (eg. ihex, srec, binary).
  8. Defaults to ihex.
  9. objcopy_target File name used for objcopy output. This defaults to the
  10. target name with objcopy_bfdname as extension.
  11. objcopy_install_path Install path for objcopy_target file. Defaults to ${PREFIX}/fw.
  12. objcopy_flags Additional flags passed to objcopy.
  13. """
  14. from waflib.Utils import def_attrs
  15. from waflib import Task
  16. from waflib.TaskGen import feature, after_method
  17. class objcopy(Task.Task):
  18. run_str = '${OBJCOPY} -O ${TARGET_BFDNAME} ${OBJCOPYFLAGS} ${SRC} ${TGT}'
  19. color = 'CYAN'
  20. @feature('objcopy')
  21. @after_method('apply_link')
  22. def map_objcopy(self):
  23. def_attrs(self,
  24. objcopy_bfdname = 'ihex',
  25. objcopy_target = None,
  26. objcopy_install_path = "${PREFIX}/firmware",
  27. objcopy_flags = '')
  28. link_output = self.link_task.outputs[0]
  29. if not self.objcopy_target:
  30. self.objcopy_target = link_output.change_ext('.' + self.objcopy_bfdname).name
  31. task = self.create_task('objcopy', src=link_output, tgt=self.path.find_or_declare(self.objcopy_target))
  32. task.env.append_unique('TARGET_BFDNAME', self.objcopy_bfdname)
  33. try:
  34. task.env.append_unique('OBJCOPYFLAGS', getattr(self, 'objcopy_flags'))
  35. except AttributeError:
  36. pass
  37. if self.objcopy_install_path:
  38. self.add_install_files(install_to=self.objcopy_install_path, install_from=task.outputs[0])
  39. def configure(ctx):
  40. ctx.find_program('objcopy', var='OBJCOPY', mandatory=True)