fix problems with options, more functionality
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@981 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
@@ -118,11 +118,14 @@ class romimage:
|
|||||||
self.partinstance = 0
|
self.partinstance = 0
|
||||||
self.root = 0
|
self.root = 0
|
||||||
self.target_dir = ''
|
self.target_dir = ''
|
||||||
self.values = {}
|
self.values = {} # values of options set in romimage
|
||||||
|
|
||||||
def getname(self):
|
def getname(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def getvalues(self):
|
||||||
|
return self.values
|
||||||
|
|
||||||
def setarch(self, arch):
|
def setarch(self, arch):
|
||||||
self.arch = arch
|
self.arch = arch
|
||||||
|
|
||||||
@@ -286,12 +289,10 @@ class romimage:
|
|||||||
def gettargetdir(self):
|
def gettargetdir(self):
|
||||||
return self.targetdir
|
return self.targetdir
|
||||||
|
|
||||||
def getvalues(self):
|
|
||||||
return self.values
|
|
||||||
|
|
||||||
# A buildrom statement
|
# A buildrom statement
|
||||||
class buildrom:
|
class buildrom:
|
||||||
def __init__ (self, size, roms):
|
def __init__ (self, payload, size, roms):
|
||||||
|
self.payload = payload
|
||||||
self.size = size
|
self.size = size
|
||||||
self.roms = roms
|
self.roms = roms
|
||||||
|
|
||||||
@@ -377,16 +378,22 @@ class option:
|
|||||||
#self.value = value
|
#self.value = value
|
||||||
setdict(values, self.name, value)
|
setdict(values, self.name, value)
|
||||||
|
|
||||||
def getvalue(self, values):
|
def getvalue(self, image, values):
|
||||||
#global curpart
|
global curimage
|
||||||
v = getdict(values, self.name)
|
v = getdict(values, self.name)
|
||||||
if (not (type(v) is str)):
|
if (v == 0):
|
||||||
|
return 0
|
||||||
|
val = v.contents()
|
||||||
|
if (not (type(val) is str)):
|
||||||
return v
|
return v
|
||||||
if (v == '' or v[0] != '{'):
|
if (val == '' or val[0] != '{'):
|
||||||
return v
|
return v
|
||||||
v = parse('delexpr', v)
|
s = curimage
|
||||||
|
curimage = image
|
||||||
|
val = parse('delexpr', val)
|
||||||
|
curimage = s
|
||||||
# TODO: need to check for parse errors!
|
# TODO: need to check for parse errors!
|
||||||
return v
|
return option_value(val)
|
||||||
|
|
||||||
def setdefault(self, value, loc):
|
def setdefault(self, value, loc):
|
||||||
global global_option_values
|
global global_option_values
|
||||||
@@ -447,6 +454,13 @@ class option:
|
|||||||
# def isused(self):
|
# def isused(self):
|
||||||
# return (self.used)
|
# return (self.used)
|
||||||
|
|
||||||
|
class option_value:
|
||||||
|
def __init__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def contents(self):
|
||||||
|
return self.value
|
||||||
|
|
||||||
# A configuration part
|
# A configuration part
|
||||||
class partobj:
|
class partobj:
|
||||||
def __init__ (self, image, dir, parent, type, name):
|
def __init__ (self, image, dir, parent, type, name):
|
||||||
@@ -628,10 +642,10 @@ def newoption(name):
|
|||||||
# option must be declared before being used in a part
|
# option must be declared before being used in a part
|
||||||
# if we're not processing a part, then we must
|
# if we're not processing a part, then we must
|
||||||
# be at the top level where all options are available
|
# be at the top level where all options are available
|
||||||
def getoption(name, part):
|
def getoption(name, image):
|
||||||
global global_uses_options, global_option_values
|
global curpart, global_uses_options, global_option_values
|
||||||
if (part):
|
if (curpart):
|
||||||
o = getdict(part.uses_options, name)
|
o = getdict(curpart.uses_options, name)
|
||||||
elif (alloptions):
|
elif (alloptions):
|
||||||
o = getdict(global_options, name)
|
o = getdict(global_options, name)
|
||||||
else:
|
else:
|
||||||
@@ -640,21 +654,22 @@ def getoption(name, part):
|
|||||||
error("Error: Option %s undefined (missing use command?)." % name)
|
error("Error: Option %s undefined (missing use command?)." % name)
|
||||||
return
|
return
|
||||||
v = 0
|
v = 0
|
||||||
if (part):
|
if (image):
|
||||||
v = o.getvalue(part.image.getvalues())
|
v = o.getvalue(image, image.getvalues())
|
||||||
if (v == 0):
|
if (v == 0):
|
||||||
v = o.getvalue(global_option_values)
|
v = o.getvalue(image, global_option_values)
|
||||||
return v
|
return v.contents()
|
||||||
|
|
||||||
def setoption(name, value):
|
def setoption(name, value):
|
||||||
global loc, global_options, global_option_values, curimage
|
global loc, global_options, global_option_values, curimage
|
||||||
o = getdict(global_options, name)
|
o = getdict(global_options, name)
|
||||||
if (o == 0):
|
if (o == 0):
|
||||||
fatal("Error: attempt to set nonexistent option %s" % name)
|
fatal("Error: attempt to set nonexistent option %s" % name)
|
||||||
|
v = option_value(value)
|
||||||
if (curimage):
|
if (curimage):
|
||||||
o.setvalue(value, curimage.getvalues(), loc)
|
o.setvalue(v, curimage.getvalues(), loc)
|
||||||
else:
|
else:
|
||||||
o.setvalue(value, global_option_values, loc)
|
o.setvalue(v, global_option_values, loc)
|
||||||
|
|
||||||
def setdefault(name, value):
|
def setdefault(name, value):
|
||||||
global loc, global_options
|
global loc, global_options
|
||||||
@@ -664,7 +679,8 @@ def setdefault(name, value):
|
|||||||
if (o.default):
|
if (o.default):
|
||||||
print "setdefault: attempt to duplicate default for %s" % name
|
print "setdefault: attempt to duplicate default for %s" % name
|
||||||
return
|
return
|
||||||
o.setdefault(value, loc)
|
v = option_value(value)
|
||||||
|
o.setdefault(v, loc)
|
||||||
|
|
||||||
def setnodefault(name):
|
def setnodefault(name):
|
||||||
global loc, global_options
|
global loc, global_options
|
||||||
@@ -711,18 +727,18 @@ def setformat(name, fmt):
|
|||||||
fatal("setformat: %s not here" % name)
|
fatal("setformat: %s not here" % name)
|
||||||
o.setformat(fmt)
|
o.setformat(fmt)
|
||||||
|
|
||||||
def getformated(name, values):
|
def getformated(name, image):
|
||||||
global global_options, global_option_values
|
global global_options, global_option_values
|
||||||
o = getdict(global_options, name)
|
o = getdict(global_options, name)
|
||||||
if (o == 0 or not o.defined):
|
if (o == 0 or not o.defined):
|
||||||
fatal( "Error: Option %s undefined." % name)
|
fatal( "Error: Option %s undefined." % name)
|
||||||
v = 0
|
v = 0
|
||||||
if (values):
|
if (image):
|
||||||
v = o.getvalue(values)
|
v = o.getvalue(image, image.getvalues())
|
||||||
if (v == 0):
|
if (v == 0):
|
||||||
v = o.getvalue(global_option_values)
|
v = o.getvalue(image, global_option_values)
|
||||||
f = o.getformat()
|
f = o.getformat()
|
||||||
return (f % v)
|
return (f % v.contents())
|
||||||
|
|
||||||
def isexported(name):
|
def isexported(name):
|
||||||
global global_options
|
global global_options
|
||||||
@@ -824,30 +840,36 @@ def addldscript(path):
|
|||||||
curimage.addldscript(fullpath)
|
curimage.addldscript(fullpath)
|
||||||
|
|
||||||
def payload(path):
|
def payload(path):
|
||||||
global curimage
|
global main_payload
|
||||||
adduserdefine("PAYLOAD:=%s"%path)
|
main_payload = path
|
||||||
curimage.addpayload(path)
|
# adduserdefine("PAYLOAD:=%s"%path)
|
||||||
# addrule('payload')
|
# addrule('payload')
|
||||||
# adddep('payload', path)
|
# adddep('payload', path)
|
||||||
# addaction('payload', 'cp $< $@')
|
# addaction('payload', 'cp $< $@')
|
||||||
|
|
||||||
def addromimage(name):
|
def startromimage(name):
|
||||||
global romimages, curimage, curpart, target_dir, target_name
|
global romimages, curimage, curpart, target_dir, target_name
|
||||||
print "Configuring ROMIMAGE %s" % name
|
print "Configuring ROMIMAGE %s" % name
|
||||||
curimage = romimage(name)
|
curimage = romimage(name)
|
||||||
curimage.settargetdir(os.path.join(target_dir, name))
|
curimage.settargetdir(os.path.join(target_dir, name))
|
||||||
o = partobj(curimage, target_dir, 0, 'board', target_name)
|
o = partobj(curimage, target_dir, 0, 'board', target_name)
|
||||||
curimage.setroot(o)
|
curimage.setroot(o)
|
||||||
curpart = o
|
|
||||||
o = getdict(romimages, name)
|
o = getdict(romimages, name)
|
||||||
if (o):
|
if (o):
|
||||||
fatal("romimage %s previously defined" % name)
|
fatal("romimage %s previously defined" % name)
|
||||||
setdict(romimages, name, curimage)
|
setdict(romimages, name, curimage)
|
||||||
|
|
||||||
def addbuildrom(size, roms):
|
def endromimage():
|
||||||
|
global curimage
|
||||||
|
partpop()
|
||||||
|
print "End ROMIMAGE"
|
||||||
|
curimage = 0
|
||||||
|
curpart = 0
|
||||||
|
|
||||||
|
def addbuildrom(payload, size, roms):
|
||||||
global buildroms
|
global buildroms
|
||||||
print "Build ROM size %d" % size
|
print "Build ROM payload %s size %d" % (payload, size)
|
||||||
b = buildrom(size, roms)
|
b = buildrom(payload, size, roms)
|
||||||
buildroms.append(b)
|
buildroms.append(b)
|
||||||
|
|
||||||
def addinitobject(object_name):
|
def addinitobject(object_name):
|
||||||
@@ -891,10 +913,8 @@ def partpop():
|
|||||||
# Warn if options are used without being set in this part
|
# Warn if options are used without being set in this part
|
||||||
for i in curpart.uses_options.keys():
|
for i in curpart.uses_options.keys():
|
||||||
if (not isset(i, curpart)):
|
if (not isset(i, curpart)):
|
||||||
print "WARNING: Option %s using default value %s" % (i, getformated(i, curpart.image.getvalues()))
|
print "WARNING: Option %s using default value %s" % (i, getformated(i, curpart.image))
|
||||||
curpart = pstack.pop()
|
curpart = pstack.pop()
|
||||||
if pstack.empty():
|
|
||||||
curpart = 0
|
|
||||||
curdir = dirstack.pop()
|
curdir = dirstack.pop()
|
||||||
|
|
||||||
# dodir is like part but there is no new part
|
# dodir is like part but there is no new part
|
||||||
@@ -918,11 +938,8 @@ def dodir(path, file):
|
|||||||
curdir = dirstack.pop()
|
curdir = dirstack.pop()
|
||||||
|
|
||||||
def lookup(name):
|
def lookup(name):
|
||||||
global curimage, curpart
|
global curimage
|
||||||
if (curpart):
|
v = getoption(name, curimage)
|
||||||
v = getoption(name, curpart)
|
|
||||||
else:
|
|
||||||
v = getoption(name, 0)
|
|
||||||
exitiferrors()
|
exitiferrors()
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@@ -1236,25 +1253,25 @@ parser Config:
|
|||||||
| prtstmt<<C>>
|
| prtstmt<<C>>
|
||||||
|
|
||||||
|
|
||||||
rule romimage: ROMIMAGE STR {{ addromimage(dequote(STR)) }}
|
rule romimage: ROMIMAGE STR {{ startromimage(dequote(STR)) }}
|
||||||
(option<<1>>)*
|
(opstmt<<1>>)*
|
||||||
MAINBOARD PATH {{ mainboard(PATH) }}
|
MAINBOARD PATH {{ mainboard(PATH) }}
|
||||||
END {{ partpop(); print "End ROMIMAGE" }}
|
END {{ endromimage() }}
|
||||||
|
|
||||||
rule roms: STR {{ s = '(' + STR }}
|
rule roms: STR {{ s = '(' + STR }}
|
||||||
( STR {{ s = s + "," + STR }}
|
( STR {{ s = s + "," + STR }}
|
||||||
)* {{ return eval(s + ')') }}
|
)* {{ return eval(s + ')') }}
|
||||||
|
|
||||||
rule buildrom: BUILDROM expr roms {{ addbuildrom(expr, roms) }}
|
rule buildrom: BUILDROM PATH expr roms {{ addbuildrom(PATH, expr, roms) }}
|
||||||
|
|
||||||
rule romstmts: (romimage)*
|
rule romstmts: romimage
|
||||||
buildrom
|
| buildrom
|
||||||
|
| opstmt<<1>>
|
||||||
|
|
||||||
# ENTRY for parsing root part
|
# ENTRY for parsing root part
|
||||||
rule board: LOADOPTIONS {{ loadoptions() }}
|
rule board: LOADOPTIONS {{ loadoptions() }}
|
||||||
TARGET DIRPATH {{ target(DIRPATH) }}
|
TARGET DIRPATH {{ target(DIRPATH) }}
|
||||||
(uses<<1>>)*
|
(uses<<1>>)*
|
||||||
(opstmt<<1>>)*
|
|
||||||
(romstmts)*
|
(romstmts)*
|
||||||
EOF {{ return 1 }}
|
EOF {{ return 1 }}
|
||||||
|
|
||||||
@@ -1329,7 +1346,7 @@ def writeimagesettings(image):
|
|||||||
file.write("TARGET_DIR:=%s\n" % (image.gettargetdir()))
|
file.write("TARGET_DIR:=%s\n" % (image.gettargetdir()))
|
||||||
for i in global_options_by_order:
|
for i in global_options_by_order:
|
||||||
if (isexported(i)):
|
if (isexported(i)):
|
||||||
file.write("export %s:=%s\n" % (i, getformated(i, image.getvalues())))
|
file.write("export %s:=%s\n" % (i, getformated(i, image)))
|
||||||
file.write("export VARIABLES := ")
|
file.write("export VARIABLES := ")
|
||||||
for i in global_options_by_order:
|
for i in global_options_by_order:
|
||||||
if (isexported(i)):
|
if (isexported(i)):
|
||||||
@@ -1537,8 +1554,8 @@ def writeldoptions(image):
|
|||||||
print "Creating", filename
|
print "Creating", filename
|
||||||
file = open(filename, 'w+')
|
file = open(filename, 'w+')
|
||||||
for i in global_options.keys():
|
for i in global_options.keys():
|
||||||
if (isexported(i) and IsInt(getoption(i, 0))):
|
if (isexported(i) and IsInt(getoption(i, image))):
|
||||||
file.write("%s = %s;\n" % (i, getformated(i, image.getvalues())))
|
file.write("%s = %s;\n" % (i, getformated(i, image)))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# Add any run-time checks to verify that parsing the configuration
|
# Add any run-time checks to verify that parsing the configuration
|
||||||
|
Reference in New Issue
Block a user