asr.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # Copyright (c) 2023 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 ASRApp(Enum):
  18. ALL_CLUSTERS = auto()
  19. ALL_CLUSTERS_MINIMAL = auto()
  20. LIGHT = auto()
  21. LIGHT_SWITCH = auto()
  22. LOCK = auto()
  23. BRIDGE = auto()
  24. TEMPERATURE_MEASUREMENT = auto()
  25. THERMOSTAT = auto()
  26. OTA_REQUESTOR = auto()
  27. DISHWASHER = auto()
  28. REFRIGERATOR = auto()
  29. def ExampleName(self):
  30. if self == ASRApp.ALL_CLUSTERS:
  31. return 'all-clusters-app'
  32. elif self == ASRApp.ALL_CLUSTERS_MINIMAL:
  33. return 'all-clusters-minimal-app'
  34. elif self == ASRApp.LIGHT:
  35. return 'lighting-app'
  36. elif self == ASRApp.LIGHT_SWITCH:
  37. return 'light-switch-app'
  38. elif self == ASRApp.LOCK:
  39. return 'lock-app'
  40. elif self == ASRApp.BRIDGE:
  41. return 'bridge-app'
  42. elif self == ASRApp.TEMPERATURE_MEASUREMENT:
  43. return 'temperature-measurement-app'
  44. elif self == ASRApp.THERMOSTAT:
  45. return 'thermostat'
  46. elif self == ASRApp.OTA_REQUESTOR:
  47. return 'ota-requestor-app'
  48. elif self == ASRApp.DISHWASHER:
  49. return 'dishwasher-app'
  50. elif self == ASRApp.REFRIGERATOR:
  51. return 'refrigerator-app'
  52. else:
  53. raise Exception('Unknown app type: %r' % self)
  54. def AppNamePrefix(self):
  55. if self == ASRApp.ALL_CLUSTERS:
  56. return 'chip-asr-all-clusters-app'
  57. elif self == ASRApp.ALL_CLUSTERS_MINIMAL:
  58. return 'chip-asr-all-clusters-minimal-app'
  59. elif self == ASRApp.LIGHT:
  60. return 'chip-asr-lighting-app'
  61. elif self == ASRApp.LIGHT_SWITCH:
  62. return 'chip-asr-light-switch-app'
  63. elif self == ASRApp.LOCK:
  64. return 'chip-asr-lock-example'
  65. elif self == ASRApp.BRIDGE:
  66. return 'chip-asr-bridge-example'
  67. elif self == ASRApp.TEMPERATURE_MEASUREMENT:
  68. return 'chip-asr-temperature-measurement-example'
  69. elif self == ASRApp.THERMOSTAT:
  70. return 'chip-asr-thermostat-example'
  71. elif self == ASRApp.OTA_REQUESTOR:
  72. return 'chip-asr-ota-requestor-example'
  73. elif self == ASRApp.DISHWASHER:
  74. return 'chip-asr-dishwasher-example'
  75. elif self == ASRApp.REFRIGERATOR:
  76. return 'chip-asr-refrigerator-example'
  77. else:
  78. raise Exception('Unknown app type: %r' % self)
  79. def BuildRoot(self, root):
  80. return os.path.join(root, 'examples', self.ExampleName(), 'asr')
  81. class ASRBoard(Enum):
  82. ASR582X = auto()
  83. ASR595X = auto()
  84. ASR550X = auto()
  85. def GetIC(self):
  86. if self == ASRBoard.ASR582X:
  87. return 'asr582x'
  88. elif self == ASRBoard.ASR595X:
  89. return 'asr595x'
  90. elif self == ASRBoard.ASR550X:
  91. return 'asr550x'
  92. else:
  93. raise Exception('Unknown board #: %r' % self)
  94. class ASRBuilder(GnBuilder):
  95. def __init__(self,
  96. root,
  97. runner,
  98. app: ASRApp = ASRApp.LIGHT,
  99. board: ASRBoard = ASRBoard.ASR582X,
  100. chip_build_libshell: bool = False,
  101. chip_logging: bool = True,
  102. enable_factory: bool = False,
  103. enable_rotating_device_id: bool = False,
  104. enable_ota_requestor: bool = False,
  105. enable_lwip_ip6_hook: bool = False):
  106. super(ASRBuilder, self).__init__(
  107. root=app.BuildRoot(root),
  108. runner=runner)
  109. self.board = board
  110. self.app = app
  111. asr_chip = self.board.GetIC()
  112. self.extra_gn_options = ['asr_ic_family="%s"' % asr_chip]
  113. if asr_chip == "asr582x":
  114. ASR_ARCH = "arm"
  115. ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr582x"
  116. elif asr_chip == "asr595x":
  117. ASR_ARCH = "riscv"
  118. ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr595x"
  119. elif asr_chip == "asr550x":
  120. ASR_ARCH = "arm"
  121. ASR_SDK_ROOT = "//third_party/connectedhomeip/third_party/asr/asr550x"
  122. self.extra_gn_options.append('target_cpu="%s"' % ASR_ARCH)
  123. toolchain = os.path.join(root, os.path.split(os.path.realpath(__file__))[0], '../../../config/asr/toolchain')
  124. toolchain = 'custom_toolchain="{}:asrtoolchain"'.format(toolchain)
  125. if toolchain:
  126. self.extra_gn_options.append(toolchain)
  127. self.extra_gn_options.append('asr_sdk_build_root="%s"' % ASR_SDK_ROOT)
  128. self.extra_gn_options.append('mbedtls_target="%s:asr_build"' % ASR_SDK_ROOT)
  129. if (asr_chip == "asr582x"
  130. or asr_chip == "asr595x"):
  131. self.extra_gn_options.append('chip_config_network_layer_ble=true')
  132. if (asr_chip == "asr550x"):
  133. self.extra_gn_options.append('chip_config_network_layer_ble=false')
  134. if enable_ota_requestor:
  135. self.extra_gn_options.append('chip_enable_ota_requestor=true')
  136. if chip_build_libshell:
  137. self.extra_gn_options.append('chip_build_libshell=true')
  138. if chip_logging is False:
  139. self.extra_gn_options.append('chip_logging=false')
  140. if enable_factory:
  141. self.extra_gn_options.append('chip_use_transitional_commissionable_data_provider=false')
  142. self.extra_gn_options.append('chip_enable_factory_data=true')
  143. if enable_rotating_device_id:
  144. self.extra_gn_options.append('chip_enable_additional_data_advertising=true')
  145. self.extra_gn_options.append('chip_enable_rotating_device_id=true')
  146. if enable_lwip_ip6_hook:
  147. self.extra_gn_options.append('chip_lwip_ip6_hook=true')
  148. self.extra_gn_options.append('asr_toolchain_root="%s"' % os.environ['ASR_TOOLCHAIN_PATH'])
  149. def GnBuildArgs(self):
  150. return self.extra_gn_options
  151. def build_outputs(self):
  152. items = {
  153. '%s.out' % self.app.AppNamePrefix():
  154. os.path.join(self.output_dir, '%s.out' %
  155. self.app.AppNamePrefix()),
  156. '%s.out.map' % self.app.AppNamePrefix():
  157. os.path.join(self.output_dir,
  158. '%s.out.map' % self.app.AppNamePrefix()),
  159. }
  160. return items