global_exported_options = []
romimages = {}
buildroms = []
+rommapping = {}
curimage = 0
+bootblocksize = 0
alloptions = 0 # override uses at top level
local_path = re.compile(r'^\.')
dict = 4
statement = 5
dump = 6
+ gengraph = 7
def __init__(self, *level):
self.__level = level
print str
global debug
-debug = debug_info(debug_info.none)
+debug = debug_info(debug_info.dumptree)
+debug = debug_info(debug_info.object)
# -----------------------------------------------------------------------------
# Error Handling
self.arch = arch
def setpayload(self, payload):
+ global rommapping
self.payload = payload
+ rommapping[self.name] = payload
+
def setinitfile(self, initfile):
self.initfile = initfile
if (object_name[0] == '.'):
source = base + suffix
object = base + '.o'
+ rel_base = base
else:
rel_base = re.sub(treetop, "", os.path.join(dirstack.tos(), base))
source = "$(TOP)/" + rel_base + suffix
rel_base = re.sub("^/", "", rel_base)
object = rel_base + '.o'
- debug.info(debug.object, "add object %s source %s" % (object_name, source))
- l = getdict(dict, base)
+ debug.info(debug.object, "add object %s source %s" % (object, source))
+ l = getdict(dict, rel_base)
if (l):
- warning("object/driver %s previously defined" % base)
- setdict(dict, base, [object, source, type, base])
+ warning("object/driver %s previously defined" % rel_base)
+ setdict(dict, rel_base, [object, source, type, rel_base])
def addinitobjectrule(self, name):
self.addobjectdriver(self.initobjectrules, name)
else:
name = "%s %s" % (name, self.path)
return name
+
+ def graph_name(self):
+ name = "{ {_dev%d|" % self.instance
+ if (self.part):
+ name = "%s%s" % (name, self.part)
+ else:
+ name = "%s%s" % (name, self.chip_or_device)
+ if (self.type_name):
+ name = "%s}|%s}" % (name, self.type_name)
+ else:
+ name = "%s}|%s}" % (name, self.parent.type_name)
+ return name
def dumpme(self, lvl):
"""Dump information about this part for debugging"""
fatal("Invalid device id")
if ((function < 0) or (function > 7)):
fatal("Invalid pci function %s" % function )
- self.set_path(".type=DEVICE_PATH_PCI,.u={.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}" % (slot, function))
+ self.set_path(".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}" % (slot, function))
def addpnppath(self, port, device):
""" Add a relative path to a pnp device hanging off our parent """
fatal("Invalid port")
if ((device < 0) or (device > 0xffff)):
fatal("Invalid device")
- self.set_path(".type=DEVICE_PATH_PNP,.u={.pnp={ .port = 0x%x, .device = 0x%x }}" % (port, device))
+ self.set_path(".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}" % (port, device))
def addi2cpath(self, device):
""" Add a relative path to a i2c device hanging off our parent """
if ((device < 0) or (device > 0x7f)):
fatal("Invalid device")
- self.set_path(".type=DEVICE_PATH_I2C,.u={.i2c={ .device = 0x%x }}" % (device))
+ self.set_path(".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}" % (device))
def addapicpath(self, apic_id):
""" Add a relative path to a cpu device hanging off our parent """
if ((apic_id < 0) or (apic_id > 255)):
fatal("Invalid device")
- self.set_path(".type=DEVICE_PATH_APIC,.u={.apic={ .apic_id = 0x%x }}" % (apic_id))
+ self.set_path(".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}" % (apic_id))
def addpci_domainpath(self, pci_domain):
""" Add a pci_domain number to a chip """
if ((pci_domain < 0) or (pci_domain > 0xffff)):
fatal("Invalid pci_domain: 0x%x is out of the range 0 to 0xffff" % pci_domain)
- self.set_path(".type=DEVICE_PATH_PCI_DOMAIN,.u={.pci_domain={ .domain = 0x%x }}" % (pci_domain))
+ self.set_path(".type=DEVICE_PATH_PCI_DOMAIN,{.pci_domain={ .domain = 0x%x }}" % (pci_domain))
def addapic_clusterpath(self, cluster):
""" Add an apic cluster to a chip """
if ((cluster < 0) or (cluster > 15)):
fatal("Invalid apic cluster: %d is out of the range 0 to ff" % cluster)
- self.set_path(".type=DEVICE_PATH_APIC_CLUSTER,.u={.apic_cluster={ .cluster = 0x%x }}" % (cluster))
+ self.set_path(".type=DEVICE_PATH_APIC_CLUSTER,{.apic_cluster={ .cluster = 0x%x }}" % (cluster))
def addcpupath(self, cpu_id):
""" Add a relative path to a cpu device hanging off our parent """
if ((cpu_id < 0) or (cpu_id > 255)):
fatal("Invalid device")
- self.set_path(".type=DEVICE_PATH_CPU,.u={.cpu={ .id = 0x%x }}" % (cpu_id))
+ self.set_path(".type=DEVICE_PATH_CPU,{.cpu={ .id = 0x%x }}" % (cpu_id))
def addcpu_buspath(self, id):
""" Add a cpu_bus to a chip """
if ((id < 0) or (id > 255)):
fatal("Invalid device")
- self.set_path(".type=DEVICE_PATH_CPU_BUS,.u={.cpu_bus={ .id = 0x%x }}" % (id))
+ self.set_path(".type=DEVICE_PATH_CPU_BUS,{.cpu_bus={ .id = 0x%x }}" % (id))
def usesoption(self, name):
"""Declare option that can be used by this part"""
def setdict(dict, name, value):
debug.info(debug.dict, "setdict sets %s to %s" % (name, value))
+ if name in dict.keys():
+ print "Duplicate in dict: %s" % name
dict[name] = value
# options.
def endromimage():
global curimage
+ global bootblocksize
mainboard()
+ imagesize = getoption("ROM_IMAGE_SIZE", curimage)
+ bootblocksize += imagesize
print "End ROMIMAGE"
curimage = 0
#curpart = 0
for o in exported:
file.write("export VARIABLES += %s\n" % o.name)
file.write("\n")
- writemakefilefooter(file,filename)
+ # writemakefilefooter(file,filename)
file.close()
# write the romimage makefile
file.write("# Get the value of TOP, VARIABLES, and several other variables.\n")
file.write("include Makefile.settings\n\n")
file.write("# Function to create an item like -Di586 or -DCONFIG_MAX_CPUS='1' or -Ui686\n")
- file.write("D_item = $(if $(subst undefined,,$(origin $1)),-D$1$(if $($1),='$($1)',),-U$1)\n\n")
+ file.write("D_item = $(shell echo '$(if $(subst undefined,,$(origin $1)),\\#define $1$(if $($1), $($1),),\\#undef $1)' >> settings.h)\n\n")
file.write("# Compute the value of CPUFLAGS here during make's first pass.\n")
- file.write("CPUFLAGS := $(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))\n\n")
+ file.write("CPUFLAGS := $(strip $(shell echo '/* autogenerated */' > settings.h)$(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))--include=settings.h)\n\n")
for i in image.getuserdefines():
file.write("%s\n" %i)
#
def writemakefile(path):
+ global rommapping
+ global bootblocksize
makefilepath = os.path.join(path, "Makefile")
print "Creating", makefilepath
file = safe_open(makefilepath, 'w+')
writemakefileheader(file, makefilepath)
+ # Hack to get the necessary settings (CONFIG_CBFS):
+ file.write("include %s/Makefile.settings\n\n" % romimages.keys()[0])
+
# main rule
- file.write("\nall:")
+ file.write("ifeq \"$(CONFIG_CBFS)\" \"1\"\n")
+ file.write("\nall: ")
+ for i in buildroms:
+ file.write(" %sfs" % i.name)
+ file.write("\n")
+ file.write("else")
+ file.write("\nall: ")
for i in buildroms:
file.write(" %s" % i.name)
- file.write("\n\n")
+ file.write("\n")
+ file.write("endif\n\n")
+
+ # cbfstool rules
+ file.write("\ncbfstool:\n\tmkdir -p tools/lzma\n\t$(MAKE) -C $(TOP)/util/cbfstool obj=$(shell pwd)\n\n")
+
file.write("include Makefile.settings\n\n")
for i, o in romimages.items():
file.write("%s/coreboot.rom:\n" % o.getname())
for j in i.roms:
file.write(" %s/coreboot.rom " % j)
file.write("> %s\n\n" %i.name)
+ # build the bootblock here as well.
+ file.write("\n")
+ file.write("\t cat ")
+ for j in i.roms:
+ file.write(" %s/coreboot.strip " % j)
+ file.write("> %s.bootblock\n\n" %i.name)
+
+ romsize = getoption("ROM_SIZE", image)
+ # i.name? That can not be right, can it?
+ file.write("%sfs: %s cbfstool\n" %(i.name,i.name));
+ file.write("\trm -f coreboot.cbfs\n");
+ file.write("\t./cbfstool %sfs create %s %s %s.bootblock\n" % (i.name, romsize, bootblocksize, i.name))
+ for i in buildroms:
+ for j in i.roms:
+ #failover is a hack that will go away soon.
+ if (j != "failover") and (rommapping[j] != "/dev/null"):
+ file.write("\tif [ -f %s/cbfs-support ]; then ./cbfstool %sfs add-payload %s %s/payload `cat %s/cbfs-support`; fi\n" % (j, i.name, rommapping[j], j, j))
+ file.write("\t ./cbfstool %sfs print\n" % i.name)
-
- file.write(".PHONY: all clean")
+ file.write(".PHONY: all clean cbfstool")
for i in romimages.keys():
file.write(" %s-clean" % i)
for i, o in romimages.items():
file.write("#include <device/pci.h>\n")
for path in image.getconfigincludes().values():
file.write("#include \"%s\"\n" % path)
+ file.write("\n/* pass 0 */\n")
gencode(image.getroot(), file, 0)
+ file.write("\n/* pass 1 */\n")
gencode(image.getroot(), file, 1)
file.close()
kid = kid.next_sibling
debug.info(debug.gencode, "DONE GENCODE")
+def writegraph(image):
+ filename = os.path.join(img_dir, "static.dot")
+ print "Creating", filename
+ file = safe_open(filename, 'w+')
+ file.write("digraph devicetree {\n")
+ file.write(" rankdir=LR\n")
+ genranks(image.getroot(), file, 0)
+ gennodes(image.getroot(), file)
+ gengraph(image.getroot(), file)
+ file.write("}\n")
+ file.close()
+
+def genranks(part, file, level):
+ #file.write(" # Level %d\n" % level )
+ file.write(" { rank = same; \"dev_%s_%d\"" % (part.type_name,part.instance ))
+ sib = part.next_sibling
+ while (sib):
+ file.write("; \"dev_%s_%d\"" % (sib.type_name, sib.instance))
+ sib = sib.next_sibling
+ file.write("}\n" )
+ # now dump the children
+ if (part.children):
+ genranks(part.children, file, level + 1)
+
+ kid = part.next_sibling
+ while (kid):
+ if (kid.children):
+ genranks(kid.children, file, level + 1)
+ kid = kid.next_sibling
+
+
+def gennodes(part, file):
+ file.write(" dev_%s_%d[shape=record, label=\"%s\"];\n" % (part.type_name,part.instance,part.graph_name() ))
+ sib = part.next_sibling
+ while (sib):
+ file.write(" dev_%s_%d[shape=record, label=\"%s\"];\n" % (sib.type_name,sib.instance,sib.graph_name() ))
+ sib = sib.next_sibling
+ # now dump the children
+ if (part.children):
+ gennodes(part.children, file)
+
+ kid = part.next_sibling
+ while (kid):
+ if (kid.children):
+ gennodes(kid.children, file)
+ kid = kid.next_sibling
+
+
+def gengraph(part, file):
+ if (part.parent != part):
+ file.write(" dev_%s_%d -> dev_%s_%d;\n" % \
+ (part.parent.type_name, part.parent.instance, \
+ part.type_name, part.instance ))
+ sib = part.next_sibling
+ while (sib):
+ file.write(" dev_%s_%d -> dev_%s_%d;\n" % \
+ (sib.parent.type_name, sib.parent.instance, \
+ sib.type_name, sib.instance ))
+ sib = sib.next_sibling
+
+ kid = part.next_sibling
+ while (kid):
+ if (kid.children):
+ gengraph(kid.children, file)
+ kid = kid.next_sibling
+
+ if (part.children):
+ gengraph(part.children, file)
+
def verifyparse():
"""Add any run-time checks to verify that parsing the configuration
was successful"""
writeinitincludes(image)
writeimagemakefile(image)
writeldoptions(image)
+ writegraph(image)
writemakefilesettings(target_dir)
writemakefile(target_dir)