16 full_mainboard_path = ''
19 global_options_by_order = []
20 global_option_values = {}
21 global_uses_options = {}
22 global_exported_options = []
29 alloptions = 0 # override uses at top level
31 local_path = re.compile(r'^\.')
32 include_pattern = re.compile(r'%%([^%]+)%%')
34 # the cpu type for this mainboard
37 # -----------------------------------------------------------------------------
39 # -----------------------------------------------------------------------------
42 """Used to keep track of the current part or dir"""
44 def __init__ (self, stack):
53 if (self.index < self.len):
54 s = self.stack[self.index]
55 self.index = self.index + 1
63 return len(self.stack)
65 def __getitem__ (self, i):
69 return self.__stack_iter(self.stack)
72 self.stack.append(part)
76 return self.stack.pop()
87 return (len(self.stack) == 0)
101 def __init__(self, *level):
104 def setdebug(self, *level):
107 def level(self, level):
108 return level in self.__level
110 def info(self, level, str):
111 if level in self.__level:
115 debug = debug_info(debug_info.dumptree)
116 debug = debug_info(debug_info.object)
118 # -----------------------------------------------------------------------------
120 # -----------------------------------------------------------------------------
123 """Used to keep track of our current location while parsing
124 configuration files"""
126 def __init__(self, file, line, command):
129 self.command = command
130 def next_line(self, command):
131 self.line = self.line + 1
132 self.command = command
134 return "%s:%d" % (self.file, self.line)
145 s = s + '\n' + p.at()
149 return self.stack.tos().file
152 return self.stack.tos().line
155 return self.stack.tos().command
157 def push(self, file):
158 self.stack.push(self.__place(os.path.normpath(file), 0, ""))
163 def next_line(self, command):
164 self.stack.tos().next_line(command)
167 return self.stack.tos().at()
171 """Print error message"""
174 print "===> ERROR: %s" % string
178 """Print error message and exit"""
183 """Print warning message"""
185 warnings = warnings + 1
186 print "===> WARNING: %s" % string
189 """Print notice message"""
190 #print "===> NOTE: %s" % string
193 """Exit parser if an error has been encountered"""
197 def safe_open(file, mode):
199 return open(file, mode)
201 fatal("Could not open file \"%s\"" % file)
203 # -----------------------------------------------------------------------------
205 # -----------------------------------------------------------------------------
208 """A rom image is the ultimate goal of coreboot"""
209 def __init__ (self, name):
210 # name of this rom image
213 # set by 'arch' directive
216 # set by 'payload' directive
219 # set by 'init' directive
222 # make rules added by 'makerule' directive
223 self.makebaserules = {}
225 # object files added by 'object' directive
226 self.objectrules = {}
228 # init object files added by 'initobject' directive
229 self.initobjectrules = {}
231 # driver files added by 'driver' directive
232 self.driverrules = {}
234 # smm object files added by 'smmobject' directive
235 self.smmobjectrules = {}
237 # loader scripts added by 'ldscript' directive
240 # user defines added by 'makedefine' directive
241 self.userdefines = []
243 # files to be included in crt0.S
244 self.initincludes = {}
246 # as above, but order is preserved
247 self.initincludesorder = []
249 # transitional flag to support old crtinclude format
250 self.useinitincludes = 0
252 # instance counter for parts
253 self.partinstance = 0
255 # chip config files included by the 'config' directive
256 self.configincludes = {}
261 # name of target directory specified by 'target' directive
264 # option values used in rom image
268 self.exported_options = []
279 def setarch(self, arch):
282 def setpayload(self, payload):
284 self.payload = payload
286 rommapping[self.name] = payload
288 def setinitfile(self, initfile):
289 self.initfile = initfile
291 def getinitfile(self):
294 def addmakerule(self, id):
295 o = getdict(self.makebaserules, id)
297 warning("rule %s previously defined" % id)
299 setdict(self.makebaserules, id, o)
301 def getmakerules(self):
302 return self.makebaserules
304 def getmakerule(self, id):
305 o = getdict(self.makebaserules, id)
308 fatal("No such make rule \"%s\"" % id)
310 def addmakeaction(self, id, str):
311 o = getdict(self.makebaserules, id)
316 fatal("No such rule \"%s\" for addmakeaction" % id)
318 def addmakedepend(self, id, str):
319 o = getdict(self.makebaserules, id)
324 fatal("No such rule \"%s\" for addmakedepend" % id)
326 def addmakeobject(self, file, obj):
327 source = topify(obj[1])
330 # for .S, .o depends on .s
331 file.write("%s: %s.s\n" % (obj[0], obj[3]))
332 file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
333 # and .s depends on .S
334 file.write("%s.s: %s\n" % (obj[3], source))
335 # Note: next 2 lines are ONE output line!
336 file.write("\t$(CPP) $(CPPFLAGS) $< ")
337 file.write(">$@.new && mv $@.new $@\n")
339 file.write("%s: %s\n" % (obj[0], source))
340 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
342 # this is called with an an object name.
343 # the easiest thing to do is add this object to the current
345 # such kludgery. If the name starts with '.' then make the
346 # dependency be on ./thing.x gag me.
347 def addobjectdriver(self, dict, object_name):
349 suffix = object_name[-2:]
352 base = object_name[:-2]
353 type = object_name[-1:]
354 if (object_name[0] == '.'):
355 source = base + suffix
359 rel_base = re.sub(treetop, "", os.path.join(dirstack.tos(), base))
360 source = "$(TOP)/" + rel_base + suffix
361 if (rel_base[0] == '/'):
362 rel_base = re.sub("^/", "", rel_base)
363 object = rel_base + '.o'
365 debug.info(debug.object, "add object %s source %s" % (object, source))
366 l = getdict(dict, rel_base)
368 warning("object/driver %s previously defined" % rel_base)
369 setdict(dict, rel_base, [object, source, type, rel_base])
371 def addinitobjectrule(self, name):
372 self.addobjectdriver(self.initobjectrules, name)
374 def addobjectrule(self, name):
375 self.addobjectdriver(self.objectrules, name)
377 def adddriverrule(self, name):
378 self.addobjectdriver(self.driverrules, name)
380 def addsmmobjectrule(self, name):
381 self.addobjectdriver(self.smmobjectrules, name)
383 def getinitobjectrules(self):
384 return self.initobjectrules
386 def getinitobjectrule(self, name):
387 o = getdict(self.initobjectrules, name)
390 fatal("No such init object rule \"%s\"" % name)
392 def getobjectrules(self):
393 return self.objectrules
395 def getobjectrule(self, name):
396 o = getdict(self.objectrules, name)
399 fatal("No such object rule \"%s\"" % name)
401 def getdriverrules(self):
402 return self.driverrules
404 def getdriverrule(self, name):
405 o = getdict(self.driverrules, name)
408 fatal("No such driver rule \"%s\"" % name)
410 def getsmmobjectrules(self):
411 return self.smmobjectrules
413 def getsmmobjectrule(self, name):
414 o = getdict(self.smmobjectrules, name)
417 fatal("No such smm object rule \"%s\"" % name)
419 def addldscript(self, path):
420 self.ldscripts.append(path)
422 def getldscripts(self):
423 return self.ldscripts
425 def adduserdefine(self, str):
426 self.userdefines.append(str)
428 def getuserdefines(self):
429 return self.userdefines
431 def addinitinclude(self, str, path):
433 self.useinitincludes = 1
435 debug.info(debug.object, "ADDCRT0: %s -> %s" % (str, path))
436 o = getdict(self.initincludes, path)
438 warning("init include for %s previously defined" % path)
439 o = initinclude(str, path)
440 setdict(self.initincludes, path, o)
441 self.initincludesorder.append(path)
443 def getinitincludes(self):
444 return self.initincludesorder
446 def getinitinclude(self, path):
447 o = getdict(self.initincludes, path)
450 fatal("No such init include \"%s\"" % path)
452 def addconfiginclude(self, part, path):
453 setdict(self.configincludes, part, path)
455 def getconfigincludes(self):
456 return self.configincludes
458 def getincludefilename(self):
459 if (self.useinitincludes):
462 return "crt0_includes.h"
465 return self.useinitincludes
468 return self.partinstance
470 def newpartinstance(self):
471 i = self.partinstance
472 self.partinstance = self.partinstance + 1
475 def setroot(self, part):
481 def settargetdir(self, path):
482 self.targetdir = path
484 def gettargetdir(self):
485 return self.targetdir
488 """A buildrom statement"""
489 def __init__ (self, filename, size, roms):
495 return len(self.roms)
497 def __getitem__(self,i):
501 """A pci_rom statement"""
502 def __init__ (self, filename, vendor, device):
504 self.pci_vid = vendor
505 self.pci_did = device
508 """include file for initialization code"""
509 def __init__ (self, str, path):
520 """Rule to be included in Makefile"""
521 def __init__ (self, target):
526 def addaction(self, action):
527 self.actions.append(action)
529 def adddependency(self, dependency):
530 self.dependency.append(dependency)
535 def gdependency(self):
536 return self.dependency
542 """Configuration option"""
543 def __init__ (self, name):
544 self.name = name # name of option
545 self.loc = 0 # current location
546 self.used = 0 # option has been used
548 self.comment = '' # description of option
549 self.exportable = 0 # option is able to be exported
550 self.format = '%s' # option print format
551 self.write = [] # parts that can set this option
556 def setcomment(self, comment, loc):
557 if (self.comment != ''):
558 print "%s: " % self.name
559 print "Attempt to modify comment at %s" % loc
561 self.comment = comment
563 def setexportable(self):
566 def setnoexport(self):
569 def setformat(self, fmt):
576 if (self.exportable):
580 def setwrite(self, part):
581 self.write.append(part)
583 def isexportable(self):
584 return self.exportable
586 def iswritable(self, part):
587 return (part in self.write)
590 """Value of a configuration option. The option has a default
591 value which can be changed at any time. Once an option has been
592 set the default value is no longer used."""
593 def __init__(self, name, prev):
598 self.value = prev.value
602 def setvalue(self, value):
603 if ((self.set & 2) == 2):
604 warning("Changing option %s" % self.name)
609 def setdefault(self, value):
610 if ((self.set & 1) == 1):
611 notice("Changing default value of %s" % self.name)
613 if ((self.set & 2) == 0):
621 return (self.set & 2) == 2
625 """A configuration part"""
626 def __init__ (self, image, dir, parent, part, type_name, instance_name, chip_or_device):
628 debug.info(debug.object, "partobj dir %s parent %s part %s" \
629 % (dir, parent.instance_name, part))
631 debug.info(debug.object, "partobj dir %s part %s" \
634 # romimage that is configuring this part
637 # links for static device tree
639 self.prev_sibling = 0
640 self.next_sibling = 0
643 self.chip_or_device = chip_or_device
645 # list of init code files
648 # initializers for static device tree
649 self.registercode = {}
654 # type name of this part
655 self.type_name = type_name
657 # object files needed to build this part
660 # directory containg part files
663 # instance number, used to distinguish anonymous
664 # instances of this part
665 self.instance = image.newpartinstance()
666 debug.info(debug.object, "INSTANCE %d" % self.instance)
668 # Options used by this part
669 self.uses_options = {}
671 # Name of chip config file (0 if not needed)
674 # Flag to indicate that we have generated type
675 # definitions for this part (only want to do it once)
681 # Resources of the device
685 # Enabled state of the device
688 # Flag if I am a dumplicate device
691 # If no instance name is supplied then generate
693 if (instance_name == 0):
694 self.instance_name = self.type_name + \
695 "_dev%d" % self.instance
696 self.chipinfo_name = "%s_info_%d" \
697 % (self.type_name, self.instance)
699 self.instance_name = instance_name
700 self.chipinfo_name = "%s_info_%d" % (self.instance_name, self.instance)
702 # Link this part into the device list
703 if (self.chip_or_device == 'device'):
704 if (image.last_device):
705 image.last_device.next_device = self
706 self.prev_device = image.last_device
707 image.last_device = self
709 # Link this part into the tree
710 if (parent and (part != 'arch')):
711 debug.info(debug.gencode, "add to parent")
713 # add current child as my sibling,
715 if (parent.children):
716 debug.info(debug.gencode, "add %s (%d) as sibling" % (parent.children.dir, parent.children.instance))
717 youngest = parent.children
718 while(youngest.next_sibling):
719 youngest = youngest.next_sibling
720 youngest.next_sibling = self
721 self.prev_sibling = youngest
723 parent.children = self
729 return "%s: %s" % (self.part, self.type)
731 return self.chip_or_device
733 def readable_name(self):
735 name = "%s_%d" % (self.type_name, self.instance)
736 if (self.chip_or_device == 'chip'):
737 name = "%s %s %s" % (name, self.part, self.dir)
739 name = "%s %s" % (name, self.path)
742 def graph_name(self):
743 name = "{ {_dev%d|" % self.instance
745 name = "%s%s" % (name, self.part)
747 name = "%s%s" % (name, self.chip_or_device)
749 name = "%s}|%s}" % (name, self.type_name)
751 name = "%s}|%s}" % (name, self.parent.type_name)
754 def dumpme(self, lvl):
755 """Dump information about this part for debugging"""
756 print "%d: %s" % (lvl, self.readable_name())
757 print "%d: part %s" % (lvl, self.part)
758 print "%d: instance %d" % (lvl, self.instance)
759 print "%d: chip_or_device %s" % (lvl, self.chip_or_device)
760 print "%d: dir %s" % (lvl,self.dir)
761 print "%d: type_name %s" % (lvl,self.type_name)
762 print "%d: parent: %s" % (lvl, self.parent.readable_name())
764 print "%d: child %s" % (lvl, self.children.readable_name())
765 if (self.next_sibling):
766 print "%d: siblings %s" % (lvl, self.next_sibling.readable_name())
767 print "%d: initcode " % lvl
768 for i in self.initcode:
770 print "%d: registercode " % lvl
771 for f, v in self.registercode.items():
772 print "\t%s = %s" % (f, v)
775 def firstchilddevice(self):
776 """Find the first device in the children link."""
779 if (kid.chip_or_device == 'device'):
785 def firstparentdevice(self):
786 """Find the first device in the parent link."""
788 while (parent and (parent.parent != parent) and (parent.chip_or_device != 'device')):
789 parent = parent.parent
790 if ((parent.parent != parent) and (parent.chip_or_device != 'device')):
792 while(parent and (parent.dup == 1)):
793 parent = parent.prev_sibling
795 fatal("Device %s has no device parent; this is a config file error" % self.readable_name())
798 def firstparentdevicelink(self):
799 """Find the first device in the parent link and record which link it is."""
802 while (parent and (parent.parent != parent) and (parent.chip_or_device != 'device')):
803 parent = parent.parent
804 if ((parent.parent != parent) and (parent.chip_or_device != 'device')):
806 while(parent and (parent.dup == 1)):
807 parent = parent.prev_sibling
810 fatal("Device %s has no device parent; this is a config file error" % self.readable_name())
814 def firstparentchip(self):
815 """Find the first chip in the parent link."""
818 if ((parent.parent == parent) or (parent.chip_or_device == 'chip')):
821 parent = parent.parent
822 fatal("Device %s has no chip parent; this is a config file error" % self.readable_name())
824 def firstsiblingdevice(self):
825 """Find the first device in the sibling link."""
826 sibling = self.next_sibling
827 while(sibling and (sibling.path == self.path)):
828 sibling = sibling.next_sibling
829 if ((not sibling) and (self.parent.chip_or_device == 'chip')):
830 sibling = self.parent.next_sibling
832 if (sibling.chip_or_device == 'device'):
835 sibling = sibling.children
838 def gencode(self, file, pass_num):
839 """Generate static initalizer code for this part. Two passes
840 are used - the first generates type information, and the second
841 generates instance information"""
843 if (self.chip_or_device == 'chip'):
847 file.write("struct device %s;\n" \
848 % self.instance_name)
850 file.write("struct device dev_root;\n")
852 # This is pass the second, which is pass number 1
853 # this is really just a case statement ...
855 if (self.chip_or_device == 'chip'):
856 if (self.chipconfig):
857 debug.info(debug.gencode, "gencode: chipconfig(%d)" % \
859 file.write("struct %s_config %s" % (self.type_name ,\
861 if (self.registercode):
862 file.write("\t= {\n")
863 for f, v in self.registercode.items():
864 file.write( "\t.%s = %s,\n" % (f, v))
870 if (self.instance == 0):
871 self.instance_name = "dev_root"
872 file.write("struct device **last_dev_p = &%s.next;\n" % (self.image.last_device.instance_name))
873 file.write("struct device dev_root = {\n")
874 file.write("\t.ops = &default_dev_ops_root,\n")
875 file.write("\t.bus = &dev_root.link[0],\n")
876 file.write("\t.path = { .type = DEVICE_PATH_ROOT },\n")
877 file.write("\t.enabled = 1,\n\t.links = 1,\n")
878 file.write("\t.on_mainboard = 1,\n")
879 file.write("\t.link = {\n\t\t[0] = {\n")
880 file.write("\t\t\t.dev=&dev_root,\n\t\t\t.link = 0,\n")
881 file.write("\t\t\t.children = &%s,\n" % self.firstchilddevice().instance_name)
882 file.write("\t\t},\n")
884 if (self.chipconfig):
885 file.write("\t.chip_ops = &%s_ops,\n" % self.type_name)
886 file.write("\t.chip_info = &%s_info_%s,\n" % (self.type_name, self.instance))
887 file.write("\t.next = &%s,\n" % self.firstchilddevice().instance_name)
891 # Don't print duplicate devices, just print their children
895 file.write("struct device %s = {\n" % self.instance_name)
896 file.write("\t.ops = 0,\n")
897 file.write("\t.bus = &%s.link[%d],\n" % \
898 (self.firstparentdevice().instance_name, \
899 self.firstparentdevicelink()))
900 file.write("\t.path = {%s},\n" % self.path)
901 file.write("\t.enabled = %d,\n" % self.enabled)
902 file.write("\t.on_mainboard = 1,\n")
904 file.write("\t.resources = %d,\n" % self.resources)
905 file.write("\t.resource = {%s\n\t },\n" % self.resource)
906 file.write("\t.link = {\n");
909 while(bus and (bus.path == self.path)):
910 child = bus.firstchilddevice()
911 if (child or (bus != self) or (bus.next_sibling and (bus.next_sibling.path == self.path))):
912 file.write("\t\t[%d] = {\n" % links)
913 file.write("\t\t\t.link = %d,\n" % links)
914 file.write("\t\t\t.dev = &%s,\n" % self.instance_name)
916 file.write("\t\t\t.children = &%s,\n" %child.instance_name)
917 file.write("\t\t},\n")
920 bus = bus.next_sibling
924 file.write("\t.links = %d,\n" % (links))
925 sibling = self.firstsiblingdevice();
927 file.write("\t.sibling = &%s,\n" % sibling.instance_name)
928 chip = self.firstparentchip()
929 if (chip and chip.chipconfig):
930 file.write("\t.chip_ops = &%s_ops,\n" % chip.type_name)
931 file.write("\t.chip_info = &%s_info_%s,\n" % (chip.type_name, chip.instance))
932 if (self.next_device):
933 file.write("\t.next=&%s\n" % self.next_device.instance_name)
937 def addinit(self, code):
938 """Add init file to this part"""
939 self.initcode.append(code)
941 def addconfig(self, path):
942 """Add chip config file to this part"""
943 self.chipconfig = os.path.join(self.dir, path)
944 self.image.addconfiginclude(self.type_name, self.chipconfig)
946 def addregister(self, field, value):
947 """Register static initialization information"""
948 if (self.chip_or_device != 'chip'):
949 fatal("Only chips can have register values")
950 field = dequote(field)
951 value = dequote(value)
952 setdict(self.registercode, field, value)
954 def set_enabled(self, enabled):
955 self.enabled = enabled
957 def start_resources(self):
961 def end_resources(self):
962 self.resource = "%s" % (self.resource)
964 def add_resource(self, type, index, value):
965 """ Add a resource to a device """
966 self.resource = "%s\n\t\t{ .flags=%s, .index=0x%x, .base=0x%x}," % (self.resource, type, index, value)
967 self.resources = self.resources + 1
969 def set_path(self, path):
971 if (self.prev_sibling and (self.prev_sibling.path == self.path)):
973 if (self.prev_device):
974 self.prev_device.next_device = self.next_device
975 if (self.next_device):
976 self.next_device.prev_device = self.prev_device
977 if (self.image.last_device == self):
978 self.image.last_device = self.prev_device
982 def addpcipath(self, slot, function):
983 """ Add a relative pci style path from our parent to this device """
984 if ((slot < 0) or (slot > 0x1f)):
985 fatal("Invalid device id")
986 if ((function < 0) or (function > 7)):
987 fatal("Invalid pci function %s" % function )
988 self.set_path(".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}" % (slot, function))
990 def addpnppath(self, port, device):
991 """ Add a relative path to a pnp device hanging off our parent """
992 if ((port < 0) or (port > 65536)):
993 fatal("Invalid port")
994 if ((device < 0) or (device > 0xffff)):
995 fatal("Invalid device")
996 self.set_path(".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}" % (port, device))
998 def addi2cpath(self, device):
999 """ Add a relative path to a i2c device hanging off our parent """
1000 if ((device < 0) or (device > 0x7f)):
1001 fatal("Invalid device")
1002 self.set_path(".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}" % (device))
1004 def addapicpath(self, apic_id):
1005 """ Add a relative path to a cpu device hanging off our parent """
1006 if ((apic_id < 0) or (apic_id > 255)):
1007 fatal("Invalid device")
1008 self.set_path(".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}" % (apic_id))
1010 def addpci_domainpath(self, pci_domain):
1011 """ Add a pci_domain number to a chip """
1012 if ((pci_domain < 0) or (pci_domain > 0xffff)):
1013 fatal("Invalid pci_domain: 0x%x is out of the range 0 to 0xffff" % pci_domain)
1014 self.set_path(".type=DEVICE_PATH_PCI_DOMAIN,{.pci_domain={ .domain = 0x%x }}" % (pci_domain))
1016 def addapic_clusterpath(self, cluster):
1017 """ Add an apic cluster to a chip """
1018 if ((cluster < 0) or (cluster > 15)):
1019 fatal("Invalid apic cluster: %d is out of the range 0 to ff" % cluster)
1020 self.set_path(".type=DEVICE_PATH_APIC_CLUSTER,{.apic_cluster={ .cluster = 0x%x }}" % (cluster))
1022 def addcpupath(self, cpu_id):
1023 """ Add a relative path to a cpu device hanging off our parent """
1024 if ((cpu_id < 0) or (cpu_id > 255)):
1025 fatal("Invalid device")
1026 self.set_path(".type=DEVICE_PATH_CPU,{.cpu={ .id = 0x%x }}" % (cpu_id))
1029 def addcpu_buspath(self, id):
1030 """ Add a cpu_bus to a chip """
1031 if ((id < 0) or (id > 255)):
1032 fatal("Invalid device")
1033 self.set_path(".type=DEVICE_PATH_CPU_BUS,{.cpu_bus={ .id = 0x%x }}" % (id))
1035 def usesoption(self, name):
1036 """Declare option that can be used by this part"""
1037 global global_options
1038 o = getdict(global_options, name)
1040 fatal("can't use undefined option %s" % name)
1041 o1 = getdict(self.uses_options, name)
1044 setdict(self.uses_options, name, o)
1045 exportoption(o, self.image.exported_options)
1047 # -----------------------------------------------------------------------------
1049 # -----------------------------------------------------------------------------
1051 def getdict(dict, name):
1052 if name not in dict.keys():
1053 debug.info(debug.dict, "Undefined: %s" % name)
1055 v = dict.get(name, 0)
1056 debug.info(debug.dict, "getdict %s returning %s" % (name, v))
1059 def setdict(dict, name, value):
1060 debug.info(debug.dict, "setdict sets %s to %s" % (name, value))
1061 if name in dict.keys():
1062 print "Duplicate in dict: %s" % name
1066 # to create an option, it has to not exist.
1067 # When an option value is fetched, the fact that it was used is
1069 # Legal things to do:
1070 # set a default value, then set a real value before the option is used.
1071 # set a value, try to set a default, default silently fails.
1073 # use the value, then try to set the value
1075 def newoption(name):
1076 global global_options, global_options_by_order
1077 o = getdict(global_options, name)
1079 fatal("option %s already defined" % name)
1081 setdict(global_options, name, o)
1082 global_options_by_order.append(name)
1084 def newoptionvalue(name, image):
1085 g = getdict(global_option_values, name)
1086 v = option_value(name, g)
1088 setdict(image.getvalues(), name, v)
1090 setdict(global_option_values, name, v)
1093 def getoptionvalue(name, op, image):
1094 global global_option_values
1095 #print "getoptionvalue name %s op %s image %s\n" % (name, op,image)
1097 # we want to debug config files, not the config tool, so no:
1099 fatal("Option %s undefined (missing use command?)" % name)
1101 v = getdict(image.getvalues(), name)
1103 v = getdict(global_option_values, name)
1106 def getoption(name, image):
1107 """option must be declared before being used in a part
1108 if we're not processing a part, then we must
1109 be at the top level where all options are available"""
1111 global global_uses_options, alloptions, curimage
1113 #print "getoption: name %s image %s alloptions %s curimage %s\n\n" % (name, image, alloptions, curimage)
1114 curpart = partstack.tos()
1116 o = getdict(global_options, name)
1118 o = getdict(curpart.uses_options, name)
1120 print "curpart.uses_options is %s\n" % curpart.uses_options
1122 o = getdict(global_uses_options, name)
1123 v = getoptionvalue(name, o, image)
1125 v = getoptionvalue(name, o, 0)
1127 fatal("No value for option %s" % name)
1129 if (not (type(val) is types.StringType)):
1131 if (val == '' or val[0] != '{'):
1135 val = parse('delexpr', val)
1140 def setoption(name, value, imp):
1141 """Set an option from within a configuration file. Normally this
1142 is only permitted in the target (top level) configuration file.
1143 If 'imp' is true, then set an option implicitly (e.g. 'arch'
1144 and 'mainboard' statements). Implicit options can be set anywhere
1145 the statements are legal, but also performs an implicit 'uses'
1148 global loc, global_options, global_option_values, curimage
1150 curpart = partstack.tos()
1151 if (not imp and curpart):
1152 fatal("Options may only be set in target configuration file")
1156 o = getdict(curpart.uses_options, name)
1158 o = getdict(global_uses_options, name)
1160 fatal("Attempt to set nonexistent option %s (missing USES?)" % name)
1161 v = getoptionvalue(name, o, curimage)
1163 v = newoptionvalue(name, curimage)
1166 def exportoption(op, exported_options):
1167 if (not op.isexportable()):
1169 if (not op in exported_options):
1170 exported_options.append(op)
1172 def setdefault(name, value, isdef):
1173 """Set the default value of an option from within a configuration
1174 file. This is permitted from any configuration file, but will
1175 result in a warning if the default is set more than once.
1176 If 'isdef' is set, we're defining the option in Options.lb so
1177 there is no need for 'uses'."""
1179 global loc, global_options, curimage
1182 o = getdict(global_options, name)
1187 curpart = partstack.tos()
1189 o = getdict(curpart.uses_options, name)
1191 o = getdict(global_uses_options, name)
1193 fatal("Attempt to set default for nonexistent option %s (missing USES?)" % name)
1196 v = getoptionvalue(name, o, image)
1198 v = newoptionvalue(name, image)
1201 def setnodefault(name):
1202 global loc, global_options
1203 o = getdict(global_options, name)
1206 v = getdict(global_option_values, name)
1208 warning("removing default for %s" % name)
1209 del global_option_values[name]
1211 def setcomment(name, value):
1212 global loc, global_options
1213 o = getdict(global_options, name)
1215 fatal("setcomment: %s not here" % name)
1216 o.setcomment(value, loc)
1218 def setexported(name):
1219 global global_options
1220 o = getdict(global_options, name)
1222 fatal("setexported: %s not here" % name)
1224 global_exported_options.append(o)
1226 def setnoexport(name):
1227 global global_options
1228 o = getdict(global_options, name)
1230 fatal("setnoexport: %s not here" % name)
1232 if (o in global_exported_options):
1233 global_exported_options.remove(o)
1235 def setexportable(name):
1236 global global_options
1237 o = getdict(global_options, name)
1239 fatal("setexportable: %s not here" % name)
1242 def setformat(name, fmt):
1243 global global_options
1244 o = getdict(global_options, name)
1246 fatal("setformat: %s not here" % name)
1249 def getformated(name, image):
1250 global global_options, global_option_values
1251 o = getdict(global_options, name)
1252 v = getoption(name, image)
1256 def setwrite(name, part):
1257 global global_options
1258 o = getdict(global_options, name)
1260 fatal("setwrite: %s not here" % name)
1263 def hasvalue(name, image):
1264 global global_options
1265 o = getdict(global_options, name)
1270 v = getdict(image.getvalues(), name)
1272 v = getdict(global_option_values, name)
1275 def isset(name, part):
1276 global global_uses_options, global_option_values, curimage
1278 o = getdict(part.uses_options, name)
1280 o = getdict(global_uses_options, name)
1285 v = getdict(curimage.getvalues(), name)
1287 v = getdict(global_option_values, name)
1288 return (v != 0 and v.isset())
1290 def usesoption(name):
1291 global global_options, global_uses_options
1292 curpart = partstack.tos()
1294 curpart.usesoption(name)
1296 o = getdict(global_options, name)
1298 fatal("Can't use undefined option %s" % name)
1299 o1 = getdict(global_uses_options, name)
1302 setdict(global_uses_options, name, o)
1303 exportoption(o, global_exported_options)
1305 def validdef(name, defval):
1306 global global_options
1307 o = getdict(global_options, name)
1309 fatal("validdef: %s not here" % name)
1310 if ((defval & 1) != 1):
1311 fatal("Must specify default value for option %s" % name)
1312 if ((defval & 2) != 2):
1313 fatal("Must specify export for option %s" % name)
1314 if ((defval & 4) != 4):
1315 fatal("Must specify comment for option %s" % name)
1317 def loadoptions(path, file, rule):
1318 file = os.path.join('src', path, file)
1319 optionsfile = os.path.join(treetop, file)
1320 fp = safe_open(optionsfile, 'r')
1322 if (not parse(rule, fp.read())):
1323 fatal("Could not parse file")
1327 global curimage, dirstack
1328 if (path[0] == '/'):
1329 curimage.setinitfile(treetop + '/src/' + path)
1331 curimage.setinitfile(dirstack.tos() + '/' + path)
1332 print "Adding init file: %s" % path
1334 def addconfig(path):
1336 curpart = partstack.tos()
1337 curpart.addconfig(path)
1339 def addregister(field, value):
1341 curpart = partstack.tos()
1342 curpart.addregister(field, value)
1344 def addcrt0include(path):
1345 """we do the crt0include as a dictionary, so that if needed we
1346 can trace who added what when. Also it makes the keys
1349 curimage.addinitinclude(0, path)
1351 def addinitinclude(str, path):
1353 curimage.addinitinclude(dequote(str), path)
1355 def addldscript(path):
1356 global curimage, dirstack
1357 curdir = dirstack.tos()
1358 if (path[0] == '/'):
1359 fullpath = treetop + '/src/' + path
1361 fullpath = curdir + '/' + path
1362 debug.info(debug.statement, "fullpath :%s: curdir :%s: path :%s:" % (fullpath, curdir, path))
1363 curimage.addldscript(fullpath)
1367 curimage.setpayload(path)
1368 adduserdefine("PAYLOAD:=%s"%path)
1370 def startromimage(name):
1371 global romimages, curimage, target_dir, target_name
1372 curpart = partstack.tos()
1373 print "Configuring ROMIMAGE %s Curimage %s" % (name, curimage)
1374 print "Curpart is %s\n" % curpart
1375 o = getdict(romimages, name)
1377 fatal("romimage %s previously defined" % name)
1378 curimage = romimage(name)
1379 curimage.settargetdir(os.path.join(target_dir, name))
1380 #o = partobj(curimage, target_dir, 0, 'board', target_name)
1381 #curimage.setroot(o)
1382 setdict(romimages, name, curimage)
1383 dodir('/config', 'Config.lb')
1387 global bootblocksize
1389 imagesize = getoption("ROM_IMAGE_SIZE", curimage)
1390 bootblocksize += imagesize
1391 print "End ROMIMAGE"
1395 def mainboardsetup(path):
1396 global full_mainboard_path, mainboard_path
1397 mainboard_path = os.path.join('mainboard', path)
1398 loadoptions(mainboard_path, 'Options.lb', 'mainboardvariables')
1399 full_mainboard_path = os.path.join(treetop, 'src', 'mainboard', path)
1400 vendor = re.sub("/.*", "", path)
1401 part_number = re.sub("[^/]*/", "", path)
1402 setdefault('MAINBOARD', full_mainboard_path, 0)
1403 setdefault('MAINBOARD_VENDOR', vendor, 0)
1404 setdefault('MAINBOARD_PART_NUMBER', part_number, 0)
1407 global curimage, dirstack, partstack
1409 partdir = mainboard_path
1410 srcdir = os.path.join(treetop, 'src')
1411 fulldir = os.path.join(srcdir, partdir)
1412 type_name = flatten_name(partdir)
1413 newpart = partobj(curimage, fulldir, partstack.tos(), 'mainboard', \
1414 'mainboard', 0, 'chip')
1415 #print "Configuring PART %s" % (type)
1416 partstack.push(newpart)
1417 #print " new PART tos is now %s\n" %partstack.tos().info()
1418 dirstack.push(fulldir)
1419 loadoptions(mainboard_path, 'Options.lb', 'mainboardvariables')
1420 # special case for 'cpu' parts.
1421 # we could add a new function too, but this is rather trivial.
1422 # if the part is a cpu, and we haven't seen it before,
1423 # arrange to source the directory /cpu/'type'
1424 doconfigfile(srcdir, partdir, file, 'cfgfile')
1425 curimage.setroot(partstack.tos())
1428 def addbuildrom(filename, size, roms):
1430 print "Build ROM size %d" % size
1431 b = buildrom(filename, size, roms)
1434 def addpci_rom(filename, vendor, device):
1436 print "Add PCI ROM %s" %filename
1437 p = pci_rom(filename, vendor, device)
1440 def addinitobject(object_name):
1442 curimage.addinitobjectrule(object_name)
1444 def addobject(object_name):
1446 curimage.addobjectrule(object_name)
1448 def adddriver(driver_name):
1450 curimage.adddriverrule(driver_name)
1452 def addsmmobject(object_name):
1454 curimage.addsmmobjectrule(object_name)
1457 global target_dir, target_name
1458 print "Configuring TARGET %s" % name
1460 target_dir = os.path.join(os.path.dirname(loc.file()), name)
1461 if not os.path.isdir(target_dir):
1462 print "Creating directory %s" % target_dir
1463 os.makedirs(target_dir)
1464 print "Will place Makefile, crt0.S, etc. in %s" % target_dir
1469 if (cpu_type and (cpu_type != path)):
1470 fatal("Two different CPU types: %s and %s" % (cpu_type, path))
1471 srcdir = "/cpu/%s" % path
1472 dodir(srcdir, "Config.lb")
1475 def devicepart(type):
1476 global curimage, dirstack, partstack
1477 newpart = partobj(curimage, 0, partstack.tos(), type, \
1479 #print "Configuring PART %s" % (type)
1480 partstack.push(newpart)
1481 #print " new PART tos is now %s\n" %partstack.tos().info()
1482 # just push TOS, so that we can pop later.
1483 dirstack.push(dirstack.tos())
1485 def part(type, path, file, name):
1486 global curimage, dirstack, partstack
1487 partdir = os.path.join(type, path)
1488 srcdir = os.path.join(treetop, 'src')
1489 fulldir = os.path.join(srcdir, partdir)
1490 type_name = flatten_name(partdir)
1491 newpart = partobj(curimage, fulldir, partstack.tos(), type, \
1492 type_name, name, 'chip')
1493 #print "Configuring PART %s, path %s" % (type, path)
1494 partstack.push(newpart)
1495 #print " new PART tos is now %s\n" %partstack.tos().info()
1496 dirstack.push(fulldir)
1497 # special case for 'cpu' parts.
1498 # we could add a new function too, but this is rather trivial.
1499 # if the part is a cpu, and we haven't seen it before,
1500 # arrange to source the directory /cpu/'type'
1504 doconfigfile(srcdir, partdir, file, 'cfgfile')
1507 global dirstack, partstack
1508 curpart = partstack.tos()
1510 fatal("Trying to pop non-existent part")
1511 #print "End PART %s" % curpart.part
1512 # Warn if options are used without being set in this part
1513 for op in curpart.uses_options.keys():
1514 if (not isset(op, curpart)):
1515 notice("Option %s using default value %s" % (op, getformated(op, curpart.image)))
1516 oldpart = partstack.pop()
1518 #print "partstack.pop, TOS is now %s\n" % oldpart.info()
1520 def dodir(path, file):
1521 """dodir is like part but there is no new part"""
1523 # if the first char is '/', it is relative to treetop,
1524 # else relative to curdir
1525 # os.path.join screws up if the name starts with '/', sigh.
1526 print "Configuring DIR %s" % os.path.join(path, file)
1527 if (path[0] == '/'):
1528 fullpath = os.path.join(treetop, 'src')
1529 path = re.sub('^/*', '', path)
1531 fullpath = dirstack.tos()
1532 debug.info(debug.statement, "DODIR: path %s, fullpath %s" % (path, fullpath))
1533 dirstack.push(os.path.join(fullpath, path))
1534 doconfigfile(fullpath, path, file, 'cfgfile')
1538 """dofile is a simple include for single files"""
1539 # if the first char is '/', it is relative to treetop,
1540 # else relative to curdir
1541 # os.path.join screws up if the name starts with '/', sigh.
1542 if (path[0] == '/'):
1543 fullpath = os.path.join(treetop, 'src')
1544 path = re.sub('^/*', '', path)
1546 fullpath = dirstack.tos()
1547 print "INCLUDE %s" %path
1548 debug.info(debug.statement, "DOFILE: path %s, fullpath %s" % (path, fullpath))
1549 doconfigfile(fullpath, '', path, 'cfgfile')
1553 return getoption(name, curimage)
1557 curimage.addmakerule(id)
1559 def adduserdefine(str):
1561 curimage.adduserdefine(str)
1563 def addaction(id, str):
1565 curimage.addmakeaction(id, str)
1567 def adddep(id, str):
1569 curimage.addmakedepend(id, str)
1571 def setarch(my_arch):
1572 """arch is 'different' ... darn it."""
1574 print "SETTING ARCH %s\n" % my_arch
1575 curimage.setarch(my_arch)
1576 setdefault('ARCH', my_arch, 1)
1577 part('arch', my_arch, 'Config.lb', 0)
1579 def doconfigfile(path, confdir, file, rule):
1580 rname = os.path.join(confdir, file)
1582 fullpath = os.path.join(path, rname)
1583 fp = safe_open(fullpath, 'r')
1584 if (not parse(rule, fp.read())):
1585 fatal("Could not parse file")
1589 #=============================================================================
1591 #=============================================================================
1592 def ternary(val, yes, no):
1593 debug.info(debug.statement, "ternary %s" % expr)
1594 debug.info(debug.statement, "expr %s a %d yes %d no %d"% (expr, a, yes, no))
1596 debug.info(debug.statement, "Ternary returns %d" % yes)
1599 debug.info(debug.statement, "Ternary returns %d" % no)
1603 """atoi is in the python library, but not strtol? Weird!"""
1604 return eval('int(%s)' % name)
1607 """ Is the given string an integer?"""
1615 a = re.sub("^\"", "", str)
1616 a = re.sub("\"$", "", a)
1617 # highly un-intuitive, need four \!
1618 a = re.sub("\\\\\"", "\"", a)
1621 def flatten_name(str):
1622 a = re.sub("[/-]", "_", str)
1626 """If the first part of <path> matches treetop, replace
1627 that part with $(TOP)"""
1628 if path[0:len(treetop)] == treetop:
1629 path = path[len(treetop):len(path)]
1630 if (path[0:1] == "/"):
1631 path = path[1:len(path)]
1632 path = "$(TOP)/" + path
1636 # to make if work without 2 passses, we use an old hack from SIMD, the
1637 # context bit. If the bit is 1, then ops get done, otherwise
1638 # ops don't get done. From the top level, context is always
1639 # 1. In an if, context depends on eval of the if condition
1645 # less general tokens should come first, otherwise they get matched
1647 token ACTION: 'action'
1648 token ADDACTION: 'addaction'
1649 token ALWAYS: 'always'
1651 token BUILDROM: 'buildrom'
1652 token COMMENT: 'comment'
1653 token CONFIG: 'config'
1655 token CPU_BUS: 'cpu_bus'
1657 token DEFAULT: 'default'
1658 token DEFINE: 'define'
1659 token DEPENDS: 'depends'
1660 token DEVICE: 'device'
1661 token DEVICE_ID: 'device_id'
1663 token DRIVER: 'driver'
1669 token EXPORT: 'export'
1670 token FORMAT: 'format'
1673 token INITOBJECT: 'initobject'
1674 token INITINCLUDE: 'initinclude'
1675 token INCLUDE: 'include'
1678 token LDSCRIPT: 'ldscript'
1679 token LOADOPTIONS: 'loadoptions'
1680 token MAINBOARD: 'mainboard'
1681 token MAINBOARDINIT: 'mainboardinit'
1682 token MAKEDEFINE: 'makedefine'
1683 token MAKERULE: 'makerule'
1685 token NEVER: 'never'
1687 token NORTHBRIDGE: 'northbridge'
1688 token OBJECT: 'object'
1689 token OPTION: 'option'
1690 token PAYLOAD: 'payload'
1691 token PCI_ROM: 'pci_rom'
1693 token PRINT: 'print'
1694 token REGISTER: 'register'
1695 token ROMIMAGE: 'romimage'
1696 token SMMOBJECT: 'smmobject'
1697 token SOUTHBRIDGE: 'southbridge'
1698 token SUPERIO: 'superio'
1699 token TARGET: 'target'
1702 token VENDOR_ID: 'vendor_id'
1703 token WRITE: 'write'
1705 token HEX_NUM: '[0-9a-fA-F]+'
1706 token HEX_PREFIX: '0x'
1707 # Why is path separate? Because paths to resources have to at least
1708 # have a slash, we thinks
1709 token PATH: r'[-a-zA-Z0-9_.][-a-zA-Z0-9/_.]+[-a-zA-Z0-9_.]+'
1710 # Dir's on the other hand are abitrary
1711 # this may all be stupid.
1712 token RULE: r'[-a-zA-Z0-9_$()./]+[-a-zA-Z0-9_ $()./]+[-a-zA-Z0-9_$()./]+'
1713 token DIRPATH: r'[-a-zA-Z0-9_$()./,]+'
1714 token ID: r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
1715 token DELEXPR: r'{([^}]+|\\.)*}'
1716 token STR: r'"([^\\"]+|\\.)*"'
1717 token RAWTEXT: r'.*'
1724 token APIC_CLUSTER: 'apic_cluster'
1726 token CPU_BUS: 'cpu_bus'
1727 token PCI_DOMAIN: 'pci_domain'
1730 rule expr: logical {{ l = logical }}
1731 ( "&&" logical {{ l = l and logical }}
1732 | "[|][|]" logical {{ l = l or logical }}
1735 rule logical: factor {{ n = factor }}
1736 ( "[+]" factor {{ n = n+factor }}
1737 | "-" factor {{ n = n-factor }}
1740 rule factor: term {{ v = term }}
1741 ( "[*]" term {{ v = v*term }}
1742 | "/" term {{ v = v/term }}
1743 | "<<" term {{ v = v << term }}
1744 | ">=" term {{ v = (v < term)}}
1747 # A term is a number, variable, or an expression surrounded by parentheses
1748 rule term: NUM {{ return long(NUM, 10) }}
1749 | HEX_PREFIX HEX_NUM {{ return long(HEX_NUM, 16) }}
1750 | ID {{ return lookup(ID) }}
1751 | unop {{ return unop }}
1752 | "\\(" expr "\\)" {{ return expr }}
1754 rule unop: "!" expr {{ return not(expr) }}
1756 rule partend<<C>>: (stmt<<C>>)* END {{ if (C): partpop()}}
1758 # This is needed because the legacy cpu command could not distinguish
1759 # between cpu vendors. It should just be PATH, but getting this change
1760 # into the source tree will be tricky...
1761 # DO NOT USE ID AS IT MAY GO AWAY IN THE FUTURE
1762 rule partid: ID {{ return ID }}
1763 | PATH {{ return PATH }}
1765 # rule parttype: NORTHBRIDGE {{ return 'northbridge' }}
1766 # | SUPERIO {{ return 'superio' }}
1767 # | PMC {{ return 'pmc' }}
1768 # | SOUTHBRIDGE {{ return 'southbridge' }}
1769 # | CPU {{ return 'cpu' }}
1770 # | CHIP {{ return '' }}
1772 rule parttype: CHIP {{ return '' }}
1774 rule partdef<<C>>: {{ name = 0 }}
1776 [ STR {{ name = dequote(STR) }}
1777 ] {{ if (C): part(parttype, partid, 'Config.lb', name) }}
1780 rule arch<<C>>: ARCH ID {{ if (C): setarch(ID) }}
1783 rule mainboardinit<<C>>:
1784 MAINBOARDINIT DIRPATH {{ if (C): addcrt0include(DIRPATH)}}
1786 rule initinclude<<C>>:
1789 DIRPATH {{ if (C): addinitinclude(STR, DIRPATH)}}
1791 rule initobject<<C>>:
1792 INITOBJECT DIRPATH {{ if (C): addinitobject(DIRPATH)}}
1794 rule object<<C>>: OBJECT DIRPATH {{ if (C): addobject(DIRPATH)}}
1796 rule driver<<C>>: DRIVER DIRPATH {{ if (C): adddriver(DIRPATH)}}
1798 rule smmobject<<C>>:
1799 SMMOBJECT DIRPATH {{ if (C): addsmmobject(DIRPATH)}}
1802 rule dir<<C>>: DIR DIRPATH {{ if (C): dodir(DIRPATH, 'Config.lb') }}
1804 rule default<<C>>: DEFAULT ID EQ value {{ if (C): setdefault(ID, value, 0) }}
1806 rule ldscript<<C>>: LDSCRIPT DIRPATH {{ if (C): addldscript(DIRPATH) }}
1808 rule iif<<C>>: IF ID {{ c = lookup(ID) }}
1810 [ ELSE (stmt<<C and not c>>)* ]
1813 rule makerule<<C>>: MAKERULE RULE {{ if (C): addrule(RULE) }}
1814 ( DEPENDS STR {{ if (C): adddep(RULE, STR) }}
1815 | ACTION STR {{ if (C): addaction(RULE, STR) }}
1819 rule makedefine<<C>>:
1820 MAKEDEFINE RAWTEXT {{ if (C): adduserdefine(RAWTEXT) }}
1822 rule addaction<<C>>:
1823 ADDACTION ID STR {{ if (C): addaction(ID, STR) }}
1825 rule init<<C>>: INIT DIRPATH {{ if (C): addinit(DIRPATH) }}
1827 rule field: STR {{ return STR }}
1829 rule register<<C>>: REGISTER field '=' STR {{ if (C): addregister(field, STR) }}
1831 rule enable<<C>>: {{ val = 1 }}
1834 ) {{ if(C): partstack.tos().set_enabled(val) }}
1836 rule resource<<C>>: {{ type = "" }}
1837 ( IO {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_IO" }}
1838 | MEM {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_MEM" }}
1839 | IRQ {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_IRQ" }}
1840 | DRQ {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_DRQ" }}
1842 term '=' {{ index = term }}
1843 term {{ value = term }}
1844 {{ if (C): partstack.tos().add_resource(type, index, value) }}
1847 rule resources<<C>>: {{ if (C): partstack.tos().start_resources() }}
1849 {{ if (C): partstack.tos().end_resources() }}
1852 rule pci<<C>>: PCI {{ if (C): devicepart('pci') }}
1854 HEX_NUM {{ slot = int(HEX_NUM,16) }}
1855 '.' HEX_NUM {{ function = int(HEX_NUM, 16) }}
1856 {{ if (C): partstack.tos().addpcipath(slot, function) }}
1857 rule pci_domain<<C>>:
1858 PCI_DOMAIN {{ if (C): devicepart('pci_domain') }}
1859 HEX_NUM {{ pci_domain = int(HEX_NUM, 16) }}
1860 {{ if (C): partstack.tos().addpci_domainpath(pci_domain) }}
1862 rule pnp<<C>>: PNP {{ if (C): devicepart('pnp') }}
1863 HEX_NUM {{ port = int(HEX_NUM,16) }}
1864 '.' HEX_NUM {{ device = int(HEX_NUM, 16) }}
1865 {{ if (C): partstack.tos().addpnppath(port, device) }}
1867 rule i2c<<C>>: I2C {{ if (C): devicepart('i2c') }}
1868 HEX_NUM {{ device = int(HEX_NUM, 16) }}
1869 {{ if (C): partstack.tos().addi2cpath(device) }}
1871 rule apic<<C>>: APIC {{ if (C): devicepart('apic') }}
1872 HEX_NUM {{ apic_id = int(HEX_NUM, 16) }}
1873 {{ if (C): partstack.tos().addapicpath(apic_id) }}
1875 rule apic_cluster<<C>>: APIC_CLUSTER {{ if (C): devicepart('apic_cluster') }}
1876 HEX_NUM {{ cluster = int(HEX_NUM, 16) }}
1877 {{ if (C): partstack.tos().addapic_clusterpath(cluster) }}
1879 rule include<<C>>: INCLUDE DIRPATH {{ dofile(DIRPATH) }}
1881 rule cpu<<C>>: CPU {{ if (C): devicepart('cpu') }}
1882 HEX_NUM {{ id = int(HEX_NUM, 16) }}
1883 {{ if (C): partstack.tos().addcpupath(id) }}
1885 rule cpu_bus<<C>>: CPU_BUS {{ if (C): devicepart('cpu_bus') }}
1886 HEX_NUM {{ id = int(HEX_NUM, 16) }}
1887 {{ if (C): partstack.tos().addcpu_buspath(id) }}
1890 pci<<C>> {{ return pci }}
1891 | pci_domain<<C>> {{ return pci_domain }}
1892 | pnp<<C>> {{ return pnp }}
1893 | i2c<<C>> {{ return i2c }}
1894 | apic<<C>> {{ return apic }}
1895 | apic_cluster<<C>> {{ return apic_cluster }}
1896 | cpu<<C>> {{ return cpu }}
1897 | cpu_bus<<C>> {{ return cpu_bus }}
1899 rule prtval: expr {{ return str(expr) }}
1900 | STR {{ return STR }}
1902 rule prtlist: prtval {{ el = "%(" + prtval }}
1903 ( "," prtval {{ el = el + "," + prtval }}
1904 )* {{ return el + ")" }}
1906 rule prtstmt<<C>>: PRINT STR {{ val = STR }}
1907 [ "," prtlist {{ val = val + prtlist }}
1908 ] {{ if (C): print eval(val) }}
1910 rule config<<C>>: CONFIG PATH {{ if (C): addconfig(PATH) }}
1912 rule device<<C>>: DEVICE dev_path<<C>>
1917 rule stmt<<C>>: arch<<C>> {{ return arch}}
1918 | addaction<<C>> {{ return addaction }}
1919 | config<<C>> {{ return config}}
1920 | default<<C>> {{ return default}}
1921 | dir<<C>> {{ return dir}}
1922 | driver<<C>> {{ return driver }}
1923 | iif<<C>> {{ return iif }}
1924 | init<<C>> {{ return init }}
1925 | initinclude<<C>> {{ return initinclude }}
1926 | include<<C>> {{ return include }}
1927 | initobject<<C>> {{ return initobject }}
1928 | ldscript<<C>> {{ return ldscript}}
1929 | mainboardinit<<C>> {{ return mainboardinit }}
1930 | makedefine<<C>> {{ return makedefine }}
1931 | makerule<<C>> {{ return makerule }}
1932 | object<<C>> {{ return object }}
1933 | option<<C>> {{ return option }}
1934 | partdef<<C>> {{ return partdef }}
1935 | prtstmt<<C>> {{ return prtstmt }}
1936 | register<<C>> {{ return register }}
1937 | device<<C>> {{ return device }}
1938 | smmobject<<C>> {{ return smmobject }}
1940 # ENTRY for parsing Config.lb file
1941 rule cfgfile: (uses<<1>>)*
1945 rule usesid<<C>>: ID {{ if (C): usesoption(ID) }}
1947 rule uses<<C>>: USES (usesid<<C>>)+
1949 rule mainboardvariables: (uses<<1>>)*
1954 rule value: STR {{ return dequote(STR) }}
1955 | expr {{ return expr }}
1956 | DELEXPR {{ return DELEXPR }}
1958 rule option<<C>>: OPTION ID EQ value {{ if (C): setoption(ID, value, 0) }}
1960 rule opif<<C>>: IF ID {{ c = lookup(ID) }}
1961 (opstmt<<C and c>>)*
1962 [ ELSE (opstmt<<C and not c>>)* ]
1965 rule opstmt<<C>>: option<<C>>
1969 rule payload<<C>>: PAYLOAD DIRPATH {{ if (C): payload(DIRPATH) }}
1972 MAINBOARD PATH {{ mainboardsetup(PATH) }}
1974 rule romif<<C>>: IF ID {{ c = lookup(ID) }}
1975 (romstmt<<C and c>>)*
1976 [ ELSE (romstmt<<C and not c>>)* ]
1979 rule romstmt<<C>>: romif<<C>>
1983 rule romimage: ROMIMAGE STR {{ startromimage(dequote(STR)) }}
1985 END {{ endromimage() }}
1987 rule roms: STR {{ s = '[' + STR }}
1988 ( STR {{ s = s + "," + STR }}
1989 )* {{ return eval(s + ']') }}
1991 rule buildrom: BUILDROM DIRPATH expr roms {{ addbuildrom(DIRPATH, expr, roms) }}
1993 rule pci_vid: VENDOR_ID EQ term {{ return term }}
1995 rule pci_did: DEVICE_ID EQ term {{ return term }}
1998 rule pci_rom: PCI_ROM DIRPATH pci_vid pci_did {{ addpci_rom(DIRPATH, pci_vid, pci_did) }}
2000 rule romstmts: romimage
2005 # ENTRY for parsing root part
2006 rule board: {{ loadoptions("config", "Options.lb", "options") }}
2007 TARGET DIRPATH {{ target(DIRPATH) }}
2012 # ENTRY for parsing a delayed value
2013 rule delexpr: "{" expr "}" EOF {{ return expr }}
2015 rule wrstr<<ID>>: STR {{ setwrite(ID, dequote(STR)) }}
2017 rule defstmts<<ID>>: {{ d = 0 }}
2019 ( value {{ setdefault(ID, value, 1) }}
2020 | NONE {{ setnodefault(ID) }}
2022 | FORMAT STR {{ setformat(ID, dequote(STR)) }}
2024 ( ALWAYS {{ setexported(ID) }}
2025 | USED {{ setexportable(ID) }}
2026 | NEVER {{ setnoexport(ID) }}
2028 | COMMENT STR {{ setcomment(ID, dequote(STR)); d = d | 4 }}
2029 | WRITE (wrstr<<ID>>)+
2032 rule define: DEFINE ID {{ newoption(ID) }}
2033 defstmts<<ID>> END {{ validdef(ID, defstmts) }}
2035 # ENTRY for parsing Options.lb file
2036 rule options: (define)* EOF {{ return 1 }}
2039 #=============================================================================
2041 #=============================================================================
2042 def writemakefileheader(file, fname):
2043 file.write("# File: %s is autogenerated\n" % fname)
2045 def writemakefilefooter(file, fname):
2046 file.write("\n\n%s: %s %s\n"
2047 % (os.path.basename(fname), os.path.abspath(sys.argv[0]), top_config_file))
2048 file.write("\t(cd %s ; export PYTHONPATH=%s/util/newconfig ; python %s %s %s)\n\n"
2049 % (os.getcwd(), treetop, sys.argv[0], sys.argv[1], sys.argv[2]))
2051 def writemakefilesettings(path):
2052 """ Write Makefile.settings to seperate the settings
2053 from the actual makefile creation."""
2055 global treetop, target_dir
2057 filename = os.path.join(path, "Makefile.settings")
2058 print "Creating", filename
2059 file = safe_open(filename, 'w+')
2060 writemakefileheader(file, filename)
2061 file.write("TOP:=%s\n" % (treetop))
2062 file.write("TARGET_DIR:=%s\n" % target_dir)
2063 writemakefilefooter(file, filename)
2066 def writeimagesettings(image):
2067 """Write Makefile.settings to seperate the settings
2068 from the actual makefile creation."""
2071 global global_options_by_order
2073 filename = os.path.join(image.gettargetdir(), "Makefile.settings")
2074 print "Creating", filename
2075 file = safe_open(filename, 'w+')
2076 writemakefileheader(file, filename)
2077 file.write("TOP:=%s\n" % (treetop))
2078 file.write("TARGET_DIR:=%s\n" % (image.gettargetdir()))
2081 for o in global_exported_options:
2083 for o in image.exported_options:
2084 if (not o in exported):
2087 file.write("export %s:=" % o.name)
2088 if (hasvalue(o.name, image)):
2089 file.write("%s" % getformated(o.name, image))
2092 file.write("export VARIABLES :=\n")
2094 file.write("export VARIABLES += %s\n" % o.name)
2096 # writemakefilefooter(file,filename)
2099 # write the romimage makefile
2100 # let's try the Makefile
2101 # first, dump all the -D stuff
2103 def writeimagemakefile(image):
2104 makefilepath = os.path.join(image.gettargetdir(), "Makefile")
2105 print "Creating", makefilepath
2106 file = safe_open(makefilepath, 'w+')
2107 writemakefileheader(file, makefilepath)
2110 file.write("\nall: coreboot.rom\n\n")
2111 file.write(".PHONY: all\n\n")
2112 #file.write("include cpuflags\n")
2113 # Putting "include cpuflags" in the Makefile has the problem that the
2114 # cpuflags file would be generated _after_ we want to include it.
2115 # Instead, let make do the work of computing CPUFLAGS:
2116 file.write("# Get the value of TOP, VARIABLES, and several other variables.\n")
2117 file.write("include Makefile.settings\n\n")
2118 file.write("# Function to create an item like -Di586 or -DCONFIG_MAX_CPUS='1' or -Ui686\n")
2119 file.write("D_item = $(shell echo '$(if $(subst undefined,,$(origin $1)),\\#define $1$(if $($1), $($1),),\\#undef $1)' >> settings.h)\n\n")
2120 file.write("# Compute the value of CPUFLAGS here during make's first pass.\n")
2121 file.write("CPUFLAGS := $(strip $(shell echo '/* autogenerated */' > settings.h)$(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))-include $(CURDIR)/settings.h)\n\n")
2123 for i in image.getuserdefines():
2124 file.write("%s\n" %i)
2127 # print out all the object dependencies
2128 file.write("\n# object dependencies (objectrules:)\n")
2129 file.write("INIT-OBJECTS :=\n")
2130 file.write("OBJECTS :=\n")
2131 file.write("DRIVER :=\n")
2132 file.write("\nSOURCES :=\n")
2133 for irule, init in image.getinitobjectrules().items():
2136 file.write("INIT-OBJECTS += %s\n" % (i_name))
2137 file.write("SOURCES += %s\n" % (i_source))
2139 for objrule, obj in image.getobjectrules().items():
2142 file.write("OBJECTS += %s\n" % (obj_name))
2143 file.write("SOURCES += %s\n" % (obj_source))
2145 for srule, smm in image.getsmmobjectrules().items():
2148 file.write("SMM-OBJECTS += %s\n" % (s_name))
2149 file.write("SOURCES += %s\n" % (s_source))
2153 file.write("OBJECTS += static.o\n")
2154 file.write("SOURCES += static.c\n")
2156 for driverrule, driver in image.getdriverrules().items():
2157 obj_name = driver[0]
2158 obj_source = driver[1]
2159 file.write("DRIVER += %s\n" % (obj_name))
2160 file.write("SOURCES += %s\n" % (obj_source))
2162 # Print out all ldscript.ld dependencies.
2163 file.write("\n# ldscript.ld dependencies:\n")
2164 file.write("LDSUBSCRIPTS-1 := \n" )
2165 for script in image.getldscripts():
2166 file.write("LDSUBSCRIPTS-1 += %s\n" % topify(script))
2168 # Print out the dependencies for crt0_includes.h
2169 file.write("\n# Dependencies for crt0_includes.h\n")
2170 file.write("CRT0_INCLUDES:=\n")
2171 for inc in image.getinitincludes():
2172 if (local_path.match(inc)):
2173 file.write("CRT0_INCLUDES += %s\n" % inc)
2175 file.write("CRT0_INCLUDES += $(TOP)/src/%s\n" % inc)
2177 # Print out the user defines.
2178 file.write("\n# userdefines:\n")
2180 # Print out the base rules.
2181 # Need to have a rule that counts on 'all'.
2182 file.write("\n# mainrulelist:")
2184 # Print out any user rules.
2185 file.write("\n# From makerule or docipl commands:\n")
2187 file.write("\n# initobjectrules:\n")
2188 for irule, init in image.getinitobjectrules().items():
2189 image.addmakeobject(file, init);
2191 file.write("\n# objectrules (don't duplicate initobjects):\n")
2192 for objrule, obj in image.getobjectrules().items():
2194 if (getdict(image.getinitobjectrules(), obj[3])):
2195 debug.info(debug.object, "skipping %s" % (obj[3]))
2197 image.addmakeobject(file, obj);
2199 for driverrule, driver in image.getdriverrules().items():
2200 source = topify(driver[1])
2201 file.write("%s: %s\n" % (driver[0], source))
2202 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2203 #file.write("%s\n" % objrule[2])
2205 file.write("\n# smmobjectrules:\n")
2206 for irule, smm in image.getsmmobjectrules().items():
2207 image.addmakeobject(file, smm);
2209 # special rule for chip_target.c
2210 file.write("static.o: static.c\n")
2211 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2213 # Print out the rules that will make cause the files
2214 # generated by NLBConfig.py to be remade if any dependencies change.
2216 file.write("\n# Remember the automatically generated files\n")
2217 file.write("GENERATED:=\n")
2218 for genfile in ['Makefile',
2221 'corebootDoc.config' ]:
2222 file.write("GENERATED += %s\n" % genfile)
2223 file.write("GENERATED += %s\n" % image.getincludefilename())
2225 keys = global_options_by_order
2227 file.write("\necho:\n")
2229 file.write("\t@echo %s='$(%s)'\n"% (key,key))
2231 for i, m in image.getmakerules().items():
2232 file.write("%s: " %i)
2233 for i in m.dependency:
2234 file.write("%s " % i)
2237 file.write("\t%s\n" % i)
2238 writemakefilefooter(file, makefilepath)
2242 def writemakefile(path):
2244 global bootblocksize
2245 makefilepath = os.path.join(path, "Makefile")
2246 print "Creating", makefilepath
2247 file = safe_open(makefilepath, 'w+')
2248 writemakefileheader(file, makefilepath)
2250 # Hack to get the necessary settings (CONFIG_CBFS):
2251 file.write("include %s/Makefile.settings\n\n" % romimages.keys()[0])
2254 file.write("\nall: ")
2256 file.write(" %s" % i.name)
2260 file.write("\ncbfstool:\n\tmkdir -p cbfs/tools/lzma\n\t$(MAKE) -C $(TOP)/util/cbfstool obj=$(shell pwd)/cbfs\n")
2261 file.write("\ncbfstool-clean:\n\t$(MAKE) -C $(TOP)/util/cbfstool obj=$(shell pwd)/cbfs clean\n\n")
2263 file.write("include Makefile.settings\n\n")
2264 for i, o in romimages.items():
2265 file.write("%s/coreboot.rom:\n" % o.getname())
2266 file.write("\tif (cd %s; \\\n" % o.getname())
2267 file.write("\t\t$(MAKE) coreboot.rom)\\\n")
2268 file.write("\tthen true; else exit 1; fi;\n\n")
2269 file.write("clean: ")
2270 for i in romimages.keys():
2271 file.write(" %s-clean" % i)
2272 file.write(" base-clean")
2274 for i, o in romimages.items():
2275 file.write("%s-clean:\n" % o.getname())
2276 file.write("\t(cd %s; $(MAKE) clean)\n\n" % o.getname())
2277 file.write("base-clean:\n")
2278 file.write("\trm -f romcc*\n\n")
2280 file.write("ifeq \"$(CONFIG_CBFS)\" \"1\"\n\n")
2281 file.write("CBFS_COMPRESS_FLAG:=\n")
2282 file.write("ifeq \"$(CONFIG_COMPRESSED_PAYLOAD_LZMA)\" \"1\"\nCBFS_COMPRESS_FLAG:=l\nendif\n\n")
2285 file.write("%s: cbfstool" %(i.name))
2287 file.write(" %s/coreboot.rom " % j)
2290 romsize = getoption("ROM_SIZE", image)
2292 file.write("\n\trm -f %s\n" %(i.name))
2294 # build the bootblock here.
2295 file.write("\n\tcat")
2297 file.write(" %s/coreboot.rom " % j)
2298 file.write("> %s.bootblock\n\n" %i.name)
2299 file.write("\t./cbfs/cbfstool %s create %s %s %s.bootblock\n"
2300 %(i.name, romsize, bootblocksize, i.name))
2302 file.write("\t./cbfs/cbfstool %s add %s pci%04x,%04x.rom optionrom\n" % (i.name, j.name, j.pci_vid, j.pci_did))
2304 #failover is a hack that will go away soon.
2305 if (j != "failover") and (rommapping[j] != "/dev/null"):
2306 file.write("\t./cbfs/cbfstool %s add-payload %s %s/payload $(CBFS_COMPRESS_FLAG)\n" % (i.name, rommapping[j], j,))
2307 if (j != "failover"):
2308 file.write("\t./cbfs/cbfstool %s add-stage %s/coreboot_ram %s/coreboot_ram $(CBFS_COMPRESS_FLAG)\n" % (i.name, j, j,))
2309 file.write("\tif [ -f %s/coreboot_apc ]; then ./cbfs/cbfstool %s add-stage %s/coreboot_apc %s/coreboot_apc $(CBFS_COMPRESS_FLAG); fi\n" % (j, i.name, j, j,))
2310 file.write("\t./cbfs/cbfstool %s print\n" % i.name)
2312 file.write("else\n\n")
2315 file.write("%s:" % i.name)
2317 file.write(" %s/coreboot.rom " % j)
2319 file.write("\t cat ")
2321 file.write(" %s/coreboot.rom " % j)
2322 file.write("> %s\n\n" %i.name)
2324 file.write("endif\n\n")
2326 file.write(".PHONY: all clean cbfstool")
2327 for i in romimages.keys():
2328 file.write(" %s-clean" % i)
2329 for i, o in romimages.items():
2330 file.write(" %s/coreboot.rom" % o.getname())
2333 writemakefilefooter(file, makefilepath)
2336 def writeinitincludes(image):
2337 global include_pattern
2338 filepath = os.path.join(image.gettargetdir(), image.getincludefilename())
2339 print "Creating", filepath
2340 outfile = safe_open(filepath, 'w+')
2341 if (image.newformat()):
2342 infile = safe_open(image.getinitfile(), 'r')
2344 line = infile.readline()
2346 p = include_pattern.match(line)
2348 for i in image.getinitincludes():
2349 inc = image.getinitinclude(i)
2350 if (inc.getstring() == p.group(1)):
2351 outfile.write("#include \"%s\"\n" % inc.getpath())
2354 line = infile.readline()
2358 for i in image.getinitincludes():
2359 outfile.write("#include <%s>\n" % i)
2362 def writeldoptions(image):
2363 """Write ldoptions file."""
2364 filename = os.path.join(image.gettargetdir(), "ldoptions")
2365 print "Creating", filename
2366 file = safe_open(filename, 'w+')
2367 for o in global_exported_options:
2368 if (hasvalue(o.name, image) and IsInt(getoption(o.name, image))):
2369 file.write("%s = %s;\n" % (o.name, getformated(o.name, image)))
2370 for o in image.exported_options:
2371 if (not o in global_exported_options and hasvalue(o.name, image) and IsInt(getoption(o.name, image))):
2372 file.write("%s = %s;\n" % (o.name, getformated(o.name, image)))
2375 def dumptree(part, lvl):
2376 debug.info(debug.dumptree, "DUMPTREE ME is")
2378 # dump the siblings -- actually are there any? not sure
2380 debug.info(debug.dumptree, "DUMPTREE SIBLINGS are")
2381 kid = part.next_sibling
2384 kid = kid.next_sibling
2386 debug.info(debug.dumptree, "DUMPTREE KIDS are")
2387 #for kid in part.children:
2389 dumptree(part.children, lvl+1)
2390 kid = part.next_sibling
2393 dumptree(kid.children, lvl + 1)
2394 kid = kid.next_sibling
2395 debug.info(debug.dumptree, "DONE DUMPTREE")
2397 def writecode(image):
2398 filename = os.path.join(img_dir, "static.c")
2399 print "Creating", filename
2400 file = safe_open(filename, 'w+')
2401 file.write("#include <device/device.h>\n")
2402 file.write("#include <device/pci.h>\n")
2403 for path in image.getconfigincludes().values():
2404 file.write("#include \"%s\"\n" % path)
2405 file.write("\n/* pass 0 */\n")
2406 gencode(image.getroot(), file, 0)
2407 file.write("\n/* pass 1 */\n")
2408 gencode(image.getroot(), file, 1)
2411 def gencode(part, file, pass_num):
2412 debug.info(debug.gencode, "GENCODE ME is")
2413 part.gencode(file, pass_num)
2414 # dump the siblings -- actually are there any? not sure
2415 debug.info(debug.gencode, "GENCODE SIBLINGS are")
2416 kid = part.next_sibling
2418 kid.gencode(file, pass_num)
2419 kid = kid.next_sibling
2420 # now dump the children
2421 debug.info(debug.gencode, "GENCODE KIDS are")
2423 gencode(part.children, file, pass_num)
2424 kid = part.next_sibling
2427 gencode(kid.children, file, pass_num)
2428 kid = kid.next_sibling
2429 debug.info(debug.gencode, "DONE GENCODE")
2431 def writegraph(image):
2432 filename = os.path.join(img_dir, "static.dot")
2433 print "Creating", filename
2434 file = safe_open(filename, 'w+')
2435 file.write("digraph devicetree {\n")
2436 file.write(" rankdir=LR\n")
2437 genranks(image.getroot(), file, 0)
2438 gennodes(image.getroot(), file)
2439 gengraph(image.getroot(), file)
2443 def genranks(part, file, level):
2444 #file.write(" # Level %d\n" % level )
2445 file.write(" { rank = same; \"dev_%s_%d\"" % (part.type_name,part.instance ))
2446 sib = part.next_sibling
2448 file.write("; \"dev_%s_%d\"" % (sib.type_name, sib.instance))
2449 sib = sib.next_sibling
2451 # now dump the children
2453 genranks(part.children, file, level + 1)
2455 kid = part.next_sibling
2458 genranks(kid.children, file, level + 1)
2459 kid = kid.next_sibling
2462 def gennodes(part, file):
2463 file.write(" dev_%s_%d[shape=record, label=\"%s\"];\n" % (part.type_name,part.instance,part.graph_name() ))
2464 sib = part.next_sibling
2466 file.write(" dev_%s_%d[shape=record, label=\"%s\"];\n" % (sib.type_name,sib.instance,sib.graph_name() ))
2467 sib = sib.next_sibling
2468 # now dump the children
2470 gennodes(part.children, file)
2472 kid = part.next_sibling
2475 gennodes(kid.children, file)
2476 kid = kid.next_sibling
2479 def gengraph(part, file):
2480 if (part.parent != part):
2481 file.write(" dev_%s_%d -> dev_%s_%d;\n" % \
2482 (part.parent.type_name, part.parent.instance, \
2483 part.type_name, part.instance ))
2484 sib = part.next_sibling
2486 file.write(" dev_%s_%d -> dev_%s_%d;\n" % \
2487 (sib.parent.type_name, sib.parent.instance, \
2488 sib.type_name, sib.instance ))
2489 sib = sib.next_sibling
2491 kid = part.next_sibling
2494 gengraph(kid.children, file)
2495 kid = kid.next_sibling
2498 gengraph(part.children, file)
2501 """Add any run-time checks to verify that parsing the configuration
2504 for image in romimages.values():
2505 print("Verifying ROMIMAGE %s" % image.name)
2506 if (image.newformat() and image.getinitfile() == ''):
2507 fatal("An init file must be specified")
2508 for op in image.exported_options:
2509 if (getoptionvalue(op.name, op, image) == 0 and getoptionvalue(op.name, op, 0) == 0):
2510 warning("Exported option %s has no value (check Options.lb)" % op.name);
2511 print("Verifing global options")
2512 for op in global_exported_options:
2513 if (getoptionvalue(op.name, op, 0) == 0):
2514 notice("Exported option %s has no value (check Options.lb)" % op.name);
2516 #=============================================================================
2518 #=============================================================================
2519 if __name__=='__main__':
2520 from sys import argv
2522 fatal("Args: <file> <path to coreboot>")
2524 top_config_file = os.path.abspath(sys.argv[1])
2526 treetop = os.path.abspath(sys.argv[2])
2528 # Now read in the customizing script...
2530 fp = safe_open(argv[1], 'r')
2531 if (not parse('board', fp.read())):
2532 fatal("Could not parse file")
2537 # no longer need to check if an options has been used
2540 for image_name, image in romimages.items():
2541 if (debug.level(debug.dumptree)):
2542 debug.info(debug.dumptree, "DEVICE TREE:")
2543 dumptree(image.getroot(), 0)
2545 img_dir = image.gettargetdir()
2546 if not os.path.isdir(img_dir):
2547 print "Creating directory %s" % img_dir
2548 os.makedirs(img_dir)
2550 for objrule, obj in image.getobjectrules().items():
2551 sub_dir = img_dir + '/' + os.path.dirname(obj[0])
2552 if not os.path.isdir(sub_dir):
2553 print "Creating sub directory %s" % sub_dir
2554 os.makedirs(sub_dir)
2556 for driverrule, driver in image.getdriverrules().items():
2557 sub_dir = img_dir + '/' + os.path.dirname(driver[0])
2558 if not os.path.isdir(sub_dir):
2559 print "Creating sub directory %s" % sub_dir
2560 os.makedirs(sub_dir)
2562 for srule, smm in image.getsmmobjectrules().items():
2563 sub_dir = img_dir + '/' + os.path.dirname(smm[0])
2564 if not os.path.isdir(sub_dir):
2565 print "Creating sub directory %s" % sub_dir
2566 os.makedirs(sub_dir)
2568 for irule, init in image.getinitobjectrules().items():
2569 sub_dir = img_dir + '/' + os.path.dirname(init[0])
2570 if not os.path.isdir(sub_dir):
2571 print "Creating sub directory %s" % sub_dir
2572 os.makedirs(sub_dir)
2574 if (debug.level(debug.dump)):
2575 for i in image.getinitincludes():
2576 debug.info(debug.dump, "crt0include file %s" % i)
2577 for i in image.getdriverrules().keys():
2578 debug.info(debug.dump, "driver file %s" % i)
2579 for i in image.getldscripts():
2580 debug.info(debug.dump, "ldscript file %s" % i)
2581 for i, m in image.getmakerules().items():
2582 debug.info(debug.dump, " makerule %s dep %s act %s" % (i, m.dependency, m.actions))
2585 writeimagesettings(image)
2586 writeinitincludes(image)
2587 writeimagemakefile(image)
2588 writeldoptions(image)
2591 writemakefilesettings(target_dir)
2592 writemakefile(target_dir)