""" Quick and dirty python script to update coreboot's cpu list in powernow_acpi.c cpuentry entr[] Extracts P-states from AMD documentation, e.g. http://support.amd.com/us/Processor_TechDocs/30430.pdf For this script to work, you'll first have to save the cpu tables as csv text Some manual editing is probably required, I'd recommend using something like PDFEdit, http://pdfedit.cz and a text editor with column mode. Example csv format: Parameter/OPN ; ADA2800AEP4AP ; ADA3000AEP4AP ;ADA3200AEP5AP Model Number ; 2800+ ; 3000+ ; 3200+ (BrandID) ; 04h ; 04h ; 04h (CPUID) ; 00000F48h ; 00000F48h ; 00000F48h """ import os import sys import string import re if len(sys.argv) < 1: print "Usage: python ", sys.argv[0], " inputfile.csv > outputfile" sys.exit() inputFile = sys.argv[1] if not os.path.exists(inputFile): print "Inputfile does not exist ", inputFile sys.exit() #fields to extract OPN = "Parameter/OPN" MODEL = "ModelNumber" BRANDID = "(BrandID)" CPUID = "(CPUID)" MAXFID = "FID/VIDStatusMaxFIDField" STARTFID = "FID/VIDStatusStartFIDField" TDP = "ThermalDesignPower" IPS = "IntermediateP-State" MPS = "MinP-State" VID = "VIDCode/VID_VDD" #how many columns to skip SKIPCOLS = 1 #csv field separator SEPARATOR = ";" file = open(inputFile, 'r') #dictionary format: #[{'model':'', 'brandid':'', 'cpuid':'', 'maxfid':'', 'startfid':'', 'tdp':'', 'pstates':[{'pstate':'', 'vid':'', 'tdp':''}]}] cpus = [] tmp = [] def parseValue(columns, regex, key): global tmp global cpus if key == OPN: cpus.extend(tmp) tmp = [] for i in range(1, len(columns)): val = re.sub(regex, "", columns[i]).strip() if not val: continue cpu = {} cpu[IPS] = [] cpu[key] = val tmp.append(cpu) elif key == IPS or key == MPS: for i in range(1, len(columns)): val = re.sub(regex, "", columns[i]).strip() if not val: continue cpu = tmp[i-SKIPCOLS] cpu[IPS].append({IPS: val}) elif key == VID: for i in range(1, len(columns)): val = re.sub(regex, "", columns[i]).strip() if re.match("^0+$", val): val = '0' else: val = re.sub("^0+", "", val) if not val: continue cpu = tmp[i-SKIPCOLS] pstates = cpu[IPS] count = len(pstates) if count > 0: pstate = pstates[count - 1] pstate[key] = val elif key == TDP: for i in range(1, len(columns)): val = re.sub(regex, "", columns[i]).strip() if not val: continue cpu = tmp[i-SKIPCOLS] pstates = cpu[IPS] count = len(pstates) if count > 0: pstate = pstates[count - 1] pstate[key] = val else: cpu[key] = val else: for i in range(1, len(columns)): val = re.sub(regex, "", columns[i]).strip() if re.match("^0+$", val): val = '0' else: val = re.sub("^0+", "", val) if not val: continue cpu = tmp[i-SKIPCOLS] cpu[key] = val while 1: line = file.readline() if not line: break line = line.strip() if not line: continue columns = string.split(line,SEPARATOR) key = re.sub("\s|#.*", "", columns[0]).strip() opts = { OPN: lambda: parseValue(columns, "\s", OPN), MODEL: lambda: parseValue(columns, "\D", MODEL), BRANDID: lambda: parseValue(columns, "h", BRANDID), CPUID: lambda: parseValue(columns, "h", CPUID), MAXFID: lambda: parseValue(columns, "h", MAXFID), STARTFID: lambda: parseValue(columns, "h", STARTFID), TDP: lambda: parseValue(columns, "\D", TDP), IPS: lambda: parseValue(columns, "\D", IPS), VID: lambda: parseValue(columns, ".*h|\.|V", VID), MPS: lambda: parseValue(columns, "\D", MPS) }.get(key, lambda: None)() for i in cpus: tmpl = "/* {0} */ \n{{{1}, 0x{2}, 0x{3}, 0x{4}, 0x{5}, {6}, \n {{{7}}}}}," pstmpl = "{{{0}, {1}, {2}}}" pstates = [] for j in i[IPS]: pstates.append( pstmpl.format(j[IPS], j[VID], j[TDP]) ) print tmpl.format(i[OPN], i[MODEL], string.lower(i[BRANDID]), string.lower(i[CPUID]), string.lower(i[MAXFID]), string.lower(i[STARTFID]), i[TDP], string.join(pstates, ", ")) file.close()