SConstruct 2.9 KB
Newer Older
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
import os
import sys
import rtconfig

if os.getenv('RTT_ROOT'):
    RTT_ROOT = os.getenv('RTT_ROOT')
else:
    RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')

sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *

TARGET = 'rtthread.' + rtconfig.TARGET_EXT

AddOption('--run',
        dest = 'run',
        type='string',
        nargs=1,
        action = 'store',
        default = "",
        help = 'Upload or debug application using openocd')

DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
    AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
G
guo 已提交
26
    CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
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
    CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
    AR = rtconfig.AR, ARFLAGS = '-rc', LIBS = rtconfig.LIBS,
    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env['ASCOM'] = env['ASPPCOM']

Export('RTT_ROOT')
Export('rtconfig')

SDK_ROOT = os.path.abspath('./')

if os.path.exists(SDK_ROOT + '/libraries'):
    libraries_path_prefix = SDK_ROOT + '/libraries'
else:
    libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries'

SDK_LIB = libraries_path_prefix
Export('SDK_LIB')

GDB = rtconfig.GDB

# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT)

bsp_library_type = rtconfig.NUCLEI_SDK_SOC
rtconfig.BSP_LIBRARY_TYPE = bsp_library_type

if hasattr(rtconfig, 'NUCLEI_SDK_OPENOCD_CFG'):
    openocd_cfg = rtconfig.NUCLEI_SDK_OPENOCD_CFG.replace('\\', '/')
else:
    print("ERROR: Nuclei SDK package is not yet downloaded, please execute <pkgs --update> in command line first!")
    exit(0)

# include hal drivers
hal_sconscript = os.path.join(libraries_path_prefix, bsp_library_type, 'HAL_Drivers', 'SConscript')

if os.path.isfile(hal_sconscript):
    objs.extend(SConscript(hal_sconscript))

# make a building
DoBuilding(TARGET, objs)

# Run upload or debug if --run=upload or --upload=debug
run_target = GetOption('run')
SUPPORT_RUN_TARGETS = ["upload", "debug"]
if run_target in SUPPORT_RUN_TARGETS:
    if os.path.isfile(TARGET):
        if run_target == "upload":
            upload_cmd = '{} {} -ex "set remotetimeout 240" \
                    -ex "target remote | openocd --pipe -f {}" \
                    --batch -ex "monitor halt" -ex "monitor flash protect 0 0 last off" -ex "load" \
78
                    -ex "monitor resume" -ex "quit"'.format(GDB, TARGET, openocd_cfg)
79 80 81 82 83 84 85 86 87 88 89 90
            print("Upload application {} using openocd and gdb".format(TARGET))
            print(upload_cmd)
            os.system(upload_cmd)
        elif run_target == "debug":
            debug_cmd = '{} {} -ex "set remotetimeout 240" \
                    -ex "target remote | openocd --pipe -f {}"'.format(GDB, TARGET, openocd_cfg)
            print("Debug application {} using openocd and gdb".format(TARGET))
            print(debug_cmd)
            os.system(debug_cmd)
    else:
        print(TARGET + ' not exist, please run scons first!!')
    exit(0)