]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tools/tinyos/misc/tos-storage-pxa27xp30
Update to tos-storage-* tools to support a '-t' flag to generate a VolumeMapC.nc...
[tinyos-2.x.git] / tools / tinyos / misc / tos-storage-pxa27xp30
index 120dd0b69e4c84b9c85ffc814546c843af309fd8..04c23fccb04c119e01c3e6486638852635aa4445 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/Library/Frameworks/Python.framework/Versions/Current/bin/python
 # -*- python -*-
 # Copyright (c) 2005-2006 Arch Rock Corporation
 # All rights reserved.
@@ -40,6 +40,33 @@ from re import match
 from sys import *
 from xml.dom import minidom
 
+from getopt import *
+import string
+import commands
+#New way of handling arguments........
+try:
+  opts, args = getopt(argv[1:], "t", [])
+except GetoptError, err:
+  print str(err) # will print something like "option -a not recognized"
+  stderr.write( "Usage: tos-storage-stm25p [-t] <platform directory>\n" )
+  
+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-stm25p [-t] <platform directory>\n" )
+  
+cthreads = False
+for o, a in opts:
+  if o == "-t":
+    cthreads = True
+  else:
+    assert False, "unhandled option"
+
 NUM_SECTORS = 16
 SECTOR_SIZE = 2097152
 
@@ -48,6 +75,8 @@ volumes = {}
 volumeNames = []
 volumeSizes = []
 volumeOffsets = []
+volumeTypes = dict()
+volumeOptions = dict()
 freeSectors = NUM_SECTORS*[ True ]
 
 def error_exit( s ):
@@ -64,6 +93,7 @@ volumes [ "PXARESERVED" ] = "blah"
 volumeNames.append( "VOLUME_PXARESERVED" )
 volumeSizes.append( 1 )
 volumeOffsets.append( 0 )
+volumeTypes[ "VOLUME_PXARESERVED" ] = ""
 freeSectors[ 0 ] = False
 
 # extract information
@@ -71,6 +101,11 @@ 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 == "":
         error_exit( "volume has no name" )
     elif not match( "^[a-zA-Z0-9_]+$", name ):
@@ -101,6 +136,9 @@ for volume in dom.documentElement.getElementsByTagName( "volume" ):
 
     volumeNames.append( "VOLUME_" + name )
     volumeSizes.append( size / SECTOR_SIZE )
+    volumeTypes["VOLUME_" + name] = type
+    volumeOptions["VOLUME_" + name] = isCircular
+      
     if base == "":
         volumeOffsets.append( -1 )
     else:
@@ -150,3 +188,48 @@ print "};"
 
 print ""
 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")
+
+  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")