diff --git a/tools/hardware/outputs/c_header.py b/tools/hardware/outputs/c_header.py index 35d05712308..b188c4dc62c 100644 --- a/tools/hardware/outputs/c_header.py +++ b/tools/hardware/outputs/c_header.py @@ -11,7 +11,6 @@ import builtins import jinja2 import hardware -from hardware.config import Config from hardware.fdt import FdtParser from hardware.memory import Region from hardware.utils.rule import HardwareYaml, KernelInterrupt @@ -125,7 +124,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): @@ -136,7 +136,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, @@ -148,14 +148,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. @@ -194,7 +193,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 8db1841bc43..84618f1e7ec 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 57bbff8ff8b..9f60dee4400 100644 --- a/tools/hardware/outputs/elfloader.py +++ b/tools/hardware/outputs/elfloader.py @@ -143,7 +143,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 8fc70c41b4f..feccffdedef 100644 --- a/tools/hardware/outputs/yaml.py +++ b/tools/hardware/outputs/yaml.py @@ -10,7 +10,6 @@ import argparse import yaml import hardware -from hardware.config import Config from hardware.fdt import FdtParser from hardware.memory import Region from hardware.utils.rule import HardwareYaml, KernelInterrupt @@ -46,7 +45,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') @@ -54,7 +53,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 35db575da1e..3ae4820a4af 100644 --- a/tools/hardware/utils/memory.py +++ b/tools/hardware/utils/memory.py @@ -6,7 +6,6 @@ from __future__ import annotations import hardware -from hardware.config import Config from hardware.device import WrappedNode from hardware.fdt import FdtParser from hardware.memory import Region @@ -61,7 +60,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 @@ -103,7 +102,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 @@ -130,8 +129,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 dc503989535..74632e7f0f0 100644 --- a/tools/hardware/utils/rule.py +++ b/tools/hardware/utils/rule.py @@ -216,10 +216,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__':