modify building script for components.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@642 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong 2010-04-18 22:16:50 +00:00
parent 5562ddf77a
commit 99bfaf72d9
9 changed files with 379 additions and 40 deletions

View File

@ -1,5 +1,6 @@
Import('env')
Import('RTT_ROOT')
Import('projects')
# The set of source files associated with this SConscript file.
src_local = Split("""
@ -29,7 +30,20 @@ STM32F10x_StdPeriph_Driver/src/stm32f10x_can.c
STM32F10x_StdPeriph_Driver/src/misc.c
""")
path = [RTT_ROOT + '/bsp/stm3210/Libraries/STM32F10x_StdPeriph_Driver/inc', RTT_ROOT + '/bsp/stm3210/Libraries/CMSIS/Core/CM3']
path = [RTT_ROOT + '/bsp/stm3210/Libraries/STM32F10x_StdPeriph_Driver/inc',
RTT_ROOT + '/bsp/stm3210/Libraries/CMSIS/Core/CM3']
# group definitions
group = {}
group['name'] = 'STM32_StdPeriph'
group['CCFLAGS'] = ''
group['CPPPATH'] = path
group['CPPDEFINES'] = []
group['LINKFLAGS'] = ''
group['src'] = File(src_local)
# add group to project list
projects.append(group)
env.Append(CPPPATH = path)

41
bsp/stm3210/SConscript Normal file
View File

@ -0,0 +1,41 @@
Import('env')
Import('projects')
Import('RTT_ROOT')
Import('rtconfig')
# group definitions
group = {}
group['name'] = 'Startup'
group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/bsp/stm3210']
group['CPPDEFINES'] = ['USE_STDPERIPH_DRIVER', rtconfig.STM32_TYPE]
group['LINKFLAGS'] = ''
src_bsp = ['application.c', 'startup.c', 'board.c', 'stm32f10x_it.c']
src_drv = ['rtc.c', 'usart.c', 'led.c']
if rtconfig.RT_USING_DFS:
if rtconfig.STM32_TYPE == 'STM32F10X_HD':
src_drv += ['sdcard.c']
else:
src_drv += ['msd.c']
if rtconfig.RT_USING_LWIP:
if rtconfig.STM32_TYPE == 'STM32F10X_CL':
src_drv += ['stm32_eth.c']
else:
src_drv += ['enc28j60.c']
group['src'] = File(src_bsp + src_drv)
# add group to project list
projects.append(group)
env.Append(CCFLAGS = group['CCFLAGS'])
env.Append(CPPPATH = group['CPPPATH'])
env.Append(CPPDEFINES = group['CPPDEFINES'])
env.Append(LINKFLAGS = group['LINKFLAGS'])
obj = env.Object(group['src'])
Return('obj')

View File

@ -1,11 +1,13 @@
import os
import sys
import rtconfig
RTT_ROOT = os.path.normpath(os.getcwd() + '/../..')
target = 'rtthread-stm32'
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
import mdk
# search path for C compiler
bsp_path = RTT_ROOT + '/bsp/stm3210'
target = 'rtthread-stm32'
projects = []
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
@ -13,46 +15,28 @@ env = Environment(tools = ['mingw'],
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env.AppendUnique(CPPPATH = bsp_path)
env.AppendUnique(CCFLAGS = ' -DUSE_STDPERIPH_DRIVER -D' + rtconfig.STM32_TYPE)
Export('env')
Export('RTT_ROOT')
Export('rtconfig')
Export('projects')
# kernel building script
objs = SConscript(RTT_ROOT + '/src/SConscript', variant_dir='build/src', duplicate=0)
# arch building script
objs = objs + SConscript(RTT_ROOT + '/libcpu/SConscript', variant_dir='build/libcpu', duplicate=0)
# STM32 firemare library building script
objs = objs + SConscript(RTT_ROOT + '/bsp/stm3210/Libraries/SConscript', variant_dir='build/Libraries', duplicate=0)
if rtconfig.RT_USING_MINILIBC:
objs = objs + SConscript(RTT_ROOT + '/libc/minilibc/SConscript', variant_dir='build/minilibc', duplicate=0)
# component script
Repository(RTT_ROOT)
objs = objs + SConscript('components/SConscript')
if rtconfig.RT_USING_FINSH:
objs = objs + SConscript(RTT_ROOT + '/finsh/SConscript', variant_dir='build/finsh', duplicate=0)
if rtconfig.RT_USING_DFS:
objs = objs + SConscript(RTT_ROOT + '/filesystem/dfs/SConscript', variant_dir='build/filesystem', duplicate=0)
if rtconfig.RT_USING_LWIP:
objs = objs + SConscript(RTT_ROOT + '/net/lwip/SConscript', variant_dir='build/net/lwip', duplicate=0)
src_bsp = ['application.c', 'startup.c', 'board.c', 'stm32f10x_it.c']
src_drv = ['rtc.c', 'usart.c', 'led.c']
if rtconfig.RT_USING_DFS:
if rtconfig.STM32_TYPE == 'STM32F10X_HD':
src_drv += ['sdcard.c']
else:
src_drv += ['msd.c']
if rtconfig.RT_USING_LWIP:
if rtconfig.STM32_TYPE == 'STM32F10X_CL':
src_drv += ['stm32_eth.c']
else:
src_drv += ['enc28j60.c']
objs = objs + env.Object(src_bsp + src_drv)
# board build script
objs = objs + SConscript('SConscript', variant_dir='build/bsp', duplicate=0)
TARGET = target + '.' + rtconfig.TARGET_EXT
env.Program(TARGET, objs)
env.AddPostAction(TARGET, rtconfig.POST_ACTION)
mdk.MDKProject('project_2.uV2', projects)

View File

@ -45,7 +45,7 @@ if rtconfig_ns.has_key('RT_USING_RTGUI'):
# toolchains options
ARCH='arm'
CPU='stm32'
CROSS_TOOL='gcc'
CROSS_TOOL='keil'
if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
@ -111,8 +111,6 @@ elif PLATFORM == 'armcc':
CFLAGS += ' -O2'
RT_USING_MINILIBC = False
if RT_USING_FINSH:
LFLAGS += ' --keep __fsym_* --keep __vsym_*'
POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET'
elif PLATFORM == 'iar':

98
bsp/stm3210/template.Uv2 Normal file
View File

@ -0,0 +1,98 @@
### uVision2 Project, (C) Keil Software
### Do not modify !
Target (RT-Thread STM32), 0x0004 // Tools: 'ARM-ADS'
Options 1,0,0 // Target 'RT-Thread STM32'
Device (STM32F103ZE)
Vendor (STMicroelectronics)
Cpu (IRAM(0x20000000-0x2000FFFF) IROM(0x8000000-0x807FFFF) CLOCK(8000000) CPUTYPE("Cortex-M3"))
FlashUt ()
StupF ("STARTUP\ST\STM32F10x.s" ("STM32 Startup Code"))
FlashDR (UL2CM3(-O14 -S0 -C0 -N00("ARM Cortex-M3") -D00(1BA00477) -L00(4) -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F10x_512 -FS08000000 -FL080000))
DevID (4216)
Rgf (stm32f10x_lib.h)
Mem ()
C ()
A ()
RL ()
OH ()
DBC_IFX ()
DBC_CMS ()
DBC_AMS ()
DBC_LMS ()
UseEnv=0
EnvBin ()
EnvInc ()
EnvLib ()
EnvReg (ÿST\STM32F10x\)
OrgReg (ÿST\STM32F10x\)
TgStat=16
OutDir (.\)
OutName (rtthread-stm32)
GenApp=1
GenLib=0
GenHex=0
Debug=1
Browse=0
LstDir (.\)
HexSel=1
MG32K=0
TGMORE=0
RunUsr 0 0 <>
RunUsr 1 0 <>
BrunUsr 0 0 <>
BrunUsr 1 0 <>
CrunUsr 0 0 <>
CrunUsr 1 0 <>
SVCSID <>
GLFLAGS=1790
ADSFLGA { 243,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ACPUTYP ("Cortex-M3")
RVDEV ()
ADSTFLGA { 0,12,0,2,99,0,0,66,0,0,0,0,0,0,0,0,0,0,0,0 }
OCMADSOCM { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
OCMADSIRAM { 0,0,0,0,32,0,0,1,0 }
OCMADSIROM { 1,0,0,0,8,0,0,8,0 }
OCMADSXRAM { 0,0,0,0,0,0,0,0,0 }
OCR_RVCT { 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,8,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,1,0,0,0,0,0,0,0,0,0,0 }
RV_STAVEC ()
ADSCCFLG { 5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSCMISC ()
ADSCDEFN ()
ADSCUDEF ()
ADSCINCD ()
ADSASFLG { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSAMISC ()
ADSADEFN ()
ADSAUDEF ()
ADSAINCD ()
PropFld { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
IncBld=1
AlwaysBuild=0
GenAsm=0
AsmAsm=0
PublicsOnly=0
StopCode=3
CustArgs ()
LibMods ()
ADSLDFG { 17,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
ADSLDTA (0x08000000)
ADSLDDA (0x20000000)
ADSLDSC ()
ADSLDIB ()
ADSLDIC ()
ADSLDMC ()
ADSLDIF ()
ADSLDDW ()
OPTDL (SARMCM3.DLL)()(DARMSTM.DLL)(-pSTM32F103ZE)(SARMCM3.DLL)()(TARMSTM.DLL)(-pSTM32F103ZE)
OPTDBG 49142,7,()()()()()()()()()() (Segger\JL2CM3.dll)()()()
FLASH1 { 1,0,0,0,1,0,0,0,6,16,0,0,0,0,0,0,0,0,0,0 }
FLASH2 (Segger\JL2CM3.dll)
FLASH3 ("" ())
FLASH4 ()
EndOpt

View File

@ -1,6 +1,7 @@
Import('env')
Import('rtconfig')
Import('RTT_ROOT')
Import('projects')
comm = rtconfig.ARCH + '/common'
path = rtconfig.ARCH + '/' + rtconfig.CPU
@ -15,7 +16,19 @@ if rtconfig.PLATFORM == 'gcc':
if rtconfig.PLATFORM == 'iar':
src_local = Glob(path + '/*.c') + Glob(path + '/*_iar.S') + Glob(comm + '/*.c')
env.Append(CPPPATH = [RTT_ROOT + '/libcpu/' + rtconfig.ARCH + '/' + rtconfig.CPU])
obj = env.Object(src_local)
# group definitions
group = {}
group['name'] = rtconfig.CPU.upper()
group['src'] = File(src_local)
group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/libcpu/' + rtconfig.ARCH + '/' + rtconfig.CPU]
group['CPPDEFINES'] = ''
group['LINKFLAGS'] = ''
# add group to project list
projects.append(group)
env.Append(CPPPATH = group['CPPPATH'])
obj = env.Object(group['src'])
Return('obj')

View File

@ -17,6 +17,7 @@
#include "serial.h"
#include <stm32f10x_dma.h>
#include <stm32f10x_usart.h>
static void rt_serial_enable_dma(DMA_Channel_TypeDef* dma_channel,
rt_uint32_t address, rt_uint32_t size);

View File

@ -1,10 +1,23 @@
Import('env')
Import('RTT_ROOT')
Import('projects')
# The set of source files associated with this SConscript file.
src_local = Glob('*.c')
env.Append(CPPPATH = [RTT_ROOT + '/include'])
obj = env.Object(src_local)
# group definitions
group = {}
group['name'] = 'Kernel'
group['src'] = File(src_local)
group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/include']
group['CPPDEFINES'] = ''
group['LINKFLAGS'] = ''
# add group to project list
projects.append(group)
env.Append(CPPPATH = group['CPPPATH'])
obj = env.Object(group['src'])
Return('obj')

177
tools/mdk.py Normal file
View File

@ -0,0 +1,177 @@
import os
import string
import SCons.Script
def _get_filetype(fn):
if fn.rfind('.c') or fn.rfind('.C') or fn.rfind('.cpp'):
return 1
# assimble file type
if fn.rfind('.s') or fn.rfind('.S'):
return 2
# header type
if fn.rfind('.h'):
return 5
# other filetype
return 5
def splitall(loc):
"""
Return a list of the path components in loc. (Used by relpath_).
The first item in the list will be either ``os.curdir``, ``os.pardir``, empty,
or the root directory of loc (for example, ``/`` or ``C:\\).
The other items in the list will be strings.
Adapted from *path.py* by Jason Orendorff.
"""
parts = []
while loc != os.curdir and loc != os.pardir:
prev = loc
loc, child = os.path.split(prev)
if loc == prev:
break
parts.append(child)
parts.append(loc)
parts.reverse()
return parts
def _make_path_relative(origin, dest):
"""
Return the relative path between origin and dest.
If it's not possible return dest.
If they are identical return ``os.curdir``
Adapted from `path.py <http://www.jorendorff.com/articles/python/path/>`_ by Jason Orendorff.
"""
origin = os.path.abspath(origin).replace('\\', '/')
dest = os.path.abspath(dest).replace('\\', '/')
#
orig_list = splitall(os.path.normcase(origin))
# Don't normcase dest! We want to preserve the case.
dest_list = splitall(dest)
#
if orig_list[0] != os.path.normcase(dest_list[0]):
# Can't get here from there.
return dest
#
# Find the location where the two paths start to differ.
i = 0
for start_seg, dest_seg in zip(orig_list, dest_list):
if start_seg != os.path.normcase(dest_seg):
break
i += 1
#
# Now i is the point where the two paths diverge.
# Need a certain number of "os.pardir"s to work up
# from the origin to the point of divergence.
segments = [os.pardir] * (len(orig_list) - i)
# Need to add the diverging part of dest_list.
segments += dest_list[i:]
if len(segments) == 0:
# If they happen to be identical, use os.curdir.
return os.curdir
else:
# return os.path.join(*segments).replace('\\', '/')
return os.path.join(*segments)
def MDKProject(target, script):
template = file('template.uV2', "rb")
lines = template.readlines()
project = file(target, "wb")
project_path = os.path.dirname(os.path.abspath(target))
line_index = 5
# write group
for group in script:
lines.insert(line_index, 'Group (%s)\r\n' % group['name'])
line_index += 1
lines.insert(line_index, '\r\n')
line_index += 1
# write file
CPPPATH = []
CPPDEFINES = []
LINKFLAGS = ''
CCFLAGS = ''
# number of groups
group_index = 1
for group in script:
print group['name']
# get each include path
if group.has_key('CPPPATH') and group['CPPPATH']:
if CPPPATH:
CPPPATH += group['CPPPATH']
else:
CPPPATH += group['CPPPATH']
# get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if CPPDEFINES:
CPPDEFINES += ';' + group['CPPDEFINES']
else:
CPPDEFINES += group['CPPDEFINES']
# get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS']
else:
LINKFLAGS += group['LINKFLAGS']
# generate file items
for node in group['src']:
fn = node.rfile()
name = fn.name
path = os.path.dirname(fn.abspath)
path = _make_path_relative(project_path, path)
path = os.path.join(path, name)
lines.insert(line_index, 'File %d,%d<%s><%s>\r\n'
% (group_index, _get_filetype(name), path, name))
line_index += 1
group_index = group_index + 1
lines.insert(line_index, '\r\n')
line_index += 1
# remove repeat path
paths = set()
for path in CPPPATH:
inc = _make_path_relative(project_path, os.path.normpath(path))
paths.add(inc) #.replace('\\', '/')
paths = [i for i in paths]
CPPPATH = string.join(paths, ';')
definitions = [i for i in set(CPPDEFINES)]
CPPDEFINES = string.join(definitions, ', ')
while line_index < len(lines):
if lines[line_index].startswith(' ADSCINCD '):
lines[line_index] = ' ADSCINCD (' + CPPPATH + ')\r\n'
if lines[line_index].startswith(' ADSLDMC ('):
lines[line_index] = ' ADSLDMC (' + LINKFLAGS + ')\r\n'
if lines[line_index].startswith(' ADSCDEFN ('):
lines[line_index] = ' ADSCDEFN (' + CPPDEFINES + ')\r\n'
line_index += 1
# write project
for line in lines:
project.write(line)
project.close()