16 global_options_by_order = []
17 global_option_values = {}
18 global_uses_options = {}
19 global_exported_options = []
23 alloptions = 0 # override uses at top level
25 local_path = re.compile(r'^\.')
26 include_pattern = re.compile(r'%%([^%]+)%%')
28 # the cpu type for this mainboard
31 # -----------------------------------------------------------------------------
33 # -----------------------------------------------------------------------------
36 """Used to keep track of the current part or dir"""
38 def __init__ (self, stack):
47 if (self.index < self.len):
48 s = self.stack[self.index]
49 self.index = self.index + 1
57 return len(self.stack)
59 def __getitem__ (self, i):
63 return self.__stack_iter(self.stack)
66 self.stack.append(part)
70 return self.stack.pop()
81 return (len(self.stack) == 0)
94 def __init__(self, *level):
97 def setdebug(self, *level):
100 def level(self, level):
101 return level in self.__level
103 def info(self, level, str):
104 if level in self.__level:
108 debug = debug_info(debug_info.none)
110 # -----------------------------------------------------------------------------
112 # -----------------------------------------------------------------------------
115 """Used to keep track of our current location while parsing
116 configuration files"""
118 def __init__(self, file, line, command):
121 self.command = command
122 def next_line(self, command):
123 self.line = self.line + 1
124 self.command = command
126 return "%s:%d" % (self.file, self.line)
137 s = s + '\n' + p.at()
141 return self.stack.tos().file
144 return self.stack.tos().line
147 return self.stack.tos().command
149 def push(self, file):
150 self.stack.push(self.__place(os.path.normpath(file), 0, ""))
155 def next_line(self, command):
156 self.stack.tos().next_line(command)
159 return self.stack.tos().at()
163 """Print error message"""
166 print "===> ERROR: %s" % string
170 """Print error message and exit"""
175 """Print warning message"""
177 warnings = warnings + 1
178 print "===> WARNING: %s" % string
181 """Print notice message"""
182 print "===> NOTE: %s" % string
185 """Exit parser if an error has been encountered"""
189 def safe_open(file, mode):
191 return open(file, mode)
193 fatal("Could not open file \"%s\"" % file)
195 # -----------------------------------------------------------------------------
197 # -----------------------------------------------------------------------------
200 """A rom image is the ultimate goal of linuxbios"""
201 def __init__ (self, name):
202 # name of this rom image
205 # set by 'arch' directive
208 # set by 'payload' directive
211 # set by 'init' directive
214 # make rules added by 'makerule' directive
215 self.makebaserules = {}
217 # object files added by 'object' directive
218 self.objectrules = {}
220 # init object files added by 'initobject' directive
221 self.initobjectrules = {}
223 # driver files added by 'drive' directive
224 self.driverrules = {}
226 # loader scripts added by 'ldscript' directive
229 # user defines added by 'makedefine' directive
230 self.userdefines = []
232 # files to be included in crt0.S
233 self.initincludes = {}
235 # as above, but order is preserved
236 self.initincludesorder = []
238 # transitional flag to support old crtinclude format
239 self.useinitincludes = 0
241 # instance counter for parts
242 self.partinstance = 0
244 # chip config files included by the 'config' directive
245 self.configincludes = {}
250 # name of target directory specified by 'target' directive
253 # option values used in rom image
257 self.exported_options = []
265 def setarch(self, arch):
268 def setpayload(self, payload):
269 self.payload = payload
271 def setinitfile(self, initfile):
272 self.initfile = initfile
274 def getinitfile(self):
277 def addmakerule(self, id):
278 o = getdict(self.makebaserules, id)
280 warning("rule %s previously defined" % id)
282 setdict(self.makebaserules, id, o)
284 def getmakerules(self):
285 return self.makebaserules
287 def getmakerule(self, id):
288 o = getdict(self.makebaserules, id)
291 fatal("No such make rule \"%s\"" % id);
293 def addmakeaction(self, id, str):
294 o = getdict(self.makebaserules, id)
299 fatal("No such rule \"%s\" for addmakeaction" % id);
301 def addmakedepend(self, id, str):
302 o = getdict(self.makebaserules, id)
307 fatal("No such rule \"%s\" for addmakedepend" % id);
309 # this is called with an an object name.
310 # the easiest thing to do is add this object to the current
312 # such kludgery. If the name starts with '.' then make the
313 # dependency be on ./thing.x gag me.
314 def addobjectdriver(self, dict, object_name):
316 suffix = object_name[-2:]
319 base = object_name[:-2]
320 type = object_name[-1:]
321 if (object_name[0] == '.'):
322 source = base + suffix
324 source = os.path.join(dirstack.tos(), base + suffix)
326 debug.info(debug.object, "add object %s source %s" % (object_name, source))
327 l = getdict(dict, base)
329 warning("object/driver %s previously defined" % base)
330 setdict(dict, base, [object, source, type, base])
332 def addinitobjectrule(self, name):
333 self.addobjectdriver(self.initobjectrules, name)
335 def addobjectrule(self, name):
336 self.addobjectdriver(self.objectrules, name)
338 def adddriverrule(self, name):
339 self.addobjectdriver(self.driverrules, name)
341 def getinitobjectrules(self):
342 return self.initobjectrules
344 def getinitobjectrule(self, name):
345 o = getdict(self.initobjectrules, name)
348 fatal("No such init object rule \"%s\"" % name);
350 def getobjectrules(self):
351 return self.objectrules
353 def getobjectrule(self, name):
354 o = getdict(self.objectrules, name)
357 fatal("No such object rule \"%s\"" % name);
359 def getdriverrules(self):
360 return self.driverrules
362 def getdriverrule(self, name):
363 o = getdict(self.driverrules, name)
366 fatal("No such driver rule \"%s\"" % name);
368 def addldscript(self, path):
369 self.ldscripts.append(path)
371 def getldscripts(self):
372 return self.ldscripts
374 def adduserdefine(self, str):
375 self.userdefines.append(str)
377 def getuserdefines(self):
378 return self.userdefines
380 def addinitinclude(self, str, path):
382 self.useinitincludes = 1
384 debug.info(debug.object, "ADDCRT0: %s -> %s" % (str, path))
385 o = getdict(self.initincludes, path)
387 warning("init include for %s previously defined" % path)
388 o = initinclude(str, path)
389 setdict(self.initincludes, path, o)
390 self.initincludesorder.append(path)
392 def getinitincludes(self):
393 return self.initincludesorder
395 def getinitinclude(self, path):
396 o = getdict(self.initincludes, path)
399 fatal("No such init include \"%s\"" % path);
401 def addconfiginclude(self, part, path):
402 setdict(self.configincludes, part, path)
404 def getconfigincludes(self):
405 return self.configincludes
407 def getincludefilename(self):
408 if (self.useinitincludes):
411 return "crt0_includes.h"
414 return self.useinitincludes
417 return self.partinstance
419 def newpartinstance(self):
420 i = self.partinstance
421 self.partinstance = self.partinstance + 1
424 def setroot(self, part):
430 def settargetdir(self, path):
431 self.targetdir = path
433 def gettargetdir(self):
434 return self.targetdir
437 """A buildrom statement"""
438 def __init__ (self, filename, size, roms):
444 return len(self.roms)
446 def __getitem__(self,i):
450 """include file for initialization code"""
451 def __init__ (self, str, path):
462 """Rule to be included in Makefile"""
463 def __init__ (self, target):
468 def addaction(self, action):
469 self.actions.append(action)
471 def adddependency(self, dependency):
472 self.dependency.append(dependency)
477 def gdependency(self):
478 return self.dependency
484 """Configuration option"""
485 def __init__ (self, name):
486 self.name = name # name of option
487 self.loc = 0 # current location
488 self.used = 0 # option has been used
490 self.comment = '' # description of option
491 self.exportable = 0 # option is able to be exported
492 self.format = '%s' # option print format
493 self.write = [] # parts that can set this option
498 def setcomment(self, comment, loc):
499 if (self.comment != ''):
500 print "%s: " % self.name
501 print "Attempt to modify comment at %s" % loc
503 self.comment = comment
505 def setexportable(self):
508 def setnoexport(self):
511 def setformat(self, fmt):
518 if (self.exportable):
522 def setwrite(self, part):
523 self.write.append(part)
525 def isexportable(self):
526 return self.exportable
528 def iswritable(self, part):
529 return (part in self.write)
532 """Value of a configuration option. The option has a default
533 value which can be changed at any time. Once an option has been
534 set the default value is no longer used."""
535 def __init__(self, name, prev):
540 self.value = prev.value
544 def setvalue(self, value):
545 if ((self.set & 2) == 2):
546 warning("Changing option %s" % self.name)
551 def setdefault(self, value):
552 if ((self.set & 1) == 1):
553 notice("Changing default value of %s" % self.name)
555 if ((self.set & 2) == 0):
563 return (self.set & 2) == 2
567 """A configuration part"""
568 def __init__ (self, image, dir, parent, part, type_name, instance_name, link):
569 debug.info(debug.object, "partobj dir %s parent %s part %s" \
570 % (dir, parent, part))
572 # romimage that is configuring this part
575 # links for static device tree
579 # list of init code files
582 # initializers for static device tree
583 self.registercode = {}
588 # type name of this part
589 self.type_name = type_name
591 # object files needed to build this part
594 # directory containg part files
597 # instance number, used to distinguish anonymous
598 # instances of this part
599 self.instance = image.newpartinstance()
600 debug.info(debug.object, "INSTANCE %d" % self.instance)
602 # Options used by this part
603 self.uses_options = {}
605 # Name of chip config file (0 if not needed)
608 # Flag to indicate that we have generated type
609 # definitions for this part (only want to do it once)
615 # Link from parent device
616 if ((link < 0) or (link > 16)):
617 fatal("Invalid link")
620 # If no instance name is supplied then generate
622 if (instance_name == 0):
623 self.instance_name = self.type_name + \
624 "_dev%d" % self.instance
625 self.config_name = "%s_config_%d" \
626 % (self.type_name, self.instance)
628 self.instance_name = instance_name
629 self.config_name = "%s_config" % self.instance_name
631 # Link this part into the tree
633 debug.info(debug.gencode, "add to parent")
635 # add current child as my sibling,
637 if (parent.children):
638 debug.info(debug.gencode, "add %s (%d) as sibling" % (parent.children.dir, parent.children.instance))
639 youngest = parent.children;
640 while(youngest.siblings):
641 youngest = youngest.siblings
642 youngest.siblings = self
644 parent.children = self
648 def dumpme(self, lvl):
649 """Dump information about this part for debugging"""
650 print "%d: part %s" % (lvl, self.part)
651 print "%d: instance %d" % (lvl, self.instance)
652 print "%d: dir %s" % (lvl,self.dir)
653 print "%d: name %s" % (lvl,self.name)
654 print "%d: parent %s" % (lvl,self.parent.part)
655 print "%d: parent dir %s" % (lvl,self.parent.dir)
657 print "%d: child %s" % (lvl, self.children.dir)
659 print "%d: siblings %s" % (lvl, self.siblings.dir)
660 print "%d: initcode " % lvl
661 for i in self.initcode:
663 print "%d: registercode " % lvl
664 for f, v in self.registercode.items():
665 print "\t%s = %s" % (f, v)
668 def gencode(self, file, pass_num):
669 """Generate static initalizer code for this part. Two passes
670 are used - the first generates type information, and the second
671 generates instance information"""
674 file.write("struct chip %s;\n" \
675 % self.instance_name)
677 file.write("struct chip static_root;\n")
679 if (self.chipconfig):
680 debug.info(debug.gencode, "gencode: chipconfig(%d)" % \
682 file.write("struct %s_config %s" % (self.type_name ,\
684 if (self.registercode):
685 file.write("\t= {\n")
686 for f, v in self.registercode.items():
687 file.write( "\t.%s = %s,\n" % (f, v))
693 file.write("struct chip %s = {\n" % self.instance_name)
695 file.write("struct chip static_root = {\n")
696 file.write("\t/* %s %s */\n" % (self.part, self.dir))
697 file.write("\t.link = %d,\n" % (self.link))
698 if (self.path != ""):
699 file.write("\t.path = { %s\n\t},\n" % (self.path) );
701 debug.info(debug.gencode, "gencode: siblings(%d)" \
702 % self.siblings.instance)
703 file.write("\t.next = &%s,\n" \
704 % self.siblings.instance_name)
706 file.write("\t.next = 0,\n")
708 debug.info(debug.gencode, "gencode: children(%d)" \
709 % self.children.instance)
710 file.write("\t.children = &%s,\n" \
711 % self.children.instance_name)
713 file.write("\t.children = 0,\n")
714 if (self.chipconfig):
715 # set the pointer to the structure for all this
717 file.write("\t.control= &%s_control,\n" % \
719 # generate the pointer to the isntance
721 file.write("\t.chip_info = (void *) &%s,\n" \
724 file.write("\t.control= 0,\n")
725 file.write("\t.chip_info= 0,\n")
728 def addinit(self, code):
729 """Add init file to this part"""
730 self.initcode.append(code)
732 def addconfig(self, path):
733 """Add chip config file to this part"""
734 self.chipconfig = os.path.join(self.dir, path)
735 self.image.addconfiginclude(self.type_name, self.chipconfig)
737 def addregister(self, field, value):
738 """Register static initialization information"""
739 field = dequote(field)
740 value = dequote(value)
741 setdict(self.registercode, field, value)
743 def addpcipath(self, enable, bus, slot, function):
744 """ Add a relative pci style path from our parent to this device """
745 if ((bus < 0) or (bus > 255)):
747 if ((slot < 0) or (slot > 0x1f)):
748 fatal("Invalid device id")
749 if ((function < 0) or (function > 7)):
750 fatal("Invalid function")
751 self.path = "%s\n\t\t{ .enable = %d, .path = {.type=DEVICE_PATH_PCI,.u={.pci={ .bus = 0x%x, .devfn = PCI_DEVFN(0x%x,%d) }}}}," % (self.path, enable, bus, slot, function)
753 def addpnppath(self, enable, port, device):
754 """ Add a relative path to a pnp device hanging off our parent """
755 if ((port < 0) or (port > 65536)):
756 fatal("Invalid port")
757 if ((device < 0) or (device > 0xff)):
758 fatal("Invalid device")
759 self.path = "%s\n\t\t{ .enable = %d, .path={.type=DEVICE_PATH_PNP,.u={.pnp={ .port = 0x%x, .device = 0x%x }}}}," % (self.path, enable, port, device)
761 def addi2cpath(self, enable, device):
762 """ Add a relative path to a i2c device hanging off our parent """
763 if ((device < 0) or (device > 0x7f)):
764 fatal("Invalid device")
765 self.path = "%s\n\t\t{ .enable = %d, .path = {.type=DEVICE_PATH_I2C,.u={.i2c={ .device = 0x%x }}}}, " % (self.path, enable, device)
767 def usesoption(self, name):
768 """Declare option that can be used by this part"""
769 global global_options
770 o = getdict(global_options, name)
772 fatal("can't use undefined option %s" % name)
773 o1 = getdict(self.uses_options, name)
776 setdict(self.uses_options, name, o)
777 exportoption(o, self.image.exported_options)
779 # -----------------------------------------------------------------------------
781 # -----------------------------------------------------------------------------
783 def getdict(dict, name):
784 if name not in dict.keys():
785 debug.info(debug.dict, "Undefined: %s" % name)
787 v = dict.get(name, 0)
788 debug.info(debug.dict, "getdict %s returning %s" % (name, v))
791 def setdict(dict, name, value):
792 debug.info(debug.dict, "setdict sets %s to %s" % (name, value))
796 # to create an option, it has to not exist.
797 # When an option value is fetched, the fact that it was used is
799 # Legal things to do:
800 # set a default value, then set a real value before the option is used.
801 # set a value, try to set a default, default silently fails.
803 # use the value, then try to set the value
806 global global_options, global_options_by_order
807 o = getdict(global_options, name)
809 fatal("option %s already defined" % name)
811 setdict(global_options, name, o)
812 global_options_by_order.append(name)
814 def newoptionvalue(name, image):
815 g = getdict(global_option_values, name)
816 v = option_value(name, g)
818 setdict(image.getvalues(), name, v)
820 setdict(global_option_values, name, v)
823 def getoptionvalue(name, op, image):
824 global global_option_values
826 fatal("Option %s undefined (missing use command?)" % name)
828 v = getdict(image.getvalues(), name)
830 v = getdict(global_option_values, name)
833 def getoption(name, image):
834 """option must be declared before being used in a part
835 if we're not processing a part, then we must
836 be at the top level where all options are available"""
838 global global_uses_options, alloptions, curimage
840 curpart = partstack.tos()
842 o = getdict(global_options, name)
844 o = getdict(curpart.uses_options, name)
846 o = getdict(global_uses_options, name)
847 v = getoptionvalue(name, o, image)
849 v = getoptionvalue(name, o, 0)
851 fatal("No value for option %s" % name)
853 if (not (type(val) is types.StringType)):
855 if (val == '' or val[0] != '{'):
859 val = parse('delexpr', val)
864 def setoption(name, value, imp):
865 """Set an option from within a configuration file. Normally this
866 is only permitted in the target (top level) configuration file.
867 If 'imp' is true, then set an option implicitly (e.g. 'arch'
868 and 'mainboard' statements). Implicit options can be set anywhere
869 the statements are legal, but also performs an implicit 'uses'
872 global loc, global_options, global_option_values, curimage
874 curpart = partstack.tos()
875 if (not imp and curpart):
876 fatal("Options may only be set in target configuration file")
880 o = getdict(curpart.uses_options, name)
882 o = getdict(global_uses_options, name)
884 fatal("Attempt to set nonexistent option %s (missing USES?)" % name)
885 v = getoptionvalue(name, o, curimage)
887 v = newoptionvalue(name, curimage)
890 def exportoption(op, exported_options):
891 if (not op.isexportable()):
893 if (not op in exported_options):
894 exported_options.append(op)
896 def setdefault(name, value, isdef):
897 """Set the default value of an option from within a configuration
898 file. This is permitted from any configuration file, but will
899 result in a warning if the default is set more than once.
900 If 'isdef' is set, we're defining the option in Options.lb so
901 there is no need for 'uses'."""
903 global loc, global_options, curimage
906 o = getdict(global_options, name)
911 curpart = partstack.tos()
913 o = getdict(curpart.uses_options, name)
915 o = getdict(global_uses_options, name)
917 fatal("Attempt to set default for nonexistent option %s (missing USES?)" % name)
920 v = getoptionvalue(name, o, image)
922 v = newoptionvalue(name, image)
925 def setnodefault(name):
926 global loc, global_options
927 o = getdict(global_options, name)
930 v = getdict(global_option_values, name)
932 warning("removing default for %s" % name)
933 del global_option_values[name]
935 def setcomment(name, value):
936 global loc, global_options
937 o = getdict(global_options, name)
939 fatal("setcomment: %s not here" % name)
940 o.setcomment(value, loc)
942 def setexported(name):
943 global global_options
944 o = getdict(global_options, name)
946 fatal("setexported: %s not here" % name)
948 global_exported_options.append(o)
950 def setnoexport(name):
951 global global_options
952 o = getdict(global_options, name)
954 fatal("setnoexport: %s not here" % name)
956 if (o in global_exported_options):
957 global_exported_options.remove(o)
959 def setexportable(name):
960 global global_options
961 o = getdict(global_options, name)
963 fatal("setexportable: %s not here" % name)
966 def setformat(name, fmt):
967 global global_options
968 o = getdict(global_options, name)
970 fatal("setformat: %s not here" % name)
973 def getformated(name, image):
974 global global_options, global_option_values
975 o = getdict(global_options, name)
976 v = getoption(name, image)
980 def setwrite(name, part):
981 global global_options
982 o = getdict(global_options, name)
984 fatal("setwrite: %s not here" % name)
987 def hasvalue(name, image):
988 global global_options
989 o = getdict(global_options, name)
994 v = getdict(image.getvalues(), name)
996 v = getdict(global_option_values, name)
999 def isset(name, part):
1000 global global_uses_options, global_option_values, curimage
1002 o = getdict(part.uses_options, name)
1004 o = getdict(global_uses_options, name)
1009 v = getdict(curimage.getvalues(), name)
1011 v = getdict(global_option_values, name)
1012 return (v != 0 and v.isset())
1014 def usesoption(name):
1015 global global_options, global_uses_options
1016 curpart = partstack.tos()
1018 curpart.usesoption(name)
1020 o = getdict(global_options, name)
1022 fatal("Can't use undefined option %s" % name)
1023 o1 = getdict(global_uses_options, name)
1026 setdict(global_uses_options, name, o)
1027 exportoption(o, global_exported_options)
1029 def validdef(name, defval):
1030 global global_options
1031 o = getdict(global_options, name)
1033 fatal("validdef: %s not here" % name)
1034 if ((defval & 1) != 1):
1035 fatal("Must specify default value for option %s" % name)
1036 if ((defval & 2) != 2):
1037 fatal("Must specify export for option %s" % name)
1038 if ((defval & 4) != 4):
1039 fatal("Must specify comment for option %s" % name)
1042 file = os.path.join('src', 'config', 'Options.lb')
1043 optionsfile = os.path.join(treetop, file)
1044 fp = safe_open(optionsfile, 'r')
1046 if (not parse('options', fp.read())):
1047 fatal("Could not parse file")
1051 global curimage, dirstack
1052 if (path[0] == '/'):
1053 curimage.setinitfile(treetop + '/src/' + path)
1055 curimage.setinitfile(dirstack.tos() + '/' + path)
1056 print "Adding init file: %s" % path
1058 def addconfig(path):
1060 curpart = partstack.tos()
1061 curpart.addconfig(path)
1063 def addregister(field, value):
1065 curpart = partstack.tos()
1066 curpart.addregister(field, value)
1068 def addcrt0include(path):
1069 """we do the crt0include as a dictionary, so that if needed we
1070 can trace who added what when. Also it makes the keys
1073 curimage.addinitinclude(0, path)
1075 def addinitinclude(str, path):
1077 curimage.addinitinclude(dequote(str), path)
1079 def addldscript(path):
1080 global curimage, dirstack
1081 curdir = dirstack.tos()
1082 if (path[0] == '/'):
1083 fullpath = treetop + '/src/' + path
1085 fullpath = curdir + '/' + path
1086 debug.info(debug.statement, "fullpath :%s: curdir :%s: path :%s:" % (fullpath, curdir, path))
1087 curimage.addldscript(fullpath)
1091 curimage.setpayload(path)
1092 adduserdefine("PAYLOAD:=%s"%path)
1094 def startromimage(name):
1095 global romimages, curimage, target_dir, target_name
1096 print "Configuring ROMIMAGE %s" % name
1097 o = getdict(romimages, name)
1099 fatal("romimage %s previously defined" % name)
1100 curimage = romimage(name)
1101 curimage.settargetdir(os.path.join(target_dir, name))
1102 #o = partobj(curimage, target_dir, 0, 'board', target_name)
1103 #curimage.setroot(o)
1104 setdict(romimages, name, curimage)
1108 print "End ROMIMAGE"
1112 def mainboard(path):
1113 full_path = os.path.join(treetop, 'src', 'mainboard', path)
1114 vendor = re.sub("/.*", "", path)
1115 part_number = re.sub("[^/]*/", "", path)
1116 setdefault('MAINBOARD', full_path, 0)
1117 setdefault('MAINBOARD_VENDOR', vendor, 0)
1118 setdefault('MAINBOARD_PART_NUMBER', part_number, 0)
1119 dodir('/config', 'Config.lb')
1120 part('mainboard', path, 'Config.lb', 0, 0)
1121 curimage.setroot(partstack.tos())
1124 def addbuildrom(filename, size, roms):
1126 print "Build ROM size %d" % size
1127 b = buildrom(filename, size, roms)
1130 def addinitobject(object_name):
1132 curimage.addinitobjectrule(object_name)
1134 def addobject(object_name):
1136 curimage.addobjectrule(object_name)
1138 def adddriver(driver_name):
1140 curimage.adddriverrule(driver_name)
1143 global target_dir, target_name
1144 print "Configuring TARGET %s" % name
1146 target_dir = os.path.join(os.path.dirname(loc.file()), name)
1147 if not os.path.isdir(target_dir):
1148 print "Creating directory %s" % target_dir
1149 os.makedirs(target_dir)
1150 print "Will place Makefile, crt0.S, etc. in %s" % target_dir
1155 if (cpu_type and (cpu_type != path)):
1156 fatal("Two different CPU types: %s and %s" % (cpu_type, path))
1157 srcdir = "/cpu/%s" % path
1158 dodir(srcdir, "Config.lb")
1161 def part(type, path, file, name, link):
1162 global curimage, dirstack, partstack
1163 partdir = os.path.join(type, path)
1164 srcdir = os.path.join(treetop, 'src')
1165 fulldir = os.path.join(srcdir, partdir)
1166 type_name = flatten_name(os.path.join(type, path))
1167 newpart = partobj(curimage, fulldir, partstack.tos(), type, \
1168 type_name, name, link)
1169 print "Configuring PART %s, path %s" % (type, path)
1170 partstack.push(newpart)
1171 dirstack.push(fulldir)
1172 # special case for 'cpu' parts.
1173 # we could add a new function too, but this is rather trivial.
1174 # if the part is a cpu, and we haven't seen it before,
1175 # arrange to source the directory /cpu/'type'
1179 doconfigfile(srcdir, partdir, file, 'cfgfile')
1182 global dirstack, partstack
1183 curpart = partstack.tos()
1185 fatal("Trying to pop non-existent part")
1186 print "End PART %s" % curpart.part
1187 # Warn if options are used without being set in this part
1188 for op in curpart.uses_options.keys():
1189 if (not isset(op, curpart)):
1190 notice("Option %s using default value %s" % (op, getformated(op, curpart.image)))
1194 def dodir(path, file):
1195 """dodir is like part but there is no new part"""
1197 # if the first char is '/', it is relative to treetop,
1198 # else relative to curdir
1199 # os.path.join screws up if the name starts with '/', sigh.
1200 print "Configuring DIR %s" % os.path.join(path, file)
1201 if (path[0] == '/'):
1202 fullpath = os.path.join(treetop, 'src')
1203 path = re.sub('^/*', '', path)
1205 fullpath = dirstack.tos()
1206 debug.info(debug.statement, "DODIR: path %s, fullpath %s" % (path, fullpath))
1207 dirstack.push(os.path.join(fullpath, path))
1208 doconfigfile(fullpath, path, file, 'cfgfile')
1213 return getoption(name, curimage)
1217 curimage.addmakerule(id)
1219 def adduserdefine(str):
1221 curimage.adduserdefine(str)
1223 def addaction(id, str):
1225 curimage.addmakeaction(id, str)
1227 def adddep(id, str):
1229 curimage.addmakedepend(id, str)
1231 def setarch(my_arch):
1232 """arch is 'different' ... darn it."""
1234 curimage.setarch(my_arch)
1235 setdefault('ARCH', my_arch, 1)
1236 part('arch', my_arch, 'Config.lb', 0, 0)
1238 def doconfigfile(path, confdir, file, rule):
1239 rname = os.path.join(confdir, file)
1241 fullpath = os.path.join(path, rname)
1242 fp = safe_open(fullpath, 'r')
1243 if (not parse(rule, fp.read())):
1244 fatal("Could not parse file")
1248 #=============================================================================
1250 #=============================================================================
1251 def ternary(val, yes, no):
1252 debug.info(debug.statement, "ternary %s" % expr)
1253 debug.info(debug.statement, "expr %s a %d yes %d no %d"% (expr, a, yes, no))
1255 debug.info(debug.statement, "Ternary returns %d" % yes)
1258 debug.info(debug.statement, "Ternary returns %d" % no)
1262 """atoi is in the python library, but not strtol? Weird!"""
1263 return eval('int(%s)' % name)
1266 """ Is the given string an integer?"""
1274 a = re.sub("^\"", "", str)
1275 a = re.sub("\"$", "", a)
1276 # highly un-intuitive, need four \!
1277 a = re.sub("\\\\\"", "\"", a)
1280 def flatten_name(str):
1281 a = re.sub("/", "_", str)
1285 """If the first part of <path> matches treetop, replace
1286 that part with $(TOP)"""
1287 if path[0:len(treetop)] == treetop:
1288 path = path[len(treetop):len(path)]
1289 if (path[0:1] == "/"):
1290 path = path[1:len(path)]
1291 path = "$(TOP)/" + path
1295 # to make if work without 2 passses, we use an old hack from SIMD, the
1296 # context bit. If the bit is 1, then ops get done, otherwise
1297 # ops don't get done. From the top level, context is always
1298 # 1. In an if, context depends on eval of the if condition
1304 # less general tokens should come first, otherwise they get matched
1306 token ACTION: 'action'
1307 token ADDACTION: 'addaction'
1308 token ALWAYS: 'always'
1310 token BUILDROM: 'buildrom'
1311 token COMMENT: 'comment'
1312 token CONFIG: 'config'
1314 token DEFAULT: 'default'
1315 token DEFINE: 'define'
1316 token DEPENDS: 'depends'
1318 token DRIVER: 'driver'
1323 token EXPORT: 'export'
1324 token FORMAT: 'format'
1327 token INITOBJECT: 'initobject'
1328 token INITINCLUDE: 'initinclude'
1329 token LDSCRIPT: 'ldscript'
1330 token LOADOPTIONS: 'loadoptions'
1331 token MAINBOARD: 'mainboard'
1332 token MAINBOARDINIT: 'mainboardinit'
1333 token MAKEDEFINE: 'makedefine'
1334 token MAKERULE: 'makerule'
1335 token NEVER: 'never'
1337 token NORTHBRIDGE: 'northbridge'
1338 token OBJECT: 'object'
1339 token OPTION: 'option'
1340 token PAYLOAD: 'payload'
1342 token PRINT: 'print'
1343 token REGISTER: 'register'
1344 token ROMIMAGE: 'romimage'
1345 token SOUTHBRIDGE: 'southbridge'
1346 token SUPERIO: 'superio'
1347 token TARGET: 'target'
1350 token WRITE: 'write'
1352 token HEX_NUM: '[0-9a-fA-F]+'
1353 token HEX_PREFIX: '0x'
1354 # Why is path separate? Because paths to resources have to at least
1355 # have a slash, we thinks
1356 token PATH: r'[a-zA-Z0-9_.][a-zA-Z0-9/_.]+[a-zA-Z0-9_.]+'
1357 # Dir's on the other hand are abitrary
1358 # this may all be stupid.
1359 token DIRPATH: r'[-a-zA-Z0-9_$()./]+'
1360 token ID: r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
1361 token DELEXPR: r'{([^}]+|\\.)*}'
1362 token STR: r'"([^\\"]+|\\.)*"'
1363 token RAWTEXT: r'.*'
1372 rule expr: logical {{ l = logical }}
1373 ( "&&" logical {{ l = l and logical }}
1374 | "||" logical {{ l = l or logical }}
1377 rule logical: factor {{ n = factor }}
1378 ( "[+]" factor {{ n = n+factor }}
1379 | "-" factor {{ n = n-factor }}
1382 rule factor: term {{ v = term }}
1383 ( "[*]" term {{ v = v*term }}
1384 | "/" term {{ v = v/term }}
1385 | "<<" term {{ v = v << term }}
1386 | ">=" term {{ v = (v < term)}}
1389 # A term is a number, variable, or an expression surrounded by parentheses
1390 rule term: NUM {{ return long(NUM, 10) }}
1391 | HEX_PREFIX HEX_NUM {{ return long(HEX_NUM, 16) }}
1392 | ID {{ return lookup(ID) }}
1393 | unop {{ return unop }}
1394 | "\\(" expr "\\)" {{ return expr }}
1396 rule unop: "!" expr {{ return not(expr) }}
1398 rule partend<<C>>: (stmt<<C>>)* END {{ if (C): partpop()}}
1400 # This is needed because the legacy cpu command could not distinguish
1401 # between cpu vendors. It should just be PATH, but getting this change
1402 # into the source tree will be tricky...
1403 # DO NOT USE ID AS IT MAY GO AWAY IN THE FUTURE
1404 rule partid: ID {{ return ID }}
1405 | PATH {{ return PATH }}
1407 rule parttype: NORTHBRIDGE {{ return 'northbridge' }}
1408 | SUPERIO {{ return 'superio' }}
1409 | PMC {{ return 'pmc' }}
1410 | SOUTHBRIDGE {{ return 'southbridge' }}
1411 | CPU {{ return 'cpu' }}
1413 rule partdef<<C>>: {{ name = 0 }} {{ link = 0 }}
1415 [ STR {{ name = dequote(STR) }}
1416 ][ LINK NUM {{ link = long(NUM, 10) }}
1417 ] {{ if (C): part(parttype, partid, 'Config.lb', name, link) }}
1420 rule arch<<C>>: ARCH ID {{ if (C): setarch(ID) }}
1423 rule mainboardinit<<C>>:
1424 MAINBOARDINIT DIRPATH {{ if (C): addcrt0include(DIRPATH)}}
1426 rule initinclude<<C>>:
1429 DIRPATH {{ if (C): addinitinclude(STR, DIRPATH)}}
1431 rule initobject<<C>>:
1432 INITOBJECT DIRPATH {{ if (C): addinitobject(DIRPATH)}}
1434 rule object<<C>>: OBJECT DIRPATH {{ if (C): addobject(DIRPATH)}}
1436 rule driver<<C>>: DRIVER DIRPATH {{ if (C): adddriver(DIRPATH)}}
1438 rule dir<<C>>: DIR DIRPATH {{ if (C): dodir(DIRPATH, 'Config.lb') }}
1440 rule default<<C>>: DEFAULT ID EQ value {{ if (C): setdefault(ID, value, 0) }}
1442 rule ldscript<<C>>: LDSCRIPT DIRPATH {{ if (C): addldscript(DIRPATH) }}
1444 rule iif<<C>>: IF ID {{ c = lookup(ID) }}
1446 [ ELSE (stmt<<C and not c>>)* ]
1449 rule depsacts<<ID, C>>:
1450 ( DEPENDS STR {{ if (C): adddep(ID, STR) }}
1451 | ACTION STR {{ if (C): addaction(ID, STR) }}
1454 rule makerule<<C>>: MAKERULE DIRPATH {{ if (C): addrule(DIRPATH) }}
1455 depsacts<<DIRPATH, C>>
1458 rule makedefine<<C>>:
1459 MAKEDEFINE RAWTEXT {{ if (C): adduserdefine(RAWTEXT) }}
1461 rule addaction<<C>>:
1462 ADDACTION ID STR {{ if (C): addaction(ID, STR) }}
1464 rule init<<C>>: INIT DIRPATH {{ if (C): addinit(DIRPATH) }}
1466 rule field: STR {{ return STR }}
1468 rule register<<C>>: REGISTER field '=' STR {{ if (C): addregister(field, STR) }}
1470 rule enable: {{ val = 1 }}
1471 [ ( ON {{ val = 1 }}
1473 ) ] {{ return val }}
1475 rule pci<<C>>: PCI HEX_NUM {{ bus = int(HEX_NUM,16) }}
1476 ':' HEX_NUM {{ slot = int(HEX_NUM,16) }}
1477 '.' HEX_NUM {{ function = int(HEX_NUM, 16) }}
1479 {{ if (C): partstack.tos().addpcipath(enable, bus, slot, function) }}
1481 rule pnp<<C>>: PNP HEX_NUM {{ port = int(HEX_NUM,16) }}
1482 '.' HEX_NUM {{ device = int(HEX_NUM, 16) }}
1484 {{ if (C): partstack.tos().addpnppath(enable, port, device) }}
1486 rule i2c<<C>>: I2C HEX_NUM {{ device = int(HEX_NUM, 16) }}
1488 {{ if (C): partstatck.tos().addi2cpath(enable, device) }}
1490 rule prtval: expr {{ return str(expr) }}
1491 | STR {{ return STR }}
1493 rule prtlist: prtval {{ el = "%(" + prtval }}
1494 ( "," prtval {{ el = el + "," + prtval }}
1495 )* {{ return el + ")" }}
1497 rule prtstmt<<C>>: PRINT STR {{ val = STR }}
1498 [ "," prtlist {{ val = val + prtlist }}
1499 ] {{ if (C): print eval(val) }}
1501 rule config<<C>>: CONFIG PATH {{ if (C): addconfig(PATH) }}
1503 rule stmt<<C>>: arch<<C>> {{ return arch}}
1504 | addaction<<C>> {{ return addaction }}
1505 | config<<C>> {{ return config}}
1506 | default<<C>> {{ return default}}
1507 | dir<<C>> {{ return dir}}
1508 | driver<<C>> {{ return driver }}
1509 | iif<<C>> {{ return iif }}
1510 | init<<C>> {{ return init }}
1511 | initinclude<<C>> {{ return initinclude }}
1512 | initobject<<C>> {{ return initobject }}
1513 | ldscript<<C>> {{ return ldscript}}
1514 | mainboardinit<<C>> {{ return mainboardinit }}
1515 | makedefine<<C>> {{ return makedefine }}
1516 | makerule<<C>> {{ return makerule }}
1517 | object<<C>> {{ return object }}
1518 | option<<C>> {{ return option }}
1519 | partdef<<C>> {{ return partdef }}
1520 | prtstmt<<C>> {{ return prtstmt }}
1521 | register<<C>> {{ return register }}
1522 | pci<<C>> {{ return pci }}
1523 | pnp<<C>> {{ return pnp }}
1525 # ENTRY for parsing Config.lb file
1526 rule cfgfile: (uses<<1>>)*
1530 rule usesid<<C>>: ID {{ if (C): usesoption(ID) }}
1532 rule uses<<C>>: USES (usesid<<C>>)+
1534 rule value: STR {{ return dequote(STR) }}
1535 | expr {{ return expr }}
1536 | DELEXPR {{ return DELEXPR }}
1538 rule option<<C>>: OPTION ID EQ value {{ if (C): setoption(ID, value, 0) }}
1540 rule opif<<C>>: IF ID {{ c = lookup(ID) }}
1541 (opstmt<<C and c>>)*
1542 [ ELSE (opstmt<<C and not c>>)* ]
1545 rule opstmt<<C>>: option<<C>>
1549 rule payload<<C>>: PAYLOAD DIRPATH {{ if (C): payload(DIRPATH) }}
1551 rule mainboard<<C>>:
1552 MAINBOARD PATH {{ if (C): mainboard(PATH) }}
1554 rule romif<<C>>: IF ID {{ c = lookup(ID) }}
1555 (romstmt<<C and c>>)*
1556 [ ELSE (romstmt<<C and not c>>)* ]
1559 rule romstmt<<C>>: romif<<C>>
1564 rule romimage: ROMIMAGE STR {{ startromimage(dequote(STR)) }}
1566 END {{ endromimage() }}
1568 rule roms: STR {{ s = '[' + STR }}
1569 ( STR {{ s = s + "," + STR }}
1570 )* {{ return eval(s + ']') }}
1572 rule buildrom: BUILDROM DIRPATH expr roms {{ addbuildrom(DIRPATH, expr, roms) }}
1574 rule romstmts: romimage
1578 # ENTRY for parsing root part
1579 rule board: LOADOPTIONS {{ loadoptions() }}
1580 TARGET DIRPATH {{ target(DIRPATH) }}
1585 # ENTRY for parsing a delayed value
1586 rule delexpr: "{" expr "}" EOF {{ return expr }}
1588 rule wrstr<<ID>>: STR {{ setwrite(ID, dequote(STR)) }}
1590 rule defstmts<<ID>>: {{ d = 0 }}
1592 ( value {{ setdefault(ID, value, 1) }}
1593 | NONE {{ setnodefault(ID) }}
1595 | FORMAT STR {{ setformat(ID, dequote(STR)) }}
1597 ( ALWAYS {{ setexported(ID) }}
1598 | USED {{ setexportable(ID) }}
1599 | NEVER {{ setnoexport(ID) }}
1601 | COMMENT STR {{ setcomment(ID, dequote(STR)); d = d | 4 }}
1602 | WRITE (wrstr<<ID>>)+
1605 rule define: DEFINE ID {{ newoption(ID) }}
1606 defstmts<<ID>> END {{ validdef(ID, defstmts) }}
1608 # ENTRY for parsing Options.lb file
1609 rule options: (define)* EOF {{ return 1 }}
1612 #=============================================================================
1614 #=============================================================================
1615 def writemakefileheader(file, fname):
1616 file.write("# File: %s\n" % fname)
1617 file.write("# This file was generated by '%s %s %s'\n\n"
1618 % (sys.argv[0], sys.argv[1], sys.argv[2]))
1620 def writemakefilesettings(path):
1621 """ Write Makefile.settings to seperate the settings
1622 from the actual makefile creation."""
1624 global treetop, target_dir
1626 filename = os.path.join(path, "Makefile.settings")
1627 print "Creating", filename
1628 file = safe_open(filename, 'w+')
1629 writemakefileheader(file, filename)
1630 file.write("TOP:=%s\n" % (treetop))
1631 file.write("TARGET_DIR:=%s\n" % target_dir)
1634 def writeimagesettings(image):
1635 """Write Makefile.settings to seperate the settings
1636 from the actual makefile creation."""
1639 global global_options_by_order
1641 filename = os.path.join(image.gettargetdir(), "Makefile.settings")
1642 print "Creating", filename
1643 file = safe_open(filename, 'w+')
1644 writemakefileheader(file, filename)
1645 file.write("TOP:=%s\n" % (treetop))
1646 file.write("TARGET_DIR:=%s\n" % (image.gettargetdir()))
1649 for o in global_exported_options:
1651 for o in image.exported_options:
1652 if (not o in exported):
1655 file.write("export %s:=" % o.name)
1656 if (hasvalue(o.name, image)):
1657 file.write("%s" % getformated(o.name, image))
1660 file.write("export VARIABLES :=\n")
1662 file.write("export VARIABLES += %s\n" % o.name)
1666 # write the romimage makefile
1667 # let's try the Makefile
1668 # first, dump all the -D stuff
1670 def writeimagemakefile(image):
1671 makefilepath = os.path.join(image.gettargetdir(), "Makefile")
1672 print "Creating", makefilepath
1673 file = safe_open(makefilepath, 'w+')
1674 writemakefileheader(file, makefilepath)
1676 #file.write("include cpuflags\n")
1677 # Putting "include cpuflags" in the Makefile has the problem that the
1678 # cpuflags file would be generated _after_ we want to include it.
1679 # Instead, let make do the work of computing CPUFLAGS:
1680 file.write("# Get the value of TOP, VARIABLES, and several other variables.\n")
1681 file.write("include Makefile.settings\n\n")
1682 file.write("# Function to create an item like -Di586 or -DCONFIG_MAX_CPUS='1' or -Ui686\n")
1683 file.write("D_item = $(if $(subst undefined,,$(origin $1)),-D$1$(if $($1),='$($1)',),-U$1)\n\n")
1684 file.write("# Compute the value of CPUFLAGS here during make's first pass.\n")
1685 file.write("CPUFLAGS := $(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))\n\n")
1687 for i in image.getuserdefines():
1688 file.write("%s\n" %i)
1692 file.write("all: linuxbios.rom")
1693 # print out all the object dependencies
1694 file.write("\n# object dependencies (objectrules:)\n")
1695 file.write("INIT-OBJECTS :=\n")
1696 file.write("OBJECTS :=\n")
1697 file.write("DRIVER :=\n")
1698 file.write("\nSOURCES :=\n")
1699 for irule, init in image.getinitobjectrules().items():
1702 file.write("INIT-OBJECTS += %s\n" % (i_name))
1703 file.write("SOURCES += %s\n" % (i_source))
1705 for objrule, obj in image.getobjectrules().items():
1708 file.write("OBJECTS += %s\n" % (obj_name))
1709 file.write("SOURCES += %s\n" % (obj_source))
1712 file.write("OBJECTS += static.o\n")
1713 file.write("SOURCES += static.c\n")
1715 for driverrule, driver in image.getdriverrules().items():
1716 obj_name = driver[0]
1717 obj_source = driver[1]
1718 file.write("DRIVER += %s\n" % (obj_name))
1719 file.write("SOURCES += %s\n" % (obj_source))
1721 # Print out all ldscript.ld dependencies.
1722 file.write("\n# ldscript.ld dependencies:\n")
1723 file.write("LDSUBSCRIPTS-1 := \n" )
1724 for script in image.getldscripts():
1725 file.write("LDSUBSCRIPTS-1 += %s\n" % topify(script))
1727 # Print out the dependencies for crt0_includes.h
1728 file.write("\n# Dependencies for crt0_includes.h\n")
1729 file.write("CRT0_INCLUDES:=\n")
1730 for inc in image.getinitincludes():
1731 if (local_path.match(inc)):
1732 file.write("CRT0_INCLUDES += %s\n" % inc)
1734 file.write("CRT0_INCLUDES += $(TOP)/src/%s\n" % inc)
1736 # Print out the user defines.
1737 file.write("\n# userdefines:\n")
1739 # Print out the base rules.
1740 # Need to have a rule that counts on 'all'.
1741 file.write("\n# mainrulelist:")
1743 # Print out any user rules.
1744 file.write("\n# From makerule or docipl commands:\n")
1746 file.write("\n# initobjectrules:\n")
1747 for irule, init in image.getinitobjectrules().items():
1748 source = topify(init[1])
1751 # for .S, .o depends on .s
1752 file.write("%s: %s.s\n" % (init[0], init[3]))
1753 file.write("\t@echo $(CC) ... -o $@ $<\n")
1754 file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
1755 # and .s depends on .S
1756 file.write("%s.s: %s\n" % (init[3], source))
1757 file.write("\t@echo $(CPP) ... $< > $@\n")
1758 # Note: next 2 lines are ONE output line!
1759 file.write("\t$(CPP) $(CPPFLAGS) $< ")
1760 file.write(">$@.new && mv $@.new $@\n")
1762 file.write("%s: %s\n" % (init[0], source))
1763 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
1765 file.write("\n# objectrules:\n")
1766 for objrule, obj in image.getobjectrules().items():
1767 source = topify(obj[1])
1770 # for .S, .o depends on .s
1771 file.write("%s: %s.s\n" % (obj[0], obj[3]))
1772 file.write("\t@echo $(CC) ... -o $@ $<\n")
1773 file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
1774 # and .s depends on .S
1775 file.write("%s.s: %s\n" % (obj[3], source))
1776 file.write("\t@echo $(CPP) ... $< > $@\n")
1777 # Note: next 2 lines are ONE output line!
1778 file.write("\t$(CPP) $(CPPFLAGS) $< ")
1779 file.write(">$@.new && mv $@.new $@\n")
1781 file.write("%s: %s\n" % (obj[0], source))
1782 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
1783 #file.write("%s\n" % objrule[2])
1785 for driverrule, driver in image.getdriverrules().items():
1786 source = topify(driver[1])
1787 file.write("%s: %s\n" % (driver[0], source))
1788 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
1789 #file.write("%s\n" % objrule[2])
1791 # special rule for chip_target.c
1792 file.write("static.o: static.c\n")
1793 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
1795 # Print out the rules that will make cause the files
1796 # generated by NLBConfig.py to be remade if any dependencies change.
1798 file.write("\n# Remember the automatically generated files\n")
1799 file.write("GENERATED:=\n")
1800 for genfile in ['Makefile',
1803 'LinuxBIOSDoc.config' ]:
1804 file.write("GENERATED += %s\n" % genfile)
1805 file.write("GENERATED += %s\n" % image.getincludefilename())
1807 keys = global_options_by_order
1809 file.write("\necho:\n")
1811 file.write("\t@echo %s='$(%s)'\n"% (key,key))
1813 for i, m in image.getmakerules().items():
1814 file.write("%s: " %i)
1815 for i in m.dependency:
1816 file.write("%s " % i)
1819 file.write("\t%s\n" % i)
1823 def writemakefile(path):
1824 makefilepath = os.path.join(path, "Makefile")
1825 print "Creating", makefilepath
1826 file = safe_open(makefilepath, 'w+')
1827 writemakefileheader(file, makefilepath)
1828 file.write("include Makefile.settings\n\n")
1832 for i in romimages.keys():
1833 file.write("%s-rom " % i)
1834 file.write("buildroms\n\n")
1835 for i, o in romimages.items():
1836 file.write("%s-rom:\n" % o.getname())
1837 file.write("\tif (cd %s; \\\n" % o.getname())
1838 file.write("\t\tmake linuxbios.rom)\\\n");
1839 file.write("\tthen true; else exit 1; fi;\n\n")
1840 file.write("clean: ")
1841 for i in romimages.keys():
1842 file.write("%s-clean " % i)
1844 for i, o in romimages.items():
1845 file.write("%s-clean:\n" % o.getname())
1846 file.write("\t(cd %s; make clean)\n" % o.getname())
1848 file.write("\nbuildroms:\n")
1850 file.write("\tcat ");
1852 file.write("%s/linuxbios.rom " % j )
1853 file.write("> %s\n" % i.name);
1858 def writeinitincludes(image):
1859 global include_pattern
1860 filepath = os.path.join(image.gettargetdir(), image.getincludefilename())
1861 print "Creating", filepath
1862 outfile = safe_open(filepath, 'w+')
1863 if (image.newformat()):
1864 infile = safe_open(image.getinitfile(), 'r')
1866 line = infile.readline()
1868 p = include_pattern.match(line)
1870 for i in image.getinitincludes():
1871 inc = image.getinitinclude(i)
1872 if (inc.getstring() == p.group(1)):
1873 outfile.write("#include \"%s\"\n" % inc.getpath())
1875 outfile.write(line);
1876 line = infile.readline()
1880 for i in image.getinitincludes():
1881 outfile.write("#include <%s>\n" % i)
1884 def writeldoptions(image):
1885 """Write ldoptions file."""
1886 filename = os.path.join(image.gettargetdir(), "ldoptions")
1887 print "Creating", filename
1888 file = safe_open(filename, 'w+')
1889 for o in global_exported_options:
1890 if (hasvalue(o.name, image) and IsInt(getoption(o.name, image))):
1891 file.write("%s = %s;\n" % (o.name, getformated(o.name, image)))
1892 for o in image.exported_options:
1893 if (not o in global_exported_options and hasvalue(o.name, image) and IsInt(getoption(o.name, image))):
1894 file.write("%s = %s;\n" % (o.name, getformated(o.name, image)))
1897 def dumptree(part, lvl):
1898 debug.info(debug.dumptree, "DUMPTREE ME is")
1900 # dump the siblings -- actually are there any? not sure
1902 debug.info(debug.dumptree, "DUMPTREE SIBLINGS are")
1908 debug.info(debug.dumptree, "DUMPTREE KIDS are")
1909 #for kid in part.children:
1911 dumptree(part.children, lvl+1)
1912 debug.info(debug.dumptree, "DONE DUMPTREE")
1914 def writecode(image):
1915 filename = os.path.join(img_dir, "static.c")
1916 print "Creating", filename
1917 file = safe_open(filename, 'w+')
1918 file.write("#include <device/chip.h>\n")
1919 file.write("#include <device/pci.h>\n")
1920 for path in image.getconfigincludes().values():
1921 file.write("#include \"%s\"\n" % path)
1922 gencode(image.getroot(), file, 0)
1923 gencode(image.getroot(), file, 1)
1926 def gencode(part, file, pass_num):
1927 debug.info(debug.gencode, "GENCODE ME is")
1928 part.gencode(file, pass_num)
1929 # dump the siblings -- actually are there any? not sure
1930 debug.info(debug.gencode, "GENCODE SIBLINGS are")
1933 kid.gencode(file, pass_num)
1935 # now dump the children
1936 debug.info(debug.gencode, "GENCODE KIDS are")
1938 gencode(part.children, file, pass_num)
1942 gencode(kid.children, file, pass_num)
1944 debug.info(debug.gencode, "DONE GENCODE")
1947 """Add any run-time checks to verify that parsing the configuration
1950 for image in romimages.values():
1951 print("Verifying ROMIMAGE %s" % image.name)
1952 if (image.newformat() and image.getinitfile() == ''):
1953 fatal("An init file must be specified")
1954 for op in image.exported_options:
1955 if (getoptionvalue(op.name, op, image) == 0 and getoptionvalue(op.name, op, 0) == 0):
1956 warning("Exported option %s has no value (check Options.lb)" % op.name);
1957 print("Verifing global options")
1958 for op in global_exported_options:
1959 if (getoptionvalue(op.name, op, 0) == 0):
1960 notice("Exported option %s has no value (check Options.lb)" % op.name);
1962 #=============================================================================
1964 #=============================================================================
1965 if __name__=='__main__':
1966 from sys import argv
1968 fatal("Args: <file> <path to linuxbios>")
1970 top_config_file = os.path.abspath(sys.argv[1])
1972 treetop = os.path.abspath(sys.argv[2])
1974 # Now read in the customizing script...
1976 fp = safe_open(argv[1], 'r')
1977 if (not parse('board', fp.read())):
1978 fatal("Could not parse file")
1983 # no longer need to check if an options has been used
1986 for image_name, image in romimages.items():
1987 if (debug.level(debug.dumptree)):
1988 debug.info(debug.dumptree, "DEVICE TREE:")
1989 dumptree(image.getroot(), 0)
1991 img_dir = image.gettargetdir()
1992 if not os.path.isdir(img_dir):
1993 print "Creating directory %s" % img_dir
1994 os.makedirs(img_dir)
1996 if (debug.level(debug.dump)):
1997 for i in image.getinitincludes():
1998 debug.info(debug.dump, "crt0include file %s" % i)
1999 for i in image.getdriverrules().keys():
2000 debug.info(debug.dump, "driver file %s" % i)
2001 for i in image.getldscripts():
2002 debug.info(debug.dump, "ldscript file %s" % i)
2003 for i, m in image.getmakerules().items():
2004 debug.info(debug.dump, " makerule %s dep %s act %s" % (i, m.dependency, m.actions))
2007 writeimagesettings(image)
2008 writeinitincludes(image)
2009 writeimagemakefile(image)
2010 writeldoptions(image)
2012 writemakefilesettings(target_dir)
2013 writemakefile(target_dir)