Files
seL4/tools/hardware/outputs/yaml.py
julia f9eb65c9a5 tools: don't exclude device-tree reserved memory
... from the device UT listed by platform_gen. The kernel itself
does not care about this memory, and it is just given as device UT.

We also just remove the reserved array entirely from the return of
`get_physical_memory` since it only seems to be a footgun, it's
only used internally to affect what memory the kernel wants to use.

Co-authored-by: Kent McLeod <kent@kry10.com>
Signed-off-by: julia <git.ts@trainwit.ch>
2025-10-16 11:05:15 +01:00

74 lines
2.1 KiB
Python

#
# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
#
# SPDX-License-Identifier: GPL-2.0-only
#
''' generate a yaml file with memory region info from the device tree '''
import argparse
import yaml
from typing import Dict, List
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:
return [
{
'start': r.base,
'end': r.base + r.size
}
for r in regions if r.size > 0
]
def create_yaml_file(dev_mem, phys_mem, 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)
def get_kernel_devices(tree: FdtParser, hw_yaml: HardwareYaml, kernel_config_dict: Dict[str, str]):
kernel_devices = tree.get_kernel_devices()
groups = []
for dev in kernel_devices:
rule = hw_yaml.get_rule(dev)
new_regions = rule.get_regions(dev)
for reg in new_regions:
if reg.macro in kernel_config_dict:
if kernel_config_dict[reg.macro] != "ON":
continue
groups.append(reg)
return groups
def run(tree: FdtParser, hw_yaml: HardwareYaml, config: Config,
kernel_config_dict, 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, _ = hardware.utils.memory.get_physical_memory(tree, config)
kernel_devs = get_kernel_devices(tree, hw_yaml, kernel_config_dict)
dev_mem = hardware.utils.memory.get_addrspace_exclude(phys_mem + kernel_devs, config)
create_yaml_file(dev_mem, phys_mem, args.yaml_out)
def add_args(parser):
parser.add_argument('--yaml-out', help='output file for memory yaml',
type=argparse.FileType('w'))