-
Notifications
You must be signed in to change notification settings - Fork 51
/
SConscript
160 lines (129 loc) · 6.62 KB
/
SConscript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# RT-Thread building script for component
Import('rtconfig')
Import('RTT_ROOT')
import os
import re
import rtconfig
from building import *
BUILTIN_ALL_DOWNLOADED_MODES = {
"gd32vf103": ("flashxip"),
"evalsoc": ("ilm", "flash", "flashxip", "ddr", "sram")
}
DEFAULT_DOWNLOAD_MODES = ("ilm", "flashxip", "ddr", "sram", "sramxip")
default_arch_abi = ("rv32imac", "ilp32")
cwd = GetCurrentDir()
FRAMEWORK_DIR = cwd
def parse_nuclei_soc_predefined_cores(core_mk):
if not os.path.isfile(core_mk):
return dict()
core_arch_abis = dict()
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*)')
with open(core_mk, "r") as core_mk_file:
for line in core_mk_file.readlines():
line = line.strip()
matches = core_arch_abi_re.match(line)
if matches:
core_lower = matches.groups()[0].lower()
core_arch_abis[core_lower] = (matches.groups()[1:3])
return core_arch_abis
NUCLEI_SOC_CORES_MK = os.path.join(cwd, "Build/Makefile.core")
core_arch_abis = parse_nuclei_soc_predefined_cores(NUCLEI_SOC_CORES_MK)
# Get configurations from rtconfig
build_soc = getattr(rtconfig, "NUCLEI_SDK_SOC").lower().strip()
build_board = getattr(rtconfig, "NUCLEI_SDK_BOARD").lower().strip()
build_download_mode = getattr(rtconfig, "NUCLEI_SDK_DOWNLOAD", "").lower().strip()
build_core = getattr(rtconfig, "NUCLEI_SDK_CORE", "").lower().strip()
build_march = getattr(rtconfig, "NUCLEI_SDK_RISCV_ARCH", "").lower().strip()
build_mabi = getattr(rtconfig, "NUCLEI_SDK_RISCV_ABI", "").lower().strip()
build_mcmodel = getattr(rtconfig, "NUCLEI_SDK_RISCV_MCMODEL", "medany").lower().strip()
build_ldscript = getattr(rtconfig, "NUCLEI_SDK_LDSCRIPT", "").lower().strip()
# Backward compatibility with previous Nuclei SDK releases
if build_soc == "hbird":
print("Warning! Since Nuclei SDK 0.3.1, SoC hbird is renamed to demosoc, please change NUCLEI_SDK_SOC to demosoc!")
build_soc = "demosoc"
if build_board == "hbird_eval":
print("Warning! Since Nuclei SDK 0.3.1, Board hbird_eval is renamed to nuclei_fpga_eval, please change NUCLEI_SDK_BOARD to nuclei_fpga_eval!")
build_board = "nuclei_fpga_eval"
if build_soc == "demosoc":
print("Warning! Since Nuclei SDK 0.5.0, SoC demosoc is removed, please change NUCLEI_SDK_SOC to evalsoc!")
build_soc = "evalsoc"
if not build_march and not build_mabi and build_core in core_arch_abis:
build_march, build_mabi = core_arch_abis[build_core]
else:
if not build_mabi or not build_march:
build_march, build_mabi = default_arch_abi
print("No mabi and march specified in rtconfig.py, use default -march=%s -mabi=%s!" % (build_march, build_mabi))
if build_soc in BUILTIN_ALL_DOWNLOADED_MODES:
supported_download_modes = BUILTIN_ALL_DOWNLOADED_MODES[build_soc]
else:
if os.path.isfile(os.path.join(cwd, build_soc, "build.mk")) == False:
print("SoC={} is not supported in Nuclei SDK".format(build_soc))
exit(0)
else:
supported_download_modes = DEFAULT_DOWNLOAD_MODES
SoC_Common = 'SoC/{}/Common'.format(build_soc)
SoC_Board = 'SoC/{}/Board/{}'.format(build_soc, build_board)
build_core_options = " -march=%s -mabi=%s -mcmodel=%s " % (build_march, build_mabi, build_mcmodel)
rtconfig.NUCLEI_SDK_OPENOCD_CFG = os.path.join(FRAMEWORK_DIR, \
"SoC", build_soc, "Board", build_board, "openocd_{}.cfg".format(build_soc))
if build_soc == "evalsoc":
if build_download_mode not in supported_download_modes:
# If build.download not defined for Eval SoC, use default "ILM"
chosen_download_mode = "ilm" if len(supported_download_modes) == 0 else supported_download_modes[0]
print("Download mode %s is not supported for SOC %s, use default download mode %s" \
% (build_download_mode, build_soc, chosen_download_mode))
build_download_mode = chosen_download_mode
else:
if build_download_mode not in supported_download_modes:
chosen_download_mode = "flashxip" if len(supported_download_modes) == 0 else supported_download_modes[0]
print("Download mode %s is not supported for SOC %s, use default download mode %s" \
% (build_download_mode, build_soc, chosen_download_mode))
build_download_mode = chosen_download_mode
print("Supported downloaded modes for board %s are %s, chosen downloaded mode is %s" \
% (build_board, supported_download_modes, build_download_mode))
if not build_ldscript:
ld_script = "gcc_%s_%s.ld" % (
build_soc, build_download_mode) if build_download_mode else "gcc_%s.ld" % build_soc
build_ldscript = os.path.join(
FRAMEWORK_DIR, "SoC", build_soc, "Board", build_board, "Source", "GCC", ld_script)
else:
print("Use user defined ldscript %s" % build_ldscript)
# Use correct downloaded modes
DOWNLOAD_MODE = "DOWNLOAD_MODE_%s" % build_download_mode.upper()
build_download_mode_upper = build_download_mode.upper()
src = Glob(SoC_Common + '/Source/*.c')
src += Glob(SoC_Common + '/Source/Drivers/*.c')
if build_soc == "gd32vf103":
src += Glob(SoC_Common + '/Source/Drivers/Usb/*.c')
src += Glob(SoC_Common + '/Source/Stubs/newlib/*.c')
src += Glob(SoC_Common + '/Source/GCC/*.S')
src += Glob(SoC_Board + '/Source/*.c')
CPPPATH = [ cwd + '/NMSIS/Core/Include',
cwd + '/NMSIS/DSP/Include',
cwd + '/NMSIS/DSP/PrivateInclude',
cwd + '/NMSIS/NN/Include',
cwd + '/' + SoC_Common + '/Include',
cwd + '/' + SoC_Common + '/Source/Stubs/newlib',
cwd + '/' + SoC_Board + '/Include']
LIBPATH = [ cwd + '/NMSIS/Library/DSP/GCC',
cwd + '/NMSIS/Library/NN/GCC' ]
if build_soc == "gd32vf103":
CPPPATH.append(cwd + '/' + SoC_Common + '/Include/Usb')
CPPDEFINES = [ '-DDOWNLOAD_MODE={}'.format(DOWNLOAD_MODE),
'-DDOWNLOAD_MODE_STRING=\"{}\"'.format(build_download_mode_upper),
'-DRTOS_RTTHREAD', '-DNUCLEI_BANNER=0' ]
# Flash download mode vector table need to remapped
if build_download_mode_upper == "FLASH":
CPPDEFINES.extend(['-DVECTOR_TABLE_REMAPPED'])
extra_flags = build_core_options
extra_lflags = "{} -T {}".format(build_core_options, build_ldscript)
# rtconfig.CFLAGS = "{} {}".format(build_core_options, rtconfig.CFLAGS)
# rtconfig.AFLAGS = "{} {}".format(build_core_options, rtconfig.AFLAGS)
# rtconfig.LFLAGS = "{} {} -T {}".format(build_core_options, rtconfig.LFLAGS, build_ldscript)
# print(rtconfig.CFLAGS)
# print(rtconfig.AFLAGS)
# print(rtconfig.LFLAGS)
group = DefineGroup('nuclei_sdk', src, depend = [''], \
CCFLAGS=extra_flags, ASFLAGS=extra_flags, LINKFLAGS=extra_lflags, \
CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES, LIBPATH=LIBPATH)
Return('group')