X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/1fe5f5eb5378a47bf0f3451762743c162e40faad..b60166b327a9108b07e3069fa6568a451529ffd9:/lunaix-os/scripts/expand.py diff --git a/lunaix-os/scripts/expand.py b/lunaix-os/scripts/expand.py index 041bb78..31e06da 100644 --- a/lunaix-os/scripts/expand.py +++ b/lunaix-os/scripts/expand.py @@ -284,33 +284,35 @@ class MemoryMapObject(DataObject): if "width" in record: self.__width = DataObject.create("width", record["width"]) - def __process(self, start_addr, idx, regions, size_lookahead = False): + def __process(self, start_addr, idx, regions): if idx >= len(regions): raise Exception("Unbounded region definition") e = regions[idx] + if "start" not in e: + ne = regions[idx + 1] + if "start" not in ne or "size" not in e: + e["start"] = start_addr + else: + self.__process(start_addr + e["size"], idx + 1, regions) + e["start"] = ne['start'] - e["size"] + if "block" in e: b = e["block"] - 1 - start_addr = (start_addr + b) & ~b + e["start"] = (e["start"] + b) & ~b - if "start" not in e: - e["start"] = start_addr - elif e["start"] < start_addr: + if e["start"] < start_addr: raise Exception(f"starting addr {hex(e['start'])} overrlapping with {hex(start_addr)}") - else: - start_addr = e["start"] - if "size" not in e: - if size_lookahead: - raise Exception("could not infer size from unbounded region") - tmp_addr = self.__process(start_addr, idx + 1, regions, size_lookahead=True) - e["size"] = tmp_addr - start_addr + start_addr = e["start"] - if not size_lookahead: - start_addr += e["size"] + if "size" not in e: + self.__process(start_addr, idx + 1, regions) + ne = regions[idx + 1] + e["size"] = ne['start'] - start_addr - return start_addr + return start_addr + e["size"] def expand(self, param={}): super().expand(param) @@ -443,10 +445,13 @@ class TemplateExpander: self.mapping[src] = dest.strip() - def render(self): + def render(self, selected = []): for k, v in self.mapping.items(): src: Path = self.tbase_path.joinpath(k) dest: Path = self.pbase_path.joinpath(v) + if (k not in selected): + continue + if not src.is_file(): continue @@ -466,6 +471,7 @@ import pprint def main(): parser = argparse.ArgumentParser() + parser.add_argument("selects", nargs="*") parser.add_argument("--arch", default='i386') parser.add_argument("-twd", "--template_dir", default=str(Path.cwd())) parser.add_argument("-pwd", "--project_dir", default=str(Path.cwd())) @@ -474,7 +480,7 @@ def main(): expander = TemplateExpander(Path(args.template_dir), Path(args.project_dir), args.arch) - expander.render() + expander.render(args.selects) # pprint.pprint(expander.data) if __name__ == "__main__":