Skip to content

Commit

Permalink
python: remove config parameter
Browse files Browse the repository at this point in the history
Config is already part of the hardware YAML object, take it from there.

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h committed Sep 15, 2022
1 parent 3a2143a commit 0a7d9b4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
11 changes: 5 additions & 6 deletions tools/hardware/outputs/c_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions tools/hardware/outputs/compat_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tools/hardware/outputs/elfloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions tools/hardware/outputs/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,15 +45,14 @@ 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')

# 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(
Expand Down
9 changes: 4 additions & 5 deletions tools/hardware/utils/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion tools/hardware/utils/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
2 changes: 1 addition & 1 deletion tools/hardware_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit 0a7d9b4

Please sign in to comment.