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 # this is called with an an object name.
327 # the easiest thing to do is add this object to the current
329 # such kludgery. If the name starts with '.' then make the
330 # dependency be on ./thing.x gag me.
331 def addobjectdriver(self, dict, object_name):
333 suffix = object_name[-2:]
336 base = object_name[:-2]
337 type = object_name[-1:]
338 if (object_name[0] == '.'):
339 source = base + suffix
343 rel_base = re.sub(treetop, "", os.path.join(dirstack.tos(), base))
344 source = "$(TOP)/" + rel_base + suffix
345 if (rel_base[0] == '/'):
346 rel_base = re.sub("^/", "", rel_base)
347 object = rel_base + '.o'
349 debug.info(debug.object, "add object %s source %s" % (object, source))
350 l = getdict(dict, rel_base)
352 warning("object/driver %s previously defined" % rel_base)
353 setdict(dict, rel_base, [object, source, type, rel_base])
355 def addinitobjectrule(self, name):
356 self.addobjectdriver(self.initobjectrules, name)
358 def addobjectrule(self, name):
359 self.addobjectdriver(self.objectrules, name)
361 def adddriverrule(self, name):
362 self.addobjectdriver(self.driverrules, name)
364 def addsmmobjectrule(self, name):
365 self.addobjectdriver(self.smmobjectrules, name)
367 def getinitobjectrules(self):
368 return self.initobjectrules
370 def getinitobjectrule(self, name):
371 o = getdict(self.initobjectrules, name)
374 fatal("No such init object rule \"%s\"" % name)
376 def getobjectrules(self):
377 return self.objectrules
379 def getobjectrule(self, name):
380 o = getdict(self.objectrules, name)
383 fatal("No such object rule \"%s\"" % name)
385 def getdriverrules(self):
386 return self.driverrules
388 def getdriverrule(self, name):
389 o = getdict(self.driverrules, name)
392 fatal("No such driver rule \"%s\"" % name)
394 def getsmmobjectrules(self):
395 return self.smmobjectrules
397 def getsmmobjectrule(self, name):
398 o = getdict(self.smmobjectrules, name)
401 fatal("No such smm object rule \"%s\"" % name)
403 def addldscript(self, path):
404 self.ldscripts.append(path)
406 def getldscripts(self):
407 return self.ldscripts
409 def adduserdefine(self, str):
410 self.userdefines.append(str)
412 def getuserdefines(self):
413 return self.userdefines
415 def addinitinclude(self, str, path):
417 self.useinitincludes = 1
419 debug.info(debug.object, "ADDCRT0: %s -> %s" % (str, path))
420 o = getdict(self.initincludes, path)
422 warning("init include for %s previously defined" % path)
423 o = initinclude(str, path)
424 setdict(self.initincludes, path, o)
425 self.initincludesorder.append(path)
427 def getinitincludes(self):
428 return self.initincludesorder
430 def getinitinclude(self, path):
431 o = getdict(self.initincludes, path)
434 fatal("No such init include \"%s\"" % path)
436 def addconfiginclude(self, part, path):
437 setdict(self.configincludes, part, path)
439 def getconfigincludes(self):
440 return self.configincludes
442 def getincludefilename(self):
443 if (self.useinitincludes):
446 return "crt0_includes.h"
449 return self.useinitincludes
452 return self.partinstance
454 def newpartinstance(self):
455 i = self.partinstance
456 self.partinstance = self.partinstance + 1
459 def setroot(self, part):
465 def settargetdir(self, path):
466 self.targetdir = path
468 def gettargetdir(self):
469 return self.targetdir
472 """A buildrom statement"""
473 def __init__ (self, filename, size, roms):
479 return len(self.roms)
481 def __getitem__(self,i):
485 """A pci_rom statement"""
486 def __init__ (self, filename, vendor, device):
488 self.pci_vid = vendor
489 self.pci_did = device
492 """include file for initialization code"""
493 def __init__ (self, str, path):
504 """Rule to be included in Makefile"""
505 def __init__ (self, target):
510 def addaction(self, action):
511 self.actions.append(action)
513 def adddependency(self, dependency):
514 self.dependency.append(dependency)
519 def gdependency(self):
520 return self.dependency
526 """Configuration option"""
527 def __init__ (self, name):
528 self.name = name # name of option
529 self.loc = 0 # current location
530 self.used = 0 # option has been used
532 self.comment = '' # description of option
533 self.exportable = 0 # option is able to be exported
534 self.format = '%s' # option print format
535 self.write = [] # parts that can set this option
540 def setcomment(self, comment, loc):
541 if (self.comment != ''):
542 print "%s: " % self.name
543 print "Attempt to modify comment at %s" % loc
545 self.comment = comment
547 def setexportable(self):
550 def setnoexport(self):
553 def setformat(self, fmt):
560 if (self.exportable):
564 def setwrite(self, part):
565 self.write.append(part)
567 def isexportable(self):
568 return self.exportable
570 def iswritable(self, part):
571 return (part in self.write)
574 """Value of a configuration option. The option has a default
575 value which can be changed at any time. Once an option has been
576 set the default value is no longer used."""
577 def __init__(self, name, prev):
582 self.value = prev.value
586 def setvalue(self, value):
587 if ((self.set & 2) == 2):
588 warning("Changing option %s" % self.name)
593 def setdefault(self, value):
594 if ((self.set & 1) == 1):
595 notice("Changing default value of %s" % self.name)
597 if ((self.set & 2) == 0):
605 return (self.set & 2) == 2
609 """A configuration part"""
610 def __init__ (self, image, dir, parent, part, type_name, instance_name, chip_or_device):
611 debug.info(debug.object, "partobj dir %s parent %s part %s" \
612 % (dir, parent, part))
614 # romimage that is configuring this part
617 # links for static device tree
619 self.prev_sibling = 0
620 self.next_sibling = 0
623 self.chip_or_device = chip_or_device
625 # list of init code files
628 # initializers for static device tree
629 self.registercode = {}
634 # type name of this part
635 self.type_name = type_name
637 # object files needed to build this part
640 # directory containg part files
643 # instance number, used to distinguish anonymous
644 # instances of this part
645 self.instance = image.newpartinstance()
646 debug.info(debug.object, "INSTANCE %d" % self.instance)
648 # Options used by this part
649 self.uses_options = {}
651 # Name of chip config file (0 if not needed)
654 # Flag to indicate that we have generated type
655 # definitions for this part (only want to do it once)
661 # Resources of the device
665 # Enabled state of the device
668 # Flag if I am a dumplicate device
671 # If no instance name is supplied then generate
673 if (instance_name == 0):
674 self.instance_name = self.type_name + \
675 "_dev%d" % self.instance
676 self.chipinfo_name = "%s_info_%d" \
677 % (self.type_name, self.instance)
679 self.instance_name = instance_name
680 self.chipinfo_name = "%s_info_%d" % (self.instance_name, self.instance)
682 # Link this part into the device list
683 if (self.chip_or_device == 'device'):
684 if (image.last_device):
685 image.last_device.next_device = self
686 self.prev_device = image.last_device
687 image.last_device = self
689 # Link this part into the tree
690 if (parent and (part != 'arch')):
691 debug.info(debug.gencode, "add to parent")
693 # add current child as my sibling,
695 if (parent.children):
696 debug.info(debug.gencode, "add %s (%d) as sibling" % (parent.children.dir, parent.children.instance))
697 youngest = parent.children
698 while(youngest.next_sibling):
699 youngest = youngest.next_sibling
700 youngest.next_sibling = self
701 self.prev_sibling = youngest
703 parent.children = self
709 return "%s: %s" % (self.part, self.type)
711 return self.chip_or_device
713 def readable_name(self):
715 name = "%s_%d" % (self.type_name, self.instance)
716 if (self.chip_or_device == 'chip'):
717 name = "%s %s %s" % (name, self.part, self.dir)
719 name = "%s %s" % (name, self.path)
722 def graph_name(self):
723 name = "{ {_dev%d|" % self.instance
725 name = "%s%s" % (name, self.part)
727 name = "%s%s" % (name, self.chip_or_device)
729 name = "%s}|%s}" % (name, self.type_name)
731 name = "%s}|%s}" % (name, self.parent.type_name)
734 def dumpme(self, lvl):
735 """Dump information about this part for debugging"""
736 print "%d: %s" % (lvl, self.readable_name())
737 print "%d: part %s" % (lvl, self.part)
738 print "%d: instance %d" % (lvl, self.instance)
739 print "%d: chip_or_device %s" % (lvl, self.chip_or_device)
740 print "%d: dir %s" % (lvl,self.dir)
741 print "%d: type_name %s" % (lvl,self.type_name)
742 print "%d: parent: %s" % (lvl, self.parent.readable_name())
744 print "%d: child %s" % (lvl, self.children.readable_name())
745 if (self.next_sibling):
746 print "%d: siblings %s" % (lvl, self.next_sibling.readable_name())
747 print "%d: initcode " % lvl
748 for i in self.initcode:
750 print "%d: registercode " % lvl
751 for f, v in self.registercode.items():
752 print "\t%s = %s" % (f, v)
755 def firstchilddevice(self):
756 """Find the first device in the children link."""
759 if (kid.chip_or_device == 'device'):
765 def firstparentdevice(self):
766 """Find the first device in the parent link."""
768 while (parent and (parent.parent != parent) and (parent.chip_or_device != 'device')):
769 parent = parent.parent
770 if ((parent.parent != parent) and (parent.chip_or_device != 'device')):
772 while(parent and (parent.dup == 1)):
773 parent = parent.prev_sibling
775 fatal("Device %s has no device parent; this is a config file error" % self.readable_name())
778 def firstparentdevicelink(self):
779 """Find the first device in the parent link and record which link it is."""
782 while (parent and (parent.parent != parent) and (parent.chip_or_device != 'device')):
783 parent = parent.parent
784 if ((parent.parent != parent) and (parent.chip_or_device != 'device')):
786 while(parent and (parent.dup == 1)):
787 parent = parent.prev_sibling
790 fatal("Device %s has no device parent; this is a config file error" % self.readable_name())
794 def firstparentchip(self):
795 """Find the first chip in the parent link."""
798 if ((parent.parent == parent) or (parent.chip_or_device == 'chip')):
801 parent = parent.parent
802 fatal("Device %s has no chip parent; this is a config file error" % self.readable_name())
804 def firstsiblingdevice(self):
805 """Find the first device in the sibling link."""
806 sibling = self.next_sibling
807 while(sibling and (sibling.path == self.path)):
808 sibling = sibling.next_sibling
809 if ((not sibling) and (self.parent.chip_or_device == 'chip')):
810 sibling = self.parent.next_sibling
812 if (sibling.chip_or_device == 'device'):
815 sibling = sibling.children
818 def gencode(self, file, pass_num):
819 """Generate static initalizer code for this part. Two passes
820 are used - the first generates type information, and the second
821 generates instance information"""
823 if (self.chip_or_device == 'chip'):
827 file.write("struct device %s;\n" \
828 % self.instance_name)
830 file.write("struct device dev_root;\n")
832 # This is pass the second, which is pass number 1
833 # this is really just a case statement ...
835 if (self.chip_or_device == 'chip'):
836 if (self.chipconfig):
837 debug.info(debug.gencode, "gencode: chipconfig(%d)" % \
839 file.write("struct %s_config %s" % (self.type_name ,\
841 if (self.registercode):
842 file.write("\t= {\n")
843 for f, v in self.registercode.items():
844 file.write( "\t.%s = %s,\n" % (f, v))
850 if (self.instance == 0):
851 self.instance_name = "dev_root"
852 file.write("struct device **last_dev_p = &%s.next;\n" % (self.image.last_device.instance_name))
853 file.write("struct device dev_root = {\n")
854 file.write("\t.ops = &default_dev_ops_root,\n")
855 file.write("\t.bus = &dev_root.link[0],\n")
856 file.write("\t.path = { .type = DEVICE_PATH_ROOT },\n")
857 file.write("\t.enabled = 1,\n\t.links = 1,\n")
858 file.write("\t.on_mainboard = 1,\n")
859 file.write("\t.link = {\n\t\t[0] = {\n")
860 file.write("\t\t\t.dev=&dev_root,\n\t\t\t.link = 0,\n")
861 file.write("\t\t\t.children = &%s,\n" % self.firstchilddevice().instance_name)
862 file.write("\t\t},\n")
864 if (self.chipconfig):
865 file.write("\t.chip_ops = &%s_ops,\n" % self.type_name)
866 file.write("\t.chip_info = &%s_info_%s,\n" % (self.type_name, self.instance))
867 file.write("\t.next = &%s,\n" % self.firstchilddevice().instance_name)
871 # Don't print duplicate devices, just print their children
875 file.write("struct device %s = {\n" % self.instance_name)
876 file.write("\t.ops = 0,\n")
877 file.write("\t.bus = &%s.link[%d],\n" % \
878 (self.firstparentdevice().instance_name, \
879 self.firstparentdevicelink()))
880 file.write("\t.path = {%s},\n" % self.path)
881 file.write("\t.enabled = %d,\n" % self.enabled)
882 file.write("\t.on_mainboard = 1,\n")
884 file.write("\t.resources = %d,\n" % self.resources)
885 file.write("\t.resource = {%s\n\t },\n" % self.resource)
886 file.write("\t.link = {\n");
889 while(bus and (bus.path == self.path)):
890 child = bus.firstchilddevice()
891 if (child or (bus != self) or (bus.next_sibling and (bus.next_sibling.path == self.path))):
892 file.write("\t\t[%d] = {\n" % links)
893 file.write("\t\t\t.link = %d,\n" % links)
894 file.write("\t\t\t.dev = &%s,\n" % self.instance_name)
896 file.write("\t\t\t.children = &%s,\n" %child.instance_name)
897 file.write("\t\t},\n")
900 bus = bus.next_sibling
904 file.write("\t.links = %d,\n" % (links))
905 sibling = self.firstsiblingdevice();
907 file.write("\t.sibling = &%s,\n" % sibling.instance_name)
908 chip = self.firstparentchip()
909 if (chip and chip.chipconfig):
910 file.write("\t.chip_ops = &%s_ops,\n" % chip.type_name)
911 file.write("\t.chip_info = &%s_info_%s,\n" % (chip.type_name, chip.instance))
912 if (self.next_device):
913 file.write("\t.next=&%s\n" % self.next_device.instance_name)
917 def addinit(self, code):
918 """Add init file to this part"""
919 self.initcode.append(code)
921 def addconfig(self, path):
922 """Add chip config file to this part"""
923 self.chipconfig = os.path.join(self.dir, path)
924 self.image.addconfiginclude(self.type_name, self.chipconfig)
926 def addregister(self, field, value):
927 """Register static initialization information"""
928 if (self.chip_or_device != 'chip'):
929 fatal("Only chips can have register values")
930 field = dequote(field)
931 value = dequote(value)
932 setdict(self.registercode, field, value)
934 def set_enabled(self, enabled):
935 self.enabled = enabled
937 def start_resources(self):
941 def end_resources(self):
942 self.resource = "%s" % (self.resource)
944 def add_resource(self, type, index, value):
945 """ Add a resource to a device """
946 self.resource = "%s\n\t\t{ .flags=%s, .index=0x%x, .base=0x%x}," % (self.resource, type, index, value)
947 self.resources = self.resources + 1
949 def set_path(self, path):
951 if (self.prev_sibling and (self.prev_sibling.path == self.path)):
953 if (self.prev_device):
954 self.prev_device.next_device = self.next_device
955 if (self.next_device):
956 self.next_device.prev_device = self.prev_device
957 if (self.image.last_device == self):
958 self.image.last_device = self.prev_device
962 def addpcipath(self, slot, function):
963 """ Add a relative pci style path from our parent to this device """
964 if ((slot < 0) or (slot > 0x1f)):
965 fatal("Invalid device id")
966 if ((function < 0) or (function > 7)):
967 fatal("Invalid pci function %s" % function )
968 self.set_path(".type=DEVICE_PATH_PCI,{.pci={ .devfn = PCI_DEVFN(0x%x,%d)}}" % (slot, function))
970 def addpnppath(self, port, device):
971 """ Add a relative path to a pnp device hanging off our parent """
972 if ((port < 0) or (port > 65536)):
973 fatal("Invalid port")
974 if ((device < 0) or (device > 0xffff)):
975 fatal("Invalid device")
976 self.set_path(".type=DEVICE_PATH_PNP,{.pnp={ .port = 0x%x, .device = 0x%x }}" % (port, device))
978 def addi2cpath(self, device):
979 """ Add a relative path to a i2c device hanging off our parent """
980 if ((device < 0) or (device > 0x7f)):
981 fatal("Invalid device")
982 self.set_path(".type=DEVICE_PATH_I2C,{.i2c={ .device = 0x%x }}" % (device))
984 def addapicpath(self, apic_id):
985 """ Add a relative path to a cpu device hanging off our parent """
986 if ((apic_id < 0) or (apic_id > 255)):
987 fatal("Invalid device")
988 self.set_path(".type=DEVICE_PATH_APIC,{.apic={ .apic_id = 0x%x }}" % (apic_id))
990 def addpci_domainpath(self, pci_domain):
991 """ Add a pci_domain number to a chip """
992 if ((pci_domain < 0) or (pci_domain > 0xffff)):
993 fatal("Invalid pci_domain: 0x%x is out of the range 0 to 0xffff" % pci_domain)
994 self.set_path(".type=DEVICE_PATH_PCI_DOMAIN,{.pci_domain={ .domain = 0x%x }}" % (pci_domain))
996 def addapic_clusterpath(self, cluster):
997 """ Add an apic cluster to a chip """
998 if ((cluster < 0) or (cluster > 15)):
999 fatal("Invalid apic cluster: %d is out of the range 0 to ff" % cluster)
1000 self.set_path(".type=DEVICE_PATH_APIC_CLUSTER,{.apic_cluster={ .cluster = 0x%x }}" % (cluster))
1002 def addcpupath(self, cpu_id):
1003 """ Add a relative path to a cpu device hanging off our parent """
1004 if ((cpu_id < 0) or (cpu_id > 255)):
1005 fatal("Invalid device")
1006 self.set_path(".type=DEVICE_PATH_CPU,{.cpu={ .id = 0x%x }}" % (cpu_id))
1009 def addcpu_buspath(self, id):
1010 """ Add a cpu_bus to a chip """
1011 if ((id < 0) or (id > 255)):
1012 fatal("Invalid device")
1013 self.set_path(".type=DEVICE_PATH_CPU_BUS,{.cpu_bus={ .id = 0x%x }}" % (id))
1015 def usesoption(self, name):
1016 """Declare option that can be used by this part"""
1017 global global_options
1018 o = getdict(global_options, name)
1020 fatal("can't use undefined option %s" % name)
1021 o1 = getdict(self.uses_options, name)
1024 setdict(self.uses_options, name, o)
1025 exportoption(o, self.image.exported_options)
1027 # -----------------------------------------------------------------------------
1029 # -----------------------------------------------------------------------------
1031 def getdict(dict, name):
1032 if name not in dict.keys():
1033 debug.info(debug.dict, "Undefined: %s" % name)
1035 v = dict.get(name, 0)
1036 debug.info(debug.dict, "getdict %s returning %s" % (name, v))
1039 def setdict(dict, name, value):
1040 debug.info(debug.dict, "setdict sets %s to %s" % (name, value))
1041 if name in dict.keys():
1042 print "Duplicate in dict: %s" % name
1046 # to create an option, it has to not exist.
1047 # When an option value is fetched, the fact that it was used is
1049 # Legal things to do:
1050 # set a default value, then set a real value before the option is used.
1051 # set a value, try to set a default, default silently fails.
1053 # use the value, then try to set the value
1055 def newoption(name):
1056 global global_options, global_options_by_order
1057 o = getdict(global_options, name)
1059 fatal("option %s already defined" % name)
1061 setdict(global_options, name, o)
1062 global_options_by_order.append(name)
1064 def newoptionvalue(name, image):
1065 g = getdict(global_option_values, name)
1066 v = option_value(name, g)
1068 setdict(image.getvalues(), name, v)
1070 setdict(global_option_values, name, v)
1073 def getoptionvalue(name, op, image):
1074 global global_option_values
1075 #print "getoptionvalue name %s op %s image %s\n" % (name, op,image)
1077 # we want to debug config files, not the config tool, so no:
1079 fatal("Option %s undefined (missing use command?)" % name)
1081 v = getdict(image.getvalues(), name)
1083 v = getdict(global_option_values, name)
1086 def getoption(name, image):
1087 """option must be declared before being used in a part
1088 if we're not processing a part, then we must
1089 be at the top level where all options are available"""
1091 global global_uses_options, alloptions, curimage
1093 #print "getoption: name %s image %s alloptions %s curimage %s\n\n" % (name, image, alloptions, curimage)
1094 curpart = partstack.tos()
1096 o = getdict(global_options, name)
1098 o = getdict(curpart.uses_options, name)
1100 print "curpart.uses_options is %s\n" % curpart.uses_options
1102 o = getdict(global_uses_options, name)
1103 v = getoptionvalue(name, o, image)
1105 v = getoptionvalue(name, o, 0)
1107 fatal("No value for option %s" % name)
1109 if (not (type(val) is types.StringType)):
1111 if (val == '' or val[0] != '{'):
1115 val = parse('delexpr', val)
1120 def setoption(name, value, imp):
1121 """Set an option from within a configuration file. Normally this
1122 is only permitted in the target (top level) configuration file.
1123 If 'imp' is true, then set an option implicitly (e.g. 'arch'
1124 and 'mainboard' statements). Implicit options can be set anywhere
1125 the statements are legal, but also performs an implicit 'uses'
1128 global loc, global_options, global_option_values, curimage
1130 curpart = partstack.tos()
1131 if (not imp and curpart):
1132 fatal("Options may only be set in target configuration file")
1136 o = getdict(curpart.uses_options, name)
1138 o = getdict(global_uses_options, name)
1140 fatal("Attempt to set nonexistent option %s (missing USES?)" % name)
1141 v = getoptionvalue(name, o, curimage)
1143 v = newoptionvalue(name, curimage)
1146 def exportoption(op, exported_options):
1147 if (not op.isexportable()):
1149 if (not op in exported_options):
1150 exported_options.append(op)
1152 def setdefault(name, value, isdef):
1153 """Set the default value of an option from within a configuration
1154 file. This is permitted from any configuration file, but will
1155 result in a warning if the default is set more than once.
1156 If 'isdef' is set, we're defining the option in Options.lb so
1157 there is no need for 'uses'."""
1159 global loc, global_options, curimage
1162 o = getdict(global_options, name)
1167 curpart = partstack.tos()
1169 o = getdict(curpart.uses_options, name)
1171 o = getdict(global_uses_options, name)
1173 fatal("Attempt to set default for nonexistent option %s (missing USES?)" % name)
1176 v = getoptionvalue(name, o, image)
1178 v = newoptionvalue(name, image)
1181 def setnodefault(name):
1182 global loc, global_options
1183 o = getdict(global_options, name)
1186 v = getdict(global_option_values, name)
1188 warning("removing default for %s" % name)
1189 del global_option_values[name]
1191 def setcomment(name, value):
1192 global loc, global_options
1193 o = getdict(global_options, name)
1195 fatal("setcomment: %s not here" % name)
1196 o.setcomment(value, loc)
1198 def setexported(name):
1199 global global_options
1200 o = getdict(global_options, name)
1202 fatal("setexported: %s not here" % name)
1204 global_exported_options.append(o)
1206 def setnoexport(name):
1207 global global_options
1208 o = getdict(global_options, name)
1210 fatal("setnoexport: %s not here" % name)
1212 if (o in global_exported_options):
1213 global_exported_options.remove(o)
1215 def setexportable(name):
1216 global global_options
1217 o = getdict(global_options, name)
1219 fatal("setexportable: %s not here" % name)
1222 def setformat(name, fmt):
1223 global global_options
1224 o = getdict(global_options, name)
1226 fatal("setformat: %s not here" % name)
1229 def getformated(name, image):
1230 global global_options, global_option_values
1231 o = getdict(global_options, name)
1232 v = getoption(name, image)
1236 def setwrite(name, part):
1237 global global_options
1238 o = getdict(global_options, name)
1240 fatal("setwrite: %s not here" % name)
1243 def hasvalue(name, image):
1244 global global_options
1245 o = getdict(global_options, name)
1250 v = getdict(image.getvalues(), name)
1252 v = getdict(global_option_values, name)
1255 def isset(name, part):
1256 global global_uses_options, global_option_values, curimage
1258 o = getdict(part.uses_options, name)
1260 o = getdict(global_uses_options, name)
1265 v = getdict(curimage.getvalues(), name)
1267 v = getdict(global_option_values, name)
1268 return (v != 0 and v.isset())
1270 def usesoption(name):
1271 global global_options, global_uses_options
1272 curpart = partstack.tos()
1274 curpart.usesoption(name)
1276 o = getdict(global_options, name)
1278 fatal("Can't use undefined option %s" % name)
1279 o1 = getdict(global_uses_options, name)
1282 setdict(global_uses_options, name, o)
1283 exportoption(o, global_exported_options)
1285 def validdef(name, defval):
1286 global global_options
1287 o = getdict(global_options, name)
1289 fatal("validdef: %s not here" % name)
1290 if ((defval & 1) != 1):
1291 fatal("Must specify default value for option %s" % name)
1292 if ((defval & 2) != 2):
1293 fatal("Must specify export for option %s" % name)
1294 if ((defval & 4) != 4):
1295 fatal("Must specify comment for option %s" % name)
1297 def loadoptions(path, file, rule):
1298 file = os.path.join('src', path, file)
1299 optionsfile = os.path.join(treetop, file)
1300 fp = safe_open(optionsfile, 'r')
1302 if (not parse(rule, fp.read())):
1303 fatal("Could not parse file")
1307 global curimage, dirstack
1308 if (path[0] == '/'):
1309 curimage.setinitfile(treetop + '/src/' + path)
1311 curimage.setinitfile(dirstack.tos() + '/' + path)
1312 print "Adding init file: %s" % path
1314 def addconfig(path):
1316 curpart = partstack.tos()
1317 curpart.addconfig(path)
1319 def addregister(field, value):
1321 curpart = partstack.tos()
1322 curpart.addregister(field, value)
1324 def addcrt0include(path):
1325 """we do the crt0include as a dictionary, so that if needed we
1326 can trace who added what when. Also it makes the keys
1329 curimage.addinitinclude(0, path)
1331 def addinitinclude(str, path):
1333 curimage.addinitinclude(dequote(str), path)
1335 def addldscript(path):
1336 global curimage, dirstack
1337 curdir = dirstack.tos()
1338 if (path[0] == '/'):
1339 fullpath = treetop + '/src/' + path
1341 fullpath = curdir + '/' + path
1342 debug.info(debug.statement, "fullpath :%s: curdir :%s: path :%s:" % (fullpath, curdir, path))
1343 curimage.addldscript(fullpath)
1347 curimage.setpayload(path)
1348 adduserdefine("PAYLOAD:=%s"%path)
1350 def startromimage(name):
1351 global romimages, curimage, target_dir, target_name
1352 curpart = partstack.tos()
1353 print "Configuring ROMIMAGE %s Curimage %s" % (name, curimage)
1354 print "Curpart is %s\n" % curpart
1355 o = getdict(romimages, name)
1357 fatal("romimage %s previously defined" % name)
1358 curimage = romimage(name)
1359 curimage.settargetdir(os.path.join(target_dir, name))
1360 #o = partobj(curimage, target_dir, 0, 'board', target_name)
1361 #curimage.setroot(o)
1362 setdict(romimages, name, curimage)
1363 dodir('/config', 'Config.lb')
1367 global bootblocksize
1369 imagesize = getoption("ROM_IMAGE_SIZE", curimage)
1370 bootblocksize += imagesize
1371 print "End ROMIMAGE"
1375 def mainboardsetup(path):
1376 global full_mainboard_path, mainboard_path
1377 mainboard_path = os.path.join('mainboard', path)
1378 loadoptions(mainboard_path, 'Options.lb', 'mainboardvariables')
1379 full_mainboard_path = os.path.join(treetop, 'src', 'mainboard', path)
1380 vendor = re.sub("/.*", "", path)
1381 part_number = re.sub("[^/]*/", "", path)
1382 setdefault('MAINBOARD', full_mainboard_path, 0)
1383 setdefault('MAINBOARD_VENDOR', vendor, 0)
1384 setdefault('MAINBOARD_PART_NUMBER', part_number, 0)
1387 global curimage, dirstack, partstack
1389 partdir = mainboard_path
1390 srcdir = os.path.join(treetop, 'src')
1391 fulldir = os.path.join(srcdir, partdir)
1392 type_name = flatten_name(partdir)
1393 newpart = partobj(curimage, fulldir, partstack.tos(), 'mainboard', \
1394 'mainboard', 0, 'chip')
1395 #print "Configuring PART %s" % (type)
1396 partstack.push(newpart)
1397 #print " new PART tos is now %s\n" %partstack.tos().info()
1398 dirstack.push(fulldir)
1399 loadoptions(mainboard_path, 'Options.lb', 'mainboardvariables')
1400 # special case for 'cpu' parts.
1401 # we could add a new function too, but this is rather trivial.
1402 # if the part is a cpu, and we haven't seen it before,
1403 # arrange to source the directory /cpu/'type'
1404 doconfigfile(srcdir, partdir, file, 'cfgfile')
1405 curimage.setroot(partstack.tos())
1408 def addbuildrom(filename, size, roms):
1410 print "Build ROM size %d" % size
1411 b = buildrom(filename, size, roms)
1414 def addpci_rom(filename, vendor, device):
1416 print "Add PCI ROM %s" %filename
1417 p = pci_rom(filename, vendor, device)
1420 def addinitobject(object_name):
1422 curimage.addinitobjectrule(object_name)
1424 def addobject(object_name):
1426 curimage.addobjectrule(object_name)
1428 def adddriver(driver_name):
1430 curimage.adddriverrule(driver_name)
1432 def addsmmobject(object_name):
1434 curimage.addsmmobjectrule(object_name)
1437 global target_dir, target_name
1438 print "Configuring TARGET %s" % name
1440 target_dir = os.path.join(os.path.dirname(loc.file()), name)
1441 if not os.path.isdir(target_dir):
1442 print "Creating directory %s" % target_dir
1443 os.makedirs(target_dir)
1444 print "Will place Makefile, crt0.S, etc. in %s" % target_dir
1449 if (cpu_type and (cpu_type != path)):
1450 fatal("Two different CPU types: %s and %s" % (cpu_type, path))
1451 srcdir = "/cpu/%s" % path
1452 dodir(srcdir, "Config.lb")
1455 def devicepart(type):
1456 global curimage, dirstack, partstack
1457 newpart = partobj(curimage, 0, partstack.tos(), type, \
1459 #print "Configuring PART %s" % (type)
1460 partstack.push(newpart)
1461 #print " new PART tos is now %s\n" %partstack.tos().info()
1462 # just push TOS, so that we can pop later.
1463 dirstack.push(dirstack.tos())
1465 def part(type, path, file, name):
1466 global curimage, dirstack, partstack
1467 partdir = os.path.join(type, path)
1468 srcdir = os.path.join(treetop, 'src')
1469 fulldir = os.path.join(srcdir, partdir)
1470 type_name = flatten_name(partdir)
1471 newpart = partobj(curimage, fulldir, partstack.tos(), type, \
1472 type_name, name, 'chip')
1473 #print "Configuring PART %s, path %s" % (type, path)
1474 partstack.push(newpart)
1475 #print " new PART tos is now %s\n" %partstack.tos().info()
1476 dirstack.push(fulldir)
1477 # special case for 'cpu' parts.
1478 # we could add a new function too, but this is rather trivial.
1479 # if the part is a cpu, and we haven't seen it before,
1480 # arrange to source the directory /cpu/'type'
1484 doconfigfile(srcdir, partdir, file, 'cfgfile')
1487 global dirstack, partstack
1488 curpart = partstack.tos()
1490 fatal("Trying to pop non-existent part")
1491 #print "End PART %s" % curpart.part
1492 # Warn if options are used without being set in this part
1493 for op in curpart.uses_options.keys():
1494 if (not isset(op, curpart)):
1495 notice("Option %s using default value %s" % (op, getformated(op, curpart.image)))
1496 oldpart = partstack.pop()
1498 #print "partstack.pop, TOS is now %s\n" % oldpart.info()
1500 def dodir(path, file):
1501 """dodir is like part but there is no new part"""
1503 # if the first char is '/', it is relative to treetop,
1504 # else relative to curdir
1505 # os.path.join screws up if the name starts with '/', sigh.
1506 print "Configuring DIR %s" % os.path.join(path, file)
1507 if (path[0] == '/'):
1508 fullpath = os.path.join(treetop, 'src')
1509 path = re.sub('^/*', '', path)
1511 fullpath = dirstack.tos()
1512 debug.info(debug.statement, "DODIR: path %s, fullpath %s" % (path, fullpath))
1513 dirstack.push(os.path.join(fullpath, path))
1514 doconfigfile(fullpath, path, file, 'cfgfile')
1518 """dofile is a simple include for single files"""
1519 # if the first char is '/', it is relative to treetop,
1520 # else relative to curdir
1521 # os.path.join screws up if the name starts with '/', sigh.
1522 if (path[0] == '/'):
1523 fullpath = os.path.join(treetop, 'src')
1524 path = re.sub('^/*', '', path)
1526 fullpath = dirstack.tos()
1527 print "INCLUDE %s" %path
1528 debug.info(debug.statement, "DOFILE: path %s, fullpath %s" % (path, fullpath))
1529 doconfigfile(fullpath, '', path, 'cfgfile')
1533 return getoption(name, curimage)
1537 curimage.addmakerule(id)
1539 def adduserdefine(str):
1541 curimage.adduserdefine(str)
1543 def addaction(id, str):
1545 curimage.addmakeaction(id, str)
1547 def adddep(id, str):
1549 curimage.addmakedepend(id, str)
1551 def setarch(my_arch):
1552 """arch is 'different' ... darn it."""
1554 print "SETTING ARCH %s\n" % my_arch
1555 curimage.setarch(my_arch)
1556 setdefault('ARCH', my_arch, 1)
1557 part('arch', my_arch, 'Config.lb', 0)
1559 def doconfigfile(path, confdir, file, rule):
1560 rname = os.path.join(confdir, file)
1562 fullpath = os.path.join(path, rname)
1563 fp = safe_open(fullpath, 'r')
1564 if (not parse(rule, fp.read())):
1565 fatal("Could not parse file")
1569 #=============================================================================
1571 #=============================================================================
1572 def ternary(val, yes, no):
1573 debug.info(debug.statement, "ternary %s" % expr)
1574 debug.info(debug.statement, "expr %s a %d yes %d no %d"% (expr, a, yes, no))
1576 debug.info(debug.statement, "Ternary returns %d" % yes)
1579 debug.info(debug.statement, "Ternary returns %d" % no)
1583 """atoi is in the python library, but not strtol? Weird!"""
1584 return eval('int(%s)' % name)
1587 """ Is the given string an integer?"""
1595 a = re.sub("^\"", "", str)
1596 a = re.sub("\"$", "", a)
1597 # highly un-intuitive, need four \!
1598 a = re.sub("\\\\\"", "\"", a)
1601 def flatten_name(str):
1602 a = re.sub("[/-]", "_", str)
1606 """If the first part of <path> matches treetop, replace
1607 that part with $(TOP)"""
1608 if path[0:len(treetop)] == treetop:
1609 path = path[len(treetop):len(path)]
1610 if (path[0:1] == "/"):
1611 path = path[1:len(path)]
1612 path = "$(TOP)/" + path
1616 # to make if work without 2 passses, we use an old hack from SIMD, the
1617 # context bit. If the bit is 1, then ops get done, otherwise
1618 # ops don't get done. From the top level, context is always
1619 # 1. In an if, context depends on eval of the if condition
1625 # less general tokens should come first, otherwise they get matched
1627 token ACTION: 'action'
1628 token ADDACTION: 'addaction'
1629 token ALWAYS: 'always'
1631 token BUILDROM: 'buildrom'
1632 token COMMENT: 'comment'
1633 token CONFIG: 'config'
1635 token CPU_BUS: 'cpu_bus'
1637 token DEFAULT: 'default'
1638 token DEFINE: 'define'
1639 token DEPENDS: 'depends'
1640 token DEVICE: 'device'
1641 token DEVICE_ID: 'device_id'
1643 token DRIVER: 'driver'
1649 token EXPORT: 'export'
1650 token FORMAT: 'format'
1653 token INITOBJECT: 'initobject'
1654 token INITINCLUDE: 'initinclude'
1655 token INCLUDE: 'include'
1658 token LDSCRIPT: 'ldscript'
1659 token LOADOPTIONS: 'loadoptions'
1660 token MAINBOARD: 'mainboard'
1661 token MAINBOARDINIT: 'mainboardinit'
1662 token MAKEDEFINE: 'makedefine'
1663 token MAKERULE: 'makerule'
1665 token NEVER: 'never'
1667 token NORTHBRIDGE: 'northbridge'
1668 token OBJECT: 'object'
1669 token OPTION: 'option'
1670 token PAYLOAD: 'payload'
1671 token PCI_ROM: 'pci_rom'
1673 token PRINT: 'print'
1674 token REGISTER: 'register'
1675 token ROMIMAGE: 'romimage'
1676 token SMMOBJECT: 'smmobject'
1677 token SOUTHBRIDGE: 'southbridge'
1678 token SUPERIO: 'superio'
1679 token TARGET: 'target'
1682 token VENDOR_ID: 'vendor_id'
1683 token WRITE: 'write'
1685 token HEX_NUM: '[0-9a-fA-F]+'
1686 token HEX_PREFIX: '0x'
1687 # Why is path separate? Because paths to resources have to at least
1688 # have a slash, we thinks
1689 token PATH: r'[-a-zA-Z0-9_.][-a-zA-Z0-9/_.]+[-a-zA-Z0-9_.]+'
1690 # Dir's on the other hand are abitrary
1691 # this may all be stupid.
1692 token RULE: r'[-a-zA-Z0-9_$()./]+[-a-zA-Z0-9_ $()./]+[-a-zA-Z0-9_$()./]+'
1693 token DIRPATH: r'[-a-zA-Z0-9_$()./]+'
1694 token ID: r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
1695 token DELEXPR: r'{([^}]+|\\.)*}'
1696 token STR: r'"([^\\"]+|\\.)*"'
1697 token RAWTEXT: r'.*'
1704 token APIC_CLUSTER: 'apic_cluster'
1706 token CPU_BUS: 'cpu_bus'
1707 token PCI_DOMAIN: 'pci_domain'
1710 rule expr: logical {{ l = logical }}
1711 ( "&&" logical {{ l = l and logical }}
1712 | "[|][|]" logical {{ l = l or logical }}
1715 rule logical: factor {{ n = factor }}
1716 ( "[+]" factor {{ n = n+factor }}
1717 | "-" factor {{ n = n-factor }}
1720 rule factor: term {{ v = term }}
1721 ( "[*]" term {{ v = v*term }}
1722 | "/" term {{ v = v/term }}
1723 | "<<" term {{ v = v << term }}
1724 | ">=" term {{ v = (v < term)}}
1727 # A term is a number, variable, or an expression surrounded by parentheses
1728 rule term: NUM {{ return long(NUM, 10) }}
1729 | HEX_PREFIX HEX_NUM {{ return long(HEX_NUM, 16) }}
1730 | ID {{ return lookup(ID) }}
1731 | unop {{ return unop }}
1732 | "\\(" expr "\\)" {{ return expr }}
1734 rule unop: "!" expr {{ return not(expr) }}
1736 rule partend<<C>>: (stmt<<C>>)* END {{ if (C): partpop()}}
1738 # This is needed because the legacy cpu command could not distinguish
1739 # between cpu vendors. It should just be PATH, but getting this change
1740 # into the source tree will be tricky...
1741 # DO NOT USE ID AS IT MAY GO AWAY IN THE FUTURE
1742 rule partid: ID {{ return ID }}
1743 | PATH {{ return PATH }}
1745 # rule parttype: NORTHBRIDGE {{ return 'northbridge' }}
1746 # | SUPERIO {{ return 'superio' }}
1747 # | PMC {{ return 'pmc' }}
1748 # | SOUTHBRIDGE {{ return 'southbridge' }}
1749 # | CPU {{ return 'cpu' }}
1750 # | CHIP {{ return '' }}
1752 rule parttype: CHIP {{ return '' }}
1754 rule partdef<<C>>: {{ name = 0 }}
1756 [ STR {{ name = dequote(STR) }}
1757 ] {{ if (C): part(parttype, partid, 'Config.lb', name) }}
1760 rule arch<<C>>: ARCH ID {{ if (C): setarch(ID) }}
1763 rule mainboardinit<<C>>:
1764 MAINBOARDINIT DIRPATH {{ if (C): addcrt0include(DIRPATH)}}
1766 rule initinclude<<C>>:
1769 DIRPATH {{ if (C): addinitinclude(STR, DIRPATH)}}
1771 rule initobject<<C>>:
1772 INITOBJECT DIRPATH {{ if (C): addinitobject(DIRPATH)}}
1774 rule object<<C>>: OBJECT DIRPATH {{ if (C): addobject(DIRPATH)}}
1776 rule driver<<C>>: DRIVER DIRPATH {{ if (C): adddriver(DIRPATH)}}
1778 rule smmobject<<C>>:
1779 SMMOBJECT DIRPATH {{ if (C): addsmmobject(DIRPATH)}}
1782 rule dir<<C>>: DIR DIRPATH {{ if (C): dodir(DIRPATH, 'Config.lb') }}
1784 rule default<<C>>: DEFAULT ID EQ value {{ if (C): setdefault(ID, value, 0) }}
1786 rule ldscript<<C>>: LDSCRIPT DIRPATH {{ if (C): addldscript(DIRPATH) }}
1788 rule iif<<C>>: IF ID {{ c = lookup(ID) }}
1790 [ ELSE (stmt<<C and not c>>)* ]
1793 rule makerule<<C>>: MAKERULE RULE {{ if (C): addrule(RULE) }}
1794 ( DEPENDS STR {{ if (C): adddep(RULE, STR) }}
1795 | ACTION STR {{ if (C): addaction(RULE, STR) }}
1799 rule makedefine<<C>>:
1800 MAKEDEFINE RAWTEXT {{ if (C): adduserdefine(RAWTEXT) }}
1802 rule addaction<<C>>:
1803 ADDACTION ID STR {{ if (C): addaction(ID, STR) }}
1805 rule init<<C>>: INIT DIRPATH {{ if (C): addinit(DIRPATH) }}
1807 rule field: STR {{ return STR }}
1809 rule register<<C>>: REGISTER field '=' STR {{ if (C): addregister(field, STR) }}
1811 rule enable<<C>>: {{ val = 1 }}
1814 ) {{ if(C): partstack.tos().set_enabled(val) }}
1816 rule resource<<C>>: {{ type = "" }}
1817 ( IO {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_IO" }}
1818 | MEM {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_MEM" }}
1819 | IRQ {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_IRQ" }}
1820 | DRQ {{ type = "IORESOURCE_FIXED | IORESOURCE_ASSIGNED | IORESOURCE_DRQ" }}
1822 term '=' {{ index = term }}
1823 term {{ value = term }}
1824 {{ if (C): partstack.tos().add_resource(type, index, value) }}
1827 rule resources<<C>>: {{ if (C): partstack.tos().start_resources() }}
1829 {{ if (C): partstack.tos().end_resources() }}
1832 rule pci<<C>>: PCI {{ if (C): devicepart('pci') }}
1834 HEX_NUM {{ slot = int(HEX_NUM,16) }}
1835 '.' HEX_NUM {{ function = int(HEX_NUM, 16) }}
1836 {{ if (C): partstack.tos().addpcipath(slot, function) }}
1837 rule pci_domain<<C>>:
1838 PCI_DOMAIN {{ if (C): devicepart('pci_domain') }}
1839 HEX_NUM {{ pci_domain = int(HEX_NUM, 16) }}
1840 {{ if (C): partstack.tos().addpci_domainpath(pci_domain) }}
1842 rule pnp<<C>>: PNP {{ if (C): devicepart('pnp') }}
1843 HEX_NUM {{ port = int(HEX_NUM,16) }}
1844 '.' HEX_NUM {{ device = int(HEX_NUM, 16) }}
1845 {{ if (C): partstack.tos().addpnppath(port, device) }}
1847 rule i2c<<C>>: I2C {{ if (C): devicepart('i2c') }}
1848 HEX_NUM {{ device = int(HEX_NUM, 16) }}
1849 {{ if (C): partstack.tos().addi2cpath(device) }}
1851 rule apic<<C>>: APIC {{ if (C): devicepart('apic') }}
1852 HEX_NUM {{ apic_id = int(HEX_NUM, 16) }}
1853 {{ if (C): partstack.tos().addapicpath(apic_id) }}
1855 rule apic_cluster<<C>>: APIC_CLUSTER {{ if (C): devicepart('apic_cluster') }}
1856 HEX_NUM {{ cluster = int(HEX_NUM, 16) }}
1857 {{ if (C): partstack.tos().addapic_clusterpath(cluster) }}
1859 rule include<<C>>: INCLUDE DIRPATH {{ dofile(DIRPATH) }}
1861 rule cpu<<C>>: CPU {{ if (C): devicepart('cpu') }}
1862 HEX_NUM {{ id = int(HEX_NUM, 16) }}
1863 {{ if (C): partstack.tos().addcpupath(id) }}
1865 rule cpu_bus<<C>>: CPU_BUS {{ if (C): devicepart('cpu_bus') }}
1866 HEX_NUM {{ id = int(HEX_NUM, 16) }}
1867 {{ if (C): partstack.tos().addcpu_buspath(id) }}
1870 pci<<C>> {{ return pci }}
1871 | pci_domain<<C>> {{ return pci_domain }}
1872 | pnp<<C>> {{ return pnp }}
1873 | i2c<<C>> {{ return i2c }}
1874 | apic<<C>> {{ return apic }}
1875 | apic_cluster<<C>> {{ return apic_cluster }}
1876 | cpu<<C>> {{ return cpu }}
1877 | cpu_bus<<C>> {{ return cpu_bus }}
1879 rule prtval: expr {{ return str(expr) }}
1880 | STR {{ return STR }}
1882 rule prtlist: prtval {{ el = "%(" + prtval }}
1883 ( "," prtval {{ el = el + "," + prtval }}
1884 )* {{ return el + ")" }}
1886 rule prtstmt<<C>>: PRINT STR {{ val = STR }}
1887 [ "," prtlist {{ val = val + prtlist }}
1888 ] {{ if (C): print eval(val) }}
1890 rule config<<C>>: CONFIG PATH {{ if (C): addconfig(PATH) }}
1892 rule device<<C>>: DEVICE dev_path<<C>>
1897 rule stmt<<C>>: arch<<C>> {{ return arch}}
1898 | addaction<<C>> {{ return addaction }}
1899 | config<<C>> {{ return config}}
1900 | default<<C>> {{ return default}}
1901 | dir<<C>> {{ return dir}}
1902 | driver<<C>> {{ return driver }}
1903 | iif<<C>> {{ return iif }}
1904 | init<<C>> {{ return init }}
1905 | initinclude<<C>> {{ return initinclude }}
1906 | include<<C>> {{ return include }}
1907 | initobject<<C>> {{ return initobject }}
1908 | ldscript<<C>> {{ return ldscript}}
1909 | mainboardinit<<C>> {{ return mainboardinit }}
1910 | makedefine<<C>> {{ return makedefine }}
1911 | makerule<<C>> {{ return makerule }}
1912 | object<<C>> {{ return object }}
1913 | option<<C>> {{ return option }}
1914 | partdef<<C>> {{ return partdef }}
1915 | prtstmt<<C>> {{ return prtstmt }}
1916 | register<<C>> {{ return register }}
1917 | device<<C>> {{ return device }}
1918 | smmobject<<C>> {{ return smmobject }}
1920 # ENTRY for parsing Config.lb file
1921 rule cfgfile: (uses<<1>>)*
1925 rule usesid<<C>>: ID {{ if (C): usesoption(ID) }}
1927 rule uses<<C>>: USES (usesid<<C>>)+
1929 rule mainboardvariables: (uses<<1>>)*
1934 rule value: STR {{ return dequote(STR) }}
1935 | expr {{ return expr }}
1936 | DELEXPR {{ return DELEXPR }}
1938 rule option<<C>>: OPTION ID EQ value {{ if (C): setoption(ID, value, 0) }}
1940 rule opif<<C>>: IF ID {{ c = lookup(ID) }}
1941 (opstmt<<C and c>>)*
1942 [ ELSE (opstmt<<C and not c>>)* ]
1945 rule opstmt<<C>>: option<<C>>
1949 rule payload<<C>>: PAYLOAD DIRPATH {{ if (C): payload(DIRPATH) }}
1952 MAINBOARD PATH {{ mainboardsetup(PATH) }}
1954 rule romif<<C>>: IF ID {{ c = lookup(ID) }}
1955 (romstmt<<C and c>>)*
1956 [ ELSE (romstmt<<C and not c>>)* ]
1959 rule romstmt<<C>>: romif<<C>>
1963 rule romimage: ROMIMAGE STR {{ startromimage(dequote(STR)) }}
1965 END {{ endromimage() }}
1967 rule roms: STR {{ s = '[' + STR }}
1968 ( STR {{ s = s + "," + STR }}
1969 )* {{ return eval(s + ']') }}
1971 rule buildrom: BUILDROM DIRPATH expr roms {{ addbuildrom(DIRPATH, expr, roms) }}
1973 rule pci_vid: VENDOR_ID EQ term {{ return term }}
1975 rule pci_did: DEVICE_ID EQ term {{ return term }}
1978 rule pci_rom: PCI_ROM DIRPATH pci_vid pci_did {{ addpci_rom(DIRPATH, pci_vid, pci_did) }}
1980 rule romstmts: romimage
1985 # ENTRY for parsing root part
1986 rule board: {{ loadoptions("config", "Options.lb", "options") }}
1987 TARGET DIRPATH {{ target(DIRPATH) }}
1992 # ENTRY for parsing a delayed value
1993 rule delexpr: "{" expr "}" EOF {{ return expr }}
1995 rule wrstr<<ID>>: STR {{ setwrite(ID, dequote(STR)) }}
1997 rule defstmts<<ID>>: {{ d = 0 }}
1999 ( value {{ setdefault(ID, value, 1) }}
2000 | NONE {{ setnodefault(ID) }}
2002 | FORMAT STR {{ setformat(ID, dequote(STR)) }}
2004 ( ALWAYS {{ setexported(ID) }}
2005 | USED {{ setexportable(ID) }}
2006 | NEVER {{ setnoexport(ID) }}
2008 | COMMENT STR {{ setcomment(ID, dequote(STR)); d = d | 4 }}
2009 | WRITE (wrstr<<ID>>)+
2012 rule define: DEFINE ID {{ newoption(ID) }}
2013 defstmts<<ID>> END {{ validdef(ID, defstmts) }}
2015 # ENTRY for parsing Options.lb file
2016 rule options: (define)* EOF {{ return 1 }}
2019 #=============================================================================
2021 #=============================================================================
2022 def writemakefileheader(file, fname):
2023 file.write("# File: %s is autogenerated\n" % fname)
2025 def writemakefilefooter(file, fname):
2026 file.write("\n\n%s: %s %s\n"
2027 % (os.path.basename(fname), os.path.abspath(sys.argv[0]), top_config_file))
2028 file.write("\t(cd %s ; export PYTHONPATH=%s/util/newconfig ; python %s %s %s)\n\n"
2029 % (os.getcwd(), treetop, sys.argv[0], sys.argv[1], sys.argv[2]))
2031 def writemakefilesettings(path):
2032 """ Write Makefile.settings to seperate the settings
2033 from the actual makefile creation."""
2035 global treetop, target_dir
2037 filename = os.path.join(path, "Makefile.settings")
2038 print "Creating", filename
2039 file = safe_open(filename, 'w+')
2040 writemakefileheader(file, filename)
2041 file.write("TOP:=%s\n" % (treetop))
2042 file.write("TARGET_DIR:=%s\n" % target_dir)
2043 writemakefilefooter(file, filename)
2046 def writeimagesettings(image):
2047 """Write Makefile.settings to seperate the settings
2048 from the actual makefile creation."""
2051 global global_options_by_order
2053 filename = os.path.join(image.gettargetdir(), "Makefile.settings")
2054 print "Creating", filename
2055 file = safe_open(filename, 'w+')
2056 writemakefileheader(file, filename)
2057 file.write("TOP:=%s\n" % (treetop))
2058 file.write("TARGET_DIR:=%s\n" % (image.gettargetdir()))
2061 for o in global_exported_options:
2063 for o in image.exported_options:
2064 if (not o in exported):
2067 file.write("export %s:=" % o.name)
2068 if (hasvalue(o.name, image)):
2069 file.write("%s" % getformated(o.name, image))
2072 file.write("export VARIABLES :=\n")
2074 file.write("export VARIABLES += %s\n" % o.name)
2076 # writemakefilefooter(file,filename)
2079 # write the romimage makefile
2080 # let's try the Makefile
2081 # first, dump all the -D stuff
2083 def writeimagemakefile(image):
2084 makefilepath = os.path.join(image.gettargetdir(), "Makefile")
2085 print "Creating", makefilepath
2086 file = safe_open(makefilepath, 'w+')
2087 writemakefileheader(file, makefilepath)
2090 file.write("\nall: coreboot.rom\n\n")
2091 file.write(".PHONY: all\n\n")
2092 #file.write("include cpuflags\n")
2093 # Putting "include cpuflags" in the Makefile has the problem that the
2094 # cpuflags file would be generated _after_ we want to include it.
2095 # Instead, let make do the work of computing CPUFLAGS:
2096 file.write("# Get the value of TOP, VARIABLES, and several other variables.\n")
2097 file.write("include Makefile.settings\n\n")
2098 file.write("# Function to create an item like -Di586 or -DCONFIG_MAX_CPUS='1' or -Ui686\n")
2099 file.write("D_item = $(shell echo '$(if $(subst undefined,,$(origin $1)),\\#define $1$(if $($1), $($1),),\\#undef $1)' >> settings.h)\n\n")
2100 file.write("# Compute the value of CPUFLAGS here during make's first pass.\n")
2101 file.write("CPUFLAGS := $(strip $(shell echo '/* autogenerated */' > settings.h)$(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))-include $(PWD)/settings.h)\n\n")
2103 for i in image.getuserdefines():
2104 file.write("%s\n" %i)
2107 # print out all the object dependencies
2108 file.write("\n# object dependencies (objectrules:)\n")
2109 file.write("INIT-OBJECTS :=\n")
2110 file.write("OBJECTS :=\n")
2111 file.write("DRIVER :=\n")
2112 file.write("\nSOURCES :=\n")
2113 for irule, init in image.getinitobjectrules().items():
2116 file.write("INIT-OBJECTS += %s\n" % (i_name))
2117 file.write("SOURCES += %s\n" % (i_source))
2119 for objrule, obj in image.getobjectrules().items():
2122 file.write("OBJECTS += %s\n" % (obj_name))
2123 file.write("SOURCES += %s\n" % (obj_source))
2125 for srule, smm in image.getsmmobjectrules().items():
2128 file.write("SMM-OBJECTS += %s\n" % (s_name))
2129 file.write("SOURCES += %s\n" % (s_source))
2133 file.write("OBJECTS += static.o\n")
2134 file.write("SOURCES += static.c\n")
2136 for driverrule, driver in image.getdriverrules().items():
2137 obj_name = driver[0]
2138 obj_source = driver[1]
2139 file.write("DRIVER += %s\n" % (obj_name))
2140 file.write("SOURCES += %s\n" % (obj_source))
2142 # Print out all ldscript.ld dependencies.
2143 file.write("\n# ldscript.ld dependencies:\n")
2144 file.write("LDSUBSCRIPTS-1 := \n" )
2145 for script in image.getldscripts():
2146 file.write("LDSUBSCRIPTS-1 += %s\n" % topify(script))
2148 # Print out the dependencies for crt0_includes.h
2149 file.write("\n# Dependencies for crt0_includes.h\n")
2150 file.write("CRT0_INCLUDES:=\n")
2151 for inc in image.getinitincludes():
2152 if (local_path.match(inc)):
2153 file.write("CRT0_INCLUDES += %s\n" % inc)
2155 file.write("CRT0_INCLUDES += $(TOP)/src/%s\n" % inc)
2157 # Print out the user defines.
2158 file.write("\n# userdefines:\n")
2160 # Print out the base rules.
2161 # Need to have a rule that counts on 'all'.
2162 file.write("\n# mainrulelist:")
2164 # Print out any user rules.
2165 file.write("\n# From makerule or docipl commands:\n")
2167 file.write("\n# initobjectrules:\n")
2168 for irule, init in image.getinitobjectrules().items():
2169 source = topify(init[1])
2172 # for .S, .o depends on .s
2173 file.write("%s: %s.s\n" % (init[0], init[3]))
2174 file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
2175 # and .s depends on .S
2176 file.write("%s.s: %s\n" % (init[3], source))
2177 # Note: next 2 lines are ONE output line!
2178 file.write("\t$(CPP) $(CPPFLAGS) $< ")
2179 file.write(">$@.new && mv $@.new $@\n")
2181 file.write("%s: %s\n" % (init[0], source))
2182 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2184 file.write("\n# objectrules:\n")
2185 for objrule, obj in image.getobjectrules().items():
2186 source = topify(obj[1])
2189 # for .S, .o depends on .s
2190 file.write("%s: %s.s\n" % (obj[0], obj[3]))
2191 file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
2192 # and .s depends on .S
2193 file.write("%s.s: %s\n" % (obj[3], source))
2194 # Note: next 2 lines are ONE output line!
2195 file.write("\t$(CPP) $(CPPFLAGS) $< ")
2196 file.write(">$@.new && mv $@.new $@\n")
2198 file.write("%s: %s\n" % (obj[0], source))
2199 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2200 #file.write("%s\n" % objrule[2])
2202 for driverrule, driver in image.getdriverrules().items():
2203 source = topify(driver[1])
2204 file.write("%s: %s\n" % (driver[0], source))
2205 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2206 #file.write("%s\n" % objrule[2])
2208 file.write("\n# smmobjectrules:\n")
2209 for irule, smm in image.getsmmobjectrules().items():
2210 source = topify(smm[1])
2213 # for .S, .o depends on .s
2214 file.write("%s: %s.s\n" % (smm[0], smm[3]))
2215 file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
2216 # and .s depends on .S
2217 file.write("%s.s: %s\n" % (smm[3], source))
2218 # Note: next 2 lines are ONE output line!
2219 file.write("\t$(CPP) $(CPPFLAGS) $< ")
2220 file.write(">$@.new && mv $@.new $@\n")
2222 file.write("%s: %s\n" % (smm[0], source))
2223 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2225 # special rule for chip_target.c
2226 file.write("static.o: static.c\n")
2227 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
2229 # Print out the rules that will make cause the files
2230 # generated by NLBConfig.py to be remade if any dependencies change.
2232 file.write("\n# Remember the automatically generated files\n")
2233 file.write("GENERATED:=\n")
2234 for genfile in ['Makefile',
2237 'corebootDoc.config' ]:
2238 file.write("GENERATED += %s\n" % genfile)
2239 file.write("GENERATED += %s\n" % image.getincludefilename())
2241 keys = global_options_by_order
2243 file.write("\necho:\n")
2245 file.write("\t@echo %s='$(%s)'\n"% (key,key))
2247 for i, m in image.getmakerules().items():
2248 file.write("%s: " %i)
2249 for i in m.dependency:
2250 file.write("%s " % i)
2253 file.write("\t%s\n" % i)
2254 writemakefilefooter(file, makefilepath)
2258 def writemakefile(path):
2260 global bootblocksize
2261 makefilepath = os.path.join(path, "Makefile")
2262 print "Creating", makefilepath
2263 file = safe_open(makefilepath, 'w+')
2264 writemakefileheader(file, makefilepath)
2266 # Hack to get the necessary settings (CONFIG_CBFS):
2267 file.write("include %s/Makefile.settings\n\n" % romimages.keys()[0])
2270 file.write("ifeq \"$(CONFIG_CBFS)\" \"1\"\n")
2271 file.write("\nall: ")
2273 file.write(" %sfs" % i.name)
2276 file.write("\nall: ")
2278 file.write(" %s" % i.name)
2280 file.write("endif\n\n")
2283 file.write("\ncbfstool:\n\tmkdir -p tools/lzma\n\t$(MAKE) -C $(TOP)/util/cbfstool obj=$(shell pwd)\n\n")
2285 file.write("include Makefile.settings\n\n")
2286 for i, o in romimages.items():
2287 file.write("%s/coreboot.rom:\n" % o.getname())
2288 file.write("\tif (cd %s; \\\n" % o.getname())
2289 file.write("\t\t$(MAKE) coreboot.rom)\\\n")
2290 file.write("\tthen true; else exit 1; fi;\n\n")
2291 file.write("clean: ")
2292 for i in romimages.keys():
2293 file.write(" %s-clean" % i)
2294 file.write(" base-clean")
2296 for i, o in romimages.items():
2297 file.write("%s-clean:\n" % o.getname())
2298 file.write("\t(cd %s; $(MAKE) clean)\n\n" % o.getname())
2299 file.write("base-clean:\n")
2300 file.write("\trm -f romcc*\n\n")
2303 file.write("%s:" % i.name)
2305 file.write(" %s/coreboot.rom " % j)
2307 file.write("\t cat ")
2309 file.write(" %s/coreboot.rom " % j)
2310 file.write("> %s\n\n" %i.name)
2311 # build the bootblock here as well.
2313 file.write("\t cat ")
2315 file.write(" %s/coreboot.strip " % j)
2316 file.write("> %s.bootblock\n\n" %i.name)
2318 romsize = getoption("ROM_SIZE", image)
2319 # i.name? That can not be right, can it?
2320 file.write("%sfs: %s cbfstool\n" %(i.name,i.name));
2321 file.write("\trm -f coreboot.cbfs\n");
2322 file.write("\t./cbfstool %sfs create %s %s %s.bootblock\n" % (i.name, romsize, bootblocksize, i.name))
2324 file.write("\tif [ -f coreboot.romfs ]; then ./cbfstool coreboot.romfs add %s pci%04x,%04x.rom 48; fi\n" % (i.name, i.pci_vid, i.pci_did))
2327 #failover is a hack that will go away soon.
2328 if (j != "failover") and (rommapping[j] != "/dev/null"):
2329 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))
2330 file.write("\t ./cbfstool %sfs print\n" % i.name)
2332 file.write(".PHONY: all clean cbfstool")
2333 for i in romimages.keys():
2334 file.write(" %s-clean" % i)
2335 for i, o in romimages.items():
2336 file.write(" %s/coreboot.rom" % o.getname())
2339 writemakefilefooter(file, makefilepath)
2342 def writeinitincludes(image):
2343 global include_pattern
2344 filepath = os.path.join(image.gettargetdir(), image.getincludefilename())
2345 print "Creating", filepath
2346 outfile = safe_open(filepath, 'w+')
2347 if (image.newformat()):
2348 infile = safe_open(image.getinitfile(), 'r')
2350 line = infile.readline()
2352 p = include_pattern.match(line)
2354 for i in image.getinitincludes():
2355 inc = image.getinitinclude(i)
2356 if (inc.getstring() == p.group(1)):
2357 outfile.write("#include \"%s\"\n" % inc.getpath())
2360 line = infile.readline()
2364 for i in image.getinitincludes():
2365 outfile.write("#include <%s>\n" % i)
2368 def writeldoptions(image):
2369 """Write ldoptions file."""
2370 filename = os.path.join(image.gettargetdir(), "ldoptions")
2371 print "Creating", filename
2372 file = safe_open(filename, 'w+')
2373 for o in global_exported_options:
2374 if (hasvalue(o.name, image) and IsInt(getoption(o.name, image))):
2375 file.write("%s = %s;\n" % (o.name, getformated(o.name, image)))
2376 for o in image.exported_options:
2377 if (not o in global_exported_options and hasvalue(o.name, image) and IsInt(getoption(o.name, image))):
2378 file.write("%s = %s;\n" % (o.name, getformated(o.name, image)))
2381 def dumptree(part, lvl):
2382 debug.info(debug.dumptree, "DUMPTREE ME is")
2384 # dump the siblings -- actually are there any? not sure
2386 debug.info(debug.dumptree, "DUMPTREE SIBLINGS are")
2387 kid = part.next_sibling
2390 kid = kid.next_sibling
2392 debug.info(debug.dumptree, "DUMPTREE KIDS are")
2393 #for kid in part.children:
2395 dumptree(part.children, lvl+1)
2396 kid = part.next_sibling
2399 dumptree(kid.children, lvl + 1)
2400 kid = kid.next_sibling
2401 debug.info(debug.dumptree, "DONE DUMPTREE")
2403 def writecode(image):
2404 filename = os.path.join(img_dir, "static.c")
2405 print "Creating", filename
2406 file = safe_open(filename, 'w+')
2407 file.write("#include <device/device.h>\n")
2408 file.write("#include <device/pci.h>\n")
2409 for path in image.getconfigincludes().values():
2410 file.write("#include \"%s\"\n" % path)
2411 file.write("\n/* pass 0 */\n")
2412 gencode(image.getroot(), file, 0)
2413 file.write("\n/* pass 1 */\n")
2414 gencode(image.getroot(), file, 1)
2417 def gencode(part, file, pass_num):
2418 debug.info(debug.gencode, "GENCODE ME is")
2419 part.gencode(file, pass_num)
2420 # dump the siblings -- actually are there any? not sure
2421 debug.info(debug.gencode, "GENCODE SIBLINGS are")
2422 kid = part.next_sibling
2424 kid.gencode(file, pass_num)
2425 kid = kid.next_sibling
2426 # now dump the children
2427 debug.info(debug.gencode, "GENCODE KIDS are")
2429 gencode(part.children, file, pass_num)
2430 kid = part.next_sibling
2433 gencode(kid.children, file, pass_num)
2434 kid = kid.next_sibling
2435 debug.info(debug.gencode, "DONE GENCODE")
2437 def writegraph(image):
2438 filename = os.path.join(img_dir, "static.dot")
2439 print "Creating", filename
2440 file = safe_open(filename, 'w+')
2441 file.write("digraph devicetree {\n")
2442 file.write(" rankdir=LR\n")
2443 genranks(image.getroot(), file, 0)
2444 gennodes(image.getroot(), file)
2445 gengraph(image.getroot(), file)
2449 def genranks(part, file, level):
2450 #file.write(" # Level %d\n" % level )
2451 file.write(" { rank = same; \"dev_%s_%d\"" % (part.type_name,part.instance ))
2452 sib = part.next_sibling
2454 file.write("; \"dev_%s_%d\"" % (sib.type_name, sib.instance))
2455 sib = sib.next_sibling
2457 # now dump the children
2459 genranks(part.children, file, level + 1)
2461 kid = part.next_sibling
2464 genranks(kid.children, file, level + 1)
2465 kid = kid.next_sibling
2468 def gennodes(part, file):
2469 file.write(" dev_%s_%d[shape=record, label=\"%s\"];\n" % (part.type_name,part.instance,part.graph_name() ))
2470 sib = part.next_sibling
2472 file.write(" dev_%s_%d[shape=record, label=\"%s\"];\n" % (sib.type_name,sib.instance,sib.graph_name() ))
2473 sib = sib.next_sibling
2474 # now dump the children
2476 gennodes(part.children, file)
2478 kid = part.next_sibling
2481 gennodes(kid.children, file)
2482 kid = kid.next_sibling
2485 def gengraph(part, file):
2486 if (part.parent != part):
2487 file.write(" dev_%s_%d -> dev_%s_%d;\n" % \
2488 (part.parent.type_name, part.parent.instance, \
2489 part.type_name, part.instance ))
2490 sib = part.next_sibling
2492 file.write(" dev_%s_%d -> dev_%s_%d;\n" % \
2493 (sib.parent.type_name, sib.parent.instance, \
2494 sib.type_name, sib.instance ))
2495 sib = sib.next_sibling
2497 kid = part.next_sibling
2500 gengraph(kid.children, file)
2501 kid = kid.next_sibling
2504 gengraph(part.children, file)
2507 """Add any run-time checks to verify that parsing the configuration
2510 for image in romimages.values():
2511 print("Verifying ROMIMAGE %s" % image.name)
2512 if (image.newformat() and image.getinitfile() == ''):
2513 fatal("An init file must be specified")
2514 for op in image.exported_options:
2515 if (getoptionvalue(op.name, op, image) == 0 and getoptionvalue(op.name, op, 0) == 0):
2516 warning("Exported option %s has no value (check Options.lb)" % op.name);
2517 print("Verifing global options")
2518 for op in global_exported_options:
2519 if (getoptionvalue(op.name, op, 0) == 0):
2520 notice("Exported option %s has no value (check Options.lb)" % op.name);
2522 #=============================================================================
2524 #=============================================================================
2525 if __name__=='__main__':
2526 from sys import argv
2528 fatal("Args: <file> <path to coreboot>")
2530 top_config_file = os.path.abspath(sys.argv[1])
2532 treetop = os.path.abspath(sys.argv[2])
2534 # Now read in the customizing script...
2536 fp = safe_open(argv[1], 'r')
2537 if (not parse('board', fp.read())):
2538 fatal("Could not parse file")
2543 # no longer need to check if an options has been used
2546 for image_name, image in romimages.items():
2547 if (debug.level(debug.dumptree)):
2548 debug.info(debug.dumptree, "DEVICE TREE:")
2549 dumptree(image.getroot(), 0)
2551 img_dir = image.gettargetdir()
2552 if not os.path.isdir(img_dir):
2553 print "Creating directory %s" % img_dir
2554 os.makedirs(img_dir)
2556 for objrule, obj in image.getobjectrules().items():
2557 sub_dir = img_dir + '/' + os.path.dirname(obj[0])
2558 if not os.path.isdir(sub_dir):
2559 print "Creating sub directory %s" % sub_dir
2560 os.makedirs(sub_dir)
2562 for driverrule, driver in image.getdriverrules().items():
2563 sub_dir = img_dir + '/' + os.path.dirname(driver[0])
2564 if not os.path.isdir(sub_dir):
2565 print "Creating sub directory %s" % sub_dir
2566 os.makedirs(sub_dir)
2568 for srule, smm in image.getsmmobjectrules().items():
2569 sub_dir = img_dir + '/' + os.path.dirname(smm[0])
2570 if not os.path.isdir(sub_dir):
2571 print "Creating sub directory %s" % sub_dir
2572 os.makedirs(sub_dir)
2574 for irule, init in image.getinitobjectrules().items():
2575 sub_dir = img_dir + '/' + os.path.dirname(init[0])
2576 if not os.path.isdir(sub_dir):
2577 print "Creating sub directory %s" % sub_dir
2578 os.makedirs(sub_dir)
2580 if (debug.level(debug.dump)):
2581 for i in image.getinitincludes():
2582 debug.info(debug.dump, "crt0include file %s" % i)
2583 for i in image.getdriverrules().keys():
2584 debug.info(debug.dump, "driver file %s" % i)
2585 for i in image.getldscripts():
2586 debug.info(debug.dump, "ldscript file %s" % i)
2587 for i, m in image.getmakerules().items():
2588 debug.info(debug.dump, " makerule %s dep %s act %s" % (i, m.dependency, m.actions))
2591 writeimagesettings(image)
2592 writeinitincludes(image)
2593 writeimagemakefile(image)
2594 writeldoptions(image)
2597 writemakefilesettings(target_dir)
2598 writemakefile(target_dir)