builder.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #! python
  2. import os
  3. import shutil
  4. import sys
  5. from datetime import datetime
  6. from buildutils.builder import Device, Compiler, Axis, Step, BuildStep, RunModelStep, Builder, Filter
  7. OPTIMIZATION = [ 'O1', 'O2', 'Ofast', 'Os', 'Oz' ]
  8. CC_OPT = {
  9. Compiler.AC5: {
  10. 'O1': 'O0',
  11. 'O2': 'O1',
  12. 'Ofast': 'Otime',
  13. 'Os': 'O2',
  14. 'Oz': 'O3'
  15. },
  16. Compiler.AC6: {
  17. 'O1': 'O1',
  18. 'O2': 'O2',
  19. 'Ofast': 'Ofast',
  20. 'Os': 'Os',
  21. 'Oz': 'Oz'
  22. },
  23. Compiler.AC6LTM: {
  24. 'O1': 'O1',
  25. 'O2': 'O2',
  26. 'Ofast': 'Ofast',
  27. 'Os': 'Os',
  28. 'Oz': 'Oz'
  29. },
  30. Compiler.AC6STBL: {
  31. 'O1': 'O1',
  32. 'O2': 'O2',
  33. 'Ofast': 'Ofast',
  34. 'Os': 'Os',
  35. 'Oz': 'Oz'
  36. },
  37. Compiler.GCC: {
  38. 'O1': 'O1',
  39. 'O2': 'O2',
  40. 'Ofast': 'Ofast',
  41. 'Os': 'Os',
  42. 'Oz': 'O3'
  43. },
  44. }
  45. CORTEX_M = [
  46. Device.CM0,
  47. Device.CM0PLUS,
  48. Device.CM3,
  49. Device.CM4,
  50. Device.CM4FP,
  51. Device.CM7,
  52. Device.CM7SP,
  53. Device.CM7DP,
  54. Device.CM23,
  55. Device.CM33,
  56. Device.CM23NS,
  57. Device.CM33NS,
  58. Device.CM23S,
  59. Device.CM33S,
  60. Device.CM35P,
  61. Device.CM35PS,
  62. Device.CM35PNS
  63. ]
  64. BOOTLOADER = [
  65. Device.CM23NS,
  66. Device.CM33NS,
  67. Device.CM35PNS
  68. ]
  69. FVP_MODELS = {
  70. Device.CM0 : { 'cmd': "FVP_MPS2_Cortex-M0", 'args': { 'limit': "1000000000", 'config': "config/ARMCM0_config.txt" } },
  71. Device.CM0PLUS : { 'cmd': "FVP_MPS2_Cortex-M0plus", 'args': { 'limit': "1000000000", 'config': "config/ARMCM0plus_config.txt" } },
  72. Device.CM3 : { 'cmd': "FVP_MPS2_Cortex-M3", 'args': { 'limit': "1000000000", 'config': "config/ARMCM3_config.txt" } },
  73. Device.CM4 : { 'cmd': "FVP_MPS2_Cortex-M4", 'args': { 'limit': "1000000000", 'config': "config/ARMCM4_config.txt" } },
  74. Device.CM4FP : { 'cmd': "FVP_MPS2_Cortex-M4", 'args': { 'limit': "1000000000", 'config': "config/ARMCM4FP_config.txt" } },
  75. Device.CM7 : { 'cmd': "FVP_MPS2_Cortex-M7", 'args': { 'limit': "1000000000", 'config': "config/ARMCM7_config.txt" } },
  76. Device.CM7SP : { 'cmd': "FVP_MPS2_Cortex-M7", 'args': { 'limit': "1000000000", 'config': "config/ARMCM7SP_config.txt" } },
  77. Device.CM7DP : { 'cmd': "FVP_MPS2_Cortex-M7", 'args': { 'limit': "1000000000", 'config': "config/ARMCM7DP_config.txt" } },
  78. Device.CM23 : { 'cmd': "FVP_MPS2_Cortex-M23", 'args': { 'limit': "1000000000", 'config': "config/ARMCM23_config.txt", 'target': "cpu0" } },
  79. Device.CM33 : { 'cmd': "FVP_MPS2_Cortex-M33", 'args': { 'limit': "1000000000", 'config': "config/ARMCM33_config.txt", 'target': "cpu0" } },
  80. Device.CM23NS : { 'cmd': "FVP_MPS2_Cortex-M23", 'args': { 'limit': "1000000000", 'config': "config/ARMCM23_TZ_config.txt", 'target': "cpu0" } },
  81. Device.CM33NS : { 'cmd': "FVP_MPS2_Cortex-M33", 'args': { 'limit': "1000000000", 'config': "config/ARMCM33_DSP_FP_TZ_config.txt", 'target': "cpu0" } },
  82. Device.CM23S : { 'cmd': "FVP_MPS2_Cortex-M23", 'args': { 'limit': "1000000000", 'config': "config/ARMCM23_TZ_config.txt", 'target': "cpu0" } },
  83. Device.CM33S : { 'cmd': "FVP_MPS2_Cortex-M33", 'args': { 'limit': "1000000000", 'config': "config/ARMCM33_DSP_FP_TZ_config.txt", 'target': "cpu0" } },
  84. Device.CM35P : { 'cmd': "FVP_MPS2_Cortex-M35P", 'args': { 'limit': "1000000000", 'config': "config/ARMCM35P_config.txt", 'target': "cpu0" } },
  85. Device.CM35PS : { 'cmd': "FVP_MPS2_Cortex-M35P", 'args': { 'limit': "1000000000", 'config': "config/ARMCM35P_DSP_FP_TZ_config.txt", 'target': "cpu0" } },
  86. Device.CM35PNS : { 'cmd': "FVP_MPS2_Cortex-M35P", 'args': { 'limit': "1000000000", 'config': "config/ARMCM35P_DSP_FP_TZ_config.txt", 'target': "cpu0" } },
  87. Device.CA5 : { 'cmd': "FVP_VE_Cortex-A5x1", 'args': { 'limit': "1000000000", 'config': "config/ARMCA5_config.txt" } },
  88. Device.CA7 : { 'cmd': "FVP_VE_Cortex-A7x1", 'args': { 'limit': "1000000000", 'config': "config/ARMCA7_config.txt" } },
  89. Device.CA9 : { 'cmd': "FVP_VE_Cortex-A9x1", 'args': { 'limit': "1000000000", 'config': "config/ARMCA9_config.txt" } },
  90. Device.CA5NEON : { 'cmd': "FVP_VE_Cortex-A5x1", 'args': { 'limit': "1000000000", 'config': "config/ARMCA5neon_config.txt" } },
  91. Device.CA7NEON : { 'cmd': "FVP_VE_Cortex-A7x1", 'args': { 'limit': "1000000000", 'config': "config/ARMCA7neon_config.txt" } },
  92. Device.CA9NEON : { 'cmd': "FVP_VE_Cortex-A9x1", 'args': { 'limit': "1000000000", 'config': "config/ARMCA9neon_config.txt" } }
  93. }
  94. def projects(step, config):
  95. result = [ str(config['compiler']).lower()+".rtebuild" ]
  96. if config['device'] in BOOTLOADER:
  97. result += [ "bootloader/"+str(config['compiler']).lower()+".rtebuild" ]
  98. return result
  99. def images(step, config):
  100. result = [ "build/arm{dev}/arm{dev}.elf".format(dev=config['device'].value[1].lower()) ]
  101. if config['device'] in BOOTLOADER:
  102. result += [ "bootloader/build/arm{dev}/arm{dev}.elf".format(dev=config['device'].value[1].lower()) ]
  103. return result
  104. def storeResult(step, config, cmd):
  105. result = "result_{cc}_{dev}_{opt}_{now}.junit".format(dev=config['device'], cc=config['compiler'], opt=config['optimize'],now=datetime.now().strftime("%Y%m%d%H%M%S"))
  106. resultfile = step.storeJunitResult(cmd, result, "{cc}.{dev}.{opt}".format(dev=config['device'], cc=config['compiler'], opt=config['optimize']))
  107. if not resultfile:
  108. cmd.appendOutput("Storing results failed!");
  109. cmd.forceResult(1)
  110. def add_options(step, config, cmd):
  111. cmd._options['optimize'] = CC_OPT[config['compiler']][config['optimize']]
  112. def create():
  113. deviceAxis = Axis("device", abbrev="d", values=Device, desc="Device(s) to be considered.")
  114. compilerAxis = Axis("compiler", abbrev="c", values=Compiler, desc="Compiler(s) to be considered.")
  115. optimizeAxis = Axis("optimize", abbrev="o", values=OPTIMIZATION , desc="Optimization level(s) to be considered.")
  116. buildStep = BuildStep("build", abbrev="b", desc="Build the selected configurations.")
  117. buildStep.projects = projects
  118. buildStep.target = lambda step, config: "arm"+config['device'].value[1].lower()
  119. buildStep.pre = add_options
  120. runStep = RunModelStep("run", abbrev="r", desc="Run the selected configurations.")
  121. runStep.images = images
  122. runStep.model = lambda step, config: FVP_MODELS[config['device']]
  123. runStep.post = storeResult
  124. debugStep = RunModelStep("debug", abbrev="d", desc="Debug the selected configurations.")
  125. debugStep.images = images
  126. debugStep.args = lambda step, config: { 'cadi' : True }
  127. debugStep.model = lambda step, config: FVP_MODELS[config['device']]
  128. filterAC5 = Filter().addAxis(compilerAxis, Compiler.AC5).addAxis(deviceAxis, "CM[23]3*")
  129. filterAC6LTM = Filter().addAxis(compilerAxis, Compiler.AC6LTM).addAxis(deviceAxis, "CM35P*")
  130. builder = Builder()
  131. builder.addAxis([ compilerAxis, deviceAxis, optimizeAxis ])
  132. builder.addStep([ buildStep, runStep, debugStep ])
  133. builder.addFilter([ filterAC5, filterAC6LTM ])
  134. return builder
  135. def complete(builder, success):
  136. builder.saveJunitResult("build_{now}.junit".format(now = datetime.now().strftime("%Y%m%d%H%M%S")))