From e75d22bedd0c3562ea4959aadb8e7ca0d1696f49 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Tue, 9 Nov 2021 00:54:45 +0100 Subject: [PATCH] python: align imports Signed-off-by: Axel Heider --- tools/hardware/memory.py | 9 ++++----- tools/hardware/outputs/c_header.py | 15 +++++++++------ tools/hardware/outputs/compat_strings.py | 8 ++++---- tools/hardware/outputs/yaml.py | 16 +++++++++------- tools/hardware/utils/memory.py | 6 +++--- tools/hardware_gen.py | 9 ++++++--- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/tools/hardware/memory.py b/tools/hardware/memory.py index 9c9b73cbd..a96a6c771 100644 --- a/tools/hardware/memory.py +++ b/tools/hardware/memory.py @@ -5,8 +5,7 @@ # import functools - -import hardware.utils as utils +import hardware @functools.total_ordering @@ -87,7 +86,7 @@ class Region: def align_base(self, align_bits): ''' align this region up to a given number of bits ''' - new_base = utils.align_up(self.base, align_bits) + new_base = hardware.utils.align_up(self.base, align_bits) diff = new_base - self.base if self.size < diff: raise ValueError( @@ -101,8 +100,8 @@ class Region: ''' align this region's size to a given number of bits. will move the base address down and the region's size up ''' - new_base = utils.align_down(self.base, align_bits) - new_size = utils.align_up(self.size, align_bits) + new_base = hardware.utils.align_down(self.base, align_bits) + new_size = hardware.utils.align_up(self.size, align_bits) return Region(new_base, new_size, self.owner) def make_chunks(self, chunksz): diff --git a/tools/hardware/outputs/c_header.py b/tools/hardware/outputs/c_header.py index 86f7c6189..4fa7e3d1a 100644 --- a/tools/hardware/outputs/c_header.py +++ b/tools/hardware/outputs/c_header.py @@ -9,8 +9,11 @@ import argparse import builtins import jinja2 from typing import Dict, List -from hardware import config, fdt -from hardware.utils import memory, rule +import hardware +from hardware.config import Config +from hardware.fdt import FdtParser +from hardware.utils.rule import HardwareYaml + HEADER_TEMPLATE = '''/* * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) @@ -119,7 +122,7 @@ static const p_region_t BOOT_RODATA avail_p_regs[] = { ''' -def get_kernel_devices(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml) -> (List, Dict): +def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml) -> (List, Dict): ''' Given a device tree and a set of rules, returns a tuple (groups, offsets). @@ -150,7 +153,7 @@ def get_kernel_devices(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml) -> (List return (groups, offsets) -def get_interrupts(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml) -> List: +def get_interrupts(tree: FdtParser, hw_yaml: HardwareYaml) -> List: ''' Get dict of interrupts, {label: KernelInterrupt} from the DT and hardware rules. ''' kernel_devices = tree.get_kernel_devices() @@ -196,11 +199,11 @@ def create_c_header_file(args, kernel_irqs: List, kernel_macros: Dict, outputStream.write(data) -def run(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml, config: config.Config, args: argparse.Namespace): +def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.Namespace): if not args.header_out: raise ValueError('You need to specify a header-out to use c header output') - physical_memory, reserved, physBase = memory.get_physical_memory(tree, config) + physical_memory, reserved, physBase = hardware.utils.memory.get_physical_memory(tree, config) kernel_regions, kernel_macros = get_kernel_devices(tree, hw_yaml) create_c_header_file( diff --git a/tools/hardware/outputs/compat_strings.py b/tools/hardware/outputs/compat_strings.py index 7b93a0169..3fe67ffa8 100644 --- a/tools/hardware/outputs/compat_strings.py +++ b/tools/hardware/outputs/compat_strings.py @@ -6,12 +6,12 @@ ''' generate a text file with matched compatible strings from the device tree ''' import argparse - -from hardware import config, fdt -from hardware.utils import rule +from hardware.config import Config +from hardware.fdt import FdtParser +from hardware.utils.rule import HardwareYaml -def run(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml, config: config.Config, +def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.Namespace): if not args.compat_strings_out: raise ValueError('You need to specify a compat-strings-out to use compat strings output') diff --git a/tools/hardware/outputs/yaml.py b/tools/hardware/outputs/yaml.py index c941d4f02..3a35fd8bd 100644 --- a/tools/hardware/outputs/yaml.py +++ b/tools/hardware/outputs/yaml.py @@ -9,9 +9,10 @@ import argparse import yaml from typing import List -from hardware import config, fdt -from hardware.utils import memory, rule -from hardware.memory import Region +import hardware +from hardware.config import Config +from hardware.fdt import FdtParser +from hardware.utils.rule import HardwareYaml def make_yaml_list_of_regions(regions) -> List: @@ -39,7 +40,7 @@ def create_yaml_file(dev_mem, phys_mem, outputStream): yaml.dump(yaml_obj, outputStream) -def get_kernel_devices(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml): +def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml): kernel_devices = tree.get_kernel_devices() groups = [] @@ -50,14 +51,15 @@ def get_kernel_devices(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml): return groups -def run(tree: fdt.FdtParser, hw_yaml: rule.HardwareYaml, config: config.Config, +def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.Namespace): if not args.yaml_out: raise ValueError('you need to provide a yaml-out to use the yaml output method') - phys_mem, reserved, _ = memory.get_physical_memory(tree, config) + phys_mem, reserved, _ = hardware.utils.memory.get_physical_memory(tree, config) kernel_devs = get_kernel_devices(tree, hw_yaml) - dev_mem = memory.get_addrspace_exclude(list(reserved) + phys_mem + kernel_devs, config) + dev_mem = hardware.utils.memory.get_addrspace_exclude( + list(reserved) + phys_mem + kernel_devs, config) create_yaml_file(dev_mem, phys_mem, args.yaml_out) diff --git a/tools/hardware/utils/memory.py b/tools/hardware/utils/memory.py index 66384934b..6fc39726f 100644 --- a/tools/hardware/utils/memory.py +++ b/tools/hardware/utils/memory.py @@ -6,8 +6,7 @@ from typing import List, Set -import hardware.utils as utils - +import hardware from hardware.config import Config from hardware.device import WrappedNode from hardware.fdt import FdtParser @@ -99,7 +98,8 @@ def get_addrspace_exclude(regions: List[Region], config: Config): ret = set() # We can't create untypeds that exceed the addrspace_max, so we round down to the smallest # untyped size alignment so that the kernel will be able to turn the entire range into untypeds. - as_max = utils.align_down(config.addrspace_max, config.get_smallest_kernel_object_alignment()) + as_max = hardware.utils.align_down(config.addrspace_max, + config.get_smallest_kernel_object_alignment()) ret.add(Region(0, as_max)) for reg in regions: diff --git a/tools/hardware_gen.py b/tools/hardware_gen.py index 76bc528df..6d084a1c6 100644 --- a/tools/hardware_gen.py +++ b/tools/hardware_gen.py @@ -10,10 +10,13 @@ import argparse import logging import yaml -from hardware import config, fdt +import hardware +from hardware.config import Config +from hardware.fdt import FdtParser from hardware.outputs import c_header, compat_strings, yaml as yaml_out, elfloader from hardware.utils.rule import HardwareYaml + OUTPUTS = { 'c_header': c_header, 'compat_strings': compat_strings, @@ -46,8 +49,8 @@ def add_task_args(outputs: dict, parser: argparse.ArgumentParser): def main(args: argparse.Namespace): ''' Parse the DT and hardware config YAML and run each selected output method. ''' - cfg = config.get_arch_config(args.arch, args.addrspace_max) - parsed_dt = fdt.FdtParser(args.dtb) + cfg = hardware.config.get_arch_config(args.arch, args.addrspace_max) + parsed_dt = FdtParser(args.dtb) rules = yaml.load(args.hardware_config, Loader=yaml.FullLoader) schema = yaml.load(args.hardware_schema, Loader=yaml.FullLoader) validate_rules(rules, schema)