2003-06-14 17:07:02 +02:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import string
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
debug = 0
|
2003-06-24 19:26:45 +02:00
|
|
|
warnings = 0
|
|
|
|
errors = 0
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
arch = ''
|
|
|
|
ldscriptbase = ''
|
|
|
|
payloadfile = ''
|
2003-07-14 20:00:10 +02:00
|
|
|
initfile = ''
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# Key is the rule name. Value is a mkrule object.
|
|
|
|
makebaserules = {}
|
|
|
|
|
|
|
|
# List of targets in the order defined by makerule commands.
|
2003-07-10 22:55:09 +02:00
|
|
|
#makerule_targets = {}
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
treetop = ''
|
|
|
|
target_dir = ''
|
|
|
|
|
2003-07-10 22:55:09 +02:00
|
|
|
#sources = {}
|
2003-06-14 17:07:02 +02:00
|
|
|
objectrules = {}
|
2003-07-14 20:00:10 +02:00
|
|
|
initobjectrules = {}
|
2003-06-14 17:07:02 +02:00
|
|
|
# make these a hash so they will be unique.
|
|
|
|
driverrules = {}
|
|
|
|
ldscripts = []
|
|
|
|
userdefines = []
|
|
|
|
curpart = 0
|
2003-06-23 18:54:12 +02:00
|
|
|
root = 0
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
globalvars = {} # We will globals here
|
|
|
|
parts = {}
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
# options in order defined. These will be unique due to use of hash
|
|
|
|
# for options.
|
|
|
|
options_by_order = []
|
|
|
|
crt0includes = []
|
2003-07-14 20:00:10 +02:00
|
|
|
initincludes = {}
|
|
|
|
useinitincludes = 0 # transitional
|
2003-06-14 17:07:02 +02:00
|
|
|
partinstance = 0
|
|
|
|
curdir = ''
|
|
|
|
dirstack = []
|
|
|
|
config_file_list = []
|
|
|
|
|
|
|
|
local_path = re.compile(r'^\.')
|
2003-07-14 20:00:10 +02:00
|
|
|
include_pattern = re.compile(r'%%([^%]+)%%')
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Error Handling
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class location:
|
|
|
|
class place:
|
|
|
|
def __init__(self, file, line, command):
|
|
|
|
self.file = file
|
|
|
|
self.line = line
|
|
|
|
self.command = command
|
|
|
|
def next_line(self, command):
|
|
|
|
self.line = self.line + 1
|
|
|
|
self.command = command
|
|
|
|
def at(self):
|
|
|
|
return "%s:%d" % (self.file, self.line)
|
|
|
|
|
|
|
|
def __init__ (self):
|
|
|
|
self.stack = []
|
|
|
|
|
|
|
|
def file(self):
|
|
|
|
return self.stack[-1].file
|
|
|
|
def line(self):
|
|
|
|
return self.stack[-1].line
|
|
|
|
def command(self):
|
|
|
|
return self.stack[-1].command
|
|
|
|
|
|
|
|
def push_file(self, file):
|
|
|
|
self.stack.append(self.place(file, 0, ""))
|
|
|
|
def pop_file(self):
|
|
|
|
self.stack.pop()
|
|
|
|
def next_line(self, command):
|
|
|
|
self.stack[-1].next_line(command)
|
|
|
|
def at(self):
|
|
|
|
return self.stack[-1].at()
|
|
|
|
loc = location()
|
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
class initinclude:
|
|
|
|
def __init__ (self, str, path):
|
|
|
|
self.string = str
|
|
|
|
self.path = path
|
|
|
|
|
|
|
|
def getstring(self):
|
|
|
|
return self.string
|
|
|
|
|
|
|
|
def getpath(self):
|
|
|
|
return self.path
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
class makerule:
|
|
|
|
def __init__ (self, target):
|
|
|
|
self.target = target
|
|
|
|
self.dependency = []
|
|
|
|
self.actions = []
|
|
|
|
|
|
|
|
def addaction(self, action):
|
|
|
|
self.actions.append(action)
|
|
|
|
|
|
|
|
def adddependency(self, dependency):
|
|
|
|
self.dependency.append(dependency)
|
|
|
|
|
|
|
|
def gtarget(self):
|
|
|
|
return self.target
|
|
|
|
|
|
|
|
def gdependency(self):
|
|
|
|
return self.dependency
|
|
|
|
|
|
|
|
def gaction(self):
|
|
|
|
return self.actions
|
|
|
|
|
|
|
|
class option:
|
|
|
|
def __init__ (self, name):
|
2003-06-23 18:54:12 +02:00
|
|
|
self.name = name # name of option
|
|
|
|
self.loc = 0 # current location
|
|
|
|
self.value = 0 # option value
|
|
|
|
self.set = 0 # option has been set
|
2003-06-24 01:52:15 +02:00
|
|
|
self.used = 0 # option has been set
|
2003-06-23 18:54:12 +02:00
|
|
|
self.default = 0 # option has default value (otherwise
|
|
|
|
# it is undefined)
|
|
|
|
self.comment = '' # description of option
|
2003-06-24 01:52:15 +02:00
|
|
|
self.exportable = 0 # option is able to be exported
|
2003-06-23 18:54:12 +02:00
|
|
|
self.exported = 0 # option is exported
|
|
|
|
self.defined = 0 # option has a value
|
|
|
|
self.format = '%s' # option print format
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def setvalue(self, value, loc):
|
|
|
|
if (self.set):
|
2003-07-10 22:55:09 +02:00
|
|
|
fatal("Error: option %s already set" % self.name)
|
2003-06-14 17:07:02 +02:00
|
|
|
self.set = 1
|
|
|
|
self.value = value
|
2003-06-23 18:54:12 +02:00
|
|
|
self.defined = 1
|
2003-06-14 17:07:02 +02:00
|
|
|
self.loc = loc
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
def getvalue(self, part):
|
|
|
|
global curpart
|
|
|
|
if (not (type(self.value) is str)):
|
|
|
|
return self.value
|
|
|
|
if (self.value == '' or self.value[0] != '{'):
|
|
|
|
return self.value
|
|
|
|
# save curpart so we can evaluate expression
|
|
|
|
# in context of part
|
|
|
|
s = curpart
|
|
|
|
curpart = part
|
2003-06-24 19:26:45 +02:00
|
|
|
v = parse('delexpr', self.value)
|
|
|
|
# TODO: need to check for parse errors!
|
2003-06-23 18:54:12 +02:00
|
|
|
curpart = s
|
|
|
|
return v
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def setdefault(self, value, loc):
|
|
|
|
if (self.default):
|
2003-07-10 22:55:09 +02:00
|
|
|
fatal("Error: default value for %s already set" % self.name)
|
2003-06-14 17:07:02 +02:00
|
|
|
self.value = value
|
2003-06-23 18:54:12 +02:00
|
|
|
self.defined = 1
|
|
|
|
self.default = 1
|
2003-06-14 17:07:02 +02:00
|
|
|
self.loc = loc
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
def setnodefault(self, loc):
|
|
|
|
self.default = 1
|
|
|
|
self.defined = 0
|
|
|
|
self.loc = loc
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
def where(self):
|
|
|
|
return self.loc
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
def setcomment(self, value, loc):
|
|
|
|
if (self.comment != ''):
|
|
|
|
print "%s: " % self.name
|
|
|
|
print "Attempt to modify comment at %s" % loc
|
|
|
|
return
|
|
|
|
self.comment = value
|
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
def setexportable(self):
|
|
|
|
self.exportable = 1
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
def setexported(self):
|
2003-06-24 01:52:15 +02:00
|
|
|
self.exportable = 1
|
2003-06-23 18:54:12 +02:00
|
|
|
self.exported = 1
|
|
|
|
|
|
|
|
def setnoexport(self):
|
2003-06-24 01:52:15 +02:00
|
|
|
self.exportable = 0
|
2003-06-23 18:54:12 +02:00
|
|
|
self.exported = 0
|
|
|
|
|
|
|
|
def setformat(self, fmt):
|
|
|
|
self.format = fmt
|
|
|
|
|
|
|
|
def getformat(self):
|
|
|
|
return self.format
|
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
def setused(self):
|
|
|
|
if (self.exportable):
|
2003-06-23 18:54:12 +02:00
|
|
|
self.exported = 1
|
2003-06-24 01:52:15 +02:00
|
|
|
self.used = 1
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
def isexported(self):
|
|
|
|
return (self.exported and self.defined)
|
|
|
|
|
|
|
|
def isdefined(self):
|
|
|
|
return (self.defined)
|
|
|
|
|
|
|
|
def isset(self):
|
|
|
|
return (self.set)
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
def isused(self):
|
|
|
|
return (self.used)
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
class partobj:
|
2003-07-11 16:51:29 +02:00
|
|
|
def __init__ (self, dir, parent, type, name):
|
2003-06-14 17:07:02 +02:00
|
|
|
global partinstance
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "partobj dir %s parent %s type %s" %(dir,parent,type)
|
2003-07-10 14:38:39 +02:00
|
|
|
self.children = 0
|
2003-06-14 17:07:02 +02:00
|
|
|
self.initcode = []
|
|
|
|
self.registercode = []
|
2003-07-10 14:38:39 +02:00
|
|
|
# sibling is not a list.
|
2003-06-14 17:07:02 +02:00
|
|
|
self.siblings = 0
|
|
|
|
self.type = type
|
|
|
|
self.objects = []
|
|
|
|
self.dir = dir
|
|
|
|
self.irq = 0
|
|
|
|
self.instance = partinstance + 1
|
2003-07-11 16:51:29 +02:00
|
|
|
self.flatten_name = flatten_name(type + "/" + name)
|
2003-07-10 16:46:59 +02:00
|
|
|
if (debug):
|
|
|
|
print "INSTANCE %d" % self.instance
|
2003-06-14 17:07:02 +02:00
|
|
|
partinstance = partinstance + 1
|
|
|
|
self.devfn = 0
|
|
|
|
self.private = 0
|
2003-06-23 18:54:12 +02:00
|
|
|
self.options = {}
|
2003-07-11 16:51:29 +02:00
|
|
|
# chip initialization. If there is a chip.h in the
|
|
|
|
# directory, generate the structs etc. to
|
|
|
|
# initialize the code
|
|
|
|
self.chipconfig = 0
|
|
|
|
if (os.path.exists(dir + "/" + "chip.h")):
|
|
|
|
self.chipconfig = 1
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
if (parent):
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "add to parent"
|
2003-06-14 17:07:02 +02:00
|
|
|
self.parent = parent
|
2003-07-10 14:38:39 +02:00
|
|
|
# add current child as my sibling,
|
|
|
|
# me as the child.
|
2003-07-10 16:46:59 +02:00
|
|
|
if (debug):
|
|
|
|
if (parent.children):
|
|
|
|
print "add %s (%d) as isbling" % (parent.children.dir, parent.children.instance)
|
2003-07-10 14:38:39 +02:00
|
|
|
self.siblings = parent.children
|
|
|
|
parent.children = self
|
2003-06-14 17:07:02 +02:00
|
|
|
else:
|
|
|
|
self.parent = self
|
|
|
|
|
|
|
|
def dumpme(self, lvl):
|
|
|
|
print "%d: type %s" % (lvl, self.type)
|
2003-07-10 16:46:59 +02:00
|
|
|
print "%d: instance %d" % (lvl, self.instance)
|
2003-06-14 17:07:02 +02:00
|
|
|
print "%d: dir %s" % (lvl,self.dir)
|
2003-07-11 16:51:29 +02:00
|
|
|
print "%d: flatten_name %s" % (lvl,self.flatten_name)
|
2003-06-14 17:07:02 +02:00
|
|
|
print "%d: parent %s" % (lvl,self.parent.type)
|
|
|
|
print "%d: parent dir %s" % (lvl,self.parent.dir)
|
2003-07-10 16:46:59 +02:00
|
|
|
if (self.children):
|
|
|
|
print "%d: child %s" % (lvl, self.children.dir)
|
|
|
|
if (self.siblings):
|
|
|
|
print "%d: siblings %s" % (lvl, self.siblings.dir)
|
2003-06-14 17:07:02 +02:00
|
|
|
print "%d: initcode " % lvl
|
|
|
|
for i in self.initcode:
|
2003-06-23 18:54:12 +02:00
|
|
|
print " %s" % i
|
2003-06-14 17:07:02 +02:00
|
|
|
print "%d: registercode " % lvl
|
|
|
|
for i in self.registercode:
|
2003-06-23 18:54:12 +02:00
|
|
|
print " %s" % i
|
2003-07-10 16:46:59 +02:00
|
|
|
print "\n"
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-07-10 14:38:39 +02:00
|
|
|
def gencode(self, file):
|
2003-07-11 16:51:29 +02:00
|
|
|
if (self.chipconfig):
|
|
|
|
file.write("struct %s_config %s_config_%d" % (\
|
|
|
|
self.flatten_name ,\
|
|
|
|
self.flatten_name , \
|
|
|
|
self.instance))
|
|
|
|
if (self.registercode):
|
|
|
|
file.write("\t= {\n")
|
|
|
|
for i in self.registercode:
|
|
|
|
file.write( "\t %s" % i)
|
|
|
|
file.write("\t}\n")
|
|
|
|
else:
|
|
|
|
file.write(";")
|
|
|
|
file.write("\n");
|
|
|
|
file.write("struct chip dev%d = {\n" % self.instance)
|
2003-07-10 14:38:39 +02:00
|
|
|
file.write("/* %s %s */\n" % (self.type, self.dir))
|
2003-07-11 16:51:29 +02:00
|
|
|
#file.write(" .devfn = %d,\n" % self.devfn)
|
2003-06-14 17:07:02 +02:00
|
|
|
if (self.siblings):
|
2003-07-11 16:51:29 +02:00
|
|
|
file.write(" .next = &dev%d,\n" % self.siblings.instance)
|
2003-06-14 17:07:02 +02:00
|
|
|
if (self.children):
|
2003-07-11 16:51:29 +02:00
|
|
|
file.write(" .children = &dev%d,\n" % \
|
2003-07-10 14:38:39 +02:00
|
|
|
self.children.instance)
|
2003-06-14 17:07:02 +02:00
|
|
|
if (self.private):
|
2003-07-11 16:51:29 +02:00
|
|
|
file.write(" .private = private%d,\n" % self.instance)
|
|
|
|
if (self.chipconfig):
|
|
|
|
# set the pointer to the structure for all this
|
|
|
|
# type of part
|
|
|
|
file.write(" .control= &%s_control,\n" % \
|
|
|
|
self.flatten_name )
|
|
|
|
# generate the pointer to the isntance
|
|
|
|
# of the chip struct
|
|
|
|
file.write(" .chip_config = (void *) &%s_config_%d,\n" %\
|
|
|
|
(self.flatten_name, self.instance ))
|
2003-07-10 14:38:39 +02:00
|
|
|
file.write("};\n")
|
2003-07-11 16:51:29 +02:00
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def irq(self, irq):
|
|
|
|
self.irq = irq
|
|
|
|
|
|
|
|
def addinit(self, code):
|
|
|
|
self.initcode.append(code)
|
|
|
|
|
|
|
|
def addregister(self, code):
|
2003-07-11 16:51:29 +02:00
|
|
|
code = dequote(code)
|
2003-06-14 17:07:02 +02:00
|
|
|
self.registercode.append(code)
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
def usesoption(self, name):
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o == 0):
|
|
|
|
fatal("Error: can't use undefined option %s" % name)
|
2003-06-24 01:52:15 +02:00
|
|
|
o.setused()
|
2003-07-14 20:00:10 +02:00
|
|
|
o1 = getvalue(self.options, name)
|
|
|
|
if (o1):
|
|
|
|
return
|
2003-06-23 18:54:12 +02:00
|
|
|
setvalue(self.options, name, o)
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
class partsstack:
|
|
|
|
def __init__ (self):
|
|
|
|
self.stack = []
|
|
|
|
|
|
|
|
def push(self, part):
|
|
|
|
self.stack.append(part)
|
|
|
|
|
|
|
|
def pop(self):
|
|
|
|
return self.stack.pop()
|
|
|
|
|
|
|
|
def tos(self):
|
|
|
|
return self.stack[-1]
|
|
|
|
pstack = partsstack()
|
|
|
|
|
2003-06-24 19:26:45 +02:00
|
|
|
def error(string):
|
|
|
|
global errors, loc
|
|
|
|
errors = errors + 1
|
2003-06-14 17:07:02 +02:00
|
|
|
size = len(loc.stack)
|
|
|
|
i = 0
|
|
|
|
while(i < size -1):
|
|
|
|
print loc.stack[i].at()
|
|
|
|
i = i + 1
|
|
|
|
print "%s: %s"% (loc.at(), string)
|
2003-06-24 19:26:45 +02:00
|
|
|
|
|
|
|
def exitiferrors():
|
|
|
|
if (errors != 0):
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def fatal(string):
|
|
|
|
error(string)
|
|
|
|
exitiferrors()
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def warning(string):
|
2003-06-24 19:26:45 +02:00
|
|
|
global warnings, loc
|
|
|
|
warnings = warnings + 1
|
2003-06-14 17:07:02 +02:00
|
|
|
print "===> Warning:"
|
|
|
|
size = len(loc.stack)
|
|
|
|
i = 0
|
|
|
|
while(i < size -1):
|
|
|
|
print loc.stack[i].at()
|
|
|
|
i = i + 1
|
|
|
|
print "%s: %s"% (loc.at(), string)
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# statements
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def getvalue(dict, name):
|
2003-06-23 18:54:12 +02:00
|
|
|
if name not in dict.keys():
|
|
|
|
if (debug >1):
|
|
|
|
print 'Undefined:', name
|
|
|
|
return 0
|
|
|
|
v = dict.get(name, 0)
|
|
|
|
if (debug > 1):
|
|
|
|
print "getvalue %s returning %s" % (name, v)
|
|
|
|
return v
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def setvalue(dict, name, value):
|
2003-06-23 18:54:12 +02:00
|
|
|
if name in dict.keys():
|
|
|
|
print "Warning, %s previously defined" % name
|
2003-06-14 17:07:02 +02:00
|
|
|
if (debug > 1):
|
2003-06-23 18:54:12 +02:00
|
|
|
print "setvalue sets %s to %s" % (name, value)
|
2003-06-14 17:07:02 +02:00
|
|
|
dict[name] = value
|
|
|
|
|
|
|
|
# options.
|
2003-06-23 18:54:12 +02:00
|
|
|
# to create an option, it has to not exist.
|
2003-06-14 17:07:02 +02:00
|
|
|
# When an option value is fetched, the fact that it was used is
|
|
|
|
# remembered.
|
|
|
|
# Legal things to do:
|
|
|
|
# set a default value, then set a real value before the option is used.
|
|
|
|
# set a value, try to set a default, default silently fails.
|
|
|
|
# Illegal:
|
|
|
|
# use the value, then try to set the value
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
def newoption(name):
|
2003-06-14 17:07:02 +02:00
|
|
|
o = getvalue(options, name)
|
2003-06-23 18:54:12 +02:00
|
|
|
if (o):
|
|
|
|
print "option %s already defined" % name
|
|
|
|
sys.exit(1)
|
|
|
|
o = option(name)
|
|
|
|
setvalue(options, name, o)
|
|
|
|
options_by_order.append(name)
|
|
|
|
|
|
|
|
# option must be declared before being used in a part
|
|
|
|
# if we're not processing a part, then we must
|
|
|
|
# be at the top level where all options are available
|
|
|
|
def getoption(name, part):
|
|
|
|
global options
|
|
|
|
if (part):
|
|
|
|
o = getvalue(part.options, name)
|
|
|
|
else:
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o == 0 or not o.defined):
|
2003-06-24 19:26:45 +02:00
|
|
|
error("Error: Option %s undefined (missing use command?)." % name)
|
|
|
|
return
|
2003-06-23 18:54:12 +02:00
|
|
|
v = o.getvalue(part)
|
2003-06-14 17:07:02 +02:00
|
|
|
if (debug > 2):
|
2003-06-23 18:54:12 +02:00
|
|
|
print "getoption returns %s" % v
|
2003-06-14 17:07:02 +02:00
|
|
|
print "%s" % o.where()
|
2003-06-23 18:54:12 +02:00
|
|
|
return v
|
|
|
|
|
|
|
|
# setoptionstmt only allowed at top level
|
|
|
|
def setoptionstmt(name, value):
|
|
|
|
global curpart
|
|
|
|
if (curpart != root):
|
|
|
|
fatal("Error: options can only be set in target configuration file")
|
|
|
|
setoption(name, value)
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def setoption(name, value):
|
2003-06-23 18:54:12 +02:00
|
|
|
global loc
|
2003-06-14 17:07:02 +02:00
|
|
|
o = getvalue(options, name)
|
2003-06-23 18:54:12 +02:00
|
|
|
if (o == 0):
|
|
|
|
fatal("Error: attempt set nonexistent option %s" % name)
|
2003-06-14 17:07:02 +02:00
|
|
|
o.setvalue(value, loc)
|
|
|
|
|
|
|
|
def setdefault(name, value):
|
2003-06-23 18:54:12 +02:00
|
|
|
global loc
|
2003-06-14 17:07:02 +02:00
|
|
|
o = getvalue(options, name)
|
2003-06-23 18:54:12 +02:00
|
|
|
if (not o):
|
|
|
|
return
|
|
|
|
if (o.default):
|
|
|
|
print "setdefault: attempt to duplicate default for %s" % name
|
2003-06-14 17:07:02 +02:00
|
|
|
return
|
|
|
|
o.setdefault(value, loc)
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
def setnodefault(name):
|
|
|
|
global loc
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
|
|
|
return
|
|
|
|
if (o.default):
|
|
|
|
print "setdefault: attempt to duplicate default for %s" % name
|
|
|
|
return
|
|
|
|
o.setnodefault(loc)
|
|
|
|
|
|
|
|
def setcomment(name, value):
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
|
|
|
fatal("setcomment: %s not here" % name)
|
|
|
|
o.setcomment(value, loc)
|
|
|
|
|
|
|
|
def setexported(name):
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
|
|
|
fatal("setexported: %s not here" % name)
|
|
|
|
o.setexported()
|
|
|
|
|
|
|
|
def setnoexport(name):
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
|
|
|
fatal("setnoexport: %s not here" % name)
|
|
|
|
o.setnoexport()
|
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
def setexportable(name):
|
2003-06-23 18:54:12 +02:00
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
2003-06-24 01:52:15 +02:00
|
|
|
fatal("setexportable: %s not here" % name)
|
|
|
|
o.setexportable()
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
def setformat(name, fmt):
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
2003-06-24 01:52:15 +02:00
|
|
|
fatal("setformat: %s not here" % name)
|
2003-06-23 18:54:12 +02:00
|
|
|
o.setformat(fmt)
|
|
|
|
|
|
|
|
def getformated(name, part):
|
|
|
|
global options
|
|
|
|
if (part):
|
|
|
|
o = getvalue(part.options, name)
|
|
|
|
else:
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o == 0 or not o.defined):
|
2003-06-24 19:26:45 +02:00
|
|
|
fatal( "Error: Option %s undefined (missing use command?)." % name)
|
2003-06-23 18:54:12 +02:00
|
|
|
v = o.getvalue(part)
|
|
|
|
f = o.getformat()
|
|
|
|
return (f % v)
|
|
|
|
|
|
|
|
def isexported(name, part):
|
|
|
|
if (part):
|
|
|
|
o = getvalue(part.options, name)
|
|
|
|
else:
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o):
|
|
|
|
return o.isexported()
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def isdefined(name, part):
|
|
|
|
if (part):
|
|
|
|
o = getvalue(part.options, name)
|
|
|
|
else:
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o):
|
|
|
|
return o.isdefined()
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def isset(name, part):
|
|
|
|
if (part):
|
|
|
|
o = getvalue(part.options, name)
|
|
|
|
else:
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o):
|
|
|
|
return o.isset()
|
|
|
|
return 0
|
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
def isused(name, part):
|
|
|
|
if (part):
|
|
|
|
o = getvalue(part.options, name)
|
|
|
|
else:
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (o):
|
|
|
|
return o.isused()
|
|
|
|
return 0
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
def usesoption(name):
|
|
|
|
global curpart
|
|
|
|
curpart.usesoption(name)
|
|
|
|
|
|
|
|
def validdef(name, defval):
|
|
|
|
o = getvalue(options, name)
|
|
|
|
if (not o):
|
|
|
|
fatal("validdef: %s not here" % name)
|
|
|
|
if ((defval & 1) != 1):
|
|
|
|
fatal("Error: must specify default value for option %s" % name)
|
|
|
|
if ((defval & 2) != 2):
|
|
|
|
fatal("Error: must specify export for option %s" % name)
|
|
|
|
if ((defval & 4) != 4):
|
|
|
|
fatal("Error: must specify comment for option %s" % name)
|
|
|
|
|
|
|
|
def loadoptions():
|
|
|
|
global treetop
|
|
|
|
optionsfile = os.path.join(treetop, 'src', 'config', 'Options.lb')
|
|
|
|
loc.push_file(optionsfile)
|
|
|
|
if (not parse('options', open(optionsfile, 'r').read())):
|
|
|
|
fatal("Error: Could not parse file")
|
|
|
|
loc.pop_file()
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
def addinit(path):
|
|
|
|
global initfile
|
|
|
|
if (path[0] == '/'):
|
|
|
|
initfile = treetop + '/src/' + path
|
|
|
|
else:
|
|
|
|
initfile = curdir + '/' + path
|
|
|
|
print "Adding init file: %s" % path
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
# we do the crt0include as a dictionary, so that if needed we
|
|
|
|
# can trace who added what when. Also it makes the keys
|
|
|
|
# nice and unique.
|
|
|
|
def addcrt0include(path):
|
|
|
|
global crt0includes
|
|
|
|
if (debug > 2):
|
2003-07-14 20:00:10 +02:00
|
|
|
print "ADDCRT0: %s" % path
|
|
|
|
crt0includes.append(path)
|
|
|
|
|
|
|
|
def addinitinclude(str, path):
|
|
|
|
global initincludes, useinitincludes
|
|
|
|
useinitincludes = 1
|
|
|
|
if (debug > 2):
|
|
|
|
print "ADDCRT0: %s -> %s" % str, path
|
|
|
|
o = initinclude(dequote(str), path)
|
|
|
|
setvalue(initincludes, path, o)
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def addldscript(path):
|
|
|
|
global ldscripts
|
|
|
|
if (path[0] == '/'):
|
|
|
|
fullpath = treetop + '/src/' + path
|
|
|
|
else:
|
|
|
|
fullpath = curdir + '/' + path
|
|
|
|
#fullpath = os.path.join(curdir, path)
|
|
|
|
#setvalue(ldscripts, fullpath, loc)
|
|
|
|
if (debug):
|
2003-06-23 18:54:12 +02:00
|
|
|
print "fullpath :%s: curdir :%s: path :%s:" % (fullpath, curdir, path)
|
2003-06-14 17:07:02 +02:00
|
|
|
ldscripts.append(fullpath)
|
|
|
|
|
|
|
|
def payload(path):
|
|
|
|
global payloadfile
|
|
|
|
adduserdefine("PAYLOAD:=%s"%path)
|
|
|
|
# addrule('payload')
|
|
|
|
# adddep('payload', path)
|
|
|
|
# addaction('payload', 'cp $< $@')
|
|
|
|
|
|
|
|
# this is called with an an object name.
|
|
|
|
# the easiest thing to do is add this object to the current
|
|
|
|
# component.
|
|
|
|
# such kludgery. If the name starts with '.' then make the
|
|
|
|
# dependency be on ./thing.x gag me.
|
|
|
|
def addobjectdriver(dict, object_name):
|
|
|
|
suffix = object_name[-2:]
|
|
|
|
if (suffix == '.o'):
|
|
|
|
suffix = '.c'
|
|
|
|
base = object_name[:-2]
|
|
|
|
if (object_name[0] == '.'):
|
|
|
|
source = base + suffix
|
|
|
|
else:
|
|
|
|
source = os.path.join(curdir, base + suffix)
|
|
|
|
object = base + '.o'
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "add object %s source %s" % (object_name, source)
|
2003-06-14 17:07:02 +02:00
|
|
|
setvalue(dict, base, [object, source])
|
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
def addinitobject(object_name):
|
|
|
|
addobjectdriver(initobjectrules, object_name)
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
def addobject(object_name):
|
|
|
|
addobjectdriver(objectrules, object_name)
|
|
|
|
|
|
|
|
def adddriver(driver_name):
|
|
|
|
addobjectdriver(driverrules, driver_name)
|
|
|
|
|
|
|
|
def target(targ_name):
|
|
|
|
global target_dir
|
|
|
|
global curpart
|
2003-06-23 18:54:12 +02:00
|
|
|
global root
|
|
|
|
print "Configuring TARGET %s" % targ_name
|
2003-06-14 17:07:02 +02:00
|
|
|
target_dir = os.path.join(os.path.dirname(loc.file()), targ_name)
|
|
|
|
if not os.path.isdir(target_dir):
|
2003-06-24 05:12:14 +02:00
|
|
|
print "Creating directory %s" % target_dir
|
2003-06-14 17:07:02 +02:00
|
|
|
os.makedirs(target_dir)
|
2003-06-23 18:54:12 +02:00
|
|
|
print "Will place Makefile, crt0.S, etc. in %s" % target_dir
|
2003-07-11 16:51:29 +02:00
|
|
|
root = partobj(target_dir, 0, 'board', targ_name)
|
2003-06-23 18:54:12 +02:00
|
|
|
curpart = root
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def part(name, path, file):
|
2003-06-23 18:54:12 +02:00
|
|
|
global curpart,curdir,treetop
|
2003-06-14 17:07:02 +02:00
|
|
|
dirstack.append(curdir)
|
|
|
|
curdir = os.path.join(treetop, 'src', name, path)
|
2003-07-11 16:51:29 +02:00
|
|
|
newpart = partobj(curdir, curpart, name, path)
|
2003-07-14 20:00:10 +02:00
|
|
|
print "Configuring PART %s, path %s" % (name,path)
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "PUSH part %s %s" % (name, curpart.dir)
|
2003-06-14 17:07:02 +02:00
|
|
|
pstack.push(curpart)
|
|
|
|
curpart = newpart
|
|
|
|
doconfigfile(curdir, file)
|
|
|
|
|
|
|
|
def partpop():
|
|
|
|
global curpart,curdir
|
2003-06-24 01:52:15 +02:00
|
|
|
print "End PART %s" % curpart.type
|
|
|
|
# Warn if options are used without being set in this part
|
|
|
|
for i in curpart.options.keys():
|
|
|
|
if (not isset(i, curpart)):
|
|
|
|
print "WARNING: Option %s using default value %s" % (i, getformated(i, curpart))
|
2003-06-14 17:07:02 +02:00
|
|
|
curpart = pstack.pop()
|
|
|
|
curdir = dirstack.pop()
|
|
|
|
|
|
|
|
# dodir is like part but there is no new part
|
|
|
|
def dodir(path, file):
|
|
|
|
global curdir, treetop
|
|
|
|
# if the first char is '/', it is relative to treetop,
|
|
|
|
# else relative to curdir
|
|
|
|
# os.path.join screws up if the name starts with '/', sigh.
|
|
|
|
if (path[0] == '/'):
|
|
|
|
fullpath = treetop + '/src/' + path
|
|
|
|
else:
|
|
|
|
fullpath = os.path.join(curdir, path)
|
|
|
|
if (debug):
|
2003-06-23 18:54:12 +02:00
|
|
|
print "DODIR: path %s, fullpath %s" % (path, fullpath)
|
|
|
|
print "DODIR: curdis %s treetop %s" % (curdir, treetop)
|
2003-06-24 01:52:15 +02:00
|
|
|
print "Configuring DIR %s" % os.path.join(path, file)
|
2003-06-14 17:07:02 +02:00
|
|
|
dirstack.append(curdir)
|
|
|
|
curdir = fullpath
|
|
|
|
file = os.path.join(fullpath, file)
|
2003-06-24 21:37:05 +02:00
|
|
|
config_file_list.append(file)
|
2003-06-14 17:07:02 +02:00
|
|
|
doconfigfile(fullpath, file)
|
|
|
|
curdir = dirstack.pop()
|
|
|
|
|
2003-06-24 19:26:45 +02:00
|
|
|
def lookup(name):
|
2003-07-10 22:55:09 +02:00
|
|
|
global curpart
|
|
|
|
v = getoption(name, curpart)
|
|
|
|
exitiferrors()
|
|
|
|
return v
|
2003-06-24 19:26:45 +02:00
|
|
|
|
|
|
|
def ternary(val, yes, no):
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "ternary %s" % expr
|
|
|
|
if (debug):
|
|
|
|
print "expr %s a %d yes %d no %d"% (expr, a, yes, no)
|
2003-06-24 19:26:45 +02:00
|
|
|
if (val == 0):
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "Ternary returns %d" % yes
|
|
|
|
return yes
|
2003-06-14 17:07:02 +02:00
|
|
|
else:
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "Ternary returns %d" % no
|
|
|
|
return no
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
# atoi is in the python library, but not strtol? Weird!
|
|
|
|
def tohex(name):
|
|
|
|
return eval('int(%s)' % name)
|
|
|
|
|
|
|
|
def IsInt( str ):
|
|
|
|
""" Is the given string an integer?"""
|
|
|
|
try:
|
|
|
|
num = int(str)
|
|
|
|
return 1
|
|
|
|
except ValueError:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def addrule(id):
|
|
|
|
o = makerule(id)
|
|
|
|
setvalue(makebaserules, id, o)
|
|
|
|
|
|
|
|
def adduserdefine(str):
|
|
|
|
userdefines.append(str)
|
|
|
|
|
|
|
|
def dequote(str):
|
|
|
|
a = re.sub("^\"", "", str)
|
|
|
|
a = re.sub("\"$", "", a)
|
|
|
|
# highly un-intuitive, need four \!
|
|
|
|
a = re.sub("\\\\\"", "\"", a)
|
|
|
|
return a
|
|
|
|
|
2003-07-11 16:51:29 +02:00
|
|
|
def flatten_name(str):
|
|
|
|
a = re.sub("/", "_", str)
|
|
|
|
return a
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
def addaction(id, str):
|
|
|
|
o = getvalue(makebaserules, id)
|
2003-07-14 20:00:10 +02:00
|
|
|
if (o):
|
|
|
|
a = dequote(str)
|
|
|
|
o.addaction(a)
|
|
|
|
return
|
|
|
|
fatal("No such rule \"%s\" for addaction" % id);
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
def adddep(id, str):
|
|
|
|
o = getvalue(makebaserules, id)
|
2003-07-14 20:00:10 +02:00
|
|
|
if (o):
|
|
|
|
a = dequote(str)
|
|
|
|
o.adddependency(a)
|
|
|
|
return
|
|
|
|
fatal("No such rule \"%s\" for adddependency" % id);
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# If the first part of <path> matches treetop, replace that part with "$(TOP)"
|
|
|
|
def topify(path):
|
|
|
|
global treetop
|
|
|
|
if path[0:len(treetop)] == treetop:
|
|
|
|
path = path[len(treetop):len(path)]
|
|
|
|
if (path[0:1] == "/"):
|
|
|
|
path = path[1:len(path)]
|
|
|
|
path = "$(TOP)/" + path
|
|
|
|
return path
|
|
|
|
|
|
|
|
# arch is 'different' ... darn it.
|
|
|
|
def set_arch(my_arch):
|
2003-06-23 18:54:12 +02:00
|
|
|
global arch
|
2003-06-14 17:07:02 +02:00
|
|
|
global curdir
|
|
|
|
arch = my_arch
|
2003-06-23 18:54:12 +02:00
|
|
|
setoption('ARCH', my_arch)
|
2003-07-14 20:00:10 +02:00
|
|
|
#part('arch', my_arch, 'config/make.base.lb')
|
|
|
|
part('arch', my_arch, 'Config.lb')
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def mainboard(path):
|
2003-06-23 18:54:12 +02:00
|
|
|
global mainboard_dir, treetop
|
2003-06-14 17:07:02 +02:00
|
|
|
mainboard_dir = path
|
|
|
|
full_mainboard_dir = os.path.join(treetop, 'src/mainboard', path)
|
2003-06-23 18:54:12 +02:00
|
|
|
setoption('MAINBOARD', full_mainboard_dir)
|
2003-06-14 17:07:02 +02:00
|
|
|
vendor = re.sub("/.*", "", path)
|
|
|
|
mainboard_part_number = re.sub("[^/]/", "", path)
|
2003-06-23 18:54:12 +02:00
|
|
|
setoption('MAINBOARD_VENDOR', vendor)
|
|
|
|
setoption('MAINBOARD_PART_NUMBER', mainboard_part_number)
|
2003-07-14 20:00:10 +02:00
|
|
|
dodir('/config', 'Config.lb')
|
2003-06-14 17:07:02 +02:00
|
|
|
part('mainboard', path, 'Config.lb')
|
2003-06-23 18:54:12 +02:00
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
#=============================================================================
|
|
|
|
# FILE OUTPUT
|
|
|
|
#=============================================================================
|
|
|
|
def writemakefileheader(file, fname):
|
|
|
|
file.write("# File: %s\n" % fname)
|
|
|
|
file.write("# This file was generated by '%s %s %s'\n\n"
|
|
|
|
% (sys.argv[0], sys.argv[1], sys.argv[2]))
|
|
|
|
|
|
|
|
|
|
|
|
def writemakefilesettings(path):
|
2003-07-14 20:00:10 +02:00
|
|
|
global treetop, arch, mainboard_dir, target_dir, root
|
|
|
|
global options_by_order, options
|
2003-06-14 17:07:02 +02:00
|
|
|
# Write Makefile.settings to seperate the settings
|
|
|
|
# from the actual makefile creation
|
|
|
|
# In practice you need to rerun NLBConfig.py to change
|
|
|
|
# these but in theory you shouldn't need to.
|
|
|
|
|
|
|
|
filename = os.path.join(path, "Makefile.settings")
|
|
|
|
print "Creating", filename
|
|
|
|
file = open(filename, 'w+')
|
|
|
|
writemakefileheader(file, filename)
|
|
|
|
file.write("TOP:=%s\n" % (treetop))
|
|
|
|
#file.write("ARCH:=%s\n" % (arch))
|
|
|
|
#file.write("MAINBOARD:=%s\n" % (mainboard_dir))
|
|
|
|
file.write("TARGET_DIR:=%s\n" % (target_dir))
|
|
|
|
for i in options_by_order:
|
2003-06-23 18:54:12 +02:00
|
|
|
if (isexported(i, 0)):
|
|
|
|
file.write("export %s:=%s\n" % (i, getformated(i, 0)))
|
|
|
|
file.write("export VARIABLES := ")
|
2003-06-14 17:07:02 +02:00
|
|
|
for i in options.keys():
|
2003-06-23 18:54:12 +02:00
|
|
|
if (isexported(i, 0)):
|
|
|
|
file.write("%s " % i)
|
|
|
|
file.write("\n")
|
|
|
|
# file.write("CPUFLAGS := ")
|
2003-06-14 17:07:02 +02:00
|
|
|
# for i in options.keys():
|
|
|
|
# o = options[i]
|
|
|
|
# file.write("-D%s=%s " % (i, o.getvalue()))
|
2003-06-23 18:54:12 +02:00
|
|
|
# file.write("\n")
|
|
|
|
file.close()
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
# write the makefile
|
|
|
|
# let's try the Makefile
|
|
|
|
# first, dump all the -D stuff
|
|
|
|
|
|
|
|
def writemakefile(path):
|
2003-07-14 20:00:10 +02:00
|
|
|
global root, useinitincludes
|
2003-06-14 17:07:02 +02:00
|
|
|
makefilepath = os.path.join(path, "Makefile")
|
|
|
|
print "Creating", makefilepath
|
|
|
|
file = open(makefilepath, 'w+')
|
|
|
|
writemakefileheader(file, makefilepath)
|
|
|
|
|
|
|
|
# file.write("include Makefile.settings\n")
|
|
|
|
# file.write("include cpuflags\n")
|
|
|
|
# Putting "include cpuflags" in the Makefile has the problem that the
|
|
|
|
# cpuflags file would be generated _after_ we want to include it.
|
|
|
|
# Instead, let make do the work of computing CPUFLAGS:
|
|
|
|
file.write("""\
|
|
|
|
# Get the value of TOP, VARIABLES, and several other variables.
|
|
|
|
include Makefile.settings
|
|
|
|
|
|
|
|
# Function to create an item like -Di586 or -DMAX_CPUS='1' or -Ui686
|
|
|
|
D_item = $(if $(subst undefined,,$(origin $1)),-D$1$(if $($1),='$($1)',),-U$1)
|
|
|
|
|
|
|
|
# Compute the value of CPUFLAGS here during make's first pass.
|
|
|
|
CPUFLAGS := $(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))
|
|
|
|
""")
|
|
|
|
|
|
|
|
for i in userdefines:
|
|
|
|
file.write("%s\n" %i)
|
2003-06-23 18:54:12 +02:00
|
|
|
file.write("\n")
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-06-30 19:29:31 +02:00
|
|
|
# main rule
|
|
|
|
file.write("all: linuxbios.rom")
|
2003-06-14 17:07:02 +02:00
|
|
|
# print out all the object dependencies
|
|
|
|
file.write("\n# object dependencies (objectrules:)\n")
|
2003-07-14 20:00:10 +02:00
|
|
|
file.write("INIT-OBJECTS :=\n")
|
2003-06-14 17:07:02 +02:00
|
|
|
file.write("OBJECTS :=\n")
|
2003-06-25 00:51:16 +02:00
|
|
|
file.write("DRIVER :=\n")
|
2003-06-30 19:04:35 +02:00
|
|
|
file.write("\nSOURCES :=\n")
|
2003-07-14 20:00:10 +02:00
|
|
|
for irule in initobjectrules.keys():
|
|
|
|
init = initobjectrules[irule]
|
|
|
|
i_name = init[0]
|
|
|
|
i_source = init[1]
|
|
|
|
file.write("INIT-OBJECTS += %s\n" % (i_name))
|
|
|
|
file.write("SOURCES += %s\n" % (i_source))
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
for objrule in objectrules.keys():
|
|
|
|
obj = objectrules[objrule]
|
|
|
|
obj_name = obj[0]
|
|
|
|
obj_source = obj[1]
|
|
|
|
file.write("OBJECTS-1 += %s\n" % (obj_name))
|
2003-06-30 19:04:35 +02:00
|
|
|
file.write("SOURCES += %s\n" % (obj_source))
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
for driverrule in driverrules.keys():
|
|
|
|
driver = driverrules[driverrule]
|
|
|
|
obj_name = driver[0]
|
|
|
|
obj_source = driver[1]
|
|
|
|
file.write("DRIVER += %s\n" % (obj_name))
|
2003-06-30 19:04:35 +02:00
|
|
|
file.write("SOURCES += %s\n" % (obj_source))
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# Print out all ldscript.ld dependencies.
|
|
|
|
file.write("\n# ldscript.ld dependencies:\n")
|
|
|
|
file.write("LDSUBSCRIPTS-1 := \n" )
|
|
|
|
for script in ldscripts:
|
|
|
|
file.write("LDSUBSCRIPTS-1 += %s\n" % topify(script))
|
|
|
|
|
|
|
|
# Print out the dependencies for crt0_includes.h
|
|
|
|
file.write("\n# Dependencies for crt0_includes.h\n")
|
|
|
|
file.write("CRT0_INCLUDES:=\n")
|
2003-07-14 20:00:10 +02:00
|
|
|
if (useinitincludes):
|
|
|
|
for inc in initincludes.keys():
|
|
|
|
if (local_path.match(inc)):
|
|
|
|
file.write("CRT0_INCLUDES += %s\n" % inc)
|
|
|
|
else:
|
|
|
|
file.write("CRT0_INCLUDES += $(TOP)/src/%s\n" % inc)
|
|
|
|
else:
|
|
|
|
for i in crt0includes:
|
|
|
|
if (local_path.match(i)):
|
|
|
|
file.write("CRT0_INCLUDES += %s\n" % i)
|
|
|
|
else:
|
|
|
|
file.write("CRT0_INCLUDES += $(TOP)/src/%s\n" % i)
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# Print out the user defines.
|
|
|
|
file.write("\n# userdefines:\n")
|
|
|
|
#for udef in userdefines:
|
|
|
|
#file.write("%s\n" % udef)
|
|
|
|
|
|
|
|
# Print out the base rules.
|
|
|
|
# Need to have a rule that counts on 'all'.
|
|
|
|
file.write("\n# mainrulelist:")
|
|
|
|
#file.write("\nmainrule: %s\n" % mainrulelist)
|
|
|
|
|
|
|
|
# Print out any user rules.
|
|
|
|
file.write("\n# From makerule or docipl commands:\n")
|
|
|
|
# Old way (hash order): for target in makebaserules.keys():
|
|
|
|
# New way (config file order):
|
|
|
|
#for target in makerule_targets:
|
|
|
|
#makebaserules[target].write(file)
|
|
|
|
|
|
|
|
file.write("\n# objectrules:\n")
|
|
|
|
for objrule in objectrules.keys():
|
|
|
|
obj = objectrules[objrule]
|
|
|
|
source = topify(obj[1])
|
|
|
|
file.write("%s: %s\n" % (obj[0], source))
|
|
|
|
file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
|
|
|
|
#file.write("%s\n" % objrule[2])
|
|
|
|
|
|
|
|
for driverrule in driverrules.keys():
|
|
|
|
driver = driverrules[driverrule]
|
|
|
|
source = topify(driver[1])
|
|
|
|
file.write("%s: %s\n" % (driver[0], source))
|
2003-06-25 00:51:16 +02:00
|
|
|
file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
|
2003-06-14 17:07:02 +02:00
|
|
|
#file.write("%s\n" % objrule[2])
|
|
|
|
|
|
|
|
# Print out the rules that will make cause the files
|
|
|
|
# generated by NLBConfig.py to be remade if any dependencies change.
|
|
|
|
|
|
|
|
file.write("\n# Remember the automatically generated files\n")
|
|
|
|
file.write("GENERATED:=\n")
|
|
|
|
for genfile in [ 'Makefile',
|
|
|
|
'Makefile.settings',
|
|
|
|
'nsuperio.c',
|
|
|
|
'chip.c',
|
|
|
|
'LinuxBIOSDoc.config' ]:
|
|
|
|
file.write("GENERATED += %s\n" % genfile)
|
2003-07-14 20:00:10 +02:00
|
|
|
if (useinitincludes):
|
|
|
|
file.write("GENERATED += crt0.S\n")
|
|
|
|
else:
|
|
|
|
file.write("GENERATED += crt0_includes.h\n")
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
file.write("\n# Remake Makefile (and the other files generated by\n")
|
|
|
|
file.write("# NLBConfig.py) if any config dependencies change.\n")
|
|
|
|
|
|
|
|
for cfile in config_file_list:
|
|
|
|
file.write("$(GENERATED): %s\n" % topify(cfile))
|
|
|
|
|
|
|
|
for depfile in [ '%s' % top_config_file, # This a duplicate, remove?
|
|
|
|
'$(TOP)/util/config/NLBConfig.py',
|
|
|
|
'$(TOP)/src/arch/$(ARCH)/config/make.base' ]:
|
|
|
|
file.write("$(GENERATED): %s\n" % depfile)
|
|
|
|
|
|
|
|
file.write("$(GENERATED):\n")
|
|
|
|
file.write("\tpython $(TOP)/util/config/NLBConfig.py %s $(TOP)\n"
|
|
|
|
% top_config_file)
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
keys = root.options.keys()
|
2003-06-14 17:07:02 +02:00
|
|
|
keys.sort()
|
|
|
|
file.write("\necho:\n")
|
|
|
|
for key in keys:
|
|
|
|
file.write("\t@echo %s='$(%s)'\n"% (key,key))
|
|
|
|
|
|
|
|
|
|
|
|
for i in makebaserules.keys():
|
|
|
|
m = makebaserules[i]
|
|
|
|
file.write("%s: " %i)
|
|
|
|
for i in m.dependency:
|
|
|
|
file.write("%s " % i)
|
|
|
|
file.write("\n")
|
|
|
|
for i in m.actions:
|
|
|
|
file.write("\t%s\n" % i)
|
2003-06-23 18:54:12 +02:00
|
|
|
file.close()
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# Write out crt0_includes.h (top-level assembly language) include file.
|
|
|
|
def writecrt0_includes(path):
|
|
|
|
crt0filepath = os.path.join(path, "crt0_includes.h")
|
|
|
|
print "Creating", crt0filepath
|
|
|
|
file = open(crt0filepath, 'w+')
|
|
|
|
for i in crt0includes:
|
|
|
|
file.write("#include <%s>\n" % i)
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
file.close()
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
def writeinitincludes(path):
|
|
|
|
global initfile, include_pattern, crt0_includes
|
|
|
|
crt0filepath = os.path.join(path, "crt0.S")
|
|
|
|
print "Creating", crt0filepath
|
|
|
|
infile = open(initfile, 'r')
|
|
|
|
outfile = open(crt0filepath, 'w+')
|
|
|
|
|
|
|
|
line = infile.readline()
|
|
|
|
while (line):
|
|
|
|
p = include_pattern.match(line)
|
|
|
|
if (p):
|
|
|
|
for i in initincludes.keys():
|
|
|
|
inc = initincludes[i]
|
|
|
|
if (inc.getstring() == p.group(1)):
|
|
|
|
outfile.write("#include \"%s\"\n" % inc.getpath())
|
|
|
|
else:
|
|
|
|
outfile.write(line);
|
|
|
|
line = infile.readline()
|
|
|
|
|
|
|
|
infile.close()
|
|
|
|
outfile.close()
|
|
|
|
|
|
|
|
def writeldoptions(path):
|
|
|
|
global options
|
|
|
|
# Write Makefile.settings to seperate the settings
|
|
|
|
# from the actual makefile creation
|
|
|
|
# In practice you need to rerun NLBConfig.py to change
|
|
|
|
# these but in theory you shouldn't need to.
|
|
|
|
|
|
|
|
filename = os.path.join(path, "ldoptions")
|
|
|
|
print "Creating", filename
|
|
|
|
file = open(filename, 'w+')
|
|
|
|
for i in options.keys():
|
|
|
|
if (isexported(i, 0) and IsInt(getoption(i, 0))):
|
|
|
|
file.write("%s = %s;\n" % (i, getformated(i, 0)))
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
# Add any run-time checks to verify that parsing the configuration
|
|
|
|
# was successful
|
|
|
|
def verifyparse():
|
|
|
|
global useinitincludes, initfile
|
|
|
|
if (useinitincludes and initfile == ''):
|
|
|
|
fatal("An init file must be specified")
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
%%
|
|
|
|
parser Config:
|
2003-06-23 18:54:12 +02:00
|
|
|
ignore: r'\s+'
|
|
|
|
ignore: "#.*?\r?\n"
|
|
|
|
|
|
|
|
# less general tokens should come first, otherwise they get matched
|
|
|
|
# by the re's
|
2003-07-14 20:00:10 +02:00
|
|
|
token ACTION: 'action'
|
2003-06-23 18:54:12 +02:00
|
|
|
token ADDACTION: 'addaction'
|
|
|
|
token ALWAYS: 'always'
|
|
|
|
token ARCH: 'arch'
|
|
|
|
token COMMENT: 'comment'
|
|
|
|
token CPU: 'cpu'
|
|
|
|
token DEFAULT: 'default'
|
|
|
|
token DEFINE: 'define'
|
2003-07-14 20:00:10 +02:00
|
|
|
token DEPENDS: 'depends'
|
2003-06-23 18:54:12 +02:00
|
|
|
token DIR: 'dir'
|
|
|
|
token DRIVER: 'driver'
|
2003-06-24 19:37:02 +02:00
|
|
|
token ELSE: 'else'
|
2003-06-23 18:54:12 +02:00
|
|
|
token END: '$|end'
|
|
|
|
token EQ: '='
|
|
|
|
token EXPORT: 'export'
|
|
|
|
token FORMAT: 'format'
|
|
|
|
token IF: 'if'
|
|
|
|
token INIT: 'init'
|
2003-07-14 20:00:10 +02:00
|
|
|
token INITOBJECT: 'initobject'
|
|
|
|
token INITINCLUDE: 'initinclude'
|
2003-06-23 18:54:12 +02:00
|
|
|
token LDSCRIPT: 'ldscript'
|
|
|
|
token LOADOPTIONS: 'loadoptions'
|
|
|
|
token MAINBOARD: 'mainboard'
|
|
|
|
token MAINBOARDINIT: 'mainboardinit'
|
|
|
|
token MAKEDEFINE: 'makedefine'
|
|
|
|
token MAKERULE: 'makerule'
|
|
|
|
token NEVER: 'never'
|
|
|
|
token NONE: 'none'
|
|
|
|
token NORTHBRIDGE: 'northbridge'
|
|
|
|
token OBJECT: 'object'
|
|
|
|
token OPTION: 'option'
|
|
|
|
token PAYLOAD: 'payload'
|
|
|
|
token PMC: 'pmc'
|
2003-06-25 05:20:22 +02:00
|
|
|
token PRINT: 'print'
|
2003-06-23 18:54:12 +02:00
|
|
|
token REGISTER: 'register'
|
|
|
|
token SOUTHBRIDGE: 'southbridge'
|
|
|
|
token SUPERIO: 'superio'
|
|
|
|
token TARGET: 'target'
|
|
|
|
token USED: 'used'
|
|
|
|
token USES: 'uses'
|
|
|
|
token NUM: r'[0-9]+'
|
|
|
|
token XNUM: r'0x[0-9a-fA-F]+'
|
|
|
|
# Why is path separate? Because paths to resources have to at least
|
|
|
|
# have a slash, we thinks
|
|
|
|
token PATH: r'[a-zA-Z0-9_.][a-zA-Z0-9/_.]+[a-zA-Z0-9_.]+'
|
|
|
|
# Dir's on the other hand are abitrary
|
|
|
|
# this may all be stupid.
|
2003-07-14 20:00:10 +02:00
|
|
|
token DIRPATH: r'[-a-zA-Z0-9_$()./]+'
|
2003-06-23 18:54:12 +02:00
|
|
|
token ID: r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
|
|
|
|
token DELEXPR: r'{([^}]+|\\.)*}'
|
|
|
|
token STR: r'"([^\\"]+|\\.)*"'
|
|
|
|
token RAWTEXT: r'.*'
|
|
|
|
|
2003-06-24 19:26:45 +02:00
|
|
|
rule expr: logical {{ l = logical }}
|
|
|
|
( "&&" logical {{ l = l and logical }}
|
|
|
|
| "||" logical {{ l = l or logical }}
|
2003-06-23 18:54:12 +02:00
|
|
|
)* {{ return l }}
|
|
|
|
|
2003-06-24 19:26:45 +02:00
|
|
|
rule logical: factor {{ n = factor }}
|
|
|
|
( "[+]" factor {{ n = n+factor }}
|
|
|
|
| "-" factor {{ n = n-factor }}
|
2003-06-23 18:54:12 +02:00
|
|
|
)* {{ return n }}
|
|
|
|
|
2003-06-24 19:26:45 +02:00
|
|
|
rule factor: term {{ v = term }}
|
|
|
|
( "[*]" term {{ v = v*term }}
|
|
|
|
| "/" term {{ v = v/term }}
|
|
|
|
| "<<" term {{ v = v << term }}
|
|
|
|
| ">=" term {{ v = (v < term)}}
|
2003-06-23 18:54:12 +02:00
|
|
|
)* {{ return v }}
|
|
|
|
|
2003-06-14 17:07:02 +02:00
|
|
|
# A term is a number, variable, or an expression surrounded by parentheses
|
2003-06-24 19:26:45 +02:00
|
|
|
rule term: NUM {{ return atoi(NUM) }}
|
2003-06-23 18:54:12 +02:00
|
|
|
| XNUM {{ return tohex(XNUM) }}
|
2003-06-24 19:26:45 +02:00
|
|
|
| ID {{ return lookup(ID) }}
|
|
|
|
| unop {{ return unop }}
|
|
|
|
| "\\(" expr "\\)" {{ return expr }}
|
|
|
|
|
|
|
|
rule unop: "!" expr {{ return not(expr) }}
|
2003-06-23 18:54:12 +02:00
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
rule partend<<C>>: (stmt<<C>>)* END {{ partpop()}}
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
rule mainboard: MAINBOARD PATH {{ mainboard(PATH) }}
|
|
|
|
partend<<1>>
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
rule northbridge<<C>>:
|
|
|
|
NORTHBRIDGE PATH {{ if (C): part('northbridge', PATH, 'Config.lb') }}
|
|
|
|
partend<<C>>
|
|
|
|
|
|
|
|
rule superio<<C>>: SUPERIO PATH {{ if (C): part('superio', PATH, 'Config.lb') }}
|
|
|
|
partend<<C>>
|
|
|
|
|
|
|
|
rule cpu<<C>>: CPU ID {{ if (C): part('cpu', ID, 'Config.lb') }}
|
|
|
|
partend<<C>>
|
|
|
|
|
|
|
|
rule pmc<<C>>: PMC PATH {{ if (C): part('pmc', PATH, 'Config.lb') }}
|
|
|
|
partend<<C>>
|
|
|
|
|
|
|
|
rule arch<<C>>: ARCH ID {{ if (C): set_arch(ID) }}
|
|
|
|
partend<<C>>
|
|
|
|
|
|
|
|
rule southbridge<<C>>:
|
|
|
|
SOUTHBRIDGE PATH {{ if (C): part('southbridge', PATH, 'Config.lb')}}
|
|
|
|
partend<<C>>
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
rule mainboardinit<<C>>:
|
2003-06-23 18:54:12 +02:00
|
|
|
MAINBOARDINIT DIRPATH {{ if (C): addcrt0include(DIRPATH)}}
|
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
rule initinclude<<C>>:
|
|
|
|
INITINCLUDE
|
|
|
|
STR
|
|
|
|
DIRPATH {{ if (C): addinitinclude(STR, DIRPATH)}}
|
|
|
|
|
|
|
|
rule initobject<<C>>:
|
|
|
|
INITOBJECT DIRPATH {{ if (C): addinitobject(DIRPATH)}}
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
rule object<<C>>: OBJECT DIRPATH {{ if (C): addobject(DIRPATH)}}
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
rule driver<<C>>: DRIVER DIRPATH {{ if (C): adddriver(DIRPATH)}}
|
|
|
|
|
|
|
|
rule dir<<C>>: DIR DIRPATH {{ if (C): dodir(DIRPATH, 'Config.lb') }}
|
|
|
|
|
|
|
|
rule ldscript<<C>>: LDSCRIPT DIRPATH {{ if (C): addldscript(DIRPATH) }}
|
|
|
|
|
|
|
|
rule payload<<C>>: PAYLOAD DIRPATH {{ if (C): payload(DIRPATH) }}
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# if is a bad id ....
|
|
|
|
# needs to be C and ID, but nested if's are, we hope, not going to
|
|
|
|
# happen. IF so, possibly ID && C could be used.
|
2003-06-24 19:26:45 +02:00
|
|
|
rule iif<<C>>: IF ID {{ c = lookup(ID) }}
|
2003-06-24 19:37:02 +02:00
|
|
|
(stmt<<c>>)* [ ELSE (stmt<<not c>>)* ] END
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
rule depsacts<<ID, C>>:
|
2003-07-14 20:00:10 +02:00
|
|
|
( DEPENDS STR {{ if (C): adddep(ID, STR) }}
|
|
|
|
| ACTION STR {{ if (C): addaction(ID, STR) }}
|
2003-06-14 17:07:02 +02:00
|
|
|
)*
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
rule makerule<<C>>: MAKERULE DIRPATH {{ if (C): addrule(DIRPATH) }}
|
2003-06-14 17:07:02 +02:00
|
|
|
depsacts<<DIRPATH, C>>
|
2003-07-14 20:00:10 +02:00
|
|
|
END
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
rule makedefine<<C>>:
|
|
|
|
MAKEDEFINE RAWTEXT {{ if (C): adduserdefine(RAWTEXT) }}
|
|
|
|
|
|
|
|
rule addaction<<C>>:
|
|
|
|
ADDACTION ID STR {{ if (C): addaction(ID, STR) }}
|
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
rule init<<C>>: INIT DIRPATH {{ if (C): addinit(DIRPATH) }}
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
rule register<<C>>: REGISTER STR {{ if (C): curpart.addregister(STR) }}
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
# to make if work without 2 passses, we use an old hack from SIMD, the
|
|
|
|
# context bit. If the bit is 1, then ops get done, otherwise
|
|
|
|
# ops don't get done. From the top level, context is always
|
|
|
|
# 1. In an if, context depends on eval of the if condition
|
2003-06-23 18:54:12 +02:00
|
|
|
rule stmt<<C>>: cpu<<C>> {{ return cpu}}
|
|
|
|
| pmc<<C>> {{ return pmc}}
|
|
|
|
| arch<<C>> {{ return arch}}
|
|
|
|
| northbridge<<C>> {{ return northbridge }}
|
|
|
|
| southbridge<<C>> {{ return southbridge }}
|
|
|
|
| superio<<C>> {{ return superio }}
|
2003-07-14 20:00:10 +02:00
|
|
|
| initobject<<C>> {{ return initobject }}
|
2003-06-23 18:54:12 +02:00
|
|
|
| object<<C>> {{ return object }}
|
|
|
|
| driver<<C>> {{ return driver }}
|
|
|
|
| mainboardinit<<C>> {{ return mainboardinit }}
|
2003-07-14 20:00:10 +02:00
|
|
|
| initinclude<<C>> {{ return initinclude }}
|
2003-06-23 18:54:12 +02:00
|
|
|
| makerule<<C>> {{ return makerule }}
|
|
|
|
| makedefine<<C>> {{ return makedefine }}
|
|
|
|
| addaction<<C>> {{ return addaction }}
|
|
|
|
| init<<C>> {{ return init }}
|
|
|
|
| register<<C>> {{ return register}}
|
|
|
|
| iif<<C>> {{ return iif }}
|
|
|
|
| dir<<C>> {{ return dir}}
|
|
|
|
| ldscript<<C>> {{ return ldscript}}
|
|
|
|
| payload<<C>> {{ return payload}}
|
2003-07-10 22:55:09 +02:00
|
|
|
| prtstmt<<C>> {{ return prtstmt}}
|
2003-06-23 18:54:12 +02:00
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
# ENTRY for parsing Config.lb file
|
|
|
|
rule cfgfile: (uses<<1>>)* (stmt<<1>>)*
|
|
|
|
{{ return 1 }}
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
rule usesid<<C>>: ID {{ if (C): usesoption(ID) }}
|
|
|
|
|
|
|
|
rule uses<<C>>: USES (usesid<<C>>)+
|
|
|
|
|
|
|
|
rule value: STR {{ return dequote(STR) }}
|
2003-06-24 19:26:45 +02:00
|
|
|
| expr {{ return expr }}
|
2003-06-23 18:54:12 +02:00
|
|
|
| DELEXPR {{ return DELEXPR }}
|
|
|
|
|
2003-06-24 19:26:45 +02:00
|
|
|
rule option<<C>>: OPTION ID EQ value {{ if (C): setoptionstmt(ID, value) }}
|
|
|
|
|
2003-06-25 17:27:41 +02:00
|
|
|
rule opif<<C>>: IF ID {{ c = lookup(ID) }}
|
|
|
|
(opstmt<<C and c>>)*
|
|
|
|
[ ELSE (opstmt<<C and not c>>)* ] END
|
|
|
|
|
|
|
|
rule opstmt<<C>>: option<<C>>
|
|
|
|
| opif<<C>>
|
2003-07-10 22:55:09 +02:00
|
|
|
| prtstmt<<C>>
|
|
|
|
|
|
|
|
rule prtval: expr {{ return str(expr) }}
|
|
|
|
| STR {{ return STR }}
|
|
|
|
|
|
|
|
rule prtlist: prtval {{ el = "%(" + prtval }}
|
|
|
|
( "," prtval {{ el = el + "," + prtval }}
|
|
|
|
)* {{ return el + ")" }}
|
2003-06-24 19:26:45 +02:00
|
|
|
|
2003-07-10 22:55:09 +02:00
|
|
|
rule prtstmt<<C>>: PRINT STR {{ val = STR }}
|
|
|
|
[ "," prtlist {{ val = val + prtlist }}
|
|
|
|
] {{ if (C): print eval(val) }}
|
2003-06-24 19:26:45 +02:00
|
|
|
|
|
|
|
# ENTRY for parsing a delayed value
|
|
|
|
rule delexpr: "{" expr "}" {{ return expr }}
|
2003-06-23 18:54:12 +02:00
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
# ENTRY for parsing root part
|
2003-06-23 18:54:12 +02:00
|
|
|
rule board: LOADOPTIONS {{ loadoptions() }}
|
|
|
|
TARGET DIRPATH {{ target(DIRPATH) }}
|
|
|
|
(uses<<1>>)*
|
2003-06-25 17:27:41 +02:00
|
|
|
(opstmt<<1>>)*
|
2003-06-23 18:54:12 +02:00
|
|
|
mainboard {{ return 1 }}
|
|
|
|
|
|
|
|
rule defstmts<<ID>>: {{ d = 0 }}
|
|
|
|
( DEFAULT
|
|
|
|
( value {{ setdefault(ID, value) }}
|
|
|
|
| NONE {{ setnodefault(ID) }}
|
2003-06-24 05:08:57 +02:00
|
|
|
) {{ d = d | 1 }}
|
2003-06-23 18:54:12 +02:00
|
|
|
| FORMAT STR {{ setformat(ID, dequote(STR)) }}
|
|
|
|
| EXPORT
|
|
|
|
( ALWAYS {{ setexported(ID) }}
|
2003-06-24 01:52:15 +02:00
|
|
|
| USED {{ setexportable(ID) }}
|
2003-06-23 18:54:12 +02:00
|
|
|
| NEVER {{ setnoexport(ID) }}
|
2003-06-24 05:08:57 +02:00
|
|
|
) {{ d = d | 2 }}
|
|
|
|
| COMMENT STR {{ setcomment(ID, dequote(STR)); d = d | 4 }}
|
2003-06-23 18:54:12 +02:00
|
|
|
)+ {{ return d }}
|
|
|
|
|
|
|
|
rule define: DEFINE ID {{ newoption(ID) }}
|
|
|
|
defstmts<<ID>> END {{ validdef(ID, defstmts) }}
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-06-24 01:52:15 +02:00
|
|
|
# ENTRY for parsing Options.lb file
|
2003-06-23 18:54:12 +02:00
|
|
|
rule options: (define)* END {{ return 1 }}
|
2003-06-14 17:07:02 +02:00
|
|
|
%%
|
|
|
|
|
|
|
|
def dumptree(part, lvl):
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "DUMPTREE ME is"
|
2003-06-14 17:07:02 +02:00
|
|
|
part.dumpme(lvl)
|
|
|
|
# dump the siblings -- actually are there any? not sure
|
2003-07-10 14:38:39 +02:00
|
|
|
# siblings are:
|
2003-07-10 16:46:59 +02:00
|
|
|
if (debug):
|
|
|
|
print "DUMPTREE SIBLINGS are"
|
|
|
|
kid = part.siblings
|
|
|
|
while (kid):
|
2003-07-10 14:38:39 +02:00
|
|
|
kid.dumpme(lvl)
|
|
|
|
kid = kid.siblings
|
2003-06-14 17:07:02 +02:00
|
|
|
# dump the kids
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "DUMPTREE KIDS are"
|
2003-07-10 14:38:39 +02:00
|
|
|
#for kid in part.children:
|
|
|
|
if (part.children):
|
|
|
|
dumptree(part.children, lvl+1)
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "DONE DUMPTREE"
|
2003-06-14 17:07:02 +02:00
|
|
|
|
2003-07-10 14:38:39 +02:00
|
|
|
def gencode(part, file):
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "GENCODE ME is"
|
2003-07-10 14:38:39 +02:00
|
|
|
part.gencode(file)
|
2003-06-14 17:07:02 +02:00
|
|
|
# dump the siblings -- actually are there any? not sure
|
|
|
|
# dump the kids
|
2003-07-10 16:46:59 +02:00
|
|
|
if (debug):
|
2003-07-11 16:51:29 +02:00
|
|
|
print "GENCODE SIBLINGS are"
|
|
|
|
kid = part.siblings
|
|
|
|
while (kid):
|
2003-07-10 14:38:39 +02:00
|
|
|
kid.gencode(file)
|
|
|
|
kid = kid.siblings
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "GENCODE KIDS are"
|
2003-07-10 14:38:39 +02:00
|
|
|
#for kid in part.children:
|
|
|
|
if (part.children):
|
|
|
|
gencode(part.children, file)
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "DONE GENCODE"
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def doconfigfile(path, file):
|
|
|
|
filename = os.path.join(path, file)
|
2003-06-23 18:54:12 +02:00
|
|
|
loc.push_file(filename)
|
2003-06-24 01:52:15 +02:00
|
|
|
if (not parse('cfgfile', open(filename, 'r').read())):
|
2003-06-23 18:54:12 +02:00
|
|
|
fatal("Error: Could not parse file")
|
2003-06-24 19:26:45 +02:00
|
|
|
exitiferrors()
|
2003-06-14 17:07:02 +02:00
|
|
|
|
|
|
|
if __name__=='__main__':
|
2003-06-23 18:54:12 +02:00
|
|
|
from sys import argv
|
|
|
|
if (len(argv) < 3):
|
|
|
|
print 'Args: <file> <path to linuxbios>'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
top_config_file = os.path.abspath(sys.argv[1])
|
|
|
|
|
|
|
|
treetop = os.path.abspath(sys.argv[2])
|
|
|
|
|
|
|
|
# Now read in the customizing script...
|
|
|
|
loc.push_file(argv[1])
|
|
|
|
if (not parse('board', open(argv[1], 'r').read())):
|
|
|
|
fatal("Error: Could not parse file")
|
|
|
|
|
2003-07-14 20:00:10 +02:00
|
|
|
verifyparse()
|
|
|
|
|
2003-06-23 18:54:12 +02:00
|
|
|
if (debug):
|
|
|
|
print "DEVICE TREE:"
|
|
|
|
dumptree(root, 0)
|
|
|
|
|
2003-07-10 14:38:39 +02:00
|
|
|
filename = os.path.join(target_dir, "chips.c")
|
|
|
|
print "Creating", filename
|
|
|
|
file = open(filename, 'w+')
|
2003-07-11 16:51:29 +02:00
|
|
|
# gen all the forward references
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
file.write("struct chip ")
|
|
|
|
while (i <= partinstance):
|
|
|
|
file.write("cdev%d "% i)
|
|
|
|
i = i + 1
|
|
|
|
file.write(";\n")
|
2003-07-10 14:38:39 +02:00
|
|
|
gencode(root, file)
|
2003-07-11 16:51:29 +02:00
|
|
|
file.close()
|
2003-06-23 18:54:12 +02:00
|
|
|
|
|
|
|
# crt0 includes
|
|
|
|
if (debug):
|
|
|
|
for i in crt0includes:
|
|
|
|
print "crt0include file %s" % (i)
|
|
|
|
for i in driverrules.keys():
|
|
|
|
print "driver file %s" % (i)
|
|
|
|
for i in ldscripts:
|
|
|
|
print "ldscript file %s" % (i)
|
|
|
|
for i in makebaserules.keys():
|
|
|
|
m = makebaserules[i]
|
|
|
|
print " makerule %s dep %s act %s" % (i, m.dependency, m.actions)
|
|
|
|
|
|
|
|
writemakefilesettings(target_dir)
|
2003-07-14 20:00:10 +02:00
|
|
|
if (useinitincludes):
|
|
|
|
writeinitincludes(target_dir)
|
|
|
|
else:
|
|
|
|
writecrt0_includes(target_dir)
|
2003-06-23 18:54:12 +02:00
|
|
|
writemakefile(target_dir)
|
2003-07-14 20:00:10 +02:00
|
|
|
writeldoptions(target_dir)
|