diff --git a/tools/hardware/outputs/c_header.py b/tools/hardware/outputs/c_header.py index 8addc7ec649..2d5074cee3e 100644 --- a/tools/hardware/outputs/c_header.py +++ b/tools/hardware/outputs/c_header.py @@ -10,7 +10,6 @@ import jinja2 from typing import Dict, List import hardware -from hardware.config import Config from hardware.fdt import FdtParser from hardware.memory import Region from hardware.utils.rule import HardwareYaml, KernelInterrupt @@ -119,7 +118,8 @@ ''' -def create_c_header_file(config, kernel_irqs: List[KernelInterrupt], +def create_c_header_file(hw_yaml: HardwareYaml, + kernel_irqs: List[KernelInterrupt], kernel_dev_addr_macros: Dict[str, int], kernel_regions: List[Region], physBase: int, physical_memory: List[Region], outputStream): @@ -130,7 +130,7 @@ def create_c_header_file(config, kernel_irqs: List[KernelInterrupt], template_args = dict( builtins.__dict__, **{ - 'config': config, + 'config': hw_yaml.config, 'kernel_irqs': kernel_irqs, 'kernel_dev_addr_macros': kernel_dev_addr_macros, 'kernel_regions': kernel_regions, @@ -142,14 +142,13 @@ def create_c_header_file(config, kernel_irqs: List[KernelInterrupt], outputStream.write(data) -def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.Namespace): +def run(tree: FdtParser, hw_yaml: HardwareYaml, args: argparse.Namespace): if not args.header_out: raise ValueError('You need to specify a header-out to use c header output') # We only care about the available physical memory and the kernel's phys # base. The device memory regions are not relevant here. physical_memory, _, physBase = hardware.utils.memory.get_phys_mem_regions(tree, - config, hw_yaml) # Collect the interrupts and kernel regions for the devices. @@ -188,7 +187,7 @@ def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.N kernel_dev_addr_macros[label] = offset create_c_header_file( - config, + hw_yaml, sorted(kernel_irq_dict.values(), key=lambda irq: irq.label), sorted(kernel_dev_addr_macros.items(), key=lambda tupel: tupel[1]), kernel_regions, diff --git a/tools/hardware/outputs/compat_strings.py b/tools/hardware/outputs/compat_strings.py index 3fe67ffa822..38cb9e757bf 100644 --- a/tools/hardware/outputs/compat_strings.py +++ b/tools/hardware/outputs/compat_strings.py @@ -6,13 +6,11 @@ ''' generate a text file with matched compatible strings from the device tree ''' import argparse -from hardware.config import Config from hardware.fdt import FdtParser from hardware.utils.rule import HardwareYaml -def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, - args: argparse.Namespace): +def run(tree: FdtParser, hw_yaml: HardwareYaml, args: argparse.Namespace): if not args.compat_strings_out: raise ValueError('You need to specify a compat-strings-out to use compat strings output') chosen = tree.get_kernel_devices() diff --git a/tools/hardware/outputs/elfloader.py b/tools/hardware/outputs/elfloader.py index 2d00712be6f..aa848ae99be 100644 --- a/tools/hardware/outputs/elfloader.py +++ b/tools/hardware/outputs/elfloader.py @@ -140,7 +140,7 @@ def get_elfloader_cpus(tree: fdt.FdtParser, devices: List[device.WrappedNode]) - return sorted(cpu_info, key=lambda a: a['cpuid']) -def run(tree: fdt.FdtParser, hardware: rule.HardwareYaml, config: config.Config, args: argparse.Namespace): +def run(tree: fdt.FdtParser, hardware: rule.HardwareYaml, args: argparse.Namespace): devices = tree.get_elfloader_devices() cpu_info = get_elfloader_cpus(tree, devices) diff --git a/tools/hardware/outputs/yaml.py b/tools/hardware/outputs/yaml.py index b5b81247f12..c3228ae37eb 100644 --- a/tools/hardware/outputs/yaml.py +++ b/tools/hardware/outputs/yaml.py @@ -10,7 +10,6 @@ import yaml from typing import List, Dict import hardware -from hardware.config import Config from hardware.fdt import FdtParser from hardware.memory import Region from hardware.utils.rule import HardwareYaml, KernelInterrupt @@ -41,7 +40,7 @@ def create_yaml_file(regions_dict: Dict[str, List[Region]], outputStream): outputStream) -def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.Namespace): +def run(tree: FdtParser, hw_yaml: HardwareYaml, args: argparse.Namespace): if not args.yaml_out: raise ValueError('you need to provide a yaml-out to use the yaml output method') @@ -49,7 +48,6 @@ def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config, args: argparse.N # Get the physical memory and device regions, we don't care about the kernel # phy_base address here. phys_mem, dev_mem, _ = hardware.utils.memory.get_phys_mem_regions(tree, - config, hw_yaml) create_yaml_file( diff --git a/tools/hardware/utils/memory.py b/tools/hardware/utils/memory.py index 175bcc8363e..7412188e3d4 100644 --- a/tools/hardware/utils/memory.py +++ b/tools/hardware/utils/memory.py @@ -7,7 +7,6 @@ from typing import List, Set import hardware -from hardware.config import Config from hardware.device import WrappedNode from hardware.fdt import FdtParser from hardware.memory import Region @@ -58,7 +57,7 @@ def carve_out_region(regions: Set[Region], reserved_reg: Region) -> Set[Region]: return ret_regions -def get_phys_mem_regions(tree: FdtParser, config: Config, hw_yaml: HardwareYaml) \ +def get_phys_mem_regions(tree: FdtParser, hw_yaml: HardwareYaml) \ -> (List[Region], List[Region], int): ''' Returns a list of regions representing physical memory as used by the kernel @@ -101,7 +100,7 @@ def visitor(node: WrappedNode): # after we have removed the reserved region from the device tree, because we # also get 'kernel_phys_base' here. And once we have that, the memory # regions can't the modified any longer. - kernel_phys_align = config.get_kernel_phys_align() + kernel_phys_align = hw_yaml.config.get_kernel_phys_align() if kernel_phys_align != 0: # Align the first so that the ELF loader will be able to load the kernel # into it. Will return the aligned memory region list, a set of any @@ -129,8 +128,8 @@ def visitor(node: WrappedNode): Region( 0, hardware.utils.align_down( - config.addrspace_max, - config.get_smallest_kernel_object_alignment())) + hw_yaml.config.addrspace_max, + hw_yaml.config.get_smallest_kernel_object_alignment())) } for reg in mem_region_list + reserved_region_list: diff --git a/tools/hardware/utils/rule.py b/tools/hardware/utils/rule.py index 829272d54ba..0e5c0d8f28d 100644 --- a/tools/hardware/utils/rule.py +++ b/tools/hardware/utils/rule.py @@ -213,10 +213,11 @@ def get_interrupts(self, tree: FdtParser, node: WrappedNode) -> List[KernelInter class HardwareYaml: - ''' Represents the hardware configuration file ''' + ''' Represents the hardware configuration ''' def __init__(self, yaml: dict, config: Config): self.rules = {} + self.config = config for dev in yaml['devices']: rule = DeviceRule(dev, config) for compat in dev['compatible']: diff --git a/tools/hardware_gen.py b/tools/hardware_gen.py index a97d23f0df1..3171a3154ed 100644 --- a/tools/hardware_gen.py +++ b/tools/hardware_gen.py @@ -59,7 +59,7 @@ def main(args: argparse.Namespace): arg_dict = vars(args) for t in sorted(OUTPUTS.keys()): if arg_dict[t]: - OUTPUTS[t].run(parsed_dt, hw_yaml, cfg, args) + OUTPUTS[t].run(parsed_dt, hw_yaml, args) if __name__ == '__main__':