From: R. Steve McKown Date: Thu, 8 Apr 2010 19:50:41 +0000 (-0600) Subject: Teach tos-storage-stm25p to derive NUM_SECTORS and SECTOR_SIZE. X-Git-Tag: debian/2.1.0-4-1tmi~1^2~13 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=8205c3ed1905491954757c0536f86a33cc39d34f Teach tos-storage-stm25p to derive NUM_SECTORS and SECTOR_SIZE. The stm25p driver is suitable for different sizes of flash parts, such as the commonly used 8Mb M25P80 and the less commonly used 1Mb M25P10A. The driver defines the flash configuration in Stm25p.h. By having tos-storage-stm25p walk the @includes for the platform, as found in the .platform file, each platform can ensure that a Stm25p.h with correct content for its flash part is found for use by the driver and this script. --- diff --git a/tools/tinyos/misc/tos-storage-stm25p.in b/tools/tinyos/misc/tos-storage-stm25p.in index f1b02b78..8002cf85 100644 --- a/tools/tinyos/misc/tos-storage-stm25p.in +++ b/tools/tinyos/misc/tos-storage-stm25p.in @@ -40,11 +40,16 @@ # @author Jonathan Hui # @author David Gay # @author Kevin Klues +# @author R. Steve McKown # # $Revision$ # $Date$ # +from __future__ import with_statement # Does this require too new a python? + +import os +import re from re import match from sys import * from xml.dom import * @@ -112,8 +117,77 @@ def expand_path( path ): return path -NUM_SECTORS = 16 -SECTOR_SIZE = 65536 +HEADER_FILE = 'Stm25p.h' +NUM_SECTORS = 0 +SECTOR_SIZE = 0 + +def parseHeader( dotplatform ): + """ Return an ordered list of paths from the dotplatform file """ + paths = [] + inArray = False + p = re.compile('push\s*\(\s*@includes,\s*qw\s*\('); + q = re.compile('\)\s*\)\s*;'); + try: + with open(dotplatform, 'r') as file: + for line in file: + path = line.strip() + if path: + if p.match(path): + inArray = True + elif q.match(path): + inArray = False + elif inArray == True: + paths.append(path) + return paths + except: + return None + +def findFile( paths, filename ): + """ Find the first occurrence of 'filename' in the list of paths given. """ + for path in paths: + rpath = expand_path(path) + try: + for file in os.listdir(rpath): + if file == filename: + return rpath + '/' + filename + except OSError: + None + return None + +def findVars( path, vars ): + """ Finds values for the variables already present in vars from path """ + inEnum = False + p = re.compile('enum\s.*{'); + q = re.compile('}s*;'); + r = re.compile('^\s*([A-Z0-9_]*)\s*=\s*([^,]*)'); + with open(path, 'r') as file: + for line in file: + line = line.strip() + if line: + if p.match(line): + inEnum = True + elif q.match(line): + inEnum = False + elif inEnum == True: + m = r.search(line) + if vars.has_key(m.group(1)): + vars[m.group(1)] = m.group(2) + +paths = parseHeader(platformdir + '/.platform') +if paths: + path = findFile(paths, HEADER_FILE) + if path: + enums = {} + enums["STM25P_NUM_SECTORS"] = 0 + enums["STM25P_SECTOR_SIZE_LOG2"] = 0 + findVars(path, enums) + NUM_SECTORS = int(enums["STM25P_NUM_SECTORS"]) + SECTOR_SIZE = 2**int(enums["STM25P_SECTOR_SIZE_LOG2"]) +if NUM_SECTORS == 0 or SECTOR_SIZE == 0: + stderr.write( 'No valid Stm25p.h in PFLAGS path; check .platform file\n' ) + stderr.write( "tos-storage-stm25p: no valid Stm25p.h found.\n\t" + "Check the platform's .platform file\n" ) + exit(2) volumes = {}