Skip to content

Commit

Permalink
Merge pull request openwsn-berkeley#1 from malishav/security_154
Browse files Browse the repository at this point in the history
Some additions/changes to the code.
  • Loading branch information
ssciancalepore committed May 24, 2015
2 parents 60969e6 + 0bb4f12 commit 3c9c962
Show file tree
Hide file tree
Showing 111 changed files with 6,286 additions and 893 deletions.
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@ settings
*.a
*.pyd
*.pyc
path.txt
/build
/.sconsign.dblite
/firmware/openos/bsp/boards/python/*.def
.directory
/firmware/openos/projects/common/03oos_openwsn_prog
/firmware/openos/projects/common/03oos_openwsn/03oos_openwsn_obj.*
/firmware/openos/projects/common/oos_openwsn.*
/firmware/openos/bsp/boards/python/openwsnmodule_obj.c
/firmware/openos/bsp/boards/python/openwsnmodule_obj.os
/firmware/openos/projects/python_vs13/oos_openwsn.sdf
*.map
*.lst
/firmware/openos/projects/wsn430v14/03oos_mercator/*.ewd
*~
177 changes: 144 additions & 33 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ if env['noadaptivesync']==1:
env.Append(CPPDEFINES = 'NOADAPTIVESYNC')
if env['cryptoengine']:
env.Append(CPPDEFINES = {'CRYPTO_ENGINE_SCONS' : env['cryptoengine']})
if env['l2_security']==1:
env.Append(CPPDEFINES = 'L2_SECURITY_ACTIVE')

if env['toolchain']=='mspgcc':

Expand Down Expand Up @@ -230,7 +232,7 @@ elif env['toolchain']=='armgcc':

elif env['board'] in ['iot-lab_M3', 'iot-lab_A8-M3']:

# compiler (C)
# compiler (C)
env.Replace(CC = 'arm-none-eabi-gcc')
if os.name=='nt':
env.Append(CCFLAGS = '-DHSE_VALUE=((uint32_t)16000000)')
Expand Down Expand Up @@ -307,6 +309,9 @@ elif env['toolchain']=='armgcc':

elif env['toolchain']=='gcc':

# compiler (C)
env.Append(CCFLAGS = '-Wall')

if env['board'] not in ['python']:
raise SystemError('toolchain {0} can not be used for board {1}'.format(env['toolchain'],env['board']))

Expand Down Expand Up @@ -432,6 +437,95 @@ def telosb_bootload(target, source, env):
for t in bootloadThreads:
countingSem.acquire()

class OpenMoteCC2538_bootloadThread(threading.Thread):
def __init__(self,comPort,hexFile,countingSem):

# store params
self.comPort = comPort
self.hexFile = hexFile
self.countingSem = countingSem

# initialize parent class
threading.Thread.__init__(self)
self.name = 'OpenMoteCC2538_bootloadThread_{0}'.format(self.comPort)

def run(self):
print 'starting bootloading on {0}'.format(self.comPort)
subprocess.call(
'python '+os.path.join('bootloader','OpenMote-CC2538','cc2538-bsl.py')+' -e -w -b 115200 -p {0} --bsl {1}'.format(self.comPort,self.hexFile),
shell=True
)
print 'done bootloading on {0}'.format(self.comPort)

# indicate done
self.countingSem.release()

def OpenMoteCC2538_bootload(target, source, env):
bootloadThreads = []
countingSem = threading.Semaphore(0)
# create threads
for comPort in env['bootload'].split(','):
bootloadThreads += [
OpenMoteCC2538_bootloadThread(
comPort = comPort,
#hexFile = os.path.split(source[0].path)[1].split('.')[0]+'.bin',
hexFile = source[0].path.split('.')[0]+'.bin',
countingSem = countingSem,
)
]
# start threads
for t in bootloadThreads:
t.start()
# wait for threads to finish
for t in bootloadThreads:
countingSem.acquire()

class IotLabM3_bootloadThread(threading.Thread):
def __init__(self,comPort,binaryFile,countingSem):

# store params
self.comPort = comPort
self.binaryFile = binaryFile
self.countingSem = countingSem

# initialize parent class
threading.Thread.__init__(self)
self.name = 'IotLabM3_bootloadThread_{0}'.format(self.comPort)

def run(self):
print 'starting bootloading on {0}'.format(self.comPort)
subprocess.call(
'python '+ os.path.join('bootloader','iot-lab_M3','iotlab-m3-bsl.py' + ' -i {0} -p {1}'.format(self.binaryFile, self.comPort)),
shell=True
)
print 'done bootloading on {0}'.format(self.comPort)

# indicate done
self.countingSem.release()

def IotLabM3_bootload(target, source, env):
bootloadThreads = []
countingSem = threading.Semaphore(0)
# create threads
for comPort in env['bootload'].split(','):
if os.name=='nt':
suffix = '.exe'
else:
suffix = ''
bootloadThreads += [
IotLabM3_bootloadThread(
comPort = comPort,
binaryFile = source[0].path.split('.')[0]+suffix,
countingSem = countingSem,
)
]
# start threads
for t in bootloadThreads:
t.start()
# wait for threads to finish
for t in bootloadThreads:
countingSem.acquire()

# bootload
def BootloadFunc():
if env['board']=='telosb':
Expand All @@ -440,6 +534,18 @@ def BootloadFunc():
suffix = '.phonyupload',
src_suffix = '.ihex',
)
elif env['board']=='OpenMote-CC2538':
return Builder(
action = OpenMoteCC2538_bootload,
suffix = '.phonyupload',
src_suffix = '.bin',
)
elif env['board']=='iot-lab_M3':
return Builder(
action = IotLabM3_bootload,
suffix = '.phonyupload',
src_suffix = ''
)
else:
raise SystemError('bootloading on board={0} unsupported.'.format(env['board']))
if env['bootload']:
Expand Down Expand Up @@ -504,39 +610,43 @@ def sconscript_scanner(localEnv):
- projects\common\
- projects\<board>\
'''

# list subdirectories
subdirs = [name for name in os.listdir('.') if os.path.isdir(os.path.join('.', name)) ]
PATH_TO_PROJECTS = os.path.join('..','..','..','..','projects',os.path.split(os.getcwd())[-1])
allsubdirs = os.listdir(os.path.join(PATH_TO_PROJECTS))
subdirs = [name for name in allsubdirs if os.path.isdir(os.path.join(PATH_TO_PROJECTS,name)) ]

# parse dirs and build targets
for projectDir in subdirs:

src_dir = os.path.join(os.getcwd(),projectDir)
variant_dir = os.path.join(env['VARDIR'],'projects',projectDir),
src_dir = os.path.join(PATH_TO_PROJECTS,projectDir)
variant_dir = os.path.join(env['VARDIR'],'projects',projectDir)

added = False
targetName = projectDir[2:]
added = False
targetName = projectDir[2:]

if (
('{0}.c'.format(projectDir) in os.listdir(projectDir)) and
if (
('{0}.c'.format(projectDir) in os.listdir(os.path.join(PATH_TO_PROJECTS,projectDir))) and
(localEnv['toolchain']!='iar-proj') and
(localEnv['board']!='python')
):
):

localEnv.VariantDir(
variant_dir = variant_dir,
src_dir = src_dir,
duplicate = 0,
variant_dir = variant_dir,
)

target = projectDir
source = [os.path.join(projectDir,'{0}.c'.format(projectDir))]
source = [
os.path.join(projectDir,'{0}.c'.format(projectDir)),
]
libs = buildLibs(projectDir)

buildIncludePath(projectDir,localEnv)

# In Linux, you cannot have the same target name as the name of the
# directory name.
target=target+"_prog"
target = target+"_prog"

exe = localEnv.Program(
target = target,
Expand All @@ -549,26 +659,33 @@ def sconscript_scanner(localEnv):
added = True

elif (
('{0}.c'.format(projectDir) in os.listdir(projectDir)) and
('{0}.c'.format(projectDir) in os.listdir(os.path.join(PATH_TO_PROJECTS,projectDir))) and
(localEnv['board']=='python')
):
):

# build the artifacts in a separate directory
localEnv.VariantDir(
variant_dir = variant_dir,
src_dir = src_dir,
duplicate = 1,
variant_dir = variant_dir,
)

# build both the application's and the Python module's main files
sources_c = [
os.path.join(projectDir,'{0}.c'.format(projectDir)),
os.path.join('#','bsp','boards','python','openwsnmodule.c'),
os.path.join(projectDir,'openwsnmodule.c'),
]

localEnv.Command(
os.path.join(projectDir,'openwsnmodule.c'),
os.path.join('#','bsp','boards','python','openwsnmodule.c'),
[
Copy('$TARGET', '$SOURCE')
]
)

# objectify those two files
for s in sources_c:
temp = localEnv.Objectify(
localEnv.Objectify(
target = localEnv.ObjectifiedFilename(s),
source = s,
)
Expand Down Expand Up @@ -611,14 +728,13 @@ def sconscript_scanner(localEnv):
added = True

elif (
('{0}.ewp'.format(projectDir) in os.listdir(projectDir)) and
('{0}.ewp'.format(projectDir) in os.listdir(os.path.join(PATH_TO_PROJECTS,projectDir))) and
(localEnv['toolchain']=='iar-proj')
):

VariantDir(
variant_dir = variant_dir,
src_dir = src_dir,
duplicate = 0,
variant_dir = variant_dir,
)

source = [os.path.join(projectDir,'{0}.ewp'.format(projectDir))]
Expand Down Expand Up @@ -650,7 +766,6 @@ buildEnv.SConscript(
os.path.join(incDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = incVarDir,
duplicate = 0,
)

# bsp
Expand All @@ -661,7 +776,6 @@ buildEnv.SConscript(
os.path.join(bspDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = bspVarDir,
duplicate = 0,
)
buildEnv.Clean('libbsp', Dir(bspVarDir).abspath)
buildEnv.Append(LIBPATH = [bspVarDir])
Expand All @@ -673,7 +787,6 @@ buildEnv.SConscript(
os.path.join(kernelHDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = kernelHVarDir,
duplicate = 0,
)

# kernel
Expand All @@ -683,7 +796,6 @@ buildEnv.SConscript(
os.path.join(kernelDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = kernelVarDir,
duplicate = 0,
)
buildEnv.Clean('libkernel', Dir(kernelVarDir).abspath)
buildEnv.Append(LIBPATH = [kernelVarDir])
Expand All @@ -695,7 +807,6 @@ buildEnv.SConscript(
os.path.join(driversDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = driversVarDir,
duplicate = 0,
)
buildEnv.Clean('libdrivers', Dir(driversVarDir).abspath)
buildEnv.Append(LIBPATH = [driversVarDir])
Expand All @@ -707,7 +818,6 @@ buildEnv.SConscript(
os.path.join(openstackDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = openstackVarDir,
duplicate = 0,
)
buildEnv.Clean('libopenstack', Dir(openstackVarDir).abspath)
buildEnv.Append(LIBPATH = [openstackVarDir])
Expand All @@ -719,14 +829,15 @@ buildEnv.SConscript(
os.path.join(openappsDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = openappsVarDir,
duplicate = 0,
)
buildEnv.Clean('libopenapps', Dir(openappsVarDir).abspath)
buildEnv.Append(LIBPATH = [openappsVarDir])

# projects
projectsDir = os.path.join('#','projects')
projectsVarDir = os.path.join(buildEnv['VARDIR'],'projects')
buildEnv.SConscript(
os.path.join('#','projects','SConscript'),
exports = {'env': buildEnv},
#variant_dir = os.path.join(env['VARDIR'],'projects'),
os.path.join(projectsDir,'SConscript'),
exports = {'env': buildEnv},
variant_dir = projectsVarDir,
)
17 changes: 13 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ project:
cryptoengine Select appropriate crypto engine implementation
(dummy_crypto_engine, firmware_crypto_engine,
board_crypto_engine).
l2_security Use hop-by-hop encryption and authentication.
Common variables:
verbose Print each complete compile/link command.
Expand Down Expand Up @@ -132,6 +133,7 @@ command_line_options = {
'debug': ['0','1'],
'noadaptivesync': ['0','1'],
'cryptoengine': ['', 'dummy_crypto_engine', 'firmware_crypto_engine', 'board_crypto_engine'],
'l2_security': ['0','1']
}

def validate_option(key, value, env):
Expand Down Expand Up @@ -269,6 +271,13 @@ command_line_vars.AddVariables(
validate_option, # validator
int, # converter
),
(
'l2_security', # key
'', # help
command_line_options['l2_security'][0], # default
validate_option, # validator
int, # converter
),
(
'apps', # key
'comma-separated list of user applications', # help
Expand Down Expand Up @@ -305,11 +314,11 @@ Default(env.Command('default', None, default))
#============================ verbose =========================================

if not env['verbose']:
env[ 'CCCOMSTR'] = "Compiling $TARGET"
env[ 'CCCOMSTR'] = "Compiling $TARGET"
env[ 'SHCCCOMSTR'] = "Compiling (shared) $TARGET"
env[ 'ARCOMSTR'] = "Archiving $TARGET"
env['RANLIBCOMSTR'] = "Indexing $TARGET"
env[ 'LINKCOMSTR'] = "Linking $TARGET"
env[ 'ARCOMSTR'] = "Archiving $TARGET"
env['RANLIBCOMSTR'] = "Indexing $TARGET"
env[ 'LINKCOMSTR'] = "Linking $TARGET"
env['SHLINKCOMSTR'] = "Linking (shared) $TARGET"

#============================ load SConscript's ===============================
Expand Down
5 changes: 5 additions & 0 deletions bootloader/OpenMote-CC2538/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This bootloader comes from https://github.com/OpenMote/cc2538-bsl.

This code is owned by the OpenMote team and is put here for ease of use only.

We deeply thank the OpenMote team for making this code available.
Loading

0 comments on commit 3c9c962

Please sign in to comment.