Skip to content

Commit

Permalink
python: make yaml generator a bit more generic
Browse files Browse the repository at this point in the history
- pass a dict
- add type information for parameters

Signed-off-by: Axel Heider <[email protected]>
  • Loading branch information
axel-h committed Feb 3, 2022
1 parent 1c3470b commit e5e32ad
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions tools/hardware/outputs/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

import argparse
import yaml
from typing import List
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


def make_yaml_list_of_regions(regions) -> List:
def make_yaml_list_of_regions(regions: List[Region]) -> List:
return [
{
'start': r.base,
Expand All @@ -25,19 +26,19 @@ def make_yaml_list_of_regions(regions) -> List:
]


def create_yaml_file(dev_mem, phys_mem, outputStream):
def create_yaml_file(regions_dict: Dict[str, List[Region]], outputStream):

yaml.add_representer(
int,
lambda dumper, data: yaml.ScalarNode('tag:yaml.org,2002:int', hex(data)))

yaml_obj = {
'devices': make_yaml_list_of_regions(dev_mem),
'memory': make_yaml_list_of_regions(phys_mem)
}

with outputStream:
yaml.dump(yaml_obj, outputStream)
yaml.dump(
{
key: make_yaml_list_of_regions(val)
for key, val in regions_dict.items()
},
outputStream)


def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml):
Expand All @@ -61,7 +62,12 @@ def run(tree: FdtParser, hw_yaml: HardwareYaml, config: 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)
create_yaml_file(
{
'devices': dev_mem,
'memory': phys_mem
},
args.yaml_out)


def add_args(parser):
Expand Down

0 comments on commit e5e32ad

Please sign in to comment.