]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
add include support to stm25p volume files
authoridgay <idgay>
Wed, 11 Apr 2007 21:29:29 +0000 (21:29 +0000)
committeridgay <idgay>
Wed, 11 Apr 2007 21:29:29 +0000 (21:29 +0000)
fix multi-volume stm25p bug

tools/tinyos/misc/tos-storage-at45db.1
tools/tinyos/misc/tos-storage-stm25p.1
tools/tinyos/misc/tos-storage-stm25p.in

index f1fcdcd4a0e7940faefe7fd789cc8554f39bad89..48444d905189b68646b57411461ae5aea38a6650 100644 (file)
@@ -22,7 +22,8 @@ This program is normally invoked automatically by the TinyOS build system
 when your application directory contains a \fBvolumes-at45db.xml\fR file.
 .SH EXAMPLES
 
 when your application directory contains a \fBvolumes-at45db.xml\fR file.
 .SH EXAMPLES
 
-  tos-storage-at45db <volumes-at45db.xml >build/mica2/StorageVolumes.h
+  tos-storage-at45db /opt/tinyos-2.x/tos/platforms/mica2 \\
+      <volumes-at45db.xml >build/mica2/StorageVolumes.h
 .SH SEE ALSO
 
 .IR tos-storage-stm25p (1)
 .SH SEE ALSO
 
 .IR tos-storage-stm25p (1)
index 21253e7976274393da0a65172150b797e7f3755a..b558bd22cb50c545b2985ec943d043efab826b02 100644 (file)
@@ -5,7 +5,7 @@
 tos-storage-stm25p - Generate storage volume description code
 .SH SYNOPSIS
 
 tos-storage-stm25p - Generate storage volume description code
 .SH SYNOPSIS
 
-\fBtos-storage-stm25p\fR
+\fBtos-storage-stm25p\fR \fIplatform-directory\fR
 .SH DESCRIPTION
 
 \fBtos-storage-stm25p\fR reads a user specification describing the layout
 .SH DESCRIPTION
 
 \fBtos-storage-stm25p\fR reads a user specification describing the layout
@@ -14,11 +14,16 @@ describing that layout for use by the TinyOS 2.0 storage subsystem.  The
 user specification is in XML and is read from standard input. The code is
 written to standard output.
 
 user specification is in XML and is read from standard input. The code is
 written to standard output.
 
+The argument should specify the platform directory for the current
+compilation target; this is necessary for the correct handling of 
+file include statements in the XML input.
+
 This program is normally invoked automatically by the TinyOS build system
 when your application directory contains a \fBvolumes-stm25p.xml\fR file.
 .SH EXAMPLES
 
 This program is normally invoked automatically by the TinyOS build system
 when your application directory contains a \fBvolumes-stm25p.xml\fR file.
 .SH EXAMPLES
 
-  tos-storage-stm25p <volumes-stm25p.xml >build/telosb/StorageVolumes.h
+  tos-storage-stm25p /opt/tinyos-2.x/tos/platforms/telosb \\
+      <volumes-stm25p.xml >build/telosb/StorageVolumes.h
 .SH SEE ALSO
 
 .IR tos-storage-stm25p (1)
 .SH SEE ALSO
 
 .IR tos-storage-stm25p (1)
index c26793be078dd0d3429101d86cf787fa8b905f99..79cb09885d976fbffd770a318a6e98ed5497290e 100644 (file)
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 # OF THE POSSIBILITY OF SUCH DAMAGE
 #
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 # OF THE POSSIBILITY OF SUCH DAMAGE
 #
+# Copyright (c) 2006-2007 Intel Corporation
+# All rights reserved.
+#
+# This file is distributed under the terms in the attached INTEL-LICENSE     
+# file. If you do not find these files, copies can be found by writing to
+# Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA, 
+# 94704.  Attention:  Intel License Inquiry.
+
 # @author Jonathan Hui <jhui@archedrock.com>
 # @author Jonathan Hui <jhui@archedrock.com>
+# @author David Gay
 #
 # $Revision$
 # $Date$
 #
 # $Revision$
 # $Date$
                                   
 from re import match
 from sys import *
                                   
 from re import match
 from sys import *
-from xml.dom import minidom
+from xml.dom import *
+from xml.dom.minidom import *
+from subprocess import Popen, PIPE
+
+def error_exit( s ):
+    stderr.write( "ERROR: " + s + "\n" )
+    exit( 2 )
+
+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
+
 
 NUM_SECTORS = 16
 SECTOR_SIZE = 65536
 
 NUM_SECTORS = 16
 SECTOR_SIZE = 65536
@@ -49,56 +94,79 @@ volumeSizes = []
 volumeOffsets = []
 freeSectors = NUM_SECTORS*[ True ]
 
 volumeOffsets = []
 freeSectors = NUM_SECTORS*[ True ]
 
-def error_exit( s ):
-    stderr.write( "ERROR: " + s + "\n" )
-    exit( 2 )
+if len( argv ) == 2:
+  platformdir = argv[1]
+  # This gives the whole string when there's no / in platformdir
+  platform = platformdir[platformdir.rfind( "/" ) + 1:]
+elif len( argv ) == 1:
+  platformdir = ""
+  platform = ""
+else:
+  error_exit( "Usage: tos-storage-stm25p <platform directory>" )
 
 
-try:
-    dom = minidom.parse( stdin )
-except xml.parsers.expat.ExpatError:
-    error_exit( "input invalid" )
-
-# extract information
-for volume in dom.documentElement.getElementsByTagName( "volume" ):
-    name = volume.getAttribute( "name" )
-    size = volume.getAttribute( "size" )
-    base = volume.getAttribute( "base" )
-    if name == "":
-        error_exit( "volume has no name" )
-    elif not match( "^[a-zA-Z0-9_]+$", name ):
-        error_exit( "volume has invalid name '%s'" % name )
-    elif volumes.has_key( name ):
-        error_exit( "duplicate volume definition '%s'" % name )
-    else:
-        volumes[ name ] = "blah"
-    
-    if size == "":
-        error_exit( "volume '%s' has no size" % name )
-    try:
-        size = int( size )
-    except ValueError:
-        error_exit( "volume '%s' has invalid size" % name )
-    if base != "":
-        try:
-            base = int( base )
-        except ValueError:
-            error_exit( "volume '%s' has invalid base" % name )
-    if ( size & ( SECTOR_SIZE - 1 ) ) != 0:
-        error_exit( "size of volume '%s' is not a multiple of %d" % \
-                    ( name, SECTOR_SIZE ) )
-    if base != "" and ( base & ( SECTOR_SIZE - 1 ) ) != 0:
-        error_exit( "base of volume '%s' is not a multiple of %d" % \
-                    ( name, SECTOR_SIZE ) )
-
-    volumeNames.append( "VOLUME_" + name )
-    volumeSizes.append( size / SECTOR_SIZE )
-    if base == "":
-        volumeOffsets.append( -1 )
+def volumeparse( file, fname, depth ):
+  if depth > 10:
+    error_exit( "include nesting too deep - check for cycles" )
+  try:
+    dom = parse( file )
+  except xml.parsers.expat.ExpatError:
+    error_exit( fname + " is not a valid input file" )
+  except IOError:
+    error_exit( "couldn't open file " + fname )
+
+  # extract information
+  for volume in dom.documentElement.getElementsByTagName( "volume" ):
+      name = volume.getAttribute( "name" )
+      size = volume.getAttribute( "size" )
+      base = volume.getAttribute( "base" )
+      if name == "":
+          error_exit( "volume has no name" )
+      elif not match( "^[a-zA-Z0-9_]+$", name ):
+          error_exit( "volume has invalid name '%s'" % name )
+      elif volumes.has_key( name ):
+          error_exit( "duplicate volume definition '%s'" % name )
+      else:
+          volumes[ name ] = "blah"
+
+      if size == "":
+          error_exit( "volume '%s' has no size" % name )
+      try:
+          size = int( size )
+      except ValueError:
+          error_exit( "volume '%s' has invalid size" % name )
+      if base != "":
+          try:
+              base = int( base )
+          except ValueError:
+              error_exit( "volume '%s' has invalid base" % name )
+      if ( size & ( SECTOR_SIZE - 1 ) ) != 0:
+          error_exit( "size of volume '%s' is not a multiple of %d" % \
+                      ( name, SECTOR_SIZE ) )
+      if base != "" and ( base & ( SECTOR_SIZE - 1 ) ) != 0:
+          error_exit( "base of volume '%s' is not a multiple of %d" % \
+                      ( name, SECTOR_SIZE ) )
+
+      volumeNames.append( "VOLUME_" + name )
+      volumeSizes.append( size / SECTOR_SIZE )
+      if base == "":
+          volumeOffsets.append( -1 )
+      else:
+          base = base / SECTOR_SIZE
+          size = size / SECTOR_SIZE
+          volumeOffsets.append( base )
+          for i in range( size ):
+              freeSectors[ i + base ] = False
+
+  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:
     else:
-        base = base / SECTOR_SIZE
-        volumeOffsets.append( base )
-        for i in range( size ):
-            freeSectors[ i + base ] = False
+      error_exit( "invalid include directive " + fname )
+  dom.unlink( )
+
+volumeparse( stdin, "(standard input)", 0 )
 
 # allocate with first fit policy
 for i in range( len( volumeOffsets ) ):
 
 # allocate with first fit policy
 for i in range( len( volumeOffsets ) ):