]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
at45db include support
authoridgay <idgay>
Wed, 11 Apr 2007 21:06:58 +0000 (21:06 +0000)
committeridgay <idgay>
Wed, 11 Apr 2007 21:06:58 +0000 (21:06 +0000)
tools/tinyos/misc/tos-storage-at45db.1
tools/tinyos/misc/tos-storage-at45db.in

index d511989d6ca4fe9585c31a14ca4bf48b63de385a..f1fcdcd4a0e7940faefe7fd789cc8554f39bad89 100644 (file)
@@ -5,7 +5,7 @@
 tos-storage-at45db - Generate storage volume description code
 .SH SYNOPSIS
 
-\fBtos-storage-at45db\fR
+\fBtos-storage-at45db\fR \fIplatform-directory\fR
 .SH DESCRIPTION
 
 \fBtos-storage-at45db\fR reads a user specification describing the layout
@@ -14,6 +14,10 @@ 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.
 
+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-at45db.xml\fR file.
 .SH EXAMPLES
index 0bf9ad2a6f18d440ce5dc9419850287f9cd0bfa6..c46719a5024eab2b4addaf8a20c3774240683a92 100644 (file)
@@ -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,6 +11,22 @@ from xml.dom import *
 from xml.dom.minidom import *
 from re import match
 from sys import *
+from subprocess import Popen, PIPE
+
+# print an error message and exit
+def nfail(s):
+  stderr.write(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:
+  nfail("Usage: tos-storage-at45db <platform directory>")
 
 sector_size = 256
 flash_size = 2048 # in sectors
@@ -18,11 +34,6 @@ flash_size = 2048 # in sectors
 volumes = {}
 volmap = []
 
-# print an error message and exit
-def nfail(s):
-  stderr.write(s + "\n")
-  exit(2)
-
 def check_volume(name, base, size):
   if base == "":
     base = None
@@ -76,20 +87,64 @@ 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")
+    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)
+  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():