1import os
2
3# toolchains options
4ARCH        ='risc-v'
5CPU         ='e24'
6CROSS_TOOL  ='gcc'
7
8if os.getenv('RTT_ROOT'):
9    RTT_ROOT = os.getenv('RTT_ROOT')
10else:
11    RTT_ROOT = r'../../..'
12
13if os.getenv('RTT_CC'):
14    CROSS_TOOL = os.getenv('RTT_CC')
15
16if  CROSS_TOOL == 'gcc':
17    PLATFORM    = 'gcc'
18    EXEC_PATH   = r'/opt/toolchain_riscv_sifive_linux/bin'
19else:
20    print('Please make sure your toolchains is GNU GCC!')
21    exit(0)
22
23if os.getenv('RTT_EXEC_PATH'):
24    EXEC_PATH = os.getenv('RTT_EXEC_PATH')
25
26BUILD = 'debug'
27
28if PLATFORM == 'gcc':
29    # toolchains
30    PREFIX  = 'riscv64-unknown-elf-'
31    CC      = PREFIX + 'gcc'
32    CXX     = PREFIX + 'g++'
33    AS      = PREFIX + 'gcc'
34    AR      = PREFIX + 'ar'
35    LINK    = PREFIX + 'gcc'
36    TARGET_EXT = 'elf'
37    SIZE    = PREFIX + 'size'
38    OBJDUMP = PREFIX + 'objdump'
39    OBJCPY  = PREFIX + 'objcopy'
40
41    DEVICE  = ' -march=rv32imafc -mabi=ilp32f'
42    CFLAGS  = DEVICE + ' -std=gnu99 -fno-jump-tables -fno-common -fms-extensions -ffunction-sections -fdata-sections -fmessage-length=0 -Wall -Wchar-subscripts -Wformat -Wundef -Wuninitialized -Winit-self -Wignored-qualifiers'
43    CFLAGS += ' -fstrict-volatile-bitfields -fshort-enums -Wno-error=unused-variable -Wno-error=format= -Wno-error=unused-function -Wno-error=implicit-function-declaration -Wno-error=deprecated-declarations -Wno-format'
44
45    LINKER_SCRIPTS = r'board/linker_scripts/bl602_flash.ld'
46
47    AFLAGS  = ' -c' + DEVICE + ' -x assembler-with-cpp'
48    LFLAGS  = DEVICE + ' -nostartfiles -ufw_header -fms-extensions -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T ' + LINKER_SCRIPTS
49    CPATH   = ''
50    LPATH   = ''
51
52    if BUILD == 'debug':
53        CFLAGS += ' -O2 -g3'
54        AFLAGS += ' -g3'
55    else:
56        CFLAGS += ' -O3'
57
58    CXXFLAGS = CFLAGS + ' -std=gnu++17 -Wno-multichar'
59
60DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n'
61POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'
62POST_ACTION += 'sh combine.sh bl602 ./rtthread.bin\n'