This patch unifies the use of config options in v2 to all start with CONFIG_
[coreboot.git] / util / newconfig / config.g
index eddff03092baa90aa2eed5fc05dc5373303d9a6e..81ce4290219f77ab76c791a3a5f2d2804bf75497 100644 (file)
@@ -22,7 +22,10 @@ global_uses_options = {}
 global_exported_options = []
 romimages = {}
 buildroms = []
+pciroms = []
+rommapping = {}
 curimage = 0
+bootblocksize = 0
 alloptions = 0 # override uses at top level
 
 local_path = re.compile(r'^\.')
@@ -277,8 +280,11 @@ class romimage:
                self.arch = arch
 
        def setpayload(self, payload):
+               global rommapping
                self.payload = payload
 
+               rommapping[self.name] = payload
+
        def setinitfile(self, initfile):
                self.initfile = initfile
 
@@ -317,6 +323,22 @@ class romimage:
                        return
                fatal("No such rule \"%s\" for addmakedepend" % id)
 
+       def addmakeobject(self, file, obj):
+               source = topify(obj[1])
+               type = obj[2]
+               if (type  == 'S'):
+                       # for .S, .o depends on .s
+                       file.write("%s: %s.s\n" % (obj[0], obj[3]))
+                       file.write("\t$(CC) -c $(CONFIG_CPU_OPT) -o $@ $<\n")
+                       # and .s depends on .S
+                       file.write("%s.s: %s\n" % (obj[3], source))
+                       # Note: next 2 lines are ONE output line!
+                       file.write("\t$(CPP) $(CPPFLAGS) $< ")
+                       file.write(">$@.new && mv $@.new $@\n")
+               else:
+                       file.write("%s: %s\n" % (obj[0], source))
+                       file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
+
        # this is called with an an object name. 
        # the easiest thing to do is add this object to the current 
        # component.
@@ -475,6 +497,13 @@ class buildrom:
        def __getitem__(self,i):
                return self.roms[i]
 
+class pci_rom:
+       """A pci_rom statement"""
+       def __init__ (self, filename, vendor, device):
+               self.name = filename
+               self.pci_vid = vendor
+               self.pci_did = device
+       
 class initinclude:
        """include file for initialization code"""
        def __init__ (self, str, path):
@@ -595,8 +624,12 @@ class option_value:
 class partobj:
        """A configuration part"""
        def __init__ (self, image, dir, parent, part, type_name, instance_name, chip_or_device):
-               debug.info(debug.object, "partobj dir %s parent %s part %s" \
-                               % (dir, parent, part))
+               if (parent):
+                       debug.info(debug.object, "partobj dir %s parent %s part %s" \
+                               % (dir, parent.instance_name, part))
+               else:
+                       debug.info(debug.object, "partobj dir %s part %s" \
+                               % (dir, part))
 
                # romimage that is configuring this part
                self.image = image
@@ -1351,7 +1384,10 @@ def startromimage(name):
 
 def endromimage():
        global curimage
+       global bootblocksize
        mainboard()
+       imagesize = getoption("CONFIG_ROM_IMAGE_SIZE", curimage)
+       bootblocksize += imagesize
        print "End ROMIMAGE"
        curimage = 0
        #curpart = 0
@@ -1363,9 +1399,9 @@ def mainboardsetup(path):
        full_mainboard_path = os.path.join(treetop, 'src', 'mainboard', path)
        vendor = re.sub("/.*", "", path)
         part_number = re.sub("[^/]*/", "", path)
-       setdefault('MAINBOARD', full_mainboard_path, 0)
-       setdefault('MAINBOARD_VENDOR', vendor, 0)
-       setdefault('MAINBOARD_PART_NUMBER', part_number, 0)
+       setdefault('CONFIG_MAINBOARD', full_mainboard_path, 0)
+       setdefault('CONFIG_MAINBOARD_VENDOR', vendor, 0)
+       setdefault('CONFIG_MAINBOARD_PART_NUMBER', part_number, 0)
 
 def mainboard():
        global curimage, dirstack, partstack
@@ -1395,6 +1431,12 @@ def addbuildrom(filename, size, roms):
        b = buildrom(filename, size, roms)
        buildroms.append(b)
 
+def addpci_rom(filename, vendor, device):
+       global pciroms
+       print "Add PCI ROM %s" %filename
+       p = pci_rom(filename, vendor, device)
+       pciroms.append(p)
+
 def addinitobject(object_name):
        global curimage
        curimage.addinitobjectrule(object_name)
@@ -1492,6 +1534,20 @@ def dodir(path, file):
        doconfigfile(fullpath, path, file, 'cfgfile')
        dirstack.pop()
 
+def dofile(path):
+       """dofile is a simple include for single files"""
+       # if the first char is '/', it is relative to treetop, 
+       # else relative to curdir
+       # os.path.join screws up if the name starts with '/', sigh.
+       if (path[0] == '/'):
+               fullpath = os.path.join(treetop, 'src')
+               path = re.sub('^/*', '', path)
+       else:
+               fullpath = dirstack.tos()
+       print "INCLUDE %s" %path
+       debug.info(debug.statement, "DOFILE: path %s, fullpath %s" % (path, fullpath))
+       doconfigfile(fullpath, '', path, 'cfgfile')
+
 def lookup(name):
        global curimage
        return getoption(name, curimage)
@@ -1515,9 +1571,9 @@ def adddep(id, str):
 def setarch(my_arch):
        """arch is 'different' ... darn it."""
        global curimage
-       print "SETTING ARCH %s\n" % my_arch
+       print "SETTING CONFIG_ARCH %s\n" % my_arch
        curimage.setarch(my_arch)
-       setdefault('ARCH', my_arch, 1)
+       setdefault('CONFIG_ARCH', my_arch, 1)
        part('arch', my_arch, 'Config.lb', 0)
 
 def doconfigfile(path, confdir, file, rule):
@@ -1591,7 +1647,7 @@ parser Config:
     token ACTION:              'action'
     token ADDACTION:           'addaction'
     token ALWAYS:              'always'
-    token ARCH:                        'arch'
+    token CONFIG_ARCH:                 'arch'
     token BUILDROM:            'buildrom'
     token COMMENT:             'comment'
     token CONFIG:              'config'
@@ -1602,6 +1658,7 @@ parser Config:
     token DEFINE:              'define'
     token DEPENDS:             'depends'
     token DEVICE:              'device'
+    token DEVICE_ID:           'device_id'
     token DIR:                 'dir'
     token DRIVER:              'driver'
     token DRQ:                 'drq'
@@ -1615,11 +1672,12 @@ parser Config:
     token INIT:                        'init'
     token INITOBJECT:          'initobject'
     token INITINCLUDE:         'initinclude'
+    token INCLUDE:             'include'
     token IO:                  'io'
     token IRQ:                 'irq'
     token LDSCRIPT:            'ldscript'
     token LOADOPTIONS:         'loadoptions'
-    token MAINBOARD:           'mainboard'
+    token CONFIG_MAINBOARD:            'mainboard'
     token MAINBOARDINIT:       'mainboardinit'
     token MAKEDEFINE:          'makedefine'
     token MAKERULE:            'makerule'
@@ -1630,6 +1688,7 @@ parser Config:
     token OBJECT:              'object'
     token OPTION:              'option'
     token PAYLOAD:             'payload'
+    token PCI_ROM:             'pci_rom'
     token PMC:                 'pmc'
     token PRINT:               'print'
     token REGISTER:            'register'
@@ -1640,6 +1699,7 @@ parser Config:
     token TARGET:              'target'
     token USED:                        'used'
     token USES:                        'uses'
+    token VENDOR_ID:           'vendor_id'
     token WRITE:               'write'
     token NUM:                 '[0-9]+'
     token HEX_NUM:             '[0-9a-fA-F]+'
@@ -1650,7 +1710,7 @@ parser Config:
     # Dir's on the other hand are abitrary
     # this may all be stupid.
     token RULE:                        r'[-a-zA-Z0-9_$()./]+[-a-zA-Z0-9_ $()./]+[-a-zA-Z0-9_$()./]+'
-    token DIRPATH:             r'[-a-zA-Z0-9_$()./]+'
+    token DIRPATH:             r'[-a-zA-Z0-9_$()./,]+'
     token ID:                  r'[a-zA-Z_.]+[a-zA-Z0-9_.]*'
     token DELEXPR:             r'{([^}]+|\\.)*}'
     token STR:                 r'"([^\\"]+|\\.)*"'
@@ -1669,7 +1729,7 @@ parser Config:
 
     rule expr:         logical                 {{ l = logical }}
                        ( "&&" logical          {{ l = l and logical }}
-                       | "||"  logical         {{ l = l or logical }}
+                       | "[|][|]" logical      {{ l = l or logical }}
                        )*                      {{ return l }}
 
     rule logical:      factor                  {{ n = factor }}
@@ -1717,7 +1777,7 @@ parser Config:
                        ]                       {{ if (C): part(parttype, partid, 'Config.lb', name) }}
                        partend<<C>>            
 
-    rule arch<<C>>:    ARCH ID                 {{ if (C): setarch(ID) }}
+    rule arch<<C>>:    CONFIG_ARCH ID                  {{ if (C): setarch(ID) }}
                        partend<<C>>
     
     rule mainboardinit<<C>>:
@@ -1816,6 +1876,8 @@ parser Config:
                        HEX_NUM                 {{ cluster = int(HEX_NUM, 16) }}
                                                {{ if (C): partstack.tos().addapic_clusterpath(cluster) }}
 
+    rule include<<C>>: INCLUDE DIRPATH         {{ dofile(DIRPATH) }}
+
     rule cpu<<C>>:     CPU                     {{ if (C): devicepart('cpu') }}
                        HEX_NUM                 {{ id = int(HEX_NUM, 16) }}
                                                {{ if (C): partstack.tos().addcpupath(id) }}
@@ -1861,6 +1923,7 @@ parser Config:
                |       iif<<C>>                {{ return iif }}
                |       init<<C>>               {{ return init }}
                |       initinclude<<C>>        {{ return initinclude }}
+               |       include<<C>>            {{ return include }}
                |       initobject<<C>>         {{ return initobject }}
                |       ldscript<<C>>           {{ return ldscript}}
                |       mainboardinit<<C>>      {{ return mainboardinit }}
@@ -1879,10 +1942,6 @@ parser Config:
                        (stmt<<1>>)*
                        EOF                     {{ return 1 }}
 
-    rule cfgfile:      (uses<<1>>)* 
-                       (stmt<<1>>)*
-                       EOF                     {{ return 1 }}
-
     rule usesid<<C>>:  ID                      {{ if (C): usesoption(ID) }}
 
     rule uses<<C>>:    USES (usesid<<C>>)+
@@ -1910,7 +1969,7 @@ parser Config:
     rule payload<<C>>: PAYLOAD DIRPATH         {{ if (C): payload(DIRPATH) }}
 
     rule mainboard:
-                       MAINBOARD PATH          {{ mainboardsetup(PATH) }}
+                       CONFIG_MAINBOARD PATH           {{ mainboardsetup(PATH) }}
 
     rule romif<<C>>:   IF ID                   {{ c = lookup(ID) }}
                        (romstmt<<C and c>>)* 
@@ -1931,9 +1990,17 @@ parser Config:
 
     rule buildrom:     BUILDROM DIRPATH expr roms      {{ addbuildrom(DIRPATH, expr, roms) }}
 
+    rule pci_vid:      VENDOR_ID EQ term       {{ return term }}
+
+    rule pci_did:      DEVICE_ID EQ term       {{ return term }}
+
+
+    rule pci_rom:      PCI_ROM DIRPATH pci_vid pci_did {{ addpci_rom(DIRPATH, pci_vid, pci_did) }}
+
     rule romstmts:     romimage 
                |       buildrom
                |       opstmt<<1>>
+               |       pci_rom
 
     # ENTRY for parsing root part
     rule board:                {{ loadoptions("config", "Options.lb", "options") }}
@@ -2026,7 +2093,7 @@ def writeimagesettings(image):
        for o in exported:
                file.write("export VARIABLES += %s\n" % o.name)
        file.write("\n")
-       writemakefilefooter(file,filename)
+       writemakefilefooter(file,filename)
        file.close()
 
 # write the romimage makefile
@@ -2051,7 +2118,7 @@ def writeimagemakefile(image):
        file.write("# Function to create an item like -Di586 or -DCONFIG_MAX_CPUS='1' or -Ui686\n")
        file.write("D_item = $(shell echo '$(if $(subst undefined,,$(origin $1)),\\#define $1$(if $($1), $($1),),\\#undef $1)' >> settings.h)\n\n")
        file.write("# Compute the value of CPUFLAGS here during make's first pass.\n")
-       file.write("CPUFLAGS := $(strip $(shell echo '/* autogenerated */' > settings.h)$(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))--include=settings.h)\n\n")
+       file.write("CPUFLAGS := $(strip $(shell echo '/* autogenerated */' > settings.h)$(foreach _var_,$(VARIABLES),$(call D_item,$(_var_)))-include $(CURDIR)/settings.h)\n\n")
 
        for i in image.getuserdefines():
                file.write("%s\n" %i)
@@ -2119,38 +2186,15 @@ def writeimagemakefile(image):
 
        file.write("\n# initobjectrules:\n")
        for irule, init in image.getinitobjectrules().items():
-               source = topify(init[1])
-               type = init[2]
-               if (type  == 'S'):
-                       # for .S, .o depends on .s
-                       file.write("%s: %s.s\n" % (init[0], init[3]))
-                       file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
-                       # and .s depends on .S
-                       file.write("%s.s: %s\n" % (init[3], source))
-                       # Note: next 2 lines are ONE output line!
-                       file.write("\t$(CPP) $(CPPFLAGS) $< ")
-                       file.write(">$@.new && mv $@.new $@\n")
-               else:
-                       file.write("%s: %s\n" % (init[0], source))
-                       file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
+               image.addmakeobject(file, init);
 
-       file.write("\n# objectrules:\n")
+       file.write("\n# objectrules (don't duplicate initobjects):\n")
        for objrule, obj in image.getobjectrules().items():
-               source = topify(obj[1])
-               type = obj[2]
-               if (type  == 'S'):
-                       # for .S, .o depends on .s
-                       file.write("%s: %s.s\n" % (obj[0], obj[3]))
-                       file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
-                       # and .s depends on .S
-                       file.write("%s.s: %s\n" % (obj[3], source))
-                       # Note: next 2 lines are ONE output line!
-                       file.write("\t$(CPP) $(CPPFLAGS) $< ")
-                       file.write(">$@.new && mv $@.new $@\n")
+
+               if (getdict(image.getinitobjectrules(), obj[3])):
+                       debug.info(debug.object, "skipping %s" % (obj[3]))
                else:
-                       file.write("%s: %s\n" % (obj[0], source))
-                       file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
-               #file.write("%s\n" % objrule[2])
+                       image.addmakeobject(file, obj);
 
        for driverrule, driver in image.getdriverrules().items():
                source = topify(driver[1])
@@ -2160,20 +2204,7 @@ def writeimagemakefile(image):
 
        file.write("\n# smmobjectrules:\n")
        for irule, smm in image.getsmmobjectrules().items():
-               source = topify(smm[1])
-               type = smm[2]
-               if (type  == 'S'):
-                       # for .S, .o depends on .s
-                       file.write("%s: %s.s\n" % (smm[0], smm[3]))
-                       file.write("\t$(CC) -c $(CPU_OPT) -o $@ $<\n")
-                       # and .s depends on .S
-                       file.write("%s.s: %s\n" % (smm[3], source))
-                       # Note: next 2 lines are ONE output line!
-                       file.write("\t$(CPP) $(CPPFLAGS) $< ")
-                       file.write(">$@.new && mv $@.new $@\n")
-               else:
-                       file.write("%s: %s\n" % (smm[0], source))
-                       file.write("\t$(CC) -c $(CFLAGS) -o $@ $<\n")
+               image.addmakeobject(file, smm);
 
        # special rule for chip_target.c
        file.write("static.o: static.c\n")
@@ -2209,16 +2240,26 @@ def writeimagemakefile(image):
 
 #
 def writemakefile(path):
+       global rommapping
+       global bootblocksize
        makefilepath = os.path.join(path, "Makefile")
        print "Creating", makefilepath
        file = safe_open(makefilepath, 'w+')
        writemakefileheader(file, makefilepath)
 
+       # Hack to get the necessary settings (CONFIG_CBFS):
+       file.write("include %s/Makefile.settings\n\n" % romimages.keys()[0])
+
        # main rule
-       file.write("\nall:")
+       file.write("\nall: ")
        for i in buildroms:
                file.write(" %s" % i.name)
-       file.write("\n\n")      
+       file.write("\n")
+
+       # cbfstool rules
+       file.write("\ncbfstool:\n\tmkdir -p cbfs/tools/lzma\n\t$(MAKE) -C $(TOP)/util/cbfstool obj=$(shell pwd)/cbfs\n")
+       file.write("\ncbfstool-clean:\n\t$(MAKE) -C $(TOP)/util/cbfstool obj=$(shell pwd)/cbfs clean\n\n")
+
        file.write("include Makefile.settings\n\n")
        for i, o in romimages.items():
                file.write("%s/coreboot.rom:\n" % o.getname())
@@ -2236,6 +2277,40 @@ def writemakefile(path):
        file.write("base-clean:\n")
        file.write("\trm -f romcc*\n\n")
 
+       file.write("ifeq \"$(CONFIG_CBFS)\" \"1\"\n\n")
+       file.write("CBFS_COMPRESS_FLAG:=\n")
+       file.write("ifeq \"$(CONFIG_COMPRESSED_PAYLOAD_LZMA)\" \"1\"\nCBFS_COMPRESS_FLAG:=l\nendif\n\n")
+
+       for i in buildroms:
+               file.write("%s: cbfstool" %(i.name))
+               for j in i.roms:
+                       file.write(" %s/coreboot.rom " % j)
+               file.write("\n")
+
+               romsize = getoption("CONFIG_ROM_SIZE", image)
+
+               file.write("\n\trm -f %s\n" %(i.name))
+
+               # build the bootblock here.
+               file.write("\n\tcat")
+               for j in i.roms:
+                       file.write(" %s/coreboot.rom " % j)
+               file.write("> %s.bootblock\n\n" %i.name)
+               file.write("\t./cbfs/cbfstool %s create %s %s %s.bootblock\n"
+                          %(i.name, romsize, bootblocksize, i.name))
+               for j in pciroms:
+                       file.write("\t./cbfs/cbfstool %s add %s pci%04x,%04x.rom optionrom\n" % (i.name, j.name, j.pci_vid, j.pci_did))
+               for j in i.roms:
+                       #failover is a hack that will go away soon. 
+                       if (j != "failover") and (rommapping[j] != "/dev/null"):
+                               file.write("\t./cbfs/cbfstool %s add-payload %s %s/payload $(CBFS_COMPRESS_FLAG)\n" % (i.name, rommapping[j], j,))
+                       if (j != "failover"):
+                               file.write("\t./cbfs/cbfstool %s add-stage %s/coreboot_ram %s/coreboot_ram $(CBFS_COMPRESS_FLAG)\n" % (i.name, j, j,))
+                       file.write("\tif [ -f %s/coreboot_apc ]; then ./cbfs/cbfstool %s add-stage %s/coreboot_apc %s/coreboot_apc $(CBFS_COMPRESS_FLAG); fi\n" % (j, i.name, j, j,))
+               file.write("\t./cbfs/cbfstool %s print\n" % i.name)
+               file.write("\n")
+       file.write("else\n\n")
+
        for i in buildroms:
                file.write("%s:" % i.name)
                for j in i.roms:
@@ -2246,8 +2321,9 @@ def writemakefile(path):
                        file.write(" %s/coreboot.rom " % j)
                file.write("> %s\n\n" %i.name)
 
+       file.write("endif\n\n")
 
-       file.write(".PHONY: all clean")
+       file.write(".PHONY: all clean cbfstool")
        for i in romimages.keys():
                file.write(" %s-clean" % i)
        for i, o in romimages.items():