15 # Key is the rule name. Value is a mkrule object.
18 # List of targets in the order defined by makerule commands.
26 # make these a hash so they will be unique.
33 globalvars = {} # We will globals here
37 # options in order defined. These will be unique due to use of hash
46 local_path = re.compile(r'^\.')
48 # -----------------------------------------------------------------------------
50 # -----------------------------------------------------------------------------
54 def __init__(self, file, line, command):
57 self.command = command
58 def next_line(self, command):
59 self.line = self.line + 1
60 self.command = command
62 return "%s:%d" % (self.file, self.line)
68 return self.stack[-1].file
70 return self.stack[-1].line
72 return self.stack[-1].command
74 def push_file(self, file):
75 self.stack.append(self.place(file, 0, ""))
78 def next_line(self, command):
79 self.stack[-1].next_line(command)
81 return self.stack[-1].at()
85 def __init__ (self, target):
90 def addaction(self, action):
91 self.actions.append(action)
93 def adddependency(self, dependency):
94 self.dependency.append(dependency)
99 def gdependency(self):
100 return self.dependency
106 def __init__ (self, name):
107 self.name = name # name of option
108 self.loc = 0 # current location
109 self.value = 0 # option value
110 self.set = 0 # option has been set
111 self.default = 0 # option has default value (otherwise
113 self.comment = '' # description of option
114 self.export = 0 # option is able to be exported
115 self.exported = 0 # option is exported
116 self.defined = 0 # option has a value
117 self.format = '%s' # option print format
119 def setvalue(self, value, loc):
121 print "Option %s: " % self.name
122 print "Attempt to set %s at %s" % (value, loc.at())
123 print "Already set to %s at %s" % \
124 (self.value, self.loc.at())
131 def getvalue(self, part):
133 if (not (type(self.value) is str)):
135 if (self.value == '' or self.value[0] != '{'):
137 # evaluate expression
138 a = re.sub("^{", "", self.value)
139 a = re.sub("}$", "", a)
140 # save curpart so we can evaluate expression
144 v = parse('value', a)
148 def setdefault(self, value, loc):
150 print "%s: " % self.name
151 print "Attempt to default %s at %s" % (value, loc)
152 print "Already defaulted to %s at %s" % \
153 (self.value, self.loc.at())
156 print "%s: " % self.name
157 print "Attempt to default %s at %s" % (value, loc)
158 print "Already set to %s at %s" % \
159 (self.value, self.loc.at())
167 def setnodefault(self, loc):
175 def setcomment(self, value, loc):
176 if (self.comment != ''):
177 print "%s: " % self.name
178 print "Attempt to modify comment at %s" % loc
185 def setexported(self):
189 def setnoexport(self):
193 def setformat(self, fmt):
203 def isexported(self):
204 return (self.exported and self.defined)
207 return (self.defined)
213 def __init__ (self, dir, parent, type):
216 print "partobj dir %s parent %s type %s" %(dir,parent,type)
219 self.registercode = []
225 self.instance = partinstance + 1
226 partinstance = partinstance + 1
232 print "add to parent"
234 parent.children.append(self)
238 def dumpme(self, lvl):
239 print "%d: type %s" % (lvl, self.type)
240 print "%d: dir %s" % (lvl,self.dir)
241 print "%d: parent %s" % (lvl,self.parent.type)
242 print "%d: parent dir %s" % (lvl,self.parent.dir)
243 print "%d: initcode " % lvl
244 for i in self.initcode:
246 print "%d: registercode " % lvl
247 for i in self.registercode:
251 print "struct cdev dev%d = {" % self.instance
252 print "/* %s %s */" % (self.type, self.dir)
253 print " .devfn = %d" % self.devfn
255 print " .next = &dev%d" % self.sibling.instance
257 print " .children = &dev%d" % \
258 self.children[0].instance
260 print " .private = private%d" % self.instance
267 def addinit(self, code):
268 self.initcode.append(code)
270 def addregister(self, code):
271 self.registercode.append(code)
273 def usesoption(self, name):
274 o = getvalue(options, name)
276 fatal("Error: can't use undefined option %s" % name)
278 setvalue(self.options, name, o)
280 print "option %s used in %s" % (name, self)
286 def push(self, part):
287 self.stack.append(part)
290 return self.stack.pop()
293 return self.stack[-1]
294 pstack = partsstack()
298 size = len(loc.stack)
301 print loc.stack[i].at()
303 print "%s: %s"% (loc.at(), string)
308 print "===> Warning:"
309 size = len(loc.stack)
312 print loc.stack[i].at()
314 print "%s: %s"% (loc.at(), string)
317 # -----------------------------------------------------------------------------
319 # -----------------------------------------------------------------------------
321 def getvalue(dict, name):
322 if name not in dict.keys():
324 print 'Undefined:', name
326 v = dict.get(name, 0)
328 print "getvalue %s returning %s" % (name, v)
331 def setvalue(dict, name, value):
332 if name in dict.keys():
333 print "Warning, %s previously defined" % name
335 print "setvalue sets %s to %s" % (name, value)
339 # to create an option, it has to not exist.
340 # When an option value is fetched, the fact that it was used is
342 # Legal things to do:
343 # set a default value, then set a real value before the option is used.
344 # set a value, try to set a default, default silently fails.
346 # use the value, then try to set the value
349 o = getvalue(options, name)
351 print "option %s already defined" % name
354 setvalue(options, name, o)
355 options_by_order.append(name)
357 # option must be declared before being used in a part
358 # if we're not processing a part, then we must
359 # be at the top level where all options are available
360 def getoption(name, part):
363 o = getvalue(part.options, name)
365 o = getvalue(options, name)
366 if (o == 0 or not o.defined):
367 fatal( "Error: Option %s Undefined." % name)
370 print "getoption returns %s" % v
371 print "%s" % o.where()
374 # setoptionstmt only allowed at top level
375 def setoptionstmt(name, value):
377 if (curpart != root):
378 fatal("Error: options can only be set in target configuration file")
379 setoption(name, value)
381 def setoption(name, value):
383 o = getvalue(options, name)
385 fatal("Error: attempt set nonexistent option %s" % name)
386 o.setvalue(value, loc)
388 def setdefault(name, value):
390 o = getvalue(options, name)
394 print "setdefault: attempt to duplicate default for %s" % name
396 o.setdefault(value, loc)
398 def setnodefault(name):
400 o = getvalue(options, name)
404 print "setdefault: attempt to duplicate default for %s" % name
408 def setcomment(name, value):
409 o = getvalue(options, name)
411 fatal("setcomment: %s not here" % name)
412 o.setcomment(value, loc)
414 def setexported(name):
415 o = getvalue(options, name)
417 fatal("setexported: %s not here" % name)
420 def setnoexport(name):
421 o = getvalue(options, name)
423 fatal("setnoexport: %s not here" % name)
427 o = getvalue(options, name)
429 fatal("setexport: %s not here" % name)
432 def setformat(name, fmt):
433 o = getvalue(options, name)
435 fatal("setexport: %s not here" % name)
438 def getformated(name, part):
441 o = getvalue(part.options, name)
443 o = getvalue(options, name)
444 if (o == 0 or not o.defined):
445 fatal( "Error: Option %s Undefined." % name)
450 def isexported(name, part):
452 o = getvalue(part.options, name)
454 o = getvalue(options, name)
456 return o.isexported()
459 def isdefined(name, part):
461 o = getvalue(part.options, name)
463 o = getvalue(options, name)
468 def isset(name, part):
470 o = getvalue(part.options, name)
472 o = getvalue(options, name)
477 def usesoption(name):
479 curpart.usesoption(name)
481 def validdef(name, defval):
482 o = getvalue(options, name)
484 fatal("validdef: %s not here" % name)
485 if ((defval & 1) != 1):
486 fatal("Error: must specify default value for option %s" % name)
487 if ((defval & 2) != 2):
488 fatal("Error: must specify export for option %s" % name)
489 if ((defval & 4) != 4):
490 fatal("Error: must specify comment for option %s" % name)
494 optionsfile = os.path.join(treetop, 'src', 'config', 'Options.lb')
495 loc.push_file(optionsfile)
496 if (not parse('options', open(optionsfile, 'r').read())):
497 fatal("Error: Could not parse file")
500 # we do the crt0include as a dictionary, so that if needed we
501 # can trace who added what when. Also it makes the keys
503 def addcrt0include(path):
505 #fullpath = os.path.join(curdir, path)
507 #setvalue(crt0includes, fullpath, loc)
508 # oh shoot. Order matters. All right, we'll worry about this
512 print "ADDCRT0: %s" % fullpath
513 crt0includes.append(fullpath)
515 def addldscript(path):
518 fullpath = treetop + '/src/' + path
520 fullpath = curdir + '/' + path
521 #fullpath = os.path.join(curdir, path)
522 #setvalue(ldscripts, fullpath, loc)
524 print "fullpath :%s: curdir :%s: path :%s:" % (fullpath, curdir, path)
525 ldscripts.append(fullpath)
529 adduserdefine("PAYLOAD:=%s"%path)
531 # adddep('payload', path)
532 # addaction('payload', 'cp $< $@')
534 # this is called with an an object name.
535 # the easiest thing to do is add this object to the current
537 # such kludgery. If the name starts with '.' then make the
538 # dependency be on ./thing.x gag me.
539 def addobjectdriver(dict, object_name):
540 suffix = object_name[-2:]
543 base = object_name[:-2]
544 if (object_name[0] == '.'):
545 source = base + suffix
547 source = os.path.join(curdir, base + suffix)
550 print "add object %s source %s" % (object_name, source)
551 setvalue(dict, base, [object, source])
553 def addobject(object_name):
554 addobjectdriver(objectrules, object_name)
556 def adddriver(driver_name):
557 addobjectdriver(driverrules, driver_name)
559 def target(targ_name):
563 print "Configuring TARGET %s" % targ_name
564 target_dir = os.path.join(os.path.dirname(loc.file()), targ_name)
565 if not os.path.isdir(target_dir):
566 print "Creating directory" % target_dir
567 os.makedirs(target_dir)
568 print "Will place Makefile, crt0.S, etc. in %s" % target_dir
569 root = partobj(target_dir, 0, 'board')
572 def part(name, path, file):
573 global curpart,curdir,treetop
574 dirstack.append(curdir)
575 curdir = os.path.join(treetop, 'src', name, path)
576 newpart = partobj(curdir, curpart, name)
577 print "Configuring PART %s" % name
579 print "PUSH part %s %s" % (name, curpart.dir)
582 doconfigfile(curdir, file)
585 global curpart,curdir
586 curpart = pstack.pop()
587 curdir = dirstack.pop()
589 print "POP PART %s" % curpart.dir
591 # dodir is like part but there is no new part
592 def dodir(path, file):
593 global curdir, treetop
594 # if the first char is '/', it is relative to treetop,
595 # else relative to curdir
596 # os.path.join screws up if the name starts with '/', sigh.
598 fullpath = treetop + '/src/' + path
600 fullpath = os.path.join(curdir, path)
602 print "DODIR: path %s, fullpath %s" % (path, fullpath)
603 print "DODIR: curdis %s treetop %s" % (curdir, treetop)
604 dirstack.append(curdir)
606 file = os.path.join(fullpath, file)
607 config_file_list.append(file)
608 doconfigfile(fullpath, file)
609 curdir = dirstack.pop()
611 def ternary(expr, yes, no):
613 print "ternary %s" % expr
614 a = tohex(expr) # expr # eval(expr)
616 print "expr %s a %d yes %d no %d"% (expr, a, yes, no)
619 print "Ternary returns %d" % yes
623 print "Ternary returns %d" % no
626 # atoi is in the python library, but not strtol? Weird!
628 return eval('int(%s)' % name)
631 """ Is the given string an integer?"""
640 setvalue(makebaserules, id, o)
642 def adduserdefine(str):
643 userdefines.append(str)
646 a = re.sub("^\"", "", str)
647 a = re.sub("\"$", "", a)
648 # highly un-intuitive, need four \!
649 a = re.sub("\\\\\"", "\"", a)
652 def addaction(id, str):
653 o = getvalue(makebaserules, id)
658 o = getvalue(makebaserules, id)
662 # If the first part of <path> matches treetop, replace that part with "$(TOP)"
665 if path[0:len(treetop)] == treetop:
666 path = path[len(treetop):len(path)]
667 if (path[0:1] == "/"):
668 path = path[1:len(path)]
669 path = "$(TOP)/" + path
672 # arch is 'different' ... darn it.
673 def set_arch(my_arch):
677 setoption('ARCH', my_arch)
678 part('arch', my_arch, 'config/make.base.lb')
682 global mainboard_dir, treetop
684 full_mainboard_dir = os.path.join(treetop, 'src/mainboard', path)
685 setoption('MAINBOARD', full_mainboard_dir)
686 vendor = re.sub("/.*", "", path)
687 mainboard_part_number = re.sub("[^/]/", "", path)
688 setoption('MAINBOARD_VENDOR', vendor)
689 setoption('MAINBOARD_PART_NUMBER', mainboard_part_number)
690 part('mainboard', path, 'Config.lb')
692 #=============================================================================
694 #=============================================================================
695 def writemakefileheader(file, fname):
696 file.write("# File: %s\n" % fname)
697 file.write("# This file was generated by '%s %s %s'\n\n"
698 % (sys.argv[0], sys.argv[1], sys.argv[2]))
701 def writemakefilesettings(path):
702 global treetop, arch, mainboard_dir, target_dir, options_by_order, root
703 # Write Makefile.settings to seperate the settings
704 # from the actual makefile creation
705 # In practice you need to rerun NLBConfig.py to change
706 # these but in theory you shouldn't need to.
708 filename = os.path.join(path, "Makefile.settings")
709 print "Creating", filename
710 file = open(filename, 'w+')
711 writemakefileheader(file, filename)
712 file.write("TOP:=%s\n" % (treetop))
713 #file.write("ARCH:=%s\n" % (arch))
714 #file.write("MAINBOARD:=%s\n" % (mainboard_dir))
715 file.write("TARGET_DIR:=%s\n" % (target_dir))
716 for i in options_by_order:
717 if (isexported(i, 0)):
718 file.write("export %s:=%s\n" % (i, getformated(i, 0)))
719 file.write("export VARIABLES := ")
720 for i in options.keys():
721 if (isexported(i, 0)):
722 file.write("%s " % i)
724 # file.write("CPUFLAGS := ")
725 # for i in options.keys():
727 # file.write("-D%s=%s " % (i, o.getvalue()))
733 # let's try the Makefile
734 # first, dump all the -D stuff
736 def writemakefile(path):
738 makefilepath = os.path.join(path, "Makefile")
739 print "Creating", makefilepath
740 file = open(makefilepath, 'w+')
741 writemakefileheader(file, makefilepath)
743 # file.write("include Makefile.settings\n")
744 # file.write("include cpuflags\n")
745 # Putting "include cpuflags" in the Makefile has the problem that the
746 # cpuflags file would be generated _after_ we want to include it.
747 # Instead, let make do the work of computing CPUFLAGS:
749 # Get the value of TOP, VARIABLES, and several other variables.
750 include Makefile.settings
752 # Function to create an item like -Di586 or -DMAX_CPUS='1' or -Ui686
753 D_item = $(if $(subst undefined,,$(origin $1)),-D$1$(if $($1),='$($1)',),-U$1)
755 # Compute the value of CPUFLAGS here during make's first pass.
756 CPUFLAGS := $(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))
759 for i in userdefines:
760 file.write("%s\n" %i)
763 # print out all the object dependencies
764 file.write("\n# object dependencies (objectrules:)\n")
765 file.write("OBJECTS :=\n")
766 file.write("DRIVERS :=\n")
767 for objrule in objectrules.keys():
768 obj = objectrules[objrule]
771 file.write("OBJECTS-1 += %s\n" % (obj_name))
773 for driverrule in driverrules.keys():
774 driver = driverrules[driverrule]
776 obj_source = driver[1]
777 file.write("DRIVER += %s\n" % (obj_name))
779 # Print out all ldscript.ld dependencies.
780 file.write("\n# ldscript.ld dependencies:\n")
781 file.write("LDSUBSCRIPTS-1 := \n" )
782 for script in ldscripts:
783 file.write("LDSUBSCRIPTS-1 += %s\n" % topify(script))
785 # Print out the dependencies for crt0_includes.h
786 file.write("\n# Dependencies for crt0_includes.h\n")
787 file.write("CRT0_INCLUDES:=\n")
788 for i in crt0includes:
789 if (local_path.match(i)):
790 file.write("CRT0_INCLUDES += %s\n" % i)
792 file.write("CRT0_INCLUDES += $(TOP)/src/%s\n" % i)
794 file.write("\nSOURCES=\n")
795 #for source in sources:
796 #file.write("SOURCES += %s\n" % source)
798 # Print out the user defines.
799 file.write("\n# userdefines:\n")
800 #for udef in userdefines:
801 #file.write("%s\n" % udef)
803 # Print out the base rules.
804 # Need to have a rule that counts on 'all'.
805 file.write("\n# mainrulelist:")
806 #file.write("\nmainrule: %s\n" % mainrulelist)
808 # Print out any user rules.
809 file.write("\n# From makerule or docipl commands:\n")
810 # Old way (hash order): for target in makebaserules.keys():
811 # New way (config file order):
812 #for target in makerule_targets:
813 #makebaserules[target].write(file)
815 file.write("\n# objectrules:\n")
816 for objrule in objectrules.keys():
817 obj = objectrules[objrule]
818 source = topify(obj[1])
819 file.write("%s: %s\n" % (obj[0], source))
820 file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
821 #file.write("%s\n" % objrule[2])
823 for driverrule in driverrules.keys():
824 driver = driverrules[driverrule]
825 source = topify(driver[1])
826 file.write("%s: %s\n" % (driver[0], source))
827 #file.write("%s\n" % objrule[2])
829 # Print out the rules that will make cause the files
830 # generated by NLBConfig.py to be remade if any dependencies change.
832 file.write("\n# Remember the automatically generated files\n")
833 file.write("GENERATED:=\n")
834 for genfile in [ 'Makefile',
839 'LinuxBIOSDoc.config' ]:
840 file.write("GENERATED += %s\n" % genfile)
842 file.write("\n# Remake Makefile (and the other files generated by\n")
843 file.write("# NLBConfig.py) if any config dependencies change.\n")
845 for cfile in config_file_list:
846 file.write("$(GENERATED): %s\n" % topify(cfile))
848 for depfile in [ '%s' % top_config_file, # This a duplicate, remove?
849 '$(TOP)/util/config/NLBConfig.py',
850 '$(TOP)/src/arch/$(ARCH)/config/make.base' ]:
851 file.write("$(GENERATED): %s\n" % depfile)
853 file.write("$(GENERATED):\n")
854 file.write("\tpython $(TOP)/util/config/NLBConfig.py %s $(TOP)\n"
857 keys = root.options.keys()
859 file.write("\necho:\n")
861 file.write("\t@echo %s='$(%s)'\n"% (key,key))
864 for i in makebaserules.keys():
866 file.write("%s: " %i)
867 for i in m.dependency:
868 file.write("%s " % i)
871 file.write("\t%s\n" % i)
874 # Write out crt0_includes.h (top-level assembly language) include file.
875 def writecrt0_includes(path):
876 crt0filepath = os.path.join(path, "crt0_includes.h")
877 print "Creating", crt0filepath
878 file = open(crt0filepath, 'w+')
880 for i in crt0includes:
881 file.write("#include <%s>\n" % i)
891 # less general tokens should come first, otherwise they get matched
894 token ADDACTION: 'addaction'
895 token ALWAYS: 'always'
897 token COMMENT: 'comment'
899 token DEFAULT: 'default'
900 token DEFINE: 'define'
903 token DRIVER: 'driver'
906 token EXPORT: 'export'
907 token FORMAT: 'format'
910 token LDSCRIPT: 'ldscript'
911 token LOADOPTIONS: 'loadoptions'
912 token MAINBOARD: 'mainboard'
913 token MAINBOARDINIT: 'mainboardinit'
914 token MAKEDEFINE: 'makedefine'
915 token MAKERULE: 'makerule'
918 token NORTHBRIDGE: 'northbridge'
919 token OBJECT: 'object'
920 token OPTION: 'option'
921 token PAYLOAD: 'payload'
923 token REGISTER: 'register'
924 token SOUTHBRIDGE: 'southbridge'
925 token SUPERIO: 'superio'
926 token TARGET: 'target'
930 token XNUM: r'0x[0-9a-fA-F]+'
931 # Why is path separate? Because paths to resources have to at least
932 # have a slash, we thinks
933 token PATH: r'[a-zA-Z0-9_.][a-zA-Z0-9/_.]+[a-zA-Z0-9_.]+'
934 # Dir's on the other hand are abitrary
935 # this may all be stupid.
936 token DIRPATH: r'[a-zA-Z0-9_$()./]+'
937 token ID: r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
938 token DELEXPR: r'{([^}]+|\\.)*}'
939 token STR: r'"([^\\"]+|\\.)*"'
942 rule expr<<V>>: logical<<V>> {{ l = logical }}
943 ( "&&" logical<<V>> {{ l = l and logical }}
944 | "||" logical<<V>> {{ l = l or logical }}
947 rule logical<<V>>: factor<<V>> {{ n = factor }}
948 ( "[+]" factor<<V>> {{ n = n+factor }}
949 | "-" factor<<V>> {{ n = n-factor }}
952 rule factor<<V>>: term<<V>> {{ v = term }}
953 ( "[*]" term<<V>> {{ v = v*term }}
954 | "/" term<<V>> {{ v = v/term }}
955 | "<<" term<<V>> {{ v = v << term }}
956 | ">=" term<<V>> {{ v = (v < term)}}
959 rule unop<<V>>: "!" ID {{ return ternary(getoption(ID, curpart), 1, 0)}}
961 # A term is a number, variable, or an expression surrounded by parentheses
962 rule term<<V>>: NUM {{ return atoi(NUM) }}
963 | XNUM {{ return tohex(XNUM) }}
964 | ID {{ return tohex(getoption(ID, curpart)) }}
965 | unop<<V>> {{ return unop }}
966 | "\\(" expr<<V>> "\\)" {{ return expr }}
968 rule partend<<C>>: partstmts<<C>> END
970 rule mainboard: MAINBOARD PATH {{ mainboard(PATH) }}
973 rule northbridge<<C>>:
974 NORTHBRIDGE PATH {{ if (C): part('northbridge', PATH, 'Config.lb') }}
977 rule superio<<C>>: SUPERIO PATH {{ if (C): part('superio', PATH, 'Config.lb') }}
980 rule cpu<<C>>: CPU ID {{ if (C): part('cpu', ID, 'Config.lb') }}
983 rule pmc<<C>>: PMC PATH {{ if (C): part('pmc', PATH, 'Config.lb') }}
986 rule arch<<C>>: ARCH ID {{ if (C): set_arch(ID) }}
989 rule southbridge<<C>>:
990 SOUTHBRIDGE PATH {{ if (C): part('southbridge', PATH, 'Config.lb')}}
993 rule mainboardinit<<C>>:
994 MAINBOARDINIT DIRPATH {{ if (C): addcrt0include(DIRPATH)}}
996 rule object<<C>>: OBJECT DIRPATH {{ if (C): addobject(DIRPATH)}}
998 rule driver<<C>>: DRIVER DIRPATH {{ if (C): adddriver(DIRPATH)}}
1000 rule dir<<C>>: DIR DIRPATH {{ if (C): dodir(DIRPATH, 'Config.lb') }}
1002 rule ldscript<<C>>: LDSCRIPT DIRPATH {{ if (C): addldscript(DIRPATH) }}
1004 rule payload<<C>>: PAYLOAD DIRPATH {{ if (C): payload(DIRPATH) }}
1006 # if is a bad id ....
1007 # needs to be C and ID, but nested if's are, we hope, not going to
1008 # happen. IF so, possibly ID && C could be used.
1009 rule iif<<C>>: IF ID {{ c = tohex(getoption(ID, curpart)) }}
1012 rule depsacts<<ID, C>>:
1013 ( DEP STR {{ if (C): adddep(ID, STR) }}
1014 | ACT STR {{ if (C): addaction(ID, STR) }}
1017 rule makerule<<C>>: MAKERULE DIRPATH {{ if (C): addrule(DIRPATH) }}
1018 depsacts<<DIRPATH, C>>
1020 rule makedefine<<C>>:
1021 MAKEDEFINE RAWTEXT {{ if (C): adduserdefine(RAWTEXT) }}
1023 rule addaction<<C>>:
1024 ADDACTION ID STR {{ if (C): addaction(ID, STR) }}
1026 rule init<<C>>: INIT STR {{ if (C): curpart.addinit(STR) }}
1028 rule register<<C>>: REGISTER STR {{ if (C): curpart.addregister(STR) }}
1030 # to make if work without 2 passses, we use an old hack from SIMD, the
1031 # context bit. If the bit is 1, then ops get done, otherwise
1032 # ops don't get done. From the top level, context is always
1033 # 1. In an if, context depends on eval of the if condition
1034 rule stmt<<C>>: cpu<<C>> {{ return cpu}}
1035 | pmc<<C>> {{ return pmc}}
1036 | arch<<C>> {{ return arch}}
1037 | northbridge<<C>> {{ return northbridge }}
1038 | southbridge<<C>> {{ return southbridge }}
1039 | superio<<C>> {{ return superio }}
1040 | object<<C>> {{ return object }}
1041 | driver<<C>> {{ return driver }}
1042 | mainboardinit<<C>> {{ return mainboardinit }}
1043 | makerule<<C>> {{ return makerule }}
1044 | makedefine<<C>> {{ return makedefine }}
1045 | addaction<<C>> {{ return addaction }}
1046 | init<<C>> {{ return init }}
1047 | register<<C>> {{ return register}}
1048 | iif<<C>> {{ return iif }}
1049 | dir<<C>> {{ return dir}}
1050 | ldscript<<C>> {{ return ldscript}}
1051 | payload<<C>> {{ return payload}}
1053 rule stmts<<C>>: (stmt<<C>>)* {{ }}
1055 rule partstmts<<C>>:
1057 (stmt<<C>>)* {{ partpop()}}
1059 # need this to get from python to the rules, I think.
1060 rule pstmts: (uses<<1>>)* stmts<<1>> {{ return 1 }}
1062 rule usesid<<C>>: ID {{ if (C): usesoption(ID) }}
1064 rule uses<<C>>: USES (usesid<<C>>)+
1066 rule value: STR {{ return dequote(STR) }}
1067 | term<<[]>> {{ return term }}
1068 | DELEXPR {{ return DELEXPR }}
1070 rule option: OPTION ID EQ value {{ setoptionstmt(ID, value) }}
1072 rule board: LOADOPTIONS {{ loadoptions() }}
1073 TARGET DIRPATH {{ target(DIRPATH) }}
1076 mainboard {{ return 1 }}
1078 rule defstmts<<ID>>: {{ d = 0 }}
1080 ( value {{ setdefault(ID, value) }}
1081 | NONE {{ setnodefault(ID) }}
1083 | FORMAT STR {{ setformat(ID, dequote(STR)) }}
1085 ( ALWAYS {{ setexported(ID) }}
1086 | USED {{ setexport(ID) }}
1087 | NEVER {{ setnoexport(ID) }}
1089 | COMMENT STR {{ setcomment(ID, dequote(STR)); d |= 4 }}
1092 rule define: DEFINE ID {{ newoption(ID) }}
1093 defstmts<<ID>> END {{ validdef(ID, defstmts) }}
1095 rule options: (define)* END {{ return 1 }}
1098 def dumptree(part, lvl):
1100 print "DUMPTREE ME is"
1102 # dump the siblings -- actually are there any? not sure
1105 print "DUMPTREE KIDS are"
1106 for kid in part.children:
1107 dumptree(kid, lvl+1)
1109 print "DONE DUMPTREE"
1113 print "GENCODE ME is"
1116 # dump the siblings -- actually are there any? not sure
1119 print "GENCODE KIDS are"
1120 for kid in part.children:
1123 print "DONE GENCODE"
1126 def doconfigfile(path, file):
1128 print "DOCONFIGFILE", path, " ", file
1129 filename = os.path.join(path, file)
1130 loc.push_file(filename)
1131 if (not parse('pstmts', open(filename, 'r').read())):
1132 fatal("Error: Could not parse file")
1134 if __name__=='__main__':
1135 from sys import argv
1137 print 'Args: <file> <path to linuxbios>'
1140 top_config_file = os.path.abspath(sys.argv[1])
1142 treetop = os.path.abspath(sys.argv[2])
1144 # Now read in the customizing script...
1145 loc.push_file(argv[1])
1146 if (not parse('board', open(argv[1], 'r').read())):
1147 fatal("Error: Could not parse file")
1150 print "DEVICE TREE:"
1155 for i in options.keys():
1156 if (isexported(i, 0) and not isset(i, 0)):
1157 print "WARNING: Option %s using default value %s" % (i, getformated(i, 0))
1161 for i in crt0includes:
1162 print "crt0include file %s" % (i)
1163 for i in driverrules.keys():
1164 print "driver file %s" % (i)
1166 print "ldscript file %s" % (i)
1167 for i in makebaserules.keys():
1168 m = makebaserules[i]
1169 print " makerule %s dep %s act %s" % (i, m.dependency, m.actions)
1171 writemakefilesettings(target_dir)
1172 writecrt0_includes(target_dir)
1173 writemakefile(target_dir)