rtconfig.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import os
  2. import re
  3. ARCH = 'risc-v'
  4. CPU = 'c920v3'
  5. # toolchains options
  6. CROSS_TOOL = 'gcc'
  7. #------- toolchains path -------------------------------------------------------
  8. if os.getenv('RTT_CC'):
  9. CROSS_TOOL = os.getenv('RTT_CC')
  10. if CROSS_TOOL == 'gcc':
  11. PLATFORM = 'gcc'
  12. EXEC_PATH = r'D:\RT-ThreadStudio\repo\Extract\ToolChain_Support_Packages\RISC-V\XTGccElfNewlib\V3.0.1\R\bin'
  13. else:
  14. print('Please make sure your toolchains is GNU GCC!')
  15. exit(0)
  16. if os.getenv('RTT_EXEC_PATH'):
  17. EXEC_PATH = os.getenv('RTT_EXEC_PATH')
  18. BUILD = 'debug'
  19. #BUILD = 'release'
  20. CORE = 'risc-v'
  21. MAP_FILE = 'rtthread.map'
  22. LINK_FILE = '../../libraries/xuantie_libraries/chip_riscv_dummy/gcc_flash_xiaohui.ld'
  23. if os.path.exists('./libraries'):
  24. LINK_FILE = './libraries/xuantie_libraries/chip_riscv_dummy/gcc_flash_xiaohui.ld'
  25. TARGET_NAME = 'rtthread.bin'
  26. #------- GCC settings ----------------------------------------------------------
  27. if PLATFORM == 'gcc':
  28. # toolchains
  29. PREFIX = 'riscv64-unknown-elf-'
  30. CC = PREFIX + 'gcc'
  31. CXX= PREFIX + 'g++'
  32. AS = PREFIX + 'gcc'
  33. AR = PREFIX + 'ar'
  34. LINK = PREFIX + 'gcc'
  35. TARGET_EXT = 'elf'
  36. SIZE = PREFIX + 'size'
  37. OBJDUMP = PREFIX + 'objdump'
  38. OBJCPY = PREFIX + 'objcopy'
  39. MCPU = ' -mcpu=c920v3 ' # Modify here based on CPU architecture.
  40. MCPU_DEFINE = ' -DCONFIG_CPU_XUANTIE_C920V3=1 ' # Modify here based on CPU architecture.
  41. DEVICE = MCPU + MCPU_DEFINE + ' -Wno-main -mcmodel=medany -MP -MMD '
  42. GLOBAL_DEFINES = (
  43. ' -DCONFIG_KERNEL_RTTHREAD=1 '
  44. ' -D__RT_KERNEL_SOURCE__=1 '
  45. ' -DCONFIG_CSI_V2=1 '
  46. ' -DCONFIG_CSI="csi2" '
  47. ' -DCONFIG_XIP=1 '
  48. ' -DCONFIG_ARCH_MAINSTACK=8192 '
  49. ' -DCONFIG_ARCH_INTERRUPTSTACK=8192 '
  50. ' -DCONFIG_BOARD_XIAOHUI_EVB=1 '
  51. ' -DCLI_CONFIG_STACK_SIZE=8192 '
  52. ' -DCONFIG_PLIC_BASE=134217728 '
  53. ' -DCONFIG_VIC_TSPDR=201326592 '
  54. ' -DCONFIG_CLINT_BASE=201326592 '
  55. ' -DCONFIG_INTC_PLIC=1 '
  56. ' -DCONFIG_INIT_TASK_STACK_SIZE=8192 '
  57. ' -DCONFIG_APP_TASK_STACK_SIZE=8192 '
  58. ' -DCONFIG_DEBUG=1 '
  59. )
  60. GLOBAL_DEFINES += ' -DCONFIG_SYSTICK_HZ=RT_TICK_PER_SECOND '
  61. ################################################################################
  62. # check smp macro in rtconfig.h
  63. def read_rtconfig_macro(macro):
  64. try:
  65. with open('rtconfig.h', 'r') as f:
  66. for line in f:
  67. if re.search(r'#define\s+' + macro + r'\b', line):
  68. return True
  69. except FileNotFoundError:
  70. pass
  71. return False
  72. if read_rtconfig_macro('RT_USING_SMP'):
  73. GLOBAL_DEFINES += ' -DCONFIG_SMP=1 '
  74. GLOBAL_DEFINES += ' -DCONFIG_NR_CPUS=RT_CPUS_NR '
  75. ################################################################################
  76. CFLAGS = DEVICE + ' -c -Wno-unused-function -g -Wpointer-arith -Wno-undef -Wall -ffunction-sections -fdata-sections -fno-inline-functions \
  77. -fno-builtin -fno-strict-aliasing -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast' + GLOBAL_DEFINES
  78. AFLAGS = DEVICE + GLOBAL_DEFINES
  79. LFLAGS = DEVICE + ' -Wl,-zmax-page-size=1024 -Wl,-Map=' + MAP_FILE + ' -nostartfiles -Wl,--gc-sections '
  80. LFLAGS += ' -T ' + LINK_FILE
  81. CPATH = ''
  82. LPATH = ''
  83. if BUILD == 'debug':
  84. CFLAGS += ' -O0 -g3'
  85. AFLAGS += ' -g3'
  86. else:
  87. CFLAGS += ' -O2 -g2'
  88. CXXFLAGS = CFLAGS
  89. POST_ACTION = OBJCPY + ' -O binary $TARGET ' + TARGET_NAME + '\n'
  90. POST_ACTION += SIZE + ' $TARGET\n'
  91. def dist_handle(BSP_ROOT, dist_dir):
  92. import sys
  93. cwd_path = os.getcwd()
  94. sys.path.append(os.path.join(os.path.dirname(BSP_ROOT), '../tools'))
  95. from sdk_dist import dist_do_building
  96. dist_do_building(BSP_ROOT, dist_dir)