ameba.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 .builder import Builder
  17. class AmebaBoard(Enum):
  18. AMEBAD = auto()
  19. class AmebaApp(Enum):
  20. ALL_CLUSTERS = auto()
  21. ALL_CLUSTERS_MINIMAL = auto()
  22. LIGHT = auto()
  23. PIGWEED = auto()
  24. LIGHT_SWITCH = auto()
  25. @property
  26. def ExampleName(self):
  27. if self == AmebaApp.ALL_CLUSTERS:
  28. return 'all-clusters-app'
  29. elif self == AmebaApp.ALL_CLUSTERS_MINIMAL:
  30. return 'all-clusters-minimal-app'
  31. elif self == AmebaApp.LIGHT:
  32. return 'lighting-app'
  33. elif self == AmebaApp.LIGHT_SWITCH:
  34. return 'light-switch-app'
  35. elif self == AmebaApp.PIGWEED:
  36. return 'pigweed-app'
  37. else:
  38. raise Exception('Unknown app type: %r' % self)
  39. @property
  40. def AppNamePrefix(self):
  41. if self == AmebaApp.ALL_CLUSTERS:
  42. return 'chip-ameba-all-clusters-app'
  43. elif self == AmebaApp.ALL_CLUSTERS_MINIMAL:
  44. return 'chip-ameba-all-clusters-minimal-app'
  45. elif self == AmebaApp.LIGHT:
  46. return 'chip-ameba-lighting-app'
  47. elif self == AmebaApp.LIGHT_SWITCH:
  48. return 'chip-ameba-light-switch-app'
  49. elif self == AmebaApp.PIGWEED:
  50. return 'chip-ameba-pigweed-app'
  51. else:
  52. raise Exception('Unknown app type: %r' % self)
  53. class AmebaBuilder(Builder):
  54. def __init__(self,
  55. root,
  56. runner,
  57. board: AmebaBoard = AmebaBoard.AMEBAD,
  58. app: AmebaApp = AmebaApp.ALL_CLUSTERS):
  59. super(AmebaBuilder, self).__init__(root, runner)
  60. self.board = board
  61. self.app = app
  62. def generate(self):
  63. cmd = '$AMEBA_PATH/project/realtek_amebaD_va0_example/GCC-RELEASE/build.sh '
  64. if self.app.ExampleName == 'pigweed-app':
  65. # rpc flag: -r
  66. cmd += '-r '
  67. # <build root> <build_system> <output_directory> <application>
  68. cmd += ' '.join([self.root, 'ninja', self.output_dir,
  69. self.app.ExampleName])
  70. self._Execute(['bash', '-c', cmd],
  71. title='Generating ' + self.identifier)
  72. def _build(self):
  73. self._Execute(['ninja', '-C', self.output_dir],
  74. title='Building ' + self.identifier)
  75. def build_outputs(self):
  76. return {
  77. self.app.AppNamePrefix + '.axf':
  78. os.path.join(self.output_dir, 'asdk', 'target_image2.axf'),
  79. self.app.AppNamePrefix + '.map':
  80. os.path.join(self.output_dir, 'asdk', 'target_image2.map'),
  81. 'km0_boot_all.bin':
  82. os.path.join(self.output_dir, 'asdk',
  83. 'bootloader', 'km0_boot_all.bin'),
  84. 'km4_boot_all.bin':
  85. os.path.join(self.output_dir, 'asdk',
  86. 'bootloader', 'km4_boot_all.bin'),
  87. 'km0_km4_image2.bin':
  88. os.path.join(self.output_dir, 'asdk',
  89. 'image', 'km0_km4_image2.bin'),
  90. }