def process_device(device, ppath, quiet): # Load the SVD and process all modifications from the yaml # (but don't bother actually applying the enums/ranges). svdpath = svdpatch.abspath(device["_path"], device["_svd"]) if not quiet: print("Loading SVD {} for {}".format(svdpath, device["_path"])) tree = ET.parse(svdpath) if not quiet: print("Processing existing device peripherals") already_included = svdpatch.yaml_includes(device) svdpatch.process_device(tree, device, False) # Now go through every YAML file we can find and see if they could be # matched against the device if not quiet: print("Matching against remaining peripherals") matches = [] if os.path.isfile(ppath): yamlpath = os.path.realpath(ppath) if yamlpath not in already_included: if process_yamlfile(tree, ppath, quiet): matches.append(ppath) else: for root, dirnames, filenames in os.walk(ppath): for filename in fnmatch.filter(filenames, "*.yaml"): yamlpath = os.path.realpath(os.path.join(root, filename)) if yamlpath in already_included: continue if process_yamlfile(tree, yamlpath, quiet): matches.append(yamlpath) return matches
def process_yamlfile(svd, yamlpath, quiet): with open(yamlpath) as f: peripheral = yaml.safe_load(f) peripheral["_path"] = yamlpath svdpatch.yaml_includes(peripheral) matched = True for pspec in peripheral: if not pspec.startswith("_"): peripheral[pspec]["_path"] = peripheral["_path"] try: svdpatch.process_peripheral(svd, pspec, peripheral[pspec], True) except svdpatch.SvdPatchError as e: if not quiet: print("Couldn't match {}: {}".format(yamlpath, e)) matched = False continue return matched
def main(): parser = argparse.ArgumentParser() parser.add_argument("devices", nargs="*") args = parser.parse_args() for dpath in args.devices: with open(dpath) as f: device = yaml.safe_load(f) device["_path"] = dpath deps = svdpatch.yaml_includes(device) depname = ".deps/{}.d".format( os.path.splitext(os.path.basename(dpath))[0]) svdname = "svd/{}.patched.svd".format( os.path.splitext(os.path.basename(dpath))[0]) print("{} {} {}: {}".format(dpath, svdname, depname, " ".join(deps)))