summaryrefslogtreecommitdiff
path: root/bsp/xuantie/xiaohui/r920/rtconfig.py
blob: b0959fd445fb21b6fa8d78fe1dc52d36f9f84bd6 (plain)
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
import os
import re
ARCH     = 'risc-v'
CPU      = 'r920'
# toolchains options
CROSS_TOOL  = 'gcc'

#------- toolchains path -------------------------------------------------------
if os.getenv('RTT_CC'):
    CROSS_TOOL = os.getenv('RTT_CC')

if  CROSS_TOOL == 'gcc':
    PLATFORM    = 'gcc'
    EXEC_PATH   = r'D:\RT-ThreadStudio\repo\Extract\ToolChain_Support_Packages\RISC-V\XTGccElfNewlib\V3.0.1\R\bin'
else:
    print('Please make sure your toolchains is GNU GCC!')
    exit(0)
    
if os.getenv('RTT_EXEC_PATH'):
    EXEC_PATH = os.getenv('RTT_EXEC_PATH')

BUILD = 'debug'
#BUILD = 'release'

CORE = 'risc-v'
MAP_FILE = 'rtthread.map'
LINK_FILE = '../../libraries/xuantie_libraries/chip_riscv_dummy/gcc_flash_xiaohui.ld'
if os.path.exists('./libraries'):
    LINK_FILE = './libraries/xuantie_libraries/chip_riscv_dummy/gcc_flash_xiaohui.ld'
TARGET_NAME = 'rtthread.bin'

#------- GCC settings ----------------------------------------------------------
if PLATFORM == 'gcc':
    # toolchains
    PREFIX = 'riscv64-unknown-elf-'
    CC = PREFIX + 'gcc'
    CXX= PREFIX + 'g++'
    AS = PREFIX + 'gcc'
    AR = PREFIX + 'ar'
    LINK = PREFIX + 'gcc'
    TARGET_EXT = 'elf'
    SIZE = PREFIX + 'size'
    OBJDUMP = PREFIX + 'objdump'
    OBJCPY = PREFIX + 'objcopy'
    
    MCPU = ' -mcpu=r920 ' # Modify here based on CPU architecture.
    MCPU_DEFINE = ' -DCONFIG_CPU_XUANTIE_R920=1 ' # Modify here based on CPU architecture.
    DEVICE = MCPU + MCPU_DEFINE + ' -Wno-main -mcmodel=medany -MP -MMD '

    GLOBAL_DEFINES = (
        ' -DCONFIG_KERNEL_RTTHREAD=1 '
        ' -D__RT_KERNEL_SOURCE__=1 '
        ' -DCONFIG_CSI_V2=1 '
        ' -DCONFIG_CSI="csi2" '
        ' -DCONFIG_XIP=1 '
        ' -DCONFIG_ARCH_MAINSTACK=8192 '
        ' -DCONFIG_ARCH_INTERRUPTSTACK=8192 '
        ' -DCONFIG_BOARD_XIAOHUI_EVB=1 '
        ' -DCLI_CONFIG_STACK_SIZE=8192 '
        ' -DCONFIG_PLIC_BASE=134217728 '
        ' -DCONFIG_VIC_TSPDR=201326592 '
        ' -DCONFIG_CLINT_BASE=201326592 '
        ' -DCONFIG_INTC_PLIC=1 '
        ' -DCONFIG_INIT_TASK_STACK_SIZE=8192 '
        ' -DCONFIG_APP_TASK_STACK_SIZE=8192 '
        ' -DCONFIG_DEBUG=1 '
    )

    GLOBAL_DEFINES += ' -DCONFIG_SYSTICK_HZ=RT_TICK_PER_SECOND '
    ################################################################################
    # check smp macro in rtconfig.h
    def read_rtconfig_macro(macro):
        try:
            with open('rtconfig.h', 'r') as f:
                for line in f:
                    if re.search(r'#define\s+' + macro + r'\b', line):
                        return True
        except FileNotFoundError:
            pass
        return False

    if read_rtconfig_macro('RT_USING_SMP'):
        GLOBAL_DEFINES += ' -DCONFIG_SMP=1 '
    GLOBAL_DEFINES += ' -DCONFIG_NR_CPUS=RT_CPUS_NR '
    ################################################################################

    CFLAGS = DEVICE + ' -c -Wno-unused-function -g -Wpointer-arith -Wno-undef -Wall -ffunction-sections -fdata-sections -fno-inline-functions \
                        -fno-builtin -fno-strict-aliasing -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast' + GLOBAL_DEFINES

    AFLAGS = DEVICE + GLOBAL_DEFINES
    
    LFLAGS = DEVICE + ' -Wl,-zmax-page-size=1024 -Wl,-Map=' + MAP_FILE + ' -nostartfiles -Wl,--gc-sections '
    LFLAGS += ' -T ' + LINK_FILE
    
    CPATH = ''
    LPATH = ''

    if BUILD == 'debug':
        CFLAGS += ' -O0 -g3'
        AFLAGS += ' -g3'
    else:
        CFLAGS += ' -O2 -g2'

    CXXFLAGS = CFLAGS

    POST_ACTION = OBJCPY + ' -O binary $TARGET ' + TARGET_NAME + '\n'
    POST_ACTION += SIZE + ' $TARGET\n'

def dist_handle(BSP_ROOT, dist_dir):
    import sys
    cwd_path = os.getcwd()
    sys.path.append(os.path.join(os.path.dirname(BSP_ROOT), '../tools'))
    from sdk_dist import dist_do_building
    dist_do_building(BSP_ROOT, dist_dir)