unstable_icestorm.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright 2017 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. from .. import mesonlib
  12. from ..interpreterbase import flatten
  13. from ..interpreterbase import FeatureNew
  14. from . import ExtensionModule
  15. class IceStormModule(ExtensionModule):
  16. @FeatureNew('FPGA/Icestorm Module', '0.45.0')
  17. def __init__(self, interpreter):
  18. super().__init__(interpreter)
  19. self.snippets.add('project')
  20. self.yosys_bin = None
  21. def detect_binaries(self, interpreter):
  22. self.yosys_bin = interpreter.find_program_impl(['yosys'])
  23. self.arachne_bin = interpreter.find_program_impl(['arachne-pnr'])
  24. self.icepack_bin = interpreter.find_program_impl(['icepack'])
  25. self.iceprog_bin = interpreter.find_program_impl(['iceprog'])
  26. self.icetime_bin = interpreter.find_program_impl(['icetime'])
  27. def project(self, interpreter, state, args, kwargs):
  28. if not self.yosys_bin:
  29. self.detect_binaries(interpreter)
  30. if not len(args):
  31. raise mesonlib.MesonException('Project requires at least one argument, which is the project name.')
  32. proj_name = args[0]
  33. arg_sources = args[1:]
  34. if not isinstance(proj_name, str):
  35. raise mesonlib.MesonException('Argument must be a string.')
  36. kwarg_sources = kwargs.get('sources', [])
  37. if not isinstance(kwarg_sources, list):
  38. kwarg_sources = [kwarg_sources]
  39. all_sources = interpreter.source_strings_to_files(flatten(arg_sources + kwarg_sources))
  40. if 'constraint_file' not in kwargs:
  41. raise mesonlib.MesonException('Constraint file not specified.')
  42. constraint_file = interpreter.source_strings_to_files(kwargs['constraint_file'])
  43. if len(constraint_file) != 1:
  44. raise mesonlib.MesonException('Constraint file must contain one and only one entry.')
  45. blif_name = proj_name + '_blif'
  46. blif_fname = proj_name + '.blif'
  47. asc_name = proj_name + '_asc'
  48. asc_fname = proj_name + '.asc'
  49. bin_name = proj_name + '_bin'
  50. bin_fname = proj_name + '.bin'
  51. time_name = proj_name + '-time'
  52. upload_name = proj_name + '-upload'
  53. blif_target = interpreter.func_custom_target(None, [blif_name], {
  54. 'input': all_sources,
  55. 'output': blif_fname,
  56. 'command': [self.yosys_bin, '-q', '-p', 'synth_ice40 -blif @OUTPUT@', '@INPUT@']})
  57. asc_target = interpreter.func_custom_target(None, [asc_name], {
  58. 'input': blif_target,
  59. 'output': asc_fname,
  60. 'command': [self.arachne_bin, '-q', '-d', '1k', '-p', constraint_file, '@INPUT@', '-o', '@OUTPUT@']})
  61. bin_target = interpreter.func_custom_target(None, [bin_name], {
  62. 'input': asc_target,
  63. 'output': bin_fname,
  64. 'command': [self.icepack_bin, '@INPUT@', '@OUTPUT@'],
  65. 'build_by_default': True})
  66. interpreter.func_run_target(None, [upload_name], {
  67. 'command': [self.iceprog_bin, bin_target]})
  68. interpreter.func_run_target(None, [time_name], {
  69. 'command': [self.icetime_bin, bin_target]})
  70. def initialize(*args, **kwargs):
  71. return IceStormModule(*args, **kwargs)