SConscript 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # RT-Thread building script for component
  2. # Nuclei 100 series not yet supported by RT-Thread build system
  3. # please take a try with the RT-Thread Nano integrated in Nuclei N100 SDK
  4. Import('rtconfig')
  5. Import('RTT_ROOT')
  6. import os
  7. import re
  8. import rtconfig
  9. from building import *
  10. BUILTIN_ALL_DOWNLOADED_MODES = {
  11. "evalsoc": ("ilm", "flash", "flashxip", "ddr", "sram")
  12. }
  13. DEFAULT_DOWNLOAD_MODES = ("ilm", "flashxip", "ddr", "sram", "sramxip")
  14. default_arch_abi = ("rv32imc", "ilp32")
  15. cwd = GetCurrentDir()
  16. FRAMEWORK_DIR = cwd
  17. def parse_nuclei_soc_predefined_cores(core_mk):
  18. if not os.path.isfile(core_mk):
  19. return dict()
  20. core_arch_abis = dict()
  21. core_arch_abi_re = re.compile(r'^([A-Z]+\d+[A-Z]*)_CORE_ARCH_ABI\s*=\s*(rv\d+\w*)\s+(i*lp\d+\w*)')
  22. with open(core_mk, "r") as core_mk_file:
  23. for line in core_mk_file.readlines():
  24. line = line.strip()
  25. matches = core_arch_abi_re.match(line)
  26. if matches:
  27. core_lower = matches.groups()[0].lower()
  28. core_arch_abis[core_lower] = (matches.groups()[1:3])
  29. return core_arch_abis
  30. NUCLEI_SOC_CORES_MK = os.path.join(cwd, "Build/Makefile.core")
  31. core_arch_abis = parse_nuclei_soc_predefined_cores(NUCLEI_SOC_CORES_MK)
  32. # Get configurations from rtconfig
  33. build_soc = getattr(rtconfig, "NUCLEI_SDK_SOC").lower().strip()
  34. build_board = getattr(rtconfig, "NUCLEI_SDK_BOARD").lower().strip()
  35. build_download_mode = getattr(rtconfig, "NUCLEI_SDK_DOWNLOAD", "").lower().strip()
  36. build_core = getattr(rtconfig, "NUCLEI_SDK_CORE", "").lower().strip()
  37. build_march = getattr(rtconfig, "NUCLEI_SDK_RISCV_ARCH", "").lower().strip()
  38. build_mabi = getattr(rtconfig, "NUCLEI_SDK_RISCV_ABI", "").lower().strip()
  39. build_mcmodel = getattr(rtconfig, "NUCLEI_SDK_RISCV_MCMODEL", "medany").lower().strip()
  40. build_ldscript = getattr(rtconfig, "NUCLEI_SDK_LDSCRIPT", "").lower().strip()
  41. if not build_march and not build_mabi and build_core in core_arch_abis:
  42. build_march, build_mabi = core_arch_abis[build_core]
  43. else:
  44. if not build_mabi or not build_march:
  45. build_march, build_mabi = default_arch_abi
  46. print("No mabi and march specified in rtconfig.py, use default -march=%s -mabi=%s!" % (build_march, build_mabi))
  47. if build_soc in BUILTIN_ALL_DOWNLOADED_MODES:
  48. supported_download_modes = BUILTIN_ALL_DOWNLOADED_MODES[build_soc]
  49. else:
  50. if os.path.isfile(os.path.join(cwd, build_soc, "build.mk")) == False:
  51. print("SoC={} is not supported in Nuclei SDK".format(build_soc))
  52. exit(0)
  53. else:
  54. supported_download_modes = DEFAULT_DOWNLOAD_MODES
  55. SoC_Common = 'SoC/{}/Common'.format(build_soc)
  56. SoC_Board = 'SoC/{}/Board/{}'.format(build_soc, build_board)
  57. build_core_options = " -march=%s -mabi=%s -mcmodel=%s " % (build_march, build_mabi, build_mcmodel)
  58. rtconfig.DEVICE = build_core_options
  59. rtconfig.NUCLEI_SDK_OPENOCD_CFG = os.path.join(FRAMEWORK_DIR, \
  60. "SoC", build_soc, "Board", build_board, "openocd_{}.cfg".format(build_soc))
  61. if build_soc == "evalsoc":
  62. if build_download_mode not in supported_download_modes:
  63. # If build.download not defined for Eval SoC, use default "ILM"
  64. chosen_download_mode = "ilm" if len(supported_download_modes) == 0 else supported_download_modes[0]
  65. print("Download mode %s is not supported for SOC %s, use default download mode %s" \
  66. % (build_download_mode, build_soc, chosen_download_mode))
  67. build_download_mode = chosen_download_mode
  68. else:
  69. if build_download_mode not in supported_download_modes:
  70. chosen_download_mode = "flashxip" if len(supported_download_modes) == 0 else supported_download_modes[0]
  71. print("Download mode %s is not supported for SOC %s, use default download mode %s" \
  72. % (build_download_mode, build_soc, chosen_download_mode))
  73. build_download_mode = chosen_download_mode
  74. print("Supported downloaded modes for board %s are %s, chosen downloaded mode is %s" \
  75. % (build_board, supported_download_modes, build_download_mode))
  76. if not build_ldscript:
  77. ld_script = "gcc_%s_%s.ld" % (
  78. build_soc, build_download_mode) if build_download_mode else "gcc_%s.ld" % build_soc
  79. build_ldscript = os.path.join(
  80. FRAMEWORK_DIR, "SoC", build_soc, "Board", build_board, "Source", "GCC", ld_script)
  81. else:
  82. print("Use user defined ldscript %s" % build_ldscript)
  83. # Use correct downloaded modes
  84. DOWNLOAD_MODE = "DOWNLOAD_MODE_%s" % build_download_mode.upper()
  85. build_download_mode_upper = build_download_mode.upper()
  86. src = Glob(SoC_Common + '/Source/*.c')
  87. src += Glob(SoC_Common + '/Source/Drivers/*.c')
  88. src += Glob(SoC_Common + '/Source/Stubs/newlib/*.c')
  89. src += Glob(SoC_Common + '/Source/GCC/*.S')
  90. src += Glob(SoC_Board + '/Source/*.c')
  91. CPPPATH = [ cwd + '/NMSIS/Core/Include',
  92. cwd + '/' + SoC_Common + '/Include',
  93. cwd + '/' + SoC_Common + '/Source/Stubs/newlib',
  94. cwd + '/' + SoC_Board + '/Include']
  95. CPPDEFINES = [ '-DDOWNLOAD_MODE={}'.format(DOWNLOAD_MODE),
  96. '-DDOWNLOAD_MODE_STRING=\"{}\"'.format(build_download_mode_upper),
  97. '-DRTOS_RTTHREAD', '-DNUCLEI_BANNER=0' ]
  98. extra_flags = build_core_options
  99. extra_lflags = "{} -T {}".format(build_core_options, build_ldscript)
  100. group = DefineGroup('nuclei_n100_sdk', src, depend = [''], \
  101. CCFLAGS=extra_flags, ASFLAGS=extra_flags, LINKFLAGS=extra_lflags, \
  102. CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES, LIBPATH=LIBPATH)
  103. Return('group')