qpg.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright (c) 2021 Project CHIP Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. from enum import Enum, auto
  16. from .gn import GnBuilder
  17. class QpgApp(Enum):
  18. LIGHT = auto()
  19. LOCK = auto()
  20. SHELL = auto()
  21. PERSISTENT_STORAGE = auto()
  22. def ExampleName(self):
  23. if self == QpgApp.LIGHT:
  24. return 'lighting-app'
  25. elif self == QpgApp.LOCK:
  26. return 'lock-app'
  27. elif self == QpgApp.SHELL:
  28. return 'shell'
  29. elif self == QpgApp.PERSISTENT_STORAGE:
  30. return 'persistent-storage'
  31. else:
  32. raise Exception('Unknown app type: %r' % self)
  33. def AppNamePrefix(self):
  34. if self == QpgApp.LIGHT:
  35. return 'chip-qpg6105-lighting-example'
  36. elif self == QpgApp.LOCK:
  37. return 'chip-qpg6105-lock-example'
  38. elif self == QpgApp.SHELL:
  39. return 'chip-qpg6105-shell-example'
  40. elif self == QpgApp.PERSISTENT_STORAGE:
  41. return 'chip-qpg6105-persistent_storage-example'
  42. else:
  43. raise Exception('Unknown app type: %r' % self)
  44. def FlashBundleName(self):
  45. if self == QpgApp.LIGHT:
  46. return 'lighting_app.out.flashbundle.txt'
  47. elif self == QpgApp.LOCK:
  48. return 'lock_app.out.flashbundle.txt'
  49. elif self == QpgApp.SHELL:
  50. return 'shell_app.out.flashbundle.txt'
  51. elif self == QpgApp.PERSISTENT_STORAGE:
  52. return 'persistent_storage_app.out.flashbundle.txt'
  53. else:
  54. raise Exception('Unknown app type: %r' % self)
  55. def BuildRoot(self, root):
  56. return os.path.join(root, 'examples', self.ExampleName(), 'qpg')
  57. class QpgBoard(Enum):
  58. QPG6105 = 1
  59. def GnArgName(self):
  60. if self == QpgBoard.QPG6105:
  61. return 'qpg6105'
  62. else:
  63. raise Exception('Unknown board #: %r' % self)
  64. class QpgBuilder(GnBuilder):
  65. def __init__(self,
  66. root,
  67. runner,
  68. app: QpgApp = QpgApp.LIGHT,
  69. board: QpgBoard = QpgBoard.QPG6105,
  70. enable_rpcs: bool = False):
  71. super(QpgBuilder, self).__init__(
  72. root=app.BuildRoot(root),
  73. runner=runner)
  74. self.app = app
  75. self.board = board
  76. self.enable_rpcs = enable_rpcs
  77. def GnBuildArgs(self):
  78. args = ['qpg_target_ic=\"%s\"' % self.board.GnArgName()]
  79. if self.enable_rpcs:
  80. args.append('import("//with_pw_rpc.gni")')
  81. return args
  82. def build_outputs(self):
  83. items = {}
  84. for extension in ["out", "out.map", "out.hex"]:
  85. name = '%s.%s' % (self.app.AppNamePrefix(), extension)
  86. items[name] = os.path.join(self.output_dir, name)
  87. # Figure out flash bundle files and build accordingly
  88. with open(os.path.join(self.output_dir, self.app.FlashBundleName())) as f:
  89. for line in f.readlines():
  90. name = line.strip()
  91. items['flashbundle/%s' %
  92. name] = os.path.join(self.output_dir, name)
  93. return items