X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=tools%2Ftinyos%2Fmisc%2Ftos-storage-at45db.in;h=614c4107cd3f9dcdd18ee4554eaa6482324cf36b;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hp=0bf9ad2a6f18d440ce5dc9419850287f9cd0bfa6;hpb=1ba974b83d19fc41bf80acd52726f36f7f1df297;p=tinyos-2.x.git diff --git a/tools/tinyos/misc/tos-storage-at45db.in b/tools/tinyos/misc/tos-storage-at45db.in index 0bf9ad2a..614c4107 100644 --- a/tools/tinyos/misc/tos-storage-at45db.in +++ b/tools/tinyos/misc/tos-storage-at45db.in @@ -1,5 +1,5 @@ #!@pathpython@ -# Copyright (c) 2006 Intel Corporation +# Copyright (c) 2006-2007 Intel Corporation # All rights reserved. # # This file is distributed under the terms in the attached INTEL-LICENSE @@ -11,18 +11,53 @@ from xml.dom import * from xml.dom.minidom import * from re import match from sys import * +from subprocess import Popen, PIPE +from getopt import * +import string +import commands +#New way of handling arguments........ +try: + opts, args = getopt(argv[1:], "ts:f:", []) +except GetoptError, err: + print str(err) # will print something like "option -a not recognized" + stderr.write("Usage: tos-storage-at45db [-t] [-s ] [-f ] \n") + sector_size = 256 flash_size = 2048 # in sectors -volumes = {} -volmap = [] +cthreads = False +for o, a in opts: + if o == "-t": + cthreads = True + elif o == "-s": + sector_size = int(a) + elif o == "-f": + flash_size = int(a) + else: + assert False, "unhandled option" + +if len( args ) == 1: + platformdir = args[0] + # This gives the whole string when there's no / in platformdir + platform = platformdir[platformdir.rfind( "/" ) + 1:] +elif len( args ) == 0: + platformdir = "" + platform = "" +else: + stderr.write("Usage: tos-storage-at45db [-t] \n") # print an error message and exit def nfail(s): stderr.write(s + "\n") exit(2) +volumes = {} +volmap = [] +volumeNames = [] +volumeTypes = dict() +volumeOptions = dict() + def check_volume(name, base, size): if base == "": base = None @@ -76,20 +111,73 @@ def allocate(name, size): base = vbase + vsize volmap.append((name, base, size)) -try: - dom = parse(stdin) -except xml.parsers.expat.ExpatError: - nfail("no valid input") - -for volume in dom.documentElement.getElementsByTagName("volume"): - name = volume.getAttribute("name") - size = volume.getAttribute("size") - base = volume.getAttribute("base") - if name == None: - nfail("name omitted in volume") - if size == None: - nfail("size omitted in volume %s" % name) - check_volume(name, base, size) +def expand_path(path): + substrs = path.split("%") + path = substrs[0] + i = 1 + while i < len(substrs): + if substrs[i] == "": + # There was a %%, leading to a blank substring, and the next string + # should just be appended + path += "%" + i = i + 1 + if i < len(substrs): + path += substrs[i] + else: + # The first character of the string is the one that followed % + c = substrs[i][0] + if c == 'p': + sub = platform + elif c == 'P': + sub = platformdir + elif c == 'T': + sub = Popen(["ncc", "-print-tosdir"], stdout=PIPE).communicate()[0] + sub = sub[:-1] # remove newline + else: + nfail("unknown include-path substitution character " + c) + path += sub + path += substrs[i][1:] + i = i + 1 + return path + +def volumeparse(file, fname, depth): + if depth > 10: + nfail("include nesting too deep - check for cycles") + try: + dom = parse(file) + except xml.parsers.expat.ExpatError: + nfail(fname + " is not a valid input file") + except IOError: + nfail("couldn't open file " + fname) + + for volume in dom.documentElement.getElementsByTagName("volume"): + name = volume.getAttribute("name") + size = volume.getAttribute("size") + base = volume.getAttribute("base") + type = string.lower(volume.getAttribute("type")) + isCircular = string.upper(volume.getAttribute("circular")) + if isCircular == "": + isCircular = "FALSE" + if name == None: + nfail("name omitted in volume " + fname) + if size == None: + nfail("size omitted in volume %s %s" % (name, fname)) + check_volume(name, base, size) + + volumeNames.append( "VOLUME_" + name ) + volumeTypes["VOLUME_" + name] = type + volumeOptions["VOLUME_" + name] = isCircular + + for include in dom.documentElement.getElementsByTagName("include"): + included = include.firstChild + if included != None and included.nodeType == included.TEXT_NODE: + included = expand_path(included.data) + volumeparse(included, "(file %s)" % included, depth + 1) + else: + nfail("invalid include directive " + fname) + dom.unlink() + +volumeparse(stdin, "(standard input)", 0) # allocate fixed-address volumes for name in volumes.keys(): @@ -134,3 +222,49 @@ for (vname, vbase, vsize) in volmap: print "#undef VB" print "#endif" +# output nc file for threads +if cthreads == True: + outFile = open(commands.getstatusoutput("pwd")[1] + "/VolumeMapC.nc", "w") + outFile.write("#include \"StorageVolumes.h\" \n") + outFile.write("\n") + outFile.write("configuration VolumeMapC { \n") + outFile.write(" provides { \n") + outFile.write(" interface BlockRead[uint8_t volume_id]; \n") + outFile.write(" interface BlockWrite[uint8_t volume_id]; \n") + outFile.write(" interface LogRead[uint8_t volumeId]; \n") + outFile.write(" interface LogWrite[uint8_t volumeId]; \n") + outFile.write(" interface Mount[uint8_t volumeId]; \n") + outFile.write(" interface ConfigStorage[uint8_t volumeId]; \n") + outFile.write(" } \n") + outFile.write("} \n") + outFile.write("\n") + outFile.write("implementation { \n") + outFile.write(" components VolumeMapP; \n") + outFile.write("\n") + outFile.write(" BlockRead = VolumeMapP; \n") + outFile.write(" BlockWrite = VolumeMapP; \n") + outFile.write(" LogRead = VolumeMapP; \n") + outFile.write(" LogWrite = VolumeMapP; \n") + outFile.write(" Mount = VolumeMapP; \n") + outFile.write(" ConfigStorage = VolumeMapP; \n") + + for i in range(len(volumeNames)): + if volumeTypes[volumeNames[i]] == "block": + outFile.write("\n") + outFile.write(" components new BlockStorageC(" + volumeNames[i] + ") as BlockStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubBlockRead[" + volumeNames[i] + "] -> BlockStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubBlockWrite[" + volumeNames[i] + "] -> BlockStorageC_" + volumeNames[i] + "; \n") + outFile.write("\n") + + elif volumeTypes[volumeNames[i]] == "log": + outFile.write("\n") + outFile.write(" components new LogStorageC(" + volumeNames[i] + ", " + volumeOptions[volumeNames[i]] + ") as LogStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubLogRead[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") + outFile.write(" VolumeMapP.SubLogWrite[" + volumeNames[i] + "] -> LogStorageC_" + volumeNames[i] + "; \n") + outFile.write("\n") + + elif volumeTypes[volumeNames[i]] == "config": + outFile.write(" components new ConfigStorageC(" + volumeNames[i] + ") as ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" Mount[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write(" ConfigStorage[" + volumeNames[i] + "] = ConfigStorageC_" + volumeNames[i] + "; \n") + outFile.write("} \n")